mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
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.
This commit is contained in:
parent
eb5cc7d7d4
commit
350acdb500
@ -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) {
|
||||
|
@ -0,0 +1,9 @@
|
||||
package ml.docilealligator.infinityforreddit.Event;
|
||||
|
||||
public class ChangeCompactLayoutToolbarHiddenByDefaultEvent {
|
||||
public boolean compactLayoutToolbarHiddenByDefault;
|
||||
|
||||
public ChangeCompactLayoutToolbarHiddenByDefaultEvent(boolean compactLayoutToolbarHiddenByDefault) {
|
||||
this.compactLayoutToolbarHiddenByDefault = compactLayoutToolbarHiddenByDefault;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package ml.docilealligator.infinityforreddit.Event;
|
||||
|
||||
public class ChangeLongPressToHideToolbarInCompactLayoutEvent {
|
||||
public boolean longPressToHideToolbarInCompactLayout;
|
||||
|
||||
public ChangeLongPressToHideToolbarInCompactLayoutEvent(boolean longPressToHideToolbarInCompactLayout) {
|
||||
this.longPressToHideToolbarInCompactLayout = longPressToHideToolbarInCompactLayout;
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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" />
|
||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user