Prefser wraps SharedPreferences and thanks to Java Generics provides you simpler API than classic SharedPreferences with only two methods:
Classic SharedPreferences allows you to store only primitive data types and set of strings.
Thanks to Gson serialization, Prefser allows you to store:
- Primitive data types (boolean, float, int, long, double)
- Custom Objects
In addition, Prefser transforms OnSharedPreferenceChangeListener into Observables from RxJava:
Observable<String> observe(final SharedPreferences sharedPreferences); Observable<String> observeDefaultPreferences();
You can subscribe one of these Observables and monitor updates of SharedPreferences with powerful RxJava.
Moreover, you can observe single preference under a specified key with the following method:
For more details, examples and download instructions visit GitHub webiste of the project at: https://github.com/pwittchen/prefser.
I’ve provided sample app using Prefeser in this repository, which you can check to get familiar with the project.
Library is open source, has Unit Tests, Travis CI job and is available on Maven Central Repository. You can depend on it through Maven or Gradle.