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 Utils @Inject constructor(private val context: Context) { | |
fun isConnectedToInternet(): Boolean { | |
val connectivity = context.getSystemService( | |
Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
if (connectivity != null) { | |
val info = connectivity.allNetworkInfo | |
if (info != null) | |
for (i in info.indices) | |
if (info[i].state == NetworkInfo.State.CONNECTED) { |
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, 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) |
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 Utils @Inject constructor(private val context: Context) { | |
fun isConnectedToInternet(): Boolean { | |
val connectivity = context.getSystemService( | |
Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
if (connectivity != null) { | |
val info = connectivity.allNetworkInfo | |
if (info != null) | |
for (i in info.indices) | |
if (info[i].state == NetworkInfo.State.CONNECTED) { |
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 Utils @Inject constructor(private val context: Context) { | |
fun isConnectedToInternet(): Boolean { | |
val connectivity = context.getSystemService( | |
Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
if (connectivity != null) { | |
val info = connectivity.allNetworkInfo | |
if (info != null) | |
for (i in info.indices) | |
if (info[i].state == NetworkInfo.State.CONNECTED) { |
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, 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) |
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, 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) |
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, 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) |
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
@Dao | |
interface CryptocurrenciesDao { | |
@Query("SELECT * FROM cryptocurrencies ORDER BY rank limit :limit offset :offset") | |
fun queryCryptocurrencies(limit:Int, offset:Int): Single<List<Cryptocurrency>> | |
// ... rest of the code | |
} |
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
@Entity( | |
tableName = "cryptocurrencies" | |
) | |
data class Cryptocurrency( | |
@Json(name = "id") | |
@PrimaryKey | |
val id: String, | |
@Json(name = "name") |
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
@Module | |
class AppModule(val app: Application) { | |
companion object { | |
val MIGRATION_1_2: Migration = object : Migration(1, 2){ | |
override fun migrate(database: SupportSQLiteDatabase) { | |
// Change the table name to the correct one | |
database.execSQL("ALTER TABLE cryptocurrency RENAME TO cryptocurrencies") | |
} | |
} |