aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2022-04-24 03:48:41 +0000
committerDocile-Alligator <chineseperson5@gmail.com>2022-04-24 03:48:41 +0000
commitd922c67ffc4cfd38efa4abf2b59531354bea242f (patch)
treef9da9e9c43b24243559e52555208d7022a18a596 /app/src/main/java/ml/docilealligator/infinityforreddit
parentbe4e73c504b55b95ac12820a4dfff131f3d0ca84 (diff)
downloadinfinity-for-reddit-d922c67ffc4cfd38efa4abf2b59531354bea242f.tar
infinity-for-reddit-d922c67ffc4cfd38efa4abf2b59531354bea242f.tar.gz
infinity-for-reddit-d922c67ffc4cfd38efa4abf2b59531354bea242f.tar.bz2
infinity-for-reddit-d922c67ffc4cfd38efa4abf2b59531354bea242f.tar.lz
infinity-for-reddit-d922c67ffc4cfd38efa4abf2b59531354bea242f.tar.xz
infinity-for-reddit-d922c67ffc4cfd38efa4abf2b59531354bea242f.tar.zst
infinity-for-reddit-d922c67ffc4cfd38efa4abf2b59531354bea242f.zip
Load selected account's subscriptions in SubredditSelectionActivity when submitting posts using another account.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java36
3 files changed, 38 insertions, 8 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java
index d40291c0..5c9d52ed 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java
@@ -15,12 +15,12 @@ import retrofit2.Response;
import retrofit2.Retrofit;
public class FetchSubscribedThing {
- public static void fetchSubscribedThing(final Retrofit retrofit, String accessToken, String accountName,
+ public static void fetchSubscribedThing(final Retrofit oauthRetrofit, String accessToken, String accountName,
final String lastItem, final ArrayList<SubscribedSubredditData> subscribedSubredditData,
final ArrayList<SubscribedUserData> subscribedUserData,
final ArrayList<SubredditData> subredditData,
final FetchSubscribedThingListener fetchSubscribedThingListener) {
- RedditAPI api = retrofit.create(RedditAPI.class);
+ RedditAPI api = oauthRetrofit.create(RedditAPI.class);
Call<String> subredditDataCall = api.getSubscribedThing(lastItem, APIUtils.getOAuthHeader(accessToken));
subredditDataCall.enqueue(new Callback<String>() {
@@ -40,7 +40,7 @@ public class FetchSubscribedThing {
fetchSubscribedThingListener.onFetchSubscribedThingSuccess(
subscribedSubredditData, subscribedUserData, subredditData);
} else {
- fetchSubscribedThing(retrofit, accessToken, accountName, lastItem,
+ fetchSubscribedThing(oauthRetrofit, accessToken, accountName, lastItem,
subscribedSubredditData, subscribedUserData, subredditData,
fetchSubscribedThingListener);
}
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 e5458540..381a4923 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
@@ -315,12 +315,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
});
iconGifImageView.setOnClickListener(view -> {
- Intent intent = new Intent(this, SubredditSelectionActivity.class);
- startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
+ subredditNameTextView.performClick();
});
subredditNameTextView.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
+ intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java
index 3578a32b..3b7700e5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java
@@ -27,6 +27,7 @@ import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.concurrent.Executor;
+import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
@@ -34,10 +35,12 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
+import ml.docilealligator.infinityforreddit.AnyAccountAccessTokenAuthenticator;
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
@@ -46,10 +49,13 @@ import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import okhttp3.ConnectionPool;
+import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
public class SubredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
+ public static final String EXTRA_SPECIFIED_ACCOUNT = "ESA";
public static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
public static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
public static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL";
@@ -68,6 +74,9 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
@BindView(R.id.toolbar_subreddit_selection_activity)
Toolbar toolbar;
@Inject
+ @Named("no_oauth")
+ Retrofit mRetrofit;
+ @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
@@ -128,9 +137,30 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
- mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
- mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
+ if (getIntent().hasExtra(EXTRA_SPECIFIED_ACCOUNT)) {
+ Account specifiedAccount = getIntent().getParcelableExtra(EXTRA_SPECIFIED_ACCOUNT);
+ if (specifiedAccount != null) {
+ mAccessToken = specifiedAccount.getAccessToken();
+ mAccountName = specifiedAccount.getAccountName();
+ mAccountProfileImageUrl = specifiedAccount.getProfileImageUrl();
+
+ mOauthRetrofit = mOauthRetrofit.newBuilder().client(new OkHttpClient.Builder().authenticator(new AnyAccountAccessTokenAuthenticator(mRetrofit, mRedditDataRoomDatabase, specifiedAccount, mCurrentAccountSharedPreferences))
+ .connectTimeout(30, TimeUnit.SECONDS)
+ .readTimeout(30, TimeUnit.SECONDS)
+ .writeTimeout(30, TimeUnit.SECONDS)
+ .connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
+ .build())
+ .build();
+ } else {
+ mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
+ mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
+ mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
+ }
+ } else {
+ mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
+ mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
+ mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
+ }
if (savedInstanceState == null) {
bindView(true);