mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-14 07:22:01 +02:00
display the checklist items on the recycler view
This commit is contained in:
parent
c4ab67b2df
commit
f34ce020bb
@ -0,0 +1,58 @@
|
||||
package com.simplemobiletools.notes.pro.adapters
|
||||
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.models.ChecklistItem
|
||||
import kotlinx.android.synthetic.main.item_checklist.view.*
|
||||
import java.util.*
|
||||
|
||||
class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<ChecklistItem>, val listener: RefreshRecyclerViewListener?,
|
||||
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
init {
|
||||
setupDragListener(true)
|
||||
}
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab_delete_only
|
||||
|
||||
override fun actionItemPressed(id: Int) {}
|
||||
|
||||
override fun getSelectableItemCount() = items.size
|
||||
|
||||
override fun getIsItemSelectable(position: Int) = true
|
||||
|
||||
override fun getItemSelectionKey(position: Int) = items.getOrNull(position)?.id
|
||||
|
||||
override fun getItemKeyPosition(key: Int) = items.indexOfFirst { it.id == key }
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_checklist, parent)
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = items[position]
|
||||
holder.bindView(item, true, true) { itemView, layoutPosition ->
|
||||
setupView(itemView, item)
|
||||
}
|
||||
bindViewHolder(holder)
|
||||
}
|
||||
|
||||
override fun getItemCount() = items.size
|
||||
|
||||
private fun setupView(view: View, checklistItem: ChecklistItem) {
|
||||
val isSelected = selectedKeys.contains(checklistItem.id)
|
||||
view.apply {
|
||||
checklist_title.apply {
|
||||
text = checklistItem.title
|
||||
setTextColor(textColor)
|
||||
}
|
||||
checklist_holder.isSelected = isSelected
|
||||
}
|
||||
}
|
||||
}
|
@ -6,8 +6,10 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.adapters.ChecklistAdapter
|
||||
import com.simplemobiletools.notes.pro.dialogs.NewChecklistItemDialog
|
||||
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
|
||||
import com.simplemobiletools.notes.pro.helpers.NotesHelper
|
||||
@ -15,7 +17,7 @@ import com.simplemobiletools.notes.pro.models.ChecklistItem
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.fragment_checklist.view.*
|
||||
|
||||
class ChecklistFragment : NoteFragment() {
|
||||
class ChecklistFragment : NoteFragment(), RefreshRecyclerViewListener {
|
||||
private var noteId = 0L
|
||||
private var note: Note? = null
|
||||
private var items = ArrayList<ChecklistItem>()
|
||||
@ -53,10 +55,24 @@ class ChecklistFragment : NoteFragment() {
|
||||
background.applyColorFilter(context!!.getAdjustedPrimaryColor())
|
||||
setOnClickListener {
|
||||
NewChecklistItemDialog(activity as SimpleActivity) {
|
||||
val checklistItem = ChecklistItem(it, false)
|
||||
val currentMaxId = items.maxBy { it.id }?.id ?: 0
|
||||
val checklistItem = ChecklistItem(currentMaxId + 1, it, false)
|
||||
items.add(checklistItem)
|
||||
setupAdapter()
|
||||
}
|
||||
}
|
||||
}
|
||||
setupAdapter()
|
||||
}
|
||||
|
||||
private fun setupAdapter() {
|
||||
ChecklistAdapter(activity as SimpleActivity, items, this, view.checklist_list) {
|
||||
|
||||
}.apply {
|
||||
view.checklist_list.adapter = this
|
||||
}
|
||||
}
|
||||
|
||||
override fun refreshItems() {
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
package com.simplemobiletools.notes.pro.models
|
||||
|
||||
data class ChecklistItem(val title: String, val isDone: Boolean)
|
||||
data class ChecklistItem(val id: Int, val title: String, val isDone: Boolean)
|
||||
|
22
app/src/main/res/layout/item_checklist.xml
Normal file
22
app/src/main/res/layout/item_checklist.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/checklist_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="@drawable/selector"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/checklist_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="@dimen/medium_margin"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:layout_marginRight="@dimen/medium_margin"/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
x
Reference in New Issue
Block a user