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