RxJava

Introducing ReactiveNetwork

2015-08-10 Android, Open source, RxJava No comments

I’ve recently released ReactiveNetwork. It is an open-source Android library listening network connection state and change of the WiFi signal strength with RxJava Observables. It’s a successor of Network Events library rewritten with Reactive Programming approach.

Library is compatible with RxJava 1.0.+ and RxAndroid 1.0.+ and uses them under the hood. Min Android SDK version is 9.
JavaDoc can be found at: http://pwittchen.github.io/ReactiveNetwork.
Repository is available at: https://github.com/pwittchen/ReactiveNetwork.

This library is much simpler and easier to use than NetworkEvents. Even code-base is much smaller, but we have to remember that it utilizes powerful RxJava and RxAndroid. RxJava hase huge API and gives a lot of possibilities. That’s why I was able to obtain desired result with fewer lines of code.

Basic library usage is quite simple. E.g if we want to monitor ConnectivityStatus (WIFI_CONNECTED, MOBILE_CONNECTED or OFFLINE), we can create the following subscription, which is quite familiar for software developers who already know RxJava:

When we want to monitor available WiFi Access Points and we want to get fresh list of them whenever strength of the WiFi Access Points signal changes (e.g. when we are moving with a mobile device around), we can use the following code snippet:

If you want to use ReactiveNetwork in your project, add the following dependency to your build.gradle file:

dependencies {
  compile 'com.github.pwittchen:reactivenetwork:0.0.2'
}

Find more in the GitHub repository of the project at: https://github.com/pwittchen/ReactiveNetwork.

It’s worth mentioning that this library was featured on Android Arsenal, Android Weekly and Android Weekly China websites.

I hope you will find it useful and you will make your apps more reactive!
Feel free to fork the library. Any feedback is welcome as usual.

Introducing Prefser

2015-02-22 Android, RxJava No comments

I’ve recently released Prefser, which is a wrapper for Android SharedPreferences with object serialization and RxJava Observables.

Prefser wraps SharedPreferences and thanks to Java Generics provides you simpler API than classic SharedPreferences with only two methods:

void put(String key, Object value);
<T> T get(String key, Class classOfT, T defaultValue);

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)
  • Strings
  • Custom Objects
  • Lists
  • Arrays
  • Sets

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:

<T> Observable<T> observe(final String key, final Class classOfT, final T defaultValue)

prefser_observable_diagram

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.