mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
Load selected account's subscriptions in SubredditSelectionActivity when submitting posts using another account.
This commit is contained in:
parent
be4e73c504
commit
d922c67ffc
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user