show an Edit button if there is only 1 item selected

This commit is contained in:
tibbi 2016-08-17 23:21:44 +02:00
parent 7e6edc20e6
commit 884e22d67e
3 changed files with 16 additions and 0 deletions

View File

@ -28,6 +28,9 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
val deleteMode = object : ModalMultiSelectorCallback(multiSelector) {
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.cab_edit -> {
}
R.id.cab_delete -> {
val positions = multiSelector.selectedPositions
val deleteIds = ArrayList<String>(positions.size)
@ -51,6 +54,12 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
act.menuInflater.inflate(R.menu.cab, menu)
return true
}
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
val menuItem = menu?.findItem(R.id.cab_edit)
menuItem?.isVisible = multiSelector.selectedPositions.size == 1
return true
}
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -112,6 +121,7 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
} else {
actMode?.title = selectedCnt.toString()
}
actMode?.invalidate()
} else {
itemClick(appLauncher)
}

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/cab_edit"
android:icon="@mipmap/edit"
android:title="@string/edit"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_delete"
android:icon="@mipmap/delete"

View File

@ -1,6 +1,7 @@
<resources>
<string name="app_name">Simple App Launcher</string>
<string name="delete">Delete</string>
<string name="edit">Edit</string>
<!-- About -->
<string name="about">About</string>