Created
March 21, 2018 00:51
-
-
Save cdmunoz/c6078de8bdb768efeaab832ab5972858 to your computer and use it in GitHub Desktop.
This file contains 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, 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