New option: Default Search Result Tab. Move Show Avatar on the Left in the Navigation Drawer to Settings->Interface->Navigation Drawer.

This commit is contained in:
Alex Ning 2021-03-15 20:06:13 +08:00
parent 57fd9edaff
commit cf370d215c
9 changed files with 49 additions and 20 deletions

View File

@ -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:

View File

@ -99,7 +99,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
this.accountName = accountName;
isNSFWEnabled = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
requireAuthToAccountSection = sharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false);
showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT_IN_THE_NAVIGATION_DRAWER, false);
showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false);
isLoggedIn = accountName != null;
collapseAccountSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_ACCOUNT_SECTION, false);
collapsePostSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_POST_SECTION, false);

View File

@ -11,7 +11,6 @@ import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent;
import ml.docilealligator.infinityforreddit.events.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@ -24,7 +23,6 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
Preference immersiveInterfaceEntryPreference = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_ENTRY_KEY);
SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY);
SwitchPreference showAvatarOnTheRightInTheNavigationDrawer = findPreference(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT_IN_THE_NAVIGATION_DRAWER);
SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY);
if (immersiveInterfaceEntryPreference != null && Build.VERSION.SDK_INT >= 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));

View File

@ -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;
});
}
}
}

View File

@ -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";

View File

@ -409,4 +409,16 @@
<item>ALL</item>
</string-array>
<string-array name="settings_default_search_result_tab">
<item>@string/posts</item>
<item>@string/subreddits</item>
<item>@string/users</item>
</string-array>
<string-array name="settings_default_search_result_tab_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>

View File

@ -542,7 +542,7 @@
<string name="settings_hide_subreddit_and_user_prefix">Hide Subreddit and User Prefix</string>
<string name="settings_hide_the_number_of_votes">Hide the Number of Votes</string>
<string name="settings_hide_the_number_of_comments">Hide the Number of Comments</string>
<string name="settings_show_avatar_on_the_right_in_the_navigation_drawer">Show Avatar on the Left in the Navigation Drawer</string>
<string name="settings_show_avatar_on_the_right">Show Avatar on the Left</string>
<string name="settings_backup_settings_title">Backup Settings</string>
<string name="settings_restore_settings_title">Restore Settings</string>
<string name="settings_credits_love_animation_title">Love Animation</string>
@ -555,6 +555,7 @@
<string name="settings_collapse_subscribed_subreddits_section_title">Collapse Subscribed Subreddits Section</string>
<string name="settings_hide_favorite_subreddits_sections_title">Hide Favorite Subreddits Section</string>
<string name="settings_hide_subscribed_subreddits_sections_title">Hide Subscribed Subreddits Section</string>
<string name="settings_default_search_result_tab">Default Search Result Tab</string>
<string name="no_link_available">Cannot get the link</string>

View File

@ -33,15 +33,18 @@
app:title="@string/settings_enable_bottom_app_bar_title"
app:summary="@string/settings_enable_bottom_app_bar_summary" />
<SwitchPreference
app:defaultValue="false"
app:key="show_avatar_on_the_right_in_the_navigation_drawer"
app:title="@string/settings_show_avatar_on_the_right_in_the_navigation_drawer" />
<Preference
app:title="@string/settings_time_format_title"
app:fragment="ml.docilealligator.infinityforreddit.settings.TimeFormatPreferenceFragment" />
<ListPreference
app:defaultValue="0"
app:entries="@array/settings_default_search_result_tab"
app:entryValues="@array/settings_default_search_result_tab_values"
app:key="default_search_result_tab"
app:title="@string/settings_default_search_result_tab"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:defaultValue="false"
app:key="hide_subreddit_description"

View File

@ -6,6 +6,11 @@
app:summary="@string/restart_app_see_changes"
app:enabled="false" />
<SwitchPreference
app:defaultValue="false"
app:key="show_avatar_on_the_right"
app:title="@string/settings_show_avatar_on_the_right" />
<SwitchPreference
app:defaultValue="false"
app:key="collapse_account_section"