mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
fix accidential volume/brightness changes when zooming
This commit is contained in:
parent
ce66873ef3
commit
2ebebb4b42
@ -14,7 +14,7 @@ import android.view.View
|
|||||||
import com.github.libretube.ui.interfaces.PlayerGestureOptions
|
import com.github.libretube.ui.interfaces.PlayerGestureOptions
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class PlayerGestureController(context: Context, private val listner: PlayerGestureOptions) :
|
class PlayerGestureController(context: Context, private val listener: PlayerGestureOptions) :
|
||||||
View.OnTouchListener {
|
View.OnTouchListener {
|
||||||
|
|
||||||
// width and height should be obtained each time using getter to adopt layout size changes.
|
// width and height should be obtained each time using getter to adopt layout size changes.
|
||||||
@ -38,13 +38,13 @@ class PlayerGestureController(context: Context, private val listner: PlayerGestu
|
|||||||
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
||||||
if (event.action == MotionEvent.ACTION_UP && isMoving) {
|
if (event.action == MotionEvent.ACTION_UP && isMoving) {
|
||||||
isMoving = false
|
isMoving = false
|
||||||
listner.onSwipeEnd()
|
listener.onSwipeEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event can be already consumed by some view which may lead to NPE.
|
// Event can be already consumed by some view which may lead to NPE.
|
||||||
try {
|
try {
|
||||||
val consumed = gestureDetector.onTouchEvent(event)
|
scaleGestureDetector.onTouchEvent(event)
|
||||||
if (!consumed) scaleGestureDetector.onTouchEvent(event)
|
gestureDetector.onTouchEvent(event)
|
||||||
} catch (_: Exception) { }
|
} catch (_: Exception) { }
|
||||||
|
|
||||||
// If orientation is landscape then allow `onScroll` to consume event and return true.
|
// If orientation is landscape then allow `onScroll` to consume event and return true.
|
||||||
@ -65,8 +65,8 @@ class PlayerGestureController(context: Context, private val listner: PlayerGestu
|
|||||||
|
|
||||||
override fun onScaleEnd(detector: ScaleGestureDetector) {
|
override fun onScaleEnd(detector: ScaleGestureDetector) {
|
||||||
when {
|
when {
|
||||||
scaleFactor < 0.8 -> listner.onMinimize()
|
scaleFactor < 0.8 -> listener.onMinimize()
|
||||||
scaleFactor > 1.2 -> listner.onZoom()
|
scaleFactor > 1.2 -> listener.onZoom()
|
||||||
}
|
}
|
||||||
scaleFactor = 1f
|
scaleFactor = 1f
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ class PlayerGestureController(context: Context, private val listner: PlayerGestu
|
|||||||
private var xPos = 0.0F
|
private var xPos = 0.0F
|
||||||
|
|
||||||
override fun onDown(e: MotionEvent): Boolean {
|
override fun onDown(e: MotionEvent): Boolean {
|
||||||
if (isMoving) return false
|
if (isMoving || scaleGestureDetector.isInProgress) return false
|
||||||
|
|
||||||
if (isEnabled && isSecondClick()) {
|
if (isEnabled && isSecondClick()) {
|
||||||
handler.removeCallbacks(runnable)
|
handler.removeCallbacks(runnable)
|
||||||
@ -86,9 +86,9 @@ class PlayerGestureController(context: Context, private val listner: PlayerGestu
|
|||||||
val eventPositionPercentageX = xPos / width
|
val eventPositionPercentageX = xPos / width
|
||||||
|
|
||||||
when {
|
when {
|
||||||
eventPositionPercentageX < 0.4 -> listner.onDoubleTapLeftScreen()
|
eventPositionPercentageX < 0.4 -> listener.onDoubleTapLeftScreen()
|
||||||
eventPositionPercentageX > 0.6 -> listner.onDoubleTapRightScreen()
|
eventPositionPercentageX > 0.6 -> listener.onDoubleTapRightScreen()
|
||||||
else -> listner.onDoubleTapCenterScreen()
|
else -> listener.onDoubleTapCenterScreen()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (recentDoubleClick()) return true
|
if (recentDoubleClick()) return true
|
||||||
@ -106,7 +106,7 @@ class PlayerGestureController(context: Context, private val listner: PlayerGestu
|
|||||||
distanceX: Float,
|
distanceX: Float,
|
||||||
distanceY: Float
|
distanceY: Float
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (!isEnabled) return false
|
if (!isEnabled || scaleGestureDetector.isInProgress) return false
|
||||||
|
|
||||||
val insideThreshHold = abs(e2.y - e1.y) <= MOVEMENT_THRESHOLD
|
val insideThreshHold = abs(e2.y - e1.y) <= MOVEMENT_THRESHOLD
|
||||||
val insideBorder = (e1.x < BORDER_THRESHOLD || e1.y < BORDER_THRESHOLD || e1.x > width - BORDER_THRESHOLD || e1.y > height - BORDER_THRESHOLD)
|
val insideBorder = (e1.x < BORDER_THRESHOLD || e1.y < BORDER_THRESHOLD || e1.x > width - BORDER_THRESHOLD || e1.y > height - BORDER_THRESHOLD)
|
||||||
@ -126,8 +126,8 @@ class PlayerGestureController(context: Context, private val listner: PlayerGestu
|
|||||||
isMoving = true
|
isMoving = true
|
||||||
|
|
||||||
when {
|
when {
|
||||||
width * 0.5 > e1.x -> listner.onSwipeLeftScreen(distanceY)
|
width * 0.5 > e1.x -> listener.onSwipeLeftScreen(distanceY)
|
||||||
width * 0.5 < e1.x -> listner.onSwipeRightScreen(distanceY)
|
width * 0.5 < e1.x -> listener.onSwipeRightScreen(distanceY)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ class PlayerGestureController(context: Context, private val listner: PlayerGestu
|
|||||||
private val runnable = Runnable {
|
private val runnable = Runnable {
|
||||||
// If user is scrolling then avoid single tap call
|
// If user is scrolling then avoid single tap call
|
||||||
if (isMoving || isSecondClick()) return@Runnable
|
if (isMoving || isSecondClick()) return@Runnable
|
||||||
listner.onSingleTap()
|
listener.onSingleTap()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isSecondClick(): Boolean {
|
private fun isSecondClick(): Boolean {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user