From 3f146c76186d537f590f3f9026851ea9e8f0fce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Fri, 25 Aug 2023 09:45:22 +0200 Subject: [PATCH] Prevent widget long press while changing pages --- .../simplemobiletools/launcher/views/HomeScreenGrid.kt | 9 ++++++++- .../launcher/views/MyAppWidgetHostView.kt | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt index 820e9d4..6fcaad5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -75,7 +75,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel getWidth = { width }, getHandler = { handler }, getNextPageBound = { right - sideMargins.right - cellWidth / 2 }, - getPrevPageBound = { left + sideMargins.left + cellWidth / 2 } + getPrevPageBound = { left + sideMargins.left + cellWidth / 2 }, + pageChangeStarted = { widgetViews.forEach { it.resetTouches() } } ) // apply fake margins at the home screen. Real ones would cause the icons be cut at dragging at screen sides @@ -862,6 +863,10 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel } fun isClickingGridItem(x: Int, y: Int): HomeScreenGridItem? { + if (pager.isAnimatingPageChange() || pager.isSwiped()) { + return null + } + for (gridItem in gridItems.filter { it.page == pager.getCurrentPage() || it.docked }) { if (gridItem.outOfBounds()) { continue @@ -995,6 +1000,7 @@ private class AnimatedGridPager( private val getHandler: () -> Handler, private val getNextPageBound: () -> Int, private val getPrevPageBound: () -> Int, + private val pageChangeStarted: () -> Unit, ) { companion object { @@ -1244,6 +1250,7 @@ private class AnimatedGridPager( val startingAt = 1 - abs(pageChangeSwipedPercentage) pageChangeSwipedPercentage = 0f getHandler().removeCallbacks(startFadingIndicators) + pageChangeStarted() if (redraw) { redrawGrid() } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt index 13e7ad6..112836d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt @@ -68,4 +68,8 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) { longPressListener?.invoke(actionDownCoords.x, actionDownCoords.y) } } + + fun resetTouches() { + longPressHandler.removeCallbacksAndMessages(null) + } }