aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ApplicationOnlyAccessTokenAuthenticator.java96
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java37
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java2
17 files changed, 179 insertions, 60 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ApplicationOnlyAccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ApplicationOnlyAccessTokenAuthenticator.java
new file mode 100644
index 00000000..8dc2e461
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ApplicationOnlyAccessTokenAuthenticator.java
@@ -0,0 +1,96 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.content.SharedPreferences;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import ml.docilealligator.infinityforreddit.account.Account;
+import ml.docilealligator.infinityforreddit.apis.RedditAPI;
+import ml.docilealligator.infinityforreddit.utils.APIUtils;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import okhttp3.Authenticator;
+import okhttp3.Headers;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.Route;
+import retrofit2.Call;
+import retrofit2.Retrofit;
+
+class ApplicationOnlyAccessTokenAuthenticator implements Authenticator {
+ private final Retrofit mRetrofit;
+ private final RedditDataRoomDatabase mRedditDataRoomDatabase;
+ private final SharedPreferences mCurrentAccountSharedPreferences;
+
+ ApplicationOnlyAccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase, SharedPreferences currentAccountSharedPreferences) {
+ mRetrofit = retrofit;
+ mRedditDataRoomDatabase = accountRoomDatabase;
+ mCurrentAccountSharedPreferences = currentAccountSharedPreferences;
+ }
+
+ @Nullable
+ @Override
+ public Request authenticate(Route route, @NonNull Response response) {
+ if (response.code() == 401) {
+ String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY);
+ if (accessTokenHeader == null) {
+ return null;
+ }
+
+ String accessToken = accessTokenHeader.substring(APIUtils.AUTHORIZATION_BASE.length());
+ synchronized (this) {
+ if (mRedditDataRoomDatabase.accountDao().isAnonymousAccountInserted()) {
+ mRedditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount());
+ }
+ String accessTokenFromSharedPreference = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, "");
+ if (accessToken.equals(accessTokenFromSharedPreference) || accessToken.equals("null")) {
+ String newAccessToken = getApplicationOnlyAccessToken();
+ if (!newAccessToken.equals("")) {
+ return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(newAccessToken))).build();
+ } else {
+ return null;
+ }
+ } else {
+ return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(accessTokenFromSharedPreference))).build();
+ }
+ }
+ }
+ return null;
+ }
+
+ //For anonymous mode
+ private String getApplicationOnlyAccessToken() {
+ RedditAPI api = mRetrofit.create(RedditAPI.class);
+
+ Map<String, String> params = new HashMap<>();
+ params.put(APIUtils.GRANT_TYPE_KEY, APIUtils.GRANT_TYPE_INSTALLED_CLIENT);
+ params.put(APIUtils.DEVICE_ID_KEY, APIUtils.DEVICE_ID);
+
+ Call<String> accessTokenCall = api.getAccessToken(APIUtils.getApplicationOnlyBasicAuthHeader(), params);
+ try {
+ retrofit2.Response<String> response = accessTokenCall.execute();
+ if (response.isSuccessful() && response.body() != null) {
+ JSONObject jsonObject = new JSONObject(response.body());
+ String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY);
+ mRedditDataRoomDatabase.accountDao().updateAccessToken(Account.ANONYMOUS_ACCOUNT, newAccessToken);
+ if (mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT).equals(Account.ANONYMOUS_ACCOUNT)) {
+ mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, newAccessToken).apply();
+ }
+
+ return newAccessToken;
+ }
+ return "";
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ }
+
+ return "";
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java
index 647d87c8..e92ed14a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java
@@ -68,6 +68,22 @@ abstract class NetworkModule {
}
@Provides
+ @Named("application_only_oauth")
+ static Retrofit provideApplicationOnlyOAuthRetrofit(@Named("base") Retrofit retrofit,
+ @Named("base") OkHttpClient httpClient,
+ RedditDataRoomDatabase accountRoomDatabase,
+ @Named("current_account") SharedPreferences currentAccountSharedPreferences,
+ ConnectionPool connectionPool) {
+ return retrofit.newBuilder()
+ .baseUrl(APIUtils.OAUTH_API_BASE_URI)
+ .client(httpClient.newBuilder()
+ .authenticator(new ApplicationOnlyAccessTokenAuthenticator(retrofit, accountRoomDatabase, currentAccountSharedPreferences))
+ .connectionPool(connectionPool)
+ .build())
+ .build();
+ }
+
+ @Provides
@Named("default")
@Singleton
static OkHttpClient provideOkHttpClient(@Named("base") OkHttpClient httpClient,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java
index 7b1cb7cc..11a11fa7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java
@@ -177,11 +177,11 @@ public class LoginActivity extends BaseActivity {
Map<String, String> params = new HashMap<>();
params.put(APIUtils.GRANT_TYPE_KEY, "authorization_code");
params.put("code", authCode);
- params.put("redirect_uri", APIUtils.REDIRECT_URI);
+ params.put(APIUtils.REDIRECT_URI_KEY, APIUtils.REDIRECT_URI);
RedditAPI api = mRetrofit.create(RedditAPI.class);
Call<String> accessTokenCall = api.getAccessToken(APIUtils.getHttpBasicAuthHeader(), params);
- accessTokenCall.enqueue(new Callback<String>() {
+ accessTokenCall.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
index dd6dbc5e..0748fb33 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
@@ -170,9 +170,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
SubscribedSubredditViewModel subscribedSubredditViewModel;
AccountViewModel accountViewModel;
@Inject
- @Named("no_oauth")
- Retrofit mRetrofit;
- @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java
index 50f67c67..f6b61a39 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java
@@ -141,12 +141,12 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
@BindView(R.id.images_recycler_view_post_gallery_activity)
RecyclerView imagesRecyclerView;
@Inject
- @Named("no_oauth")
- Retrofit mRetrofit;
- @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
@Named("upload_media")
Retrofit mUploadMediaRetrofit;
@Inject
@@ -531,7 +531,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
- mAccessToken, mAccountName, mOauthRetrofit, iconImageUrl -> {
+ mAccessToken, mApplicationOnlyRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java
index 2b5799ef..34bda5e2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java
@@ -136,12 +136,12 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
@BindView(R.id.image_view_post_image_activity)
ImageView imageView;
@Inject
- @Named("no_oauth")
- Retrofit mRetrofit;
- @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
@Named("upload_media")
Retrofit mUploadMediaRetrofit;
@Inject
@@ -493,7 +493,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
- mAccessToken, mAccountName, mOauthRetrofit, iconImageUrl -> {
+ mAccessToken, mApplicationOnlyRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java
index 1f197874..17b2e887 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java
@@ -131,6 +131,9 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@Named("default")
@@ -479,7 +482,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
- mAccessToken, mAccountName, mOauthRetrofit, iconImageUrl -> {
+ mAccessToken, mApplicationOnlyRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java
index b8ff179a..740cd81f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java
@@ -154,12 +154,12 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
@BindView(R.id.option_6_text_input_layout_edit_text_post_poll_activity)
TextInputEditText option6TextInputEditText;
@Inject
- @Named("no_oauth")
- Retrofit mRetrofit;
- @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@Named("default")
@@ -529,7 +529,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
- mAccessToken, mAccountName, mOauthRetrofit, iconImageUrl -> {
+ mAccessToken, mApplicationOnlyRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
index 873d9ef5..f0d151a4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
@@ -139,12 +139,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
@BindView(R.id.markdown_bottom_bar_recycler_view_post_text_activity)
RecyclerView markdownBottomBarRecyclerView;
@Inject
- @Named("no_oauth")
- Retrofit mRetrofit;
- @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
@Named("upload_media")
Retrofit mUploadMediaRetrofit;
@Inject
@@ -486,7 +486,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
- mAccessToken, mAccountName, mOauthRetrofit, iconImageUrl -> {
+ mAccessToken, mApplicationOnlyRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java
index 0ffbe321..6ff3c081 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java
@@ -139,12 +139,12 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
@BindView(R.id.player_view_post_video_activity)
PlayerView videoPlayerView;
@Inject
- @Named("no_oauth")
- Retrofit mRetrofit;
- @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
@Named("upload_media")
Retrofit mUploadMediaRetrofit;
@Inject
@@ -512,7 +512,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
- mAccessToken, mAccountName, mOauthRetrofit, iconImageUrl -> {
+ mAccessToken, mApplicationOnlyRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
index b3005638..c10e6994 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
@@ -136,12 +136,12 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
@BindView(R.id.play_button_image_view_submit_crosspost_activity)
ImageView playButton;
@Inject
- @Named("no_oauth")
- Retrofit mRetrofit;
- @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@Named("default")
@@ -501,7 +501,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
- mAccessToken, mAccountName, mOauthRetrofit, iconImageUrl -> {
+ mAccessToken, mApplicationOnlyRetrofit, iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index fb4ecb26..03a28620 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -138,8 +138,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private final BaseActivity mActivity;
private final ViewPostDetailFragment mFragment;
private final Executor mExecutor;
- private final Retrofit mRetrofit;
private final Retrofit mOauthRetrofit;
+ private final Retrofit mApplicationOnlyRetrofit;
private final Retrofit mGfycatRetrofit;
private final Retrofit mRedgifsRetrofit;
private final Provider<StreamableAPI> mStreamableApiProvider;
@@ -224,7 +224,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public PostDetailRecyclerViewAdapter(@NonNull BaseActivity activity, ViewPostDetailFragment fragment,
Executor executor, CustomThemeWrapper customThemeWrapper,
- Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit,
+ Retrofit oauthRetrofit, Retrofit applicationOnlyRetrofit, Retrofit gfycatRetrofit,
Retrofit redgifsRetrofit, Provider<StreamableAPI> streamableApiProvider,
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
boolean separatePostAndComments, @Nullable String accessToken,
@@ -238,8 +238,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mActivity = activity;
mFragment = fragment;
mExecutor = executor;
- mRetrofit = retrofit;
mOauthRetrofit = oauthRetrofit;
+ mApplicationOnlyRetrofit = applicationOnlyRetrofit;
mGfycatRetrofit = gfycatRetrofit;
mRedgifsRetrofit = redgifsRetrofit;
mStreamableApiProvider = streamableApiProvider;
@@ -561,7 +561,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
if (mPost.getSubredditIconUrl() == null) {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(),
mRedditDataRoomDatabase, mPost.getSubredditNamePrefixed().substring(2),
- mAccessToken, mAccountName, mOauthRetrofit, iconImageUrl -> {
+ mAccessToken, mApplicationOnlyRetrofit, iconImageUrl -> {
if (iconImageUrl == null || iconImageUrl.equals("")) {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java
index 0d82746d..ab11cb68 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/LoadSubredditIcon.java
@@ -2,12 +2,11 @@ package ml.docilealligator.infinityforreddit.asynctasks;
import android.os.Handler;
-import androidx.annotation.NonNull;
-
import java.util.ArrayList;
import java.util.concurrent.Executor;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditDao;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
@@ -16,8 +15,7 @@ import retrofit2.Retrofit;
public class LoadSubredditIcon {
public static void loadSubredditIcon(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
- String subredditName, String accessToken, @NonNull String accountName,
- Retrofit oauthRetrofit,
+ String subredditName, String accessToken, Retrofit applicationOnlyOauthRetrofit,
LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener) {
executor.execute(() -> {
SubredditDao subredditDao = redditDataRoomDatabase.subredditDao();
@@ -26,21 +24,22 @@ public class LoadSubredditIcon {
String iconImageUrl = subredditDao.getSubredditData(subredditName).getIconUrl();
handler.post(() -> loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl));
} else {
- handler.post(() -> FetchSubredditData.fetchSubredditData(oauthRetrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
- @Override
- public void onFetchSubredditDataSuccess(SubredditData subredditData1, int nCurrentOnlineSubscribers) {
- ArrayList<SubredditData> singleSubredditDataList = new ArrayList<>();
- singleSubredditDataList.add(subredditData1);
- InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, accountName,
- null, null, singleSubredditDataList,
- () -> loadSubredditIconAsyncTaskListener.loadIconSuccess(subredditData1.getIconUrl()));
- }
-
- @Override
- public void onFetchSubredditDataFail(boolean isQuarantined) {
- loadSubredditIconAsyncTaskListener.loadIconSuccess(null);
- }
- }));
+ handler.post(() -> FetchSubredditData.fetchSubredditData(applicationOnlyOauthRetrofit,
+ subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
+ @Override
+ public void onFetchSubredditDataSuccess(SubredditData subredditData1, int nCurrentOnlineSubscribers) {
+ ArrayList<SubredditData> singleSubredditDataList = new ArrayList<>();
+ singleSubredditDataList.add(subredditData1);
+ InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, Account.ANONYMOUS_ACCOUNT,
+ null, null, singleSubredditDataList,
+ () -> loadSubredditIconAsyncTaskListener.loadIconSuccess(subredditData1.getIconUrl()));
+ }
+
+ @Override
+ public void onFetchSubredditDataFail(boolean isQuarantined) {
+ loadSubredditIconAsyncTaskListener.loadIconSuccess(null);
+ }
+ }));
}
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java
index dce65040..ceff2214 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java
@@ -163,6 +163,9 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
@Named("gfycat")
Retrofit mGfycatRetrofit;
@Inject
@@ -931,7 +934,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
} else {
if (isSubreddit) {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase,
- subredditOrUserName, accessToken, accountName, mOauthRetrofit,
+ subredditOrUserName, accessToken, mApplicationOnlyRetrofit,
iconImageUrl -> {
subredditOrUserIcons.put(subredditOrUserName, iconImageUrl);
loadIconListener.loadIconSuccess(subredditOrUserName, iconImageUrl);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index 22ca005f..5e3caec6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -16,7 +16,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
-import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -186,6 +185,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
@Named("gfycat")
Retrofit mGfycatRetrofit;
@Inject
@@ -1743,7 +1745,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} else {
if (isSubreddit) {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase,
- subredditOrUserName, accessToken, accountName, mOauthRetrofit,
+ subredditOrUserName, accessToken, mApplicationOnlyRetrofit,
iconImageUrl -> {
subredditOrUserIcons.put(subredditOrUserName, iconImageUrl);
loadIconListener.loadIconSuccess(subredditOrUserName, iconImageUrl);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index 4f03500d..9ac12810 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -160,6 +160,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("application_only_oauth")
+ Retrofit mApplicationOnlyRetrofit;
+ @Inject
@Named("gfycat")
Retrofit mGfycatRetrofit;
@Inject
@@ -600,8 +603,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
setupMenu();
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
- this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
- mRedgifsRetrofit, mStreamableApiProvider, mRedditDataRoomDatabase, mGlide,
+ this, mExecutor, mCustomThemeWrapper, mOauthRetrofit, mApplicationOnlyRetrofit,
+ mGfycatRetrofit, mRedgifsRetrofit, mStreamableApiProvider, mRedditDataRoomDatabase, mGlide,
mSeparatePostAndComments, mAccessToken, mAccountName, mPost, mLocale,
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
@@ -1293,7 +1296,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper,
- mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit,
+ mOauthRetrofit, mApplicationOnlyRetrofit, mGfycatRetrofit, mRedgifsRetrofit,
mStreamableApiProvider, mRedditDataRoomDatabase, mGlide, mSeparatePostAndComments,
mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences,
mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java
index ef25931a..d3032e6c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java
@@ -55,7 +55,7 @@ public class FetchPost {
call = retrofit.create(RedditAPI.class).getRandomPost();
}
- call.enqueue(new Callback<String>() {
+ call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {