From 57020626dbd96933ef47652563f0aa87195e4575 Mon Sep 17 00:00:00 2001 From: Agnieszka C <85929121+Aga-C@users.noreply.github.com> Date: Sat, 6 Nov 2021 10:41:14 +0100 Subject: [PATCH] Fixed missing permission for rotate on external memory (#2236) --- .../gallery/pro/adapters/MediaAdapter.kt | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index f052d1d7e..3aec5fc3e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -308,24 +308,36 @@ class MediaAdapter( } private fun rotateSelection(degrees: Int) { - activity.toast(R.string.saving) - ensureBackgroundThread { - val paths = getSelectedPaths().filter { it.isImageFast() } - var fileCnt = paths.size - rotatedImagePaths.clear() - paths.forEach { - rotatedImagePaths.add(it) - activity.saveRotatedImageToFile(it, it, degrees, true) { - fileCnt-- - if (fileCnt == 0) { - activity.runOnUiThread { - listener?.refreshItems() - finishActMode() + val paths = getSelectedPaths().filter { it.isImageFast() } + var fileCnt = paths.size + rotatedImagePaths.clear() + val handleRotate = { + activity.toast(R.string.saving) + ensureBackgroundThread { + paths.forEach { + rotatedImagePaths.add(it) + activity.saveRotatedImageToFile(it, it, degrees, true) { + fileCnt-- + if (fileCnt == 0) { + activity.runOnUiThread { + listener?.refreshItems() + finishActMode() + } } } } } } + + if (paths.any { activity.needsStupidWritePermissions(it) }) { + activity.handleSAFDialog(paths.first { activity.needsStupidWritePermissions(it) }) { + if (it) { + handleRotate() + } + } + } else { + handleRotate() + } } private fun moveFilesTo() {