From 19c79b51dbb64852962ed0ad2adad0e2d2eacd6c Mon Sep 17 00:00:00 2001 From: Manuel Lorenzo Date: Thu, 15 Jun 2023 19:59:33 +0200 Subject: [PATCH] Fix image upload cancel crash (#671) * Fix image upload cancel crash * :lipstick: revert formatting changes --- .../ui/components/common/PictrsImage.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/jerboa/ui/components/common/PictrsImage.kt b/app/src/main/java/com/jerboa/ui/components/common/PictrsImage.kt index f2eb79b18..9a81cd40a 100644 --- a/app/src/main/java/com/jerboa/ui/components/common/PictrsImage.kt +++ b/app/src/main/java/com/jerboa/ui/components/common/PictrsImage.kt @@ -1,4 +1,5 @@ package com.jerboa.ui.components.common + import android.graphics.Bitmap import android.net.Uri import android.util.Log @@ -188,11 +189,13 @@ fun PickImage( val launcher = rememberLauncherForActivityResult( ActivityResultContracts.GetContent(), ) { uri -> - imageUri = uri - bitmap.value = decodeUriToBitmap(ctx, imageUri!!) - Log.d("jerboa", "Uploading image...") - Log.d("jerboa", imageUri.toString()) - onPickedImage(uri!!) + uri?.let { + imageUri = it + bitmap.value = decodeUriToBitmap(ctx, it) + Log.d("jerboa", "Uploading image...") + Log.d("jerboa", imageUri.toString()) + onPickedImage(it) + } } Column( modifier = modifier, @@ -209,14 +212,11 @@ fun PickImage( if (showImage) { Spacer(modifier = Modifier.height(SMALL_PADDING)) - - imageUri?.let { - bitmap.value?.let { btm -> - Image( - bitmap = btm.asImageBitmap(), - contentDescription = stringResource(R.string.pickImage_imagePreview), - ) - } + bitmap.value?.let { btm -> + Image( + bitmap = btm.asImageBitmap(), + contentDescription = stringResource(R.string.pickImage_imagePreview), + ) } } }