implementation 'com.frybits.rx.preferences:rx3:1.1.0'
Create a Rx3SharedPreferences
instance which wraps a SharedPreferences
:
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val rx3SharedPreferences = Rx3haredPreferences.create(preferences)
Hint: Keep a strong reference on your Rx3haredPreferences
instance for as long as you want to observe them to prevent listeners from being GCed.
Create individual Rx3Preference
objects:
val username = rx3SharedPreferences.getString("username")
val showWhatsNew = rx3SharedPreferences.getBoolean("show-whats-new", true)
Observe changes to individual preferences:
username.asObservable().subscribe { username ->
Log.d(TAG, "Username: $username")
}
Subscribe preferences to streams to store values:
someBooleanRx3Stream.subscribe(showWhatsNew.asConsumer())