From 7beff9a6921c5ec23f865c5096f842efc989b528 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 20 Oct 2018 16:35:12 +0200 Subject: [PATCH] optimize some things at the directory and media adapter --- .../gallery/adapters/DirectoryAdapter.kt | 16 +++++------ .../gallery/adapters/MediaAdapter.kt | 28 +++++++++++-------- 2 files changed, 25 insertions(+), 19 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 f03a9e92c..df6e1798b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -61,11 +61,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList) { var hiddenCnt = 0 var unhiddenCnt = 0 - getSelectedPaths().forEach { + selectedPaths.forEach { if (File(it).doesThisOrParentHaveNoMedia()) { hiddenCnt++ } else { @@ -132,11 +132,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList 0 } - private fun checkPinBtnVisibility(menu: Menu) { + private fun checkPinBtnVisibility(menu: Menu, selectedPaths: ArrayList) { val pinnedFolders = config.pinnedFolders var pinnedCnt = 0 var unpinnedCnt = 0 - getSelectedPaths().forEach { + selectedPaths.forEach { if (pinnedFolders.contains(it)) { pinnedCnt++ } else { 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 06ef2b350..da0cc5526 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -103,14 +103,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList menu.apply { - findItem(R.id.cab_rename).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.getIsInRecycleBin() == false + findItem(R.id.cab_rename).isVisible = isOneItemSelected() && selectedItems.firstOrNull()?.getIsInRecycleBin() == false findItem(R.id.cab_open_with).isVisible = isOneItemSelected() findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.size > 0 - findItem(R.id.cab_restore_recycle_bin_files).isVisible = getSelectedPaths().all { it.startsWith(activity.filesDir.absolutePath) } + findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.filesDir.absolutePath) } - checkHideBtnVisibility(this) - checkFavoriteBtnVisibility(this) + checkHideBtnVisibility(this, selectedItems) + checkFavoriteBtnVisibility(this, selectedItems) } } @@ -152,8 +158,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList) { var hiddenCnt = 0 var unhiddenCnt = 0 - getSelectedItems().forEach { + selectedItems.forEach { if (it.isHidden()) { hiddenCnt++ } else { @@ -173,15 +179,15 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList 0 && !isInRecycleBin menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 && !isInRecycleBin } - private fun checkFavoriteBtnVisibility(menu: Menu) { + private fun checkFavoriteBtnVisibility(menu: Menu, selectedItems: ArrayList) { var favoriteCnt = 0 var nonFavoriteCnt = 0 - getSelectedItems().forEach { + selectedItems.forEach { if (it.isFavorite) { favoriteCnt++ } else {