Reminders: global repeat toggle + per-dose "Ikke forstyrr"
Two ways to stop the every-10-min nag, per feature request: - A global "Gjenta påminnelser" switch in Settings. Off → a due dose alerts once and goes quiet; only the automatic re-nag chain is gated, so an explicit "Utsett 15 min" still gives one more reminder. The gate sits at the three automatic arm points (fireOccurrence, escalate re-arm, armAll resume-after-reboot), never on Snooze. - An "Ikke forstyrr" action that appears from the second reminder on (nagCount >= 1). It stops nagging this one dose but leaves it PENDING so it can still be taken later — distinct from Skip. Implemented by jumping to the existing terminal state (nagCount = NAG_CAP) rather than a new column, so it needs no migration and survives reboot for free (armAll re-arms only nagCount < cap). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
5b9a3d6877
commit
778a6aec27
7 changed files with 82 additions and 3 deletions
|
|
@ -90,7 +90,9 @@ class AlarmScheduler(private val context: Context) {
|
|||
// Resume nagging for doses that were unresolved when the device died —
|
||||
// but only PAST-DUE ones. An unresolved log can also be a future dose
|
||||
// (e.g. "Ta nå" + "Angre" before its time); its own occurrence alarm
|
||||
// handles it when it actually falls due.
|
||||
// handles it when it actually falls due. Resuming the nag chain is the
|
||||
// automatic repeat the setting governs, so honour it here too.
|
||||
if (!no.naiv.meddetsamme.settings.SettingsStore(context).repeatReminders) return
|
||||
val now = System.currentTimeMillis()
|
||||
db.doseLogDao().getUnresolved().forEach { log ->
|
||||
if (log.nagCount < NAG_CAP && log.scheduledAtMillis <= now) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import no.naiv.meddetsamme.domain.DoseActions
|
|||
* - 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.
|
||||
*/
|
||||
class DoseActionReceiver : BroadcastReceiver() {
|
||||
|
||||
|
|
@ -22,6 +23,7 @@ class DoseActionReceiver : BroadcastReceiver() {
|
|||
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"
|
||||
}
|
||||
|
||||
|
|
@ -45,6 +47,7 @@ class DoseActionReceiver : BroadcastReceiver() {
|
|||
ACTION_TAKEN -> actions.take(logId)
|
||||
ACTION_SNOOZE -> actions.snooze(logId)
|
||||
ACTION_SKIP -> actions.skip(logId)
|
||||
ACTION_MUTE -> actions.mute(logId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,11 @@ class DoseAlarmReceiver : BroadcastReceiver() {
|
|||
Notifications.doseNotificationId(log.id),
|
||||
Notifications.buildDoseNotification(context, med, log),
|
||||
)
|
||||
if (log.nagCount < AlarmScheduler.NAG_CAP) scheduler.armEscalation(log.id)
|
||||
// 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) {
|
||||
scheduler.armEscalation(log.id)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun escalate(context: Context, logId: Long) {
|
||||
|
|
@ -107,6 +111,14 @@ class DoseAlarmReceiver : BroadcastReceiver() {
|
|||
Notifications.doseNotificationId(logId),
|
||||
Notifications.buildDoseNotification(context, med, nagged),
|
||||
)
|
||||
if (nagged.nagCount < AlarmScheduler.NAG_CAP) AlarmScheduler(context).armEscalation(logId)
|
||||
// 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.
|
||||
if (repeatReminders(context) && nagged.nagCount < AlarmScheduler.NAG_CAP) {
|
||||
AlarmScheduler(context).armEscalation(logId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun repeatReminders(context: Context): Boolean =
|
||||
no.naiv.meddetsamme.settings.SettingsStore(context).repeatReminders
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue