Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Created March 6, 2018 18:51
Show Gist options
  • Select an option

  • Save cdmunoz/89a2ddeaad748b1cd6de8a0d4d7386b8 to your computer and use it in GitHub Desktop.

Select an option

Save cdmunoz/89a2ddeaad748b1cd6de8a0d4d7386b8 to your computer and use it in GitHub Desktop.
class CryptocurrenciesActivity : AppCompatActivity() {
val compositeDisposable = CompositeDisposable()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
showCryptocurrencies()
}
private fun showCryptocurrencies() {
val cryptocurrenciesResponse = getCryptocurrencies()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
val disposableObserver =
cryptocurrenciesResponse.subscribeWith(object : DisposableObserver<List<Cryptocurrency>>() {
override fun onComplete() {
}
override fun onNext(cryptocurrencies: List<Cryptocurrency>) {
val listSize = cryptocurrencies.size
Log.e("ITEMS **** ", listSize.toString())
}
override fun onError(e: Throwable) {
Log.e("ERROR *** ", e.message)
}
})
compositeDisposable.addAll(disposableObserver)
}
private fun getCryptocurrencies(): Observable<List<Cryptocurrency>> {
val retrofit = ApiClient.getClient()
val apiInterface = retrofit.create(ApiInterface::class.java)
return apiInterface.getCryptocurrencies("0")
}
override fun onDestroy() {
compositeDisposable.dispose()
super.onDestroy()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment