RxJava-RxKotlin-Android-Samples
Learn RxKotlin with simple coding examples
Migration from RxKotlin 1.0 to RxKotlin 2.0
To allow having RxKotlin 1 and RxKotlin 2 side-by-side, RxKotlin 2 is under the maven coordinates io.reactivex.rxjava2:rxjava:2.x.y and classes are accessible below io.reactivex. Users switching from 1.x to 2.x have to re-organize their imports, but carefully.
Using RxKotlin 2.0 Library in your application
Add this in your build.gradle
compile 'io.reactivex.rxjava2:rxjava:2.1.1'
If you are using RxAndroid also, then add the following
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
Quick Look on few changes done in RxKotlin2 over RxKotlin1
RxJava1/RxKotlin1 -> RxJava2/RxKotlin2
onCompleted->onComplete- without the trailing dFunc1->FunctionFunc2->BiFunctionCompositeSubscription->CompositeDisposablelimitoperator has been removed - Usetakein RxKotlin2
....... and so on
RxOperators :
map()-> Transform the items emitted by an Observable by applying a function to each itemzip()-> Combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this functiontake()-> Emit only the first n items emitted by an Observabletimer()-> Create an Observable that emits a particular item after a given delayflatMap()-> Transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observableinterval()-> Create an Observable that emits a sequence of integers spaced by a given time intervaldebounce()-> Only emit an item from an Observable if a particular time span has passed without it emitting another itemSingle Observer-> A Single is something like an Observable, but instead of emitting a series of values — anywhere from none at all to an infinite number — it always either emits one value or an error notification.reduce()-> Apply a function to each item emitted by an Observable, sequentially, and emit the final valuebuffer()-> Periodically gather items emitted by an Observable into bundles and emit these bundles rather than emitting the items one at a timefilter()-> Emit only those items from an Observable that pass a predicate testskip()-> Suppress the first n items emitted by an Observablescan()-> Apply a function to each item emitted by an Observable, sequentially, and emit each successive valuereplay()-> Ensure that all observers see the same sequence of emitted items, even if they subscribe after the Observable has begun emitting itemsconcat()-> Emit the emissions from two or more Observables without interleaving themmerge()-> Combine multiple Observables into one by merging their emissionsdefer()-> The Defer operator waits until an observer subscribes to it, and then it generates an Observable, typically with an Observable factory function. It does this afresh for each subscriber, so although each subscriber may think it is subscribing to the same Observable, in fact each subscriber gets its own individual sequence.distinct()-> Suppress duplicate items emitted by an ObservableReplay Subject-> Replays events (in a configurable bounded or unbounded manner) to current and late Observers.Publish Subject-> Subject that, once an Observer has subscribed, emits all subsequently observed items to the subscriberBehaviour Subject-> Subject that emits the most recent item it has observed and all subsequent observed items to each subscribed Observer.Aync Subject-> A Subject that emits the very last value followed by a completion event or the received error to Observers.Throttle First-> Emit the first items emitted by an Observable within periodic time intervalsamb()-> Given two or more source Observables, emits all of the items from the first of these Observables to emit an itemCatch-> Recover from an onError notification by continuing the sequence without errorRetry-> If a source Observable emits an error, resubscribe to it in the hopes that it will complete without errorComing More
TODO
Adding more operator examples
Highlights :
- SimpleOperatorActivity - Using
Simpleoperator - MapOperatorActivity - Using
Mapoperator - ZipOperatorActivity - Using
Zipobserver - DisposableOperatorActivity - Using
Disposableoperator - FlatMapOperatorActivity - Using
FlatMapOperator - IntervalOperatorActivity - Using
IntervalOperator - TakeOperatorActivity - Using
TakeOperator - TimerOperatorActivity - Using
TimerOperator - DebounceOperatorActivity - Using
DebounceOperator - SingleObserverOperatorActivity - Using
Single ObserverOperator - FlowableOperatorActivity - Using
Flowable - ReduceOperatorActivity -Using
ReduceOperator - BufferOperatorActivity -Using
BufferOperator - FilterOperatorActivity -Using
FilterOperator - SkipOperatorActivity -Using
SkipOperator - ScanOperatorActivity -Using
ScanOperator - ReplayOperatorActivity -Using
ReplayOperator - ConcatOperatorActivity -Using
ConcatOperator - MergeOperatorActivity -Using
MergeOperator - DeferOperatorActivity -Using
DeferOperator - DistinctOperatorActivity -Using
DistinctOperator - ReplaySubjectOperatorActivity -Using
Replay SubjectOperator - PublishSubjectOperatorActivity -Using
Publish SubjectOperator - BehaviorSubjectActivity -Using
Behavior SubjectOperator - AsyncSubjectOperatorActivity -Using
Aync SubjectOperator - ThrottleFirstOperatorActivity -Using
Throttle FirstOperator - ThrottleLastOperatorActivity -Using
Throttle LastOperator - WindowOperatorActivity -Using
WindowOperator - AmbOperatorActivity -Using
AmbOperator - DelayOperatorActivity -Using
DelayOperator - CombineLatestOperatorActivity
- CompletableObserverOperatorActivity
- RepeatWhenOperatorActivity
- Coming More
RxBinding
Rx is powerful because we can compose transformations. What that means is that we can have reusable, safe and more functional code that simply plugs into your code.
As an example let’s say we’re making a login screen with an email and a password…
Consider the following rules that we want for our email addresses
- Length should be greater than 6
- Should have a correct email pattern
- Let the user know if any of the above fails
- On each key stroke, verify
Highlights :
- RxLoginScreenActivity - Login Screen using RxBinding
Pagination And Lazy loading using RxKotlin
Highlights :
- PaginationActivity - Activity containing recyclerview and data.
- PaginationAdapter - Adapter containing layout item
Contact - Let's connect to learn together
License
Copyright 2017 Ankit Kumar
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.
