From 73c4ead2c05609b20bd1a6cabb45f4fe61a9b042 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 24 Sep 2020 22:27:05 +0800 Subject: [PATCH] Add favorite subreddits to the navigation drawer. Add favorite and subscriptions header to the navigation drawer. --- .../Activity/MainActivity.java | 13 ++- .../NavigationDrawerRecyclerViewAdapter.java | 84 ++++++++++++++++--- .../CustomizeMainPageTabsFragment.java | 3 + .../fragment_customize_main_page_tabs.xml | 13 +++ app/src/main/res/values/strings.xml | 3 +- 5 files changed, 96 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 6dd98c4c..4387387b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -678,13 +678,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb sectionsPagerAdapter.setSubscribedSubreddits(subscribedSubredditData); } }); - if (mShowFavoriteSubscribedSubreddits) { - subscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(this, subscribedSubredditData -> { - if (sectionsPagerAdapter != null) { - sectionsPagerAdapter.setFavoriteSubscribedSubreddits(subscribedSubredditData); - } - }); - } + subscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(this, subscribedSubredditData -> { + adapter.setFavoriteSubscribedSubreddits(subscribedSubredditData); + if (mShowFavoriteSubscribedSubreddits && sectionsPagerAdapter != null) { + sectionsPagerAdapter.setFavoriteSubscribedSubreddits(subscribedSubredditData); + } + }); accountViewModel = new ViewModelProvider(this, new AccountViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)).get(AccountViewModel.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java index 088a576c..d8147480 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java @@ -50,8 +50,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter favoriteSubscribedSubreddits; private ArrayList subscribedSubreddits; private ArrayList accounts; private int primaryTextColor; @@ -94,14 +96,24 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter(); + subscribedSubreddits = new ArrayList<>(); } @Override public int getItemViewType(int position) { if (isInMainPage) { if (isLoggedIn) { - if (position >= CURRENT_MENU_ITEMS) { - return VIEW_TYPE_SUBSCRIBED_SUBREDDIT; + if (position == CURRENT_MENU_ITEMS) { + return VIEW_TYPE_MENU_GROUP_TITLE; + } else if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS + favoriteSubscribedSubreddits.size() + 1) { + return VIEW_TYPE_MENU_GROUP_TITLE; + } else if (position > CURRENT_MENU_ITEMS) { + if (!favoriteSubscribedSubreddits.isEmpty() && position <= CURRENT_MENU_ITEMS + favoriteSubscribedSubreddits.size()) { + return VIEW_TYPE_FAVORITE_SUBSCRIBED_SUBREDDIT; + } else { + return VIEW_TYPE_SUBSCRIBED_SUBREDDIT; + } } else if (position == 0) { return VIEW_TYPE_NAV_HEADER; } else if (position == 1 || position == 6 || position == 12) { @@ -153,6 +165,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter itemClickListener.onMenuClick(finalStringId)); } } + } else if (holder instanceof FavoriteSubscribedThingViewHolder) { + SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.get(position - CURRENT_MENU_ITEMS - 1); + String subredditName = subreddit.getName(); + String iconUrl = subreddit.getIconUrl(); + ((FavoriteSubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName); + if (iconUrl != null && !iconUrl.equals("")) { + glide.load(iconUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((FavoriteSubscribedThingViewHolder) holder).iconGifImageView); + } else { + glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((FavoriteSubscribedThingViewHolder) holder).iconGifImageView); + } + + ((FavoriteSubscribedThingViewHolder) holder).itemView.setOnClickListener(view -> { + itemClickListener.onSubscribedSubredditClick(subredditName); + }); } else if (holder instanceof SubscribedThingViewHolder) { - SubscribedSubredditData subreddit = subscribedSubreddits.get(position - CURRENT_MENU_ITEMS); + SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.isEmpty() ? subscribedSubreddits.get(position - CURRENT_MENU_ITEMS - 1) + : subscribedSubreddits.get(position - CURRENT_MENU_ITEMS - favoriteSubscribedSubreddits.size() - 2); String subredditName = subreddit.getName(); String iconUrl = subreddit.getIconUrl(); ((SubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName); @@ -418,11 +460,8 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter favoriteSubscribedSubreddits) { + this.favoriteSubscribedSubreddits = (ArrayList) favoriteSubscribedSubreddits; + if (isInMainPage) { + notifyDataSetChanged(); + } + } + public void setSubscribedSubreddits(List subscribedSubreddits) { this.subscribedSubreddits = (ArrayList) subscribedSubreddits; if (isInMainPage) { @@ -564,6 +611,19 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter + + Autoplay Videos Visible Area Offset (Landscape) Start autoplaying videos when %1$d%% of them are visible Immersive Interface - Does Not Apply to All Pages\nMay Not Work On Android 11 + Does Not Apply to All Pages Ignore Navigation Bar in Immersive Interface Prevent the Bottom Navigation Bar Having Extra Padding Customize Tabs in Main Page @@ -453,6 +453,7 @@ Tab 2 Tab 3 More Tabs + Enabling the following options will cause an unintended behaviour:\nTabs may lose all the content after switching to others. This is the same as refreshing the page. Show Favorite Subscribed Subreddits Show Subscribed Subreddits Title