Make hasChanges and apply suspending

pull/1043/head
Alex Baker 4 years ago
parent 3418ea7f3c
commit 968ec62acb

@ -302,7 +302,7 @@ public final class TaskEditFragment extends Fragment
}
for (TaskEditControlFragment fragment :
filter(fragments, not(TaskEditControlFragment::requiresId))) {
fragment.apply(model);
fragment.applyBlocking(model);
}
Completable.fromAction(
@ -315,7 +315,7 @@ public final class TaskEditFragment extends Fragment
for (TaskEditControlFragment fragment :
filter(fragments, TaskEditControlFragment::requiresId)) {
fragment.apply(model);
fragment.applyBlocking(model);
}
taskDao.save(model, null);
@ -375,7 +375,7 @@ public final class TaskEditFragment extends Fragment
try {
for (TaskEditControlFragment fragment : fragments) {
if (fragment.hasChanges(model)) {
if (fragment.hasChangesBlocking(model)) {
return true;
}
}

@ -75,7 +75,7 @@ class FilesControlSet : TaskEditControlFragment() {
override fun controlId() = TAG
override fun apply(task: Task) {}
override suspend fun apply(task: Task) {}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == AddAttachmentDialog.REQUEST_CAMERA || requestCode == AddAttachmentDialog.REQUEST_AUDIO) {

@ -174,13 +174,13 @@ class RepeatControlSet : TaskEditControlFragment() {
override fun controlId() = TAG
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
val repeatUntil = rrule?.let { DateTime.from(it.until).millis } ?: 0
return recurrenceValue != original.recurrence.orEmpty()
|| original.repeatUntil != repeatUntil
}
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
task.repeatUntil = if (rrule == null) 0 else DateTime.from(rrule!!.until).millis
task.recurrence = recurrenceValue
}

@ -74,7 +74,7 @@ class TagsControlSet : TaskEditControlFragment() {
override val layout: Int
get() = R.layout.control_set_tags
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
if (tagDao.applyTags(task, tagDataDao, selectedTags)) {
task.modificationDate = DateUtilities.now()
}
@ -94,7 +94,7 @@ class TagsControlSet : TaskEditControlFragment() {
override fun controlId() = TAG
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
return HashSet(originalTags) != HashSet(selectedTags)
}

@ -136,12 +136,12 @@ class TimerControlSet : TaskEditControlFragment() {
override fun controlId() = TAG
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
return (elapsed.timeDurationInSeconds != original.elapsedSeconds
|| estimated.timeDurationInSeconds != original.estimatedSeconds)
}
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
task.elapsedSeconds = elapsed.timeDurationInSeconds
task.estimatedSeconds = estimated.timeDurationInSeconds
}

@ -162,11 +162,11 @@ class HideUntilControlSet : TaskEditControlFragment(), OnItemSelectedListener {
}
}
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
task.hideUntil = getHideUntil(task)
}
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
return original.hideUntil != getHideUntil(original)
}

@ -167,13 +167,13 @@ class ReminderControlSet : TaskEditControlFragment() {
}
}
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
return getFlags() != original.reminderFlags || randomReminderPeriod != original.reminderPeriod || HashSet(currentAlarms()) != alarms
}
override fun requiresId() = true
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
task.reminderFlags = getFlags()
task.reminderPeriod = randomReminderPeriod
if (alarmService.synchronizeAlarms(task.id, alarms)) {

@ -88,7 +88,7 @@ class CommentBarFragment : TaskEditControlFragment() {
override fun controlId() = TAG
override fun apply(task: Task) {}
override suspend fun apply(task: Task) {}
@OnTextChanged(R.id.commentField)
fun onTextChanged(s: CharSequence) {

@ -92,7 +92,7 @@ class CalendarControlSet : TaskEditControlFragment() {
override fun controlId() = TAG
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
if (!permissionChecker.canAccessCalendars()) {
return false
}
@ -105,7 +105,7 @@ class CalendarControlSet : TaskEditControlFragment() {
} else originalUri != eventUri
}
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
if (!permissionChecker.canAccessCalendars()) {
return
}

@ -71,11 +71,11 @@ class DeadlineControlSet : TaskEditControlFragment() {
override fun controlId() = TAG
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
return original.dueDate != dueDateTime
}
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
val dueDate = dueDateTime
if (dueDate != task.dueDate) {
task.reminderSnooze = 0L

@ -60,11 +60,11 @@ class DescriptionControlSet : TaskEditControlFragment() {
description = text.toString().trim { it <= ' ' }
}
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
task.notes = description
}
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
return !if (isNullOrEmpty(description)) isNullOrEmpty(original.notes) else description == stripCarriageReturns(original.notes)
}

@ -119,14 +119,14 @@ class ListFragment : TaskEditControlFragment() {
override fun requiresId() = true
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
if (isNew || hasChanges()) {
task.parent = 0
taskMover.move(listOf(task.id), selectedList)
}
}
override fun hasChanges(original: Task) = hasChanges()
override suspend fun hasChanges(original: Task) = hasChanges()
private fun hasChanges() = selectedList != originalList

@ -202,7 +202,7 @@ class LocationControlSet : TaskEditControlFragment() {
startActivity(Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + location!!.phone)))
}
override fun hasChanges(task: Task): Boolean {
override suspend fun hasChanges(task: Task): Boolean {
if (original == null) {
return location != null
}
@ -220,7 +220,7 @@ class LocationControlSet : TaskEditControlFragment() {
override fun requiresId() = true
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
if (original == null || location == null || original!!.place != location!!.place) {
task.putTransitory(SyncFlags.FORCE_CALDAV_SYNC, true)
}

@ -68,11 +68,11 @@ class PriorityControlSet : TaskEditControlFragment() {
override fun controlId() = TAG
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
task.priority = priority
}
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
return original.priority != priority
}

@ -109,7 +109,7 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks
override fun requiresId() = true
override fun apply(task: Task) {
override suspend fun apply(task: Task) {
for (subtask in newSubtasks) {
if (isNullOrEmpty(subtask.title)) {
continue
@ -138,7 +138,7 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks
}
}
override fun hasChanges(original: Task): Boolean {
override suspend fun hasChanges(original: Task): Boolean {
return newSubtasks.isNotEmpty()
}

@ -10,6 +10,7 @@ import android.widget.LinearLayout
import androidx.fragment.app.Fragment
import butterknife.ButterKnife
import com.todoroo.astrid.data.Task
import kotlinx.coroutines.runBlocking
import org.tasks.R
abstract class TaskEditControlFragment : Fragment() {
@ -50,9 +51,19 @@ abstract class TaskEditControlFragment : Fragment() {
return false
}
abstract fun apply(task: Task)
@Deprecated("use coroutines")
fun applyBlocking(task: Task) = runBlocking {
apply(task)
}
abstract suspend fun apply(task: Task)
@Deprecated("use coroutines")
fun hasChangesBlocking(original: Task) = runBlocking {
hasChanges(original)
}
open fun hasChanges(original: Task): Boolean {
open suspend fun hasChanges(original: Task): Boolean {
return false
}

Loading…
Cancel
Save