From 57b7dfdda90935cd051594c2fbc8a789022b31af Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 10 Apr 2023 14:53:28 +0200 Subject: [PATCH] Separate swipe gestures and fullscreen gestures --- .../com/github/libretube/constants/PreferenceKeys.kt | 1 + .../java/com/github/libretube/helpers/PlayerHelper.kt | 6 ++++++ .../github/libretube/ui/fragments/PlayerFragment.kt | 10 ++++------ .../github/libretube/ui/views/CustomExoPlayerView.kt | 11 +++++------ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/player_settings.xml | 6 ++++++ 6 files changed, 23 insertions(+), 12 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 fd4d98d79..d66223db0 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -96,6 +96,7 @@ object PreferenceKeys { const val LBRY_HLS = "lbry_hls" const val AUTO_FULLSCREEN_SHORTS = "auto_fullscreen_shorts" const val PLAY_AUTOMATICALLY = "play_automatically" + const val FULLSCREEN_GESTURES = "fullscreen_gestures" /** * Background mode diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index ff6249cc6..0ef79f27d 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -322,6 +322,12 @@ object PlayerHelper { true ) + val fullscreenGesturesEnabled: Boolean + get() = PreferenceHelper.getBoolean( + PreferenceKeys.FULLSCREEN_GESTURES, + false + ) + val pinchGestureEnabled: Boolean get() = PreferenceHelper.getBoolean( PreferenceKeys.PLAYER_PINCH_CONTROL, diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 23d3cd11f..6ab72770c 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -322,12 +322,10 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { } }) - if (PlayerHelper.swipeGestureEnabled) { - binding.playerMotionLayout.addSwipeUpListener { - if (this::streams.isInitialized) { - binding.player.hideController() - setFullscreen() - } + binding.playerMotionLayout.addSwipeUpListener { + if (this::streams.isInitialized && PlayerHelper.fullscreenGesturesEnabled) { + binding.player.hideController() + setFullscreen() } } 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 a38ba52d4..a234171a1 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 @@ -691,15 +691,14 @@ internal class CustomExoPlayerView( } override fun onSwipeCenterScreen(distanceY: Float) { - if (!PlayerHelper.swipeGestureEnabled) return + if (!PlayerHelper.fullscreenGesturesEnabled) return if (isControllerFullyVisible) hideController() + if (distanceY >= 0) return - if (distanceY < 0) { - playerGestureController.isMoving = false - (context as? AppCompatActivity)?.onBackPressedDispatcher?.onBackPressed() - playerViewModel?.isFullscreen?.value = false - } + playerGestureController.isMoving = false + (context as? AppCompatActivity)?.onBackPressedDispatcher?.onBackPressed() + playerViewModel?.isFullscreen?.value = false } override fun onSwipeEnd() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index daee12479..0eeefe5e6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -462,6 +462,7 @@ Edit group Play automatically Start playing video automatically when selecting + Enter/exit fullscreen gestures Download Service diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index 61db6633d..17b947382 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -11,6 +11,12 @@ app:key="player_swipe_controls" app:title="@string/swipe_controls" /> + +