From 9d9709be7bfed8d19cab209c69da677dc6fc0364 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 27 Nov 2022 18:41:34 +0100 Subject: [PATCH] Option to disable double tap to seek --- .../libretube/constants/PreferenceKeys.kt | 1 + .../libretube/ui/views/CustomExoPlayerView.kt | 38 +++++++++--- .../com/github/libretube/util/PlayerHelper.kt | 6 ++ .../layout/exo_styled_player_control_view.xml | 58 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/player_settings.xml | 9 ++- 6 files changed, 103 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt index dd4f0e7be..905379e7d 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -86,6 +86,7 @@ object PreferenceKeys { const val PLAYER_SWIPE_CONTROLS = "player_swipe_controls" const val PLAYER_SCREEN_BRIGHTNESS = "player_screen_brightness" const val CAPTIONS_SIZE = "captions_size" + const val DOUBLE_TAP_TO_SEEK = "double_tap_seek" /** * Background mode diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index f7ebb754c..0223726aa 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -92,7 +92,8 @@ internal class CustomExoPlayerView( // Set touch listner for tap and swipe gestures. setOnTouchListener(playerGestureController) initializeGestureProgress() - enableDoubleTapToSeek() + + initRewindAndForward() initializeAdvancedOptions(context) @@ -138,6 +139,29 @@ internal class CustomExoPlayerView( return false } + private fun initRewindAndForward() { + val seekIncrementText = (PlayerHelper.seekIncrement / 1000).toString() + listOf( + doubleTapOverlayBinding?.rewindTV, + doubleTapOverlayBinding?.forwardTV, + binding.forwardTV, + binding.rewindTV + ).forEach { + it?.text = seekIncrementText + } + binding.forwardBTN.setOnClickListener { + player?.seekTo(player!!.currentPosition + PlayerHelper.seekIncrement) + } + binding.rewindBTN.setOnClickListener { + player?.seekTo(player!!.currentPosition - PlayerHelper.seekIncrement) + } + if (PlayerHelper.doubleTapToSeek) return + + listOf(binding.forwardBTN, binding.rewindBTN).forEach { + it.visibility = View.VISIBLE + } + } + private fun initializeAdvancedOptions(context: Context) { binding.toggleOptions.setOnClickListener { val items = mutableListOf( @@ -254,13 +278,6 @@ internal class CustomExoPlayerView( playerGestureController.isEnabled = isLocked } - private fun enableDoubleTapToSeek() { - // set seek increment text - val seekIncrementText = (PlayerHelper.seekIncrement / 1000).toString() - doubleTapOverlayBinding?.rewindTV?.text = seekIncrementText - doubleTapOverlayBinding?.forwardTV?.text = seekIncrementText - } - private fun rewind() { player?.seekTo((player?.currentPosition ?: 0L) - PlayerHelper.seekIncrement) @@ -322,7 +339,8 @@ internal class CustomExoPlayerView( private fun initializeGestureProgress() { gestureViewBinding.brightnessProgressBar.let { bar -> - bar.progress = brightnessHelper.getBrightnessWithScale(bar.max.toFloat(), saved = true).toInt() + bar.progress = + brightnessHelper.getBrightnessWithScale(bar.max.toFloat(), saved = true).toInt() } gestureViewBinding.volumeProgressBar.let { bar -> bar.progress = audioHelper.getVolumeWithScale(bar.max) @@ -469,10 +487,12 @@ internal class CustomExoPlayerView( } override fun onDoubleTapLeftScreen() { + if (!PlayerHelper.doubleTapToSeek) return rewind() } override fun onDoubleTapRightScreen() { + if (!PlayerHelper.doubleTapToSeek) return forward() } diff --git a/app/src/main/java/com/github/libretube/util/PlayerHelper.kt b/app/src/main/java/com/github/libretube/util/PlayerHelper.kt index 88644c9de..80ad0ee94 100644 --- a/app/src/main/java/com/github/libretube/util/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/util/PlayerHelper.kt @@ -306,6 +306,12 @@ object PlayerHelper { "18" ).toFloat() + val doubleTapToSeek: Boolean + get() = PreferenceHelper.getBoolean( + PreferenceKeys.DOUBLE_TAP_TO_SEEK, + true + ) + fun getDefaultResolution(context: Context): String { return if (NetworkHelper.isNetworkMobile(context)) { PreferenceHelper.getString( diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index 6906d3099..f377d1a24 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -237,7 +237,6 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:background="@android:color/transparent" - android:clipToPadding="false" android:gravity="center" android:padding="20dp"> @@ -249,12 +248,69 @@ android:visibility="invisible" app:tint="@android:color/white" /> + + + + + + + + + + + + + + + + Comments are disabled by the uploader. This video has no comments available. Captions size + Double tap to seek + Tap twice at the left or right to rewind or forward the player position. Download Service diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index 683f6b794..477be4500 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -18,6 +18,13 @@ app:key="skip_buttons" app:title="@string/skip_buttons" /> + +