mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Simplify preferences visiblity by using dependencies
This commit is contained in:
parent
e8b2d8d02c
commit
13bd7427a2
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
@ -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) {
|
||||
|
@ -40,6 +40,7 @@
|
||||
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"/>
|
||||
|
||||
|
@ -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"
|
||||
|
@ -15,6 +15,7 @@
|
||||
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"/>
|
||||
|
||||
@ -24,12 +25,14 @@
|
||||
app:entries="@array/checkingFrequency"
|
||||
app:entryValues="@array/checkingFrequencyValues"
|
||||
app:key="checking_frequency"
|
||||
android:dependency="notification_toggle"
|
||||
app:title="@string/checking_frequency"
|
||||
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"
|
||||
@ -47,10 +50,12 @@
|
||||
|
||||
<com.github.libretube.ui.views.TimePickerPreference
|
||||
app:key="notification_start_time"
|
||||
android:dependency="notification_time"
|
||||
app:title="@string/start_time"/>
|
||||
|
||||
<com.github.libretube.ui.views.TimePickerPreference
|
||||
app:key="notification_end_time"
|
||||
android:dependency="notification_time"
|
||||
app:title="@string/end_time"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
@ -48,6 +48,7 @@
|
||||
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"/>
|
||||
|
||||
@ -55,6 +56,7 @@
|
||||
android:defaultValue="false"
|
||||
android:icon="@drawable/ic_pause_filled"
|
||||
app:key="pause_on_quit"
|
||||
android:dependency="picture_in_picture"
|
||||
app:title="@string/pause_on_quit"/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
@ -62,6 +64,7 @@
|
||||
android:summary="@string/autoRotatePlayer_summary"
|
||||
app:defaultValue="false"
|
||||
app:key="auto_fullscreen"
|
||||
android:disableDependentsState="true"
|
||||
app:title="@string/autoRotatePlayer"/>
|
||||
|
||||
<ListPreference
|
||||
@ -70,6 +73,7 @@
|
||||
app:entries="@array/fullscreenOrientation"
|
||||
app:entryValues="@array/fullscreenOrientationValues"
|
||||
app:key="fullscreen_orientation"
|
||||
android:dependency="auto_fullscreen"
|
||||
app:title="@string/fullscreen_orientation"
|
||||
app:useSimpleSummaryProvider="true"/>
|
||||
|
||||
@ -117,6 +121,7 @@
|
||||
<Preference
|
||||
android:icon="@drawable/ic_settings"
|
||||
app:key="caption_settings"
|
||||
android:dependency="system_caption_style"
|
||||
app:title="@string/caption_settings"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
@ -195,6 +200,7 @@
|
||||
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"/>
|
||||
|
||||
|
@ -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" />
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user