@@ -23,21 +23,21 @@ import org.fossify.commons.interfaces.StartReorderDragListener
2323import org.fossify.commons.views.MyRecyclerView
2424import org.fossify.notes.R
2525import org.fossify.notes.databinding.ItemChecklistBinding
26- import org.fossify.notes.dialogs.RenameChecklistItemDialog
26+ import org.fossify.notes.dialogs.EditTaskDialog
2727import org.fossify.notes.extensions.config
2828import org.fossify.notes.extensions.getPercentageFontSize
2929import org.fossify.notes.helpers.DONE_CHECKLIST_ITEM_ALPHA
30- import org.fossify.notes.interfaces.ChecklistItemsListener
31- import org.fossify.notes.models.ChecklistItem
30+ import org.fossify.notes.interfaces.TasksActionListener
31+ import org.fossify.notes.models.Task
3232import java.util.Collections
3333
34- class ChecklistAdapter (
34+ class TasksAdapter (
3535 activity : BaseSimpleActivity ,
36- val listener : ChecklistItemsListener ? ,
36+ val listener : TasksActionListener ? ,
3737 recyclerView : MyRecyclerView ,
3838 itemClick : (Any ) -> Unit = {},
39- ) : MyRecyclerViewListAdapter<ChecklistItem >(
40- activity = activity, recyclerView = recyclerView, diffUtil = ChecklistItemDiffUtil (), itemClick = itemClick
39+ ) : MyRecyclerViewListAdapter<Task >(
40+ activity = activity, recyclerView = recyclerView, diffUtil = TaskDiffCallback (), itemClick = itemClick
4141), ItemTouchHelperContract {
4242
4343 private var touchHelper: ItemTouchHelper ? = null
@@ -111,72 +111,72 @@ class ChecklistAdapter(
111111 }
112112
113113 private fun renameChecklistItem () {
114- val item = getSelectedItems().first()
115- RenameChecklistItemDialog (activity, item .title) { title ->
116- val items = currentList.toMutableList()
117- items [getSelectedItemPositions().first()] = item .copy(title = title)
118- saveChecklist(items )
114+ val task = getSelectedItems().first()
115+ EditTaskDialog (activity, task .title) { title ->
116+ val tasks = currentList.toMutableList()
117+ tasks [getSelectedItemPositions().first()] = task .copy(title = title)
118+ saveTasks(tasks )
119119 finishActMode()
120120 }
121121 }
122122
123123 private fun deleteSelection () {
124- val items = currentList.toMutableList()
125- val itemsToRemove = ArrayList <ChecklistItem >(selectedKeys.size)
124+ val tasks = currentList.toMutableList()
125+ val tasksToRemove = ArrayList <Task >(selectedKeys.size)
126126 selectedKeys.forEach { key ->
127- val position = items .indexOfFirst { it.id == key }
127+ val position = tasks .indexOfFirst { it.id == key }
128128 if (position != - 1 ) {
129129 val favorite = getItemWithKey(key)
130130 if (favorite != null ) {
131- itemsToRemove .add(favorite)
131+ tasksToRemove .add(favorite)
132132 }
133133 }
134134 }
135135
136- items .removeAll(itemsToRemove .toSet())
137- saveChecklist(items )
136+ tasks .removeAll(tasksToRemove .toSet())
137+ saveTasks(tasks )
138138 }
139139
140140 private fun moveSelectedItemsToTop () {
141141 activity.config.sorting = SORT_BY_CUSTOM
142- val items = currentList.toMutableList()
143- selectedKeys.reversed().forEach { checklistId ->
144- val position = items .indexOfFirst { it.id == checklistId }
145- val tempItem = items [position]
146- items .removeAt(position)
147- items .add(0 , tempItem)
142+ val tasks = currentList.toMutableList()
143+ selectedKeys.reversed().forEach { id ->
144+ val position = tasks .indexOfFirst { it.id == id }
145+ val tempItem = tasks [position]
146+ tasks .removeAt(position)
147+ tasks .add(0 , tempItem)
148148 }
149149
150- saveChecklist(items )
150+ saveTasks(tasks )
151151 }
152152
153153 private fun moveSelectedItemsToBottom () {
154154 activity.config.sorting = SORT_BY_CUSTOM
155- val items = currentList.toMutableList()
156- selectedKeys.forEach { checklistId ->
157- val position = items .indexOfFirst { it.id == checklistId }
158- val tempItem = items [position]
159- items .removeAt(position)
160- items .add(items .size, tempItem)
155+ val tasks = currentList.toMutableList()
156+ selectedKeys.forEach { id ->
157+ val position = tasks .indexOfFirst { it.id == id }
158+ val tempItem = tasks [position]
159+ tasks .removeAt(position)
160+ tasks .add(tasks .size, tempItem)
161161 }
162162
163- saveChecklist(items )
163+ saveTasks(tasks )
164164 }
165165
166- private fun getItemWithKey (key : Int ): ChecklistItem ? = currentList.firstOrNull { it.id == key }
166+ private fun getItemWithKey (key : Int ): Task ? = currentList.firstOrNull { it.id == key }
167167
168168 private fun getSelectedItems () = currentList.filter { selectedKeys.contains(it.id) }.toMutableList()
169169
170- private fun setupView (view : View , checklistItem : ChecklistItem , holder : ViewHolder ) {
171- val isSelected = selectedKeys.contains(checklistItem .id)
170+ private fun setupView (view : View , task : Task , holder : ViewHolder ) {
171+ val isSelected = selectedKeys.contains(task .id)
172172 ItemChecklistBinding .bind(view).apply {
173173 checklistTitle.apply {
174- text = checklistItem .title
174+ text = task .title
175175 setTextColor(textColor)
176176 setTextSize(TypedValue .COMPLEX_UNIT_PX , context.getPercentageFontSize())
177177 gravity = context.config.getTextGravity()
178178
179- if (checklistItem .isDone) {
179+ if (task .isDone) {
180180 paintFlags = paintFlags or Paint .STRIKE_THRU_TEXT_FLAG
181181 alpha = DONE_CHECKLIST_ITEM_ALPHA
182182 } else {
@@ -185,7 +185,7 @@ class ChecklistAdapter(
185185 }
186186 }
187187
188- checklistCheckbox.isChecked = checklistItem .isDone
188+ checklistCheckbox.isChecked = task .isDone
189189 checklistHolder.isSelected = isSelected
190190
191191 checklistDragHandle.beVisibleIf(selectedKeys.isNotEmpty())
@@ -201,42 +201,42 @@ class ChecklistAdapter(
201201
202202 override fun onRowMoved (fromPosition : Int , toPosition : Int ) {
203203 activity.config.sorting = SORT_BY_CUSTOM
204- val items = currentList.toMutableList()
204+ val tasks = currentList.toMutableList()
205205 if (fromPosition < toPosition) {
206206 for (i in fromPosition until toPosition) {
207- Collections .swap(items , i, i + 1 )
207+ Collections .swap(tasks , i, i + 1 )
208208 }
209209 } else {
210210 for (i in fromPosition downTo toPosition + 1 ) {
211- Collections .swap(items , i, i - 1 )
211+ Collections .swap(tasks , i, i - 1 )
212212 }
213213 }
214214
215- saveChecklist(items )
215+ saveTasks(tasks )
216216 }
217217
218218 override fun onRowSelected (myViewHolder : MyRecyclerViewAdapter .ViewHolder ? ) {}
219219
220220 override fun onRowClear (myViewHolder : MyRecyclerViewAdapter .ViewHolder ? ) {
221- saveChecklist (currentList.toList())
221+ saveTasks (currentList.toList())
222222 }
223223
224- private fun saveChecklist ( items : List <ChecklistItem >) {
225- listener?.saveChecklist(items ) {
224+ private fun saveTasks ( tasks : List <Task >) {
225+ listener?.saveTasks(tasks ) {
226226 listener.refreshItems()
227227 }
228228 }
229229}
230230
231- private class ChecklistItemDiffUtil : DiffUtil .ItemCallback <ChecklistItem >() {
231+ private class TaskDiffCallback : DiffUtil .ItemCallback <Task >() {
232232 override fun areItemsTheSame (
233- oldItem : ChecklistItem ,
234- newItem : ChecklistItem
233+ oldItem : Task ,
234+ newItem : Task
235235 ) = oldItem.id == newItem.id
236236
237237 override fun areContentsTheSame (
238- oldItem : ChecklistItem ,
239- newItem : ChecklistItem
238+ oldItem : Task ,
239+ newItem : Task
240240 ) = oldItem.id == newItem.id
241241 && oldItem.isDone == newItem.isDone
242242 && oldItem.title == newItem.title
0 commit comments