From aebfa078e1a7f00f85b280aa02fb2ef0d48c63e6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 8 Oct 2016 22:42:11 +0200 Subject: [PATCH] check for unknown file path at editing remote images --- .../gallery/activities/EditActivity.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 8c88743e7..970daee02 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -69,13 +69,19 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener if (uri.scheme == "file") { saveBitmapToFile(result.bitmap, uri.path) } else if (uri.scheme == "content") { - saveBitmapToFile(result.bitmap, convertMediaUriToPath(uri)) + val newPath = convertMediaUriToPath(uri) ?: "" + if (!newPath.isEmpty()) { + saveBitmapToFile(result.bitmap, newPath) + } else { + toast(R.string.image_editing_failed) + finish() + } } else { toast(R.string.unknown_file_location) finish() } } else { - toast("${getString(R.string.image_editing_failed)} ${result.error.message}") + toast("${getString(R.string.image_editing_failed)}: ${result.error.message}") } } @@ -118,7 +124,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } } - private fun convertMediaUriToPath(uri: Uri): String { + private fun convertMediaUriToPath(uri: Uri): String? { val proj = arrayOf(MediaStore.Images.Media.DATA) val cursor = contentResolver.query(uri, proj, null, null, null) val index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)