Rx.Observe

Project Url: florent37/Rx.Observe
Introduction: Transform any method to an Rx Observable ! (VIPER)
More: Author   ReportBugs   
Tags:

RxJava2 ready !

Android app on Google Play

Create an interface with @Observe annotated method

public class User {

       private int age;

       @Observe
       public int getAge() {
           return age;
       }

       @Observe
       public void setAge(int age) {
           this.age = age;
       }

}

Will generate 2 observables

Observable<Integer> getAge()

Observable<T> setAge(T toReturn, int age)

setAge is a void method so it will return the first T toReturn argument (useful for your flatmaps)

Those observable are accessible through Rx.observe(user)

Static

public class Calculator {

    @Observe
    public static int addOne(int number) {
        return number + 1;
    }

}

Will generate

Observable<T> addOne(int age)

Accessible through Rx.observeCalculator()

Example

User user = new User();

Rx.observe(user).setAge(user, 3)
         .flatMap(u -> Rx.observe(u).getAge())
         .flatMap(age -> Rx.observeCalculator().addOne(age))

         .subscribeOn(Schedulers.newThread())
         .observeOn(AndroidSchedulers.mainThread())

         .subscribe(integer -> {
             Toast.makeText(getBaseContext(), "" + integer, Toast.LENGTH_SHORT).show();
         });

RxJava2

Rx.Observable is also compatible with @Single, @Flowable, @Completable

Download

Buy Me a Coffee at ko-fi.com

In your module Download

repositories {
    google()
    jcenter()
    maven { url "https://dl.bintray.com/florent37/maven" }
    // ...
}
provided 'com.github.florent37:rxobserve-annotations:1.0.0'
annotationProcessor 'com.github.florent37:rxobserve-compiler:1.0.0'

compile 'io.reactivex:rxjava2:2.0.7'

Credits

Author: Florent Champigny http://www.florentchampigny.com/

Blog : http://www.tutos-android-france.com/

Android app on Google Play

Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2017 florent37, Inc.

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.
Support Me
Apps
About Me
Google+: Trinea trinea
GitHub: Trinea