rx-java2

RxJava performing operation on a list and returning an observable

痴心易碎 提交于 2019-12-07 08:29:06
问题 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

What is the MutableLiveData equivalent in RxJava?

别来无恙 提交于 2019-12-07 05:09:31
问题 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

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

本秂侑毒 提交于 2019-12-07 03:46:22
问题 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.

RxJava2 Publish

依然范特西╮ 提交于 2019-12-07 03:10:14
问题 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. 回答1: The difference is that the top transformer will subscribe to the upstream twice for a

Rxjava 2 exception with camera

喜欢而已 提交于 2019-12-07 01:15:27
问题 I just switched my code from asynctask to rxjava2 and I'm randomly getting this exception on my nexus: Camera is being used after Camera.release() was called in Galaxy s6 Edge Following is my code- Class Camera : public class Cameras { private static final String TAG = Cameras.class.getSimpleName(); private static final String SP_CAMERA_ID = "camera_id"; private static final int NO_NEXT_TASK = 0; private static final int NEXT_TASK_RELEASE_COMPLETE = 1; private static final int NEXT_TASK

Android room insert with Completable not working? methods annotated with @insert can return either void,long?

醉酒当歌 提交于 2019-12-06 15:59:03
The versions i'm using are implementation 'io.reactivex.rxjava2:rxjava:2.2.4' implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0' implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' implementation 'android.arch.persistence.room:runtime:2.1.0-alpha04' kapt 'android.arch.persistence.room:compiler:2.1.0-alpha04' implementation 'android.arch.persistence.room:rxjava2:2.1.0-alpha04' and the Dao is @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertStore(stores: Stores): Completable From this great article on

How to retry a consumed Observable?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 09:29:06
I am trying to re-execute a defined observable that failed. Using Retrofit2 and RxJava2 together i want to retry a specific request with its subscription and behavior when clicking a button. is that possible? service.excecuteLoginService(url, tokenModel, RetrofitManager.apiKey) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(....) An option is to create Publisher, which emission is controlled by your button. final PublishSubject<Object> retrySubject = PublishSubject.create(); service.excecuteLoginService(url, tokenModel, RetrofitManager.apiKey)

Emit each item from Flowable Room ORM

Deadly 提交于 2019-12-06 07:58:35
问题 I have a list of items in the Room ORM which I would like to display in a Recycler view. The data is being added from the network to the db. The problem is I am getting every time the whole list emited from the Flowable and not each item. I have tried with .distinctUntilChanged with no difference. @Query("SELECT * FROM items") Flowable<List<Item>> getItems(); I have tried also to return only a single item which loads only the first one that is the db. 回答1: You can use flatMap to get stream of

Wait until the user stops typing before executing a heavy search in searchview

我与影子孤独终老i 提交于 2019-12-06 07:19:39
问题 Search is central in my app and I need it to work well. Right now I have a SearchView. I need to display the results inline, so I'm using this code. searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { srl.setVisibility(View.GONE); return false; } @Override public boolean onQueryTextChange(String query) { currentQuery = query; if (query.length()>= 3) { searchFor(currentQuery); } else { srl.setVisibility(View.GONE);

Could crashlytics crash on Android?

拈花ヽ惹草 提交于 2019-12-06 06:55:35
问题 Here is an overview of a crash on fabric.io java.lang.IllegalStateException - Fatal exception thrown on Scheduler.Worker thread rx.exceptions.OnErrorFailedException - an exception originating somewhere in the depth of rx and ending in SafeSubscriber#_onError . rx.exceptions.CompositeException - 2 exceptions occured Casual chain - that's the interesting part Caused by rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received => at