Merge pull request #3017 from Bnyro/master

Enter/Exit Fullscreen swipe gestures
This commit is contained in:
Bnyro 2023-02-10 18:54:02 +01:00 committed by GitHub
commit d705dc167a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 4 deletions

View File

@ -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()

View File

@ -14,6 +14,8 @@ interface PlayerGestureOptions {
fun onSwipeRightScreen(distanceY: Float)
fun onSwipeCenterScreen(distanceY: Float)
fun onSwipeEnd()
fun onZoom()

View File

@ -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
}

View File

@ -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

View File

@ -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 {