I'm trying to show a popup if my client is disconnected (false) for more than 10 seconds. However, I'm also dismissing the popup when the connection is regained (true). I need the popup to be dismissed instantly if true.
I think what I need to do is debounce based on value (false) but i'm not sure.
mConnectionObservable
.distinctUntilChanged()
.debounce(10, TimeUnit.SECONDS)
.subscribe(online -> {
if (online) {
//Dismiss popup
} else {
//Show popup about internet connection
}
});
You can try
mConnectionObservable.debounce(item -> (item? Observable.empty() : Observable.timer(10,TimeUnit.SECONDS)))
.distinctUntilChanged()
This dynamically changes the debounce period so that a true value is always emitted but a false value with have the 10 second debounce.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With