From c2b6066c7ec68a9f1d7e72a24d5bfb22c5461e3c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 26 Feb 2021 22:15:39 +0800 Subject: New option: Show avatar on the right in the navigation drawer. --- .../infinityforreddit/activities/MainActivity.java | 26 ++++++++++++++++++++- .../NavigationDrawerRecyclerViewAdapter.java | 16 +++++++++++++ ...AvatarOnTheRightInTheNavigationDrawerEvent.java | 9 +++++++ .../settings/InterfacePreferenceFragment.java | 9 +++++++ .../utils/SharedPreferencesUtils.java | 1 + .../main/res/drawable/subreddit_default_icon.jpg | Bin 51471 -> 0 bytes .../main/res/drawable/subreddit_default_icon.png | Bin 0 -> 16621 bytes .../main/res/drawable/subreddit_default_icon_2.jpg | Bin 0 -> 51471 bytes app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/interface_preferences.xml | 5 ++++ 10 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent.java delete mode 100644 app/src/main/res/drawable/subreddit_default_icon.jpg create mode 100644 app/src/main/res/drawable/subreddit_default_icon.png create mode 100644 app/src/main/res/drawable/subreddit_default_icon_2.jpg diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 83b8a2c9..18955498 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -95,6 +95,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeDisableSwipingBetweenTa import ml.docilealligator.infinityforreddit.events.ChangeLockBottomAppBarEvent; import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent; +import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.PostFragment; @@ -1162,7 +1163,30 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Subscribe public void onChangeRequireAuthToAccountSectionEvent(ChangeRequireAuthToAccountSectionEvent changeRequireAuthToAccountSectionEvent) { - adapter.setRequireAuthToAccountSection(changeRequireAuthToAccountSectionEvent.requireAuthToAccountSection); + if (adapter != null) { + adapter.setRequireAuthToAccountSection(changeRequireAuthToAccountSectionEvent.requireAuthToAccountSection); + } + } + + @Subscribe + public void onChangeShowAvatarOnTheRightInTheNavigationDrawerEvent(ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent event) { + if (adapter != null) { + adapter.setShowAvatarOnTheRightInTheNavigationDrawer(event.showAvatarOnTheRightInTheNavigationDrawer); + int previousPosition = -1; + if (navDrawerRecyclerView.getLayoutManager() != null) { + previousPosition = ((LinearLayoutManager) navDrawerRecyclerView.getLayoutManager()).findFirstVisibleItemPosition(); + } + + RecyclerView.LayoutManager layoutManager = navDrawerRecyclerView.getLayoutManager(); + navDrawerRecyclerView.setAdapter(null); + navDrawerRecyclerView.setLayoutManager(null); + navDrawerRecyclerView.setAdapter(adapter); + navDrawerRecyclerView.setLayoutManager(layoutManager); + + if (previousPosition > 0) { + navDrawerRecyclerView.scrollToPosition(previousPosition); + } + } } @Override 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 744e6ad8..d6de3458 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java @@ -7,6 +7,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -64,6 +65,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter= Build.VERSION_CODES.O) { @@ -36,6 +38,13 @@ 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/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index aa2d7c3f..be8489a9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -38,6 +38,7 @@ 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 SORT_TYPE_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.sort_type"; public static final String SORT_TYPE_BEST_POST = "sort_type_best_post"; diff --git a/app/src/main/res/drawable/subreddit_default_icon.jpg b/app/src/main/res/drawable/subreddit_default_icon.jpg deleted file mode 100644 index 4e9bc2fc..00000000 Binary files a/app/src/main/res/drawable/subreddit_default_icon.jpg and /dev/null differ diff --git a/app/src/main/res/drawable/subreddit_default_icon.png b/app/src/main/res/drawable/subreddit_default_icon.png new file mode 100644 index 00000000..072c8e24 Binary files /dev/null and b/app/src/main/res/drawable/subreddit_default_icon.png differ diff --git a/app/src/main/res/drawable/subreddit_default_icon_2.jpg b/app/src/main/res/drawable/subreddit_default_icon_2.jpg new file mode 100644 index 00000000..4e9bc2fc Binary files /dev/null and b/app/src/main/res/drawable/subreddit_default_icon_2.jpg differ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5278ec55..81cc184b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -540,6 +540,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 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 d6f8dc68..e40f5b25 100644 --- a/app/src/main/res/xml/interface_preferences.xml +++ b/app/src/main/res/xml/interface_preferences.xml @@ -29,6 +29,11 @@ app:title="@string/settings_enable_bottom_app_bar_title" app:summary="@string/settings_enable_bottom_app_bar_summary" /> + + -- cgit v1.2.3