diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index de8fca45c..2cbbf2613 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,7 +5,12 @@ package="com.simplemobiletools.gallery.pro" android:installLocation="auto"> - + + + (SETTINGS_LIST) if (settings != null) { val brush = settings.getSettingsModel(BrushSettings::class.java) @@ -118,45 +113,67 @@ class NewEditActivity : SimpleActivity() { config.editorBrushSize = brush.brushSize } - if (resultCode != Activity.RESULT_OK || sourceImageUri == null || sourceImageUri.toString().isEmpty() || cacheImagePathFromEditor.isEmpty() || sourceImageUri.toString() == cacheImagePathFromEditor) { + if (resultCode != Activity.RESULT_OK || resultPath.isEmpty()) { toast(R.string.image_editing_cancelled) finish() } else { - // the image is stored at the internal app storage first, for example /data/user/0/com.simplemobiletools.gallery.pro/cache/editor/IMG_20191207_183023.jpg - // first we rename it to the desired name, then move - val sourceString = Uri.decode(sourceImageUri.toString())?.toString() ?: "" - val source = if (sourceString.isEmpty() || sourceString.startsWith("content")) { + val source = if (sourcePath.isEmpty() || sourcePath.startsWith("content")) { internalStoragePath } else { - sourceString.substringAfter("file://") - } - - if (source == cacheImagePathFromEditor) { - finish() - return + sourcePath.substringAfter("file://") } SaveAsDialog(this, source, true, cancelCallback = { toast(R.string.image_editing_failed) finish() }, callback = { - destinationFilePath = it + val destinationFilePath = it handleSAFDialog(destinationFilePath) { if (it) { - storeOldExif(source) - sourceFileLastModified = File(source).lastModified() - val newFile = File("${cacheImagePathFromEditor.getParentPath()}/${destinationFilePath.getFilenameFromPath()}") - File(cacheImagePathFromEditor).renameTo(newFile) - val sourceFile = FileDirItem(newFile.absolutePath, newFile.name) + ensureBackgroundThread { + storeOldExif(source) + sourceFileLastModified = File(source).lastModified() - val conflictResolutions = LinkedHashMap() - conflictResolutions[destinationFilePath] = CONFLICT_OVERWRITE + var inputStream: InputStream? = null + var outputStream: OutputStream? = null + try { + inputStream = contentResolver.openInputStream(Uri.parse(resultPath)) + outputStream = getFileOutputStreamSync(destinationFilePath, destinationFilePath.getMimeType()) + inputStream!!.copyTo(outputStream!!) + outputStream.flush() + inputStream.close() + outputStream.close() - val pair = Pair(arrayListOf(sourceFile), destinationFilePath.getParentPath()) - CopyMoveTask(this, false, true, conflictResolutions, editCopyMoveListener, true).execute(pair) + try { + if (isNougatPlus()) { + val newExif = ExifInterface(destinationFilePath) + oldExif?.copyTo(newExif, false) + } + } catch (ignored: Exception) { + } + + if (config.keepLastModified) { + // add 1 s to the last modified time to properly update the thumbnail + updateLastModified(destinationFilePath, sourceFileLastModified + 1000) + } + + val paths = arrayListOf(destinationFilePath) + rescanPaths(arrayListOf(destinationFilePath)) { + fixDateTaken(paths, false) + } + + setResult(Activity.RESULT_OK, intent) + toast(R.string.file_edited_successfully) + finish() + } catch (e: Exception) { + showErrorToast(e) + } finally { + inputStream?.close() + outputStream?.close() + } + } } else { toast(R.string.image_editing_failed) - File(cacheImagePathFromEditor).delete() finish() } } @@ -180,43 +197,8 @@ class NewEditActivity : SimpleActivity() { } } - private val editCopyMoveListener = object : CopyMoveListener { - override fun copySucceeded(copyOnly: Boolean, copiedAll: Boolean, destinationPath: String) { - try { - if (isNougatPlus()) { - val newExif = ExifInterface(destinationFilePath) - oldExif?.copyTo(newExif, false) - } - } catch (ignored: Exception) { - } - - if (config.keepLastModified) { - // add 1 s to the last modified time to properly update the thumbnail - updateLastModified(destinationFilePath, sourceFileLastModified + 1000) - } - - val paths = arrayListOf(destinationFilePath) - rescanPaths(paths) { - fixDateTaken(paths, false) - } - - setResult(Activity.RESULT_OK, intent) - toast(R.string.file_edited_successfully) - finish() - } - - override fun copyFailed() { - toast(R.string.unknown_error_occurred) - File(cacheImagePathFromEditor).delete() - finish() - } - } - private fun openEditor(inputImage: Uri) { - sourceImageUri = inputImage - val filename = inputImage.toString().getFilenameFromPath() - - val settingsList = createPesdkSettingsList(filename) + val settingsList = createPesdkSettingsList() settingsList.configure { it.source = inputImage @@ -225,11 +207,11 @@ class NewEditActivity : SimpleActivity() { settingsList[LoadSettings::class].source = inputImage PhotoEditorBuilder(this) - .setSettingsList(settingsList) - .startActivityForResult(this, PESDK_EDIT_IMAGE) + .setSettingsList(settingsList) + .startActivityForResult(this, PESDK_EDIT_IMAGE) } - private fun createPesdkSettingsList(filename: String): PhotoEditorSettingsList { + private fun createPesdkSettingsList(): PhotoEditorSettingsList { val settingsList = PhotoEditorSettingsList().apply { configure { it.setFilterList(FilterPackBasic.getFilterPack()) @@ -285,9 +267,9 @@ class NewEditActivity : SimpleActivity() { getSettingsModel(UiConfigTheme::class.java).theme = R.style.Imgly_Theme_NoFullscreen configure { - it.exportFormat = SaveSettings.FORMAT.AUTO - it.setOutputFilePath("$cacheDir/editor/$filename") - it.savePolicy = SaveSettings.SavePolicy.RETURN_SOURCE_OR_CREATE_OUTPUT_IF_NECESSARY + it.setExportFormat(ImageExportFormat.AUTO) + it.setOutputToTemp() + it.outputMode = OutputMode.EXPORT_IF_NECESSARY } } diff --git a/build.gradle b/build.gradle index 0d8b1ad7a..ee5323575 100644 --- a/build.gradle +++ b/build.gradle @@ -13,10 +13,10 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath 'com.android.tools.build:gradle:4.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" if (is_proprietary) { - classpath 'ly.img.android.pesdk:plugin:7.6.4' + classpath 'ly.img.android.pesdk:plugin:8.0.2' } // NOTE: Do not place your application dependencies here; they belong