Closed digounet closed 7 years ago
Thanks for your nice idea. Surely, we can improve that. If you want to try it again and make PR, I highly appreciate that. I saw you are using Kotlin.
Hi @digounet ,
Please check my new commit.
Besides, the above logic of handling data should be decided by Presenter
instead of Repository
.
It keeps Repository
behavior consistent and decoupling with other components => easy to maintain and extend.
If you prefer to change it inside Repository
with RxJava, you should try the following.
override fun loadAll(forceRemote: Boolean): Flowable<List<Question>> {
if (forceRemote){
///....
} else {
return localDataSource.loadAll(false)
.flatMap{ if (it.isEmpty()) remoteDataSource.loadAll(true) else Flowable.fromArray(it) }
}
}
The QuestionsActivity is calling loadQuestions(false) method.
This method is loading data from local storage but there's no data.
I think, it would be: if ther's no data on local storage, then load from remote.
I've tryied to change it to something like:
But no success...