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

Commit 3d19426f authored by tibbi's avatar tibbi
Browse files

couple copy/move improvements

parent 980eec06
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.42'
        propVersionName = '3.11.43'
        kotlin_version = '1.2.21'
        support_libs = '27.0.2'
    }
+3 −5
Original line number Diff line number Diff line
@@ -77,8 +77,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
            try {
                val newPath = "${pair.second!!.path}/${file.name}"
                val newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath())

                if (File(newPath).exists() || activity.getSomeDocumentFile(newPath) != null) {
                if (activity.doesFilePathExist(newPath)) {
                    val resolution = getConflictResolution(newPath)
                    if (resolution == CONFLICT_SKIP) {
                        mFileCountToCopy--
@@ -219,10 +218,9 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
        var out: OutputStream? = null
        try {
            if (!mDocuments.containsKey(directory) && activity.needsStupidWritePermissions(destination.path)) {
                mDocuments[directory] = activity.getSomeDocumentFile(directory)
                mDocuments[directory] = activity.getDocumentFile(directory)
            }

            out = activity.getFileOutputStreamSync(directory, source.path.getMimeType(), mDocuments[directory])
            out = activity.getFileOutputStreamSync(destination.path, source.path.getMimeType(), mDocuments[directory])
            inputStream = activity.getFileInputStreamSync(source.path)!!

            var copiedSize = 0L
+1 −1
Original line number Diff line number Diff line
@@ -543,7 +543,7 @@ fun BaseSimpleActivity.getFileOutputStreamSync(path: String, mimeType: String, p
    val targetFile = File(path)

    return if (needsStupidWritePermissions(path)) {
        val documentFile = parentDocumentFile ?: getDocumentFile(targetFile.parent)
        val documentFile = parentDocumentFile ?: getDocumentFile(path.getParentPath())
        if (documentFile == null) {
            val error = String.format(getString(R.string.could_not_create_file), targetFile.parent)
            showErrorToast(error)
+2 −0
Original line number Diff line number Diff line
@@ -355,6 +355,8 @@ fun Context.trySAFFileDelete(fileDirItem: FileDirItem, allowDeleteFolder: Boolea
    }
}

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

// avoid these being set as SD card paths
private val physicalPaths = arrayListOf(
        "/storage/sdcard1", // Motorola Xoom
+4 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@ package com.simplemobiletools.commons.extensions

import android.content.Context
import android.media.ExifInterface
import com.simplemobiletools.commons.R.string.name
import com.simplemobiletools.commons.R.string.path
import com.simplemobiletools.commons.helpers.OTG_PATH
import java.text.SimpleDateFormat
import java.util.*
@@ -122,6 +124,8 @@ fun String.getGenericMimeType(): String {
    return "$type/*"
}

fun String.getParentPath() = substring(0, length - getFilenameFromPath().length)

fun String.getMimeTypeFromPath(): String {
    val typesMap = HashMap<String, String>().apply {
        put("323", "text/h323")
Loading