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 1/2] 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() { From 1f47af7826d90bfb035d2e2d331cd775582a331d Mon Sep 17 00:00:00 2001 From: Agnieszka C <85929121+Aga-C@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:55:10 +0100 Subject: [PATCH 2/2] Moved handleRotate to the separate method --- .../gallery/pro/adapters/MediaAdapter.kt | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 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 3aec5fc3e..bc01fc36f 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 @@ -307,36 +307,37 @@ class MediaAdapter( } } - private fun rotateSelection(degrees: Int) { - val paths = getSelectedPaths().filter { it.isImageFast() } + private fun handleRotate(paths: List, degrees: Int) { 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() - } + 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() } } } } } + } + + private fun rotateSelection(degrees: Int) { + val paths = getSelectedPaths().filter { it.isImageFast() } if (paths.any { activity.needsStupidWritePermissions(it) }) { activity.handleSAFDialog(paths.first { activity.needsStupidWritePermissions(it) }) { if (it) { - handleRotate() + handleRotate(paths, degrees) } } } else { - handleRotate() + handleRotate(paths, degrees) } }