diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt index 7616702b1..f6ec30b0d 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt @@ -236,10 +236,10 @@ abstract class BaseSimpleActivity : AppCompatActivity() { val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION applicationContext.contentResolver.takePersistableUriPermission(treeUri, takeFlags) - funAfterSAFPermission?.invoke(true) - funAfterSAFPermission = null + funAfterDelete30File?.invoke(true) + funAfterDelete30File = null } else { - funAfterSAFPermission?.invoke(false) + funAfterDelete30File?.invoke(false) } } else if (requestCode == OPEN_DOCUMENT_TREE_FOR_ANDROID_DATA_OR_OBB) { @@ -429,7 +429,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() { callback(true) false } else if (isShowingSAFDialogForDeleteSdk30(path)) { - funAfterSAFPermission = callback + funAfterDelete30File = callback true } else { callback(true) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt index d3d568526..10fb7e107 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt @@ -153,7 +153,7 @@ fun BaseSimpleActivity.isShowingSAFDialog(path: String): Boolean { @SuppressLint("InlinedApi") fun BaseSimpleActivity.isShowingSAFDialogForDeleteSdk30(path: String): Boolean { - return if (!hasProperStoredFirstParentUri(path)) { + return if (isAccessibleWithSAFSdk30(path) && !hasProperStoredFirstParentUri(path)) { runOnUiThread { if (!isDestroyed && !isFinishing) { WritePermissionDialog(this, false) { @@ -643,31 +643,38 @@ fun BaseSimpleActivity.deleteFilesBg(files: List, allowDeleteFolder } var wasSuccess = false - handleSAFDialog(files[0].path) { + val firstFile = files.first() + handleSAFDialog(firstFile.path) { if (!it) { return@handleSAFDialog } - val failedFileDirItems = ArrayList() - files.forEachIndexed { index, file -> - deleteFileBg(file, allowDeleteFolder, true) { - if (it) { - wasSuccess = true - } else { - failedFileDirItems.add(file) - } + handleSAFDeleteSdk30Dialog(firstFile.path) { + if (!it) { + return@handleSAFDeleteSdk30Dialog + } - if (index == files.lastIndex) { - if (isRPlus() && failedFileDirItems.isNotEmpty()) { - val fileUris = getFileUrisFromFileDirItems(failedFileDirItems).second - deleteSDK30Uris(fileUris) { success -> - runOnUiThread { - callback?.invoke(success) - } - } + val failedFileDirItems = ArrayList() + files.forEachIndexed { index, file -> + deleteFileBg(file, allowDeleteFolder, true) { + if (it) { + wasSuccess = true } else { - runOnUiThread { - callback?.invoke(wasSuccess) + failedFileDirItems.add(file) + } + + if (index == files.lastIndex) { + if (isRPlus() && failedFileDirItems.isNotEmpty()) { + val fileUris = getFileUrisFromFileDirItems(failedFileDirItems).second + deleteSDK30Uris(fileUris) { success -> + runOnUiThread { + callback?.invoke(success) + } + } + } else { + runOnUiThread { + callback?.invoke(wasSuccess) + } } } } @@ -786,7 +793,7 @@ fun Activity.rescanPaths(paths: List, callback: (() -> Unit)? = null) { applicationContext.rescanPaths(paths, callback) } -fun BaseSimpleActivity.renameFile ( +fun BaseSimpleActivity.renameFile( oldPath: String, newPath: String, isRenamingMultipleFiles: Boolean, diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt index de21233b1..5f92d489c 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt @@ -164,6 +164,10 @@ fun Context.getSAFOnlyDirs(): List { } fun Context.isAccessibleWithSAFSdk30(path: String): Boolean { + if(path.startsWith(filesDir.absolutePath)){ + return false + } + val firstParentPath = path.getFirstParentPath(this) val firstParentDir = path.getFirstParentDirName(this) return isRPlus() && firstParentPath != path &&