mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 05:40:31 +05:30
refactor: merge PiP and pause on quit preference into one
This commit is contained in:
parent
f814630f41
commit
b6669cf65d
@ -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
|
||||
|
@ -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,
|
||||
|
@ -34,21 +34,22 @@ class PlayerSettings : BasePreferenceFragment() {
|
||||
true
|
||||
}
|
||||
|
||||
val pictureInPicture =
|
||||
findPreference<SwitchPreferenceCompat>(PreferenceKeys.PICTURE_IN_PICTURE)!!
|
||||
val behaviorWhenMinimized =
|
||||
findPreference<ListPreference>(PreferenceKeys.BEHAVIOR_WHEN_MINIMIZED)!!
|
||||
val alternativePipControls =
|
||||
findPreference<SwitchPreferenceCompat>(PreferenceKeys.ALTERNATIVE_PIP_CONTROLS)
|
||||
val pauseOnQuit = findPreference<SwitchPreferenceCompat>(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) {
|
||||
|
@ -517,4 +517,16 @@
|
||||
<item>@string/category_music_offtopic</item>
|
||||
<item>@string/category_preview</item>
|
||||
</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>
|
||||
|
@ -469,6 +469,7 @@
|
||||
<string name="enqueueing_playlist_download">Enqueueing videos to download of playlist "%1$s"</string>
|
||||
<string name="audio_language">Audio language</string>
|
||||
<string name="default_language">Default</string>
|
||||
<string name="behavior_when_minimized">Behavior when minimized</string>
|
||||
|
||||
<!-- Backup & Restore Settings -->
|
||||
<string name="import_subscriptions_from">Import subscriptions from</string>
|
||||
|
@ -51,11 +51,14 @@
|
||||
app:key="skip_buttons"
|
||||
app:title="@string/skip_buttons" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
<ListPreference
|
||||
android:defaultValue="true"
|
||||
android:icon="@drawable/ic_window"
|
||||
app:key="picture_in_picture"
|
||||
app:title="@string/picture_in_picture" />
|
||||
app:key="behavior_when_minimized"
|
||||
app:title="@string/behavior_when_minimized"
|
||||
app:entries="@array/onMinimize"
|
||||
app:entryValues="@array/onMinimizeValues"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:disableDependentsState="true"
|
||||
@ -218,7 +221,6 @@
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:dependency="picture_in_picture"
|
||||
android:icon="@drawable/ic_headphones"
|
||||
android:summary="@string/alternative_pip_controls_summary"
|
||||
app:key="alternative_pip_controls"
|
||||
@ -231,12 +233,6 @@
|
||||
app:key="pause_screen_off"
|
||||
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>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user