diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/compose/components/prefs/BasicPrefs.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/compose/components/prefs/BasicPrefs.kt index f5546e3f..3ddd7d96 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/compose/components/prefs/BasicPrefs.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/ui/compose/components/prefs/BasicPrefs.kt @@ -18,8 +18,11 @@ import androidx.compose.material3.Switch import androidx.compose.material3.Text import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha @@ -31,6 +34,7 @@ import androidx.compose.ui.unit.sp import com.machiav3lli.fdroid.content.BooleanPrefsMeta import com.machiav3lli.fdroid.content.NonBooleanPrefsMeta import com.machiav3lli.fdroid.content.Preferences +import com.machiav3lli.fdroid.content.PrefsEntries import com.machiav3lli.fdroid.ui.compose.utils.addIf import com.machiav3lli.fdroid.utility.Utils import com.machiav3lli.fdroid.utility.Utils.getLocaleOfCode @@ -175,3 +179,37 @@ fun StringPreference( onClick = onClick ) } + +@Composable +fun EnumPreference( + modifier: Modifier = Modifier, + prefKey: Preferences.Key>, + index: Int = 1, + groupSize: Int = 1, + isEnabled: Boolean = true, + onClick: (() -> Unit) = {}, +) { + var prefValue by remember { + mutableStateOf(Preferences[prefKey]) + } + SideEffect { + CoroutineScope(Dispatchers.Default).launch { + Preferences.subject.collect { + when (it) { + prefKey -> prefValue = Preferences[prefKey] + else -> {} + } + } + } + } + + BasePreference( + modifier = modifier, + titleId = NonBooleanPrefsMeta[prefKey] ?: -1, + summary = stringResource(id = PrefsEntries[prefKey]?.get(prefValue) ?: -1), + index = index, + groupSize = groupSize, + isEnabled = isEnabled, + onClick = onClick + ) +}