Skip to content

Commit

Permalink
Use SubscribedThingListingActivity to select subreddits.
Browse files Browse the repository at this point in the history
  • Loading branch information
Docile-Alligator committed Sep 4, 2024
1 parent 2352b04 commit e217d62
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,11 @@ public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull R
});

binding.subredditRelativeLayoutPostGalleryActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@ protected void onCreate(Bundle savedInstanceState) {
});

binding.subredditRelativeLayoutPostImageActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,11 @@ protected void onCreate(Bundle savedInstanceState) {
});

binding.subredditRelativeLayoutPostLinkActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ protected void onCreate(Bundle savedInstanceState) {
});

binding.subredditRelativeLayoutPostPollActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ protected void onCreate(Bundle savedInstanceState) {
});

binding.subredditRelativeLayoutPostTextActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,11 @@ protected void onCreate(Bundle savedInstanceState) {
});

binding.subredditRelativeLayoutPostVideoActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ public void onDismissed(Snackbar transientBottomBar, int event) {
binding.subredditNameRelativeLayoutSearchActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_EXTRA_CLEAR_SELECTION, true);
requestThingSelectionForCurrentActivityLauncher.launch(intent);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,11 @@ public void onLoadCleared(@Nullable Drawable placeholder) {
});

binding.subredditNameTextViewSubmitCrosspostActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;
import javax.inject.Named;

import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AnyAccountAccessTokenAuthenticator;
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
Expand All @@ -67,19 +69,26 @@
import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

public class SubscribedThingListingActivity extends BaseActivity implements ActivityToolbarInterface {

public static final String EXTRA_SHOW_MULTIREDDITS = "ESM";
public static final String EXTRA_THING_SELECTION_MODE = "ETSM";
public static final String EXTRA_THING_SELECTION_TYPE = "ETST";
public static final String EXTRA_SPECIFIED_ACCOUNT = "ESA";
public static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
public static final int EXTRA_THING_SELECTION_TYPE_ALL = 0;
public static final int EXTRA_THING_SELECTION_TYPE_SUBREDDIT = 1;
public static final int EXTRA_THING_SELECTION_TYPE_USER = 2;
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
private static final String INSERT_MULTIREDDIT_STATE = "IMS";

@Inject
@Named("no_oauth")
Retrofit mRetrofit;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
Expand All @@ -100,6 +109,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
private boolean showMultiReddits;
private boolean isThingSelectionMode;
private int thingSelectionType;
private String mAccountProfileImageUrl;
private SectionsPagerAdapter sectionsPagerAdapter;
private Menu mMenu;
private ActivityResultLauncher<Intent> requestSearchThingLauncher;
Expand Down Expand Up @@ -150,6 +160,27 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(binding.toolbarSubscribedThingListingActivity);

if (getIntent().hasExtra(EXTRA_SPECIFIED_ACCOUNT)) {
Account specifiedAccount = getIntent().getParcelableExtra(EXTRA_SPECIFIED_ACCOUNT);
if (specifiedAccount != null) {
accessToken = specifiedAccount.getAccessToken();
accountName = 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 {
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
}
} else {
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
}

if (savedInstanceState != null) {
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
mInsertMultiredditSuccess = savedInstanceState.getBoolean(INSERT_MULTIREDDIT_STATE);
Expand All @@ -160,6 +191,10 @@ protected void onCreate(Bundle savedInstanceState) {
isThingSelectionMode = getIntent().getBooleanExtra(EXTRA_THING_SELECTION_MODE, false);
thingSelectionType = getIntent().getIntExtra(EXTRA_THING_SELECTION_TYPE, EXTRA_THING_SELECTION_TYPE_ALL);

if (isThingSelectionMode && thingSelectionType != EXTRA_THING_SELECTION_TYPE_ALL) {
binding.tabLayoutSubscribedThingListingActivity.setVisibility(View.GONE);
}

if (accountName.equals(Account.ANONYMOUS_ACCOUNT) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding.searchEditTextSubscribedThingListingActivity.setImeOptions(binding.searchEditTextSubscribedThingListingActivity.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
}
Expand Down Expand Up @@ -515,9 +550,9 @@ private Fragment getSubscribedSubredditListingFragment() {
SubscribedSubredditsListingFragment fragment = new SubscribedSubredditsListingFragment();
Bundle bundle = new Bundle();
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, isThingSelectionMode);
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_EXTRA_CLEAR_SELECTION, isThingSelectionMode);
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_PROFILE_IMAGE_URL,
mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null));
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_EXTRA_CLEAR_SELECTION,
isThingSelectionMode && getIntent().getBooleanExtra(EXTRA_EXTRA_CLEAR_SELECTION, false));
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_PROFILE_IMAGE_URL, mAccountProfileImageUrl);
fragment.setArguments(bundle);
return fragment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import ml.docilealligator.infinityforreddit.activities.MultiredditSelectionActivity;
import ml.docilealligator.infinityforreddit.activities.SearchActivity;
import ml.docilealligator.infinityforreddit.activities.SettingsActivity;
import ml.docilealligator.infinityforreddit.activities.SubredditSelectionActivity;
import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity;
import ml.docilealligator.infinityforreddit.databinding.FragmentCustomizeMainPageTabsBinding;
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
Expand Down Expand Up @@ -502,7 +502,10 @@ private void selectName(int tab) {
case 0:
switch (tab1CurrentPostType) {
case 3: {
Intent intent = new Intent(activity, SubredditSelectionActivity.class);
Intent intent = new Intent(activity, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, tab);
break;
}
Expand All @@ -522,7 +525,10 @@ private void selectName(int tab) {
case 1:
switch (tab2CurrentPostType) {
case 3: {
Intent intent = new Intent(activity, SubredditSelectionActivity.class);
Intent intent = new Intent(activity, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, tab);
break;
}
Expand All @@ -542,7 +548,10 @@ private void selectName(int tab) {
case 2:
switch (tab3CurrentPostType) {
case 3: {
Intent intent = new Intent(activity, SubredditSelectionActivity.class);
Intent intent = new Intent(activity, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_MODE, true);
intent.putExtra(SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE,
SubscribedThingListingActivity.EXTRA_THING_SELECTION_TYPE_SUBREDDIT);
startActivityForResult(intent, tab);
break;
}
Expand Down

0 comments on commit e217d62

Please sign in to comment.