From e6585180c3fc4fdbf039a68bde2ce25bff989e97 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 5 Dec 2016 21:58:46 +0100 Subject: [PATCH] show pin/unpin actionmenu item only when needed --- .../gallery/adapters/DirectoryAdapter.kt | 49 +++++++++++++------ .../asynctasks/GetDirectoriesAsynctask.kt | 9 +--- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 028f671a6..2bfc4ea0e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -108,24 +108,12 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList 0 - menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 - + val menuItem = menu.findItem(R.id.cab_edit) + menuItem.isVisible = positions.size <= 1 + checkHideBtnVisibility(menu, positions) + checkPinBtnVisibility(menu, positions) return true } @@ -135,6 +123,35 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList) { + var hiddenCnt = 0 + var unhiddenCnt = 0 + positions.map { dirs[it].path }.forEach { + if (config.getIsFolderHidden(it)) + hiddenCnt++ + else + unhiddenCnt++ + } + + menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 + menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 + } + + fun checkPinBtnVisibility(menu: Menu, positions: List) { + val pinnedFolders = config.pinnedFolders + var pinnedCnt = 0 + var unpinnedCnt = 0 + positions.map { dirs[it].path }.forEach { + if (pinnedFolders.contains(it)) + pinnedCnt++ + else + unpinnedCnt++ + } + + menu.findItem(R.id.cab_pin).isVisible = unpinnedCnt > 0 + menu.findItem(R.id.cab_unpin).isVisible = pinnedCnt > 0 + } } private fun showProperties() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 2ea315e34..8080b0c94 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -80,20 +80,15 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va } context.scanFiles(invalidFiles) {} - var dirs = ArrayList(directories.values) + val dirs = ArrayList(directories.values) filterDirectories(dirs) Directory.sorting = mConfig.directorySorting dirs.sort() - dirs = movePinnedToFront(dirs) - - return dirs + return movePinnedToFront(dirs) } private fun movePinnedToFront(dirs: ArrayList): ArrayList { - if (dirs.isEmpty()) - return dirs - val foundFolders = ArrayList() val pinnedFolders = mConfig.pinnedFolders