Automatically dismiss summary notification

This commit is contained in:
2017-11-14 23:03:46 -06:00
parent 2a4a7c975f
commit 0077d35ff9

View File

@@ -44,8 +44,15 @@ class AndroidNotificationTray
private val ringtoneManager: RingtoneManager private val ringtoneManager: RingtoneManager
) : NotificationTray.SystemTray { ) : NotificationTray.SystemTray {
private var active = HashSet<Int>()
override fun removeNotification(id: Int) { override fun removeNotification(id: Int) {
NotificationManagerCompat.from(context).cancel(id) val manager = NotificationManagerCompat.from(context)
manager.cancel(id)
active.remove(id)
// Clear the group summary notification
if(active.isEmpty()) manager.cancelAll()
} }
override fun showNotification(habit: Habit, override fun showNotification(habit: Habit,
@@ -58,6 +65,7 @@ class AndroidNotificationTray
notificationManager.notify(Int.MAX_VALUE, summary) notificationManager.notify(Int.MAX_VALUE, summary)
val notification = buildNotification(habit, reminderTime, timestamp) val notification = buildNotification(habit, reminderTime, timestamp)
notificationManager.notify(notificationId, notification) notificationManager.notify(notificationId, notification)
active.add(notificationId)
} }
@NonNull @NonNull
@@ -79,8 +87,7 @@ class AndroidNotificationTray
val removeRepetitionAction = Action( val removeRepetitionAction = Action(
R.drawable.ic_action_cancel, R.drawable.ic_action_cancel,
context.getString(R.string.no), context.getString(R.string.no),
pendingIntents.removeRepetition(habit) pendingIntents.removeRepetition(habit))
)
val wearableBg = decodeResource(context.resources, R.drawable.stripe) val wearableBg = decodeResource(context.resources, R.drawable.stripe)