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

Commit db42b536 authored by tibbi's avatar tibbi
Browse files

couple copy/move improvements

parent fc3c4167
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.11.46'
        propVersionName = '3.11.47'
        kotlin_version = '1.2.21'
        support_libs = '27.0.2'
    }
+1 −1
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ open class BaseSimpleActivity : AppCompatActivity() {
                                    newFile.setLastModified(System.currentTimeMillis())
                                }
                                updateInMediaStore(oldFileDirItem.path, newFile.absolutePath)
                                updatedFiles.add(newFile.toFileDirItem())
                                updatedFiles.add(newFile.toFileDirItem(applicationContext))
                            }
                        }

+14 −11
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
    private val PROGRESS_RECHECK_INTERVAL = 500L

    private var mListener: WeakReference<CopyMoveListener>? = null
    private var mMovedFiles = ArrayList<FileDirItem>()
    private var mTransferredFiles = ArrayList<FileDirItem>()
    private var mDocuments = LinkedHashMap<String, DocumentFile?>()
    private var mFiles = ArrayList<FileDirItem>()
    private var mFileCountToCopy = 0
@@ -76,7 +76,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
        for (file in mFiles) {
            try {
                val newPath = "${pair.second!!.path}/${file.name}"
                val newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath())
                val newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), file.isDirectory)
                if (activity.doesFilePathExist(newPath)) {
                    val resolution = getConflictResolution(newPath)
                    if (resolution == CONFLICT_SKIP) {
@@ -96,7 +96,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
        }

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

        val paths = mFiles.map { it.path } as ArrayList<String>
@@ -110,7 +110,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
        val listener = mListener?.get() ?: return

        if (success) {
            listener.copySucceeded(copyOnly, mMovedFiles.size >= mFileCountToCopy)
            listener.copySucceeded(copyOnly, mTransferredFiles.size >= mFileCountToCopy)
        } else {
            listener.copyFailed()
        }
@@ -172,10 +172,10 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
        }

        if (activity.isPathOnOTG(source.path)) {
            val children = activity.getSomeDocumentFile(source.path)?.listFiles() ?: return
            val children = activity.getDocumentFile(source.path)?.listFiles() ?: return
            for (child in children) {
                val newPath = "$destinationPath/${child.name}"
                if (activity.getFastDocumentFile(newPath)?.exists() == true) {
                if (activity.doesFilePathExist(newPath)) {
                    continue
                }

@@ -184,18 +184,21 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
                val newFileDirItem = FileDirItem(newPath, child.name, child.isDirectory)
                copy(oldFileDirItem, newFileDirItem)
            }
            mTransferredFiles.add(source)
        } else {
            val children = File(source.path).list()
            for (child in children) {
                val newFile = File(destinationPath, child)
                if (newFile.exists()) {
                val newPath = "$destinationPath/$child"
                if (activity.doesFilePathExist(newPath)) {
                    continue
                }

                val oldFile = File(source.path, child)
                copy(oldFile.toFileDirItem(), newFile.toFileDirItem())
                val oldFileDirItem = oldFile.toFileDirItem(activity.applicationContext)
                val newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), oldFile.isDirectory)
                copy(oldFileDirItem, newFileDirItem)
            }
            mMovedFiles.add(source)
            mTransferredFiles.add(source)
        }
    }

@@ -234,7 +237,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
            mCurrentProgress += copiedSize

            if (source.size == copiedSize) {
                mMovedFiles.add(source)
                mTransferredFiles.add(source)
                if (activity.baseConfig.keepLastModified) {
                    copyOldLastModified(source.path, destination.path)
                } else {
+3 −3
Original line number Diff line number Diff line
@@ -332,7 +332,7 @@ fun BaseSimpleActivity.deleteFolderBg(fileDirItem: FileDirItem, deleteMediaOnly:
        val filesList = (filesArr as Array).toList()
        val files = filesList.filter { !deleteMediaOnly || it.isImageVideoGif() }
        for (file in files) {
            deleteFileBg(file.toFileDirItem(), false) { }
            deleteFileBg(file.toFileDirItem(applicationContext), false) { }
        }

        if (folder.listFiles()?.isEmpty() == true) {
@@ -589,12 +589,12 @@ fun Activity.handleAppPasswordProtection(callback: (success: Boolean) -> Unit) {
}

fun BaseSimpleActivity.createDirectorySync(directory: String): Boolean {
    if (File(directory).exists()) {
    if (doesFilePathExist(directory)) {
        return true
    }

    if (needsStupidWritePermissions(directory)) {
        val documentFile = getDocumentFile(directory) ?: return false
        val documentFile = getDocumentFile(directory.getParentPath()) ?: return false
        val newDir = documentFile.createDirectory(directory.getFilenameFromPath())
        return newDir != null
    }
+2 −1
Original line number Diff line number Diff line
package com.simplemobiletools.commons.extensions

import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Point
@@ -150,4 +151,4 @@ private fun getDirectoryFileCount(dir: File, countHiddenItems: Boolean): Int {
    return count
}

fun File.toFileDirItem() = FileDirItem(absolutePath, name, isDirectory, 0, 0L)
fun File.toFileDirItem(context: Context) = FileDirItem(absolutePath, name, absolutePath.getIsDirectory(context), 0, 0L)
Loading