From ac5f1a0d93565c273dde40467af6605ab4b52c1e Mon Sep 17 00:00:00 2001 From: Mitchell Syer Date: Mon, 21 Jul 2025 15:13:17 -0400 Subject: [PATCH] Add enabled preference setting (#1539) * Add enabled preference setting * Don't change preference if its not enabled --- .../src/main/java/androidx/preference/Preference.java | 7 ++++++- .../suwayomi/tachidesk/graphql/types/SourceType.kt | 10 ++++++++++ .../kotlin/suwayomi/tachidesk/manga/impl/Source.kt | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/AndroidCompat/src/main/java/androidx/preference/Preference.java b/AndroidCompat/src/main/java/androidx/preference/Preference.java index 8b7a55bf..90ccd152 100644 --- a/AndroidCompat/src/main/java/androidx/preference/Preference.java +++ b/AndroidCompat/src/main/java/androidx/preference/Preference.java @@ -23,6 +23,7 @@ public class Preference { protected Context context; private boolean isVisible; + private boolean isEnabled = true; private String key; private CharSequence title; private CharSequence summary; @@ -68,7 +69,11 @@ public class Preference { } public void setEnabled(boolean enabled) { - throw new RuntimeException("Stub!"); + isEnabled = enabled; + } + + public boolean isEnabled() { + return isEnabled; } public String getKey() { diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SourceType.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SourceType.kt index 5fd14751..87fb1fd2 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SourceType.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SourceType.kt @@ -342,6 +342,7 @@ data class SwitchPreference( val title: String?, val summary: String?, val visible: Boolean, + val enabled: Boolean, val currentValue: Boolean?, val default: Boolean, ) : Preference @@ -351,6 +352,7 @@ data class CheckBoxPreference( val title: String?, val summary: String?, val visible: Boolean, + val enabled: Boolean, val currentValue: Boolean?, val default: Boolean, ) : Preference @@ -360,6 +362,7 @@ data class EditTextPreference( val title: String?, val summary: String?, val visible: Boolean, + val enabled: Boolean, val currentValue: String?, val default: String?, val dialogTitle: String?, @@ -372,6 +375,7 @@ data class ListPreference( val title: String?, val summary: String?, val visible: Boolean, + val enabled: Boolean, val currentValue: String?, val default: String?, val entries: List, @@ -383,6 +387,7 @@ data class MultiSelectListPreference( val title: String?, val summary: String?, val visible: Boolean, + val enabled: Boolean, val currentValue: List?, val default: List?, val dialogTitle: String?, @@ -399,6 +404,7 @@ fun preferenceOf(preference: SourcePreference): Preference = preference.title?.toString(), preference.summary?.toString(), preference.visible, + preference.isEnabled, preference.currentValue as Boolean, preference.defaultValue as Boolean, ) @@ -408,6 +414,7 @@ fun preferenceOf(preference: SourcePreference): Preference = preference.title?.toString(), preference.summary?.toString(), preference.visible, + preference.isEnabled, preference.currentValue as Boolean, preference.defaultValue as Boolean, ) @@ -417,6 +424,7 @@ fun preferenceOf(preference: SourcePreference): Preference = preference.title?.toString(), preference.summary?.toString(), preference.visible, + preference.isEnabled, (preference.currentValue as CharSequence?)?.toString(), (preference.defaultValue as CharSequence?)?.toString(), preference.dialogTitle?.toString(), @@ -429,6 +437,7 @@ fun preferenceOf(preference: SourcePreference): Preference = preference.title?.toString(), preference.summary?.toString(), preference.visible, + preference.isEnabled, (preference.currentValue as CharSequence?)?.toString(), (preference.defaultValue as CharSequence?)?.toString(), preference.entries.map { it.toString() }, @@ -440,6 +449,7 @@ fun preferenceOf(preference: SourcePreference): Preference = preference.title?.toString(), preference.summary?.toString(), preference.visible, + preference.isEnabled, (preference.currentValue as Collection<*>?)?.map { it.toString() }, (preference.defaultValue as Collection<*>?)?.map { it.toString() }, preference.dialogTitle?.toString(), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt index f83ea3ba..a177abb9 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt @@ -142,6 +142,10 @@ object Source { val screen = preferenceScreenMap[sourceId]!! val pref = screen.preferences[position] + if (!pref.isEnabled) { + return + } + val newValue = getValue(pref) pref.saveNewValue(newValue)