I use RxJava's throttleFirst for one second to avoid rapid button clicks, however I also want that on a button click a second button be also disabled for a second and vice versa, So, in short I do not allow rapid clicks on those two buttons one after another... What would you recommend? Can I achieve this using RxBinding?
RxView.clicks(button)
.throttleFirst(1000, TimeUnit.MILLISECONDS)
.subscribe {
doSomething()
}
here's one possible approach...
map
the output of each stream to some known value that will be handled in the subscribermerge
the two streams together and throttleFirst
that merged streamthat would all look something like this:
RxView.clicks(button1).map { "button1" }
.mergeWith(RxView.clicks(button2).map { "button2" })
.throttleFirst(1, TimeUnit.SECONDS)
.subscribeBy(
onNext = { value ->
if(value == "button1") {
// handle button1 click
} else {
// handle button2 click
}
},
onError = {
...
}
)
maybe not the most elegant, but hopefully it at least inspires some thought!