| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f0a73ec commit 804f157
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,64 +3,78 @@ 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 deatils 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. Below are a list of examples with a little more details on the approach: | ||
| 7 | 7 | ||
| 8 | 8 | ## Examples: | |
| 9 | 9 | ||
| 10 | 10 | ### 1. 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 onc ompletion, back into the UI/main thread. 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! | ||
| 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. | ||
| 13 | 13 | ||
| 14 | 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. | |
| 15 | 15 | ||
| 16 | - To really see this 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 | ||
| 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 | 19 | ||
| 19 | - ### 2. Accumulate calls using buffer | ||
| 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) | ||
| 33 | + | ||
| 34 | + [Courtesy: gist](https://gist.github.com/adelnizamutdinov/7483969) | ||
| 35 | + http://www.programmableweb.com/category/all/apis?order=field_popularity | ||
| 36 | + | ||
| 37 | + | ||
| 38 | + ### 1. Accumulate calls (buffer) | ||
| 20 | 39 | ||
| 21 | 40 | This is a demo of how events can be accumulated using the "buffer" operation. | |
| 22 | 41 | ||
| 23 | 42 | A button is provided and we accumulate the number of clicks on that button, over a span of time and then spit out the final results. | |
| 24 | 43 | ||
| 25 | - If you hit the button once. you'll get message saying the button was hit once. If you hit it 5 times continuosly within a span of 2 seconds, then you get a single log, saying you hit that button 5 times (vs 5 individual logs saying Button hit once). | ||
| 44 | + If you hit the button once. you'll get message saying the button was hit once. If you hit it 5 times continuosly within a span of 2 seconds, then you get a single log, saying you hit that button 5 times (vs 5 individual logs saying "Button hit once"). | ||
| 26 | 45 | ||
| 27 | 46 | Two implementations: | |
| 28 | 47 | ||
| 29 | 48 | 2a. Using a traditional observable - but encompassing the OnClick within the observable | |
| 30 | - 2b. Using PublishSubject and sending single clicks to the Observable, which inturn then sends it to the Observer | ||
| 49 | + 2b. Using PublishSubject and sending single clicks to the Observable, which in-turn then sends it to the Observer | ||
| 31 | 50 | ||
| 32 | - | ||
| 33 | - ### 3. Instant/Auto searching (using a subject and debounce) | ||
| 51 | + ### 1. Instant/Auto searching (subject + debounce) | ||
| 34 | 52 | ||
| 35 | 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". | |
| 36 | 54 | ||
| 37 | - 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. \n\nThis is the debounce/throttleWithTimeout method in RxJava. | ||
| 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. | ||
| 38 | 56 | ||
| 57 | + This is the debounce/throttleWithTimeout method in RxJava. | ||
| 39 | 58 | ||
| 40 | - ### 4. Orchestrating Observables (flatmap + zip) (wip) | ||
| 59 | + ### 1. Orchestrating Observables (flatmap + zip) (wip) | ||
| 41 | 60 | ||
| 42 | 61 | 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? | |
| 43 | 62 | ||
| 44 | 63 | ____________ A ________________ | |
| 45 | - (flatmap) / | (zip) | ||
| 64 | + (flatmap) / | (zip all 3) | ||
| 46 | 65 | X ------------/_____________ B ________________| ----------- > Ouput | |
| 47 | 66 | | | |
| 48 | 67 | Y ------------------------- C ________________| | |
| 49 | 68 | ||
| 50 | 69 | ||
| 51 | 70 | ||
| 52 | - ### 5. Pagination (zip) (wip) | ||
| 71 | + ### 1. Pagination (zip) (wip) | ||
| 53 | 72 | ||
| 54 | 73 | a. Simple pagination | |
| 55 | 74 | b. Optimized pagination | |
| 56 | 75 | ||
| 57 | 76 | ||
| 58 | - ### 6. Working examples of github from JakeWharton's Retrofit preso at Netflix (wip) | ||
| 59 | - | ||
| 60 | - https://www.youtube.com/watch?v=aEuNBk1b5OE#t=2480 | ||
| 61 | - https://speakerdeck.com/jakewharton/2014-1 | ||
| 62 | - | ||
| 63 | 77 | ||
| 64 | - ### 7. Replacing your event Bus (wip) | ||
| 78 | + ### 1. Replacing your event Bus (wip) | ||
| 65 | 79 | ||
| 66 | - http://stackoverflow.com/questions/19266834/rxjava-and-random-sporadic-events-on-android | ||
| 80 | + http://stackoverflow.com/questions/19266834/rxjava-and-random-sporadic-events-on-android | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments