show pin/unpin actionmenu item only when needed

This commit is contained in:
tibbi 2016-12-05 21:58:46 +01:00
parent 830f456359
commit e6585180c3
2 changed files with 35 additions and 23 deletions

View File

@ -108,24 +108,12 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
}
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean {
val menuItem = menu.findItem(R.id.cab_edit)
menuItem.isVisible = multiSelector.selectedPositions.size <= 1
var hiddenCnt = 0
var unhiddenCnt = 0
val positions = multiSelector.selectedPositions
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
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<Direc
views.forEach { toggleItemSelection(it, false) }
markedItems.clear()
}
fun checkHideBtnVisibility(menu: Menu, positions: List<Int>) {
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<Int>) {
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() {

View File

@ -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<Directory>): ArrayList<Directory> {
if (dirs.isEmpty())
return dirs
val foundFolders = ArrayList<Directory>()
val pinnedFolders = mConfig.pinnedFolders