Skip to content

Instantly share code, notes, and snippets.

@jeremyrempel
Created February 18, 2019 17:07
Show Gist options
  • Save jeremyrempel/e3f8c4ff05d9b39857abf313c22ad59f to your computer and use it in GitHub Desktop.
Save jeremyrempel/e3f8c4ff05d9b39857abf313c22ad59f to your computer and use it in GitHub Desktop.
interface PhotoActions {
fun onRequestData()
}
class PhotoPresenter(
uiContext: CoroutineContext,
val view: PhotoView
) : CoroutinePresenter(uiContext, view), PhotoActions {
val api: PhotoApi by kodein.instance("Api")
override fun onRequestData() = updateData()
private fun updateData() {
// update view, show loader
view.isUpdating = true
GlobalScope.launch(coroutineContext) {
// HTTP request, handle response. Errors will be handled via BaseView.showError(error: Throwable)
val response = api.getRandom()
view.onUpdate(response)
}.invokeOnCompletion {
// update view, hide loader
view.isUpdating = false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment