rx-java2

RxJava: combine two optional observables

烈酒焚心 提交于 2021-02-19 04:09:14
问题 I have two Observable s, let's call them PeanutButter and Jelly . I'd like to combine them to a Sandwich Observable . I can do that using: Observable<PeanutButter> peanutButterObservable = ...; Observable<Jelly> jellyObservable = ...; Observable<Sandwich> sandwichObservable = Observable.combineLatest( peanutButterObservable, jellyObservable, (pb, j) -> makeSandwich(pb, j)) The problem is that RX waits for the first PeanutButter and the first Jelly to be emitted before emitting the first

RxJava: combine two optional observables

守給你的承諾、 提交于 2021-02-19 04:08:20
问题 I have two Observable s, let's call them PeanutButter and Jelly . I'd like to combine them to a Sandwich Observable . I can do that using: Observable<PeanutButter> peanutButterObservable = ...; Observable<Jelly> jellyObservable = ...; Observable<Sandwich> sandwichObservable = Observable.combineLatest( peanutButterObservable, jellyObservable, (pb, j) -> makeSandwich(pb, j)) The problem is that RX waits for the first PeanutButter and the first Jelly to be emitted before emitting the first

How to do a single row query with Android Room

ⅰ亾dé卋堺 提交于 2021-02-17 21:31:10
问题 How do I make a single row query with Android Room with RxJava? I am able to query for List of items, no issues. Here, I want to find if a specific row exists. According to the docs, looks like I can return Single and check for EmptyResultSetException exception if no row exists. I can have something like: @Query("SELECT * FROM Users WHERE userId = :id LIMIT 1") Single<User> findByUserId(String userId); How do I use this call? Looks like there is some onError / onSuccess but cannot find those

How to do a single row query with Android Room

陌路散爱 提交于 2021-02-17 21:30:19
问题 How do I make a single row query with Android Room with RxJava? I am able to query for List of items, no issues. Here, I want to find if a specific row exists. According to the docs, looks like I can return Single and check for EmptyResultSetException exception if no row exists. I can have something like: @Query("SELECT * FROM Users WHERE userId = :id LIMIT 1") Single<User> findByUserId(String userId); How do I use this call? Looks like there is some onError / onSuccess but cannot find those

Is It a Good Idea to Make Singleton's getInstance() Method Asynchronous by Making It Returns an Observable<Singleton>?

随声附和 提交于 2021-02-11 15:25:12
问题 I have a singleton that takes a few seconds to instantiate. It makes the UI freezes. So I'm planning to make the getInstance() method asynchronous. Is writing the following code a common practice? /* * The singleton class */ public class Singleton { private static volatile Singleton instance; public static Observable<Singleton> getInstance(Context context) { return Observable.fromCallable(() -> { synchronized (Singleton.class) { if (instance == null) instance = new Singleton(context

Dagger2: Using CompositeDisposable with Android Paging Library

。_饼干妹妹 提交于 2021-02-11 14:18:04
问题 I'm using Dagger2. I will be injecting CompositeDisposable in ViewModel through @Inject constructor(private val compositeDisposable: CompositeDisposable) And my screen would also be using Android Pagination library and inside PageKeyedDataSource class I would be adding every network call into compositeDisposable using it's .add(diposable) . I also would be adding CompositeDisposable in PageKeyedDataSource constructor through Dagger graph. Is there any way that CompositeDisposable in ViewModel

Why onNext() is updating textview, though observeOn(Schedulars.io()) on a different thread?

℡╲_俬逩灬. 提交于 2021-02-11 04:31:19
问题 Observable.range(11,10).subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) .subscribe(new Observer<Integer>() { @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onNext(@NonNull Integer integer) { textView.setText(String.valueOf(integer)); Log.d(TAG, "onNext: "+Thread.currentThread().getName()); } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); onNext() supposed to run on separate thread, but how is it

RxJava tricky startWith(Observable)

三世轮回 提交于 2021-02-10 05:51:47
问题 The following code emits items from observable1 only after observable2 is completed. observable1.startWith(observable2) .subscribe() I need to achieve another behavior observable1 -> 0 1 2 3 observable2 -> 1 2 3 4 5 6 observable1.startWithDefault(observable2) -> 1 2 0 1 2 3 The second observable emits items only while first observable is empty and then items from first one are emited. I could not find correct solution using only basic operators, what is correct RxJava 2 implementation of

Optional Observables in combineLatest

余生长醉 提交于 2021-02-08 19:43:35
问题 As definied combineLatest in rx emites only if all values have changed at least once. (so long as each of the source Observables has emitted at least one item) I use it to manipulate views within my android views. For example, I enable a call to action button as soon as all observables emitted a valid value. Otherwise I disable it. Observable.combineLatest( toObservable(email), toObservable(username), toObservable(status), toObservable(phonenumber), toObservable(birthdate), Function5<String,

Optional Observables in combineLatest

偶尔善良 提交于 2021-02-08 19:43:14
问题 As definied combineLatest in rx emites only if all values have changed at least once. (so long as each of the source Observables has emitted at least one item) I use it to manipulate views within my android views. For example, I enable a call to action button as soon as all observables emitted a valid value. Otherwise I disable it. Observable.combineLatest( toObservable(email), toObservable(username), toObservable(status), toObservable(phonenumber), toObservable(birthdate), Function5<String,