February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
-- http://reactivex.io/
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
single items | multiple items | |
---|---|---|
synchronous | T getData() | Iterable<T> getData() |
asynchronous | Future<T> getData() | Observable<T> getData() |
event | Iterable (pull) | Observable (push) |
---|---|---|
retrieve data | T next() | onNext(T) |
discover error | throws Exception | onError(Exception) |
complete | !hasNext() | onCompleted() |
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
obs = Observable.just(1, 2, 3, 4, 5);
obs.subscribe(onNext, onError, onComplete);
1
2
3
4
5
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
obs.subscribe(new Action1< Integer >() {
@Override
public void call(String value) { /* on emition */ }
}, new Action1< Throwable >() {
@Override
public void call(Throwable throwable) { /* on error */ }
}, new Action0() {
@Override
public void call() { /* on complete */ }
});
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
Observable.just(1, 2, 3, 4, 5)
.map(new Func1< Integer, String >() {
@Override
public String call(Integer number) {
return number.toString();
}
});
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
(Chaining)
Observable obs = Observable.just(1, 2, 3, 4, 5)
.filter(new Func1<Integer, Boolean>() {
@Override
public Boolean call(Integer number) {
return number % 2 == 0;
}
})
.map(new Func1< Integer, String >() {
@Override
public String call(Integer number) {
return number.toString();
}
});
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git clone git@github.com:3pillarlabs/rx_android_workshop.git
cd rx_android_workshop
git checkout mb1
git checkout -b mb1
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
"... they provide a clear and concise way to represent one method interface using an expression ... "
-- Java 8
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
/* no arguments, single statement */ () -> 42
/* one argument */ number -> number * 2
/* multiple arguments */ (i, j) -> i * j
/* multiple arguments types */ (int i, long j) -> i * j
/* multiple statements */
(int i, long j) -> { long result = i * j; return result; }
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
Observable.just(1, 2, 3, 4, 5)
.map(new Func1< Integer, String >() {
@Override
public String call(Integer number) {
return number.toString();
}
});
becomes
Observable.just(1, 2, 3, 4, 5)
.map(i -> i.toString());
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
obs = Observable.just("1", "2", "3")
/* lambda enhanced code */
obs.map(nr -> Integer.parseInt(nr))
/* using method reference */
obs.map(Integer::parseInt)
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb2
git checkout -b mb2
Neat huh?! Let's get to work
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb3
git checkout -b mb3
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
"Retrofit turns your HTTP API into a Java interface"
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
public interface OmdbApi {
@GET("/?y=&plot=short&r=json")
Observable< OmdbMovie > findByTitle(@Query("t") String t);
}
...
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://www.omdbapi.com")
.build();
OmdbApi api = retrofit.create(OmdbApi.class);
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb4
git checkout -b mb4
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb5
git checkout -b mb5
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb6
git checkout -b mb6
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
RxTextView.textChanges(searchText)
.flatMap(title -> omdbApi.searchByTitle(title))
.subscribeOn(Schedulers.io());
RxTextView.textChanges(searchText)
.flatMap(title -> omdbApi.searchByTitle(title)
.subscribeOn(Schedulers.io()));
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb7
git checkout -b mb7
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb8
git checkout -b mb8
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
To improve:
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb9
git checkout -b mb9
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
...
@Inject
BriteDatabase db;
...
db.createQuery(table_name, query, params)
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb10
git checkout -b mb10
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb11
git checkout -b mb11
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
Wrap events and errors
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
When Producer is faster than consumer
February 19, 2016 | GitHub: 3pillarlabs / rx_android_workshop
git add -A && git commit -m "progress"
git checkout mb12
git checkout -b mb12