diff options
4 files changed, 21 insertions, 5 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java index e1f9c5e7..1a7736c4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Call; @@ -25,10 +26,10 @@ public class FetchRules { void failed(); } - public static void fetchRules(Executor executor, Handler handler, Retrofit retrofit, String subredditName, + public static void fetchRules(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String subredditName, FetchRulesListener fetchRulesListener) { RedditAPI api = retrofit.create(RedditAPI.class); - Call<String> rulesCall = api.getRules(subredditName); + Call<String> rulesCall = accessToken == null ? api.getRules(subredditName) : api.getRulesOauth(APIUtils.getOAuthHeader(accessToken), subredditName); rulesCall.enqueue(new Callback<String>() { @Override public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java index 91ca0686..f3265367 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java @@ -119,7 +119,7 @@ public class ReportActivity extends BaseActivity { recyclerView.setAdapter(mAdapter); if (rulesReasons == null) { - FetchRules.fetchRules(mExecutor, new Handler(), mRetrofit, mSubredditName, new FetchRules.FetchRulesListener() { + FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() { @Override public void success(ArrayList<Rule> rules) { mAdapter.setRules(ReportReason.convertRulesToReasons(rules)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java index 21bf5f85..a33bdde0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java @@ -11,6 +11,7 @@ import android.view.Window; import android.view.WindowManager; import android.widget.ProgressBar; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; @@ -65,6 +66,15 @@ public class RulesActivity extends BaseActivity { @Named("no_oauth") Retrofit mRetrofit; @Inject + @Named("oauth") + Retrofit mOauthRetrofit; + + private String mAccessToken; + @Inject + @Named("current_account") + SharedPreferences mCurrentAccountSharedPreferences; + + @Inject @Named("default") SharedPreferences mSharedPreferences; @Inject @@ -114,6 +124,7 @@ public class RulesActivity extends BaseActivity { } } } + mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); appBarLayout.setBackgroundColor(mCustomThemeWrapper.getColorPrimary()); setSupportActionBar(toolbar); @@ -124,7 +135,7 @@ public class RulesActivity extends BaseActivity { mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, slidrInterface); recyclerView.setAdapter(mAdapter); - FetchRules.fetchRules(mExecutor, new Handler(), mRetrofit, mSubredditName, new FetchRules.FetchRulesListener() { + FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() { @Override public void success(ArrayList<Rule> rules) { progressBar.setVisibility(View.GONE); @@ -142,6 +153,7 @@ public class RulesActivity extends BaseActivity { displayError(); } }); + } @Override @@ -172,7 +184,7 @@ public class RulesActivity extends BaseActivity { errorTextView.setOnClickListener(view -> { progressBar.setVisibility(View.VISIBLE); errorTextView.setVisibility(View.GONE); - FetchRules.fetchRules(mExecutor, new Handler(), mRetrofit, mSubredditName, new FetchRules.FetchRulesListener() { + FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() { @Override public void success(ArrayList<Rule> rules) { progressBar.setVisibility(View.GONE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java index 2c75a17c..9cb8246b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java @@ -131,6 +131,9 @@ public interface RedditAPI { @GET("/r/{subredditName}/about/rules.json?raw_json=1") Call<String> getRules(@Path("subredditName") String subredditName); + @GET("/r/{subredditName}/about/rules.json?raw_json=1") + Call<String> getRulesOauth(@HeaderMap Map<String, String> headers, @Path("subredditName") String subredditName); + @GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1") Call<String> getPostAndCommentsSingleThreadByIdOauth(@Path("id") String id, @Path("singleCommentId") String singleCommentId, @Query("sort") String sortType, @Query("context") String contextNumber, |