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
|
|
@ -9,45 +9,41 @@ import kotlinx.coroutines.launch
|
|||
import no.naiv.meddetsamme.domain.DoseActions
|
||||
|
||||
/**
|
||||
* Handles the notification actions (and later, the same actions from the UI).
|
||||
* Handles the notification actions. The dose card groups every med due at the
|
||||
* same wall-clock minute, so its buttons act on the whole occurrence (carried
|
||||
* as EXTRA_SCHEDULED_AT), not a single log — "Tatt alle" / "Utsett alle".
|
||||
*
|
||||
* Contract (CLAUDE.md, load-bearing):
|
||||
* Contract (CLAUDE.md, load-bearing), applied to each dose in the occurrence:
|
||||
* - Taken → TAKEN, decrement inventory by the *logged* amount, stop escalating.
|
||||
* - Snooze → SNOOZED, next nag in 15 min, keeps escalating (and counting) after.
|
||||
* - Skip → SKIPPED, stop escalating, no inventory change.
|
||||
* - Mute → "Ikke forstyrr": stop escalating, dose stays unresolved.
|
||||
* (Skip stays a per-dose UI action; the notification never offers it.)
|
||||
*/
|
||||
class DoseActionReceiver : BroadcastReceiver() {
|
||||
|
||||
companion object {
|
||||
const val ACTION_TAKEN = "no.naiv.meddetsamme.action.TAKEN"
|
||||
const val ACTION_SNOOZE = "no.naiv.meddetsamme.action.SNOOZE"
|
||||
const val ACTION_SKIP = "no.naiv.meddetsamme.action.SKIP"
|
||||
const val ACTION_MUTE = "no.naiv.meddetsamme.action.MUTE"
|
||||
const val EXTRA_LOG_ID = "logId"
|
||||
const val EXTRA_SCHEDULED_AT = "scheduledAt"
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val logId = intent.getLongExtra(EXTRA_LOG_ID, -1)
|
||||
if (logId < 0) return
|
||||
val scheduledAt = intent.getLongExtra(EXTRA_SCHEDULED_AT, -1)
|
||||
if (scheduledAt < 0) return
|
||||
val action = intent.action ?: return
|
||||
val pending = goAsync()
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
handle(context, action, logId)
|
||||
val actions = DoseActions(context)
|
||||
when (action) {
|
||||
ACTION_TAKEN -> actions.takeAll(scheduledAt)
|
||||
ACTION_SNOOZE -> actions.snoozeAll(scheduledAt)
|
||||
ACTION_MUTE -> actions.muteAll(scheduledAt)
|
||||
}
|
||||
} finally {
|
||||
pending.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun handle(context: Context, action: String, logId: Long) {
|
||||
val actions = DoseActions(context)
|
||||
when (action) {
|
||||
ACTION_TAKEN -> actions.take(logId)
|
||||
ACTION_SNOOZE -> actions.snooze(logId)
|
||||
ACTION_SKIP -> actions.skip(logId)
|
||||
ACTION_MUTE -> actions.mute(logId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue