aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java84
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java3
-rw-r--r--app/src/main/res/layout/fragment_customize_main_page_tabs.xml13
-rw-r--r--app/src/main/res/values/strings.xml3
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<Re
private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1;
private static final int VIEW_TYPE_MENU_ITEM = 2;
private static final int VIEW_TYPE_DIVIDER = 3;
- private static final int VIEW_TYPE_SUBSCRIBED_SUBREDDIT = 4;
- private static final int VIEW_TYPE_ACCOUNT = 5;
+ private static final int VIEW_TYPE_FAVORITE_SUBSCRIBED_SUBREDDIT = 4;
+ private static final int VIEW_TYPE_SUBSCRIBED_SUBREDDIT = 5;
+ private static final int VIEW_TYPE_ACCOUNT = 6;
private static final int CURRENT_MENU_ITEMS = 17;
private AppCompatActivity appCompatActivity;
@@ -66,6 +67,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
private ItemClickListener itemClickListener;
private boolean isLoggedIn;
private boolean isInMainPage = true;
+ private ArrayList<SubscribedSubredditData> favoriteSubscribedSubreddits;
private ArrayList<SubscribedSubredditData> subscribedSubreddits;
private ArrayList<Account> accounts;
private int primaryTextColor;
@@ -94,14 +96,24 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
dividerColor = customThemeWrapper.getDividerColor();
primaryIconColor = customThemeWrapper.getPrimaryIconColor();
+ favoriteSubscribedSubreddits = new ArrayList<>();
+ 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<Re
case VIEW_TYPE_ACCOUNT:
return new AccountViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_nav_drawer_account, parent, false));
+ case VIEW_TYPE_FAVORITE_SUBSCRIBED_SUBREDDIT:
+ return new FavoriteSubscribedThingViewHolder(LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.item_nav_drawer_subscribed_thing, parent, false));
default:
return new SubscribedThingViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_nav_drawer_subscribed_thing, parent, false));
@@ -234,6 +249,12 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post);
} else if (position == 12) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_preferences);
+ } else {
+ if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS) {
+ ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.favorites);
+ } else {
+ ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.subscriptions);
+ }
}
} else if (holder instanceof MenuItemViewHolder) {
int stringId = 0;
@@ -383,8 +404,29 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
((MenuItemViewHolder) holder).itemView.setOnClickListener(view -> 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<Re
if (!(checkIsInMainPage && isInMainPage)) {
notifyItemRangeRemoved(1, getItemCount() - 1);
if (isLoggedIn) {
- if (subscribedSubreddits != null) {
- notifyItemRangeInserted(1, subscribedSubreddits.size() + CURRENT_MENU_ITEMS - 1);
- } else {
- notifyItemRangeInserted(1, CURRENT_MENU_ITEMS - 1);
- }
+ notifyItemRangeInserted(1, (favoriteSubscribedSubreddits.isEmpty() ? 0 : favoriteSubscribedSubreddits.size() + 1)
+ + (subscribedSubreddits.isEmpty() ? 0 : subscribedSubreddits.size() + 1) + CURRENT_MENU_ITEMS - 1);
} else {
notifyItemRangeInserted(1, 2);
}
@@ -453,8 +492,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
public int getItemCount() {
if (isInMainPage) {
if (isLoggedIn) {
- if (subscribedSubreddits != null) {
- return CURRENT_MENU_ITEMS + subscribedSubreddits.size();
+ if (!(favoriteSubscribedSubreddits.isEmpty() && subscribedSubreddits.isEmpty())) {
+ return CURRENT_MENU_ITEMS + (favoriteSubscribedSubreddits.isEmpty() ? 0 : favoriteSubscribedSubreddits.size() + 1)
+ + (subscribedSubreddits.isEmpty() ? 0 : subscribedSubreddits.size() + 1);
}
return CURRENT_MENU_ITEMS - 1;
} else {
@@ -485,6 +525,13 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
}
}
+ public void setFavoriteSubscribedSubreddits(List<SubscribedSubredditData> favoriteSubscribedSubreddits) {
+ this.favoriteSubscribedSubreddits = (ArrayList<SubscribedSubredditData>) favoriteSubscribedSubreddits;
+ if (isInMainPage) {
+ notifyDataSetChanged();
+ }
+ }
+
public void setSubscribedSubreddits(List<SubscribedSubredditData> subscribedSubreddits) {
this.subscribedSubreddits = (ArrayList<SubscribedSubredditData>) subscribedSubreddits;
if (isInMainPage) {
@@ -564,6 +611,19 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
}
}
+ class FavoriteSubscribedThingViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.thing_icon_gif_image_view_item_nav_drawer_subscribed_thing)
+ GifImageView iconGifImageView;
+ @BindView(R.id.thing_name_text_view_item_nav_drawer_subscribed_thing)
+ TextView subredditNameTextView;
+
+ FavoriteSubscribedThingViewHolder(@NonNull View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+ subredditNameTextView.setTextColor(primaryTextColor);
+ }
+ }
+
class SubscribedThingViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.thing_icon_gif_image_view_item_nav_drawer_subscribed_thing)
GifImageView iconGifImageView;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
index 1dbb9a4e..bdc19942 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
@@ -99,6 +99,8 @@ public class CustomizeMainPageTabsFragment extends Fragment {
View divider4;
@BindView(R.id.more_tabs_group_summary_customize_main_page_tabs_fragment)
TextView moreTabsGroupSummaryTextView;
+ @BindView(R.id.more_tabs_info_text_view_customize_main_page_tabs_fragment)
+ TextView moreTabsInfoTextView;
@BindView(R.id.show_subscribed_subreddits_linear_layout_customize_main_page_tabs_fragment)
LinearLayout showSubscribedSubredditsLinearLayout;
@BindView(R.id.show_subscribed_subreddits_switch_material_customize_main_page_tabs_fragment)
@@ -156,6 +158,7 @@ public class CustomizeMainPageTabsFragment extends Fragment {
tab3TypeLinearLayout.setVisibility(View.GONE);
divider4.setVisibility(View.GONE);
moreTabsGroupSummaryTextView.setVisibility(View.GONE);
+ moreTabsInfoTextView.setVisibility(View.GONE);
showSubscribedSubredditsLinearLayout.setVisibility(View.GONE);
showFavoriteSubscribedSubredditsLinearLayout.setVisibility(View.GONE);
diff --git a/app/src/main/res/layout/fragment_customize_main_page_tabs.xml b/app/src/main/res/layout/fragment_customize_main_page_tabs.xml
index c9991b92..f20ec4d3 100644
--- a/app/src/main/res/layout/fragment_customize_main_page_tabs.xml
+++ b/app/src/main/res/layout/fragment_customize_main_page_tabs.xml
@@ -447,6 +447,19 @@
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" />
+ <TextView
+ android:id="@+id/more_tabs_info_text_view_customize_main_page_tabs_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="16dp"
+ android:drawablePadding="32dp"
+ android:text="@string/settings_more_tabs_info_summary"
+ android:textColor="@color/settingsSubtitleColor"
+ android:gravity="center_vertical"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family"
+ app:drawableStartCompat="@drawable/ic_info_preference_24dp" />
+
<LinearLayout
android:id="@+id/show_favorite_subscribed_subreddits_linear_layout_customize_main_page_tabs_fragment"
android:layout_width="match_parent"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b0341de1..5a30de5a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -341,7 +341,7 @@
<string name="settings_start_autoplay_visible_area_offset_landscape_title">Autoplay Videos Visible Area Offset (Landscape)</string>
<string name="settings_start_autoplay_visible_area_offset_landscape_summary">Start autoplaying videos when %1$d%% of them are visible</string>
<string name="settings_immersive_interface_title">Immersive Interface</string>
- <string name="settings_immersive_interface_summary">Does Not Apply to All Pages\nMay Not Work On Android 11</string>
+ <string name="settings_immersive_interface_summary">Does Not Apply to All Pages</string>
<string name="settings_immersive_interface_ignore_nav_bar_title">Ignore Navigation Bar in Immersive Interface</string>
<string name="settings_immersive_interface_ignore_nav_bar_summary">Prevent the Bottom Navigation Bar Having Extra Padding</string>
<string name="settings_customize_tabs_in_main_page_title">Customize Tabs in Main Page</string>
@@ -453,6 +453,7 @@
<string name="settings_tab_2_summary">Tab 2</string>
<string name="settings_tab_3_summary">Tab 3</string>
<string name="settings_more_tabs_summary">More Tabs</string>
+ <string name="settings_more_tabs_info_summary">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.</string>
<string name="settings_more_tabs_show_favorite_subscribed_subreddits_title">Show Favorite Subscribed Subreddits</string>
<string name="settings_more_tabs_show_subscribed_subreddits_title">Show Subscribed Subreddits</string>
<string name="settings_tab_title">Title</string>