The library does provide some convenient interfaces to listen to the changes to the SharedPreferences object. However, first, we need to obtain a reference to the RxSharedPreferences object by calling this:
SharedPreferences preferences
= PreferenceManager.getDefaultSharedPreferences(context);
RxSharedPreferences rxPreferences
= RxSharedPreferences.create(preferences);
After that is done, we can start querying settings using something like this:
final Boolean item1 = rxPreferences.getBoolean("item1").get();
Alternatively, we can use the following:
rxPreferences.getBoolean("item1")
.asObservable()
.subscribe(value -> log(value));
Naturally, it exposes interfaces to other types, so it is possible to do the following, along with others:
rxPreferences.getBoolean("key");
rxPreferences.getFloat("key");
rxPreferences.getInteger("key");
rxPreferences.getLong("key");
rxPreferences.getString("key");
Setting properties is also straightforward with this:
rxPreferences.getBoolean("key").set(false);
rxPreferences.getString("key").set("newValue");
However, we won't use this functionality now as we will be relying on Android and its settings related UI to do the SharedPreferences modifications.