do not rely on SOURCE_IMAGE_PATH from the editor, store the original path
This commit is contained in:
parent
6234050c7f
commit
b1b9d11148
|
@ -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<SettingsList>(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)
|
||||
|
|
Loading…
Reference in New Issue