Support
Quality
Security
License
Reuse
kandi has reviewed RxJava-Android-Samples and discovered the below as its top functions. This is intended to give you an instant insight into RxJava-Android-Samples implemented functionality, and help decide if they suit your requirements.
[Learning RxJava For Android by Example : Part 1](https://www.youtube.com/watch?v=k3D0cWyNno4) \[[slides](https://speakerdeck.com/kaushikgopal/learning-rxjava-for-android-by-example)\] (SF Android Meetup 2015)
[Learning Rx by Example : Part 2](https://vimeo.com/190922794) \[[slides](https://speakerdeck.com/kaushikgopal/learning-rx-by-example-2)\] (Øredev 2016)
[Background work & concurrency (using Schedulers)](#1-background-work—concurrency-using-schedulers)
[Accumulate calls (using buffer)](#2-accumulate-calls-using-buffer)
[Instant/Auto searching text listeners (using Subjects & debounce)](#3-instantauto-searching-text-listeners-using-subjects—debounce)
[Networking with Retrofit & RxJava (using zip, flatmap)](#4-networking-with-retrofit—rxjava-using-zip-flatmap)
[Two-way data binding for TextViews (using PublishSubject)](#5-two-way-data-binding-for-textviews-using-publishsubject)
[Simple and Advanced polling (using interval and repeatWhen)](#6-simple-and-advanced-polling-using-interval-and-repeatwhen)
[Simple and Advanced exponential backoff (using delay and retryWhen)](#7-simple-and-advanced-exponential-backoff-using-delay-and-retrywhen)
[Form validation (using combineLatest)](#8-form-validation-using-combinelatest)
[Pseudo caching : retrieve data first from a cache, then a network call (using concat, concatEager, merge or publish)](#9-pseudo-caching—retrieve-data-first-from-a-cache-then-a-network-call-using-concat-concateager-merge-or-publish)
[Simple timing demos (using timer, interval or delay)](#10-simple-timing-demos-using-timer-interval-and-delay)
[RxBus : event bus using RxJava (using RxRelay (never terminating Subjects) and debouncedBuffer)](#11-rxbus—event-bus-using-rxjava-using-rxrelay-never-terminating-subjects-and-debouncedbuffer)
[Persist data on Activity rotations (using Subjects and retained Fragments)](#12-persist-data-on-activity-rotations-using-subjects-and-retained-fragments)
[Networking with Volley](#13-networking-with-volley)
[Pagination with Rx (using Subjects)](#14-pagination-with-rx-using-subjects)
[Orchestrating Observable: make parallel network calls, then combine the result into a single data point (using flatmap & zip)](#15-orchestrating-observable-make-parallel-network-calls-then-combine-the-result-into-a-single-data-point-using-flatmap—zip)
[Simple Timeout example (using timeout)](#16-simple-timeout-example-using-timeout)
[Setup and teardown resources (using using)](#17-setup-and-teardown-resources-using-using)
[Multicast playground](#18-multicast-playground)
Simple Polling: say when you want to execute a certain task every 5 seconds
Increasing Delayed Polling: say when you want to execute a task first in 1 second, then in 2 seconds, then 3 and so on.
http://stackoverflow.com/a/25292833/159825
Another excellent implementation via @[sddamico](https://github.com/sddamico) : https://gist.github.com/sddamico/c45d7cdabc41e663bea1
This one includes support for jittering, by @[leandrofavarin](https://github.com/leandrofavarin) : http://leandrofavarin.com/exponential-backoff-rxjava-operator-with-jitter
[.concat](http://reactivex.io/documentation/operators/concat.html)
[.concatEager](http://reactivex.io/RxJava/javadoc/rx/Observable.html#concatEager(java.lang.Iterable))
[.merge](http://reactivex.io/documentation/operators/merge.html)
[.publish](http://reactivex.io/RxJava/javadoc/rx/Observable.html#publish(rx.functions.Func1)) selector + merge + takeUntil
run a single task after a delay of 2s, then complete
run a task constantly every 1s (there’s a delay of 1s before the first task fires off)
run a task constantly every 1s (same as above but there’s no delay before the first task fires off)
run a task constantly every 3s, but after running it 5 times, terminate automatically
run a task A, pause for sometime, then execute Task B, then terminate
[Implementing an event bus with RxJava](http://blog.kaush.co/2014/12/24/implementing-an-event-bus-with-rxjava-rxbus/)
[DebouncedBuffer used for the fancier variant of the demo](http://blog.kaush.co/2015/01/05/debouncedbuffer-with-rxjava/)
[share/publish/refcount](http://blog.kaush.co/2015/01/21/rxjava-tip-for-the-day-share-publish-refcount-and-all-that-jazz/)
[Matthias example of an Rx based pager](https://gist.github.com/mttkay/24881a0ce986f6ec4b4d)
[Eugene’s very comprehensive Pagination sample](https://github.com/matzuk/PaginationSample)
[Recursive Paging example](http://stackoverflow.com/questions/28047272/handle-paging-with-rxjava)
Have a look at [PR #83 to see the diff of changes between RxJava 1 and 2](https://github.com/kaushikgopal/RxJava-Android-Samples/pull/83/files)
[What’s different in Rx 2.x](https://github.com/ReactiveX/RxJava/wiki/What’s-different-in-2.0)
default
(flatmap)
f1 ___________________ f3 _______
(flatmap) | (zip)
f2 ___________________ f4 _______| ___________ final output
\ |
\____________ f5 _______|
Query on RxJava thread scheduling
/**
* Once that you set in your pipeline the observerOn all the next steps of your pipeline will be executed in another thread.
* Shall print
* First step main
* Second step RxNewThreadScheduler-2
* Third step RxNewThreadScheduler-1
*/
@Test
public void testObservableObserverOn() throws InterruptedException {
Subscription subscription = Observable.just(1)
.doOnNext(number -> System.out.println("First step " + Thread.currentThread()
.getName()))
.observeOn(Schedulers.newThread())
.doOnNext(number -> System.out.println("Second step " + Thread.currentThread()
.getName()))
.observeOn(Schedulers.newThread())
.doOnNext(number -> System.out.println("Third step " + Thread.currentThread()
.getName()))
.subscribe();
new TestSubscriber((Observer) subscription)
.awaitTerminalEvent(100, TimeUnit.MILLISECONDS);
}
/**
* Does not matter at what point in your pipeline you set your subscribeOn, once that is set in the pipeline,
* all steps will be executed in another thread.
* Shall print
* First step RxNewThreadScheduler-1
* Second step RxNewThreadScheduler-1
*/
@Test
public void testObservableSubscribeOn() throws InterruptedException {
Subscription subscription = Observable.just(1)
.doOnNext(number -> System.out.println("First step " + Thread.currentThread()
.getName()))
.subscribeOn(Schedulers.newThread())
.doOnNext(number -> System.out.println("Second step " + Thread.currentThread()
.getName()))
.subscribe();
new TestSubscriber((Observer) subscription)
.awaitTerminalEvent(100, TimeUnit.MILLISECONDS);
}
-----------------------
/**
* Once that you set in your pipeline the observerOn all the next steps of your pipeline will be executed in another thread.
* Shall print
* First step main
* Second step RxNewThreadScheduler-2
* Third step RxNewThreadScheduler-1
*/
@Test
public void testObservableObserverOn() throws InterruptedException {
Subscription subscription = Observable.just(1)
.doOnNext(number -> System.out.println("First step " + Thread.currentThread()
.getName()))
.observeOn(Schedulers.newThread())
.doOnNext(number -> System.out.println("Second step " + Thread.currentThread()
.getName()))
.observeOn(Schedulers.newThread())
.doOnNext(number -> System.out.println("Third step " + Thread.currentThread()
.getName()))
.subscribe();
new TestSubscriber((Observer) subscription)
.awaitTerminalEvent(100, TimeUnit.MILLISECONDS);
}
/**
* Does not matter at what point in your pipeline you set your subscribeOn, once that is set in the pipeline,
* all steps will be executed in another thread.
* Shall print
* First step RxNewThreadScheduler-1
* Second step RxNewThreadScheduler-1
*/
@Test
public void testObservableSubscribeOn() throws InterruptedException {
Subscription subscription = Observable.just(1)
.doOnNext(number -> System.out.println("First step " + Thread.currentThread()
.getName()))
.subscribeOn(Schedulers.newThread())
.doOnNext(number -> System.out.println("Second step " + Thread.currentThread()
.getName()))
.subscribe();
new TestSubscriber((Observer) subscription)
.awaitTerminalEvent(100, TimeUnit.MILLISECONDS);
}
QUESTION
RxJava2 Flowable.combineLatest behavior if all Flowables don't emit
Asked 2017-Jul-05 at 19:55I am following this code to do some error validation. Here's the combineLatest implementation which accepts inputs from 3 fields and does error validation on each of them.
Flowable.combineLatest(
_emailChangeObservable,
_passwordChangeObservable,
_numberChangeObservable,
(newEmail, newPassword, newNumber) -> {
boolean emailValid = !isEmpty(newEmail) && EMAIL_ADDRESS.matcher(newEmail).matches();
if (!emailValid) {
_email.setError("Invalid Email!");
}
boolean passValid = !isEmpty(newPassword) && newPassword.length() > 8;
if (!passValid) {
_password.setError("Invalid Password!");
}
boolean numValid = !isEmpty(newNumber);
if (numValid) {
int num = Integer.parseInt(newNumber.toString());
numValid = num > 0 && num <= 100;
}
if (!numValid) {
_number.setError("Invalid Number!");
}
return emailValid && passValid && numValid;
})
.subscribe(_disposableObserver);
My problem is that the combiner function is not triggered unless all 3 input field observables have emitted at least once. So when users enter an incorrect email address, they are not notified until they have entered some data in all the 3 fields.
ANSWER
Answered 2017-Jul-05 at 19:55combineLatest()
must have all values for starting emitting something, as by definition the combiner function gets n values that emitted from n sources.
When RxBInding wraps TextView
events with RxTextView
, it emits an initial value (contents of the TextView
) when subscribed, so without the skip(1)
, you will have your desired logic, the thing is the validation logic in this sample do not expect that, and display error for empty values (by the !isEmpty(newXXX)
checks).
My hunch based on the explicit skip(1)
transformation is that in this example this is the desired behavior - meaning just when all fields has been entered we need to display errors.
In your case if you want to implement your logic, you need to skip empty values from displaying errors while still emit false
at the end as the whole input is not yet valid, then - with any change at any fields independent of the others, while not empty you will the errors .
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit