Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android-Live-Shared-Preferences-Git2
class LiveSharedPreferences constructor(private val preferences: SharedPreferences) {
private val publisher = PublishSubject.create<String>()
private val listener = OnSharedPreferenceChangeListener { _, key -> publisher.onNext(key) }
private val updates = publisher.doOnSubscribe {
preferences.registerOnSharedPreferenceChangeListener(listener)
}.doOnDispose {
if (!publisher.hasObservers())
preferences.unregisterOnSharedPreferenceChangeListener(listener)
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.