nickbutcher / plaid

An Android app which provides design news & inspiration as well as being an example of implementing material design.
Apache License 2.0
16.25k stars 3.16k forks source link

The app doesn't stop making network requests when offline #668

Open manuelvicnt opened 5 years ago

manuelvicnt commented 5 years ago

You can check the logs how it doesn't stop making network requests:

D/OkHttp: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "dribbble.com": No address associated with hostname
D/OkHttp: --> GET https://www.designernews.co/api/v2/stories?page=171
    --> END GET
D/OkHttp: --> GET https://dribbble.com/search?q=Material%20Design&page=171&s=latest&per_page=12
    --> END GET
D/OkHttp: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "www.designernews.co": No address associated with hostname
D/OkHttp: --> GET https://api.producthunt.com/v1/posts?days_ago=170
    --> END GET
D/OkHttp: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "api.producthunt.com": No address associated with hostname
D/OkHttp: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "dribbble.com": No address associated with hostname
D/OkHttp: --> GET https://www.designernews.co/api/v2/stories?page=172
    --> END GET
D/OkHttp: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "www.designernews.co": No address associated with hostname
D/OkHttp: --> GET https://dribbble.com/search?q=Material%20Design&page=172&s=latest&per_page=12
    --> END GET
D/OkHttp: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "dribbble.com": No address associated with hostname
D/OkHttp: --> GET https://api.producthunt.com/v1/posts?days_ago=171
    --> END GET

... 
...
tolstovdmit commented 4 years ago

Hi, I was trying to solve this issue. But I'm not sure which way.

  1. We can make an Interceptor for OkHttpClient and cancel calls when there is no connection.

Pros:

Cons:

  1. We can use ConnectivityChecker only not unregister it for one time use. And then use it in InfiniteScrollListener and other places.

Pros:

Cons:

  1. Same as 2nd option but we will check connectionStatus.value in viewModel

Pros:

Cons:

  1. We can make standalone ConnectivityChecker that will be registered to the ConnectivityManager through the hole app lifecycle. Then it can produce a livedata, that will listen to it through onActive/onInactive methods to be observed by UI, and it can give a connectionStatus to the deeper layers so that DataManager, Repositories, DataSources or UseCases will use it to call or not to call it and return Result.Error for these cases.

Pros:

Cons:

akri16 commented 3 years ago

I would like to work on this. Does it still accept PRs?