rx-android

Debouncing button clicks using Rx

岁酱吖の 提交于 2020-02-23 09:37:05
问题 I'm trying to make a simple "button debouncer" which will count filtered clicks and display it thru a TextView. I want to filter rapid/spam clicks in a way that clicks with less than 300ms time-gap in-between are ignored. I did my research and stumbled upon Rx 's awesome debounce() which in theory should do the exact thing I wanted.. ..or so I thought. As the app seemed to only register the first click; the counter won't increment no matter how long I tried to wait. Here's a piece of my code:

How to concatenate two observable operations in a linear fashion (do first this thing and after that one finishes do the second thing)?

╄→гoц情女王★ 提交于 2020-02-03 08:27:08
问题 Polidea has released a new handy library called RxAndroidBle which is very useful for dealing with a lot of issues when you're using vanilla Bluetooth APIs. Before explaining more the idea is to have a POJO model that has all the recent values that the device send (or I query) to me (in this case is represented by a Map object): If I want to be notified about multiple characteristic notifications I can do this: final UUID serviceUuid = // your service UUID final Map<UUID, byte[]> genericModel

RxJava: prevent an observable from emitting until data from another observable is emitted

独自空忆成欢 提交于 2020-01-24 21:55:07
问题 The block of code below is designed to be offline-first. If data is emitted by the memory observable the local and remote observable will never fire. If data is not held in memory the local observable will attempt to read data from room database and if all else fails then the remote observable queries an API. The remote source uses retrofit to send queries and returns a flowable which is then converted into an observable. Before the remote observable fires, however, I have another observable

Observable Timer for screen timeout android

爷,独闯天下 提交于 2020-01-24 20:08:48
问题 I'm working on a use-case where I have to implement a sort of screen timeout after the completion of which application navigates to the main screen. I want it to implemente it using Observable and use Observable.timer() or Observable.interval() for the timing. (Either is suitable for my use-case.). Every time the user interacts with the activity I have to reset or refresh my timer Observable . This is where I am stuck. I don't know how to refresh or reset an Observable . A simple way would be

In RxJava, how to retry/resume on error, instead of completing the observable

蓝咒 提交于 2020-01-23 06:30:06
问题 What I want to achieve is: monitor preferences for a certain change when a change is detected, start new network call using the new value transform result display result in UI I know when the change happens, now I presume I need to call onNext on a Subject. This should then trigger a Rx chain, and in the end I can update the UI. mViewPeriodSubject = PublishSubject.create(); mAdapterObservable = mViewPeriodSubject .flatMap(period -> MyRetrofitAPI.getService().fetchData(period)) // this might

Does take(1) stop the upstream flowable doing work?

梦想与她 提交于 2020-01-16 09:41:10
问题 Let's assume we have some Flowable that looks like: val exampleFlowable = Flowable.create<Int>({ emitter -> while (true) { Thread.sleep(TimeUnit.SECONDS.toMillis(1)) emitter.onNext(1) } }, BackpressureStrategy.LATEST) .subscribeOn(Schedulers.io()) And then I call take(1) on it and subscribe to it like so (notice, disposing of the disposable in the subscribe block): var disposable: Disposable? = null disposable = exampleFlowable.take(1) .observeOn(AndroidSchedulers.mainThread()) .subscribe({

Does take(1) stop the upstream flowable doing work?

主宰稳场 提交于 2020-01-16 09:41:10
问题 Let's assume we have some Flowable that looks like: val exampleFlowable = Flowable.create<Int>({ emitter -> while (true) { Thread.sleep(TimeUnit.SECONDS.toMillis(1)) emitter.onNext(1) } }, BackpressureStrategy.LATEST) .subscribeOn(Schedulers.io()) And then I call take(1) on it and subscribe to it like so (notice, disposing of the disposable in the subscribe block): var disposable: Disposable? = null disposable = exampleFlowable.take(1) .observeOn(AndroidSchedulers.mainThread()) .subscribe({

RxAndroid `Observable…subscribe` highlighted in Android Studio

社会主义新天地 提交于 2020-01-16 06:07:10
问题 I'm using RxAndroid to marshal a string from a background thread into the main thread, and do something with that string on that main thread: String stringFromDatabase = readFromDatabase(); Observable.just(stringFromDatabase) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<String>() { @Override public void accept(String string) throws Exception { webViewFragment.onInjectMessage(string, null); } }); Android Studio is highlighting the entire Observable.just... command chain

RxAndroid `Observable…subscribe` highlighted in Android Studio

与世无争的帅哥 提交于 2020-01-16 06:06:10
问题 I'm using RxAndroid to marshal a string from a background thread into the main thread, and do something with that string on that main thread: String stringFromDatabase = readFromDatabase(); Observable.just(stringFromDatabase) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<String>() { @Override public void accept(String string) throws Exception { webViewFragment.onInjectMessage(string, null); } }); Android Studio is highlighting the entire Observable.just... command chain

How to use the state of one observable to skip values of another observable?

不羁的心 提交于 2020-01-15 02:29:31
问题 This is best explained with a short example. let's say this is my source observable that I want to filter Observable.interval(1, TimeUnit.SECONDS) I use a checkbox to handle the filter state. When the box is not checked, I want to skip all values. I use RxAndroid to get an observable for the checkbox like this: RxCompoundButton.checkedChanges(checkBox) here is my code: Observable.combineLatest( RxCompoundButton.checkedChanges(checkBox) , Observable.interval(1, TimeUnit.SECONDS) , (isChecked,