try harder at fetching uris from FileDirItems
This commit is contained in:
parent
edb96519a7
commit
aebda1f471
6 changed files with 24 additions and 12 deletions
|
@ -666,7 +666,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
|
|||
if (isCopyOperation) {
|
||||
val recycleBinPath = fileDirItems.first().isRecycleBinPath(this)
|
||||
if (canManageMedia() && !recycleBinPath) {
|
||||
val fileUris = getFileUrisFromFileDirItems(fileDirItems).second
|
||||
val fileUris = getFileUrisFromFileDirItems(fileDirItems)
|
||||
updateSDK30Uris(fileUris) { sdk30UriSuccess ->
|
||||
if (sdk30UriSuccess) {
|
||||
startCopyMove(fileDirItems, destination, isCopyOperation, copyPhotoVideoOnly, copyHidden)
|
||||
|
@ -685,7 +685,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
|
|||
if (safSuccess) {
|
||||
val recycleBinPath = fileDirItems.first().isRecycleBinPath(this)
|
||||
if (canManageMedia() && !recycleBinPath) {
|
||||
val fileUris = getFileUrisFromFileDirItems(fileDirItems).second
|
||||
val fileUris = getFileUrisFromFileDirItems(fileDirItems)
|
||||
updateSDK30Uris(fileUris) { sdk30UriSuccess ->
|
||||
if (sdk30UriSuccess) {
|
||||
startCopyMove(fileDirItems, destination, isCopyOperation, copyPhotoVideoOnly, copyHidden)
|
||||
|
|
|
@ -323,7 +323,7 @@ class CopyMoveTask(
|
|||
// if we delete multiple files from Downloads folder on Android 11 or 12 without being a Media Management app, show the confirmation dialog just once
|
||||
private fun deleteProtectedFiles() {
|
||||
if (mFileDirItemsToDelete.isNotEmpty()) {
|
||||
val fileUris = activity.getFileUrisFromFileDirItems(mFileDirItemsToDelete).second
|
||||
val fileUris = activity.getUrisPathsFromFileDirItems(mFileDirItemsToDelete).second
|
||||
activity.deleteSDK30Uris(fileUris) { success ->
|
||||
if (success) {
|
||||
mFileDirItemsToDelete.forEach {
|
||||
|
|
|
@ -729,7 +729,8 @@ fun BaseSimpleActivity.deleteFilesBg(files: List<FileDirItem>, allowDeleteFolder
|
|||
|
||||
val recycleBinPath = firstFile.isRecycleBinPath(this)
|
||||
if (canManageMedia() && !recycleBinPath) {
|
||||
val fileUris = getFileUrisFromFileDirItems(files).second
|
||||
val fileUris = getFileUrisFromFileDirItems(files)
|
||||
|
||||
deleteSDK30Uris(fileUris) { success ->
|
||||
runOnUiThread {
|
||||
callback?.invoke(success)
|
||||
|
@ -759,7 +760,7 @@ private fun BaseSimpleActivity.deleteFilesCasual(
|
|||
|
||||
if (index == files.lastIndex) {
|
||||
if (isRPlus() && failedFileDirItems.isNotEmpty()) {
|
||||
val fileUris = getFileUrisFromFileDirItems(failedFileDirItems).second
|
||||
val fileUris = getFileUrisFromFileDirItems(failedFileDirItems)
|
||||
deleteSDK30Uris(fileUris) { success ->
|
||||
runOnUiThread {
|
||||
callback?.invoke(success)
|
||||
|
@ -850,7 +851,7 @@ fun BaseSimpleActivity.deleteFileBg(
|
|||
}
|
||||
|
||||
private fun BaseSimpleActivity.deleteSdk30(fileDirItem: FileDirItem, callback: ((wasSuccess: Boolean) -> Unit)?) {
|
||||
val fileUris = getFileUrisFromFileDirItems(arrayListOf(fileDirItem)).second
|
||||
val fileUris = getFileUrisFromFileDirItems(arrayListOf(fileDirItem))
|
||||
deleteSDK30Uris(fileUris) { success ->
|
||||
runOnUiThread {
|
||||
callback?.invoke(success)
|
||||
|
@ -1009,7 +1010,7 @@ private fun BaseSimpleActivity.renameCasually(
|
|||
if (isRenamingMultipleFiles) {
|
||||
callback?.invoke(false, Android30RenameFormat.CONTENT_RESOLVER)
|
||||
} else {
|
||||
val fileUris = getFileUrisFromFileDirItems(arrayListOf(File(oldPath).toFileDirItem(this))).second
|
||||
val fileUris = getFileUrisFromFileDirItems(arrayListOf(File(oldPath).toFileDirItem(this)))
|
||||
updateSDK30Uris(fileUris) { success ->
|
||||
if (success) {
|
||||
val values = ContentValues().apply {
|
||||
|
@ -1071,7 +1072,7 @@ private fun BaseSimpleActivity.renameCasually(
|
|||
if (isRenamingMultipleFiles) {
|
||||
callback?.invoke(false, Android30RenameFormat.SAF)
|
||||
} else {
|
||||
val fileUris = getFileUrisFromFileDirItems(arrayListOf(File(oldPath).toFileDirItem(this))).second
|
||||
val fileUris = getFileUrisFromFileDirItems(arrayListOf(File(oldPath).toFileDirItem(this)))
|
||||
updateSDK30Uris(fileUris) { success ->
|
||||
if (!success) {
|
||||
return@updateSDK30Uris
|
||||
|
@ -1255,7 +1256,7 @@ fun BaseSimpleActivity.getFileOutputStream(fileDirItem: FileDirItem, allowCreati
|
|||
isRestrictedWithSAFSdk30(fileDirItem.path) -> {
|
||||
callback.invoke(
|
||||
try {
|
||||
val fileUri = getFileUrisFromFileDirItems(arrayListOf(fileDirItem)).second
|
||||
val fileUri = getFileUrisFromFileDirItems(arrayListOf(fileDirItem))
|
||||
applicationContext.contentResolver.openOutputStream(fileUri.first())
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
|
|
|
@ -943,7 +943,7 @@ private val physicalPaths = arrayListOf(
|
|||
// Convert paths like /storage/emulated/0/Pictures/Screenshots/first.jpg to content://media/external/images/media/131799
|
||||
// so that we can refer to the file in the MediaStore.
|
||||
// If we found no mediastore uri for a given file, do not return its path either to avoid some mismatching
|
||||
fun Context.getFileUrisFromFileDirItems(fileDirItems: List<FileDirItem>): Pair<ArrayList<String>, ArrayList<Uri>> {
|
||||
fun Context.getUrisPathsFromFileDirItems(fileDirItems: List<FileDirItem>): Pair<ArrayList<String>, ArrayList<Uri>> {
|
||||
val fileUris = ArrayList<Uri>()
|
||||
val successfulFilePaths = ArrayList<String>()
|
||||
val allIds = getMediaStoreIds(this)
|
||||
|
@ -987,3 +987,14 @@ fun getMediaStoreIds(context: Context): HashMap<String, Long> {
|
|||
|
||||
return ids
|
||||
}
|
||||
|
||||
fun Context.getFileUrisFromFileDirItems(fileDirItems: List<FileDirItem>): List<Uri> {
|
||||
val fileUris = getUrisPathsFromFileDirItems(fileDirItems).second
|
||||
if (fileUris.isEmpty()) {
|
||||
fileDirItems.map { fileDirItem ->
|
||||
fileUris.add(fileDirItem.assembleContentUri())
|
||||
}
|
||||
}
|
||||
|
||||
return fileUris
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ class RenamePatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(c
|
|||
callback: (success: Boolean) -> Unit
|
||||
) {
|
||||
val fileDirItems = paths.map { File(it).toFileDirItem(context) }
|
||||
val uriPairs = context.getFileUrisFromFileDirItems(fileDirItems)
|
||||
val uriPairs = context.getUrisPathsFromFileDirItems(fileDirItems)
|
||||
val validPaths = uriPairs.first
|
||||
val uris = uriPairs.second
|
||||
val activity = activity
|
||||
|
|
|
@ -121,7 +121,7 @@ class RenameSimpleTab(context: Context, attrs: AttributeSet) : RelativeLayout(co
|
|||
callback: (success: Boolean) -> Unit
|
||||
) {
|
||||
val fileDirItems = paths.map { File(it).toFileDirItem(context) }
|
||||
val uriPairs = context.getFileUrisFromFileDirItems(fileDirItems)
|
||||
val uriPairs = context.getUrisPathsFromFileDirItems(fileDirItems)
|
||||
val validPaths = uriPairs.first
|
||||
val uris = uriPairs.second
|
||||
val activity = activity
|
||||
|
|
Loading…
Reference in a new issue