diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index f76378e71..ed9418899 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -314,30 +314,6 @@ class MediaActivity : SimpleActivity(), AdapterView.OnItemClickListener, View.On private fun isSetWallpaperIntent() = intent.getBooleanExtra(Constants.SET_WALLPAPER_INTENT, false) - private fun displayCopyDialog() { - /*val items = media_grid.checkedItemPositions - val cnt = items.size() - val files = (0..cnt - 1) - .filter { items.valueAt(it) } - .map { items.keyAt(it) } - .mapTo(ArrayList()) { File(mMedia[it].path) } - - CopyDialog(this, files, object : CopyMoveTask.CopyMoveListener { - override fun copySucceeded(deleted: Boolean, copiedAll: Boolean) { - if (deleted) { - refreshDir() - toast(if (copiedAll) R.string.moving_success else R.string.moving_success_partial) - } else { - toast(if (copiedAll) R.string.copying_success else R.string.copying_success_partial) - } - } - - override fun copyFailed() { - toast(R.string.copy_move_failed) - } - })*/ - } - override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) { val curItemPath = mMedia[position].path if (isSetWallpaperIntent()) { @@ -377,16 +353,6 @@ class MediaActivity : SimpleActivity(), AdapterView.OnItemClickListener, View.On } } - /*override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - when (item.itemId) { - R.id.cab_copy_move -> { - displayCopyDialog() - return true - } - else -> return false - } - }*/ - override fun onTouch(v: View, event: MotionEvent): Boolean { if (mIsSnackbarShown) { deleteFiles() @@ -395,6 +361,10 @@ class MediaActivity : SimpleActivity(), AdapterView.OnItemClickListener, View.On return false } + override fun refreshItems() { + refreshDir() + } + override fun onRefresh() { refreshDir() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 6dc93891d..ef52bb7aa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -10,17 +10,21 @@ import com.bignerdranch.android.multiselector.SwappingHolder import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.signature.StringSignature +import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog +import com.simplemobiletools.filepicker.extensions.toast import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog import com.simplemobiletools.gallery.Config import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity +import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.extensions.beVisibleIf import com.simplemobiletools.gallery.extensions.shareMedia import com.simplemobiletools.gallery.extensions.shareMedium import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.photo_video_item.view.* import kotlinx.android.synthetic.main.photo_video_tmb.view.* +import java.io.File import java.util.* class MediaAdapter(val activity: SimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val itemClick: (Medium) -> Unit) : @@ -52,6 +56,10 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, shareMedia() return true } + R.id.cab_copy_move -> { + displayCopyDialog() + return true + } R.id.cab_delete -> { askConfirmDelete() true @@ -95,6 +103,28 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } } + private fun displayCopyDialog() { + val files = ArrayList() + val positions = multiSelector.selectedPositions + positions.forEach { files.add(File(media[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() { @@ -189,6 +219,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } interface MediaOperationsListener { + fun refreshItems() + fun prepareForDeleting(paths: ArrayList) } }