rx-android

Get response status code using Retrofit 2.0 and RxJava

≡放荡痞女 提交于 2019-11-27 02:29:55
I'm trying to upgrade to Retrofit 2.0 and add RxJava in my android project. I'm making an api call and want to retrieve the error code in case of an error response from the server. Observable<MyResponseObject> apiCall(@Body body); And in the RxJava call: myRetrofitObject.apiCall(body).subscribe(new Subscriber<MyResponseObject>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(MyResponseObject myResponseObject) { //On response from server } }); In Retrofit 1.9, the RetrofitError still existed and we could get the status by

rxJava Schedulers Use Cases

淺唱寂寞╮ 提交于 2019-11-26 21:13:44
In RxJava there are 5 different schedulers to choose from: immediate() : Creates and returns a Scheduler that executes work immediately on the current thread. trampoline() : Creates and returns a Scheduler that queues work on the current thread to be executed after the current work completes. newThread() : Creates and returns a Scheduler that creates a new Thread for each unit of work. computation() : Creates and returns a Scheduler intended for computational work. This can be used for event-loops, processing callbacks and other computational work. Do not perform IO-bound work on this

Deliver the first item immediately, 'debounce' following items

一笑奈何 提交于 2019-11-26 20:31:38
问题 Consider the following use case: need to deliver first item as soon as possible need to debounce following events with 1 second timeout I ended up implementing custom operator based on OperatorDebounceWithTime then using it like this .lift(new CustomOperatorDebounceWithTime<>(1, TimeUnit.SECONDS, Schedulers.computation())) CustomOperatorDebounceWithTime delivers the first item immediately then uses OperatorDebounceWithTime operator's logic to debounce later items. Is there an easier way to

Combine a list of Observables and wait until all completed

筅森魡賤 提交于 2019-11-26 18:46:51
问题 TL;DR How to convert Task.whenAll(List<Task>) into RxJava ? My existing code uses Bolts to build up a list of asynchronous tasks and waits until all of those tasks finish before performing other steps. Essentially, it builds up a List<Task> and returns a single Task which is marked as completed when all tasks in the list complete, as per the example on the Bolts site. I'm looking to replace Bolts with RxJava and I'm assuming this method of building up a list of async tasks (size not known in

Get response status code using Retrofit 2.0 and RxJava

混江龙づ霸主 提交于 2019-11-26 10:07:36
问题 I\'m trying to upgrade to Retrofit 2.0 and add RxJava in my android project. I\'m making an api call and want to retrieve the error code in case of an error response from the server. Observable<MyResponseObject> apiCall(@Body body); And in the RxJava call: myRetrofitObject.apiCall(body).subscribe(new Subscriber<MyResponseObject>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(MyResponseObject myResponseObject) { //On

Use cases for RxJava schedulers

淺唱寂寞╮ 提交于 2019-11-26 07:50:49
问题 In RxJava there are 5 different schedulers to choose from: immediate() : Creates and returns a Scheduler that executes work immediately on the current thread. trampoline() : Creates and returns a Scheduler that queues work on the current thread to be executed after the current work completes. newThread() : Creates and returns a Scheduler that creates a new Thread for each unit of work. computation() : Creates and returns a Scheduler intended for computational work. This can be used for event