From a67c1c79db2c7a71b4246daf636dbd8530b6b5ea Mon Sep 17 00:00:00 2001 From: Naveen Date: Thu, 5 Oct 2023 21:31:39 +0530 Subject: [PATCH] Cancel expired notification when task is completed --- .../simplemobiletools/calendar/pro/extensions/Context.kt | 6 ++++++ .../calendar/pro/services/MarkCompletedService.kt | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index 1b69ca2ca..7c4d7041d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -856,6 +856,12 @@ fun Context.updateTaskCompletion(event: Event, completed: Boolean) { event.flags = event.flags.removeBit(FLAG_TASK_COMPLETED) completedTasksDB.deleteTaskWithIdAndTs(event.id!!, event.startTS) } + + // remove existing notification (if any) and schedule a new one if needed + cancelPendingIntent(event.id!!) + cancelNotification(event.id!!) + scheduleNextEventReminder(event, showToasts = false) + // mark event as "incomplete" in the main events db eventsDB.updateTaskCompletion(event.id!!, event.flags.removeBit(FLAG_TASK_COMPLETED)) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/services/MarkCompletedService.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/services/MarkCompletedService.kt index f64afda7d..9e6568d32 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/services/MarkCompletedService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/services/MarkCompletedService.kt @@ -2,8 +2,6 @@ package com.simplemobiletools.calendar.pro.services import android.app.IntentService import android.content.Intent -import com.simplemobiletools.calendar.pro.extensions.cancelNotification -import com.simplemobiletools.calendar.pro.extensions.cancelPendingIntent import com.simplemobiletools.calendar.pro.extensions.eventsDB import com.simplemobiletools.calendar.pro.extensions.updateTaskCompletion import com.simplemobiletools.calendar.pro.helpers.ACTION_MARK_COMPLETED @@ -17,9 +15,7 @@ class MarkCompletedService : IntentService("MarkCompleted") { val taskId = intent.getLongExtra(EVENT_ID, 0L) val task = eventsDB.getTaskWithId(taskId) if (task != null) { - updateTaskCompletion(task, true) - cancelPendingIntent(task.id!!) - cancelNotification(task.id!!) + updateTaskCompletion(task, completed = true) } } }