pref: 优化新 UI 设置
This commit is contained in:
parent
5018ef5b6e
commit
92e962336f
|
|
@ -112,13 +112,13 @@ fun SwitchPref(
|
||||||
prefs?.get(selectionKey)?.also { checked = it } // starting value if it exists in datastore
|
prefs?.get(selectionKey)?.also { checked = it } // starting value if it exists in datastore
|
||||||
|
|
||||||
fun edit(newState: Boolean) = run {
|
fun edit(newState: Boolean) = run {
|
||||||
|
checked = newState
|
||||||
|
onCheckedChange?.invoke(newState)
|
||||||
scope.launch {
|
scope.launch {
|
||||||
try {
|
try {
|
||||||
datastore.edit { preferences ->
|
datastore.edit { preferences ->
|
||||||
preferences[selectionKey] = newState
|
preferences[selectionKey] = newState
|
||||||
}
|
}
|
||||||
checked = newState
|
|
||||||
onCheckedChange?.invoke(newState)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("SwitchPref", "Could not write pref $key to database. ${e.printStackTrace()}")
|
Log.e("SwitchPref", "Could not write pref $key to database. ${e.printStackTrace()}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue