From 4b104fc8d61458f408430b45dce74b71babc131d Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 28 Feb 2017 22:07:43 +0100 Subject: [PATCH] do not allow picking the source folder as the destination at copy/move --- .../simplemobiletools/gallery/dialogs/CopyDialog.kt | 2 +- .../gallery/dialogs/PickAlbumDialog.kt | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt index ec110ad43..589338505 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt @@ -24,7 +24,7 @@ class CopyDialog(val activity: SimpleActivity, val files: ArrayList, val c var destinationPath = "" view.destination.setOnClickListener { - PickAlbumDialog(activity) { + PickAlbumDialog(activity, sourcePath) { destinationPath = it view.destination.text = activity.humanizePath(it) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt index d5139a49e..c3ec72601 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt @@ -6,6 +6,7 @@ import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.adapters.DirectoryAdapter @@ -13,7 +14,7 @@ import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.dialog_album_picker.view.* -class PickAlbumDialog(val activity: SimpleActivity, val callback: (path: String) -> Unit) { +class PickAlbumDialog(val activity: SimpleActivity, val sourcePath: String, val callback: (path: String) -> Unit) { var directoriesGrid: RecyclerView init { @@ -29,8 +30,13 @@ class PickAlbumDialog(val activity: SimpleActivity, val callback: (path: String) GetDirectoriesAsynctask(activity, false, false) { val adapter = DirectoryAdapter(activity, it, null) { - callback.invoke(it.path) - dismiss() + if (it.path.trimEnd('/') == sourcePath) { + activity.toast(R.string.source_and_destination_same) + return@DirectoryAdapter + } else { + callback.invoke(it.path) + dismiss() + } } directoriesGrid.adapter = adapter }.execute()