Created
March 8, 2018 02:12
-
-
Save cdmunoz/ad95b75806732b49fc0f076da85c65b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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