Clean-ups and more enforcements for SDK 30
This commit is contained in:
parent
dd64d4af82
commit
1942947aae
3 changed files with 36 additions and 25 deletions
|
@ -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)
|
||||
|
|
|
@ -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<FileDirItem>, allowDeleteFolder
|
|||
}
|
||||
|
||||
var wasSuccess = false
|
||||
handleSAFDialog(files[0].path) {
|
||||
val firstFile = files.first()
|
||||
handleSAFDialog(firstFile.path) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
val failedFileDirItems = ArrayList<FileDirItem>()
|
||||
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<FileDirItem>()
|
||||
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<String>, callback: (() -> Unit)? = null) {
|
|||
applicationContext.rescanPaths(paths, callback)
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.renameFile (
|
||||
fun BaseSimpleActivity.renameFile(
|
||||
oldPath: String,
|
||||
newPath: String,
|
||||
isRenamingMultipleFiles: Boolean,
|
||||
|
|
|
@ -164,6 +164,10 @@ fun Context.getSAFOnlyDirs(): List<String> {
|
|||
}
|
||||
|
||||
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 &&
|
||||
|
|
Loading…
Reference in a new issue