optimize the way some actionmenu button visibility is determined
This commit is contained in:
parent
9d3848b2ab
commit
feba98917a
2 changed files with 9 additions and 49 deletions
|
@ -119,34 +119,14 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkHideBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
private fun checkHideBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
||||||
var hiddenCnt = 0
|
menu.findItem(R.id.cab_hide).isVisible = selectedPaths.any { !File(it).doesThisOrParentHaveNoMedia() }
|
||||||
var unhiddenCnt = 0
|
menu.findItem(R.id.cab_unhide).isVisible = selectedPaths.any { File(it).doesThisOrParentHaveNoMedia() }
|
||||||
selectedPaths.forEach {
|
|
||||||
if (File(it).doesThisOrParentHaveNoMedia()) {
|
|
||||||
hiddenCnt++
|
|
||||||
} else {
|
|
||||||
unhiddenCnt++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0
|
|
||||||
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkPinBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
private fun checkPinBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
||||||
val pinnedFolders = config.pinnedFolders
|
val pinnedFolders = config.pinnedFolders
|
||||||
var pinnedCnt = 0
|
menu.findItem(R.id.cab_pin).isVisible = selectedPaths.any { !pinnedFolders.contains(it) }
|
||||||
var unpinnedCnt = 0
|
menu.findItem(R.id.cab_unpin).isVisible = selectedPaths.any { pinnedFolders.contains(it) }
|
||||||
selectedPaths.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() {
|
private fun showProperties() {
|
||||||
|
|
|
@ -113,7 +113,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.cab_rename).isVisible = isOneItemSelected && selectedItems.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_open_with).isVisible = isOneItemSelected
|
||||||
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.size > 0
|
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.isNotEmpty()
|
||||||
findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.filesDir.absolutePath) }
|
findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.filesDir.absolutePath) }
|
||||||
|
|
||||||
checkHideBtnVisibility(this, selectedItems)
|
checkHideBtnVisibility(this, selectedItems)
|
||||||
|
@ -170,34 +170,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
fun isASectionTitle(position: Int) = media.getOrNull(position) is ThumbnailSection
|
fun isASectionTitle(position: Int) = media.getOrNull(position) is ThumbnailSection
|
||||||
|
|
||||||
private fun checkHideBtnVisibility(menu: Menu, selectedItems: ArrayList<Medium>) {
|
private fun checkHideBtnVisibility(menu: Menu, selectedItems: ArrayList<Medium>) {
|
||||||
var hiddenCnt = 0
|
|
||||||
var unhiddenCnt = 0
|
|
||||||
selectedItems.forEach {
|
|
||||||
if (it.isHidden()) {
|
|
||||||
hiddenCnt++
|
|
||||||
} else {
|
|
||||||
unhiddenCnt++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val isInRecycleBin = selectedItems.firstOrNull()?.getIsInRecycleBin() == true
|
val isInRecycleBin = selectedItems.firstOrNull()?.getIsInRecycleBin() == true
|
||||||
menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 && !isInRecycleBin
|
menu.findItem(R.id.cab_hide).isVisible = !isInRecycleBin && selectedItems.any { !it.isHidden() }
|
||||||
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 && !isInRecycleBin
|
menu.findItem(R.id.cab_unhide).isVisible = !isInRecycleBin && selectedItems.any { it.isHidden() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkFavoriteBtnVisibility(menu: Menu, selectedItems: ArrayList<Medium>) {
|
private fun checkFavoriteBtnVisibility(menu: Menu, selectedItems: ArrayList<Medium>) {
|
||||||
var favoriteCnt = 0
|
menu.findItem(R.id.cab_add_to_favorites).isVisible = selectedItems.any { !it.isFavorite }
|
||||||
var nonFavoriteCnt = 0
|
menu.findItem(R.id.cab_remove_from_favorites).isVisible = selectedItems.any { it.isFavorite }
|
||||||
selectedItems.forEach {
|
|
||||||
if (it.isFavorite) {
|
|
||||||
favoriteCnt++
|
|
||||||
} else {
|
|
||||||
nonFavoriteCnt++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
menu.findItem(R.id.cab_add_to_favorites).isVisible = nonFavoriteCnt > 0
|
|
||||||
menu.findItem(R.id.cab_remove_from_favorites).isVisible = favoriteCnt > 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun confirmSelection() {
|
private fun confirmSelection() {
|
||||||
|
|
Loading…
Reference in a new issue