mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Supports close video on MiniPlayer swipe down
This commit is contained in:
parent
bd2b0eb163
commit
84dbabe23e
@ -0,0 +1,23 @@
|
|||||||
|
package com.github.libretube.ui.extensions
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function animates a view in a downward direction by a specified amount.
|
||||||
|
*
|
||||||
|
* @param duration The duration of the animation in milliseconds.
|
||||||
|
* @param dy The distance to move the view along the Y-axis.
|
||||||
|
* @param onEnd An optional lambda function that is invoked when the animation ends.
|
||||||
|
*/
|
||||||
|
fun View.animateDown(
|
||||||
|
duration: Long,
|
||||||
|
dy: Float,
|
||||||
|
onEnd: () -> Unit = { }
|
||||||
|
) {
|
||||||
|
this
|
||||||
|
.animate()
|
||||||
|
.withEndAction { onEnd.invoke() }
|
||||||
|
.y(dy)
|
||||||
|
.setDuration(duration)
|
||||||
|
.start()
|
||||||
|
}
|
@ -97,6 +97,7 @@ import com.github.libretube.ui.base.BaseActivity
|
|||||||
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
|
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
|
||||||
import com.github.libretube.ui.dialogs.DownloadDialog
|
import com.github.libretube.ui.dialogs.DownloadDialog
|
||||||
import com.github.libretube.ui.dialogs.ShareDialog
|
import com.github.libretube.ui.dialogs.ShareDialog
|
||||||
|
import com.github.libretube.ui.extensions.animateDown
|
||||||
import com.github.libretube.ui.extensions.setupSubscriptionButton
|
import com.github.libretube.ui.extensions.setupSubscriptionButton
|
||||||
import com.github.libretube.ui.interfaces.OnlinePlayerOptions
|
import com.github.libretube.ui.interfaces.OnlinePlayerOptions
|
||||||
import com.github.libretube.ui.listeners.SeekbarPreviewListener
|
import com.github.libretube.ui.listeners.SeekbarPreviewListener
|
||||||
@ -461,12 +462,18 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
binding.playerMotionLayout.addSwipeUpListener {
|
binding.playerMotionLayout
|
||||||
if (this::streams.isInitialized && PlayerHelper.fullscreenGesturesEnabled) {
|
.addSwipeUpListener {
|
||||||
binding.player.hideController()
|
if (this::streams.isInitialized && PlayerHelper.fullscreenGesturesEnabled) {
|
||||||
setFullscreen()
|
binding.player.hideController()
|
||||||
|
setFullscreen()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.addSwipeDownListener {
|
||||||
|
if (viewModel.isMiniPlayerVisible.value == true) {
|
||||||
|
closeMiniPlayer()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
binding.playerMotionLayout.progress = 1F
|
binding.playerMotionLayout.progress = 1F
|
||||||
binding.playerMotionLayout.transitionToStart()
|
binding.playerMotionLayout.transitionToStart()
|
||||||
@ -477,6 +484,16 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun closeMiniPlayer() {
|
||||||
|
binding
|
||||||
|
.playerMotionLayout
|
||||||
|
.animateDown(
|
||||||
|
duration = 300L,
|
||||||
|
dy = 500F,
|
||||||
|
onEnd = ::killPlayerFragment,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun onManualPlayerClose() {
|
private fun onManualPlayerClose() {
|
||||||
PlayingQueue.clear()
|
PlayingQueue.clear()
|
||||||
BackgroundHelper.stopBackgroundPlay(requireContext())
|
BackgroundHelper.stopBackgroundPlay(requireContext())
|
||||||
|
@ -21,6 +21,7 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
|
|||||||
private var touchStarted = false
|
private var touchStarted = false
|
||||||
private val transitionListenerList = mutableListOf<TransitionListener?>()
|
private val transitionListenerList = mutableListOf<TransitionListener?>()
|
||||||
private val swipeUpListener = mutableListOf<() -> Unit>()
|
private val swipeUpListener = mutableListOf<() -> Unit>()
|
||||||
|
private val swipeDownListener = mutableListOf<() -> Unit>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
addTransitionListener(object : TransitionAdapter() {
|
addTransitionListener(object : TransitionAdapter() {
|
||||||
@ -63,18 +64,29 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
|
|||||||
distanceX: Float,
|
distanceX: Float,
|
||||||
distanceY: Float
|
distanceY: Float
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (progress != 0F || distanceY < 30F) return false
|
|
||||||
swipeUpListener.forEach {
|
if (distanceY < -15F) {
|
||||||
it.invoke()
|
swipeDownListener.forEach { it.invoke() }
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
|
if (progress == 0F && distanceY > 30F) {
|
||||||
|
swipeUpListener.forEach { it.invoke() }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addSwipeUpListener(listener: () -> Unit) {
|
fun addSwipeUpListener(listener: () -> Unit) = apply {
|
||||||
swipeUpListener.add(listener)
|
swipeUpListener.add(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addSwipeDownListener(listener: () -> Unit) = apply {
|
||||||
|
swipeDownListener.add(listener)
|
||||||
|
}
|
||||||
|
|
||||||
private val gestureDetector = GestureDetector(context, Listener())
|
private val gestureDetector = GestureDetector(context, Listener())
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user