Paul Woitaschek
05/09/2019, 7:32 AMval imageSource = suspendCoroutine<ImageSource> { cont ->
MaterialDialog(context).show {
listItems(
items = ImageSource.values().map { getString(it.nameRes) },
selection = { _, i, _ ->
val imageSource = ImageSource.values()[i]
cont.resume(imageSource)
}
)
}
}
val uri = when (imageSource) {
ImageSource.GALLERY -> {
module<SelectPictureFromGalleryModule>().take()
}
ImageSource.TAKE_PICTURE -> null
}
into this:
val uri = when (suspendCoroutine<ImageSource> { cont ->
MaterialDialog(context).show {
listItems(
items = ImageSource.values().map { getString(it.nameRes) },
selection = { _, i, _ ->
val imageSource = ImageSource.values()[i]
cont.resume(imageSource)
}
)
}
}) {
ImageSource.GALLERY -> {
module<SelectPictureFromGalleryModule>().take()
}
ImageSource.TAKE_PICTURE -> null
}
spand
05/09/2019, 7:42 AMkarelpeeters
05/09/2019, 7:52 AMPaulius Ruminas
05/09/2019, 8:22 AMimageSource
outside of when
scope but do not use it anywhere else that is why it reports it. But at least for me 1st snippet is easier to read.Pavlo Liapota
05/09/2019, 8:25 AMPaul Woitaschek
05/09/2019, 8:44 AMlouiscad
05/09/2019, 8:55 AMsuspendCancellableCoroutine
and handle cancellation and dismissal properly?Paul Woitaschek
05/09/2019, 8:56 AMthanksforallthefish
05/09/2019, 10:48 AMlouiscad
05/09/2019, 10:51 AMkarelpeeters
05/09/2019, 1:23 PM