@@ -6,6 +6,7 @@ import androidx.compose.material.icons.filled.Lightbulb
66import androidx.compose.material3.Icon
77import androidx.compose.material3.OutlinedTextField
88import androidx.compose.material3.Switch
9+ import androidx.compose.runtime.Composable
910import androidx.compose.runtime.DisposableEffect
1011import androidx.compose.ui.Modifier
1112import androidx.compose.ui.unit.dp
@@ -27,7 +28,7 @@ class Other {
2728 after = sketches
2829 )
2930
30- fun register (panes : PDEPreferencePanes ) {
31+ fun register () {
3132 PDEPreferences .register(
3233 PDEPreference (
3334 key = " preferences.show_other" ,
@@ -41,57 +42,61 @@ class Other {
4142 setPreference(it.toString())
4243 }
4344 )
44- if (! showOther) {
45- return @PDEPreference
46- }
47- val prefs = LocalPreferences .current
48- val locale = LocalLocale .current
49- DisposableEffect (Unit ) {
50- // add all the other options to the same group as the current one
51- val group =
52- panes[other]?.find { group -> group.any { preference -> preference.key == " preferences.show_other" } } as ? MutableList <PDEPreference >
45+ }
46+ )
47+ )
48+ }
5349
54- val existing = panes.values.flatten().flatten().map { preference -> preference.key }
55- val keys = prefs.keys.mapNotNull { it as ? String }.filter { it !in existing }.sorted()
50+ @Composable
51+ fun handleOtherPreferences (panes : PDEPreferencePanes ) {
52+ // This function can be used to handle any specific logic related to other preferences if needed
53+ val prefs = LocalPreferences .current
54+ val locale = LocalLocale .current
55+ if (prefs[" preferences.show_other" ]?.toBoolean() != true ) {
56+ return
57+ }
58+ DisposableEffect (panes) {
59+ // add all the other options to the same group as the current one
60+ val group =
61+ panes[other]?.find { group -> group.any { preference -> preference.key == " preferences.show_other" } } as ? MutableList <PDEPreference >
5662
57- for (prefKey in keys) {
58- val descriptionKey = " preferences.$prefKey "
59- val preference = PDEPreference (
60- key = prefKey,
61- descriptionKey = if (locale.containsKey(descriptionKey)) descriptionKey else prefKey,
62- pane = other,
63- control = { preference, updatePreference ->
64- if (preference?.toBooleanStrictOrNull() != null ) {
65- Switch (
66- checked = preference.toBoolean(),
67- onCheckedChange = {
68- updatePreference(it.toString())
69- }
70- )
71- return @PDEPreference
72- }
63+ val existing = panes.values.flatten().flatten().map { preference -> preference.key }
64+ val keys = prefs.keys.mapNotNull { it as ? String }.filter { it !in existing }.sorted()
7365
74- OutlinedTextField (
75- modifier = Modifier .widthIn(max = 300 .dp),
76- value = preference ? : " " ,
77- singleLine = true ,
78- onValueChange = {
79- updatePreference(it)
80- }
81- )
66+ for (prefKey in keys) {
67+ val descriptionKey = " preferences.$prefKey "
68+ val preference = PDEPreference (
69+ key = prefKey,
70+ descriptionKey = if (locale.containsKey(descriptionKey)) descriptionKey else prefKey,
71+ pane = other,
72+ control = { preference, updatePreference ->
73+ if (preference?.toBooleanStrictOrNull() != null ) {
74+ Switch (
75+ checked = preference.toBoolean(),
76+ onCheckedChange = {
77+ updatePreference(it.toString())
8278 }
8379 )
84- group?.add(preference)
80+ return @PDEPreference
8581 }
86- onDispose {
87- group?.apply {
88- removeIf { it.key != " preferences.show_other" }
82+
83+ OutlinedTextField (
84+ modifier = Modifier .widthIn(max = 300 .dp),
85+ value = preference ? : " " ,
86+ onValueChange = {
87+ updatePreference(it)
8988 }
90- }
89+ )
9190 }
91+ )
92+ group?.add(preference)
93+ }
94+ onDispose {
95+ group?.apply {
96+ removeIf { it.key != " preferences.show_other" }
9297 }
93- )
94- )
98+ }
99+ }
95100 }
96101 }
97102}
0 commit comments