|
1 | 1 | <img src=https://raw.githubusercontent.com/amitshekhariitbhu/RxJava2-Android-Samples/master/assets/rxjava2.png > |
2 | 2 |
|
3 | | -# Learning RxJava 2 for Android by example |
4 | 3 |
|
5 | | -[](https://mindorks.com/open-source-projects) |
6 | | -[](https://mindorks.com/join-community) |
7 | | -[](https://mindorks.com/android/store) |
8 | | -[](https://opensource.org/licenses/Apache-2.0) |
9 | | -[](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/LICENSE) |
10 | | - |
11 | | - |
12 | | -### How to use RxJava 2 in Android Application |
13 | | -### How to migrate from RxJava 1.0 to RxJava 2.0 |
14 | | - |
15 | | -### This project is for : |
16 | | -* who is migrating to RxJava 2 |
17 | | -* or just started with RxJava. |
18 | | - |
19 | | -## [My Personal Blog - amitshekhar.me](https://amitshekhar.me/blog) - High-quality content to learn Android concepts. |
20 | | - |
21 | | -### Just Build the project and start learning RxJava by examples. |
22 | | - |
23 | | -RxJava 2.0 has been completely rewritten from scratch on top of the Reactive-Streams specification. The specification itself has evolved out of RxJava 1.x and provides a common baseline for reactive systems and libraries. |
24 | | - |
25 | | -Because Reactive-Streams has a different architecture, it mandates changes to some well known RxJava types. |
26 | | - |
27 | | - |
28 | | -# Migration From RxJava 1.0 to RxJava 2.0 |
29 | | - |
30 | | -To allow having RxJava 1 and RxJava 2 side-by-side, RxJava 2 is under the maven coordinates |
31 | | -io.reactivex.rxjava2:rxjava:2.x.y and classes are accessible below io.reactivex. |
32 | | - |
33 | | -Users switching from 1.x to 2.x have to re-organize their imports, but carefully. |
34 | | - |
35 | | -### Using RxJava 2.0 Library in your application |
36 | | - |
37 | | -Add this in your build.gradle |
38 | | -```groovy |
39 | | -compile 'io.reactivex.rxjava2:rxjava:2.2.2' |
40 | | -``` |
41 | | -If you are using RxAndroid also, then add the following |
42 | | -```groovy |
43 | | -compile 'io.reactivex.rxjava2:rxandroid:2.1.0' |
44 | | -``` |
45 | | - |
46 | | -# RxJava 2 Examples present in this sample project |
47 | | - |
48 | | -* RxJava 2.0 Example using `CompositeDisposable` as `CompositeSubscription` and `Subscription` have |
49 | | -been removed. |
50 | | - |
51 | | -* RxJava 2 Example using `Flowable`. |
52 | | - |
53 | | -* RxJava 2 Example using `SingleObserver`, `CompletableObserver`. |
54 | | - |
55 | | -* RxJava 2 Example using RxJava2 operators such as `map, zip, take, reduce, flatMap, filter, buffer, skip, merge, concat, replay`, and much more: |
56 | | - |
57 | | -* RxJava 2 Android Samples using `Function` as `Func1` has been removed. |
58 | | - |
59 | | -* RxJava 2 Android Samples using `BiFunction` as `Func2` has been removed. |
60 | | - |
61 | | -* And many others android examples |
62 | | - |
63 | | -# Quick Look on few changes done in RxJava2 over RxJava1 |
64 | | - |
65 | | -RxJava1 -> RxJava2 |
66 | | - |
67 | | -* `onCompleted` -> `onComplete` - without the trailing d |
68 | | -* `Func1` -> `Function` |
69 | | -* `Func2` -> `BiFunction` |
70 | | -* `CompositeSubscription` -> `CompositeDisposable` |
71 | | -* `limit` operator has been removed - Use `take` in RxJava2 |
72 | | -* and much more. |
73 | | - |
74 | | -# Operators : |
75 | | -* `Map` -> transform the items emitted by an Observable by applying a function to each item |
76 | | -* `Zip` -> combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this function |
77 | | -* `Filter` -> emit only those items from an Observable that pass a predicate test |
78 | | -* `FlatMap` -> transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable |
79 | | -* `Take` -> emit only the first n items emitted by an Observable |
80 | | -* `Reduce` -> apply a function to each item emitted by an Observable, sequentially, and emit the final value |
81 | | -* `Skip` -> suppress the first n items emitted by an Observable |
82 | | -* `Buffer` -> periodically gather items emitted by an Observable into bundles and emit these bundles rather than emitting the items one at a time |
83 | | -* `Concat` -> emit the emissions from two or more Observables without interleaving them |
84 | | -* `Replay` -> ensure that all observers see the same sequence of emitted items, even if they subscribe after the Observable has begun emitting items |
85 | | -* `Merge` -> combine multiple Observables into one by merging their emissions |
86 | | -* `SwitchMap` -> transform the items emitted by an Observable into Observables, and mirror those items emitted by the most-recently transformed Observable |
87 | | - |
88 | | - |
89 | | -# Highlights of the examples : |
90 | | - |
91 | | -* [DisposableExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/DisposableExampleActivity.java) - Using `CompositeDisposable` |
92 | | -* [FlowableExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/FlowableExampleActivity.java) - Using `Flowable` and `reduce` operator |
93 | | -* [SingleObserverExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/SingleObserverExampleActivity.java) - Using `SingleObserver` |
94 | | -* [CompletableObserverActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/CompletableObserverExampleActivity.java) - Using `CompletableObserver` |
95 | | -* [MapExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/MapExampleActivity.java) - Using `map` Operator |
96 | | -* [ZipExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/ZipExampleActivity.java) - Using `zip` Operator, [Blog for reference](https://blog.mindorks.com/understanding-rxjava-zip-operator-with-example) |
97 | | -* [BufferExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/BufferExampleActivity.java) - Using `buffer` Operator |
98 | | -* [TakeExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/TakeExampleActivity.java) - Using `take` Operator |
99 | | -* [ReduceExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/ReduceExampleActivity.java) - Using `reduce` Operator |
100 | | -* [FilterExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/FilterExampleActivity.java) - Using `filter` Operator |
101 | | -* [SkipExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/SkipExampleActivity.java) - Using `skip` Operator |
102 | | -* [ReplayExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/ReplayExampleActivity.java) - Using `replay` Operator |
103 | | -* [ConcatExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/ConcatExampleActivity.java) - Using `concat` Operator |
104 | | -* [MergeExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/MergeExampleActivity.java) - Using `merge` Operator |
105 | | -* [DeferExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/DeferExampleActivity.java) - Using `defer` Observable |
106 | | -* [SwitchMapExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/SwitchMapExampleActivity.java) - Using `switchMap` Observable |
107 | | -* [IntervalExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/IntervalExampleActivity.java) - Using `Interval` |
108 | | -* [RxBusActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/rxbus/RxBusActivity.java) - RxBus, RxJava2Bus, EventBus, RxEventBus, [Blog for reference](https://blog.mindorks.com/implementing-eventbus-with-rxjava-rxbus-e6c940a94bd8) |
109 | | -* [PaginationActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/pagination/PaginationActivity.java) - Pagination for loadMore in RecyclerView |
110 | | -* [ComposeOperatorExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/compose/ComposeOperatorExampleActivity.java) - Compose operator for reusable |
111 | | -* [Search Implementation](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/search/SearchActivity.java) - Using `debounce`, `switchMap`, `distinctUntilChanged`, [Blog for reference](https://blog.mindorks.com/implement-search-using-rxjava-operators-c8882b64fe1d) |
112 | | -* [Implement Caching Using RxJava Operators](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/cache/CacheExampleActivity.java) - Using `concat`, `firstElement`, [Blog for reference](https://blog.mindorks.com/implement-caching-in-android-using-rxjava-operators) |
113 | | -* [PublishSubjectExampleActivity](https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/operators/PublishSubjectExampleActivity.java) |
114 | | - |
115 | | -### TODO |
116 | | - |
117 | | -* Many examples are to be added |
118 | | - |
119 | | -### Find this project useful ? :heart: |
120 | | -* Support it by clicking the :star: button on the upper right of this page. :v: |
121 | | - |
122 | | -### Check out an awesome MVP architecture based project which uses RxJava2, Dagger2. |
123 | | -* [Android-MVP-Architecture](https://github.com/MindorksOpenSource/android-mvp-architecture) |
124 | | - |
125 | | -### Check out an awesome Kotlin MVP architecture based project which uses RxJava2, Dagger2. |
126 | | -* [Android-Kotlin-MVP-Architecture](https://github.com/MindorksOpenSource/android-kotlin-mvp-architecture) |
127 | | - |
128 | | -### Check out an awesome library for fast and simple networking in Android. |
129 | | -* [Fast Android Networking Library](https://github.com/amitshekhariitbhu/Fast-Android-Networking) |
130 | | - |
131 | | -### Another awesome library for debugging databases and shared preferences. |
132 | | -* [Android Debug Database](https://github.com/amitshekhariitbhu/Android-Debug-Database) |
133 | | - |
134 | | - |
135 | | -### Learn to build a ride-sharing Android app like Uber, Lyft. |
136 | | -* [Check here](https://github.com/MindorksOpenSource/ridesharing-uber-lyft-app) |
137 | | - |
138 | | -### [Check out Mindorks awesome open source projects here](https://mindorks.com/open-source-projects) |
139 | | - |
140 | | -### Contact - Let's become friend |
141 | | -- [Twitter](https://twitter.com/amitiitbhu) |
142 | | -- [Github](https://github.com/amitshekhariitbhu) |
143 | | -- [Medium](https://medium.com/@amitshekhar) |
144 | | -- [Facebook](https://www.facebook.com/amit.shekhar.iitbhu) |
145 | | - |
146 | | -### License |
147 | | -``` |
148 | | - Copyright (C) 2016 Amit Shekhar |
149 | | - Copyright (C) 2011 Android Open Source Project |
150 | | -
|
151 | | - Licensed under the Apache License, Version 2.0 (the "License"); |
152 | | - you may not use this file except in compliance with the License. |
153 | | - You may obtain a copy of the License at |
154 | | -
|
155 | | - http://www.apache.org/licenses/LICENSE-2.0 |
156 | | -
|
157 | | - Unless required by applicable law or agreed to in writing, software |
158 | | - distributed under the License is distributed on an "AS IS" BASIS, |
159 | | - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
160 | | - See the License for the specific language governing permissions and |
161 | | - limitations under the License. |
162 | | -``` |
163 | | - |
164 | | -### Contributing to RxJava 2 Android Samples |
165 | | -Just make pull request. You are in! |
166 | 4 |
|
167 | 5 |
|
0 commit comments