mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-24 12:08:44 +02:00
toggle checklist item checked state on click
This commit is contained in:
parent
0babf17c63
commit
ddb5654b9f
@ -52,7 +52,7 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
|
|||||||
|
|
||||||
override fun getItemCount() = items.size
|
override fun getItemCount() = items.size
|
||||||
|
|
||||||
fun initDrawables() {
|
private fun initDrawables() {
|
||||||
val res = activity.resources
|
val res = activity.resources
|
||||||
crossDrawable = res.getColoredDrawableWithColor(R.drawable.ic_cross_big, res.getColor(R.color.theme_dark_red_primary_color))
|
crossDrawable = res.getColoredDrawableWithColor(R.drawable.ic_cross_big, res.getColor(R.color.theme_dark_red_primary_color))
|
||||||
checkDrawable = res.getColoredDrawableWithColor(R.drawable.ic_check_big, res.getColor(R.color.md_green_700))
|
checkDrawable = res.getColoredDrawableWithColor(R.drawable.ic_check_big, res.getColor(R.color.md_green_700))
|
||||||
|
@ -64,13 +64,7 @@ class ChecklistFragment : NoteFragment(), RefreshRecyclerViewListener {
|
|||||||
val currentMaxId = items.maxBy { it.id }?.id ?: 0
|
val currentMaxId = items.maxBy { it.id }?.id ?: 0
|
||||||
val checklistItem = ChecklistItem(currentMaxId + 1, it, false)
|
val checklistItem = ChecklistItem(currentMaxId + 1, it, false)
|
||||||
items.add(checklistItem)
|
items.add(checklistItem)
|
||||||
setupAdapter()
|
saveNote(-1)
|
||||||
Thread {
|
|
||||||
if (note != null && context != null) {
|
|
||||||
note!!.value = Gson().toJson(items)
|
|
||||||
context?.notesDB?.insertOrUpdate(note!!)
|
|
||||||
}
|
|
||||||
}.start()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,12 +73,29 @@ class ChecklistFragment : NoteFragment(), RefreshRecyclerViewListener {
|
|||||||
|
|
||||||
private fun setupAdapter() {
|
private fun setupAdapter() {
|
||||||
ChecklistAdapter(activity as SimpleActivity, items, this, view.checklist_list) {
|
ChecklistAdapter(activity as SimpleActivity, items, this, view.checklist_list) {
|
||||||
|
val clickedNote = it as ChecklistItem
|
||||||
|
clickedNote.isDone = !clickedNote.isDone
|
||||||
|
saveNote(items.indexOfFirst { it.id == clickedNote.id })
|
||||||
}.apply {
|
}.apply {
|
||||||
view.checklist_list.adapter = this
|
view.checklist_list.adapter = this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun saveNote(refreshIndex: Int) {
|
||||||
|
Thread {
|
||||||
|
if (note != null && context != null) {
|
||||||
|
if (refreshIndex != -1) {
|
||||||
|
view.checklist_list.post {
|
||||||
|
view.checklist_list.adapter?.notifyItemChanged(refreshIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
note!!.value = Gson().toJson(items)
|
||||||
|
context?.notesDB?.insertOrUpdate(note!!)
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
override fun refreshItems() {
|
override fun refreshItems() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user