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
|
||||
|
||||
fun edit(newState: Boolean) = run {
|
||||
checked = newState
|
||||
onCheckedChange?.invoke(newState)
|
||||
scope.launch {
|
||||
try {
|
||||
datastore.edit { preferences ->
|
||||
preferences[selectionKey] = newState
|
||||
}
|
||||
checked = newState
|
||||
onCheckedChange?.invoke(newState)
|
||||
} catch (e: Exception) {
|
||||
Log.e("SwitchPref", "Could not write pref $key to database. ${e.printStackTrace()}")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue