In my app I always retrieve data from a room database, display it, and then update the data over the network (and then animate the change in data). I’m wondering what the best approach would be using clean architecture. Currently in the ViewModel a coroutine is launched and from inside the coroutine a Use Case is executed to retrieve the data from the db, then the livedata object (observed by the view) is updated. After this a second Use Case is launched to retrieve the data from the network, and then the livedata is updated again.
I would like to be able to simplify this so that the ViewModel doesn’t know about where the data is coming from (or the fact that it comes from db first then network), so that it simply executes one GetDataUseCase and inside the use case (or inside the repository if that is preferable) I will retrieve data from db first, push data back to the ViewModel, then retrieve data from network, and push the updated data to the ViewModel.
What would be the best approach to achieve this? I thought about adding LiveData objects inside the UseCase or Repository however in order to observe these objects I need to give them a lifecycle owner, and also since the whole process is kicked off inside a coroutine inside the ViewModel, I’m not sure how to do that. I’ve also read that the UseCase should be a pure Java/Kotlin file so that it stays testable.