mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #3017 from Bnyro/master
Enter/Exit Fullscreen swipe gestures
This commit is contained in:
commit
d705dc167a
@ -338,6 +338,13 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
}
|
||||
})
|
||||
|
||||
if (PlayerHelper.swipeGestureEnabled) {
|
||||
binding.playerMotionLayout.addSwipeUpListener {
|
||||
exoPlayerView.hideController()
|
||||
setFullscreen()
|
||||
}
|
||||
}
|
||||
|
||||
binding.playerMotionLayout.progress = 1.toFloat()
|
||||
binding.playerMotionLayout.transitionToStart()
|
||||
|
||||
|
@ -14,6 +14,8 @@ interface PlayerGestureOptions {
|
||||
|
||||
fun onSwipeRightScreen(distanceY: Float)
|
||||
|
||||
fun onSwipeCenterScreen(distanceY: Float)
|
||||
|
||||
fun onSwipeEnd()
|
||||
|
||||
fun onZoom()
|
||||
|
@ -35,7 +35,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
|
||||
private val scaleGestureDetector: ScaleGestureDetector
|
||||
|
||||
private var isFullscreen = false
|
||||
private var isMoving = false
|
||||
var isMoving = false
|
||||
var isEnabled = true
|
||||
|
||||
// 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
|
||||
|
||||
when {
|
||||
width * 0.5 > e1.x -> listener.onSwipeLeftScreen(distanceY)
|
||||
width * 0.5 < e1.x -> listener.onSwipeRightScreen(distanceY)
|
||||
e1.x < width * 0.4 -> listener.onSwipeLeftScreen(distanceY)
|
||||
e1.x > width * 0.6 -> listener.onSwipeRightScreen(distanceY)
|
||||
else -> listener.onSwipeCenterScreen(distanceY)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.os.postDelayed
|
||||
import androidx.core.view.updateLayoutParams
|
||||
@ -670,6 +671,18 @@ internal class CustomExoPlayerView(
|
||||
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() {
|
||||
gestureViewBinding.brightnessControlView.visibility = View.GONE
|
||||
gestureViewBinding.volumeControlView.visibility = View.GONE
|
||||
|
@ -19,6 +19,7 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
|
||||
private val viewRect = Rect()
|
||||
private var touchStarted = false
|
||||
private val transitionListenerList = mutableListOf<TransitionListener?>()
|
||||
private val swipeUpListener = mutableListOf<() -> Unit>()
|
||||
|
||||
init {
|
||||
addTransitionListener(object : TransitionListener {
|
||||
@ -87,9 +88,26 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
|
||||
transitionToStart()
|
||||
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")
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user