Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac36826f authored by tibbi's avatar tibbi
Browse files

couple file deleting improvements

parent 416b0391
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ buildscript {
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '3.12.8'
        propVersionName = '3.12.11'
        kotlin_version = '1.2.21'
        support_libs = '27.0.2'
    }
+2 −2
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
        }

        if (!copyOnly) {
            activity.deleteFiles(mTransferredFiles) {}
            activity.deleteFilesBg(mTransferredFiles) {}
        }

        val paths = mFiles.map { it.path } as ArrayList<String>
@@ -183,7 +183,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
                }

                val oldPath = "${source.path}/${child.name}"
                val oldFileDirItem = FileDirItem(oldPath, child.name, child.isDirectory)
                val oldFileDirItem = FileDirItem(oldPath, child.name, child.isDirectory, 0, child.length())
                val newFileDirItem = FileDirItem(newPath, child.name, child.isDirectory)
                copy(oldFileDirItem, newFileDirItem)
            }
+3 −3
Original line number Diff line number Diff line
@@ -417,7 +417,7 @@ fun BaseSimpleActivity.deleteFileBg(fileDirItem: FileDirItem, allowDeleteFolder:
    val file = File(path)
    var fileDeleted = !isPathOnOTG(path) && (!file.exists() || file.delete())
    if (fileDeleted) {
        rescanDeletedPath(fileDirItem.path) {
        rescanDeletedPath(path) {
            callback?.invoke(true)
        }
    } else {
@@ -427,10 +427,10 @@ fun BaseSimpleActivity.deleteFileBg(fileDirItem: FileDirItem, allowDeleteFolder:

        if (!fileDeleted) {
            if (isPathOnSD(path)) {
                handleSAFDialog(fileDirItem.path) {
                handleSAFDialog(path) {
                    trySAFFileDelete(fileDirItem, allowDeleteFolder, callback)
                }
            } else if (isPathOnOTG(fileDirItem.path)) {
            } else if (isPathOnOTG(path)) {
                trySAFFileDelete(fileDirItem, allowDeleteFolder, callback)
            }
        }
+6 −5
Original line number Diff line number Diff line
@@ -346,6 +346,7 @@ fun Context.trySAFFileDelete(fileDirItem: FileDirItem, allowDeleteFolder: Boolea
        if (document != null && (fileDirItem.isDirectory == document.isDirectory)) {
            fileDeleted = (document.isFile == true || allowDeleteFolder) && DocumentsContract.deleteDocument(applicationContext.contentResolver, document.uri)
        }
    }

    if (fileDeleted) {
        rescanDeletedPath(fileDirItem.path) {
@@ -353,9 +354,9 @@ fun Context.trySAFFileDelete(fileDirItem: FileDirItem, allowDeleteFolder: Boolea
        }
    }
}
}

fun Context.getDoesFilePathExist(path: String) = if (isPathOnOTG(path)) getFastDocumentFile(path)?.exists() ?: false else File(path).exists()
fun Context.getDoesFilePathExist(path: String) = if (isPathOnOTG(path)) getFastDocumentFile(path)?.exists()
        ?: false else File(path).exists()

fun Context.getIsPathDirectory(path: String): Boolean {
    return if (isPathOnOTG(path)) {
+1 −1
Original line number Diff line number Diff line
@@ -70,4 +70,4 @@ private fun getDirectoryFileCount(dir: File, countHiddenItems: Boolean): Int {

fun File.getDirectChildrenCount(countHiddenItems: Boolean) = listFiles()?.filter { if (countHiddenItems) true else !it.isHidden }?.size ?: 0

fun File.toFileDirItem(context: Context) = FileDirItem(absolutePath, name, context.getIsPathDirectory(absolutePath), 0, 0L)
fun File.toFileDirItem(context: Context) = FileDirItem(absolutePath, name, context.getIsPathDirectory(absolutePath), 0, length())