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

Commit b380f7fc authored by tibbi's avatar tibbi
Browse files

add a Merge option to folder conflict resolution

parent 72b35843
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.8.15'
        propVersionName = '3.9.0'
        kotlin_version = '1.2.21'
        support_libs = '27.0.2'
    }
+8 −2
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_OVERWRITE
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
import com.simplemobiletools.commons.interfaces.CopyMoveListener
import java.io.File
@@ -39,8 +40,13 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
        for (file in mFiles) {
            try {
                val newFile = File(pair.second, file.name)
                if (newFile.exists() && getConflictResolution(newFile) == CONFLICT_SKIP) {
                if (newFile.exists()) {
                    val resolution = getConflictResolution(newFile)
                    if (resolution == CONFLICT_SKIP) {
                        continue
                    } else if (resolution == CONFLICT_OVERWRITE) {
                        activity.deleteFilesBg(arrayListOf(newFile), true)
                    }
                }

                copy(file, newFile)
+9 −1
Original line number Diff line number Diff line
@@ -3,9 +3,12 @@ package com.simplemobiletools.commons.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.R.id.conflict_dialog_radio_merge
import com.simplemobiletools.commons.R.id.conflict_dialog_radio_skip
import com.simplemobiletools.commons.extensions.baseConfig
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.CONFLICT_MERGE
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
import kotlinx.android.synthetic.main.dialog_file_conflict.view.*
@@ -16,11 +19,14 @@ class FileConflictDialog(val activity: Activity, val file: File, val callback: (

    init {
        view.apply {
            conflict_dialog_title.text = String.format(activity.getString(R.string.file_already_exists), file.name)
            val stringBase = if (file.isDirectory) R.string.folder_already_exists else R.string.file_already_exists
            conflict_dialog_title.text = String.format(activity.getString(stringBase), file.name)
            conflict_dialog_apply_to_all.isChecked = activity.baseConfig.lastConflictApplyToAll
            conflict_dialog_radio_merge.beVisibleIf(file.isDirectory)

            val resolutionButton = when (activity.baseConfig.lastConflictResolution) {
                CONFLICT_OVERWRITE -> conflict_dialog_radio_overwrite
                CONFLICT_MERGE -> conflict_dialog_radio_merge
                else -> conflict_dialog_radio_skip
            }
            resolutionButton.isChecked = true
@@ -37,6 +43,7 @@ class FileConflictDialog(val activity: Activity, val file: File, val callback: (
    private fun dialogConfirmed() {
        val resolution = when (view.conflict_dialog_radio_group.checkedRadioButtonId) {
            conflict_dialog_radio_skip -> CONFLICT_SKIP
            conflict_dialog_radio_merge -> CONFLICT_MERGE
            else -> CONFLICT_OVERWRITE
        }

@@ -45,6 +52,7 @@ class FileConflictDialog(val activity: Activity, val file: File, val callback: (
            lastConflictApplyToAll = applyToAll
            lastConflictResolution = resolution
        }

        callback(resolution, applyToAll)
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -127,9 +127,10 @@ fun Context.tryFastDocumentDelete(file: File, allowDeleteFolder: Boolean): Boole
    val document = getFastDocument(file)
    return if (document?.isFile == true || allowDeleteFolder) {
        DocumentsContract.deleteDocument(contentResolver, document?.uri)
    } else
    } else {
        false
    }
}

@SuppressLint("NewApi")
fun Context.getFastDocument(file: File): DocumentFile? {
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ const val PERMISSION_CALL_PHONE = 9
// conflict resolving
const val CONFLICT_SKIP = 1
const val CONFLICT_OVERWRITE = 2
const val CONFLICT_MERGE = 3

fun getDateFormats() = arrayListOf(
        "yyyy-MM-dd",
Loading