From 70dced795cb3dfb4d130e6ad1f401a415627727e Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Mon, 13 Mar 2023 10:17:41 +0100 Subject: [PATCH] Don't display error message if user cancels picking an image (#3427) * Don't display error message if user cancels picking an image * Update app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt --- .../tusky/EditProfileActivity.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt b/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt index 33d7a281a..715c45fb0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt @@ -34,6 +34,7 @@ import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.resource.bitmap.FitCenter import com.bumptech.glide.load.resource.bitmap.RoundedCorners +import com.canhub.cropper.CropImage import com.canhub.cropper.CropImageContract import com.canhub.cropper.options import com.google.android.material.snackbar.Snackbar @@ -80,14 +81,18 @@ class EditProfileActivity : BaseActivity(), Injectable { } private val cropImage = registerForActivityResult(CropImageContract()) { result -> - if (result.isSuccessful) { - if (result.uriContent == viewModel.getAvatarUri()) { - viewModel.newAvatarPicked() - } else { - viewModel.newHeaderPicked() - } + if (result is CropImage.CancelledResult) { + return@registerForActivityResult + } + + if (!result.isSuccessful) { + return@registerForActivityResult onPickFailure(result.error) + } + + if (result.uriContent == viewModel.getAvatarUri()) { + viewModel.newAvatarPicked() } else { - onPickFailure(result.error) + viewModel.newHeaderPicked() } }