rx-java2

RxJava2 get event when Observable/Completed is completed or disposed

故事扮演 提交于 2019-12-06 05:36:57
I need to show a progress dialog when I subscribe to a Completable and hide it after the operation is completed(successfully or with an error) or is canceled. So I do final Completable completable = notificationRepository.markAllAsRead() .doOnSubscribe(d -> progressDialog.show()) .doOnError(error -> progressDialog.dismiss()) .doOnComplete(() -> progressDialog.dismiss()) .doOnDispose(() -> progressDialog.dismiss()); Is there any elegant way to get single callback when onError , onComplete or onDispose happens? Rostyslav Roshak I have done some tests, so doOnDispose is called when the subscriber

Convert/ wrap async listener to Observable (RxJava2)

给你一囗甜甜゛ 提交于 2019-12-06 01:12:29
I want to wrap a real listener to Observable object. For starters here is a test case, with him everything is fine. @Override public void onCreate(@Nullable Bundle savedInstanceState) { getObservablePhoneState() // Run on a background thread .subscribeOn(Schedulers.io()) // Be notified on the main thread .observeOn(AndroidSchedulers.mainThread()) .subscribe(integer -> Log.i(TAG, "----- subscribe onNext = " + integer)); } private Flowable<Integer> getObservablePhoneState() { return Flowable.create(emitter -> { Log.i(TAG, "Emitting 1"); emitter.onNext(1); Log.i(TAG, "Emitting 2"); emitter.onNext

RxAndroid Release Apk is not working for build 25.0.2

五迷三道 提交于 2019-12-05 19:10:11
I have posted this on rxandroid issue page too but no response its been 4 days but no response , problem is in debug apk rxjava functionalities are working as expected , but in release apk , only functionalities related to rxjava or rxandroid are not working at all build.gradle(project) apply plugin: 'com.android.application' //or apply plugin: 'java' apply plugin: 'me.tatarka.retrolambda' apply plugin: 'com.jakewharton.hugo' apply plugin: 'android-apt' def AAVersion = '4.1.0' android { compileSdkVersion 25 buildToolsVersion '25.0.2' defaultConfig { applicationId "com.jutt.example1"

RXJava2: correct pattern to chain retrofit requests

折月煮酒 提交于 2019-12-05 18:02:07
问题 I am relatively new to RXJava in general (really only started using it with RXJava2), and most documentation I can find tends to be RXJava1; I can usually translate between both now, but the entire Reactive stuff is so big, that it's an overwhelming API with good documentation (when you can find it). I'm trying to streamline my code, an I want to do it with baby steps. The first problem I want to solve is this common pattern I do a lot in my current project: You have a Request that, if

RxJava performing operation on a list and returning an observable

二次信任 提交于 2019-12-05 17:57:58
I'm new to RxJava (specifically, RxJava2) and I'm having some trouble with what seems to be a relatively easy operation. I need to get some data from a db, iterate through the data (it is represented as a list), perform an operation on each item, wrap the data in another object and return. This is what I have so far: mDataManager .getStuffList(id) .flatMapIterable(listOfStuff -> listOfStuff) .flatMap(item -> mDataManager .performCount(id, item.getTitle()) .doOnNext(item::setCounter) .takeLast(1) .map(counter -> item)) .toList() .toObservable() .flatMap(listOfStuff -> Observable.just(new

Rewrite Java code in Kotlin using Function Reference occurs SAM types conflict

无人久伴 提交于 2019-12-05 15:10:47
I have an example Java code using method reference that I want to rewrite to Kotlin. Java version is using method reference, solution is short and clear. But on the other hand I cannot use method reference in Kotlin. The only version that I've managed to write is one presented below. It seems like Function3 { s: String, b: Boolean, i: Int -> combine(s, b, i) } could be written in cleaner way (if possible method reference would be perfect). I'm new to Kotlin so I'll be grateful for any clues. Java import io.reactivex.Observable; public class TestJava { Observable<String> strings() { return

How can I explicitly signal completion of a Flowable in RxJava?

不问归期 提交于 2019-12-05 13:17:43
I'm trying to create a Flowable which is wrapping an Iterable . I push elements to my Iterable periodically but it seems that the completion event is implicit. I don't know how to signal that processing is complete. For example in my code: // note that this code is written in Kotlin val iterable = LinkedBlockingQueue<Int>() iterable.addAll(listOf(1, 2, 3)) val flowable = Flowable.fromIterable(iterable) .subscribeOn(Schedulers.computation()) .observeOn(Schedulers.computation()) flowable.subscribe(::println, {it.printStackTrace()}, {println("completed")}) iterable.add(4) Thread.sleep(1000)

RxJava - How to stop (and resume) a Hot Observable (interval)?

假如想象 提交于 2019-12-05 12:56:42
I have the following Hot Observable: hotObservable = Observable.interval(0L, 1L, TimeUnit.SECONDS) .map((t) -> getCurrentTimeInMillis())) However, I can't find a good way to stop it. I was able to partially solve this using takeWhile and a boolean flag ( runTimer ): Observable.interval(0L, 1L, TimeUnit.SECONDS) .takeWhile((t) -> runTimer) .map((t) -> getCurrentTimeInMillis())) There are 2 things I don't like in this approach though: I must keep the flag runTimer around, which I don't want. Once runTimer becomes false , the Observable simply completes, which means if I want to emit again I need

What is the MutableLiveData equivalent in RxJava?

被刻印的时光 ゝ 提交于 2019-12-05 10:31:40
Per the example below from the LiveData Android documentation, what would be the RxJava 2 equivalent? We certainly can use a combination of publish() , refcount() and replay() to achieve the core of the MutableLiveData observable behavior. That said, what would be the analogous counterpart of mCurrentName.setValue() as it pertains to detecting a change and emitting the corresponding event? public class NameViewModel extends ViewModel { // Create a LiveData with a String private MutableLiveData<String> mCurrentName; public MutableLiveData<String> getCurrentName() { if (mCurrentName == null) {

RxJava2 Publish

我是研究僧i 提交于 2019-12-05 08:11:38
What is the difference between ObservableTransformer { Observable.merge( it.ofType(x).compose(transformerherex), it.ofType(y).compose(transformerherey) ) } and ObservableTransformer { it.publish{ shared -> Observable.merge( shared.ofType(x).compose(transformerherex), shared.ofType(y).compose(transformerherey) ) } } when I run my code using this two, I got the same results. What does publish do here. The difference is that the top transformer will subscribe to the upstream twice for a single subscription from the downstream, duplicating any side effects of the upstream which is usually not