Cancel notifications in TaskCompleter

pull/2906/head
Alex Baker 6 months ago
parent 09ffbdd036
commit 07a2eda5ea

@ -8,14 +8,14 @@ package com.todoroo.astrid.dao
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.timers.TimerPlugin
import org.tasks.LocalBroadcastManager
import org.tasks.data.entity.Task
import org.tasks.data.TaskContainer
import org.tasks.data.dao.TaskDao
import org.tasks.data.db.SuspendDbUtils.eachChunk
import org.tasks.data.entity.Task
import org.tasks.data.fetchFiltered
import org.tasks.data.fetchTasks
import org.tasks.data.setCollapsed
import org.tasks.date.DateTimeUtils.isAfterNow
import org.tasks.data.db.SuspendDbUtils.eachChunk
import org.tasks.jobs.WorkManager
import org.tasks.location.GeofenceApi
import org.tasks.notifications.NotificationManager
@ -108,12 +108,10 @@ class TaskDao @Inject constructor(
val completionDateModified = task.completionDate != (original?.completionDate ?: 0)
val deletionDateModified = task.deletionDate != (original?.deletionDate ?: 0)
val justCompleted = completionDateModified && task.isCompleted
val justDeleted = deletionDateModified && task.isDeleted
if (task.calendarURI?.isNotBlank() == true) {
workManager.updateCalendar(task)
}
if (justCompleted || justDeleted) {
notificationManager.cancel(task.id)
if (justCompleted) {
if (task.timerStart > 0) {
timerPlugin.stopTimer(task)
}

@ -1,20 +1,20 @@
package com.todoroo.astrid.service
import android.app.NotificationManager
import android.app.NotificationManager.INTERRUPTION_FILTER_ALL
import android.content.Context
import android.media.AudioAttributes
import android.media.AudioAttributes.USAGE_NOTIFICATION_EVENT
import android.media.RingtoneManager
import androidx.room.withTransaction
import org.tasks.data.db.Database
import com.todoroo.astrid.dao.TaskDao
import org.tasks.data.entity.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.data.dao.CaldavDao
import org.tasks.data.db.Database
import org.tasks.data.entity.Task
import org.tasks.notifications.NotificationManager
import org.tasks.preferences.Preferences
import org.tasks.time.DateTimeUtils2.currentTimeMillis
import timber.log.Timber
@ -64,6 +64,7 @@ class TaskCompleter @Inject internal constructor(
if (tasks.isEmpty()) {
return
}
tasks.forEach { notificationManager.cancel(it.id) }
val completed = completionDate > 0
val modified = currentTimeMillis()
database.withTransaction {

@ -2,22 +2,21 @@ package com.todoroo.astrid.service
import android.content.Context
import androidx.room.withTransaction
import org.tasks.data.db.Database
import org.tasks.data.entity.Task
import com.todoroo.astrid.timers.TimerPlugin
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.withContext
import org.tasks.BuildConfig
import org.tasks.LocalBroadcastManager
import org.tasks.caldav.VtodoCache
import org.tasks.data.entity.CaldavAccount
import org.tasks.data.entity.CaldavCalendar
import org.tasks.data.dao.DeletionDao
import org.tasks.data.dao.LocationDao
import org.tasks.data.dao.TaskDao
import org.tasks.data.dao.UserActivityDao
import org.tasks.data.db.Database
import org.tasks.data.db.SuspendDbUtils.chunkedMap
import org.tasks.data.entity.CaldavAccount
import org.tasks.data.entity.CaldavCalendar
import org.tasks.data.entity.Task
import org.tasks.files.FileHelper
import org.tasks.location.GeofenceApi
import org.tasks.notifications.NotificationManager
@ -34,7 +33,6 @@ class TaskDeleter @Inject constructor(
private val vtodoCache: VtodoCache,
private val notificationManager: NotificationManager,
private val geofenceApi: GeofenceApi,
private val timerPlugin: TimerPlugin,
private val userActivityDao: UserActivityDao,
private val locationDao: LocationDao,
) {

@ -5,8 +5,8 @@
*/
package com.todoroo.astrid.timers
import org.tasks.data.entity.Task
import org.tasks.data.dao.TaskDao
import org.tasks.data.entity.Task
import org.tasks.notifications.NotificationManager
import org.tasks.time.DateTimeUtils2.currentTimeMillis
import javax.inject.Inject

@ -5,6 +5,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat.InterruptionFilter
import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.andlib.utility.AndroidUtilities.preUpsideDownCake
import com.todoroo.astrid.core.BuiltInFilterExposer
@ -12,11 +13,11 @@ import com.todoroo.astrid.utility.Constants
import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.data.entity.Alarm
import org.tasks.data.dao.LocationDao
import org.tasks.data.entity.Notification
import org.tasks.data.dao.NotificationDao
import org.tasks.data.dao.TaskDao
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Notification
import org.tasks.intents.TaskIntents
import org.tasks.markdown.MarkdownProvider
import org.tasks.preferences.PermissionChecker
@ -45,6 +46,10 @@ class NotificationManager @Inject constructor(
private val markdownProvider: MarkdownProvider,
private val permissionChecker: PermissionChecker,
) {
@InterruptionFilter
val currentInterruptionFilter: Int
get() = notificationManager.currentInterruptionFilter
private val colorProvider = ColorProvider(context, preferences)
private val queue = NotificationLimiter(MAX_NOTIFICATIONS)

@ -3,6 +3,7 @@ package org.tasks.notifications
import android.app.Notification
import android.content.Context
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.NotificationManagerCompat.InterruptionFilter
import dagger.hilt.android.qualifiers.ApplicationContext
import java.util.concurrent.Executors.newSingleThreadExecutor
import javax.inject.Inject
@ -14,6 +15,10 @@ class ThrottledNotificationManager @Inject constructor(
private val executor = newSingleThreadExecutor()
private val throttle = Throttle(NOTIFICATIONS_PER_SECOND, executor = executor, tag = "NOTIFY")
@InterruptionFilter
val currentInterruptionFilter: Int
get() = notificationManagerCompat.currentInterruptionFilter
fun cancel(id: Int) {
executor.execute {
notificationManagerCompat.cancel(id)

Loading…
Cancel
Save