RxPreferences

Reactive SharedPreferences for Android

License

License

GroupId

GroupId

com.f2prateek.rx.preferences2
ArtifactId

ArtifactId

rx-preferences
Last Version

Last Version

2.0.1
Release Date

Release Date

Type

Type

aar
Description

Description

RxPreferences
Reactive SharedPreferences for Android
Project URL

Project URL

https://github.com/f2prateek/rx-preferences
Source Code Management

Source Code Management

https://github.com/f2prateek/rx-preferences

Download rx-preferences

How to add to project

<!-- https://jarcasting.com/artifacts/com.f2prateek.rx.preferences2/rx-preferences/ -->
<dependency>
    <groupId>com.f2prateek.rx.preferences2</groupId>
    <artifactId>rx-preferences</artifactId>
    <version>2.0.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.f2prateek.rx.preferences2/rx-preferences/
implementation 'com.f2prateek.rx.preferences2:rx-preferences:2.0.1'
// https://jarcasting.com/artifacts/com.f2prateek.rx.preferences2/rx-preferences/
implementation ("com.f2prateek.rx.preferences2:rx-preferences:2.0.1")
'com.f2prateek.rx.preferences2:rx-preferences:aar:2.0.1'
<dependency org="com.f2prateek.rx.preferences2" name="rx-preferences" rev="2.0.1">
  <artifact name="rx-preferences" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.f2prateek.rx.preferences2', module='rx-preferences', version='2.0.1')
)
libraryDependencies += "com.f2prateek.rx.preferences2" % "rx-preferences" % "2.0.1"
[com.f2prateek.rx.preferences2/rx-preferences "2.0.1"]

Dependencies

compile (2)

Group / Artifact Type Version
io.reactivex.rxjava2 : rxjava jar 2.2.7
androidx.annotation » annotation jar 1.0.2

Project Modules

There are no modules declared in this project.

Rx Preferences

Reactive SharedPreferences for Android.

Usage

Create an RxSharedPreferences instance which wraps a SharedPreferences:

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:

Preference<String> username = rxPreferences.getString("username");
Preference<Boolean> showWhatsNew = rxPreferences.getBoolean("show-whats-new", true);

Observe changes to individual preferences:

username.asObservable().subscribe(new Action1<String>() {
  @Override public void call(String username) {
    Log.d(TAG, "Username: " + username);
  }
}

Subscribe preferences to streams to store values:

RxCompoundButton.checks(showWhatsNewView)
    .subscribe(showWhatsNew.asConsumer());

(Note: RxCompoundButton is from RxBinding)

Download

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 at

   http://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.

Versions

Version
2.0.1
2.0.1-beta1
2.0.0
2.0.0-RC3
2.0.0-RC2
2.0.0-RC1