From 9cf86a76752365bae74e343d0b6fe3f122f04fa4 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 17 Jul 2022 11:10:46 +0200 Subject: [PATCH 1/3] new icon for open --- app/src/main/res/drawable/ic_open.xml | 28 +++++++++++++++++++++ app/src/main/res/layout/fragment_player.xml | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_open.xml 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" /> Date: Sun, 17 Jul 2022 11:39:55 +0200 Subject: [PATCH 2/3] switch to gesture listener --- .../libretube/fragments/PlayerFragment.kt | 79 +++++++++++-------- .../libretube/views/DoubleClickListener.kt | 51 ------------ 2 files changed, 48 insertions(+), 82 deletions(-) delete mode 100644 app/src/main/java/com/github/libretube/views/DoubleClickListener.kt 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..bd50763b1 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 @@ -982,44 +984,59 @@ class PlayerFragment : Fragment() { private fun enableDoubleTapToSeek() { 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) - } - - override fun singleClicked() { - toggleController() - } + val rewindGestureDetector = GestureDetector( + context, + object : SimpleOnGestureListener() { + override fun onDoubleTap(e: MotionEvent): Boolean { + binding.rewindBTN.visibility = View.VISIBLE + exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement) + Handler(Looper.getMainLooper()).postDelayed({ + binding.rewindBTN.visibility = View.INVISIBLE + }, 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 { + binding.forwardBTN.visibility = View.VISIBLE + exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement) + Handler(Looper.getMainLooper()).postDelayed({ + binding.forwardBTN.visibility = View.INVISIBLE + }, hideDoubleTapOverlayDelay) + return super.onSingleTapConfirmed(e) } - ) + + override fun onSingleTapConfirmed(e: MotionEvent?): Boolean { + toggleController() + return super.onSingleTapConfirmed(e) + } + } ) + + binding.forwardFL.setOnTouchListener { view, event -> + forwardGestureDetector.onTouchEvent(event) + view.performClick() + true + } } private fun disableDoubleTapToSeek() { 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() - } -} From a705b29b95549e87cf837a4c25823e9598ce9785 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 17 Jul 2022 12:02:49 +0200 Subject: [PATCH 3/3] improve when the buttons show --- .../libretube/fragments/PlayerFragment.kt | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) 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 bd50763b1..addc10160 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -984,6 +984,7 @@ class PlayerFragment : Fragment() { private fun enableDoubleTapToSeek() { val seekIncrement = PreferenceHelper.getString(requireContext(), "seek_increment", "5")?.toLong()!! * 1000 + val hideDoubleTapOverlayDelay = 700L // enable rewind button @@ -991,11 +992,14 @@ class PlayerFragment : Fragment() { context, object : SimpleOnGestureListener() { override fun onDoubleTap(e: MotionEvent): Boolean { - binding.rewindBTN.visibility = View.VISIBLE exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement) - Handler(Looper.getMainLooper()).postDelayed({ - binding.rewindBTN.visibility = View.INVISIBLE - }, hideDoubleTapOverlayDelay) + + // show the rewind button + binding.rewindBTN.apply { + visibility = View.VISIBLE + removeCallbacks(hideRewindButtonRunnable) + postDelayed(hideRewindButtonRunnable, hideDoubleTapOverlayDelay) + } return super.onDoubleTap(e) } @@ -1017,12 +1021,15 @@ class PlayerFragment : Fragment() { context, object : SimpleOnGestureListener() { override fun onDoubleTap(e: MotionEvent): Boolean { - binding.forwardBTN.visibility = View.VISIBLE exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement) - Handler(Looper.getMainLooper()).postDelayed({ - binding.forwardBTN.visibility = View.INVISIBLE - }, hideDoubleTapOverlayDelay) - return super.onSingleTapConfirmed(e) + + // 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 { @@ -1039,6 +1046,9 @@ class PlayerFragment : Fragment() { } } + 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