Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Created March 21, 2018 00:51
Show Gist options
  • Save cdmunoz/c6078de8bdb768efeaab832ab5972858 to your computer and use it in GitHub Desktop.
Save cdmunoz/c6078de8bdb768efeaab832ab5972858 to your computer and use it in GitHub Desktop.
class CryptocurrencyRepository @Inject constructor(val apiInterface: ApiInterface,
val cryptocurrenciesDao: CryptocurrenciesDao, val utils: Utils) {
fun getCryptocurrencies(limit: Int, offset: Int): Observable<List<Cryptocurrency>> {
val hasConnection = utils.isConnectedToInternet()
var observableFromApi: Observable<List<Cryptocurrency>>? = null
if (hasConnection){
observableFromApi = getCryptocurrenciesFromApi()
}
val observableFromDb = getCryptocurrenciesFromDb(limit, offset)
return if (hasConnection) Observable.concatArrayEager(observableFromApi, observableFromDb)
else observableFromDb
}
//...rest of the code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment