Skip to content

Commit 5bfd3c0

Browse files
committed
Rename ChecklistItem to Task
1 parent 57f8f66 commit 5bfd3c0

File tree

12 files changed

+138
-138
lines changed

12 files changed

+138
-138
lines changed

app/src/main/kotlin/org/fossify/notes/activities/WidgetConfigureActivity.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import org.fossify.commons.helpers.PROTECTION_NONE
2020
import org.fossify.commons.helpers.ensureBackgroundThread
2121
import org.fossify.commons.models.RadioItem
2222
import org.fossify.notes.R
23-
import org.fossify.notes.adapters.ChecklistAdapter
23+
import org.fossify.notes.adapters.TasksAdapter
2424
import org.fossify.notes.databinding.WidgetConfigBinding
2525
import org.fossify.notes.extensions.config
2626
import org.fossify.notes.extensions.getPercentageFontSize
2727
import org.fossify.notes.extensions.widgetsDB
2828
import org.fossify.notes.helpers.*
29-
import org.fossify.notes.models.ChecklistItem
3029
import org.fossify.notes.models.Note
3130
import org.fossify.notes.models.NoteType
31+
import org.fossify.notes.models.Task
3232
import org.fossify.notes.models.Widget
3333

3434
class WidgetConfigureActivity : SimpleActivity() {
@@ -159,19 +159,19 @@ class WidgetConfigureActivity : SimpleActivity() {
159159
binding.notesPickerValue.text = note.title
160160
binding.textNoteViewTitle.text = note.title
161161
if (note.type == NoteType.TYPE_CHECKLIST) {
162-
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
163-
val items = Gson().fromJson<ArrayList<ChecklistItem>>(note.value, checklistItemType) ?: ArrayList(1)
162+
val taskType = object : TypeToken<List<Task>>() {}.type
163+
val items = Gson().fromJson<ArrayList<Task>>(note.value, taskType) ?: ArrayList(1)
164164
items.apply {
165165
if (isEmpty()) {
166-
add(ChecklistItem(0, System.currentTimeMillis(), "Milk", true))
167-
add(ChecklistItem(1, System.currentTimeMillis(), "Butter", true))
168-
add(ChecklistItem(2, System.currentTimeMillis(), "Salt", false))
169-
add(ChecklistItem(3, System.currentTimeMillis(), "Water", false))
170-
add(ChecklistItem(4, System.currentTimeMillis(), "Meat", true))
166+
add(Task(0, System.currentTimeMillis(), "Milk", true))
167+
add(Task(1, System.currentTimeMillis(), "Butter", true))
168+
add(Task(2, System.currentTimeMillis(), "Salt", false))
169+
add(Task(3, System.currentTimeMillis(), "Water", false))
170+
add(Task(4, System.currentTimeMillis(), "Meat", true))
171171
}
172172
}
173173

174-
ChecklistAdapter(this, null, binding.checklistNoteView).apply {
174+
TasksAdapter(this, null, binding.checklistNoteView).apply {
175175
updateTextColor(mTextColor)
176176
binding.checklistNoteView.adapter = this
177177
submitList(items.toList())
@@ -244,7 +244,7 @@ class WidgetConfigureActivity : SimpleActivity() {
244244
private fun updateTextColor() {
245245
binding.textNoteView.setTextColor(mTextColor)
246246
binding.textNoteViewTitle.setTextColor(mTextColor)
247-
(binding.checklistNoteView.adapter as? ChecklistAdapter)?.updateTextColor(mTextColor)
247+
(binding.checklistNoteView.adapter as? TasksAdapter)?.updateTextColor(mTextColor)
248248
binding.configTextColor.setFillWithStroke(mTextColor, mTextColor)
249249
binding.configSave.setTextColor(getProperPrimaryColor().getContrastColor())
250250
}

app/src/main/kotlin/org/fossify/notes/adapters/NotesPagerAdapter.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import android.view.ViewGroup
66
import androidx.fragment.app.FragmentManager
77
import androidx.fragment.app.FragmentStatePagerAdapter
88
import org.fossify.commons.extensions.showErrorToast
9-
import org.fossify.notes.fragments.ChecklistFragment
109
import org.fossify.notes.fragments.NoteFragment
10+
import org.fossify.notes.fragments.TasksFragment
1111
import org.fossify.notes.fragments.TextFragment
1212
import org.fossify.notes.helpers.NOTE_ID
1313
import org.fossify.notes.models.Note
@@ -30,7 +30,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
3030
return fragments[position]!!
3131
}
3232

33-
val fragment = if (note.type == NoteType.TYPE_TEXT) TextFragment() else ChecklistFragment()
33+
val fragment = if (note.type == NoteType.TYPE_TEXT) TextFragment() else TasksFragment()
3434
fragment.arguments = bundle
3535
fragments[position] = fragment
3636
return fragment
@@ -63,9 +63,9 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
6363

6464
fun saveAllFragmentTexts() = fragments.values.forEach { (it as? TextFragment)?.saveText(false) }
6565

66-
fun getNoteChecklistRawItems(position: Int) = (fragments[position] as? ChecklistFragment)?.items
66+
fun getNoteChecklistRawItems(position: Int) = (fragments[position] as? TasksFragment)?.tasks
6767

68-
fun getNoteChecklistItems(position: Int) = (fragments[position] as? ChecklistFragment)?.getChecklistItems()
68+
fun getNoteChecklistItems(position: Int) = (fragments[position] as? TasksFragment)?.getTasks()
6969

7070
fun undo(position: Int) = (fragments[position] as? TextFragment)?.undo()
7171

@@ -91,10 +91,10 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
9191
}
9292

9393
fun removeDoneCheckListItems(position: Int) {
94-
(fragments[position] as? ChecklistFragment)?.removeDoneItems()
94+
(fragments[position] as? TasksFragment)?.removeDoneItems()
9595
}
9696

9797
fun refreshChecklist(position: Int) {
98-
(fragments[position] as? ChecklistFragment)?.refreshItems()
98+
(fragments[position] as? TasksFragment)?.refreshItems()
9999
}
100100
}

app/src/main/kotlin/org/fossify/notes/adapters/OpenNoteAdapter.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import org.fossify.commons.views.MyRecyclerView
1919
import org.fossify.notes.R
2020
import org.fossify.notes.databinding.OpenNoteItemBinding
2121
import org.fossify.notes.extensions.config
22-
import org.fossify.notes.models.ChecklistItem
2322
import org.fossify.notes.models.Note
2423
import org.fossify.notes.models.NoteType
24+
import org.fossify.notes.models.Task
2525

2626
class OpenNoteAdapter(
2727
activity: BaseSimpleActivity,
@@ -122,12 +122,12 @@ class OpenNoteAdapter(
122122
return when (type) {
123123
NoteType.TYPE_TEXT -> getNoteStoredValue(context)
124124
NoteType.TYPE_CHECKLIST -> {
125-
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
126-
var items = Gson().fromJson<List<ChecklistItem>>(getNoteStoredValue(context), checklistItemType) ?: listOf()
125+
val taskType = object : TypeToken<List<Task>>() {}.type
126+
var items = Gson().fromJson<List<Task>>(getNoteStoredValue(context), taskType) ?: listOf()
127127
items = items.let {
128128
val sorting = context.config.sorting
129-
ChecklistItem.sorting = sorting
130-
if (ChecklistItem.sorting and SORT_BY_CUSTOM == 0) {
129+
Task.sorting = sorting
130+
if (Task.sorting and SORT_BY_CUSTOM == 0) {
131131
it.sorted().let {
132132
if (context.config.moveDoneChecklistItems) {
133133
it.sortedBy { it.isDone }

app/src/main/kotlin/org/fossify/notes/adapters/ChecklistAdapter.kt renamed to app/src/main/kotlin/org/fossify/notes/adapters/TasksAdapter.kt

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ import org.fossify.commons.interfaces.StartReorderDragListener
2323
import org.fossify.commons.views.MyRecyclerView
2424
import org.fossify.notes.R
2525
import org.fossify.notes.databinding.ItemChecklistBinding
26-
import org.fossify.notes.dialogs.RenameChecklistItemDialog
26+
import org.fossify.notes.dialogs.EditTaskDialog
2727
import org.fossify.notes.extensions.config
2828
import org.fossify.notes.extensions.getPercentageFontSize
2929
import 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
3232
import 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

app/src/main/kotlin/org/fossify/notes/adapters/WidgetAdapter.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import org.fossify.notes.extensions.config
1818
import org.fossify.notes.extensions.getPercentageFontSize
1919
import org.fossify.notes.extensions.notesDB
2020
import org.fossify.notes.helpers.*
21-
import org.fossify.notes.models.ChecklistItem
2221
import org.fossify.notes.models.Note
2322
import org.fossify.notes.models.NoteType
23+
import org.fossify.notes.models.Task
2424

2525
class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
2626
private val textIds = arrayOf(
@@ -33,7 +33,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
3333
)
3434
private var widgetTextColor = DEFAULT_WIDGET_TEXT_COLOR
3535
private var note: Note? = null
36-
private var checklistItems = mutableListOf<ChecklistItem>()
36+
private var tasks = mutableListOf<Task>()
3737

3838
override fun getViewAt(position: Int): RemoteViews {
3939
val noteId = intent.getLongExtra(NOTE_ID, 0L)
@@ -46,7 +46,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
4646
val textSize = context.getPercentageFontSize() / context.resources.displayMetrics.density
4747
if (note!!.type == NoteType.TYPE_CHECKLIST) {
4848
remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply {
49-
val checklistItem = checklistItems.getOrNull(position) ?: return@apply
49+
val checklistItem = tasks.getOrNull(position) ?: return@apply
5050
val widgetNewTextColor = if (checklistItem.isDone) widgetTextColor.adjustAlpha(DONE_CHECKLIST_ITEM_ALPHA) else widgetTextColor
5151
val paintFlags = if (checklistItem.isDone) Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG else Paint.ANTI_ALIAS_FLAG
5252

@@ -125,15 +125,15 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
125125
val noteId = intent.getLongExtra(NOTE_ID, 0L)
126126
note = context.notesDB.getNoteWithId(noteId)
127127
if (note?.type == NoteType.TYPE_CHECKLIST) {
128-
checklistItems = note!!.getNoteStoredValue(context)?.ifEmpty { "[]" }?.let { Json.decodeFromString(it) } ?: mutableListOf()
128+
tasks = note!!.getNoteStoredValue(context)?.ifEmpty { "[]" }?.let { Json.decodeFromString(it) } ?: mutableListOf()
129129

130130
// checklist title can be null only because of the glitch in upgrade to 6.6.0, remove this check in the future
131-
checklistItems = checklistItems.toMutableList() as ArrayList<ChecklistItem>
131+
tasks = tasks.toMutableList() as ArrayList<Task>
132132
val sorting = context.config.sorting
133133
if (sorting and SORT_BY_CUSTOM == 0) {
134-
checklistItems.sort()
134+
tasks.sort()
135135
if (context.config.moveDoneChecklistItems) {
136-
checklistItems.sortBy { it.isDone }
136+
tasks.sortBy { it.isDone }
137137
}
138138
}
139139
}
@@ -143,7 +143,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
143143

144144
override fun getCount(): Int {
145145
return if (note?.type == NoteType.TYPE_CHECKLIST) {
146-
checklistItems.size
146+
tasks.size
147147
} else {
148148
1
149149
}

app/src/main/kotlin/org/fossify/notes/dialogs/RenameChecklistItemDialog.kt renamed to app/src/main/kotlin/org/fossify/notes/dialogs/EditTaskDialog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import android.content.DialogInterface.BUTTON_POSITIVE
55
import org.fossify.commons.extensions.*
66
import org.fossify.notes.databinding.DialogRenameChecklistItemBinding
77

8-
class RenameChecklistItemDialog(val activity: Activity, val oldTitle: String, callback: (newTitle: String) -> Unit) {
8+
class EditTaskDialog(val activity: Activity, val oldTitle: String, callback: (newTitle: String) -> Unit) {
99
init {
1010
val binding = DialogRenameChecklistItemBinding.inflate(activity.layoutInflater).apply {
1111
checklistItemTitle.setText(oldTitle)

0 commit comments

Comments
 (0)