From 2131cb79d3d0061f1c1d4b5243997a23ab728c68 Mon Sep 17 00:00:00 2001 From: Naveen Date: Wed, 1 Feb 2023 03:14:29 +0530 Subject: [PATCH] Always request write permission when updating existing file on 30+ A casual file output stream was needed to fix the file size update issue --- .../gallery/pro/activities/EditActivity.kt | 15 ++++++++++----- .../gallery/pro/dialogs/SaveAsDialog.kt | 5 +---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt index 07fb8fd0e..d1e1986c4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt @@ -873,11 +873,16 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener ensureBackgroundThread { val file = File(path) val fileDirItem = FileDirItem(path, path.getFilenameFromPath()) - getFileOutputStream(fileDirItem, true) { - if (it != null) { - saveBitmap(file, bitmap, it, showSavingToast) - } else { - toast(R.string.image_editing_failed) + try { + val out = FileOutputStream(file) + saveBitmap(file, bitmap, out, showSavingToast) + } catch (e: Exception) { + getFileOutputStream(fileDirItem, true) { + if (it != null) { + saveBitmap(file, bitmap, it, showSavingToast) + } else { + toast(R.string.image_editing_failed) + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt index 74617af07..77881b179 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/SaveAsDialog.kt @@ -78,10 +78,7 @@ class SaveAsDialog( if (activity.getDoesFilePathExist(newPath)) { val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename) ConfirmationDialog(activity, title) { - val newFile = File(newPath) - val isInDownloadDir = activity.isInDownloadDir(newPath) - val isInSubFolderInDownloadDir = activity.isInSubFolderInDownloadDir(newPath) - if ((isRPlus() && !isExternalStorageManager()) && isInDownloadDir && !isInSubFolderInDownloadDir && !newFile.canWrite()) { + if ((isRPlus() && !isExternalStorageManager())) { val fileDirItem = arrayListOf(File(newPath).toFileDirItem(activity)) val fileUris = activity.getFileUrisFromFileDirItems(fileDirItem) activity.updateSDK30Uris(fileUris) { success ->