mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-11 06:44:00 +00:00
feat: Support infinite scroll on home screen (#5807)
* scrolling * removed logging from the scrolling part in pagedview * added toggle for infinite scrolling * strings * scrolling preferences moved * string fix
This commit is contained in:
@@ -586,6 +586,9 @@
|
||||
<string name="wallpaper_depth_effect_description">Zoom in and out of the wallpaper when transitioning between areas of the launcher</string>
|
||||
<string name="show_sys_ui_scrim">Top shadow</string>
|
||||
|
||||
<string name="infinite_scrolling_label">Infinite scrolling</string>
|
||||
<string name="infinite_scrolling_description">Swipe to loop between the first and last pages</string>
|
||||
|
||||
<string name="home_screen_grid">Home screen grid</string>
|
||||
<string name="home_screen_lock">Lock home screen</string>
|
||||
<string name="home_screen_unlock">Unlock home screen</string>
|
||||
|
||||
@@ -63,6 +63,7 @@ class PreferenceManager private constructor(private val context: Context) :
|
||||
val windowCornerRadius = IntPref("pref_windowCornerRadius", 80, recreate)
|
||||
val autoLaunchRoot = BoolPref("pref_autoLaunchRoot", false)
|
||||
val wallpaperScrolling = BoolPref("pref_wallpaperScrolling", true)
|
||||
val infiniteScrolling = BoolPref("pref_infiniteScrolling", false)
|
||||
val enableDebugMenu = BoolPref("pref_enableDebugMenu", false)
|
||||
val customAppName = object : MutableMapPref<ComponentKey, String>("pref_appNameMap", reloadGrid) {
|
||||
override fun flattenKey(key: ComponentKey) = key.toString()
|
||||
|
||||
@@ -89,6 +89,11 @@ fun HomeScreenPreferences(
|
||||
adapter = prefs2.doubleTapGestureHandler.getAdapter(),
|
||||
label = stringResource(id = R.string.gesture_double_tap),
|
||||
)
|
||||
SwitchPreference(
|
||||
prefs.infiniteScrolling.getAdapter(),
|
||||
label = stringResource(id = R.string.infinite_scrolling_label),
|
||||
description = stringResource(id = R.string.infinite_scrolling_description),
|
||||
)
|
||||
}
|
||||
PreferenceGroup(heading = stringResource(id = R.string.minus_one)) {
|
||||
val feedAvailable = OverlayCallbackImpl.minusOneAvailable(LocalContext.current)
|
||||
|
||||
@@ -65,6 +65,7 @@ import com.android.launcher3.views.ActivityContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import app.lawnchair.preferences.PreferenceManager;
|
||||
import app.lawnchair.ui.StretchEdgeEffect;
|
||||
|
||||
/**
|
||||
@@ -86,6 +87,8 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
|
||||
|
||||
private static final float MAX_SCROLL_PROGRESS = 1.0f;
|
||||
|
||||
private PreferenceManager prefs = PreferenceManager.getInstance(getContext());
|
||||
|
||||
private boolean mFreeScroll = false;
|
||||
|
||||
private int mFlingThresholdVelocity;
|
||||
@@ -1421,19 +1424,27 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
|
||||
// test for a large move if a fling has been registered. That is, a large
|
||||
// move to the left and fling to the right will register as a fling to the right.
|
||||
|
||||
boolean infiniteScroll = prefs.getInstance(getContext()).getInfiniteScrolling().get();
|
||||
|
||||
if (((isSignificantMove && !isDeltaLeft && !isFling) ||
|
||||
(isFling && !isVelocityLeft)) && mCurrentPage > 0) {
|
||||
finalPage = returnToOriginalPage
|
||||
? mCurrentPage : mCurrentPage - getPanelCount();
|
||||
runOnPageScrollsInitialized(
|
||||
() -> snapToPageWithVelocity(finalPage, velocity));
|
||||
} else if (((isSignificantMove && isDeltaLeft && !isFling) ||
|
||||
(isFling && isVelocityLeft)) &&
|
||||
mCurrentPage < getChildCount() - 1) {
|
||||
finalPage = returnToOriginalPage
|
||||
? mCurrentPage : mCurrentPage + getPanelCount();
|
||||
runOnPageScrollsInitialized(
|
||||
() -> snapToPageWithVelocity(finalPage, velocity));
|
||||
} else if (((isSignificantMove && isDeltaLeft && !isFling) || (isFling && isVelocityLeft)) && mCurrentPage < getChildCount() - 1) {
|
||||
|
||||
finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + getPanelCount();
|
||||
runOnPageScrollsInitialized(() -> snapToPageWithVelocity(finalPage, velocity));
|
||||
} else if (mCurrentPage == getChildCount() - 1 && infiniteScroll) {
|
||||
finalPage = returnToOriginalPage ? mCurrentPage : 0;
|
||||
snapToPageWithVelocity(finalPage, velocity);
|
||||
|
||||
|
||||
} else if (mCurrentPage == 0 && infiniteScroll) {
|
||||
finalPage = returnToOriginalPage ? mCurrentPage : getChildCount() - 1;
|
||||
snapToPageWithVelocity(finalPage, velocity);
|
||||
|
||||
} else {
|
||||
runOnPageScrollsInitialized(this::snapToDestination);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user