Remove AfterSaveWork

pull/2744/head
Alex Baker 12 months ago
parent 457b89c092
commit db889d233a

@ -1,50 +1,68 @@
package com.todoroo.astrid.repeats
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.data.Task
import com.todoroo.astrid.service.TaskCompleter
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.tasks.data.TaskDao
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule
import org.tasks.makers.TaskMaker.COMPLETION_TIME
import org.tasks.makers.TaskMaker.PARENT
import org.tasks.makers.TaskMaker.RECUR
import org.tasks.makers.TaskMaker.newTask
import org.tasks.time.DateTime
import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class RepeatWithSubtasksTests : InjectingTestCase() {
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var repeat: RepeatTaskHelper
@Inject lateinit var taskCompleter: TaskCompleter
@Test
fun uncompleteGrandchildren() = runBlocking {
val grandparent = taskDao.createNew(newTask(with(RECUR, "RRULE:FREQ=DAILY")))
val parent = taskDao.createNew(newTask(with(PARENT, grandparent)))
val child = taskDao.createNew(newTask(
with(PARENT, parent),
with(COMPLETION_TIME, DateTime())
))
val grandparent = taskDao.createNew(
Task(
recurrence = "RRULE:FREQ=DAILY"
)
)
val parent = taskDao.createNew(
Task(
parent = grandparent
)
)
val child = taskDao.createNew(
Task(
parent = parent,
completionDate = now(),
)
)
repeat.handleRepeat(taskDao.fetch(grandparent)!!)
assertTrue(taskDao.fetch(child)!!.isCompleted)
taskCompleter.setComplete(grandparent)
assertFalse(taskDao.fetch(child)!!.isCompleted)
}
@Test
fun uncompleteGoogleTaskChildren() = runBlocking {
val parent = taskDao.createNew(newTask(with(RECUR, "RRULE:FREQ=DAILY")))
val child = taskDao.createNew(newTask(
with(PARENT, parent),
with(COMPLETION_TIME, DateTime())
))
val parent = taskDao.createNew(
Task(
recurrence = "RRULE:FREQ=DAILY"
)
)
val child = taskDao.createNew(
Task(
parent = parent,
completionDate = now(),
)
)
assertTrue(taskDao.fetch(child)!!.isCompleted)
repeat.handleRepeat(taskDao.fetch(parent)!!)
taskCompleter.setComplete(parent)
assertFalse(taskDao.fetch(child)!!.isCompleted)
}

@ -21,7 +21,7 @@ import org.tasks.data.TaskDao
import org.tasks.preferences.PermissionChecker
import org.tasks.preferences.Preferences
import timber.log.Timber
import java.util.*
import java.util.TimeZone
import javax.inject.Inject
class GCalHelper @Inject constructor(

@ -11,7 +11,6 @@ import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.data.Task
import com.todoroo.astrid.data.Task.Companion.createDueDate
import com.todoroo.astrid.gcal.GCalHelper
import com.todoroo.astrid.service.TaskCompleter
import net.fortuna.ical4j.model.Date
import net.fortuna.ical4j.model.Recur
import net.fortuna.ical4j.model.WeekDay
@ -31,7 +30,6 @@ class RepeatTaskHelper @Inject constructor(
private val alarmService: AlarmService,
private val taskDao: TaskDao,
private val localBroadcastManager: LocalBroadcastManager,
private val taskCompleter: TaskCompleter,
) {
suspend fun handleRepeat(task: Task) {
val recurrence = task.recurrence
@ -77,7 +75,6 @@ class RepeatTaskHelper @Inject constructor(
.takeIf { it > 0 }
?: (newDueDate - (computeNextDueDate(task, recurrence, repeatAfterCompletion) - newDueDate))
rescheduleAlarms(task.id, previousDueDate, newDueDate)
taskCompleter.setComplete(task, false)
broadcastCompletion(task, previousDueDate)
}

@ -6,23 +6,30 @@ import android.content.Context
import android.media.AudioAttributes
import android.media.AudioAttributes.USAGE_NOTIFICATION_EVENT
import android.media.RingtoneManager
import androidx.room.withTransaction
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.dao.Database
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.data.Task
import com.todoroo.astrid.gcal.GCalHelper
import com.todoroo.astrid.repeats.RepeatTaskHelper
import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.LocalBroadcastManager
import org.tasks.jobs.WorkManager
import org.tasks.data.CaldavDao
import org.tasks.preferences.Preferences
import timber.log.Timber
import javax.inject.Inject
class TaskCompleter @Inject internal constructor(
@ApplicationContext private val context: Context,
private val database: Database,
private val taskDao: TaskDao,
private val preferences: Preferences,
private val notificationManager: NotificationManager,
private val localBroadcastManager: LocalBroadcastManager,
private val workManager: WorkManager,
private val repeatTaskHelper: RepeatTaskHelper,
private val caldavDao: CaldavDao,
private val gCalHelper: GCalHelper
) {
suspend fun setComplete(taskId: Long) =
taskDao
@ -58,16 +65,23 @@ class TaskCompleter @Inject internal constructor(
return
}
val completed = completionDate > 0
taskDao.setCompletionDate(tasks.mapNotNull { it.remoteId }, completionDate)
tasks.forEachIndexed { i, original ->
if (i < tasks.size - 1) {
original.suppressRefresh()
database.withTransaction {
taskDao.setCompletionDate(tasks.mapNotNull { it.remoteId }, completionDate)
tasks.forEachIndexed { i, original ->
if (i < tasks.lastIndex) {
original.suppressRefresh()
}
taskDao.saved(original)
}
taskDao.saved(original)
}
tasks.forEach {
if (completed && it.isRecurring) {
workManager.scheduleRepeat(it)
tasks.forEach { task ->
if (completed && task.isRecurring) {
gCalHelper.updateEvent(task)
if (caldavDao.getAccountForTask(task.id)?.isSuppressRepeatingTasks != true) {
repeatTaskHelper.handleRepeat(task)
setComplete(task, false)
}
}
}
}
if (completed && notificationManager.currentInterruptionFilter == INTERRUPTION_FILTER_ALL) {

@ -1,44 +0,0 @@
package org.tasks.jobs
import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.WorkerParameters
import com.todoroo.astrid.gcal.GCalHelper
import com.todoroo.astrid.repeats.RepeatTaskHelper
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.tasks.analytics.Firebase
import org.tasks.data.CaldavDao
import org.tasks.data.TaskDao
import org.tasks.injection.BaseWorker
@HiltWorker
class AfterSaveWork @AssistedInject constructor(
@Assisted context: Context,
@Assisted workerParams: WorkerParameters,
firebase: Firebase,
private val repeatTaskHelper: RepeatTaskHelper,
private val taskDao: TaskDao,
private val caldavDao: CaldavDao,
private val gCalHelper: GCalHelper
) : BaseWorker(context, workerParams, firebase) {
override suspend fun run(): Result {
val taskId = inputData.getLong(EXTRA_ID, -1)
val task = taskDao.fetch(taskId) ?: return Result.failure()
if (inputData.getBoolean(EXTRA_SUPPRESS_COMPLETION_SNACKBAR, false)) {
task.suppressRefresh()
}
gCalHelper.updateEvent(task)
if (caldavDao.getAccountForTask(taskId)?.isSuppressRepeatingTasks != true) {
repeatTaskHelper.handleRepeat(task)
}
return Result.success()
}
companion object {
const val EXTRA_ID = "extra_id"
const val EXTRA_SUPPRESS_COMPLETION_SNACKBAR = "extra_suppress_snackbar"
}
}

@ -8,8 +8,6 @@ import org.tasks.data.Place
interface WorkManager {
fun scheduleRepeat(task: Task)
fun updateCalendar(task: Task)
fun migrateLocalTasks(caldavAccount: CaldavAccount)

@ -56,16 +56,6 @@ class WorkManagerImpl(
private val alarmManager: AlarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
private val workManager = androidx.work.WorkManager.getInstance(context)
override fun scheduleRepeat(task: Task) {
enqueue(
OneTimeWorkRequest.Builder(AfterSaveWork::class.java)
.setInputData(
AfterSaveWork.EXTRA_ID to task.id,
AfterSaveWork.EXTRA_SUPPRESS_COMPLETION_SNACKBAR to task.isSuppressRefresh()
)
)
}
override fun updateCalendar(task: Task) {
enqueue(
OneTimeWorkRequest.Builder(UpdateCalendarWork::class.java)

@ -22,7 +22,6 @@ abstract class RepeatTests {
alarmService,
mock(TaskDao::class.java),
mock(LocalBroadcastManager::class.java),
mock(TaskCompleter::class.java)
)
@Before

Loading…
Cancel
Save