diff --git a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt index c42e4e59a..0a737e5dd 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt @@ -243,6 +243,10 @@ class AudioPlayerFragment : BaseFragment(), AudioPlayerOptions { } override fun onSingleTap() { + if (isPaused) playerService?.play() else playerService?.pause() + } + + override fun onLongTap() { val current = PlayingQueue.getCurrent() VideoOptionsBottomSheet(current?.url?.toID() ?: return, current.title ?: return) .show(childFragmentManager) diff --git a/app/src/main/java/com/github/libretube/ui/interfaces/AudioPlayerOptions.kt b/app/src/main/java/com/github/libretube/ui/interfaces/AudioPlayerOptions.kt index eddb6387b..91a0198fb 100644 --- a/app/src/main/java/com/github/libretube/ui/interfaces/AudioPlayerOptions.kt +++ b/app/src/main/java/com/github/libretube/ui/interfaces/AudioPlayerOptions.kt @@ -4,6 +4,8 @@ interface AudioPlayerOptions { fun onSingleTap() + fun onLongTap() + fun onSwipe(distanceY: Float) fun onSwipeEnd() diff --git a/app/src/main/java/com/github/libretube/ui/listeners/AudioPlayerThumbnailListener.kt b/app/src/main/java/com/github/libretube/ui/listeners/AudioPlayerThumbnailListener.kt index 464bbcdf8..05e747704 100644 --- a/app/src/main/java/com/github/libretube/ui/listeners/AudioPlayerThumbnailListener.kt +++ b/app/src/main/java/com/github/libretube/ui/listeners/AudioPlayerThumbnailListener.kt @@ -7,6 +7,7 @@ import android.os.Looper import android.view.GestureDetector import android.view.MotionEvent import android.view.View +import android.view.ViewConfiguration import androidx.core.os.postDelayed import com.github.libretube.ui.interfaces.AudioPlayerOptions import kotlin.math.abs @@ -36,10 +37,9 @@ class AudioPlayerThumbnailListener(context: Context, private val listener: Audio private inner class GestureListener : GestureDetector.SimpleOnGestureListener() { override fun onDown(e: MotionEvent): Boolean { - // Initially assume this event is for click if (isMoving) return false - handler.postDelayed(300) { + handler.postDelayed(ACTION_INTERVAL, SINGLE_PRESS_TOKEN) { if (!isMoving) listener.onSingleTap() } @@ -64,9 +64,18 @@ class AudioPlayerThumbnailListener(context: Context, private val listener: Audio listener.onSwipe(distanceY) return true } + + override fun onLongPress(e: MotionEvent) { + // remove to single press action from the queue + handler.removeCallbacksAndMessages(SINGLE_PRESS_TOKEN) + + listener.onLongTap() + } } companion object { private const val MOVEMENT_THRESHOLD = 10 + private val ACTION_INTERVAL = ViewConfiguration.getLongPressTimeout().toLong() + private const val SINGLE_PRESS_TOKEN = "singlePress" } }