|
|
@ -12,6 +12,7 @@ import dagger.assisted.AssistedInject
|
|
|
|
import org.tasks.Notifier
|
|
|
|
import org.tasks.Notifier
|
|
|
|
import org.tasks.R
|
|
|
|
import org.tasks.R
|
|
|
|
import org.tasks.analytics.Firebase
|
|
|
|
import org.tasks.analytics.Firebase
|
|
|
|
|
|
|
|
import org.tasks.data.Alarm.Companion.TYPE_RANDOM
|
|
|
|
import org.tasks.data.Alarm.Companion.TYPE_SNOOZE
|
|
|
|
import org.tasks.data.Alarm.Companion.TYPE_SNOOZE
|
|
|
|
import org.tasks.data.AlarmDao
|
|
|
|
import org.tasks.data.AlarmDao
|
|
|
|
import org.tasks.date.DateTimeUtils.toDateTime
|
|
|
|
import org.tasks.date.DateTimeUtils.toDateTime
|
|
|
@ -37,12 +38,8 @@ class NotificationWork @AssistedInject constructor(
|
|
|
|
nextAlarm = preferences.adjustForQuietHours(now())
|
|
|
|
nextAlarm = preferences.adjustForQuietHours(now())
|
|
|
|
return Result.success()
|
|
|
|
return Result.success()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
repeat(3) {
|
|
|
|
val (overdue, _) = alarmService.getAlarms()
|
|
|
|
val (overdue, future) = alarmService.getAlarms()
|
|
|
|
if (overdue.isNotEmpty()) {
|
|
|
|
nextAlarm = future.minOfOrNull { it.time } ?: 0
|
|
|
|
|
|
|
|
if (overdue.isEmpty()) {
|
|
|
|
|
|
|
|
return Result.success()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
overdue
|
|
|
|
overdue
|
|
|
|
.sortedBy { it.time }
|
|
|
|
.sortedBy { it.time }
|
|
|
|
.also { alarms ->
|
|
|
|
.also { alarms ->
|
|
|
@ -54,8 +51,14 @@ class NotificationWork @AssistedInject constructor(
|
|
|
|
.map { it.toNotification() }
|
|
|
|
.map { it.toNotification() }
|
|
|
|
.let { notifier.triggerNotifications(it) }
|
|
|
|
.let { notifier.triggerNotifications(it) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
firebase.reportException(IllegalStateException("Should have returned already"))
|
|
|
|
val alreadyTriggered = overdue.map { it.taskId }.toSet()
|
|
|
|
return Result.failure()
|
|
|
|
val (moreOverdue, future) = alarmService.getAlarms()
|
|
|
|
|
|
|
|
nextAlarm = moreOverdue
|
|
|
|
|
|
|
|
.filterNot { it.type == TYPE_RANDOM || alreadyTriggered.contains(it.taskId)}
|
|
|
|
|
|
|
|
.plus(future)
|
|
|
|
|
|
|
|
.minOfOrNull { it.time }
|
|
|
|
|
|
|
|
?: 0
|
|
|
|
|
|
|
|
return Result.success()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override suspend fun scheduleNext() {
|
|
|
|
override suspend fun scheduleNext() {
|
|
|
|