mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Fix single tap on scroll or pinch gesture
Keep track whether the last touch event was for click or other gesture which can be used by runnable.
This commit is contained in:
parent
e925d72d0b
commit
677a01a055
@ -34,6 +34,10 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
|||||||
private var isMoving = false
|
private var isMoving = false
|
||||||
var isEnabled = true
|
var isEnabled = true
|
||||||
|
|
||||||
|
// Indicates last touch event was for click or other gesture, used to avoid single click
|
||||||
|
// by runnable when scroll or pinch gesture already completed.
|
||||||
|
var wasClick = true
|
||||||
|
|
||||||
init {
|
init {
|
||||||
gestureDetector = GestureDetector(activity, GestureListener(), handler)
|
gestureDetector = GestureDetector(activity, GestureListener(), handler)
|
||||||
scaleGestureDetector = ScaleGestureDetector(activity, ScaleGestureListener(), handler)
|
scaleGestureDetector = ScaleGestureDetector(activity, ScaleGestureListener(), handler)
|
||||||
@ -66,6 +70,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
|||||||
var scaleFactor: Float = 1f
|
var scaleFactor: Float = 1f
|
||||||
|
|
||||||
override fun onScale(detector: ScaleGestureDetector): Boolean {
|
override fun onScale(detector: ScaleGestureDetector): Boolean {
|
||||||
|
wasClick = false
|
||||||
scaleFactor *= detector.scaleFactor
|
scaleFactor *= detector.scaleFactor
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -89,6 +94,9 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
|||||||
private var xPos = 0.0F
|
private var xPos = 0.0F
|
||||||
|
|
||||||
override fun onDown(e: MotionEvent): Boolean {
|
override fun onDown(e: MotionEvent): Boolean {
|
||||||
|
// Initially assume this event is for click
|
||||||
|
wasClick = true
|
||||||
|
|
||||||
if (isMoving || scaleGestureDetector.isInProgress) return false
|
if (isMoving || scaleGestureDetector.isInProgress) return false
|
||||||
|
|
||||||
if (isEnabled && isSecondClick()) {
|
if (isEnabled && isSecondClick()) {
|
||||||
@ -135,6 +143,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
|||||||
}
|
}
|
||||||
|
|
||||||
isMoving = true
|
isMoving = true
|
||||||
|
wasClick = false
|
||||||
|
|
||||||
when {
|
when {
|
||||||
width * 0.5 > e1.x -> listener.onSwipeLeftScreen(distanceY)
|
width * 0.5 > e1.x -> listener.onSwipeLeftScreen(distanceY)
|
||||||
@ -144,8 +153,8 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val runnable = Runnable {
|
private val runnable = Runnable {
|
||||||
// If user is scrolling then avoid single tap call
|
// If the last event was for scroll or pinch then avoid single tap call
|
||||||
if (isMoving || isSecondClick()) return@Runnable
|
if (!wasClick || isSecondClick()) return@Runnable
|
||||||
listener.onSingleTap()
|
listener.onSingleTap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user