Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/f2prateek/rx-preferences
Reactive SharedPreferences for Android
https://github.com/f2prateek/rx-preferences
Last synced: 6 days ago
JSON representation
Reactive SharedPreferences for Android
- Host: GitHub
- URL: https://github.com/f2prateek/rx-preferences
- Owner: f2prateek
- License: apache-2.0
- Created: 2014-12-16T05:28:28.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-05-24T00:46:03.000Z (over 1 year ago)
- Last Synced: 2024-10-01T22:25:17.623Z (2 months ago)
- Language: Java
- Homepage: http://f2prateek.com/2015/10/05/rx-preferences/
- Size: 295 KB
- Stars: 1,539
- Watchers: 32
- Forks: 132
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-rxjava - rx-preferences - Reactive `SharedPreferences` for Android. (Bindings)
README
# DEPRECATED
rx-preferences is deprecated. Please consider using a replacement, such as [this](https://github.com/pablobaxter/rx-preferences). Thank you for using the library!
Rx Preferences
--------------Reactive `SharedPreferences` for Android.
Usage
-----Create an `RxSharedPreferences` instance which wraps a `SharedPreferences`:
```java
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
RxSharedPreferences rxPreferences = RxSharedPreferences.create(preferences);
```*Hint: Keep a strong reference on your `RxSharedPreferences` instance for as long as you want to observe them to prevent listeners from being GCed.*
Create individual `Preference` objects:
```java
Preference username = rxPreferences.getString("username");
Preference showWhatsNew = rxPreferences.getBoolean("show-whats-new", true);
```Observe changes to individual preferences:
```java
username.asObservable().subscribe(new Action1() {
@Override public void call(String username) {
Log.d(TAG, "Username: " + username);
}
}
```Subscribe preferences to streams to store values:
```java
RxCompoundButton.checks(showWhatsNewView)
.subscribe(showWhatsNew.asConsumer());
```
*(Note: `RxCompoundButton` is from [RxBinding][1])*Download
--------```groovy
implementation 'com.f2prateek.rx.preferences2:rx-preferences:2.0.1'
```License
-------Copyright 2014 Prateek Srivastava
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.[1]: https://github.com/JakeWharton/RxBinding
[2]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.f2prateek.rx.preferences&a=rx-preferences&v=LATEST