rizmaulana / kotlin-mvvm-covid19

This repository contains simple COVID19 data monitoring with android stack MVVM, Live Data, Koin, RxJava, RxBinding, Offline first with simple caching, etc
Apache License 2.0
435 stars 111 forks source link

Pull to Refresh and State Handling #27

Closed pandubaraja closed 4 years ago

pandubaraja commented 4 years ago

This PR improves Repository

Multiple API call error handling is a little bit tricky because when one of API call failed the other got cancelled because RxJava ended the stream if the Observable enter onError function.

e.g. when daily endpoint failed but overview endpoint succeed we should show Overview result and do nothing with daily updates. User can reload if he/she wishes to see daily updates.

In order to keep the RxJava stream alive we need to wrap Response with Result class and use onErrorResumeNext function to handle the API throwable.

ref: https://rongi.github.io/kotlin-blog/rxjava/rx/2017/08/01/error-handling-in-rxjava.html

Other improvements :

Preview Loading State:

loading-resize

Preview Connection Error State:

error-state-resize

Preview Connection Error State (Only occurs when does not have cached data):

reload

pandubaraja commented 4 years ago

Thank you 🎉

rizmaulana commented 4 years ago

You're welcome mas Pandu, thanks for your contribution 🎉