From 677a01a0552c6f68262e1d8e8137e1d7765fb121 Mon Sep 17 00:00:00 2001 From: Krunal Patel Date: Thu, 1 Dec 2022 22:14:59 +0530 Subject: [PATCH 1/2] Fix single tap on scroll or pinch gesture Keep track whether the last touch event was for click or other gesture which can be used by runnable. --- .../libretube/util/PlayerGestureController.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/util/PlayerGestureController.kt b/app/src/main/java/com/github/libretube/util/PlayerGestureController.kt index 57a294bbb..ac9095745 100644 --- a/app/src/main/java/com/github/libretube/util/PlayerGestureController.kt +++ b/app/src/main/java/com/github/libretube/util/PlayerGestureController.kt @@ -34,6 +34,10 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play private var isMoving = false var isEnabled = true + // Indicates last touch event was for click or other gesture, used to avoid single click + // by runnable when scroll or pinch gesture already completed. + var wasClick = true + init { gestureDetector = GestureDetector(activity, GestureListener(), handler) scaleGestureDetector = ScaleGestureDetector(activity, ScaleGestureListener(), handler) @@ -66,6 +70,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play var scaleFactor: Float = 1f override fun onScale(detector: ScaleGestureDetector): Boolean { + wasClick = false scaleFactor *= detector.scaleFactor return true } @@ -89,6 +94,9 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play private var xPos = 0.0F override fun onDown(e: MotionEvent): Boolean { + // Initially assume this event is for click + wasClick = true + if (isMoving || scaleGestureDetector.isInProgress) return false if (isEnabled && isSecondClick()) { @@ -135,6 +143,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play } isMoving = true + wasClick = false when { width * 0.5 > e1.x -> listener.onSwipeLeftScreen(distanceY) @@ -144,8 +153,8 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play } private val runnable = Runnable { - // If user is scrolling then avoid single tap call - if (isMoving || isSecondClick()) return@Runnable + // If the last event was for scroll or pinch then avoid single tap call + if (!wasClick || isSecondClick()) return@Runnable listener.onSingleTap() } From 09d709dca82717a7a79417d20a065032b8d3fe3f Mon Sep 17 00:00:00 2001 From: Krunal Patel Date: Thu, 1 Dec 2022 23:03:30 +0530 Subject: [PATCH 2/2] Add setting to enable or disable pinch gesture --- .../github/libretube/constants/PreferenceKeys.kt | 1 + .../libretube/ui/views/CustomExoPlayerView.kt | 2 ++ .../java/com/github/libretube/util/PlayerHelper.kt | 6 ++++++ app/src/main/res/drawable/ic_pinch_gesture.xml | 13 +++++++++++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/player_settings.xml | 7 +++++++ 6 files changed, 31 insertions(+) create mode 100644 app/src/main/res/drawable/ic_pinch_gesture.xml 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 8836fec16..927b1a53b 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -83,6 +83,7 @@ object PreferenceKeys { const val QUEUE_AUTO_INSERT_RELATED = "queue_insert_related_videos" const val PLAYER_SWIPE_CONTROLS = "player_swipe_controls" const val PLAYER_SCREEN_BRIGHTNESS = "player_screen_brightness" + const val PLAYER_PINCH_CONTROL = "player_pinch_control" const val CAPTIONS_SIZE = "captions_size" const val DOUBLE_TAP_TO_SEEK = "double_tap_seek" 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 4da4fe780..bf68e6739 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 @@ -509,10 +509,12 @@ internal class CustomExoPlayerView( } override fun onZoom() { + if (!PlayerHelper.pinchGestureEnabled) return resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM } override fun onMinimize() { + if (!PlayerHelper.pinchGestureEnabled) return resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT } 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 80ad0ee94..5d0797100 100644 --- a/app/src/main/java/com/github/libretube/util/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/util/PlayerHelper.kt @@ -300,6 +300,12 @@ object PlayerHelper { true ) + val pinchGestureEnabled: Boolean + get() = PreferenceHelper.getBoolean( + PreferenceKeys.PLAYER_PINCH_CONTROL, + true + ) + val captionsTextSize: Float get() = PreferenceHelper.getString( PreferenceKeys.CAPTIONS_SIZE, diff --git a/app/src/main/res/drawable/ic_pinch_gesture.xml b/app/src/main/res/drawable/ic_pinch_gesture.xml new file mode 100644 index 000000000..ab1c7d82d --- /dev/null +++ b/app/src/main/res/drawable/ic_pinch_gesture.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 57c9f7f85..65c63d1c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -394,6 +394,8 @@ Auto Swipe controls Use swipe gesture to adjust the brightness and volume. + Pinch control + Use pinch gesture to zoom in/out. Defaults Pop-Up Comments are disabled by the uploader. diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index 477be4500..8434460f9 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -11,6 +11,13 @@ app:key="player_swipe_controls" app:title="@string/swipe_controls" /> + +