Reminders: one grouped card for co-timed meds, acked together
Meds due at the same wall-clock minute now share a single notification instead of one card each — they resolve to an identical scheduledAtMillis, which becomes the occurrence (and notification) key. Per the feature request: "Tatt alle" / "Utsett alle" handle the whole morning batch in one tap; a single med just renders as a normal card with "Tatt". - Notification id is per-occurrence (scheduledAtMillis), not per-log, so co-timed doses collapse onto one card and re-nags replace it. - DoseActionReceiver buttons carry the occurrence and call group ops (takeAll/snoozeAll/muteAll); DoseActions keeps a single per-dose state mutation (takeState/snoozeState/muteState) reused by both the group ops and the app's per-dose actions, so the two surfaces can't diverge. - The card is rebuilt from getActiveAtOccurrence: still-unresolved doses with nagCount <= cap. "Ikke forstyrr" now sets nagCount above the cap so a muted dose drops off the card, while a naturally-capped dose (== cap) stays visible and actionable. - refreshOccurrence re-renders silently after a single in-app action and never creates a card for a not-yet-due occurrence. Adds DoseActionsGroupTest (instrumented) covering takeAll, muteAll, and the muted-vs-capped distinction at the data layer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
778a6aec27
commit
44ea4ed87b
6 changed files with 309 additions and 82 deletions
|
|
@ -80,11 +80,7 @@ class DoseAlarmReceiver : BroadcastReceiver() {
|
|||
else -> existing
|
||||
}
|
||||
|
||||
Notifications.post(
|
||||
context,
|
||||
Notifications.doseNotificationId(log.id),
|
||||
Notifications.buildDoseNotification(context, med, log),
|
||||
)
|
||||
postOccurrence(context, db, scheduledAt)
|
||||
// Start the automatic re-nag chain only if the user wants repeats; an
|
||||
// explicit Snooze still re-arms regardless (DoseActions.snooze).
|
||||
if (repeatReminders(context) && log.nagCount < AlarmScheduler.NAG_CAP) {
|
||||
|
|
@ -102,15 +98,11 @@ class DoseAlarmReceiver : BroadcastReceiver() {
|
|||
// depth against any path that arms one too early).
|
||||
if (log.scheduledAtMillis > System.currentTimeMillis()) return
|
||||
|
||||
val med = db.medicationDao().getById(log.medId) ?: return
|
||||
val nagged = log.copy(nagCount = log.nagCount + 1)
|
||||
db.doseLogDao().setNagCount(logId, nagged.nagCount)
|
||||
|
||||
Notifications.post(
|
||||
context,
|
||||
Notifications.doseNotificationId(logId),
|
||||
Notifications.buildDoseNotification(context, med, nagged),
|
||||
)
|
||||
// Re-post the whole occurrence so co-timed siblings stay on one card.
|
||||
postOccurrence(context, db, log.scheduledAtMillis)
|
||||
// Re-arm the next automatic nag only while repeats are enabled. A nag
|
||||
// already in flight from a Snooze still fires once (this post), then
|
||||
// stops here — Snooze stays a single deferral, not an endless chain.
|
||||
|
|
@ -119,6 +111,23 @@ class DoseAlarmReceiver : BroadcastReceiver() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post (or replace) the single grouped card for one wall-clock occurrence:
|
||||
* every med due at that minute, still active (not taken/skipped/muted). If
|
||||
* nothing's active it clears the card — a redundant escalation that raced a
|
||||
* "Tatt alle" then just tidies up.
|
||||
*/
|
||||
private suspend fun postOccurrence(context: Context, db: MedDatabase, scheduledAtMillis: Long) {
|
||||
val active = db.doseLogDao().getActiveAtOccurrence(scheduledAtMillis, AlarmScheduler.NAG_CAP)
|
||||
val id = Notifications.doseNotificationId(scheduledAtMillis)
|
||||
val entries = active.mapNotNull { l -> db.medicationDao().getById(l.medId)?.let { it to l } }
|
||||
if (entries.isEmpty()) {
|
||||
Notifications.cancel(context, id)
|
||||
return
|
||||
}
|
||||
Notifications.post(context, id, Notifications.buildDoseNotification(context, entries, scheduledAtMillis))
|
||||
}
|
||||
|
||||
private fun repeatReminders(context: Context): Boolean =
|
||||
no.naiv.meddetsamme.settings.SettingsStore(context).repeatReminders
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue