@@ -14,16 +14,15 @@ import androidx.lifecycle.lifecycleScope
1414import com.edricchan.studybuddy.exts.android.showToast
1515import com.edricchan.studybuddy.exts.datetime.format
1616import com.edricchan.studybuddy.exts.datetime.toLocalDateTime
17- import com.edricchan.studybuddy.exts.firebase.toLocalDateTime
1817import com.edricchan.studybuddy.exts.firebase.toTimestamp
1918import com.edricchan.studybuddy.exts.material.picker.setCalendarConstraints
2019import com.edricchan.studybuddy.exts.material.picker.setSelection
2120import com.edricchan.studybuddy.exts.material.picker.setStart
2221import com.edricchan.studybuddy.exts.material.picker.showMaterialDatePicker
2322import com.edricchan.studybuddy.exts.material.textfield.editTextStrValue
2423import com.edricchan.studybuddy.features.tasks.R
25- import com.edricchan.studybuddy.features.tasks.data.model.TodoItem
2624import com.edricchan.studybuddy.features.tasks.databinding.FragEditTaskBinding
25+ import com.edricchan.studybuddy.features.tasks.domain.model.TaskItem
2726import com.edricchan.studybuddy.features.tasks.edit.vm.EditTaskViewModel
2827import com.edricchan.studybuddy.features.tasks.edit.vm.EditTaskViewModel.TaskState
2928import com.edricchan.studybuddy.ui.common.fragment.ViewBindingFragment
@@ -48,7 +47,7 @@ class EditTaskFragment : ViewBindingFragment<FragEditTaskBinding>(FragEditTaskBi
4847 lateinit var auth: FirebaseAuth
4948
5049 private var taskInstant: Instant ? = null
51- private lateinit var todoItem : TodoItem
50+ private lateinit var taskItem : TaskItem
5251
5352 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
5453 super .onViewCreated(view, savedInstanceState)
@@ -126,12 +125,12 @@ class EditTaskFragment : ViewBindingFragment<FragEditTaskBinding>(FragEditTaskBi
126125 is TaskState .Success -> binding.apply {
127126 progressBar.isVisible = false
128127 scrollView.isVisible = true
129- todoItem = state.item
130- with (todoItem ) {
131- title?. let { textInputTitle.editText?.setText(it) }
128+ taskItem = state.item
129+ with (taskItem ) {
130+ textInputTitle.editText?.setText(title)
132131 content?.let { textInputContent.editText?.setText(it) }
133- done?. let { checkboxMarkAsDone.isChecked = it }
134- taskInstant = dueDate?.toInstant()
132+ checkboxMarkAsDone.isChecked = isCompleted
133+ taskInstant = dueDate
135134 dueDate?.let {
136135 // We need to convert it to a LocalDateTime as Instants don't support
137136 // temporal units bigger than days - see the `Instant#isSupported` Javadocs
@@ -161,27 +160,27 @@ class EditTaskFragment : ViewBindingFragment<FragEditTaskBinding>(FragEditTaskBi
161160
162161 override fun onMenuItemSelected (menuItem : MenuItem ): Boolean {
163162 if (menuItem.itemId == R .id.action_save) {
164- val taskItemUpdates = buildMap<TodoItem .Field , Any > {
163+ val taskItemUpdates = buildMap<TaskItem .Field , Any > {
165164 binding.also {
166- if (it.textInputTitle.editTextStrValue != todoItem .title) {
167- this [TodoItem .Field .Title ] = it.textInputTitle.editTextStrValue
165+ if (it.textInputTitle.editTextStrValue != taskItem .title) {
166+ this [TaskItem .Field .Title ] = it.textInputTitle.editTextStrValue
168167 }
169- if (it.textInputContent.editTextStrValue != todoItem .content) {
170- this [TodoItem .Field .Content ] = it.textInputContent.editTextStrValue
168+ if (it.textInputContent.editTextStrValue != taskItem .content) {
169+ this [TaskItem .Field .Content ] = it.textInputContent.editTextStrValue
171170 }
172- this [TodoItem .Field .IsDone ] = it.checkboxMarkAsDone.isChecked
173- this [TodoItem .Field .Tags ] = it.textInputTags.editTextStrValue.split(
171+ this [TaskItem .Field .IsCompleted ] = it.checkboxMarkAsDone.isChecked
172+ this [TaskItem .Field .Tags ] = it.textInputTags.editTextStrValue.split(
174173 Regex (""" \s*,\s*""" )
175174 ).filter(String ::isNotBlank)
176175 }
177176 taskInstant?.let {
178- if (todoItem .dueDate?.toInstant() != it) {
179- this [TodoItem .Field .DueDate ] = it.toTimestamp()
177+ if (taskItem .dueDate != it) {
178+ this [TaskItem .Field .DueDate ] = it.toTimestamp()
180179 }
181180 // When taskInstant is set to null, this means that the user
182181 // wants to clear the due-date of the item
183182 } ? : run {
184- this [TodoItem .Field .DueDate ] = FieldValue .delete()
183+ this [TaskItem .Field .DueDate ] = FieldValue .delete()
185184 }
186185 }
187186
0 commit comments