diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-09-04 14:18:46 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-09-04 14:18:46 +0000 |
commit | 2352b0466eef62fcb5d1412d8e725447c08a3a9d (patch) | |
tree | d67cb6c6890a0d308b46368154ee15cfbf7d7f85 /app | |
parent | 651ee7437271bfd01cdd6950ec63b38edc8c4acc (diff) | |
download | infinity-for-reddit-2352b0466eef62fcb5d1412d8e725447c08a3a9d.tar infinity-for-reddit-2352b0466eef62fcb5d1412d8e725447c08a3a9d.tar.gz infinity-for-reddit-2352b0466eef62fcb5d1412d8e725447c08a3a9d.tar.bz2 infinity-for-reddit-2352b0466eef62fcb5d1412d8e725447c08a3a9d.tar.lz infinity-for-reddit-2352b0466eef62fcb5d1412d8e725447c08a3a9d.tar.xz infinity-for-reddit-2352b0466eef62fcb5d1412d8e725447c08a3a9d.tar.zst infinity-for-reddit-2352b0466eef62fcb5d1412d8e725447c08a3a9d.zip |
Preparing to use SubscribedThingListingActivity to select subreddits or users.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java | 132 |
1 files changed, 106 insertions, 26 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java index decf7d7d..a00aa2b1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -20,6 +20,7 @@ import android.widget.Toast; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.inputmethod.EditorInfoCompat; import androidx.fragment.app.Fragment; @@ -33,6 +34,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import java.util.ArrayList; +import java.util.List; import java.util.concurrent.Executor; import javax.inject.Inject; @@ -71,6 +73,10 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti 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 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"; @@ -93,6 +99,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti private boolean mInsertMultiredditSuccess; private boolean showMultiReddits; private boolean isThingSelectionMode; + private int thingSelectionType; private SectionsPagerAdapter sectionsPagerAdapter; private Menu mMenu; private ActivityResultLauncher<Intent> requestSearchThingLauncher; @@ -151,6 +158,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } isThingSelectionMode = getIntent().getBooleanExtra(EXTRA_THING_SELECTION_MODE, false); + thingSelectionType = getIntent().getIntExtra(EXTRA_THING_SELECTION_TYPE, EXTRA_THING_SELECTION_TYPE_ALL); 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); @@ -256,7 +264,13 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti if (item.getItemId() == R.id.action_search_subscribed_thing_listing_activity) { if (isThingSelectionMode) { Intent intent = new Intent(this, SearchActivity.class); - intent.putExtra(SearchActivity.EXTRA_SEARCH_SUBREDDITS_AND_USERS, true); + if (thingSelectionType == EXTRA_THING_SELECTION_TYPE_SUBREDDIT) { + intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true); + } else if (thingSelectionType == EXTRA_THING_SELECTION_TYPE_USER) { + intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_USERS, true); + } else { + intent.putExtra(SearchActivity.EXTRA_SEARCH_SUBREDDITS_AND_USERS, true); + } requestSearchThingLauncher.launch(intent); return true; } @@ -469,27 +483,56 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti @NonNull @Override public Fragment getItem(int position) { - switch (position) { - case 0: { - SubscribedSubredditsListingFragment fragment = new SubscribedSubredditsListingFragment(); - Bundle bundle = new Bundle(); - bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, false); - 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)); - fragment.setArguments(bundle); - return fragment; - } - case 1: { - FollowedUsersListingFragment fragment = new FollowedUsersListingFragment(); - Bundle bundle = new Bundle(); - bundle.putBoolean(FollowedUsersListingFragment.EXTRA_IS_USER_SELECTION, isThingSelectionMode); - fragment.setArguments(bundle); - return fragment; + if (isThingSelectionMode) { + switch (thingSelectionType) { + case EXTRA_THING_SELECTION_TYPE_SUBREDDIT: + return getSubscribedSubredditListingFragment(); + case EXTRA_THING_SELECTION_TYPE_USER: + return getFollowedUserFragment(); + default: + switch (position) { + case 0: + return getSubscribedSubredditListingFragment(); + case 1: + return getFollowedUserFragment(); + default: + return getMultiRedditListingFragment(); + } } } + switch (position) { + case 0: + return getSubscribedSubredditListingFragment(); + case 1: + return getFollowedUserFragment(); + default: + return getMultiRedditListingFragment(); + } + } + @NonNull + 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)); + fragment.setArguments(bundle); + return fragment; + } + + @NonNull + private Fragment getFollowedUserFragment() { + FollowedUsersListingFragment fragment = new FollowedUsersListingFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean(FollowedUsersListingFragment.EXTRA_IS_USER_SELECTION, isThingSelectionMode); + fragment.setArguments(bundle); + return fragment; + } + + @NonNull + private Fragment getMultiRedditListingFragment() { MultiRedditListingFragment fragment = new MultiRedditListingFragment(); Bundle bundle = new Bundle(); bundle.putBoolean(MultiRedditListingFragment.EXTRA_IS_GETTING_MULTIREDDIT_INFO, isThingSelectionMode); @@ -499,11 +542,37 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti @Override public int getCount() { - return isThingSelectionMode && Account.ANONYMOUS_ACCOUNT.equals(accountName) ? 2 : 3; + if (isThingSelectionMode) { + switch (thingSelectionType) { + case EXTRA_THING_SELECTION_TYPE_ALL: + return Account.ANONYMOUS_ACCOUNT.equals(accountName) ? 2 : 3; + case EXTRA_THING_SELECTION_TYPE_SUBREDDIT: + case EXTRA_THING_SELECTION_TYPE_USER: + return 1; + } + } + return 3; } @Override public CharSequence getPageTitle(int position) { + if (isThingSelectionMode) { + switch (thingSelectionType) { + case EXTRA_THING_SELECTION_TYPE_ALL: + switch (position) { + case 0: + return Utils.getTabTextWithCustomFont(typeface, getString(R.string.subreddits)); + case 1: + return Utils.getTabTextWithCustomFont(typeface, getString(R.string.users)); + case 2: + return Utils.getTabTextWithCustomFont(typeface, getString(R.string.multi_reddits)); + } + case EXTRA_THING_SELECTION_TYPE_SUBREDDIT: + return Utils.getTabTextWithCustomFont(typeface, getString(R.string.subreddits)); + case EXTRA_THING_SELECTION_TYPE_USER: + return Utils.getTabTextWithCustomFont(typeface, getString(R.string.users)); + } + } switch (position) { case 0: return Utils.getTabTextWithCustomFont(typeface, getString(R.string.subreddits)); @@ -546,13 +615,24 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } } + @Nullable + Fragment getCurrentFragment() { + List<Fragment> fragments = getSupportFragmentManager().getFragments(); + if (binding.viewPagerSubscribedThingListingActivity.getCurrentItem() < fragments.size()) { + return fragments.get(binding.viewPagerSubscribedThingListingActivity.getCurrentItem()); + } + + return null; + } + void goBackToTop() { - if (binding.viewPagerSubscribedThingListingActivity.getCurrentItem() == 0) { - subscribedSubredditsListingFragment.goBackToTop(); - } else if (binding.viewPagerSubscribedThingListingActivity.getCurrentItem() == 1) { - followedUsersListingFragment.goBackToTop(); - } else { - multiRedditListingFragment.goBackToTop(); + Fragment fragment = getCurrentFragment(); + if (fragment instanceof SubscribedSubredditsListingFragment) { + ((SubscribedSubredditsListingFragment) fragment).goBackToTop(); + } else if (fragment instanceof FollowedUsersListingFragment) { + ((FollowedUsersListingFragment) fragment).goBackToTop(); + } else if (fragment instanceof MultiRedditListingFragment) { + ((MultiRedditListingFragment) fragment).goBackToTop(); } } |