Created
March 6, 2018 18:51
-
-
Save cdmunoz/89a2ddeaad748b1cd6de8a0d4d7386b8 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 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