Add "Mark completed" action in task notifications
This commit is contained in:
parent
48d26b4ab2
commit
0c797f21fe
|
@ -252,6 +252,7 @@
|
|||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||
|
||||
<service android:name=".services.SnoozeService" />
|
||||
<service android:name=".services.MarkCompleteService" />
|
||||
|
||||
<service
|
||||
android:name=".jobs.CalDAVUpdateListener"
|
||||
|
|
|
@ -37,6 +37,8 @@ import com.simplemobiletools.calendar.pro.interfaces.WidgetsDao
|
|||
import com.simplemobiletools.calendar.pro.models.*
|
||||
import com.simplemobiletools.calendar.pro.receivers.CalDAVSyncReceiver
|
||||
import com.simplemobiletools.calendar.pro.receivers.NotificationReceiver
|
||||
import com.simplemobiletools.calendar.pro.services.MarkCompleteService
|
||||
import com.simplemobiletools.calendar.pro.services.MarkCompleteService.Companion.ACTION_MARK_COMPLETE
|
||||
import com.simplemobiletools.calendar.pro.services.SnoozeService
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
|
@ -312,7 +314,12 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
|
|||
.setAutoCancel(true)
|
||||
.setSound(Uri.parse(soundUri), config.reminderAudioStream)
|
||||
.setChannelId(channelId)
|
||||
.addAction(R.drawable.ic_snooze_vector, getString(R.string.snooze), getSnoozePendingIntent(this, event))
|
||||
.apply {
|
||||
if (event.isTask() && !event.isTaskCompleted()) {
|
||||
addAction(R.drawable.ic_task_vector, getString(R.string.mark_completed), getMarkCompletePendingIntent(this@getNotification, event))
|
||||
}
|
||||
addAction(R.drawable.ic_snooze_vector, getString(R.string.snooze), getSnoozePendingIntent(this@getNotification, event))
|
||||
}
|
||||
|
||||
if (config.vibrateOnReminder) {
|
||||
val vibrateArray = LongArray(2) { 500 }
|
||||
|
@ -354,6 +361,12 @@ private fun getSnoozePendingIntent(context: Context, event: Event): PendingInten
|
|||
}
|
||||
}
|
||||
|
||||
private fun getMarkCompletePendingIntent(context: Context, task: Event): PendingIntent {
|
||||
val intent = Intent(context, MarkCompleteService::class.java).setAction(ACTION_MARK_COMPLETE)
|
||||
intent.putExtra(EVENT_ID, task.id)
|
||||
return PendingIntent.getService(context, task.id!!.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
fun Context.rescheduleReminder(event: Event?, minutes: Int) {
|
||||
if (event != null) {
|
||||
cancelPendingIntent(event.id!!)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
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.helpers.EVENT_ID
|
||||
import com.simplemobiletools.calendar.pro.helpers.FLAG_TASK_COMPLETED
|
||||
|
||||
class MarkCompleteService : IntentService("MarkComplete") {
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onHandleIntent(intent: Intent?) {
|
||||
if (intent != null && intent.action == ACTION_MARK_COMPLETE) {
|
||||
val taskId = intent.getLongExtra(EVENT_ID, 0L)
|
||||
val task = eventsDB.getTaskWithId(taskId)
|
||||
if (task != null) {
|
||||
task.flags = task.flags or FLAG_TASK_COMPLETED
|
||||
eventsDB.updateTaskCompletion(task.id!!, task.flags)
|
||||
cancelPendingIntent(task.id!!)
|
||||
cancelNotification(task.id!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ACTION_MARK_COMPLETE = "ACTION_MARK_COMPLETE"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue