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

@ -27,6 +27,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import no.naiv.meddetsamme.R
@ -68,6 +70,15 @@ fun ItemEditScreen(nav: Nav, itemId: Long?) {
) {
InventoryItemForm(form)
if (form.name.isNotBlank()) {
TextButton(
onClick = { context.startActivity(felleskatalogenIntent(form.name)) },
modifier = Modifier
.fillMaxWidth()
.semantics { contentDescription = "Slå opp ${form.name} i Felleskatalogen. Åpner nettleseren." },
) { Text("Slå opp i Felleskatalogen ↗") }
}
Button(
onClick = {
val item = form.buildItem(itemId ?: 0) ?: return@Button

View file

@ -71,6 +71,20 @@ fun guessForm(festForm: String): MedForm = when {
fun parseAmount(s: String): Double? = s.trim().replace(',', '.').toDoubleOrNull()
/**
* Browser link to Felleskatalogen's search for a preparation patient-facing
* reading only. Decision #8 bans Felleskatalogen as a DATA source (licensed
* editorial content, no API); pointing the human at their website is fine.
*/
fun felleskatalogenIntent(name: String): android.content.Intent =
android.content.Intent(
android.content.Intent.ACTION_VIEW,
android.net.Uri.parse(
"https://www.felleskatalogen.no/medisin/sok?sokord=" +
java.net.URLEncoder.encode(name.trim(), "UTF-8"),
),
)
/**
* State + validation for an [InventoryItem] form shared between the
* inventory editor and inline item creation in the med editor, so the two

View file

@ -164,6 +164,12 @@ fun MedEditScreen(nav: Nav, initialMedId: Long?) {
"Lager: ${ScheduleText.amountText(item.stockUnits, item.unit)} — rediger varen på Lager-siden",
style = MaterialTheme.typography.bodySmall,
)
TextButton(
onClick = { context.startActivity(felleskatalogenIntent(item.name)) },
modifier = Modifier.semantics {
contentDescription = "Slå opp ${item.name} i Felleskatalogen. Åpner nettleseren."
},
) { Text("Slå opp i Felleskatalogen ↗") }
}
}
}

View file

@ -173,6 +173,10 @@ fun SettingsScreen(nav: Nav) {
modifier = Modifier.fillMaxWidth(),
) { Text("Importer fra fil …") }
HorizontalDivider()
Text("Varsler", style = MaterialTheme.typography.titleMedium)
SupplyCheckTimeRow(settings)
HorizontalDivider()
Text("FEST-legemiddeldata", style = MaterialTheme.typography.titleMedium)
OutlinedTextField(
@ -264,6 +268,48 @@ fun SettingsScreen(nav: Nav) {
}
}
/** Daily low-stock/rx notification time; re-arms the (replacing) alarm on change. */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun SupplyCheckTimeRow(settings: SettingsStore) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var minute by remember { mutableStateOf(settings.supplyCheckMinuteOfDay) }
var showPicker by remember { mutableStateOf(false) }
androidx.compose.foundation.layout.Row(
verticalAlignment = androidx.compose.ui.Alignment.CenterVertically,
) {
Text(
"Daglig varsel om lager og resept: %02d:%02d".format(minute / 60, minute % 60),
modifier = Modifier.weight(1f),
)
TextButton(onClick = { showPicker = true }) { Text("Endre") }
}
if (showPicker) {
val state = androidx.compose.material3.rememberTimePickerState(
initialHour = minute / 60,
initialMinute = minute % 60,
is24Hour = true,
)
AlertDialog(
onDismissRequest = { showPicker = false },
title = { Text("Tidspunkt for daglig varsel") },
text = { androidx.compose.material3.TimePicker(state = state) },
confirmButton = {
TextButton(onClick = {
minute = state.hour * 60 + state.minute
settings.supplyCheckMinuteOfDay = minute
showPicker = false
scope.launch { AlarmScheduler(context).armSupplyCheck() }
}) { Text("OK") }
},
dismissButton = { TextButton(onClick = { showPicker = false }) { Text("Avbryt") } },
)
}
}
@Composable
private fun PassphraseDialog(
title: String,