add hide/unhide menu items to media activity cab

This commit is contained in:
tibbi 2017-04-26 20:23:04 +02:00
parent 0ee20b4604
commit 40c4a9aec1
2 changed files with 36 additions and 3 deletions

View File

@ -72,6 +72,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
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<Medium>,
}
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<Medium>,
markedItems.clear()
actMode = null
}
fun checkHideBtnVisibility(menu: Menu, positions: List<Int>) {
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<Medium>,
actMode?.finish()
}
private fun toggleFileVisibility(hide: Boolean) {
}
private fun shareMedia() {
val selections = multiSelector.selectedPositions
if (selections.size <= 1) {

View File

@ -21,6 +21,16 @@
android:icon="@drawable/ic_rename"
android:title="@string/rename"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_hide"
android:icon="@drawable/ic_hide"
android:title="@string/hide"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_unhide"
android:icon="@drawable/ic_unhide"
android:title="@string/unhide"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_edit"
android:icon="@drawable/ic_edit"