aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-09-24 11:01:54 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-09-24 11:01:54 +0000
commit0c251c972c61867f7ebe802390df2ace9c19761f (patch)
treeabb29b4b1731f84ac507c7fec0f0a42d57d9221b /app/src
parentd6051ca932a234da18dcd9eb351be741d085c9d4 (diff)
downloadinfinity-for-reddit-0c251c972c61867f7ebe802390df2ace9c19761f.tar
infinity-for-reddit-0c251c972c61867f7ebe802390df2ace9c19761f.tar.gz
infinity-for-reddit-0c251c972c61867f7ebe802390df2ace9c19761f.tar.bz2
infinity-for-reddit-0c251c972c61867f7ebe802390df2ace9c19761f.tar.lz
infinity-for-reddit-0c251c972c61867f7ebe802390df2ace9c19761f.tar.xz
infinity-for-reddit-0c251c972c61867f7ebe802390df2ace9c19761f.tar.zst
infinity-for-reddit-0c251c972c61867f7ebe802390df2ace9c19761f.zip
Support showing favorite subscribed subreddits in the main page.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java50
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/layout/fragment_customize_main_page_tabs.xml31
-rw-r--r--app/src/main/res/values/strings.xml1
5 files changed, 82 insertions, 13 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 be8799c6..6dd98c4c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
@@ -206,6 +206,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private boolean mConfirmToExit;
private boolean mLockBottomAppBar;
private boolean mDisableSwipingBetweenTabs;
+ private boolean mShowFavoriteSubscribedSubreddits;
private boolean mShowSubscribedSubreddits;
@Override
@@ -602,13 +603,15 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
navDrawerRecyclerView.setAdapter(adapter);
int tabCount = mMainActivityTabsSharedPreferences.getInt((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_COUNT, 3);
+ mShowFavoriteSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false);
mShowSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false);
- sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle(), tabCount, mShowSubscribedSubreddits);
+ sectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager, getLifecycle(), tabCount,
+ mShowFavoriteSubscribedSubreddits, mShowSubscribedSubreddits);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(1);
viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs);
if (mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_TAB_NAMES, true)) {
- if (mShowSubscribedSubreddits) {
+ if (mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) {
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
} else {
tabLayout.setTabMode(TabLayout.MODE_FIXED);
@@ -635,10 +638,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)));
break;
}
- if (position >= tabCount && mShowSubscribedSubreddits && sectionsPagerAdapter != null) {
+ if (position >= tabCount && (mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) && sectionsPagerAdapter != null) {
+ List<SubscribedSubredditData> favoriteSubscribedSubreddits = sectionsPagerAdapter.favoriteSubscribedSubreddits;
List<SubscribedSubredditData> subscribedSubreddits = sectionsPagerAdapter.subscribedSubreddits;
- if (position - tabCount < subscribedSubreddits.size()) {
- tab.setText(subscribedSubreddits.get(position - tabCount).getName());
+ if (position - tabCount < favoriteSubscribedSubreddits.size()) {
+ tab.setText(favoriteSubscribedSubreddits.get(position - tabCount).getName());
+ } else if (position - tabCount - favoriteSubscribedSubreddits.size() < subscribedSubreddits.size()) {
+ tab.setText(subscribedSubreddits.get(position - tabCount - favoriteSubscribedSubreddits.size()).getName());
}
}
}
@@ -672,6 +678,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
sectionsPagerAdapter.setSubscribedSubreddits(subscribedSubredditData);
}
});
+ if (mShowFavoriteSubscribedSubreddits) {
+ subscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(this, subscribedSubredditData -> {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.setFavoriteSubscribedSubreddits(subscribedSubredditData);
+ }
+ });
+ }
accountViewModel = new ViewModelProvider(this,
new AccountViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)).get(AccountViewModel.class);
@@ -1003,13 +1016,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private class SectionsPagerAdapter extends FragmentStateAdapter {
int tabCount;
+ boolean showFavoriteSubscribedSubreddits;
boolean showSubscribedSubreddits;
+ List<SubscribedSubredditData> favoriteSubscribedSubreddits;
List<SubscribedSubredditData> subscribedSubreddits;
- SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle, int tabCount, boolean showSubscribedSubreddits) {
+ SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle, int tabCount, boolean showFavoriteSubscribedSubreddits, boolean showSubscribedSubreddits) {
super(fm, lifecycle);
this.tabCount = tabCount;
+ favoriteSubscribedSubreddits = new ArrayList<>();
subscribedSubreddits = new ArrayList<>();
+ this.showFavoriteSubscribedSubreddits = showFavoriteSubscribedSubreddits;
this.showSubscribedSubreddits = showSubscribedSubreddits;
}
@@ -1049,10 +1066,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
String name = mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, "");
return generatePostFragment(postType, name);
} else {
+ if (showFavoriteSubscribedSubreddits) {
+ if (position >= tabCount && position - tabCount < favoriteSubscribedSubreddits.size()) {
+ int postType = SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT;
+ String name = favoriteSubscribedSubreddits.get(position - tabCount).getName();
+ return generatePostFragment(postType, name);
+ }
+ }
if (showSubscribedSubreddits) {
- if (position >= tabCount && position - tabCount < subscribedSubreddits.size()) {
+ if (position >= tabCount && position - tabCount - favoriteSubscribedSubreddits.size() < subscribedSubreddits.size()) {
int postType = SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT;
- String name = subscribedSubreddits.get(position - tabCount).getName();
+ String name = subscribedSubreddits.get(position - tabCount - favoriteSubscribedSubreddits.size()).getName();
return generatePostFragment(postType, name);
}
}
@@ -1062,6 +1086,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
}
+ public void setFavoriteSubscribedSubreddits(List<SubscribedSubredditData> favoriteSubscribedSubreddits) {
+ this.favoriteSubscribedSubreddits = favoriteSubscribedSubreddits;
+ notifyDataSetChanged();
+ }
+
public void setSubscribedSubreddits(List<SubscribedSubredditData> subscribedSubreddits) {
this.subscribedSubreddits = subscribedSubreddits;
notifyDataSetChanged();
@@ -1136,10 +1165,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
if (mAccessToken == null) {
return 2;
}
- if (showSubscribedSubreddits) {
- return tabCount + subscribedSubreddits.size();
- }
- return tabCount;
+ return tabCount + favoriteSubscribedSubreddits.size() + subscribedSubreddits.size();
}
@Nullable
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 a07ad3c4..1dbb9a4e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
@@ -103,6 +103,10 @@ public class CustomizeMainPageTabsFragment extends Fragment {
LinearLayout showSubscribedSubredditsLinearLayout;
@BindView(R.id.show_subscribed_subreddits_switch_material_customize_main_page_tabs_fragment)
SwitchMaterial showSubscribedSubredditsSwitchMaterial;
+ @BindView(R.id.show_favorite_subscribed_subreddits_linear_layout_customize_main_page_tabs_fragment)
+ LinearLayout showFavoriteSubscribedSubredditsLinearLayout;
+ @BindView(R.id.show_favorite_subscribed_subreddits_switch_material_customize_main_page_tabs_fragment)
+ SwitchMaterial showFavoriteSubscribedSubredditsSwitchMaterial;
@Inject
@Named("main_activity_tabs")
SharedPreferences sharedPreferences;
@@ -153,7 +157,7 @@ public class CustomizeMainPageTabsFragment extends Fragment {
divider4.setVisibility(View.GONE);
moreTabsGroupSummaryTextView.setVisibility(View.GONE);
showSubscribedSubredditsLinearLayout.setVisibility(View.GONE);
- showSubscribedSubredditsSwitchMaterial.setVisibility(View.GONE);
+ showFavoriteSubscribedSubredditsLinearLayout.setVisibility(View.GONE);
return rootView;
}
@@ -482,6 +486,12 @@ public class CustomizeMainPageTabsFragment extends Fragment {
showSubscribedSubredditsSwitchMaterial.performClick();
});
+ showFavoriteSubscribedSubredditsSwitchMaterial.setChecked(sharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false));
+ showFavoriteSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> sharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, b).apply());
+ showFavoriteSubscribedSubredditsLinearLayout.setOnClickListener(view -> {
+ showFavoriteSubscribedSubredditsSwitchMaterial.performClick();
+ });
+
return rootView;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
index fd5e9a47..8d08c696 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -149,6 +149,7 @@ public class SharedPreferencesUtils {
public static final int MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT = 4;
public static final int MAIN_PAGE_TAB_POST_TYPE_USER = 5;
public static final String MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS = "_main_page_show_subscribed_subreddits";
+ public static final String MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS = "_main_page_show_favorite_subscribed_subreddits";
public static final String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler";
public static final String NSFW_BASE = "_nsfw";
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 9a91549a..c9991b92 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
@@ -448,6 +448,37 @@
android:fontFamily="?attr/font_family" />
<LinearLayout
+ android:id="@+id/show_favorite_subscribed_subreddits_linear_layout_customize_main_page_tabs_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="4dp"
+ android:paddingBottom="4dp"
+ android:paddingStart="72dp"
+ android:paddingEnd="16dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground">
+
+ <TextView
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_marginEnd="16dp"
+ android:layout_gravity="center_vertical"
+ android:text="@string/settings_more_tabs_show_favorite_subscribed_subreddits_title"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_16"
+ android:fontFamily="?attr/font_family" />
+
+ <com.google.android.material.switchmaterial.SwitchMaterial
+ android:id="@+id/show_favorite_subscribed_subreddits_switch_material_customize_main_page_tabs_fragment"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical" />
+
+ </LinearLayout>
+
+ <LinearLayout
android:id="@+id/show_subscribed_subreddits_linear_layout_customize_main_page_tabs_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 45212b52..b0341de1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -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_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>
<string name="settings_tab_post_type">Type</string>