diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 1a4a98cae..addc10160 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -20,7 +20,10 @@ import android.support.v4.media.session.MediaSessionCompat import android.text.Html import android.text.TextUtils import android.util.Log +import android.view.GestureDetector +import android.view.GestureDetector.SimpleOnGestureListener import android.view.LayoutInflater +import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.widget.Toast @@ -62,7 +65,6 @@ import com.github.libretube.util.DescriptionAdapter import com.github.libretube.util.PlayerHelper import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.formatShort -import com.github.libretube.views.DoubleClickListener import com.google.android.exoplayer2.C import com.google.android.exoplayer2.DefaultLoadControl import com.google.android.exoplayer2.ExoPlayer @@ -983,45 +985,70 @@ class PlayerFragment : Fragment() { val seekIncrement = PreferenceHelper.getString(requireContext(), "seek_increment", "5")?.toLong()!! * 1000 + val hideDoubleTapOverlayDelay = 700L + // enable rewind button - binding.rewindFL.setOnClickListener( - DoubleClickListener( - callback = object : DoubleClickListener.Callback { - override fun doubleClicked() { - binding.rewindBTN.visibility = View.VISIBLE - exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement) - Handler(Looper.getMainLooper()).postDelayed({ - binding.rewindBTN.visibility = View.INVISIBLE - }, 700) - } + val rewindGestureDetector = GestureDetector( + context, + object : SimpleOnGestureListener() { + override fun onDoubleTap(e: MotionEvent): Boolean { + exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement) - override fun singleClicked() { - toggleController() + // show the rewind button + binding.rewindBTN.apply { + visibility = View.VISIBLE + removeCallbacks(hideRewindButtonRunnable) + postDelayed(hideRewindButtonRunnable, hideDoubleTapOverlayDelay) } + return super.onDoubleTap(e) } - ) + + override fun onSingleTapConfirmed(e: MotionEvent?): Boolean { + toggleController() + return super.onSingleTapConfirmed(e) + } + } ) - // enable fast forward button - binding.forwardFL.setOnClickListener( - DoubleClickListener( - callback = object : DoubleClickListener.Callback { - override fun doubleClicked() { - binding.forwardBTN.visibility = View.VISIBLE - exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement) - Handler(Looper.getMainLooper()).postDelayed({ - binding.forwardBTN.visibility = View.INVISIBLE - }, 700) - } + binding.rewindFL.setOnTouchListener { view, event -> + rewindGestureDetector.onTouchEvent(event) + view.performClick() + true + } - override fun singleClicked() { - toggleController() + // enable forward button + val forwardGestureDetector = GestureDetector( + context, + object : SimpleOnGestureListener() { + override fun onDoubleTap(e: MotionEvent): Boolean { + exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement) + + // show the forward button + binding.forwardBTN.apply { + visibility = View.VISIBLE + removeCallbacks(hideForwardButtonRunnable) + postDelayed(hideForwardButtonRunnable, hideDoubleTapOverlayDelay) } + return super.onDoubleTap(e) } - ) + + override fun onSingleTapConfirmed(e: MotionEvent?): Boolean { + toggleController() + return super.onSingleTapConfirmed(e) + } + } ) + + binding.forwardFL.setOnTouchListener { view, event -> + forwardGestureDetector.onTouchEvent(event) + view.performClick() + true + } } + private val hideForwardButtonRunnable = Runnable { binding.forwardBTN.visibility = View.GONE } + private val hideRewindButtonRunnable = Runnable { binding.rewindBTN.visibility = View.GONE } + private fun disableDoubleTapToSeek() { // disable fast forward and rewind by double tapping binding.forwardFL.visibility = View.GONE diff --git a/app/src/main/java/com/github/libretube/views/DoubleClickListener.kt b/app/src/main/java/com/github/libretube/views/DoubleClickListener.kt deleted file mode 100644 index 808ef2320..000000000 --- a/app/src/main/java/com/github/libretube/views/DoubleClickListener.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.github.libretube.views - -import android.os.Handler -import android.os.Looper -import android.view.View - -class DoubleClickListener( - private val doubleClickTimeLimitMills: Long = 200, - private val callback: Callback -) : View.OnClickListener { - private var lastClicked: Long = -1L - - override fun onClick(v: View?) { - lastClicked = when { - lastClicked == -1L -> { - checkForSingleClick() - System.currentTimeMillis() - } - isDoubleClicked() -> { - callback.doubleClicked() - -1L - } - else -> { - checkForSingleClick() - System.currentTimeMillis() - } - } - } - - private fun checkForSingleClick() { - Handler(Looper.getMainLooper()).postDelayed({ - if (lastClicked != -1L) callback.singleClicked() - }, doubleClickTimeLimitMills) - } - - private fun getTimeDiff(from: Long, to: Long): Long { - return to - from - } - - private fun isDoubleClicked(): Boolean { - return getTimeDiff( - lastClicked, - System.currentTimeMillis() - ) <= doubleClickTimeLimitMills - } - - interface Callback { - fun doubleClicked() - fun singleClicked() - } -} diff --git a/app/src/main/res/drawable/ic_open.xml b/app/src/main/res/drawable/ic_open.xml new file mode 100644 index 000000000..332a0f27a --- /dev/null +++ b/app/src/main/res/drawable/ic_open.xml @@ -0,0 +1,28 @@ + + + + + diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 35811e6c4..8f51f28c6 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -192,7 +192,7 @@ android:layout_width="24dp" android:layout_height="25dp" android:padding="2dp" - android:src="@drawable/ic_videocam" /> + android:src="@drawable/ic_open" />