mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 13:50:30 +05:30
Merge pull request #6480 from Bnyro/master
fix: double click gesture inaccurate in landscape player
This commit is contained in:
commit
37f8bb20c4
@ -23,4 +23,11 @@ interface PlayerGestureOptions {
|
||||
fun onMinimize()
|
||||
|
||||
fun onFullscreenChange(isFullscreen: Boolean)
|
||||
|
||||
/**
|
||||
* Returns a pair of the width and height of the view this listener is used for
|
||||
* These measures change when the screen orientation changes or fullscreen is entered, thus
|
||||
* needs to be refreshed manually all the time when needed.
|
||||
*/
|
||||
fun getViewMeasures(): Pair<Int, Int>
|
||||
}
|
||||
|
@ -21,10 +21,6 @@ import kotlin.math.abs
|
||||
class PlayerGestureController(activity: BaseActivity, private val listener: PlayerGestureOptions) :
|
||||
View.OnTouchListener {
|
||||
|
||||
// width and height should be obtained each time using getter to adopt layout
|
||||
// size changes.
|
||||
private val width get() = Resources.getSystem().displayMetrics.widthPixels
|
||||
private val height get() = Resources.getSystem().displayMetrics.heightPixels
|
||||
private val orientation get() = Resources.getSystem().configuration.orientation
|
||||
private val elapsedTime get() = SystemClock.elapsedRealtime()
|
||||
|
||||
@ -59,6 +55,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
||||
listener.onSwipeEnd()
|
||||
}
|
||||
|
||||
val (_, height) = listener.getViewMeasures()
|
||||
// ignore touches to the top of the player when in landscape mode
|
||||
if (event.y < height * 0.1 && orientation == Configuration.ORIENTATION_LANDSCAPE) return false
|
||||
|
||||
@ -75,7 +72,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
||||
}
|
||||
|
||||
private inner class ScaleGestureListener : ScaleGestureDetector.OnScaleGestureListener {
|
||||
var scaleFactor: Float = 1f
|
||||
var scaleFactor = 1f
|
||||
|
||||
override fun onScale(detector: ScaleGestureDetector): Boolean {
|
||||
wasClick = false
|
||||
@ -111,6 +108,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
||||
return true
|
||||
}
|
||||
|
||||
val (width, _) = listener.getViewMeasures()
|
||||
if (isEnabled && isSecondClick()) {
|
||||
handler.removeCallbacksAndMessages(SINGLE_TAP_TOKEN)
|
||||
lastDoubleClick = elapsedTime
|
||||
@ -142,6 +140,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
||||
): Boolean {
|
||||
if (!isEnabled || scaleGestureDetector.isInProgress) return false
|
||||
|
||||
val (width, height) = listener.getViewMeasures()
|
||||
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)
|
||||
|
@ -834,6 +834,10 @@ abstract class CustomExoPlayerView(
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getViewMeasures(): Pair<Int, Int> {
|
||||
return width to height
|
||||
}
|
||||
|
||||
open fun onPlaybackEvents(player: Player, events: Player.Events) {
|
||||
if (events.containsAny(
|
||||
Player.EVENT_PLAYBACK_STATE_CHANGED,
|
||||
|
Loading…
Reference in New Issue
Block a user