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

Commit 72b35843 authored by tibbi's avatar tibbi
Browse files

properly handle file skip/overwrite at conflicts

parent 52ea3766
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -175,13 +175,6 @@ open class BaseSimpleActivity : AppCompatActivity() {
            return
        }

        if (files.size == 1) {
            if (File(destination, files[0].name).exists()) {
                toast(R.string.name_taken)
                return
            }
        }

        handleSAFDialog(destinationFolder) {
            copyMoveCallback = callback
            if (isCopyOperation) {
@@ -236,14 +229,15 @@ open class BaseSimpleActivity : AppCompatActivity() {
        }

        val file = files[index]
        if (file.exists()) {
            FileConflictDialog(this, file.name) { resolution, applyForAll ->
        val newFile = File(destinationFolder, file.name)
        if (newFile.exists()) {
            FileConflictDialog(this, newFile) { resolution, applyForAll ->
                if (applyForAll) {
                    conflictResolutions.clear()
                    conflictResolutions[""] = resolution
                    checkConflict(files, destinationFolder, files.size, conflictResolutions, callback)
                } else {
                    conflictResolutions[file.absolutePath] = resolution
                    conflictResolutions[newFile.absolutePath] = resolution
                    checkConflict(files, destinationFolder, index + 1, conflictResolutions, callback)
                }
            }
+14 −3
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import android.support.v4.util.Pair
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
import com.simplemobiletools.commons.interfaces.CopyMoveListener
import java.io.File
import java.io.FileInputStream
@@ -37,12 +38,12 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal

        for (file in mFiles) {
            try {
                val curFile = File(pair.second, file.name)
                if (curFile.exists()) {
                val newFile = File(pair.second, file.name)
                if (newFile.exists() && getConflictResolution(newFile) == CONFLICT_SKIP) {
                    continue
                }

                copy(file, curFile)
                copy(file, newFile)
            } catch (e: Exception) {
                activity.toast(e.toString())
                return false
@@ -57,6 +58,16 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
        return true
    }

    private fun getConflictResolution(file: File): Int {
        return if (conflictResolutions.size == 1 && conflictResolutions.containsKey("")) {
            conflictResolutions[""]!!
        } else if (conflictResolutions.containsKey(file.absolutePath)) {
            conflictResolutions[file.absolutePath]!!
        } else {
            CONFLICT_SKIP
        }
    }

    private fun copy(source: File, destination: File) {
        if (source.isDirectory) {
            copyDirectory(source, destination)
+4 −3
Original line number Diff line number Diff line
@@ -9,13 +9,14 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
import kotlinx.android.synthetic.main.dialog_file_conflict.view.*
import java.io.File

class FileConflictDialog(val activity: Activity, val filename: String, val callback: (resolution: Int, applyForAll: Boolean) -> Unit) {
    val view = activity.layoutInflater.inflate(R.layout.dialog_file_conflict, null)
class FileConflictDialog(val activity: Activity, val file: File, val callback: (resolution: Int, applyForAll: Boolean) -> Unit) {
    val view = activity.layoutInflater.inflate(R.layout.dialog_file_conflict, null)!!

    init {
        view.apply {
            conflict_dialog_title.text = String.format(activity.getString(R.string.file_already_exists), filename)
            conflict_dialog_title.text = String.format(activity.getString(R.string.file_already_exists), file.name)
            conflict_dialog_apply_to_all.isChecked = activity.baseConfig.lastConflictApplyToAll

            val resolutionButton = when (activity.baseConfig.lastConflictResolution) {