Show previously shown notifications silently

pull/1509/head
Felix Wiemuth 3 years ago
parent 09c46f5b88
commit 857e21af1d

@ -66,10 +66,11 @@ class AndroidNotificationTray
habit: Habit, habit: Habit,
notificationId: Int, notificationId: Int,
timestamp: Timestamp, timestamp: Timestamp,
reminderTime: Long reminderTime: Long,
silent: Boolean
) { ) {
val notificationManager = NotificationManagerCompat.from(context) val notificationManager = NotificationManagerCompat.from(context)
val notification = buildNotification(habit, reminderTime, timestamp) val notification = buildNotification(habit, reminderTime, timestamp, silent = silent)
createAndroidNotificationChannel(context) createAndroidNotificationChannel(context)
try { try {
notificationManager.notify(notificationId, notification) notificationManager.notify(notificationId, notification)
@ -83,7 +84,8 @@ class AndroidNotificationTray
habit, habit,
reminderTime, reminderTime,
timestamp, timestamp,
disableSound = true disableSound = true,
silent = silent
) )
notificationManager.notify(notificationId, n) notificationManager.notify(notificationId, n)
} }
@ -94,7 +96,8 @@ class AndroidNotificationTray
habit: Habit, habit: Habit,
reminderTime: Long, reminderTime: Long,
timestamp: Timestamp, timestamp: Timestamp,
disableSound: Boolean = false disableSound: Boolean = false,
silent: Boolean = false
): Notification { ): Notification {
val addRepetitionAction = Action( val addRepetitionAction = Action(
@ -132,6 +135,7 @@ class AndroidNotificationTray
.setSound(null) .setSound(null)
.setWhen(reminderTime) .setWhen(reminderTime)
.setShowWhen(true) .setShowWhen(true)
.setSilent(silent)
.setOngoing(preferences.shouldMakeNotificationsSticky()) .setOngoing(preferences.shouldMakeNotificationsSticky())
if (habit.isNumerical) { if (habit.isNumerical) {

@ -117,19 +117,26 @@ class NotificationTray @Inject constructor(
habit: Habit, habit: Habit,
notificationId: Int, notificationId: Int,
timestamp: Timestamp, timestamp: Timestamp,
reminderTime: Long reminderTime: Long,
silent: Boolean = false
) )
fun log(msg: String) fun log(msg: String)
} }
@Serializable @Serializable
internal class NotificationData(val timestamp: Timestamp, val reminderTime: Long) internal class NotificationData(
private inner class ShowNotificationTask(private val habit: Habit, data: NotificationData) : val timestamp: Timestamp,
val reminderTime: Long,
var shown: Boolean = false
)
private inner class ShowNotificationTask(
private val habit: Habit,
private val data: NotificationData
) :
Task { Task {
var isCompleted = false var isCompleted = false
private val timestamp: Timestamp = data.timestamp
private val reminderTime: Long = data.reminderTime
override fun doInBackground() { override fun doInBackground() {
isCompleted = habit.isCompletedToday() isCompleted = habit.isCompletedToday()
@ -184,8 +191,9 @@ class NotificationTray @Inject constructor(
systemTray.showNotification( systemTray.showNotification(
habit, habit,
getNotificationId(habit), getNotificationId(habit),
timestamp, data.timestamp,
reminderTime data.reminderTime,
silent = data.shown
) )
if (data.shown) { if (data.shown) {
systemTray.log( systemTray.log(
@ -204,7 +212,7 @@ class NotificationTray @Inject constructor(
if (!habit.hasReminder()) return false if (!habit.hasReminder()) return false
val reminder = habit.reminder val reminder = habit.reminder
val reminderDays = Objects.requireNonNull(reminder)!!.days.toArray() val reminderDays = Objects.requireNonNull(reminder)!!.days.toArray()
val weekday = timestamp.weekday val weekday = data.timestamp.weekday
return reminderDays[weekday] return reminderDays[weekday]
} }
} }

Loading…
Cancel
Save