From 3689793f91a2b863d576c043e91b797aca7867b3 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Fri, 31 Jul 2020 14:40:29 -0500 Subject: [PATCH] Move some save work to background --- .../java/com/todoroo/astrid/dao/TaskDao.kt | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/todoroo/astrid/dao/TaskDao.kt b/app/src/main/java/com/todoroo/astrid/dao/TaskDao.kt index fe26b8201..f5ae5433c 100644 --- a/app/src/main/java/com/todoroo/astrid/dao/TaskDao.kt +++ b/app/src/main/java/com/todoroo/astrid/dao/TaskDao.kt @@ -9,6 +9,9 @@ import com.todoroo.astrid.api.Filter import com.todoroo.astrid.data.Task import com.todoroo.astrid.reminders.ReminderService import com.todoroo.astrid.timers.TimerPlugin +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch import org.tasks.LocalBroadcastManager import org.tasks.data.SubtaskInfo import org.tasks.data.TaskContainer @@ -91,25 +94,28 @@ class TaskDao @Inject constructor( if (justCompleted && (task.isRecurring || !task.calendarURI.isNullOrBlank())) { workManager.afterComplete(task) } - - if (justCompleted || justDeleted) { - notificationManager.cancel(task.id) - if (task.timerStart > 0) { - timerPlugin.stopTimer(task) + coroutineScope { + launch(Dispatchers.Default) { + if (justCompleted || justDeleted) { + notificationManager.cancel(task.id) + if (task.timerStart > 0) { + timerPlugin.stopTimer(task) + } + } + if (task.dueDate != original?.dueDate && newDateTime(task.dueDate).isAfterNow) { + notificationManager.cancel(task.id) + } + if (completionDateModified || deletionDateModified) { + geofenceApi.update(task.id) + } + reminderService.scheduleAlarm(task) + refreshScheduler.scheduleRefresh(task) + if (!task.checkTransitory(Task.TRANS_SUPPRESS_REFRESH)) { + localBroadcastManager.broadcastRefresh() + } + syncAdapters.sync(task, original) } } - if (task.dueDate != original?.dueDate && newDateTime(task.dueDate).isAfterNow) { - notificationManager.cancel(task.id) - } - if (completionDateModified || deletionDateModified) { - geofenceApi.update(task.id) - } - reminderService.scheduleAlarm(task) - refreshScheduler.scheduleRefresh(task) - if (!task.checkTransitory(Task.TRANS_SUPPRESS_REFRESH)) { - localBroadcastManager.broadcastRefresh() - } - syncAdapters.sync(task, original) } }