mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
Fullscreen swipe gestures
This commit is contained in:
parent
61334db826
commit
a051d70f48
@ -338,6 +338,13 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (PlayerHelper.swipeGestureEnabled) {
|
||||||
|
binding.playerMotionLayout.addSwipeUpListener {
|
||||||
|
exoPlayerView.hideController()
|
||||||
|
setFullscreen()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
binding.playerMotionLayout.progress = 1.toFloat()
|
binding.playerMotionLayout.progress = 1.toFloat()
|
||||||
binding.playerMotionLayout.transitionToStart()
|
binding.playerMotionLayout.transitionToStart()
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@ interface PlayerGestureOptions {
|
|||||||
|
|
||||||
fun onSwipeRightScreen(distanceY: Float)
|
fun onSwipeRightScreen(distanceY: Float)
|
||||||
|
|
||||||
|
fun onSwipeCenterScreen(distanceY: Float)
|
||||||
|
|
||||||
fun onSwipeEnd()
|
fun onSwipeEnd()
|
||||||
|
|
||||||
fun onZoom()
|
fun onZoom()
|
||||||
|
@ -35,7 +35,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
|||||||
private val scaleGestureDetector: ScaleGestureDetector
|
private val scaleGestureDetector: ScaleGestureDetector
|
||||||
|
|
||||||
private var isFullscreen = false
|
private var isFullscreen = false
|
||||||
private var isMoving = false
|
var isMoving = false
|
||||||
var isEnabled = true
|
var isEnabled = true
|
||||||
|
|
||||||
// Indicates last touch event was for click or other gesture, used to avoid single click
|
// Indicates last touch event was for click or other gesture, used to avoid single click
|
||||||
@ -155,8 +155,9 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
|||||||
wasClick = false
|
wasClick = false
|
||||||
|
|
||||||
when {
|
when {
|
||||||
width * 0.5 > e1.x -> listener.onSwipeLeftScreen(distanceY)
|
e1.x < width * 0.4 -> listener.onSwipeLeftScreen(distanceY)
|
||||||
width * 0.5 < e1.x -> listener.onSwipeRightScreen(distanceY)
|
e1.x > width * 0.6 -> listener.onSwipeRightScreen(distanceY)
|
||||||
|
else -> listener.onSwipeCenterScreen(distanceY)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import android.view.View
|
|||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.os.postDelayed
|
import androidx.core.os.postDelayed
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
@ -670,6 +671,18 @@ internal class CustomExoPlayerView(
|
|||||||
updateVolume(distanceY)
|
updateVolume(distanceY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onSwipeCenterScreen(distanceY: Float) {
|
||||||
|
if (!PlayerHelper.swipeGestureEnabled) return
|
||||||
|
|
||||||
|
if (isControllerFullyVisible) hideController()
|
||||||
|
|
||||||
|
if (distanceY < 0) {
|
||||||
|
playerGestureController.isMoving = false
|
||||||
|
(context as? AppCompatActivity)?.onBackPressedDispatcher?.onBackPressed()
|
||||||
|
playerViewModel?.isFullscreen?.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onSwipeEnd() {
|
override fun onSwipeEnd() {
|
||||||
gestureViewBinding.brightnessControlView.visibility = View.GONE
|
gestureViewBinding.brightnessControlView.visibility = View.GONE
|
||||||
gestureViewBinding.volumeControlView.visibility = View.GONE
|
gestureViewBinding.volumeControlView.visibility = View.GONE
|
||||||
|
@ -19,6 +19,7 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
|
|||||||
private val viewRect = Rect()
|
private val viewRect = Rect()
|
||||||
private var touchStarted = false
|
private var touchStarted = false
|
||||||
private val transitionListenerList = mutableListOf<TransitionListener?>()
|
private val transitionListenerList = mutableListOf<TransitionListener?>()
|
||||||
|
private val swipeUpListener = mutableListOf<() -> Unit>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
addTransitionListener(object : TransitionListener {
|
addTransitionListener(object : TransitionListener {
|
||||||
@ -87,9 +88,26 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
|
|||||||
transitionToStart()
|
transitionToStart()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onScroll(
|
||||||
|
e1: MotionEvent,
|
||||||
|
e2: MotionEvent,
|
||||||
|
distanceX: Float,
|
||||||
|
distanceY: Float
|
||||||
|
): Boolean {
|
||||||
|
if (progress != 0F || distanceY < 30F) return false
|
||||||
|
swipeUpListener.forEach {
|
||||||
|
it.invoke()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val gestureDetector = GestureDetector(context, Listener())
|
fun addSwipeUpListener(listener: () -> Unit) {
|
||||||
|
swipeUpListener.add(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val gestureDetector = GestureDetector(context, Listener())
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user