From 40c4a9aec115747a2bec4f2a058c331ebf544f6b Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 26 Apr 2017 20:23:04 +0200 Subject: [PATCH] add hide/unhide menu items to media activity cab --- .../gallery/adapters/MediaAdapter.kt | 29 +++++++++++++++++-- app/src/main/res/menu/cab_media.xml | 10 +++++++ 2 files changed, 36 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 784245ec3..103887658 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -72,6 +72,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, R.id.cab_properties -> showProperties() R.id.cab_rename -> renameFile() R.id.cab_edit -> editFile() + R.id.cab_hide -> toggleFileVisibility(true) + R.id.cab_unhide -> toggleFileVisibility(false) R.id.cab_share -> shareMedia() R.id.cab_copy_to -> copyMoveTo(true) R.id.cab_move_to -> copyMoveTo(false) @@ -90,9 +92,12 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean { - val selections = multiSelector.selectedPositions - menu.findItem(R.id.cab_rename).isVisible = selections.size <= 1 - menu.findItem(R.id.cab_edit).isVisible = selections.size == 1 && media[selections[0]].isImage() + val positions = multiSelector.selectedPositions + menu.findItem(R.id.cab_rename).isVisible = positions.size <= 1 + menu.findItem(R.id.cab_edit).isVisible = positions.size == 1 && media[positions[0]].isImage() + + checkHideBtnVisibility(menu, positions) + return true } @@ -102,6 +107,20 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, markedItems.clear() actMode = null } + + fun checkHideBtnVisibility(menu: Menu, positions: List) { + var hiddenCnt = 0 + var unhiddenCnt = 0 + positions.map { media[it] }.forEach { + if (it.name.startsWith('.')) + hiddenCnt++ + else + unhiddenCnt++ + } + + menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 + menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 + } } private fun showProperties() { @@ -129,6 +148,10 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, actMode?.finish() } + private fun toggleFileVisibility(hide: Boolean) { + + } + private fun shareMedia() { val selections = multiSelector.selectedPositions if (selections.size <= 1) { diff --git a/app/src/main/res/menu/cab_media.xml b/app/src/main/res/menu/cab_media.xml index 0364126d2..4b47e6025 100644 --- a/app/src/main/res/menu/cab_media.xml +++ b/app/src/main/res/menu/cab_media.xml @@ -21,6 +21,16 @@ android:icon="@drawable/ic_rename" android:title="@string/rename" app:showAsAction="ifRoom"/> + +