add a Merge option to folder conflict resolution
This commit is contained in:
parent
72b358430a
commit
b380f7fcb5
7 changed files with 31 additions and 6 deletions
|
@ -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,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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -42,6 +42,15 @@
|
|||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:text="@string/overwrite"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/conflict_dialog_radio_merge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:text="@string/merge"/>
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
|
|
|
@ -81,7 +81,7 @@
|
|||
<string name="file_already_exists">Súbor \"%1$s\" už existuje</string>
|
||||
<string name="file_already_exists_overwrite">Súbor \"%1$s\" už existuje. Prepísať?</string>
|
||||
<string name="folder_already_exists">Priečinok \"%1$s\" už existuje</string>
|
||||
<string name="merge">Merge</string>
|
||||
<string name="merge">Zlúčiť</string>
|
||||
<string name="overwrite">Prepísať</string>
|
||||
<string name="skip">Preskočiť</string>
|
||||
<string name="append">Pripnúť \'_1\'</string>
|
||||
|
|
Loading…
Reference in a new issue