bod
10/31/2020, 4:05 PMMutableStateFlow
? For instance, does something similar to callbackFlow {}
exist?gildor
11/01/2020, 2:20 PMbod
11/01/2020, 3:33 PMMutableStateFlow
sMutableStateFlow
but that involves quite a bit of boilerplatebezrukov
11/01/2020, 8:28 PMbod
11/01/2020, 11:19 PMStateFlow
though - my need is for a mutable one.gildor
11/02/2020, 12:58 AMclass FlowPreferences {
private val flows = HashMap<String, MutableStateFlow<Any>>()
private val sharedPreferences = TODO()
private val someScope: CoroutineScope = TODO("Lifecycle of this scope really depends on your case, it can be just GlobalScope, if preferences are global")
fun stringFlow(key: String): MutableStateFlow<String> {
flows.getOrPut(key) {
MutableStateFlow<String>(sharedPreferences.getString(key)).apply {
someScope.launch {
collect {
if (sharedPreferences != it) {
sharedPreferences.edit().putString(it).apply()
}
}
}
//TODO: it also possible observe sharedPreferences and update flow
}
}
}
}
bod
11/02/2020, 7:52 AMRaul
11/10/2020, 6:25 PM