From 00dd9df07e68440331619b7d03e8228f76a26e4f Mon Sep 17 00:00:00 2001 From: Serchinastico <54cymru@gmail.com> Date: Wed, 30 Jan 2019 17:05:07 +0100 Subject: [PATCH] Use blocks to define the onSaveSuperHero function so that later on data binding we don't have to change the function that much --- .../ui/presenter/EditSuperHeroPresenter.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/karumi/jetpack/superheroes/ui/presenter/EditSuperHeroPresenter.kt b/app/src/main/java/com/karumi/jetpack/superheroes/ui/presenter/EditSuperHeroPresenter.kt index dd78da1..d81d5d2 100644 --- a/app/src/main/java/com/karumi/jetpack/superheroes/ui/presenter/EditSuperHeroPresenter.kt +++ b/app/src/main/java/com/karumi/jetpack/superheroes/ui/presenter/EditSuperHeroPresenter.kt @@ -41,19 +41,21 @@ class EditSuperHeroPresenter( name: String, description: String, isAvenger: Boolean - ) = launch { - view?.showLoading() - val superHero = this@EditSuperHeroPresenter.superHero ?: return@launch - async { - saveSuperHero( - superHero.copy( - name = name, - description = description, - isAvenger = isAvenger + ) { + launch { + view?.showLoading() + val superHero = superHero ?: return@launch + async { + saveSuperHero( + superHero.copy( + name = name, + description = description, + isAvenger = isAvenger + ) ) - ) + } + view?.close() } - view?.close() } private fun refreshSuperHero() = launch {