From b98b6e6cb9f5007d0679a3abbdb056879d98aa7f Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 27 Oct 2017 09:36:41 +0200 Subject: [PATCH] add Set As to the media thumbnails view --- .../com/simplemobiletools/gallery/adapters/MediaAdapter.kt | 6 +++++- app/src/main/res/menu/cab_media.xml | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 64ea45c2a..b71a694a7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -88,6 +88,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, R.id.cab_move_to -> copyMoveTo(false) R.id.cab_select_all -> selectAll() R.id.cab_open_with -> activity.openFile(Uri.fromFile(getCurrentFile())) + R.id.cab_set_as -> activity.setAs(Uri.fromFile(getCurrentFile())) R.id.cab_delete -> checkDeleteConfirmation() else -> return false } @@ -104,7 +105,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean { menu.findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 menu.findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1 - menu.findItem(R.id.cab_edit).isVisible = selectedPositions.size == 1 && media.size > selectedPositions.first() && media[selectedPositions.first()].isImage() + menu.findItem(R.id.cab_edit).isVisible = isOneImageSelected() + menu.findItem(R.id.cab_set_as).isVisible = isOneImageSelected() menu.findItem(R.id.cab_confirm_selection).isVisible = isPickIntent && allowMultiplePicks && selectedPositions.size > 0 checkHideBtnVisibility(menu) @@ -135,6 +137,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 } + + private fun isOneImageSelected() = selectedPositions.size == 1 && media.size > selectedPositions.first() && media[selectedPositions.first()].isImage() } private fun confirmSelection() { diff --git a/app/src/main/res/menu/cab_media.xml b/app/src/main/res/menu/cab_media.xml index bcf08f106..8ebb87f08 100644 --- a/app/src/main/res/menu/cab_media.xml +++ b/app/src/main/res/menu/cab_media.xml @@ -50,6 +50,10 @@ android:id="@+id/cab_open_with" android:title="@string/open_with" app:showAsAction="never"/> +