From b1b9d111483ff911822ffa52e9caa941dd5a819d Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 2 Jan 2020 19:25:13 +0100 Subject: [PATCH] do not rely on SOURCE_IMAGE_PATH from the editor, store the original path --- .../gallery/pro/activities/NewEditActivity.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/NewEditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/NewEditActivity.kt index 4a9adb5ee..4f5174640 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/NewEditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/NewEditActivity.kt @@ -37,11 +37,11 @@ import kotlin.collections.set class NewEditActivity : SimpleActivity() { private val PESDK_EDIT_IMAGE = 1 private val SETTINGS_LIST = "SETTINGS_LIST" - private val SOURCE_IMAGE_PATH = "SOURCE_IMAGE_PATH" private val RESULT_IMAGE_PATH = "RESULT_IMAGE_PATH" private var sourceFileLastModified = 0L private var destinationFilePath = "" private var imagePathFromEditor = "" // delete the file stored at the internal app storage (the editor saves it there) in case moving to the selected location fails + private var sourceImageUri: Uri? = null private lateinit var uri: Uri private lateinit var saveUri: Uri @@ -102,7 +102,6 @@ class NewEditActivity : SimpleActivity() { override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { if (requestCode == PESDK_EDIT_IMAGE) { val extras = resultData?.extras - val source = extras?.getString(SOURCE_IMAGE_PATH, "") ?: "" imagePathFromEditor = extras?.getString(RESULT_IMAGE_PATH, "") ?: "" val settings = extras?.getParcelable(SETTINGS_LIST) @@ -113,12 +112,19 @@ class NewEditActivity : SimpleActivity() { config.editorBrushSize = brush.brushSize } - if (resultCode != Activity.RESULT_OK || source.isEmpty() || imagePathFromEditor.isEmpty() || source == imagePathFromEditor) { + if (resultCode != Activity.RESULT_OK || sourceImageUri == null || sourceImageUri.toString().isEmpty() || imagePathFromEditor.isEmpty() || sourceImageUri.toString() == imagePathFromEditor) { toast(R.string.image_editing_failed) finish() } else { // the image is stored at the internal app storage first, for example /data/user/0/com.simplemobiletools.gallery.pro/files/editor/IMG_20191207_183023.jpg // first we rename it to the desired name, then move + val sourceString = sourceImageUri?.toString() ?: "" + val source = if (sourceString.isEmpty() || sourceString.startsWith("content")) { + internalStoragePath + } else { + sourceString.substringAfter("file://") + } + SaveAsDialog(this, source, true, cancelCallback = { toast(R.string.image_editing_failed) finish() @@ -173,10 +179,11 @@ class NewEditActivity : SimpleActivity() { } private fun openEditor(inputImage: Uri) { + sourceImageUri = inputImage val filename = inputImage.toString().getFilenameFromPath() val settingsList = createPesdkSettingsList(filename) - settingsList.getSettingsModel(EditorLoadSettings::class.java).imageSource = inputImage + settingsList.getSettingsModel(EditorLoadSettings::class.java).imageSource = sourceImageUri PhotoEditorBuilder(this) .setSettingsList(settingsList)