mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 11:22:12 +00:00
Add: PrefsBuilder (inclusive BooleanPref handler)
This commit is contained in:
parent
7ea7761877
commit
b1b3d63bf7
@ -0,0 +1,29 @@
|
|||||||
|
package com.machiav3lli.fdroid.ui.compose.components.prefs
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||||
|
import com.machiav3lli.fdroid.content.Preferences
|
||||||
|
import com.machiav3lli.fdroid.content.PrefsDependencies
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun PrefsBuilder(
|
||||||
|
prefKey: Preferences.Key<*>,
|
||||||
|
onDialogPref: (Any) -> Unit,
|
||||||
|
enabledSetState: SnapshotStateList<Preferences.Key<*>>,
|
||||||
|
index: Int,
|
||||||
|
size: Int
|
||||||
|
) {
|
||||||
|
when (prefKey.default.value) {
|
||||||
|
is Boolean -> SwitchPreference(
|
||||||
|
prefKey = prefKey as Preferences.Key<Boolean>,
|
||||||
|
index = index,
|
||||||
|
groupSize = size,
|
||||||
|
enabled = enabledSetState.contains(prefKey)
|
||||||
|
) {
|
||||||
|
val dependents =
|
||||||
|
PrefsDependencies.entries.filter { it.value == prefKey }.map { it.key }.toSet()
|
||||||
|
if (it) enabledSetState.addAll(dependents)
|
||||||
|
else enabledSetState.removeAll(dependents)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user