mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-04 18:51:14 +02:00
add a cab button for editing checklist items
This commit is contained in:
parent
8bba5eb942
commit
451c7bb19f
app/src/main
@ -28,7 +28,7 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
|
||||
initDrawables()
|
||||
}
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab_delete_only
|
||||
override fun getActionMenuId() = R.menu.cab_checklist
|
||||
|
||||
override fun actionItemPressed(id: Int) {
|
||||
if (selectedKeys.isEmpty()) {
|
||||
@ -36,6 +36,7 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
|
||||
}
|
||||
|
||||
when (id) {
|
||||
R.id.cab_edit -> editNote()
|
||||
R.id.cab_delete -> deleteSelection()
|
||||
}
|
||||
}
|
||||
@ -48,7 +49,14 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
|
||||
|
||||
override fun getItemKeyPosition(key: Int) = items.indexOfFirst { it.id == key }
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
override fun prepareActionMode(menu: Menu) {
|
||||
val selectedItems = getSelectedItems()
|
||||
if (selectedItems.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
menu.findItem(R.id.cab_edit).isVisible = isOneItemSelected()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_checklist, parent)
|
||||
|
||||
@ -68,6 +76,10 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
|
||||
checkDrawable = res.getColoredDrawableWithColor(R.drawable.ic_check_big, res.getColor(R.color.md_green_700))
|
||||
}
|
||||
|
||||
private fun editNote() {
|
||||
|
||||
}
|
||||
|
||||
private fun deleteSelection() {
|
||||
val removeItems = ArrayList<ChecklistItem>(selectedKeys.size)
|
||||
val positions = ArrayList<Int>()
|
||||
@ -96,6 +108,8 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
|
||||
|
||||
private fun getItemWithKey(key: Int): ChecklistItem? = items.firstOrNull { it.id == key }
|
||||
|
||||
private fun getSelectedItems() = items.filter { selectedKeys.contains(it.id) } as ArrayList<ChecklistItem>
|
||||
|
||||
private fun setupView(view: View, checklistItem: ChecklistItem) {
|
||||
val isSelected = selectedKeys.contains(checklistItem.id)
|
||||
view.apply {
|
||||
|
14
app/src/main/res/menu/cab_checklist.xml
Normal file
14
app/src/main/res/menu/cab_checklist.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?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="@drawable/ic_edit"
|
||||
android:title="@string/rename"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/cab_delete"
|
||||
android:icon="@drawable/ic_delete"
|
||||
android:title="@string/delete"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
Loading…
x
Reference in New Issue
Block a user