do not allow picking the source folder as the destination at copy/move

This commit is contained in:
tibbi 2017-02-28 22:07:43 +01:00
parent 9cae71b7ab
commit 4b104fc8d6
2 changed files with 10 additions and 4 deletions

View file

@ -24,7 +24,7 @@ class CopyDialog(val activity: SimpleActivity, val files: ArrayList<File>, val c
var destinationPath = ""
view.destination.setOnClickListener {
PickAlbumDialog(activity) {
PickAlbumDialog(activity, sourcePath) {
destinationPath = it
view.destination.text = activity.humanizePath(it)
}

View file

@ -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,9 +30,14 @@ class PickAlbumDialog(val activity: SimpleActivity, val callback: (path: String)
GetDirectoriesAsynctask(activity, false, false) {
val adapter = DirectoryAdapter(activity, it, null) {
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()
}