diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-02-26 14:15:39 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-02-26 14:15:39 +0000 |
commit | c2b6066c7ec68a9f1d7e72a24d5bfb22c5461e3c (patch) | |
tree | cd67e0e190de871f242807ef1139f40c30730499 /app/src/main/java/ml | |
parent | a6289f4c1fbf21b719bfc41a99e00b2eecbd1458 (diff) | |
download | infinity-for-reddit-c2b6066c7ec68a9f1d7e72a24d5bfb22c5461e3c.tar infinity-for-reddit-c2b6066c7ec68a9f1d7e72a24d5bfb22c5461e3c.tar.gz infinity-for-reddit-c2b6066c7ec68a9f1d7e72a24d5bfb22c5461e3c.tar.bz2 infinity-for-reddit-c2b6066c7ec68a9f1d7e72a24d5bfb22c5461e3c.tar.lz infinity-for-reddit-c2b6066c7ec68a9f1d7e72a24d5bfb22c5461e3c.tar.xz infinity-for-reddit-c2b6066c7ec68a9f1d7e72a24d5bfb22c5461e3c.tar.zst infinity-for-reddit-c2b6066c7ec68a9f1d7e72a24d5bfb22c5461e3c.zip |
New option: Show avatar on the right in the navigation drawer.
Diffstat (limited to 'app/src/main/java/ml')
5 files changed, 60 insertions, 1 deletions
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<Re private int karma; private boolean isNSFWEnabled; private boolean requireAuthToAccountSection; + private boolean showAvatarOnTheRightInTheNavigationDrawer; private ItemClickListener itemClickListener; private boolean isLoggedIn; private boolean isInMainPage = true; @@ -86,6 +88,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); isLoggedIn = accountName != null; this.itemClickListener = itemClickListener; primaryTextColor = customThemeWrapper.getPrimaryTextColor(); @@ -173,6 +176,15 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof NavHeaderViewHolder) { + if (showAvatarOnTheRightInTheNavigationDrawer) { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ((NavHeaderViewHolder) holder).profileImageView.getLayoutParams(); + params.addRule(RelativeLayout.ALIGN_PARENT_END); + ((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params); + } else { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ((NavHeaderViewHolder) holder).profileImageView.getLayoutParams(); + params.removeRule(RelativeLayout.ALIGN_PARENT_END); + ((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params); + } if (isLoggedIn) { ((NavHeaderViewHolder) holder).karmaTextView.setText(appCompatActivity.getString(R.string.karma_info, karma)); ((NavHeaderViewHolder) holder).accountNameTextView.setText(accountName); @@ -564,6 +576,10 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re this.requireAuthToAccountSection = requireAuthToAccountSection; } + public void setShowAvatarOnTheRightInTheNavigationDrawer(boolean showAvatarOnTheRightInTheNavigationDrawer) { + this.showAvatarOnTheRightInTheNavigationDrawer = showAvatarOnTheRightInTheNavigationDrawer; + } + class NavHeaderViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.name_text_view_nav_header_main) TextView accountNameTextView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent.java new file mode 100644 index 00000000..b36fa732 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.events; + +public class ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent { + public boolean showAvatarOnTheRightInTheNavigationDrawer; + + public ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent(boolean showAvatarOnTheRightInTheNavigationDrawer) { + this.showAvatarOnTheRightInTheNavigationDrawer = showAvatarOnTheRightInTheNavigationDrawer; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/InterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/InterfacePreferenceFragment.java index 2ef43ebf..0d16cb45 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/InterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/InterfacePreferenceFragment.java @@ -11,6 +11,7 @@ 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; @@ -23,6 +24,7 @@ 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) { @@ -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"; |