rx-java

How to filter duplicate values emitted by observable in RXJava?

ぃ、小莉子 提交于 2020-01-31 22:09:11
问题 I have a collection of objects, where i want to suppress duplicate items. I know about Distinct operator, but if i am not mistaken it compare items by properly overrided hashcode method. But what if my hashcode returns different values for same objects, and i want to set equality by my own. distinct have 2 overloaded methods - one without params and one with Func1 param,i suppose that i should use 2nd method, but how exaclty? .distinct(new Func1<ActivityManager.RunningServiceInfo, Object>() {

How to filter duplicate values emitted by observable in RXJava?

拟墨画扇 提交于 2020-01-31 22:05:43
问题 I have a collection of objects, where i want to suppress duplicate items. I know about Distinct operator, but if i am not mistaken it compare items by properly overrided hashcode method. But what if my hashcode returns different values for same objects, and i want to set equality by my own. distinct have 2 overloaded methods - one without params and one with Func1 param,i suppose that i should use 2nd method, but how exaclty? .distinct(new Func1<ActivityManager.RunningServiceInfo, Object>() {

RxJava Observable.fromEmitter odd backpressure behaviour

血红的双手。 提交于 2020-01-31 17:29:53
问题 I've been making use of Observable.fromEmitter() as a fantastic alternative to Observable.create() . I've recently run into some weird behaviour and I can't quite work out why this is the case. I'd really appreciate someone with some knowledge on backpressure and schedulers taking a look at this. public final class EmitterTest { public static void main(String[] args) { Observable<Integer> obs = Observable.fromEmitter(emitter -> { for (int i = 1; i < 1000; i++) { if (i % 5 == 0) { sleep(300L);

Do I have to unsubscribe from completed observable?

女生的网名这么多〃 提交于 2020-01-30 14:30:11
问题 If an observable completes, do I still have to unsubscribe / dispose (in RxJava2) the observable to remove the Observer (prevent memory leaks) or is this handled internally by RxJava once a onComplete or onError event occurs? what about other types like Single , Completable , Flowable etc. 回答1: Yes you are correct. After a stream is terminated ( onComplete / onError has been called ), subscriber unsubscribes automatically. You should be able to test these behaviors using isUnsubscribed()

Writing multiple commands to characteristic

拟墨画扇 提交于 2020-01-25 09:02:04
问题 I am just discovering rxandroidble and can reliably send a single command to the BLE device after connection However I am struggling to find the best way to write a chain of commands, ie if I have a series of 3 commands that need to be sent Of course this can be done by nesting the sends, but Im sure there is a better approach!! Single command send code is rxBleMainConection.writeCharacteristic(COMS_WRITE_CHAR_UUID,bytes).toObservable() .subscribe( characteristicValue -> { // Written

How to convert from Observable<List<X>> to Observable<List<Y>>, using a function that takes X as parameter & returns Observable<Y>

此生再无相见时 提交于 2020-01-25 07:23:23
问题 I have a method that emits a list of user ids, indefinitely (not finite). Observable<List<String>> getFriendUserIds() And another method that returns Account data for a specific user id. Observable<Account> getAccount(String userId) I need to get the Account data for all the user ids returned by the getFriendUserIds() method, grouped together in a list corresponding to the user id list. Basically, I need the following, preferably in a non-blocking way. Observable<List<String>> // infinite

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

RetryWhen is giving some issues when using with Single

孤街醉人 提交于 2020-01-24 20:41:06
问题 I am trying to hit an API call using retrofit and receive the response from the call. I am using the Single of Rxjava to get the response. What I need to do is that a retry if the call fails. I have gone through lots of examples but it seems none could have been a help (Also because of my limited knowledge on RXjava and Kotlin). Below is the function which does the call and the retryWhen function I wrote override fun fetchMessage(southDataModel: SouthDataModel): Single<ArrayList

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

RxJava - Mapping a result of list to another list

妖精的绣舞 提交于 2020-01-24 19:25:07
问题 I want to convert every object in my list to an another object. But in doing so my code stucks in converting them back to List override fun myFunction(): LiveData<MutableList<MyModel>> { return mySdk .getAllElements() // Returns Flowable<List<CustomObject>> .flatMap { Flowable.fromIterable(it) } .map {MyModel(it.name!!, it.phoneNumber!!) } .toList() //Debugger does not enter here .toFlowable() .onErrorReturn { Collections.emptyList() } .subscribeOn(Schedulers.io()) .to {