bufferapp/android-clean-architecture-boilerplate

How can I fetch the data from cache when fetching data from remote failed?

arohim opened this issue · 1 comments

Hi, I'm new on Clean architecture and we are planning to convert our project(MVP) to Clean architecture and I'm making POC project from our code base and see how it goes for my team.

as the sample code, the data fetch from the cache only the cache not expired or cached in our case is fetch the data from cached when fetching the data from network failed whatever case.

Any ideas?

There are some empty methods which you can use for your purpose:

override fun showErrorState() {
   }

   override fun hideErrorState() {
   }

   override fun showEmptyState() {
   }

   override fun hideEmptyState() {
   }

Show an error message with Retry button when showErrorState is called, the method retry/refresh() would be available in presenter/viewModel - it will retry the whole network request from the beginning.

You can also use SwipeToRefreshLayout instead of ProgressBar, so for empty/error you would show only message and user will swipe to get new data