pwittchen / ReactiveNetwork

Android library listening network connection state and Internet connectivity with RxJava Observables
http://pwittchen.github.io/ReactiveNetwork/docs/RxJava2.x/
Apache License 2.0
2.53k stars 276 forks source link

Better internet detection? #310

Open Kisty opened 5 years ago

Kisty commented 5 years ago

Just a thought, but could the internet connection check be a bit more intelligent and use the network check and then only check the internet if at least one is connected? Not sure if this would cause more problems than it solves but worth a thought.

pwittchen commented 5 years ago

You can do that now. It's described in documentation here: https://github.com/pwittchen/ReactiveNetwork#chaining-network-and-internet-connectivity-streams

Sometimes, switchMapSingle may be a better choice than flatMapSingle to discard first stream.

Kisty commented 5 years ago

Thanks for getting back to me so quick! That makes sense, though what if there's lots of connection events in a small space of time, e.g. DISCONNECTED -> CONNECTING -> CONNECTED then you'd fire off many internet checks. Couldn't you just filter CONNECTED and DISCONNECTED states? Also, putting such an API in the library might be a good idea? Although it may be subjective on when to react to network changes...

pwittchen commented 5 years ago

You can do that too right now. You can use RxJava operators like debounce(...), sample(...) or something like that. Have a look at docs: https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables.