add hide/unhide menu items to media activity cab
This commit is contained in:
parent
0ee20b4604
commit
40c4a9aec1
2 changed files with 36 additions and 3 deletions
|
@ -72,6 +72,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
R.id.cab_properties -> showProperties()
|
R.id.cab_properties -> showProperties()
|
||||||
R.id.cab_rename -> renameFile()
|
R.id.cab_rename -> renameFile()
|
||||||
R.id.cab_edit -> editFile()
|
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_share -> shareMedia()
|
||||||
R.id.cab_copy_to -> copyMoveTo(true)
|
R.id.cab_copy_to -> copyMoveTo(true)
|
||||||
R.id.cab_move_to -> copyMoveTo(false)
|
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 {
|
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean {
|
||||||
val selections = multiSelector.selectedPositions
|
val positions = multiSelector.selectedPositions
|
||||||
menu.findItem(R.id.cab_rename).isVisible = selections.size <= 1
|
menu.findItem(R.id.cab_rename).isVisible = positions.size <= 1
|
||||||
menu.findItem(R.id.cab_edit).isVisible = selections.size == 1 && media[selections[0]].isImage()
|
menu.findItem(R.id.cab_edit).isVisible = positions.size == 1 && media[positions[0]].isImage()
|
||||||
|
|
||||||
|
checkHideBtnVisibility(menu, positions)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +107,20 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
markedItems.clear()
|
markedItems.clear()
|
||||||
actMode = null
|
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() {
|
private fun showProperties() {
|
||||||
|
@ -129,6 +148,10 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
actMode?.finish()
|
actMode?.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun toggleFileVisibility(hide: Boolean) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private fun shareMedia() {
|
private fun shareMedia() {
|
||||||
val selections = multiSelector.selectedPositions
|
val selections = multiSelector.selectedPositions
|
||||||
if (selections.size <= 1) {
|
if (selections.size <= 1) {
|
||||||
|
|
|
@ -21,6 +21,16 @@
|
||||||
android:icon="@drawable/ic_rename"
|
android:icon="@drawable/ic_rename"
|
||||||
android:title="@string/rename"
|
android:title="@string/rename"
|
||||||
app:showAsAction="ifRoom"/>
|
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
|
<item
|
||||||
android:id="@+id/cab_edit"
|
android:id="@+id/cab_edit"
|
||||||
android:icon="@drawable/ic_edit"
|
android:icon="@drawable/ic_edit"
|
||||||
|
|
Loading…
Reference in a new issue