Created
February 18, 2019 17:07
-
-
Save jeremyrempel/e3f8c4ff05d9b39857abf313c22ad59f 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
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