Skip to content

Instantly share code, notes, and snippets.

@egorikftp

egorikftp/old.kt Secret

Created Aug 22, 2021
Embed
What would you like to do?
//Listen app theme mode (dark, light)
private val selectedThemeChannel: ConflatedBroadcastChannel<String> by lazy {
ConflatedBroadcastChannel<String>().also { channel ->
channel.trySend(selectedTheme)
}
}
private val changeListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
when (key) {
PREF_DARK_MODE_ENABLED -> selectedThemeChannel.trySend(selectedTheme)
}
}
val selectedThemeFlow: Flow<String>
get() = selectedThemeChannel.asFlow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment