Merge pull request #2226 from naveensingh/task_notification_improvements
Task notification improvements
This commit is contained in:
commit
53be7f1335
2 changed files with 13 additions and 5 deletions
|
@ -117,9 +117,15 @@ fun Context.scheduleNextEventReminder(event: Event, showToasts: Boolean) {
|
||||||
|
|
||||||
val now = getNowSeconds()
|
val now = getNowSeconds()
|
||||||
val reminderSeconds = validReminders.reversed().map { it.minutes * 60 }
|
val reminderSeconds = validReminders.reversed().map { it.minutes * 60 }
|
||||||
|
val isTask = event.isTask()
|
||||||
eventsHelper.getEvents(now, now + YEAR, event.id!!, false) { events ->
|
eventsHelper.getEvents(now, now + YEAR, event.id!!, false) { events ->
|
||||||
if (events.isNotEmpty()) {
|
if (events.isNotEmpty()) {
|
||||||
for (curEvent in events) {
|
for (curEvent in events) {
|
||||||
|
if (isTask && curEvent.isTaskCompleted()) {
|
||||||
|
// skip scheduling reminders for completed tasks
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for (curReminder in reminderSeconds) {
|
for (curReminder in reminderSeconds) {
|
||||||
if (curEvent.getEventStartTS() - curReminder > now) {
|
if (curEvent.getEventStartTS() - curReminder > now) {
|
||||||
scheduleEventIn((curEvent.getEventStartTS() - curReminder) * 1000L, curEvent, showToasts)
|
scheduleEventIn((curEvent.getEventStartTS() - curReminder) * 1000L, curEvent, showToasts)
|
||||||
|
@ -856,6 +862,12 @@ fun Context.updateTaskCompletion(event: Event, completed: Boolean) {
|
||||||
event.flags = event.flags.removeBit(FLAG_TASK_COMPLETED)
|
event.flags = event.flags.removeBit(FLAG_TASK_COMPLETED)
|
||||||
completedTasksDB.deleteTaskWithIdAndTs(event.id!!, event.startTS)
|
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
|
// mark event as "incomplete" in the main events db
|
||||||
eventsDB.updateTaskCompletion(event.id!!, event.flags.removeBit(FLAG_TASK_COMPLETED))
|
eventsDB.updateTaskCompletion(event.id!!, event.flags.removeBit(FLAG_TASK_COMPLETED))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@ package com.simplemobiletools.calendar.pro.services
|
||||||
|
|
||||||
import android.app.IntentService
|
import android.app.IntentService
|
||||||
import android.content.Intent
|
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.eventsDB
|
||||||
import com.simplemobiletools.calendar.pro.extensions.updateTaskCompletion
|
import com.simplemobiletools.calendar.pro.extensions.updateTaskCompletion
|
||||||
import com.simplemobiletools.calendar.pro.helpers.ACTION_MARK_COMPLETED
|
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 taskId = intent.getLongExtra(EVENT_ID, 0L)
|
||||||
val task = eventsDB.getTaskWithId(taskId)
|
val task = eventsDB.getTaskWithId(taskId)
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
updateTaskCompletion(task, true)
|
updateTaskCompletion(task, completed = true)
|
||||||
cancelPendingIntent(task.id!!)
|
|
||||||
cancelNotification(task.id!!)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue