From f245d7ef5ba4349ff6cb3b38f862736a2c5dc281 Mon Sep 17 00:00:00 2001 From: RafaRamos Date: Mon, 8 Jan 2024 11:31:25 +0100 Subject: [PATCH] Ensure mini-player is only closed when swiping strictly down, from the collapsed state. --- .../ui/views/SingleViewTouchableMotionLayout.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt b/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt index f52f0787a..7a7f05dac 100644 --- a/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt +++ b/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt @@ -23,6 +23,9 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS private val swipeUpListener = mutableListOf<() -> Unit>() private val swipeDownListener = mutableListOf<() -> Unit>() + private var startedMinimized = false + private var isStrictlyDownSwipe = false + init { addTransitionListener(object : TransitionAdapter() { override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) { @@ -65,7 +68,11 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS distanceY: Float ): Boolean { - if (distanceY < -15F) { + if (isStrictlyDownSwipe && distanceY > 0) { + isStrictlyDownSwipe = false + } + + if (isStrictlyDownSwipe && startedMinimized && distanceY < -15F) { swipeDownListener.forEach { it.invoke() } return true } @@ -101,6 +108,10 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS touchStarted = false return super.onTouchEvent(event) } + MotionEvent.ACTION_DOWN -> { + isStrictlyDownSwipe = true + startedMinimized = progress == 1F + } } if (!touchStarted) { viewToDetectTouch.getHitRect(viewRect)