aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-09-16 03:58:42 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-09-16 03:58:42 +0000
commit350acdb5009c5fdca5c19727ede88bf123b44f6d (patch)
tree29a3c863777fb5723e9da71feebe4087344794d4
parenteb5cc7d7d41c1db8548fdcab52ce04d4d1a1439e (diff)
downloadinfinity-for-reddit-350acdb5009c5fdca5c19727ede88bf123b44f6d.tar
infinity-for-reddit-350acdb5009c5fdca5c19727ede88bf123b44f6d.tar.gz
infinity-for-reddit-350acdb5009c5fdca5c19727ede88bf123b44f6d.tar.bz2
infinity-for-reddit-350acdb5009c5fdca5c19727ede88bf123b44f6d.tar.lz
infinity-for-reddit-350acdb5009c5fdca5c19727ede88bf123b44f6d.tar.xz
infinity-for-reddit-350acdb5009c5fdca5c19727ede88bf123b44f6d.tar.zst
infinity-for-reddit-350acdb5009c5fdca5c19727ede88bf123b44f6d.zip
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.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java30
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeCompactLayoutToolbarHiddenByDefaultEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeLongPressToHideToolbarInCompactLayoutEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java2
-rw-r--r--app/src/main/res/values/strings.xml4
-rw-r--r--app/src/main/res/xml/interface_preference.xml10
-rw-r--r--app/src/main/res/xml/security_preferences.xml2
9 files changed, 100 insertions, 2 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";
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 39a228ff..3c46cf9f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -484,7 +484,9 @@
<string name="settings_enable_swipe_action_title">Enable Swipe Action</string>
<string name="settings_pull_to_refresh_title">Pull to Refresh</string>
<string name="settings_security_title">Security</string>
- <string name="settings_require_authentication_to_go_to_account_section_in_navigation_drawer">Require Authentication to Go to Account Section in Navigation Drawer</string>
+ <string name="settings_require_authentication_to_go_to_account_section_in_navigation_drawer_title">Require Authentication to Go to Account Section in Navigation Drawer</string>
+ <string name="settings_long_press_to_hide_toolbar_in_compact_layout_title">Long Press to Hide Toolbar in Compact Layout</string>
+ <string name="settings_post_compact_layout_toolbar_hidden_by_default_title">Toolbar in Compact Layout Hidden by Default</string>
<string name="no_link_available">Cannot get the link</string>
diff --git a/app/src/main/res/xml/interface_preference.xml b/app/src/main/res/xml/interface_preference.xml
index 0fcd1977..f898291c 100644
--- a/app/src/main/res/xml/interface_preference.xml
+++ b/app/src/main/res/xml/interface_preference.xml
@@ -62,6 +62,16 @@
app:key="show_thumbnail_on_the_left_in_compact_layout"
app:title="@string/settings_show_thumbnail_on_the_left_in_compact_layout" />
+ <SwitchPreference
+ app:defaultValue="false"
+ app:key="long_press_to_hide_toolbar_in_compact_layout"
+ app:title="@string/settings_long_press_to_hide_toolbar_in_compact_layout_title" />
+
+ <SwitchPreference
+ app:defaultValue="false"
+ app:key="post_compact_layout_toolbar_hidden_by_default"
+ app:title="@string/settings_post_compact_layout_toolbar_hidden_by_default_title" />
+
<Preference
app:title="@string/settings_number_of_columns_in_post_feed_title"
app:fragment="ml.docilealligator.infinityforreddit.Settings.NumberOfColumnsInPostFeedPreferenceFragment" />
diff --git a/app/src/main/res/xml/security_preferences.xml b/app/src/main/res/xml/security_preferences.xml
index a7174faf..d43c2384 100644
--- a/app/src/main/res/xml/security_preferences.xml
+++ b/app/src/main/res/xml/security_preferences.xml
@@ -3,6 +3,6 @@
<SwitchPreference
app:defaultValue="false"
app:key="require_auth_to_account_section"
- app:title="@string/settings_require_authentication_to_go_to_account_section_in_navigation_drawer" />
+ app:title="@string/settings_require_authentication_to_go_to_account_section_in_navigation_drawer_title" />
</PreferenceScreen> \ No newline at end of file