From 4df18af91447d7fcd9768f0b5a8f71974f826280 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 12 Aug 2019 14:42:25 +0800 Subject: Minor bugs fixed. --- .../infinityforreddit/FetchPost.java | 10 +++++++--- .../infinityforreddit/RedditAPI.java | 4 ++++ .../infinityforreddit/ViewPostDetailActivity.java | 23 +++++++++++++--------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPost.java index b1e7816b..d169cb10 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPost.java @@ -17,9 +17,13 @@ class FetchPost { void fetchPostFailed(); } - static void fetchPost(Retrofit oauthRetrofit, String id, String accessToken, Locale locale, FetchPostListener fetchPostListener) { - RedditAPI api = oauthRetrofit.create(RedditAPI.class); - Call postCall = api.getPostOauth(id, RedditUtils.getOAuthHeader(accessToken)); + static void fetchPost(Retrofit retrofit, String id, String accessToken, Locale locale, FetchPostListener fetchPostListener) { + Call postCall; + if(accessToken == null) { + postCall = retrofit.create(RedditAPI.class).getPost(id); + } else { + postCall = retrofit.create(RedditAPI.class).getPostOauth(id, RedditUtils.getOAuthHeader(accessToken)); + } postCall.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java index 89d848c1..0412b99e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java @@ -127,4 +127,8 @@ public interface RedditAPI { @Multipart @POST(".") Call uploadMediaToAWS(@PartMap()Map params, @Part() MultipartBody.Part file); + + @FormUrlEncoded + @POST("/api/editusertext") + Call editPostOrComment(@HeaderMap Map headers, @FieldMap Map params); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index f96301b3..4be80aa7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit; -import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; @@ -252,13 +251,15 @@ public class ViewPostDetailActivity extends AppCompatActivity { private void fetchPostAndCommentsById(String subredditId) { mFetchPostInfoLinearLayout.setVisibility(View.GONE); + mProgressBar.setVisibility(View.VISIBLE); mGlide.clear(mFetchPostInfoImageView); - String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE) - .getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, ""); - - RedditAPI api = mOauthRetrofit.create(RedditAPI.class); - Call postAndComments = api.getPostAndCommentsByIdOauth(subredditId, RedditUtils.getOAuthHeader(accessToken)); + Call postAndComments; + if(mAccessToken == null) { + postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsById(subredditId); + } else { + postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId, RedditUtils.getOAuthHeader(mAccessToken)); + } postAndComments.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { @@ -419,9 +420,13 @@ public class ViewPostDetailActivity extends AppCompatActivity { fetchComments(); - String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE) - .getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, ""); - FetchPost.fetchPost(mOauthRetrofit, mPost.getId(), accessToken, mLocale, + Retrofit retrofit; + if(mAccessToken == null) { + retrofit = mRetrofit; + } else { + retrofit = mOauthRetrofit; + } + FetchPost.fetchPost(retrofit, mPost.getId(), mAccessToken, mLocale, new FetchPost.FetchPostListener() { @Override public void fetchPostSuccess(Post post) { -- cgit v1.2.3