-
-
Save rozkminiacz/3d8538b941395e4cfcf2ae1105b02956 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
package tech.michalik.mvptesting | |
import io.reactivex.rxkotlin.subscribeBy | |
class MainScreenPresenter( | |
private val fetchCurrencyUseCase: FetchCurrencyUseCase, | |
private val schedulerProvider: SchedulerProvider | |
) : MainScreenContract.Presenter { | |
private var view: MainScreenContract.View? = null | |
override fun attach(view: MainScreenContract.View) { | |
this.view = view | |
fetchData() | |
} | |
private fun fetchData() { | |
fetchCurrencyUseCase.execute() | |
.subscribeOn(schedulerProvider.io) | |
.observeOn(schedulerProvider.main) | |
.doOnSubscribe { view?.toggleLoadingIndicator(loading = true) } | |
.doFinally { view?.toggleLoadingIndicator(loading = false) } | |
.subscribeBy( | |
onError = { | |
view?.displayError(it) | |
}, | |
onSuccess = { | |
view?.displayData(it) | |
} | |
) | |
} | |
override fun detach() { | |
this.view = null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment