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/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() } 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" /> + +