From cf4395ed5c972453c225d72c436e189f362656b4 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 13 May 2020 12:51:44 +0800 Subject: [PATCH] Customize tabs in main page for logged-in users. --- .../Activity/MainActivity.java | 194 +++++++++++------- .../infinityforreddit/AppComponent.java | 3 + .../CustomizeMainPageTabsFragment.java | 174 ++++++++++++++++ .../Utils/SharedPreferencesUtils.java | 15 ++ app/src/main/res/values/arrays.xml | 18 ++ app/src/main/res/values/strings.xml | 16 +- .../customize_main_page_tabs_preferences.xml | 76 +++++++ app/src/main/res/xml/interface_preference.xml | 5 + 8 files changed, 425 insertions(+), 76 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java create mode 100644 app/src/main/res/xml/customize_main_page_tabs_preferences.xml 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 ca7e42d2..8f773a69 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -922,9 +922,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } private class SectionsPagerAdapter extends FragmentPagerAdapter { - private PostFragment frontPagePostFragment; - private PostFragment popularPostFragment; - private PostFragment allPostFragment; + private PostFragment tab1; + private PostFragment tab2; + private PostFragment tab3; SectionsPagerAdapter(FragmentManager fm) { super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); @@ -956,6 +956,22 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } if (position == 0) { + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + String name = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, ""); + return generatePostFragment(postType, name); + } else if (position == 1) { + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + String name = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, ""); + return generatePostFragment(postType, name); + } else { + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + String name = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, ""); + return generatePostFragment(postType, name); + } + } + + private Fragment generatePostFragment(String postType, String name) { + if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME)) { PostFragment fragment = new PostFragment(); Bundle bundle = new Bundle(); bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE); @@ -963,11 +979,39 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); fragment.setArguments(bundle); return fragment; - } else if (position == 1) { + } else if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL)) { PostFragment fragment = new PostFragment(); Bundle bundle = new Bundle(); bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); - bundle.putString(PostFragment.EXTRA_NAME, "popular"); + bundle.putString(PostFragment.EXTRA_NAME, "all"); + bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); + bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + fragment.setArguments(bundle); + return fragment; + } else if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT)) { + PostFragment fragment = new PostFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); + bundle.putString(PostFragment.EXTRA_NAME, name); + bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); + bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + fragment.setArguments(bundle); + return fragment; + } else if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT)) { + PostFragment fragment = new PostFragment(); + Bundle bundle = new Bundle(); + bundle.putString(PostFragment.EXTRA_NAME, name); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_MULTI_REDDIT); + bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); + bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + fragment.setArguments(bundle); + return fragment; + } else if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER)) { + PostFragment fragment = new PostFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER); + bundle.putString(PostFragment.EXTRA_USER_NAME, name); + bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SUBMITTED); bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); fragment.setArguments(bundle); @@ -976,7 +1020,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb PostFragment fragment = new PostFragment(); Bundle bundle = new Bundle(); bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); - bundle.putString(PostFragment.EXTRA_NAME, "all"); + bundle.putString(PostFragment.EXTRA_NAME, "popular"); bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); fragment.setArguments(bundle); @@ -1004,11 +1048,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } else { switch (position) { case 0: - return "Home"; + return mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home)); case 1: - return "Popular"; + return mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular)); case 2: - return "All"; + return mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)); } } return null; @@ -1021,21 +1065,21 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (position) { case 0: - popularPostFragment = (PostFragment) fragment; + tab2 = (PostFragment) fragment; break; case 1: - allPostFragment = (PostFragment) fragment; + tab3 = (PostFragment) fragment; } } else { switch (position) { case 0: - frontPagePostFragment = (PostFragment) fragment; + tab1 = (PostFragment) fragment; break; case 1: - popularPostFragment = (PostFragment) fragment; + tab2 = (PostFragment) fragment; break; case 2: - allPostFragment = (PostFragment) fragment; + tab3 = (PostFragment) fragment; } } return fragment; @@ -1045,18 +1089,18 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (viewPager.getCurrentItem()) { case 0: - return popularPostFragment.handleKeyDown(keyCode); + return tab2.handleKeyDown(keyCode); case 1: - return allPostFragment.handleKeyDown(keyCode); + return tab3.handleKeyDown(keyCode); } } else { switch (viewPager.getCurrentItem()) { case 0: - return frontPagePostFragment.handleKeyDown(keyCode); + return tab1.handleKeyDown(keyCode); case 1: - return popularPostFragment.handleKeyDown(keyCode); + return tab2.handleKeyDown(keyCode); case 2: - return allPostFragment.handleKeyDown(keyCode); + return tab3.handleKeyDown(keyCode); } } return false; @@ -1066,18 +1110,18 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (viewPager.getCurrentItem()) { case 0: - return popularPostFragment.startLazyMode(); + return tab2.startLazyMode(); case 1: - return allPostFragment.startLazyMode(); + return tab3.startLazyMode(); } } else { switch (viewPager.getCurrentItem()) { case 0: - return frontPagePostFragment.startLazyMode(); + return tab1.startLazyMode(); case 1: - return popularPostFragment.startLazyMode(); + return tab2.startLazyMode(); case 2: - return allPostFragment.startLazyMode(); + return tab3.startLazyMode(); } } @@ -1088,22 +1132,22 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (getCurrentLazyModeFragmentPosition()) { case 0: - popularPostFragment.stopLazyMode(); + tab2.stopLazyMode(); break; case 1: - allPostFragment.stopLazyMode(); + tab3.stopLazyMode(); break; } } else { switch (getCurrentLazyModeFragmentPosition()) { case 0: - frontPagePostFragment.stopLazyMode(); + tab1.stopLazyMode(); break; case 1: - popularPostFragment.stopLazyMode(); + tab2.stopLazyMode(); break; case 2: - allPostFragment.stopLazyMode(); + tab3.stopLazyMode(); break; } } @@ -1113,22 +1157,22 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (getCurrentLazyModeFragmentPosition()) { case 0: - popularPostFragment.resumeLazyMode(false); + tab2.resumeLazyMode(false); break; case 1: - allPostFragment.resumeLazyMode(false); + tab3.resumeLazyMode(false); break; } } else { switch (getCurrentLazyModeFragmentPosition()) { case 0: - frontPagePostFragment.resumeLazyMode(false); + tab1.resumeLazyMode(false); break; case 1: - popularPostFragment.resumeLazyMode(false); + tab2.resumeLazyMode(false); break; case 2: - allPostFragment.resumeLazyMode(false); + tab3.resumeLazyMode(false); break; } } @@ -1138,21 +1182,21 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (getCurrentLazyModeFragmentPosition()) { case 0: - popularPostFragment.pauseLazyMode(false); + tab2.pauseLazyMode(false); break; case 1: - allPostFragment.pauseLazyMode(false); + tab3.pauseLazyMode(false); } } else { switch (getCurrentLazyModeFragmentPosition()) { case 0: - frontPagePostFragment.pauseLazyMode(false); + tab1.pauseLazyMode(false); break; case 1: - popularPostFragment.pauseLazyMode(false); + tab2.pauseLazyMode(false); break; case 2: - allPostFragment.pauseLazyMode(false); + tab3.pauseLazyMode(false); } } } @@ -1161,9 +1205,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { if (!isInLazyMode) { return -1; - } else if (popularPostFragment != null && popularPostFragment.isInLazyMode()) { + } else if (tab2 != null && tab2.isInLazyMode()) { return 0; - } else if (allPostFragment != null && allPostFragment.isInLazyMode()) { + } else if (tab3 != null && tab3.isInLazyMode()) { return 1; } else { return -1; @@ -1171,11 +1215,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } else { if (!isInLazyMode) { return -1; - } else if (frontPagePostFragment != null && frontPagePostFragment.isInLazyMode()) { + } else if (tab1 != null && tab1.isInLazyMode()) { return 0; - } else if (popularPostFragment != null && popularPostFragment.isInLazyMode()) { + } else if (tab2 != null && tab2.isInLazyMode()) { return 1; - } else if (allPostFragment != null && allPostFragment.isInLazyMode()) { + } else if (tab3 != null && tab3.isInLazyMode()) { return 2; } else { return -1; @@ -1186,9 +1230,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb void changeSortType(SortType sortType) { if (mAccessToken == null) { if (viewPager.getCurrentItem() == 0) { - popularPostFragment.changeSortType(sortType); + tab2.changeSortType(sortType); } else { - allPostFragment.changeSortType(sortType); + tab3.changeSortType(sortType); } } else { switch (viewPager.getCurrentItem()) { @@ -1198,7 +1242,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply(); } - frontPagePostFragment.changeSortType(sortType); + tab1.changeSortType(sortType); break; case 1: mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, sortType.getType().name()).apply(); @@ -1206,7 +1250,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, sortType.getTime().name()).apply(); } - popularPostFragment.changeSortType(sortType); + tab2.changeSortType(sortType); break; case 2: mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, sortType.getType().name()).apply(); @@ -1214,7 +1258,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_ALL_POST, sortType.getTime().name()).apply(); } - allPostFragment.changeSortType(sortType); + tab3.changeSortType(sortType); } } } @@ -1222,77 +1266,77 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb public void refresh() { if (mAccessToken == null) { if (viewPager.getCurrentItem() == 0) { - if (popularPostFragment != null) { - popularPostFragment.refresh(); + if (tab2 != null) { + tab2.refresh(); } } else { - if (allPostFragment != null) { - allPostFragment.refresh(); + if (tab3 != null) { + tab3.refresh(); } } } else { switch (viewPager.getCurrentItem()) { case 0: - if (frontPagePostFragment != null) { - frontPagePostFragment.refresh(); + if (tab1 != null) { + tab1.refresh(); } break; case 1: - if (popularPostFragment != null) { - popularPostFragment.refresh(); + if (tab2 != null) { + tab2.refresh(); } break; case 2: - if (allPostFragment != null) { - allPostFragment.refresh(); + if (tab3 != null) { + tab3.refresh(); } } } } void changeNSFW(boolean nsfw) { - if (frontPagePostFragment != null) { - frontPagePostFragment.changeNSFW(nsfw); + if (tab1 != null) { + tab1.changeNSFW(nsfw); } - if (popularPostFragment != null) { - popularPostFragment.changeNSFW(nsfw); + if (tab2 != null) { + tab2.changeNSFW(nsfw); } - if (allPostFragment != null) { - allPostFragment.changeNSFW(nsfw); + if (tab3 != null) { + tab3.changeNSFW(nsfw); } } void changePostLayout(int postLayout) { if (mAccessToken == null) { if (viewPager.getCurrentItem() == 0) { - if (popularPostFragment != null) { + if (tab2 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply(); - popularPostFragment.changePostLayout(postLayout); + tab2.changePostLayout(postLayout); } } else { - if (allPostFragment != null) { + if (tab3 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply(); - allPostFragment.changePostLayout(postLayout); + tab3.changePostLayout(postLayout); } } } else { switch (viewPager.getCurrentItem()) { case 0: - if (frontPagePostFragment != null) { + if (tab1 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply(); - frontPagePostFragment.changePostLayout(postLayout); + tab1.changePostLayout(postLayout); } break; case 1: - if (popularPostFragment != null) { + if (tab2 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply(); - popularPostFragment.changePostLayout(postLayout); + tab2.changePostLayout(postLayout); } break; case 2: - if (allPostFragment != null) { + if (tab3 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply(); - allPostFragment.changePostLayout(postLayout); + tab3.changePostLayout(postLayout); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 351ab8f8..5368f6f4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -51,6 +51,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListing import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment; import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import ml.docilealligator.infinityforreddit.Settings.AdvancedPreferenceFragment; +import ml.docilealligator.infinityforreddit.Settings.CustomizeMainPageTabsFragment; import ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment; @@ -164,4 +165,6 @@ public interface AppComponent { void inject(SelectedSubredditsActivity selectedSubredditsActivity); void inject(ReportActivity reportActivity); + + void inject(CustomizeMainPageTabsFragment customizeMainPageTabsFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java new file mode 100644 index 00000000..89e212dc --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java @@ -0,0 +1,174 @@ +package ml.docilealligator.infinityforreddit.Settings; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.preference.EditTextPreference; +import androidx.preference.ListPreference; +import androidx.preference.PreferenceFragmentCompat; + +import javax.inject.Inject; +import javax.inject.Named; + +import ml.docilealligator.infinityforreddit.Activity.SettingsActivity; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; + +/** + * A simple {@link Fragment} subclass. + */ +public class CustomizeMainPageTabsFragment extends PreferenceFragmentCompat { + + @Inject + @Named("default") + SharedPreferences mSharedPreferences; + @Inject + CustomThemeWrapper customThemeWrapper; + private SettingsActivity activity; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.customize_main_page_tabs_preferences, rootKey); + + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + + EditTextPreference tab1TitlePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE); + EditTextPreference tab2TitlePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE); + EditTextPreference tab3TitlePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE); + ListPreference tab1PostTypePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE); + ListPreference tab2PostTypePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE); + ListPreference tab3PostTypePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE); + EditTextPreference tab1NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME); + EditTextPreference tab2NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME); + EditTextPreference tab3NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME); + + if (tab1TitlePreference != null && tab1PostTypePreference != null && tab1NamePreference != null) { + String string = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, + SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(string)) { + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_subreddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(string)) { + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(string)) { + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_username); + } + + tab1PostTypePreference.setOnPreferenceChangeListener((preference, newValue) -> { + switch ((String) newValue) { + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL: + tab1NamePreference.setVisible(false); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_subreddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT: + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER: + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_username); + } + return true; + }); + } + + if (tab2TitlePreference != null && tab2PostTypePreference != null && tab2NamePreference != null) { + String string = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, + SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(string)) { + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_subreddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(string)) { + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(string)) { + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_username); + } + + tab2PostTypePreference.setOnPreferenceChangeListener((preference, newValue) -> { + switch ((String) newValue) { + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL: + tab2NamePreference.setVisible(false); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_subreddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT: + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER: + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_username); + } + return true; + }); + } + + if (tab3TitlePreference != null && tab3PostTypePreference != null && tab3NamePreference != null) { + String string = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, + SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(string)) { + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_subreddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(string)) { + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(string)) { + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_username); + } + + tab3PostTypePreference.setOnPreferenceChangeListener((preference, newValue) -> { + switch ((String) newValue) { + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL: + tab3NamePreference.setVisible(false); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_subreddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT: + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER: + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_username); + } + return true; + }); + } + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (SettingsActivity) context; + } +} 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 538e5899..7b12ef6c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -100,4 +100,19 @@ public class SharedPreferencesUtils { public static final String DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE = "delete_all_post_layout_data_in_database"; public static final String DELETE_ALL_THEMES_IN_DATABASE = "delete_all_themes_in_database"; public static final String RESET_ALL_SETTINGS = "reset_all_settings"; + public static final String MAIN_PAGE_TAB_1_TITLE = "main_page_tab_1_title"; + public static final String MAIN_PAGE_TAB_2_TITLE = "main_page_tab_2_title"; + public static final String MAIN_PAGE_TAB_3_TITLE = "main_page_tab_3_title"; + public static final String MAIN_PAGE_TAB_1_POST_TYPE = "main_page_tab_1_post_type"; + public static final String MAIN_PAGE_TAB_2_POST_TYPE = "main_page_tab_2_post_type"; + public static final String MAIN_PAGE_TAB_3_POST_TYPE = "main_page_tab_3_post_type"; + public static final String MAIN_PAGE_TAB_1_NAME = "main_page_tab_1_name"; + public static final String MAIN_PAGE_TAB_2_NAME = "main_page_tab_2_name"; + public static final String MAIN_PAGE_TAB_3_NAME = "main_page_tab_3_name"; + public static final String MAIN_PAGE_TAB_POST_TYPE_HOME = "0"; + public static final String MAIN_PAGE_TAB_POST_TYPE_POPULAR = "1"; + public static final String MAIN_PAGE_TAB_POST_TYPE_ALL = "2"; + public static final String MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT = "3"; + public static final String MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT = "4"; + public static final String MAIN_PAGE_TAB_POST_TYPE_USER = "5"; } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index b415b0f5..5fce9e21 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -122,4 +122,22 @@ XLarge XXLarge + + + Home + Popular + All + Subreddit + MultiReddit + User + + + + 0 + 1 + 2 + 3 + 4 + 5 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52ec8509..5df67ecc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -321,6 +321,8 @@ Immersive Interface Ignore Navigation Bar in Immersive Interface Prevent the Bottom Navigation Bar Having Extra Padding + Customize Tabs in Main Page + Only for Logged-in User Enable Bottom Navigation Has No Effect in Anonymous Mode Vote Buttons on the Right @@ -393,6 +395,15 @@ Delete All Themes in Database Reset All Settings Clean the database and shared preferences + Restart the app to see the changes + Tab 1 + Tab 2 + Tab 3 + Title + Type + Subreddit Name + MultiReddit Name + Username Cannot get the link @@ -711,10 +722,13 @@ Reported Report failed You haven\'t selected a reason - + It Is Spam It Contains Copyright Issue It Contains Child Pornography It Contains Abusive Content + Home + Best + diff --git a/app/src/main/res/xml/customize_main_page_tabs_preferences.xml b/app/src/main/res/xml/customize_main_page_tabs_preferences.xml new file mode 100644 index 00000000..37e17d0c --- /dev/null +++ b/app/src/main/res/xml/customize_main_page_tabs_preferences.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/interface_preference.xml b/app/src/main/res/xml/interface_preference.xml index 8b67a3bc..58de9ef4 100644 --- a/app/src/main/res/xml/interface_preference.xml +++ b/app/src/main/res/xml/interface_preference.xml @@ -20,6 +20,11 @@ app:summary="@string/settings_immersive_interface_ignore_nav_bar_summary" app:isPreferenceVisible="false" /> + +