From b380f7fcb53e8f92ad3ea4c9d66a23db04924ad7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 29 Jan 2018 15:10:21 +0100 Subject: [PATCH] add a Merge option to folder conflict resolution --- build.gradle | 2 +- .../commons/asynctasks/CopyMoveTask.kt | 10 ++++++++-- .../commons/dialogs/FileConflictDialog.kt | 10 +++++++++- .../commons/extensions/Context-storage.kt | 3 ++- .../com/simplemobiletools/commons/helpers/Constants.kt | 1 + commons/src/main/res/layout/dialog_file_conflict.xml | 9 +++++++++ commons/src/main/res/values-sk/strings.xml | 2 +- 7 files changed, 31 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 5f316da88..d029c8740 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt index 9a2601762..2d8a6a5cd 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt @@ -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) { - continue + 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) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FileConflictDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FileConflictDialog.kt index e767e0cce..409a7087b 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FileConflictDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FileConflictDialog.kt @@ -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) } } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt index c8ab13e4d..5ab5677da 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt @@ -127,8 +127,9 @@ 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") diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/helpers/Constants.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/helpers/Constants.kt index f5f7e8628..9648b4e43 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/helpers/Constants.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/helpers/Constants.kt @@ -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", diff --git a/commons/src/main/res/layout/dialog_file_conflict.xml b/commons/src/main/res/layout/dialog_file_conflict.xml index e5423c1a1..35c30a602 100644 --- a/commons/src/main/res/layout/dialog_file_conflict.xml +++ b/commons/src/main/res/layout/dialog_file_conflict.xml @@ -42,6 +42,15 @@ android:paddingBottom="@dimen/normal_margin" android:paddingTop="@dimen/normal_margin" android:text="@string/overwrite"/> + + + Súbor \"%1$s\" už existuje Súbor \"%1$s\" už existuje. Prepísať? Priečinok \"%1$s\" už existuje - Merge + Zlúčiť Prepísať Preskočiť Pripnúť \'_1\'