@@ -3,39 +3,27 @@ Learning RxJava for Android by example |
3 | 3 |
|
4 | 4 | I've read and watched a lot on Rx. Most examples either use the J8 lambda notations/Scala/Groovy or some other awesome language that us Android developers are constantly envious of. |
5 | 5 |
|
6 | | -Unfortunately i could never find real-world simple examples in Android, that could show me how to use RxJava in Android. This repo is a solution to that problem. Below are a list of examples with a little more details on the approach: |
| 6 | +Unfortunately i could never find real-world simple examples in Android, that could show me how to use RxJava in Android. This repo is a solution to that problem. |
7 | 7 |
|
8 | 8 | ## Examples: |
9 | 9 |
|
10 | | -### 1. Concurrency using schedulers |
| 10 | +### Concurrency using schedulers |
11 | 11 |
|
12 | | -A common requirement is to offload lengthy heavy I/O intensive operations to a background thread (non-UI thread), and feed the results back to the UI/main thread, on completion. This is a demo of how long running operations can be offloaded to a background thread. After the operation is done, we resume back on the main thread. All using RxJava! Think of this is as a replacement for AsyncTasks. |
| 12 | +A common requirement is to offload lengthy heavy I/O intensive operations to a background thread (non-UI thread), and feed the results back to the UI/main thread, on completion. This is a demo of how long running operations can be offloaded to a background thread. After the operation is done, we resume back on the main thread. All using RxJava! Think of this as a replacement to AsyncTasks. |
13 | 13 |
|
14 | | -The long operation is simulated by a blocking Thread.sleep call. But since it's in a background thread, our UI is never interrupted. |
| 14 | +The long operation is simulated by a blocking Thread.sleep call (since this is done in a background thread, our UI is never interrupted). |
15 | 15 |
|
16 | 16 | To really see this example shine. Hit the button multiple times and see how the button click (which is a ui operation) is never blocked because the long operation only runs in the background. |
17 | 17 |
|
18 | | -### 1. Retrofit and RxJava (zip, flatmap) (wip) |
| 18 | +### Instant/Auto searching (subject + debounce) |
19 | 19 |
|
20 | | -Working examples of github from JakeWharton's Retrofit preso at Netflix |
21 | | -https://www.youtube.com/watch?v=aEuNBk1b5OE#t=2480 |
22 | | -https://speakerdeck.com/jakewharton/2014-1 |
23 | | - |
24 | | -### 1. simpler operations: map/collect (wip) |
25 | | - |
26 | | -We have a list of three twitter handles. We wish to get the 3 latest tweets from each of these people, and print them out on our screen. |
27 | | - |
28 | | -### 1. First retrieve from cached data, then make a network call if you can't find your data (concat) (wip) |
29 | | - |
30 | | -[Courtesy: gist](https://gist.github.com/adelnizamutdinov/7483969) |
31 | | - |
32 | | -### 1. Make two parallel network calls, then combine the result into a single data point (zip) (wip) |
| 20 | +This is a demo of how events can be swallowed in a way that only the last one is respected. A typical example of this is instant search result boxes. As you type the word "Bruce Lee", you don't want to execute searches for B, Br, Bru, Bruce, Bruce , Bruce L ... etc. But rather intelligently wait for a couple of moments, make sure the user has finished typing the whole word, and then shoot out a single call for "Bruce Lee". |
33 | 21 |
|
34 | | -[Courtesy: gist](https://gist.github.com/adelnizamutdinov/7483969) |
35 | | -http://www.programmableweb.com/category/all/apis?order=field_popularity |
| 22 | +As you type in the input box, it will not shoot out log messages at every single input character change, but rather only pick the lastly emitted event (i.e. input) and log that. |
36 | 23 |
|
| 24 | +This is the debounce/throttleWithTimeout method in RxJava. |
37 | 25 |
|
38 | | -### 1. Accumulate calls (buffer) |
| 26 | +### Accumulate calls (buffer) |
39 | 27 |
|
40 | 28 | This is a demo of how events can be accumulated using the "buffer" operation. |
41 | 29 |
|
@@ -48,15 +36,24 @@ Two implementations: |
48 | 36 | 2a. Using a traditional observable - but encompassing the OnClick within the observable |
49 | 37 | 2b. Using PublishSubject and sending single clicks to the Observable, which in-turn then sends it to the Observer |
50 | 38 |
|
51 | | -### 1. Instant/Auto searching (subject + debounce) |
| 39 | +## Work in Progress: |
52 | 40 |
|
53 | | -This is a demo of how events can be swallowed in a way that only the last one is respected. A typical example of this is instant search result boxes. As you type the word "Bruce Lee", you don't want to execute searches for B, Br, Bru, Bruce, Bruce , Bruce L ... etc. But rather intelligently wait for a couple of moments, make sure the user has finished typing the whole word, and then shoot out a single call for "Bruce Lee". |
| 41 | +### Retrofit and RxJava (zip, flatmap) (wip) |
54 | 42 |
|
55 | | -As you type in the input box, it will not shoot out log messages at every single input character change, but rather only pick the lastly emitted event (i.e. input) and log that. |
| 43 | +Working examples of github from JakeWharton's Retrofit preso at Netflix |
| 44 | +https://www.youtube.com/watch?v=aEuNBk1b5OE#t=2480 |
| 45 | +https://speakerdeck.com/jakewharton/2014-1 |
56 | 46 |
|
57 | | -This is the debounce/throttleWithTimeout method in RxJava. |
| 47 | +### First retrieve from cached data, then make a network call if you can't find your data (concat) (wip) |
| 48 | + |
| 49 | +[Courtesy: gist](https://gist.github.com/adelnizamutdinov/7483969) |
| 50 | + |
| 51 | +### Make two parallel network calls, then combine the result into a single data point (zip) (wip) |
58 | 52 |
|
59 | | -### 1. Orchestrating Observables (flatmap + zip) (wip) |
| 53 | +[Courtesy: gist](https://gist.github.com/adelnizamutdinov/7483969) |
| 54 | +http://www.programmableweb.com/category/all/apis?order=field_popularity |
| 55 | + |
| 56 | +### Orchestrating Observables (flatmap + zip) (wip) |
60 | 57 |
|
61 | 58 | If actions A and B depend on action X running; and action C depends on action Y running. What if you want to combine the result of all those calls and have a single output? |
62 | 59 |
|
@@ -66,15 +63,13 @@ If actions A and B depend on action X running; and action C depends on action Y |
66 | 63 | | |
67 | 64 | Y ------------------------- C ________________| |
68 | 65 |
|
69 | | - |
70 | | - |
71 | | -### 1. Pagination (zip) (wip) |
| 66 | +### Pagination (zip) (wip) |
72 | 67 |
|
73 | 68 | a. Simple pagination |
74 | 69 | b. Optimized pagination |
75 | 70 |
|
76 | 71 |
|
77 | 72 |
|
78 | | -### 1. Replacing your event Bus (wip) |
| 73 | +### Replacing your event Bus (wip) |
79 | 74 |
|
80 | 75 | http://stackoverflow.com/questions/19266834/rxjava-and-random-sporadic-events-on-android |