mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-07 18:10:31 +05:30
Play and pause the video on single touches
This commit is contained in:
parent
288067b044
commit
1403c3bc1c
@ -243,6 +243,10 @@ class AudioPlayerFragment : BaseFragment(), AudioPlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSingleTap() {
|
override fun onSingleTap() {
|
||||||
|
if (isPaused) playerService?.play() else playerService?.pause()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLongTap() {
|
||||||
val current = PlayingQueue.getCurrent()
|
val current = PlayingQueue.getCurrent()
|
||||||
VideoOptionsBottomSheet(current?.url?.toID() ?: return, current.title ?: return)
|
VideoOptionsBottomSheet(current?.url?.toID() ?: return, current.title ?: return)
|
||||||
.show(childFragmentManager)
|
.show(childFragmentManager)
|
||||||
|
@ -4,6 +4,8 @@ interface AudioPlayerOptions {
|
|||||||
|
|
||||||
fun onSingleTap()
|
fun onSingleTap()
|
||||||
|
|
||||||
|
fun onLongTap()
|
||||||
|
|
||||||
fun onSwipe(distanceY: Float)
|
fun onSwipe(distanceY: Float)
|
||||||
|
|
||||||
fun onSwipeEnd()
|
fun onSwipeEnd()
|
||||||
|
@ -7,6 +7,7 @@ import android.os.Looper
|
|||||||
import android.view.GestureDetector
|
import android.view.GestureDetector
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewConfiguration
|
||||||
import androidx.core.os.postDelayed
|
import androidx.core.os.postDelayed
|
||||||
import com.github.libretube.ui.interfaces.AudioPlayerOptions
|
import com.github.libretube.ui.interfaces.AudioPlayerOptions
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
@ -36,10 +37,9 @@ class AudioPlayerThumbnailListener(context: Context, private val listener: Audio
|
|||||||
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
||||||
|
|
||||||
override fun onDown(e: MotionEvent): Boolean {
|
override fun onDown(e: MotionEvent): Boolean {
|
||||||
// Initially assume this event is for click
|
|
||||||
if (isMoving) return false
|
if (isMoving) return false
|
||||||
|
|
||||||
handler.postDelayed(300) {
|
handler.postDelayed(ACTION_INTERVAL, SINGLE_PRESS_TOKEN) {
|
||||||
if (!isMoving) listener.onSingleTap()
|
if (!isMoving) listener.onSingleTap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,9 +64,18 @@ class AudioPlayerThumbnailListener(context: Context, private val listener: Audio
|
|||||||
listener.onSwipe(distanceY)
|
listener.onSwipe(distanceY)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onLongPress(e: MotionEvent) {
|
||||||
|
// remove to single press action from the queue
|
||||||
|
handler.removeCallbacksAndMessages(SINGLE_PRESS_TOKEN)
|
||||||
|
|
||||||
|
listener.onLongTap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val MOVEMENT_THRESHOLD = 10
|
private const val MOVEMENT_THRESHOLD = 10
|
||||||
|
private val ACTION_INTERVAL = ViewConfiguration.getLongPressTimeout().toLong()
|
||||||
|
private const val SINGLE_PRESS_TOKEN = "singlePress"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user