🛠A small Kotlin library to make shared preferences easy + RxJava and Coroutines support
SharedPreferences
, now, since the stock Context
method is deprecated with API 29.Enable multiple subscribers on the same Pref instance.
With this:
val myPref: Pref<Int> = // ...
myPref.observe().subscribe { println("One: $it") }
myPref.set("Hi")
myPref.observe().subscribe { println("Two: $it") }
myPref.set("Hello")
You'd get console output like this:
One: Hi
One: Hello
Two: Hello
RxkPrefs
is now an interface, allowing this library to be more mockable in tests. You now must use the rxkPrefs
function to retrieve an instance of this interface, rather than invoking a constructor.
Pref
itself is now an Rx Consumer
, so asConsumer()
is redundant.asObservable()
to observe()
.getSharedPrefs()
method in case you need access to the underlying SharedPreferences
instance.The initial release