|
|
|
@ -1,9 +1,11 @@
|
|
|
|
package org.tasks.notifications
|
|
|
|
package org.tasks.notifications
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.app.PendingIntent
|
|
|
|
import android.app.PendingIntent
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.Intent
|
|
|
|
|
|
|
|
import androidx.annotation.RequiresPermission
|
|
|
|
import androidx.core.app.NotificationCompat
|
|
|
|
import androidx.core.app.NotificationCompat
|
|
|
|
import androidx.core.app.NotificationManagerCompat.InterruptionFilter
|
|
|
|
import androidx.core.app.NotificationManagerCompat.InterruptionFilter
|
|
|
|
import com.todoroo.andlib.utility.AndroidUtilities.preUpsideDownCake
|
|
|
|
import com.todoroo.andlib.utility.AndroidUtilities.preUpsideDownCake
|
|
|
|
@ -82,7 +84,11 @@ class NotificationManager @Inject constructor(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("MissingPermission")
|
|
|
|
suspend fun restoreNotifications(cancelExisting: Boolean) {
|
|
|
|
suspend fun restoreNotifications(cancelExisting: Boolean) {
|
|
|
|
|
|
|
|
if (!permissionChecker.hasNotificationPermission()) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
val notifications = notificationDao.getAllOrdered()
|
|
|
|
val notifications = notificationDao.getAllOrdered()
|
|
|
|
if (cancelExisting) {
|
|
|
|
if (cancelExisting) {
|
|
|
|
for (notification in notifications) {
|
|
|
|
for (notification in notifications) {
|
|
|
|
@ -114,11 +120,16 @@ class NotificationManager @Inject constructor(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("MissingPermission")
|
|
|
|
suspend fun notifyTasks(
|
|
|
|
suspend fun notifyTasks(
|
|
|
|
newNotifications: List<Notification>,
|
|
|
|
newNotifications: List<Notification>,
|
|
|
|
alert: Boolean,
|
|
|
|
alert: Boolean,
|
|
|
|
nonstop: Boolean,
|
|
|
|
nonstop: Boolean,
|
|
|
|
fiveTimes: Boolean) {
|
|
|
|
fiveTimes: Boolean
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (!permissionChecker.hasNotificationPermission()) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
val existingNotifications = notificationDao.getAllOrdered()
|
|
|
|
val existingNotifications = notificationDao.getAllOrdered()
|
|
|
|
notificationDao.insertAll(newNotifications)
|
|
|
|
notificationDao.insertAll(newNotifications)
|
|
|
|
val totalCount = existingNotifications.size + newNotifications.size
|
|
|
|
val totalCount = existingNotifications.size + newNotifications.size
|
|
|
|
@ -167,6 +178,7 @@ class NotificationManager @Inject constructor(
|
|
|
|
localBroadcastManager.broadcastRefresh()
|
|
|
|
localBroadcastManager.broadcastRefresh()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("MissingPermission")
|
|
|
|
private suspend fun createNotifications(
|
|
|
|
private suspend fun createNotifications(
|
|
|
|
notifications: List<Notification>,
|
|
|
|
notifications: List<Notification>,
|
|
|
|
alert: Boolean,
|
|
|
|
alert: Boolean,
|
|
|
|
@ -204,6 +216,7 @@ class NotificationManager @Inject constructor(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("MissingPermission")
|
|
|
|
suspend fun notify(
|
|
|
|
suspend fun notify(
|
|
|
|
notificationId: Long,
|
|
|
|
notificationId: Long,
|
|
|
|
builder: NotificationCompat.Builder,
|
|
|
|
builder: NotificationCompat.Builder,
|
|
|
|
@ -211,6 +224,9 @@ class NotificationManager @Inject constructor(
|
|
|
|
nonstop: Boolean,
|
|
|
|
nonstop: Boolean,
|
|
|
|
fiveTimes: Boolean,
|
|
|
|
fiveTimes: Boolean,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (!permissionChecker.hasNotificationPermission()) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
if (preUpsideDownCake()) {
|
|
|
|
if (preUpsideDownCake()) {
|
|
|
|
builder.setLocalOnly(!preferences.getBoolean(R.string.p_wearable_notifications, true))
|
|
|
|
builder.setLocalOnly(!preferences.getBoolean(R.string.p_wearable_notifications, true))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -245,6 +261,7 @@ class NotificationManager @Inject constructor(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
|
|
|
|
private suspend fun updateSummary(
|
|
|
|
private suspend fun updateSummary(
|
|
|
|
notify: Boolean,
|
|
|
|
notify: Boolean,
|
|
|
|
nonStop: Boolean,
|
|
|
|
nonStop: Boolean,
|
|
|
|
@ -415,7 +432,11 @@ class NotificationManager @Inject constructor(
|
|
|
|
.extend(wearableExtender)
|
|
|
|
.extend(wearableExtender)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("MissingPermission")
|
|
|
|
suspend fun updateTimerNotification() {
|
|
|
|
suspend fun updateTimerNotification() {
|
|
|
|
|
|
|
|
if (!permissionChecker.hasNotificationPermission()) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
val count = taskDao.activeTimers()
|
|
|
|
val count = taskDao.activeTimers()
|
|
|
|
if (count == 0) {
|
|
|
|
if (count == 0) {
|
|
|
|
cancel(Constants.NOTIFICATION_TIMER.toLong())
|
|
|
|
cancel(Constants.NOTIFICATION_TIMER.toLong())
|
|
|
|
|