diff options
Diffstat (limited to 'app/src/main/java/ml')
6 files changed, 86 insertions, 0 deletions
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<Post, RecyclerView private double mStartAutoplayVisibleAreaOffset; private boolean mMuteNSFWVideo; private boolean mAutomaticallyTryRedgifs; + private boolean mLongPressToHideToolbarInCompactLayout; + private boolean mCompactLayoutToolbarHiddenByDefault; private Drawable mCommentIcon; private NetworkState networkState; private ExoCreator mExoCreator; @@ -231,6 +233,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mMuteNSFWVideo = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_NSFW_VIDEO, false); mAutomaticallyTryRedgifs = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOMATICALLY_TRY_REDGIFS, true); + mLongPressToHideToolbarInCompactLayout = sharedPreferences.getBoolean(SharedPreferencesUtils.LONG_PRESS_TO_HIDE_TOOLBAR_IN_COMPACT_LAYOUT, false); + mCompactLayoutToolbarHiddenByDefault = sharedPreferences.getBoolean(SharedPreferencesUtils.POST_COMPACT_LAYOUT_TOOLBAR_HIDDEN_BY_DEFAULT, false); + mPostLayout = postLayout; mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); @@ -775,6 +780,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostCompactBaseViewHolder) holder).postTimeTextView.setText(Utils.getFormattedTime(mLocale, post.getPostTimeMillis(), mTimeFormatPattern)); } + if (mCompactLayoutToolbarHiddenByDefault) { + ((PostCompactBaseViewHolder) holder).bottomConstraintLayout.setVisibility(View.GONE); + } else { + ((PostCompactBaseViewHolder) holder).bottomConstraintLayout.setVisibility(View.VISIBLE); + } + if (mShowDividerInCompactLayout) { ((PostCompactBaseViewHolder) holder).divider.setVisibility(View.VISIBLE); } else { @@ -1184,6 +1195,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView this.mMuteNSFWVideo = muteNSFWVideo; } + public void setLongPressToHideToolbarInCompactLayout(boolean longPressToHideToolbarInCompactLayout) { + mLongPressToHideToolbarInCompactLayout = longPressToHideToolbarInCompactLayout; + } + + public void setCompactLayoutToolbarHiddenByDefault(boolean compactLayoutToolbarHiddenByDefault) { + mCompactLayoutToolbarHiddenByDefault = compactLayoutToolbarHiddenByDefault; + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); @@ -2794,6 +2813,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } }); + itemView.setOnLongClickListener(view -> { + 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"; |