diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index aa625dcb..04a23c83 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -13,7 +13,9 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import com.simplemobiletools.filemanager.Config import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.activities.SimpleActivity +import com.simplemobiletools.filemanager.dialogs.CopyDialog import com.simplemobiletools.filemanager.dialogs.RenameItemDialog +import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog import com.simplemobiletools.filepicker.extensions.formatSize import com.simplemobiletools.filepicker.extensions.isGif @@ -61,6 +63,10 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List, shareFiles() true } + R.id.cab_copy_move -> { + displayCopyDialog() + true + } R.id.cab_delete -> { askConfirmDelete() true @@ -130,6 +136,28 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List, } } + private fun displayCopyDialog() { + val files = ArrayList() + val positions = multiSelector.selectedPositions + positions.forEach { files.add(File(mItems[it].path)) } + + CopyDialog(activity, files, object : CopyMoveTask.CopyMoveListener { + override fun copySucceeded(deleted: Boolean, copiedAll: Boolean) { + if (deleted) { + activity.toast(if (copiedAll) R.string.moving_success else R.string.moving_success_partial) + } else { + activity.toast(if (copiedAll) R.string.copying_success else R.string.copying_success_partial) + } + listener?.refreshItems() + actMode?.finish() + } + + override fun copyFailed() { + activity.toast(R.string.copy_move_failed) + } + }) + } + private fun askConfirmDelete() { ConfirmationDialog(activity, listener = object : ConfirmationDialog.OnConfirmedListener { override fun onConfirmed() { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index 357042c1..66d6bb3a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -15,9 +15,7 @@ import com.simplemobiletools.filemanager.PATH import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.activities.SimpleActivity import com.simplemobiletools.filemanager.adapters.ItemsAdapter -import com.simplemobiletools.filemanager.dialogs.CopyDialog import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog -import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask import com.simplemobiletools.filepicker.extensions.* import com.simplemobiletools.filepicker.models.FileDirItem import com.simplemobiletools.filepicker.views.RecyclerViewDivider @@ -174,52 +172,6 @@ class ItemsFragment : android.support.v4.app.Fragment(), ItemsAdapter.ItemOperat return type + "/*" } - /*override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - when (item.itemId) { - R.id.cab_copy -> { - displayCopyDialog() - mode.finish() - } - else -> return false - } - - return true - }*/ - - private fun displayCopyDialog() { - val fileIndexes = getSelectedItemIndexes() - if (fileIndexes.isEmpty()) - return - - val files = ArrayList(fileIndexes.size) - fileIndexes.mapTo(files) { File(mItems[it].path) } - - CopyDialog(activity as SimpleActivity, files, object : CopyMoveTask.CopyMoveListener { - override fun copySucceeded(deleted: Boolean, copiedAll: Boolean) { - if (deleted) { - context.toast(if (copiedAll) R.string.moving_success else R.string.moving_success_partial) - } else { - context.toast(if (copiedAll) R.string.copying_success else R.string.copying_success_partial) - } - fillItems() - } - - override fun copyFailed() { - context.toast(R.string.copy_move_failed) - } - }) - } - - private fun getSelectedItemIndexes(): List { - /*val items = items_list.checkedItemPositions - val cnt = items.size() - val selectedItems = (0..cnt - 1) - .filter { items.valueAt(it) } - .map { items.keyAt(it) } - return selectedItems*/ - return ArrayList() - } - override fun prepareForDeleting(paths: ArrayList) { activity.toast(R.string.deleting) mToBeDeleted = paths diff --git a/app/src/main/res/menu/cab.xml b/app/src/main/res/menu/cab.xml index d1255446..5ec2e027 100644 --- a/app/src/main/res/menu/cab.xml +++ b/app/src/main/res/menu/cab.xml @@ -17,7 +17,7 @@ android:title="@string/share" app:showAsAction="ifRoom"/>