Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Created March 8, 2018 02:12
Show Gist options
  • Save cdmunoz/ad95b75806732b49fc0f076da85c65b5 to your computer and use it in GitHub Desktop.
Save cdmunoz/ad95b75806732b49fc0f076da85c65b5 to your computer and use it in GitHub Desktop.
class CryptocurrencyRepository @Inject constructor(val apiInterface: ApiInterface,
val cryptocurrenciesDao: CryptocurrenciesDao) {
fun getCryptocurrencies(): Observable<List<Cryptocurrency>> {
val observableFromApi = getCryptocurrenciesFromApi()
val observableFromDb = getCryptocurrenciesFromDb()
return Observable.concatArrayEager(observableFromApi, observableFromDb)
}
fun getCryptocurrenciesFromApi(): Observable<List<Cryptocurrency>> {
return apiInterface.getCryptocurrencies("0")
.doOnNext {
Log.e("REPOSITORY API * ", it.size.toString())
for (item in it) {
cryptocurrenciesDao.insertCryptocurrency(item)
}
}
}
fun getCryptocurrenciesFromDb(): Observable<List<Cryptocurrency>> {
return cryptocurrenciesDao.queryCryptocurrencies()
.toObservable()
.doOnNext {
//Print log it.size :)
Log.e("REPOSITORY DB *** ", it.size.toString())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment