From 74d828733306a36c630a90d039bfb81cb9d48250 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 6 Dec 2016 23:30:22 +0100 Subject: [PATCH] add an Edit button to media cab --- .../gallery/adapters/MediaAdapter.kt | 19 ++++++++++++++++--- app/src/main/res/menu/cab_media.xml | 5 +++++ 2 files changed, 21 insertions(+), 3 deletions(-) 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 3cdcbd353..e1dc63988 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -20,6 +20,7 @@ import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.RenameFileDialog import com.simplemobiletools.gallery.extensions.beVisibleIf +import com.simplemobiletools.gallery.extensions.openEditor import com.simplemobiletools.gallery.extensions.shareMedia import com.simplemobiletools.gallery.extensions.shareMedium import com.simplemobiletools.gallery.helpers.Config @@ -67,13 +68,17 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, renameFile() true } + R.id.cab_edit -> { + editFile() + true + } R.id.cab_share -> { shareMedia() - return true + true } R.id.cab_copy_move -> { displayCopyDialog() - return true + true } R.id.cab_delete -> { askConfirmDelete() @@ -92,6 +97,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean { menu.findItem(R.id.cab_rename).isVisible = multiSelector.selectedPositions.size <= 1 + menu.findItem(R.id.cab_edit).isVisible = multiSelector.selectedPositions.size <= 1 return true } @@ -115,7 +121,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } private fun renameFile() { - RenameFileDialog(activity, File(media[multiSelector.selectedPositions[0]].path)) { + RenameFileDialog(activity, getCurrentFile()) { listener?.refreshItems() activity.runOnUiThread { actMode?.finish() @@ -123,6 +129,11 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } } + private fun editFile() { + activity.openEditor(getCurrentFile()) + actMode?.finish() + } + private fun shareMedia() { val selections = multiSelector.selectedPositions if (selections.size <= 1) { @@ -161,6 +172,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } } + private fun getCurrentFile() = File(media[multiSelector.selectedPositions[0]].path) + private fun prepareForDeleting() { val selections = multiSelector.selectedPositions val paths = ArrayList(selections.size) diff --git a/app/src/main/res/menu/cab_media.xml b/app/src/main/res/menu/cab_media.xml index 8d51dbad8..006a9091b 100644 --- a/app/src/main/res/menu/cab_media.xml +++ b/app/src/main/res/menu/cab_media.xml @@ -21,6 +21,11 @@ android:icon="@mipmap/rename" android:title="@string/rename" app:showAsAction="ifRoom"/> +