From cf370d215c14a6a96edd2cacf7264d07729034d3 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 15 Mar 2021 20:06:13 +0800 Subject: New option: Default Search Result Tab. Move Show Avatar on the Left in the Navigation Drawer to Settings->Interface->Navigation Drawer. --- .../infinityforreddit/activities/SearchResultActivity.java | 8 ++++++-- .../adapters/NavigationDrawerRecyclerViewAdapter.java | 2 +- .../settings/InterfacePreferenceFragment.java | 9 --------- .../settings/NavigationDrawerPreferenceFragment.java | 13 +++++++++++++ .../infinityforreddit/utils/SharedPreferencesUtils.java | 4 ++-- app/src/main/res/values/arrays.xml | 12 ++++++++++++ app/src/main/res/values/strings.xml | 3 ++- app/src/main/res/xml/interface_preferences.xml | 13 ++++++++----- app/src/main/res/xml/navigation_drawer_preferences.xml | 5 +++++ 9 files changed, 49 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index 35d6c66e..5096e5f7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -185,7 +185,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect if (savedInstanceState != null) { mInsertSearchQuerySuccess = savedInstanceState.getBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE); } - bindView(); + bindView(savedInstanceState); } @Override @@ -214,7 +214,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect applyFABTheme(fab); } - private void bindView() { + private void bindView(Bundle savedInstanceState) { sectionsPagerAdapter = new SectionsPagerAdapter(this); viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setOffscreenPageLimit(3); @@ -246,6 +246,10 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect }).attach(); fixViewPager2Sensitivity(viewPager2); + if (savedInstanceState == null) { + viewPager2.setCurrentItem(Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_SEARCH_RESULT_TAB, "0")), false); + } + fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); switch (fabOption) { case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH: diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java index 1ecd8b25..d89c0160 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java @@ -99,7 +99,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter= Build.VERSION_CODES.O) { @@ -38,13 +36,6 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { }); } - if (showAvatarOnTheRightInTheNavigationDrawer != null) { - showAvatarOnTheRightInTheNavigationDrawer.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent((Boolean) newValue)); - return true; - }); - } - if (voteButtonsOnTheRightSwitch != null) { voteButtonsOnTheRightSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeVoteButtonsPositionEvent((Boolean) newValue)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java index 85751e38..6b6d7c04 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java @@ -4,8 +4,12 @@ import android.os.Bundle; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; +import androidx.preference.SwitchPreference; + +import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class NavigationDrawerPreferenceFragment extends PreferenceFragmentCompat { @@ -15,5 +19,14 @@ public class NavigationDrawerPreferenceFragment extends PreferenceFragmentCompat PreferenceManager preferenceManager = getPreferenceManager(); preferenceManager.setSharedPreferencesName(SharedPreferencesUtils.NAVIGATION_DRAWER_SHARED_PREFERENCES_FILE); setPreferencesFromResource(R.xml.navigation_drawer_preferences, rootKey); + + SwitchPreference showAvatarOnTheRightSwitch = findPreference(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT); + + if (showAvatarOnTheRightSwitch != null) { + showAvatarOnTheRightSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent((Boolean) newValue)); + return true; + }); + } } } \ No newline at end of file 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 74b882b0..48714674 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -38,7 +38,8 @@ public class SharedPreferencesUtils { public static final String DISABLE_IMMERSIVE_INTERFACE_IN_LANDSCAPE_MODE = "disable_immersive_interface_in_landscape_mode"; public static final String BOTTOM_APP_BAR_KEY = "bottom_app_bar"; public static final String VOTE_BUTTONS_ON_THE_RIGHT_KEY = "vote_buttons_on_the_right"; - public static final String SHOW_AVATAR_ON_THE_RIGHT_IN_THE_NAVIGATION_DRAWER = "show_avatar_on_the_right_in_the_navigation_drawer"; + public static final String SHOW_AVATAR_ON_THE_RIGHT = "show_avatar_on_the_right"; + public static final String DEFAULT_SEARCH_RESULT_TAB = "default_search_result_tab"; public static final String SORT_TYPE_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.sort_type"; public static final String SORT_TYPE_BEST_POST = "sort_type_best_post"; @@ -145,7 +146,6 @@ public class SharedPreferencesUtils { public static final String DATA_SAVING_MODE_ALWAYS = "2"; public static final String NATIONAL_FLAGS = "national_flags"; public static final String RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE = "respect_subreddit_recommended_comment_sort_type"; - public static final String SUBREDDIT_FILTER_POPULAR_AND_ALL = "subreddit_filter_popular_and_all"; public static final String UFO_CAPTURING_ANIMATION = "ufo_capturing_animation"; public static final String HIDE_SUBREDDIT_DESCRIPTION = "hide_subreddit_description"; public static final String DISABLE_IMAGE_PREVIEW = "disable_image_preview"; diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index cb475059..2c65f6e0 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -409,4 +409,16 @@ ALL + + @string/posts + @string/subreddits + @string/users + + + + 0 + 1 + 2 + + \ 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 70f5f6eb..e6a546f7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -542,7 +542,7 @@ Hide Subreddit and User Prefix Hide the Number of Votes Hide the Number of Comments - Show Avatar on the Left in the Navigation Drawer + Show Avatar on the Left Backup Settings Restore Settings Love Animation @@ -555,6 +555,7 @@ Collapse Subscribed Subreddits Section Hide Favorite Subreddits Section Hide Subscribed Subreddits Section + Default Search Result Tab Cannot get the link diff --git a/app/src/main/res/xml/interface_preferences.xml b/app/src/main/res/xml/interface_preferences.xml index 1d45da42..6387a850 100644 --- a/app/src/main/res/xml/interface_preferences.xml +++ b/app/src/main/res/xml/interface_preferences.xml @@ -33,15 +33,18 @@ app:title="@string/settings_enable_bottom_app_bar_title" app:summary="@string/settings_enable_bottom_app_bar_summary" /> - - + + + +