From 780a719227339c5af28473a87ac2e4641091e33d Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:21:33 -0500 Subject: Continue changing anonymous mode. --- .../activities/ViewSubredditDetailActivity.java | 7 +++++-- .../adapters/SubredditListingRecyclerViewAdapter.java | 12 +++++++----- .../fragments/SubredditListingFragment.java | 8 ++++---- .../infinityforreddit/subreddit/FetchSubredditData.java | 7 ++++--- .../infinityforreddit/subreddit/SubredditSubscription.java | 8 ++++---- 5 files changed, 24 insertions(+), 18 deletions(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 2cb49550..b9a77bc2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -180,6 +180,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Named("oauth") Retrofit mOauthRetrofit; @Inject + @Named("application_only_oauth") + Retrofit mApplicationOnlyOauthRetrofit; + @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject @Named("default") @@ -959,7 +962,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp subscriptionReady = false; if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) { SubredditSubscription.anonymousSubscribeToSubreddit(mExecutor, new Handler(), - mRetrofit, mRedditDataRoomDatabase, subredditName, + mApplicationOnlyOauthRetrofit, mRedditDataRoomDatabase, subredditName, new SubredditSubscription.SubredditSubscriptionListener() { @Override public void onSubredditSubscriptionSuccess() { @@ -1000,7 +1003,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp subscriptionReady = false; if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) { SubredditSubscription.subscribeToSubreddit(mExecutor, new Handler(), mOauthRetrofit, - mRetrofit, mAccessToken, subredditName, mAccountName, mRedditDataRoomDatabase, + mAccessToken, subredditName, mAccountName, mRedditDataRoomDatabase, new SubredditSubscription.SubredditSubscriptionListener() { @Override public void onSubredditSubscriptionSuccess() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java index c1d60585..39cafb9d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java @@ -60,7 +60,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter { if (!accountName.equals(Account.ANONYMOUS_ACCOUNT)) { SubredditSubscription.subscribeToSubreddit(executor, new Handler(), - oauthRetrofit, retrofit, accessToken, subredditData.getName(), + oauthRetrofit, accessToken, subredditData.getName(), accountName, redditDataRoomDatabase, new SubredditSubscription.SubredditSubscriptionListener() { @Override @@ -176,7 +177,8 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter subredditData = oauthApi.getSubredditDataOauth(subredditName, APIUtils.getOAuthHeader(accessToken)); subredditData.enqueue(new Callback<>() { @@ -47,8 +48,8 @@ public class FetchSubredditData { public static void fetchSubredditData(Retrofit applicationOnlyOauthRetrofit, String subredditName, final FetchSubredditDataListener fetchSubredditDataListener) { - RedditAPI oauthApi = applicationOnlyOauthRetrofit.create(RedditAPI.class); - Call subredditData = oauthApi.getSubredditDataOauth(subredditName, new HashMap<>()); + Call subredditData = applicationOnlyOauthRetrofit.create(RedditAPI.class) + .getSubredditDataOauth(subredditName, new HashMap<>()); subredditData.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java index 71372ade..969f9ea4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java @@ -20,18 +20,18 @@ import retrofit2.Retrofit; public class SubredditSubscription { public static void subscribeToSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, - Retrofit retrofit, @Nullable String accessToken, String subredditName, + @Nullable String accessToken, String subredditName, @NonNull String accountName, RedditDataRoomDatabase redditDataRoomDatabase, SubredditSubscriptionListener subredditSubscriptionListener) { subredditSubscription(executor, handler, oauthRetrofit, accessToken, subredditName, accountName, "sub", redditDataRoomDatabase, subredditSubscriptionListener); } - public static void anonymousSubscribeToSubreddit(Executor executor, Handler handler, Retrofit retrofit, + public static void anonymousSubscribeToSubreddit(Executor executor, Handler handler, Retrofit applicationOnlyOauth, RedditDataRoomDatabase redditDataRoomDatabase, String subredditName, SubredditSubscriptionListener subredditSubscriptionListener) { - FetchSubredditData.fetchSubredditData(null, subredditName, "", new FetchSubredditData.FetchSubredditDataListener() { + FetchSubredditData.fetchSubredditData(applicationOnlyOauth, subredditName, new FetchSubredditData.FetchSubredditDataListener() { @Override public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { insertSubscription(executor, handler, redditDataRoomDatabase, @@ -72,7 +72,7 @@ public class SubredditSubscription { params.put(APIUtils.SR_NAME_KEY, subredditName); Call subredditSubscriptionCall = api.subredditSubscription(APIUtils.getOAuthHeader(accessToken), params); - subredditSubscriptionCall.enqueue(new Callback() { + subredditSubscriptionCall.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { -- cgit v1.2.3