From f814630f41040aed67ce6c838763e039ccc8dfc9 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 5 Feb 2024 17:01:36 +0100 Subject: [PATCH 1/2] refactor: reorganize player settings --- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/player_settings.xml | 68 +++++++++++++----------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eb623b7a5..8bf33f9ad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -512,6 +512,7 @@ Add to group %.2f%% uptime Change + Gestures Download Service diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index 4cf9dd1da..59671d835 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -2,7 +2,7 @@ - + - - + + + + + + + + - - @@ -196,12 +200,14 @@ - + + + - - \ No newline at end of file From b6669cf65db8c12ca3be7feca6bb99a505ce7770 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 5 Feb 2024 17:22:16 +0100 Subject: [PATCH 2/2] refactor: merge PiP and pause on quit preference into one --- .../libretube/constants/PreferenceKeys.kt | 3 +-- .../github/libretube/helpers/PlayerHelper.kt | 19 ++++++++--------- .../ui/preferences/PlayerSettings.kt | 21 ++++++++++--------- app/src/main/res/values/array.xml | 12 +++++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/player_settings.xml | 16 ++++++-------- 6 files changed, 40 insertions(+), 32 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 e4c033239..b1b9cc725 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -80,7 +80,6 @@ object PreferenceKeys { const val PLAYER_AUDIO_QUALITY_MOBILE = "player_audio_quality_mobile" const val DEFAULT_SUBTITLE = "default_subtitle" const val SKIP_BUTTONS = "skip_buttons" - const val PICTURE_IN_PICTURE = "picture_in_picture" const val PLAYER_RESIZE_MODE = "player_resize_mode" const val DEARROW = "dearrow" const val USE_HLS_OVER_DASH = "use_hls" @@ -90,7 +89,6 @@ object PreferenceKeys { const val PLAYER_PINCH_CONTROL = "player_pinch_control" const val CAPTIONS_SIZE = "captions_size" const val DOUBLE_TAP_TO_SEEK = "double_tap_seek" - const val PAUSE_ON_QUIT = "pause_on_quit" const val ALTERNATIVE_PIP_CONTROLS = "alternative_pip_controls" const val SKIP_SILENCE = "skip_silence" const val ENABLED_VIDEO_CODECS = "video_codecs" @@ -104,6 +102,7 @@ object PreferenceKeys { const val SHOW_TIME_LEFT = "show_time_left" const val FALLBACK_PIPED_PROXY = "fallback_piped_proxy" const val ALLOW_PLAYBACK_DURING_CALL = "playback_during_call" + const val BEHAVIOR_WHEN_MINIMIZED = "behavior_when_minimized" /** * 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 d9fc92cc9..a6e6cd64a 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -221,11 +221,16 @@ object PlayerHelper { false ) + private val behaviorWhenMinimized = PreferenceHelper.getString( + PreferenceKeys.BEHAVIOR_WHEN_MINIMIZED, + "pip" + ) + val pipEnabled: Boolean - get() = PreferenceHelper.getBoolean( - PreferenceKeys.PICTURE_IN_PICTURE, - true - ) + get() = behaviorWhenMinimized == "pip" + + val pauseOnQuit: Boolean + get() = behaviorWhenMinimized == "pause" var autoPlayEnabled: Boolean get() = PreferenceHelper.getBoolean( @@ -306,12 +311,6 @@ object PlayerHelper { true ) - val pauseOnQuit: Boolean - get() = PreferenceHelper.getBoolean( - PreferenceKeys.PAUSE_ON_QUIT, - false - ) - private val alternativePiPControls: Boolean get() = PreferenceHelper.getBoolean( PreferenceKeys.ALTERNATIVE_PIP_CONTROLS, diff --git a/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt index c254899a9..9582e1405 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt @@ -34,21 +34,22 @@ class PlayerSettings : BasePreferenceFragment() { true } - val pictureInPicture = - findPreference(PreferenceKeys.PICTURE_IN_PICTURE)!! + val behaviorWhenMinimized = + findPreference(PreferenceKeys.BEHAVIOR_WHEN_MINIMIZED)!! val alternativePipControls = findPreference(PreferenceKeys.ALTERNATIVE_PIP_CONTROLS) - val pauseOnQuit = findPreference(PreferenceKeys.PAUSE_ON_QUIT) val pipAvailable = PictureInPictureCompat.isPictureInPictureAvailable(requireContext()) - pictureInPicture.isVisible = pipAvailable - alternativePipControls?.isVisible = pipAvailable - - pauseOnQuit?.isEnabled = !pictureInPicture.isChecked - pictureInPicture.setOnPreferenceChangeListener { _, newValue -> - pauseOnQuit?.isEnabled = !(newValue as Boolean) - true + if (!pipAvailable) { + with(behaviorWhenMinimized) { + // remove PiP option entry + entries = entries.toList().subList(1, 3).toTypedArray() + entryValues = entryValues.toList().subList(1, 3).toTypedArray() + if (value !in entryValues) value = entryValues.first().toString() + } } + + alternativePipControls?.isVisible = pipAvailable } private fun setupSubtitlePref(preference: ListPreference) { diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index b12dea0b5..8dd47ad53 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -517,4 +517,16 @@ @string/category_music_offtopic @string/category_preview + + + @string/picture_in_picture + @string/pause + @string/none + + + + pip + pause + none + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8bf33f9ad..ebfed8276 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -469,6 +469,7 @@ Enqueueing videos to download of playlist "%1$s" Audio language Default + Behavior when minimized Import subscriptions from diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index 59671d835..6a330673e 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -51,11 +51,14 @@ app:key="skip_buttons" app:title="@string/skip_buttons" /> - + app:key="behavior_when_minimized" + app:title="@string/behavior_when_minimized" + app:entries="@array/onMinimize" + app:entryValues="@array/onMinimizeValues" + app:useSimpleSummaryProvider="true" /> - - \ No newline at end of file