Rx-expiry ongoing alert (7-day lead), configurable morning check, Felleskatalogen links

The daily digest splits in two: low stock stays an auto-cancel
notification re-posted each morning while below the per-item limit;
prescription renewal becomes a separate ONGOING notification starting
7 days before rx expiry — survives 'Clear all', swipe-dismissable on
Android 14+, returns each morning until the rx date is updated, and
cancels itself once renewed (post-or-cancel in SupplyCheckReceiver).
Check time is now configurable (Innstillinger → Varsler, M3 TimePicker,
default 10:00); same PendingIntent so re-arming replaces. 'Slå opp i
Felleskatalogen' buttons on the item editor and the med editor's
summary card open the browser — decision #8 clarified: the ban covers
Felleskatalogen as a data source, not human-facing links.

Emulator-verified: both notifications post with correct flags
(ONGOING_EVENT vs AUTO_CANCEL), auto-clear after renewal/restock,
alarm follows the configured time (10:00 → 07:30), FK button opens
Chrome.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Ole-Morten Duesund 2026-06-11 16:21:25 +02:00
commit 608d84236b
9 changed files with 142 additions and 15 deletions

View file

@ -26,8 +26,6 @@ class AlarmScheduler(private val context: Context) {
const val NAG_CAP = 6
const val SNOOZE_MINUTES = 15L
/** Daily supply/renewal check; lateness is harmless so it's inexact. */
val SUPPLY_CHECK_TIME: LocalTime = LocalTime.of(10, 0)
private const val SUPPLY_REQUEST_CODE = 9_001
}
@ -127,9 +125,15 @@ class AlarmScheduler(private val context: Context) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
/** Inexact daily check at ~10:00; the receiver re-arms the next one. */
/**
* Inexact daily check at the user-configured morning time (default 10:00);
* the receiver re-arms the next one. Same PendingIntent re-arming after a
* settings change replaces the alarm, never stacks.
*/
fun armSupplyCheck() {
var next = LocalDateTime.of(java.time.LocalDate.now(), SUPPLY_CHECK_TIME)
val minute = no.naiv.meddetsamme.settings.SettingsStore(context).supplyCheckMinuteOfDay
val time = LocalTime.of(minute / 60, minute % 60)
var next = LocalDateTime.of(java.time.LocalDate.now(), time)
if (!next.isAfter(LocalDateTime.now())) next = next.plusDays(1)
alarmManager.setAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,