mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Rules can now show in private subreddits (#1181)
* Added oauth to fetching rules * Added getRulesOauth for users that are logged in Co-authored-by: Abi <u7290897@anu.edu.au>
This commit is contained in:
parent
2863fa90be
commit
0cab9663d4
@ -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) {
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
@ -64,6 +65,15 @@ public class RulesActivity extends BaseActivity {
|
||||
@Inject
|
||||
@Named("no_oauth")
|
||||
Retrofit mRetrofit;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
|
||||
private String mAccessToken;
|
||||
@Inject
|
||||
@Named("current_account")
|
||||
SharedPreferences mCurrentAccountSharedPreferences;
|
||||
|
||||
@Inject
|
||||
@Named("default")
|
||||
SharedPreferences mSharedPreferences;
|
||||
@ -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);
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user