Simplify preferences visiblity by using dependencies

This commit is contained in:
Bnyro 2023-04-27 09:39:45 +02:00
parent e8b2d8d02c
commit 13bd7427a2
9 changed files with 62 additions and 121 deletions

View File

@ -63,10 +63,7 @@ class AppearanceSettings : BasePreferenceFragment() {
val navBarOptions = findPreference<Preference>(PreferenceKeys.NAVBAR_ITEMS)
navBarOptions?.setOnPreferenceClickListener {
NavBarOptionsDialog().show(
childFragmentManager,
null
)
NavBarOptionsDialog().show(childFragmentManager, null)
true
}

View File

@ -52,8 +52,6 @@ class InstanceSettings : BasePreferenceFragment() {
true
}
// hide auth instance if option deselected
authInstance.isVisible = authInstanceToggle.isChecked
authInstance.setOnPreferenceChangeListener { _, newValue ->
// save new auth url
RetrofitInstance.authUrl = newValue.toString()
@ -63,7 +61,6 @@ class InstanceSettings : BasePreferenceFragment() {
}
authInstanceToggle.setOnPreferenceChangeListener { _, newValue ->
authInstance.isVisible = newValue == true
// either use new auth url or the normal api url if auth instance disabled
RetrofitInstance.authUrl = if (newValue == false) {
RetrofitInstance.url

View File

@ -8,7 +8,6 @@ import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.helpers.NotificationHelper
import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.views.TimePickerPreference
class NotificationSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.notifications
@ -21,43 +20,20 @@ class NotificationSettings : BasePreferenceFragment() {
val checkingFrequency = findPreference<ListPreference>(PreferenceKeys.CHECKING_FREQUENCY)
val requiredNetwork = findPreference<ListPreference>(PreferenceKeys.REQUIRED_NETWORK)
notificationsEnabled?.setOnPreferenceChangeListener { _, newValue ->
checkingFrequency?.isEnabled = newValue as Boolean
requiredNetwork?.isEnabled = newValue
notificationsEnabled?.setOnPreferenceChangeListener { _, _ ->
updateNotificationPrefs()
true
}
checkingFrequency?.isEnabled = notificationsEnabled!!.isChecked
checkingFrequency?.setOnPreferenceChangeListener { _, _ ->
updateNotificationPrefs()
true
}
requiredNetwork?.isEnabled = notificationsEnabled.isChecked
requiredNetwork?.setOnPreferenceChangeListener { _, _ ->
updateNotificationPrefs()
true
}
val notificationTime = findPreference<SwitchPreferenceCompat>(
PreferenceKeys.NOTIFICATION_TIME_ENABLED
)
val notificationStartTime = findPreference<TimePickerPreference>(
PreferenceKeys.NOTIFICATION_START_TIME
)
val notificationEndTime = findPreference<TimePickerPreference>(
PreferenceKeys.NOTIFICATION_END_TIME
)
listOf(notificationStartTime, notificationEndTime).forEach {
it?.isEnabled = notificationTime?.isChecked == true
}
notificationTime?.setOnPreferenceChangeListener { _, newValue ->
listOf(notificationStartTime, notificationEndTime).forEach {
it?.isEnabled = newValue as Boolean
}
true
}
}
private fun updateNotificationPrefs() {

View File

@ -12,9 +12,7 @@ import com.github.libretube.R
import com.github.libretube.compat.PictureInPictureCompat
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.helpers.LocaleHelper
import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.views.SliderPreference
class PlayerSettings : BasePreferenceFragment() {
override val titleResourceId: Int = R.string.player
@ -22,33 +20,10 @@ class PlayerSettings : BasePreferenceFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.player_settings, rootKey)
val playerOrientation =
findPreference<ListPreference>(PreferenceKeys.FULLSCREEN_ORIENTATION)
val autoRotateToFullscreen =
findPreference<SwitchPreferenceCompat>(PreferenceKeys.AUTO_FULLSCREEN)
// only show the player orientation option if auto fullscreen is disabled
playerOrientation?.isEnabled = autoRotateToFullscreen?.isChecked != true
autoRotateToFullscreen?.setOnPreferenceChangeListener { _, newValue ->
playerOrientation?.isEnabled = newValue != true
true
}
val defaultSubtitle = findPreference<ListPreference>(PreferenceKeys.DEFAULT_SUBTITLE)
defaultSubtitle?.let { setupSubtitlePref(it) }
val systemCaptionStyle =
findPreference<SwitchPreferenceCompat>(PreferenceKeys.SYSTEM_CAPTION_STYLE)
val captionSettings = findPreference<Preference>(PreferenceKeys.CAPTION_SETTINGS)
captionSettings?.isVisible =
PreferenceHelper.getBoolean(PreferenceKeys.SYSTEM_CAPTION_STYLE, true)
systemCaptionStyle?.setOnPreferenceChangeListener { _, newValue ->
captionSettings?.isVisible = newValue as Boolean
true
}
captionSettings?.setOnPreferenceClickListener {
try {
val captionSettingsIntent = Intent(Settings.ACTION_CAPTIONING_SETTINGS)
@ -70,26 +45,6 @@ class PlayerSettings : BasePreferenceFragment() {
val isPipEnabled = pictureInPicture.isVisible && pictureInPicture.isChecked
pauseOnQuit?.isVisible = !isPipEnabled
alternativePipControls?.isVisible = isPipEnabled
pictureInPicture.setOnPreferenceChangeListener { _, newValue ->
val isChecked = newValue as Boolean
pauseOnQuit?.isVisible = !isChecked
alternativePipControls?.isVisible = isChecked
true
}
val customBackgroundSpeed = findPreference<SwitchPreferenceCompat>(
PreferenceKeys.CUSTOM_PLAYBACK_SPEED
)
val backgroundSpeed = findPreference<SliderPreference>(
PreferenceKeys.BACKGROUND_PLAYBACK_SPEED
)
backgroundSpeed?.isEnabled = customBackgroundSpeed?.isChecked == true
customBackgroundSpeed?.setOnPreferenceChangeListener { _, newValue ->
backgroundSpeed?.isEnabled = newValue as Boolean
true
}
}
private fun setupSubtitlePref(preference: ListPreference) {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/search_history">
@ -9,19 +9,19 @@
android:icon="@drawable/ic_history_filled"
android:summary="@string/search_history_summary"
app:key="search_history_toggle"
app:title="@string/search_history" />
app:title="@string/search_history"/>
<SwitchPreferenceCompat
android:dependency="search_history_toggle"
android:defaultValue="false"
android:icon="@drawable/ic_search"
app:key="unlimited_search_history"
app:title="@string/unlimited_search_history" />
app:title="@string/unlimited_search_history"/>
<Preference
android:icon="@drawable/ic_trash"
app:key="clear_search_history"
app:title="@string/clear_history" />
app:title="@string/clear_history"/>
</PreferenceCategory>
@ -32,7 +32,7 @@
android:icon="@drawable/ic_time_outlined"
android:summary="@string/watch_history_summary"
app:key="watch_history_toggle"
app:title="@string/watch_history" />
app:title="@string/watch_history"/>
<ListPreference
android:defaultValue="100"
@ -40,13 +40,14 @@
android:entryValues="@array/historySizeValues"
android:icon="@drawable/ic_list"
app:key="watch_history_size"
android:dependency="watch_history_toggle"
app:title="@string/history_size"
app:useSimpleSummaryProvider="true" />
app:useSimpleSummaryProvider="true"/>
<Preference
android:icon="@drawable/ic_trash"
app:key="clear_watch_history"
app:title="@string/clear_history" />
app:title="@string/clear_history"/>
</PreferenceCategory>
@ -59,12 +60,12 @@
android:icon="@drawable/ic_play_filled"
app:key="watch_positions"
app:summary="@string/watch_positions_summary"
app:title="@string/watch_positions" />
app:title="@string/watch_positions"/>
<Preference
android:icon="@drawable/ic_reset"
app:key="clear_watch_positions"
app:title="@string/reset_watch_positions" />
app:title="@string/reset_watch_positions"/>
</PreferenceCategory>
@ -73,7 +74,7 @@
<Preference
android:title="@string/clear_bookmarks"
app:icon="@drawable/ic_bookmark"
app:key="clear_bookmarks" />
app:key="clear_bookmarks"/>
</PreferenceCategory>

View File

@ -32,6 +32,7 @@
<ListPreference
android:icon="@drawable/ic_server"
android:dependency="auth_instance_toggle"
app:defaultValue="https://pipedapi.kavin.rocks"
app:entries="@array/instances"
app:entryValues="@array/instancesValue"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/notifications">
@ -9,14 +9,15 @@
android:summary="@string/notify_new_streams_summary"
app:defaultValue="true"
app:key="notification_toggle"
app:title="@string/notify_new_streams" />
app:title="@string/notify_new_streams"/>
<SwitchPreferenceCompat
android:icon="@drawable/ic_image"
app:defaultValue="false"
app:key="show_stream_thumbnails"
android:dependency="notification_toggle"
app:title="@string/show_stream_thumbnails"
app:summary="@string/show_stream_thumbnails_summary" />
app:summary="@string/show_stream_thumbnails_summary"/>
<ListPreference
android:icon="@drawable/ic_time"
@ -24,17 +25,19 @@
app:entries="@array/checkingFrequency"
app:entryValues="@array/checkingFrequencyValues"
app:key="checking_frequency"
android:dependency="notification_toggle"
app:title="@string/checking_frequency"
app:useSimpleSummaryProvider="true" />
app:useSimpleSummaryProvider="true"/>
<ListPreference
android:icon="@drawable/ic_signal"
app:defaultValue="all"
android:dependency="notification_toggle"
app:entries="@array/requiredNetwork"
app:entryValues="@array/requiredNetworkValues"
app:key="required_network"
app:title="@string/required_network"
app:useSimpleSummaryProvider="true" />
app:useSimpleSummaryProvider="true"/>
</PreferenceCategory>
@ -43,15 +46,17 @@
<SwitchPreferenceCompat
android:summary="@string/notification_time_summary"
app:key="notification_time"
app:title="@string/notification_time" />
app:title="@string/notification_time"/>
<com.github.libretube.ui.views.TimePickerPreference
app:key="notification_start_time"
app:title="@string/start_time" />
android:dependency="notification_time"
app:title="@string/start_time"/>
<com.github.libretube.ui.views.TimePickerPreference
app:key="notification_end_time"
app:title="@string/end_time" />
android:dependency="notification_time"
app:title="@string/end_time"/>
</PreferenceCategory>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/behavior">
@ -9,60 +9,63 @@
android:icon="@drawable/ic_swipe_gesture"
android:summary="@string/swipe_controls_summary"
app:key="player_swipe_controls"
app:title="@string/swipe_controls" />
app:title="@string/swipe_controls"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_fullscreen"
app:key="fullscreen_gestures"
app:title="@string/fullscreen_gestures" />
app:title="@string/fullscreen_gestures"/>
<SwitchPreferenceCompat
android:defaultValue="true"
android:icon="@drawable/ic_pinch_gesture"
android:summary="@string/pinch_control_summary"
app:key="player_pinch_control"
app:title="@string/pinch_control" />
app:title="@string/pinch_control"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_next"
android:summary="@string/skip_buttons_summary"
app:key="skip_buttons"
app:title="@string/skip_buttons" />
app:title="@string/skip_buttons"/>
<SwitchPreferenceCompat
android:defaultValue="true"
android:icon="@drawable/ic_skip"
android:summary="@string/double_tap_seek_summary"
app:key="double_tap_seek"
app:title="@string/double_tap_seek" />
app:title="@string/double_tap_seek"/>
<SwitchPreferenceCompat
android:defaultValue="true"
android:icon="@drawable/ic_window"
app:key="picture_in_picture"
app:title="@string/picture_in_picture" />
app:title="@string/picture_in_picture"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_headphones"
android:summary="@string/alternative_pip_controls_summary"
android:dependency="picture_in_picture"
app:key="alternative_pip_controls"
app:title="@string/alternative_pip_controls" />
app:title="@string/alternative_pip_controls"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_pause_filled"
app:key="pause_on_quit"
app:title="@string/pause_on_quit" />
android:dependency="picture_in_picture"
app:title="@string/pause_on_quit"/>
<SwitchPreferenceCompat
android:icon="@drawable/ic_rotating_circle"
android:summary="@string/autoRotatePlayer_summary"
app:defaultValue="false"
app:key="auto_fullscreen"
app:title="@string/autoRotatePlayer" />
android:disableDependentsState="true"
app:title="@string/autoRotatePlayer"/>
<ListPreference
android:icon="@drawable/ic_flip"
@ -70,8 +73,9 @@
app:entries="@array/fullscreenOrientation"
app:entryValues="@array/fullscreenOrientationValues"
app:key="fullscreen_orientation"
android:dependency="auto_fullscreen"
app:title="@string/fullscreen_orientation"
app:useSimpleSummaryProvider="true" />
app:useSimpleSummaryProvider="true"/>
</PreferenceCategory>
@ -84,7 +88,7 @@
app:stepSize="5.0"
app:title="@string/seek_increment"
app:valueFrom="5.0"
app:valueTo="60.0" />
app:valueTo="60.0"/>
<ListPreference
android:icon="@drawable/ic_time"
@ -93,7 +97,7 @@
app:entryValues="@array/bufferingGoalValues"
app:key="buffering_goal"
app:summary="@string/buffering_goal_summary"
app:title="@string/buffering_goal" />
app:title="@string/buffering_goal"/>
<com.github.libretube.ui.views.SliderPreference
android:icon="@drawable/ic_text"
@ -102,7 +106,7 @@
app:defValue="18"
app:stepSize="1"
app:valueFrom="8"
app:valueTo="30" />
app:valueTo="30"/>
</PreferenceCategory>
@ -112,12 +116,13 @@
android:icon="@drawable/ic_caption"
app:defaultValue="true"
app:key="system_caption_style"
app:title="@string/system_caption_style" />
app:title="@string/system_caption_style"/>
<Preference
android:icon="@drawable/ic_settings"
app:key="caption_settings"
app:title="@string/caption_settings" />
android:dependency="system_caption_style"
app:title="@string/caption_settings"/>
</PreferenceCategory>
@ -127,7 +132,7 @@
android:defaultValue="true"
android:icon="@drawable/ic_list"
android:title="@string/queue_insert_related_videos"
app:key="queue_insert_related_videos" />
app:key="queue_insert_related_videos"/>
</PreferenceCategory>
@ -141,13 +146,13 @@
app:stepSize="0.1"
app:title="@string/playback_speed"
app:valueFrom="0.2"
app:valueTo="4.0" />
app:valueTo="4.0"/>
<ListPreference
android:defaultValue=""
android:icon="@drawable/ic_caption"
app:key="default_subtitle"
app:title="@string/default_subtitle_language" />
app:title="@string/default_subtitle_language"/>
<ListPreference
android:defaultValue="fit"
@ -156,27 +161,27 @@
android:icon="@drawable/ic_zoom"
app:key="player_resize_mode"
app:title="@string/player_resize_mode"
app:useSimpleSummaryProvider="true" />
app:useSimpleSummaryProvider="true"/>
<SwitchPreferenceCompat
android:icon="@drawable/ic_play_filled"
android:summary="@string/autoplay_summary"
app:defaultValue="true"
app:key="autoplay"
app:title="@string/player_autoplay" />
app:title="@string/player_autoplay"/>
<SwitchPreferenceCompat
android:icon="@drawable/ic_speed"
android:summary="@string/autoplay_countdown_summary"
app:defaultValue="false"
app:key="autoplay_countdown"
app:title="@string/autoplay_countdown" />
app:title="@string/autoplay_countdown"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_fullscreen"
android:title="@string/auto_fullscreen_shorts"
app:key="auto_fullscreen_shorts" />
app:key="auto_fullscreen_shorts"/>
</PreferenceCategory>
@ -187,7 +192,7 @@
android:summary="@string/custom_playback_speed_summary"
app:defaultValue="false"
app:key="custom_playback_speed"
app:title="@string/custom_playback_speed" />
app:title="@string/custom_playback_speed"/>
<com.github.libretube.ui.views.SliderPreference
android:icon="@drawable/ic_speed"
@ -195,8 +200,9 @@
app:key="background_playback_speed"
app:stepSize="0.1"
app:title="@string/playback_speed"
android:dependency="custom_playback_speed"
app:valueFrom="0.2"
app:valueTo="4.0" />
app:valueTo="4.0"/>
</PreferenceCategory>
@ -207,7 +213,7 @@
android:summary="@string/pauseOnScreenOff_summary"
app:defaultValue="false"
app:key="pause_screen_off"
app:title="@string/pauseOnScreenOff" />
app:title="@string/pauseOnScreenOff"/>
</PreferenceCategory>

View File

@ -12,6 +12,7 @@
<SwitchPreferenceCompat
android:summaryOff="@string/disabled"
android:summaryOn="@string/enabled"
android:dependency="sb_enabled_key"
app:defaultValue="true"
app:key="sb_notifications_key"
app:title="@string/sponsorblock_notifications" />
@ -19,12 +20,14 @@
<SwitchPreferenceCompat
android:summary="@string/sb_markers_summary"
app:defaultValue="true"
android:dependency="sb_enabled_key"
app:key="sb_show_markers"
app:title="@string/sb_markers" />
<SwitchPreferenceCompat
android:summary="@string/sb_skip_manual_summary"
app:defaultValue="false"
android:dependency="sb_enabled_key"
app:key="sb_skip_manually_key"
app:title="@string/sb_skip_manual" />