refactor: merge PiP and pause on quit preference into one

This commit is contained in:
Bnyro 2024-02-05 17:22:16 +01:00
parent f814630f41
commit b6669cf65d
6 changed files with 40 additions and 32 deletions

View File

@ -80,7 +80,6 @@ object PreferenceKeys {
const val PLAYER_AUDIO_QUALITY_MOBILE = "player_audio_quality_mobile" const val PLAYER_AUDIO_QUALITY_MOBILE = "player_audio_quality_mobile"
const val DEFAULT_SUBTITLE = "default_subtitle" const val DEFAULT_SUBTITLE = "default_subtitle"
const val SKIP_BUTTONS = "skip_buttons" const val SKIP_BUTTONS = "skip_buttons"
const val PICTURE_IN_PICTURE = "picture_in_picture"
const val PLAYER_RESIZE_MODE = "player_resize_mode" const val PLAYER_RESIZE_MODE = "player_resize_mode"
const val DEARROW = "dearrow" const val DEARROW = "dearrow"
const val USE_HLS_OVER_DASH = "use_hls" const val USE_HLS_OVER_DASH = "use_hls"
@ -90,7 +89,6 @@ object PreferenceKeys {
const val PLAYER_PINCH_CONTROL = "player_pinch_control" const val PLAYER_PINCH_CONTROL = "player_pinch_control"
const val CAPTIONS_SIZE = "captions_size" const val CAPTIONS_SIZE = "captions_size"
const val DOUBLE_TAP_TO_SEEK = "double_tap_seek" 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 ALTERNATIVE_PIP_CONTROLS = "alternative_pip_controls"
const val SKIP_SILENCE = "skip_silence" const val SKIP_SILENCE = "skip_silence"
const val ENABLED_VIDEO_CODECS = "video_codecs" const val ENABLED_VIDEO_CODECS = "video_codecs"
@ -104,6 +102,7 @@ object PreferenceKeys {
const val SHOW_TIME_LEFT = "show_time_left" const val SHOW_TIME_LEFT = "show_time_left"
const val FALLBACK_PIPED_PROXY = "fallback_piped_proxy" const val FALLBACK_PIPED_PROXY = "fallback_piped_proxy"
const val ALLOW_PLAYBACK_DURING_CALL = "playback_during_call" const val ALLOW_PLAYBACK_DURING_CALL = "playback_during_call"
const val BEHAVIOR_WHEN_MINIMIZED = "behavior_when_minimized"
/** /**
* Background mode * Background mode

View File

@ -221,11 +221,16 @@ object PlayerHelper {
false false
) )
private val behaviorWhenMinimized = PreferenceHelper.getString(
PreferenceKeys.BEHAVIOR_WHEN_MINIMIZED,
"pip"
)
val pipEnabled: Boolean val pipEnabled: Boolean
get() = PreferenceHelper.getBoolean( get() = behaviorWhenMinimized == "pip"
PreferenceKeys.PICTURE_IN_PICTURE,
true val pauseOnQuit: Boolean
) get() = behaviorWhenMinimized == "pause"
var autoPlayEnabled: Boolean var autoPlayEnabled: Boolean
get() = PreferenceHelper.getBoolean( get() = PreferenceHelper.getBoolean(
@ -306,12 +311,6 @@ object PlayerHelper {
true true
) )
val pauseOnQuit: Boolean
get() = PreferenceHelper.getBoolean(
PreferenceKeys.PAUSE_ON_QUIT,
false
)
private val alternativePiPControls: Boolean private val alternativePiPControls: Boolean
get() = PreferenceHelper.getBoolean( get() = PreferenceHelper.getBoolean(
PreferenceKeys.ALTERNATIVE_PIP_CONTROLS, PreferenceKeys.ALTERNATIVE_PIP_CONTROLS,

View File

@ -34,21 +34,22 @@ class PlayerSettings : BasePreferenceFragment() {
true true
} }
val pictureInPicture = val behaviorWhenMinimized =
findPreference<SwitchPreferenceCompat>(PreferenceKeys.PICTURE_IN_PICTURE)!! findPreference<ListPreference>(PreferenceKeys.BEHAVIOR_WHEN_MINIMIZED)!!
val alternativePipControls = val alternativePipControls =
findPreference<SwitchPreferenceCompat>(PreferenceKeys.ALTERNATIVE_PIP_CONTROLS) findPreference<SwitchPreferenceCompat>(PreferenceKeys.ALTERNATIVE_PIP_CONTROLS)
val pauseOnQuit = findPreference<SwitchPreferenceCompat>(PreferenceKeys.PAUSE_ON_QUIT)
val pipAvailable = PictureInPictureCompat.isPictureInPictureAvailable(requireContext()) val pipAvailable = PictureInPictureCompat.isPictureInPictureAvailable(requireContext())
pictureInPicture.isVisible = pipAvailable if (!pipAvailable) {
alternativePipControls?.isVisible = pipAvailable with(behaviorWhenMinimized) {
// remove PiP option entry
pauseOnQuit?.isEnabled = !pictureInPicture.isChecked entries = entries.toList().subList(1, 3).toTypedArray()
pictureInPicture.setOnPreferenceChangeListener { _, newValue -> entryValues = entryValues.toList().subList(1, 3).toTypedArray()
pauseOnQuit?.isEnabled = !(newValue as Boolean) if (value !in entryValues) value = entryValues.first().toString()
true }
} }
alternativePipControls?.isVisible = pipAvailable
} }
private fun setupSubtitlePref(preference: ListPreference) { private fun setupSubtitlePref(preference: ListPreference) {

View File

@ -517,4 +517,16 @@
<item>@string/category_music_offtopic</item> <item>@string/category_music_offtopic</item>
<item>@string/category_preview</item> <item>@string/category_preview</item>
</string-array> </string-array>
<string-array name="onMinimize">
<item>@string/picture_in_picture</item>
<item>@string/pause</item>
<item>@string/none</item>
</string-array>
<string-array name="onMinimizeValues">
<item>pip</item>
<item>pause</item>
<item>none</item>
</string-array>
</resources> </resources>

View File

@ -469,6 +469,7 @@
<string name="enqueueing_playlist_download">Enqueueing videos to download of playlist "%1$s"</string> <string name="enqueueing_playlist_download">Enqueueing videos to download of playlist "%1$s"</string>
<string name="audio_language">Audio language</string> <string name="audio_language">Audio language</string>
<string name="default_language">Default</string> <string name="default_language">Default</string>
<string name="behavior_when_minimized">Behavior when minimized</string>
<!-- Backup & Restore Settings --> <!-- Backup & Restore Settings -->
<string name="import_subscriptions_from">Import subscriptions from</string> <string name="import_subscriptions_from">Import subscriptions from</string>

View File

@ -51,11 +51,14 @@
app:key="skip_buttons" app:key="skip_buttons"
app:title="@string/skip_buttons" /> app:title="@string/skip_buttons" />
<SwitchPreferenceCompat <ListPreference
android:defaultValue="true" android:defaultValue="true"
android:icon="@drawable/ic_window" android:icon="@drawable/ic_window"
app:key="picture_in_picture" app:key="behavior_when_minimized"
app:title="@string/picture_in_picture" /> app:title="@string/behavior_when_minimized"
app:entries="@array/onMinimize"
app:entryValues="@array/onMinimizeValues"
app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:disableDependentsState="true" android:disableDependentsState="true"
@ -218,7 +221,6 @@
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:dependency="picture_in_picture"
android:icon="@drawable/ic_headphones" android:icon="@drawable/ic_headphones"
android:summary="@string/alternative_pip_controls_summary" android:summary="@string/alternative_pip_controls_summary"
app:key="alternative_pip_controls" app:key="alternative_pip_controls"
@ -231,12 +233,6 @@
app:key="pause_screen_off" app:key="pause_screen_off"
app:title="@string/pauseOnScreenOff" /> app:title="@string/pauseOnScreenOff" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_pause_filled"
app:key="pause_on_quit"
app:title="@string/pause_on_quit" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>