add a Select All button

This commit is contained in:
tibbi 2017-06-20 20:39:13 +02:00
parent dc595c5a0e
commit 9d17c5a568
2 changed files with 16 additions and 3 deletions

View File

@ -56,11 +56,11 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
}
updateTitle(selectedPositions.size)
actMode?.invalidate()
}
fun updateTitle(cnt: Int) {
actMode?.title = "$cnt / ${mItems.size}"
actMode?.invalidate()
}
init {
@ -86,6 +86,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
R.id.cab_share -> shareFiles()
R.id.cab_copy_to -> copyMoveTo(true)
R.id.cab_move_to -> copyMoveTo(false)
R.id.cab_select_all -> selectAll()
R.id.cab_delete -> askConfirmDelete()
else -> return false
}
@ -168,6 +169,15 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
}
}
fun selectAll() {
val cnt = mItems.size
for (i in 0..cnt - 1) {
selectedPositions.add(i)
notifyItemChanged(i)
}
updateTitle(cnt)
}
private fun askConfirmDelete() {
ConfirmationDialog(activity) {
deleteFiles()
@ -245,8 +255,6 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
item_name.setTextColor(textColor)
item_details.setTextColor(textColor)
// toggleItemSelection(this, selectedPositions.contains(pos), pos)
if (fileDirItem.isDirectory) {
item_icon.setImageDrawable(folderDrawable)
item_details.text = getChildrenCnt(fileDirItem)

View File

@ -24,6 +24,11 @@
android:id="@+id/cab_move_to"
android:title="@string/move_to"
app:showAsAction="never"/>
<item
android:id="@+id/cab_select_all"
android:icon="@drawable/ic_select_all"
android:title="@string/select_all"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_delete"
android:icon="@drawable/ic_delete"