UI buildout: today screen, med editor with FEST autocomplete, schedule editor, settings
Milestone 9. Hand-rolled back-stack navigation (4 screens don't justify navigation-compose). DoseActions is now the single implementation of Taken/Snooze/Skip/Undo shared by notification receiver and UI — two code paths for 'taken' would eventually disagree about inventory. Screens read DAO Flows directly; every schedule mutation re-arms alarms via armAll() (idempotent, OS-deduplicated). One-time battery prompt + POST_NOTIFICATIONS request on the today screen. Settings: S3/Garage config, typed-passphrase export/import (replace-all import re-arms alarms), FEST refresh, PDF share. TalkBack: merged semantics with full descriptions on dose cards, content descriptions on icon buttons and day chips. Doctor PDF locale pinned to Bokmål — verified on emulator after catching English month names on an en-US device. Emulator-verified end-to-end: battery prompt → system dialog, med created via editor (validation catches bad input), dose time added → exact alarm armed immediately, Ta nå → TAKEN + inventory 20→19 + reactive UI update, Angre → PENDING + inventory restored, settings renders, PDF generated and share sheet opened. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
c4d0ed9c3b
commit
2e7eadeb39
13 changed files with 1390 additions and 100 deletions
|
|
@ -6,9 +6,7 @@ import android.content.Intent
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import no.naiv.meddetsamme.data.DoseStatus
|
||||
import no.naiv.meddetsamme.data.MedDatabase
|
||||
import no.naiv.meddetsamme.notify.Notifications
|
||||
import no.naiv.meddetsamme.domain.DoseActions
|
||||
|
||||
/**
|
||||
* Handles the notification actions (and later, the same actions from the UI).
|
||||
|
|
@ -42,31 +40,11 @@ class DoseActionReceiver : BroadcastReceiver() {
|
|||
}
|
||||
|
||||
private suspend fun handle(context: Context, action: String, logId: Long) {
|
||||
val db = MedDatabase.get(context)
|
||||
val scheduler = AlarmScheduler(context)
|
||||
val log = db.doseLogDao().getById(logId) ?: return
|
||||
val now = System.currentTimeMillis()
|
||||
|
||||
val actions = DoseActions(context)
|
||||
when (action) {
|
||||
ACTION_TAKEN -> {
|
||||
// Idempotence: double-tap on a laggy notification must not
|
||||
// decrement stock twice.
|
||||
if (log.status == DoseStatus.TAKEN) return
|
||||
db.doseLogDao().setStatus(logId, DoseStatus.TAKEN, now)
|
||||
db.medicationDao().decrementInventory(log.medId, log.amount)
|
||||
scheduler.cancelEscalation(logId)
|
||||
Notifications.cancel(context, Notifications.doseNotificationId(logId))
|
||||
}
|
||||
ACTION_SNOOZE -> {
|
||||
db.doseLogDao().setStatus(logId, DoseStatus.SNOOZED, now)
|
||||
scheduler.armEscalation(logId, delayMinutes = AlarmScheduler.SNOOZE_MINUTES)
|
||||
Notifications.cancel(context, Notifications.doseNotificationId(logId))
|
||||
}
|
||||
ACTION_SKIP -> {
|
||||
db.doseLogDao().setStatus(logId, DoseStatus.SKIPPED, now)
|
||||
scheduler.cancelEscalation(logId)
|
||||
Notifications.cancel(context, Notifications.doseNotificationId(logId))
|
||||
}
|
||||
ACTION_TAKEN -> actions.take(logId)
|
||||
ACTION_SNOOZE -> actions.snooze(logId)
|
||||
ACTION_SKIP -> actions.skip(logId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue