From 32e0ff24e1fa06420abb18645dff7e68c4e576b9 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 17 Jul 2021 23:14:32 +0800 Subject: Add Reddit section in the navigation drawer. --- .../infinityforreddit/activities/MainActivity.java | 4 + .../NavigationDrawerRecyclerViewAdapter.java | 147 +++++++++++++++------ .../utils/SharedPreferencesUtils.java | 1 + 3 files changed, 109 insertions(+), 43 deletions(-) (limited to 'app/src/main/java/ml') 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 3b62cd49..6bb41682 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -754,6 +754,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } else if (stringId == R.string.multi_reddit) { intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); + } else if (stringId == R.string.rpan) { + intent = new Intent(MainActivity.this, RPANActivity.class); + } else if (stringId == R.string.trending) { + } else if (stringId == R.string.upvoted) { intent = new Intent(MainActivity.this, AccountPostsActivity.class); intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_UPVOTED); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java index 863b2da3..664f2689 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java @@ -56,8 +56,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter CURRENT_MENU_ITEMS - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0) + - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0) - (collapsePostSection ? POST_SECTION_ITEMS : 0) - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) { if (!favoriteSubscribedSubreddits.isEmpty() && !hideFavoriteSubredditsSection && !collapseFavoriteSubredditsSection && position <= CURRENT_MENU_ITEMS - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0) + - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0) - (collapsePostSection ? POST_SECTION_ITEMS : 0) - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0) + favoriteSubscribedSubreddits.size()) { @@ -152,11 +159,17 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { + holder.itemView.setOnClickListener(view -> { if (isInMainPage) { if (requireAuthToAccountSection) { BiometricManager biometricManager = BiometricManager.from(appCompatActivity); @@ -301,15 +312,27 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { + holder.itemView.setOnClickListener(view -> { switch (type) { case 0: if (collapseAccountSection) { @@ -353,6 +377,15 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter REDDIT_SECTION_ITEMS + 2) { + pseudoPosition += ACCOUNT_SECTION_ITEMS + POST_SECTION_ITEMS; + } + } else if (collapseRedditSection && collapsePostSection) { + if (position > ACCOUNT_SECTION_ITEMS + 1) { + pseudoPosition += REDDIT_SECTION_ITEMS + POST_SECTION_ITEMS; + } } else if (collapseAccountSection) { pseudoPosition += ACCOUNT_SECTION_ITEMS; - } else if (collapsePostSection) { + } else if (collapseRedditSection) { if (position > ACCOUNT_SECTION_ITEMS + 1) { + pseudoPosition += REDDIT_SECTION_ITEMS; + } + } else if (collapsePostSection) { + if (position > ACCOUNT_SECTION_ITEMS + REDDIT_SECTION_ITEMS + 2) { pseudoPosition += POST_SECTION_ITEMS; } } @@ -431,32 +476,40 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { + holder.itemView.setOnClickListener(view -> { Intent intent = new Intent(appCompatActivity, InboxActivity.class); appCompatActivity.startActivity(intent); }); break; case 7: + stringId = R.string.rpan; + drawableId = R.drawable.ic_rpan_24dp; + break; + case 8: + stringId = R.string.trending; + drawableId = R.drawable.ic_trending_24dp; + break; + case 10: stringId = R.string.upvoted; drawableId = R.drawable.ic_arrow_upward_black_24dp; break; - case 8: + case 11: stringId = R.string.downvoted; drawableId = R.drawable.ic_arrow_downward_black_24dp; break; - case 9: + case 12: stringId = R.string.hidden; drawableId = R.drawable.ic_outline_lock_24dp; break; - case 10: + case 13: stringId = R.string.account_saved_thing_activity_label; drawableId = R.drawable.ic_outline_bookmarks_24dp; break; - case 11: + case 14: stringId = R.string.gilded; drawableId = R.drawable.ic_star_border_24dp; break; - case 13: + case 16: if ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { stringId = R.string.dark_theme; drawableId = R.drawable.ic_dark_theme_24dp; @@ -465,7 +518,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { + holder.itemView.setOnClickListener(view -> { if (isNSFWEnabled) { isNSFWEnabled = false; ((MenuItemViewHolder) holder).menuTextView.setText(R.string.enable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(appCompatActivity.getDrawable(R.drawable.ic_nsfw_on_24dp)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_on_24dp)); itemClickListener.onMenuClick(R.string.disable_nsfw); } else { isNSFWEnabled = true; ((MenuItemViewHolder) holder).menuTextView.setText(R.string.disable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(appCompatActivity.getDrawable(R.drawable.ic_nsfw_off_24dp)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_off_24dp)); itemClickListener.onMenuClick(R.string.enable_nsfw); } }); break; - case 15: + case 18: stringId = R.string.settings; drawableId = R.drawable.ic_settings_24dp; } @@ -518,16 +571,16 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { + holder.itemView.setOnClickListener(view -> { if (isNSFWEnabled) { isNSFWEnabled = false; ((MenuItemViewHolder) holder).menuTextView.setText(R.string.enable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(appCompatActivity.getDrawable(R.drawable.ic_nsfw_on_24dp)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_on_24dp)); itemClickListener.onMenuClick(R.string.disable_nsfw); } else { isNSFWEnabled = true; ((MenuItemViewHolder) holder).menuTextView.setText(R.string.disable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(appCompatActivity.getDrawable(R.drawable.ic_nsfw_off_24dp)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_off_24dp)); itemClickListener.onMenuClick(R.string.enable_nsfw); } }); @@ -558,15 +611,16 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter itemClickListener.onMenuClick(finalStringId)); + holder.itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId)); } } } else if (holder instanceof FavoriteSubscribedThingViewHolder) { SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.get(position - (CURRENT_MENU_ITEMS - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0) + - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0) - (collapsePostSection ? POST_SECTION_ITEMS : 0) - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) - 1); @@ -585,17 +639,19 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { + holder.itemView.setOnClickListener(view -> { itemClickListener.onSubscribedSubredditClick(subredditName); }); } else if (holder instanceof SubscribedThingViewHolder) { SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.isEmpty() || hideFavoriteSubredditsSection ? subscribedSubreddits.get(position - (CURRENT_MENU_ITEMS - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0) + - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0) - (collapsePostSection ? POST_SECTION_ITEMS : 0) - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) - 1) : subscribedSubreddits.get(position - (CURRENT_MENU_ITEMS - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0) + - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0) - (collapsePostSection ? POST_SECTION_ITEMS : 0) - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) - (collapseFavoriteSubredditsSection ? 0 : favoriteSubscribedSubreddits.size()) @@ -615,7 +671,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { + holder.itemView.setOnClickListener(view -> { itemClickListener.onSubscribedSubredditClick(subredditName); }); } else if (holder instanceof AccountViewHolder) { @@ -624,7 +680,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter + holder.itemView.setOnClickListener(view -> itemClickListener.onAccountClick(accounts.get(position - 1).getAccountName())); } } @@ -669,18 +725,21 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter