diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeMultipleImagesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeMultipleImagesDialog.kt index e1b96f357..cd75fd057 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeMultipleImagesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeMultipleImagesDialog.kt @@ -10,15 +10,13 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.gallery.pro.R -import com.simplemobiletools.gallery.pro.extensions.config import com.simplemobiletools.gallery.pro.extensions.ensureWriteAccess -import com.simplemobiletools.gallery.pro.extensions.fixDateTaken +import com.simplemobiletools.gallery.pro.extensions.rescanPathsAndUpdateLastModified import com.simplemobiletools.gallery.pro.extensions.resizeImage import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_edit_text import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_info import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_input_layout import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_progress -import java.io.File import kotlin.math.roundToInt private const val DEFAULT_RESIZE_FACTOR = "75" @@ -113,17 +111,7 @@ class ResizeMultipleImagesDialog( toast(R.string.images_resized_successfully) } - rescanPaths(pathsToRescan) { - fixDateTaken(pathsToRescan, false) - for (path in pathsToRescan) { - val file = File(path) - val lastModified = file.lastModified() - if (config.keepLastModified && lastModified != 0L) { - File(file.absolutePath).setLastModified(lastModified) - updateLastModified(file.absolutePath, lastModified) - } - } - } + rescanPathsAndUpdateLastModified(pathsToRescan) activity.runOnUiThread { dialog?.dismiss() callback.invoke() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index a93311a08..09119dd97 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -747,6 +747,7 @@ fun BaseSimpleActivity.ensureWriteAccess(path: String, callback: () -> Unit) { callback.invoke() } } + needsStupidWritePermissions(path) -> { handleSAFDialog(path) { if (!it) { @@ -755,6 +756,7 @@ fun BaseSimpleActivity.ensureWriteAccess(path: String, callback: () -> Unit) { callback() } } + isAccessibleWithSAFSdk30(path) -> { handleSAFDialogSdk30(path) { if (!it) { @@ -763,6 +765,7 @@ fun BaseSimpleActivity.ensureWriteAccess(path: String, callback: () -> Unit) { callback() } } + else -> { callback() } @@ -797,16 +800,8 @@ fun BaseSimpleActivity.launchResizeImageDialog(path: String, callback: (() -> Un toast(R.string.file_saved) val file = File(path) - val lastModified = file.lastModified() val paths = arrayListOf(file.absolutePath) - rescanPaths(paths) { - fixDateTaken(paths, false) - if (config.keepLastModified && lastModified != 0L) { - File(file.absolutePath).setLastModified(lastModified) - updateLastModified(file.absolutePath, lastModified) - } - } - + rescanPathsAndUpdateLastModified(paths) runOnUiThread { callback?.invoke() } @@ -855,6 +850,20 @@ fun BaseSimpleActivity.resizeImage(path: String, size: Point, callback: (success } } +fun BaseSimpleActivity.rescanPathsAndUpdateLastModified(paths: ArrayList) { + rescanPaths(paths) { + fixDateTaken(paths, false) + for (path in paths) { + val file = File(path) + val lastModified = file.lastModified() + if (config.keepLastModified && lastModified != 0L) { + File(file.absolutePath).setLastModified(lastModified) + updateLastModified(file.absolutePath, lastModified) + } + } + } +} + fun saveFile(path: String, bitmap: Bitmap, out: FileOutputStream, degrees: Int) { val matrix = Matrix() matrix.postRotate(degrees.toFloat())