From 350acdb5009c5fdca5c19727ede88bf123b44f6d Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 16 Sep 2020 11:58:42 +0800 Subject: Add an option which is long press to hide toolbar in post compact layout. This option has crappy animation for now. Add another option to hide toolbar in post compact layout by default. --- .../Adapter/PostRecyclerViewAdapter.java | 30 ++++++++++++++++++++++ ...geCompactLayoutToolbarHiddenByDefaultEvent.java | 9 +++++++ ...LongPressToHideToolbarInCompactLayoutEvent.java | 9 +++++++ .../infinityforreddit/Fragment/PostFragment.java | 18 +++++++++++++ .../Settings/InterfacePreferenceFragment.java | 18 +++++++++++++ .../Utils/SharedPreferencesUtils.java | 2 ++ 6 files changed, 86 insertions(+) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeCompactLayoutToolbarHiddenByDefaultEvent.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeLongPressToHideToolbarInCompactLayoutEvent.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index d9e9c0de..a815302f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -182,6 +182,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + if (mLongPressToHideToolbarInCompactLayout) { + if (bottomConstraintLayout.getVisibility() == View.VISIBLE) { + bottomConstraintLayout.setVisibility(View.GONE); + } else { + bottomConstraintLayout.setVisibility(View.VISIBLE); + } + } + return true; + }); + nameTextView.setOnClickListener(view -> { int position = getAdapterPosition(); if (position < 0) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeCompactLayoutToolbarHiddenByDefaultEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeCompactLayoutToolbarHiddenByDefaultEvent.java new file mode 100644 index 00000000..be9349ba --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeCompactLayoutToolbarHiddenByDefaultEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ChangeCompactLayoutToolbarHiddenByDefaultEvent { + public boolean compactLayoutToolbarHiddenByDefault; + + public ChangeCompactLayoutToolbarHiddenByDefaultEvent(boolean compactLayoutToolbarHiddenByDefault) { + this.compactLayoutToolbarHiddenByDefault = compactLayoutToolbarHiddenByDefault; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeLongPressToHideToolbarInCompactLayoutEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeLongPressToHideToolbarInCompactLayoutEvent.java new file mode 100644 index 00000000..1d1cfcdf --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeLongPressToHideToolbarInCompactLayoutEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ChangeLongPressToHideToolbarInCompactLayoutEvent { + public boolean longPressToHideToolbarInCompactLayout; + + public ChangeLongPressToHideToolbarInCompactLayoutEvent(boolean longPressToHideToolbarInCompactLayout) { + this.longPressToHideToolbarInCompactLayout = longPressToHideToolbarInCompactLayout; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 6208807e..e04e1dde 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -68,8 +68,10 @@ import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer; import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeCompactLayoutToolbarHiddenByDefaultEvent; import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeEnableSwipeActionSwitchEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeLongPressToHideToolbarInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeMuteAutoplayingVideosEvent; import ml.docilealligator.infinityforreddit.Event.ChangeMuteNSFWVideoEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; @@ -1207,6 +1209,22 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mSwipeRefreshLayout.setEnabled(changePullToRefreshEvent.pullToRefresh); } + @Subscribe + public void onChangeLongPressToHideToolbarInCompactLayoutEvent(ChangeLongPressToHideToolbarInCompactLayoutEvent changeLongPressToHideToolbarInCompactLayoutEvent) { + if (mAdapter != null) { + mAdapter.setLongPressToHideToolbarInCompactLayout(changeLongPressToHideToolbarInCompactLayoutEvent.longPressToHideToolbarInCompactLayout); + refreshAdapter(); + } + } + + @Subscribe + public void onChangeCompactLayoutToolbarHiddenByDefaultEvent(ChangeCompactLayoutToolbarHiddenByDefaultEvent changeCompactLayoutToolbarHiddenByDefaultEvent) { + if (mAdapter != null) { + mAdapter.setCompactLayoutToolbarHiddenByDefault(changeCompactLayoutToolbarHiddenByDefaultEvent.compactLayoutToolbarHiddenByDefault); + refreshAdapter(); + } + } + private void refreshAdapter() { int previousPosition = -1; if (mLinearLayoutManager != null) { 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 bec9cad8..29f33fc8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java @@ -11,7 +11,9 @@ import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; +import ml.docilealligator.infinityforreddit.Event.ChangeCompactLayoutToolbarHiddenByDefaultEvent; import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeLongPressToHideToolbarInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; @@ -33,6 +35,8 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); SwitchPreference showThumbnailOnTheRightInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_LEFT_IN_COMPACT_LAYOUT); SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES); + SwitchPreference longPressToHideToolbarInCompactLayoutSwitch = findPreference(SharedPreferencesUtils.LONG_PRESS_TO_HIDE_TOOLBAR_IN_COMPACT_LAYOUT); + SwitchPreference postCompactLayoutToolbarHiddenByDefaultSwitch = findPreference(SharedPreferencesUtils.POST_COMPACT_LAYOUT_TOOLBAR_HIDDEN_BY_DEFAULT); if (immersiveInterfaceEntryPreference != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { immersiveInterfaceEntryPreference.setVisible(true); @@ -79,5 +83,19 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { return true; }); } + + if (longPressToHideToolbarInCompactLayoutSwitch != null) { + longPressToHideToolbarInCompactLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeLongPressToHideToolbarInCompactLayoutEvent((Boolean) newValue)); + return true; + }); + } + + if (postCompactLayoutToolbarHiddenByDefaultSwitch != null) { + postCompactLayoutToolbarHiddenByDefaultSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeCompactLayoutToolbarHiddenByDefaultEvent((Boolean) newValue)); + return true; + }); + } } } 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 8381319b..87b70f3e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -124,6 +124,8 @@ public class SharedPreferencesUtils { public static final String ENABLE_SWIPE_ACTION = "enable_swipe_action"; public static final String PULL_TO_REFRESH = "pull_to_refresh"; public static final String REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER = "require_auth_to_account_section"; + public static final String LONG_PRESS_TO_HIDE_TOOLBAR_IN_COMPACT_LAYOUT = "long_press_to_hide_toolbar_in_compact_layout"; + public static final String POST_COMPACT_LAYOUT_TOOLBAR_HIDDEN_BY_DEFAULT = "post_compact_layout_toolbar_hidden_by_default"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TAB_1_TITLE = "_main_page_tab_1_title"; -- cgit v1.2.3