rx-java

RxJava data from DB with onscreen list

杀马特。学长 韩版系。学妹 提交于 2019-12-25 08:04:57
问题 I've just begun to learn RxJava and I'm a little bit lost. My scenario is the following: A local NoSQL key-value database where I store some data. The problem is that the endpoint can add data to this DB and also the user can delete some of it. I'm displaying this data as an on-screen list (RecyclerView). I'd like to know what is the best approach to always know what's the most up to date data from the DB in a single place so I can update the UI accordingly. 回答1: What you're looking for is a

Is it ok to transform following code in rxjava

心不动则不痛 提交于 2019-12-25 07:58:48
问题 For example, I have following runnable java code. It is about a producer and several parallel consumers. These consumers are running time consuming jobs, and they are running in parallel. I wonder if this use case match rx-java, and how to rewrite it in rx-java. public class DemoInJava { public static void main(String[] args) { final BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(); AtomicBoolean done = new AtomicBoolean(false); Thread producer = new Thread(() -> { int offset = 0;

How to make multiple requests with reactive android and retrofit

最后都变了- 提交于 2019-12-25 07:50:13
问题 I have presenter which calls getShops() method. Observable<List<Shop>> observable = interactor.getData(); Subscription subscription = observable .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<List<Shop>>() { @Override public void onCompleted() { view.hideProgress(); } @Override public void onError(Throwable e) { super.onError(e); view.hideProgress(); } @Override public void onNext(List<Shop> shops) { handleShops(shops); view.onSuccess

RxJava: InterruptedIOException

倾然丶 夕夏残阳落幕 提交于 2019-12-25 07:11:13
问题 I wrote some code to download a file from server meanwhile updating progress bar. Downloading code was running in Schedulers.io thread and updating ui code was running in AndroidSchedulers.mainThread . My program terminated after download began. Here is my code: Observable .create(new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<? super String> subscriber) { try { Response response = getResponse(url); if (response != null && response.isSuccessful()) { InputStream

RxJava + JavaFX Property

回眸只為那壹抹淺笑 提交于 2019-12-25 04:42:45
问题 I have a method called rxToProperty() that turns an Observable into a JavaFX Property . public static <T> ReadOnlyObjectProperty<T> rxToProperty(Observable<T> obs) { ReadOnlyObjectWrapper<T> property = new ReadOnlyObjectWrapper<>(); obs.onBackpressureLatest().serialize().subscribe(v -> { synchronized(property) { property.set(v); } }); return property.getReadOnlyProperty(); } How do I ensure that the returned Property is always up-to-date especially when it is bound to controls in JavaFX? I

Rx SearchView needs to cancel on going request with less priority

孤街浪徒 提交于 2019-12-25 04:14:17
问题 I am using RxSearchView.queryTextChangeEvents to detect the events of “Search As You Type” and also when you submit a search, SAYT is to get suggestions and when you do a submit, it executes a full search. There are 2 problems I am having at the moment. When you are typing, and getting suggestions, but suddenly you click submit then it executes the full search but the problem is that if there is an on going suggestion request there might be the case that they appear on screen when they should

RxJava group two responses one of which might be NULL with zip operator

北慕城南 提交于 2019-12-25 02:33:00
问题 I want to make two concurent request to Realm database and return results with RxJava. The issue is that one of requests can return NULL object and I have a crash. How can I properly return results from both DB even if one of them NULL? Thanks. public void getDataFromTwoSources(DisposableObserver<ComplexUserDto> observer, String shopId) { Preconditions.checkNotNull(observer); final Observable<ComplexUserDto> observable = Observable.zip(firstRepository.getUserData(userId), secondRepository

Sort collection of objects with Reactive Extensions in Java?

断了今生、忘了曾经 提交于 2019-12-25 02:06:34
问题 How can I can sort a collection of objects using rxjava based on one or more fields of the objects? public class Car { public String model; public int numberOfWheels; public String color; public int yearOfProduction; } List<Car> cars = new ArrayList<>(); cars.add(...); cars.add(...); Observable<List<Car>> getCars() { Observable.just(cars) }; Observable<List<Car>> getCarsSortedByModel() { ??? }; Observable<List<Car>> getCarsSortedByColor() { ??? }; Observable<List<Car>>

RxJava order of execution confusion

旧城冷巷雨未停 提交于 2019-12-25 00:24:00
问题 I have this very simple RxJava example List<Integer> arrayIntegers = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); Observable.fromIterable(arrayIntegers).map(i -> { Log.d("RxJava", "map i = " + i); return i; }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()). subscribe(new DisposableObserver<Integer>() { @Override public void onNext(Integer i) { Log.d("RxJava", "next i = " + i); } @Override public void onError(Throwable e) {} @Override public void onComplete() {

How to mock EntityBus.rxSend()

断了今生、忘了曾经 提交于 2019-12-25 00:05:52
问题 The io.vertx.reactivex.core.eventbus.EventBus.rxSend() method has the following signature: public <T> Single<Message<T>> rxSend(String address, Object message, DeliveryOptions options) What is the correct way to mock this so that it returns a Single containing a real object? The issue is that the Message class has no constructor apart from one which which takes another Message object. So the following will compile: Mockito.when(eventBus.rxSend(Mockito.isA(String.class), Mockito.isA(JsonObject