From f8e8dca0813bfdf4a058f139675acf520a353988 Mon Sep 17 00:00:00 2001 From: Ole-Morten Duesund Date: Wed, 10 Jun 2026 14:58:53 +0200 Subject: [PATCH] Med editor: wrap day chips so the whole week is visible; Enhet follows Form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 7 day chips overflowed the dose-time dialog (no scroll, week cut off) — FlowRow wraps them, with full day names for TalkBack. Enhet auto-fills from Form while it still holds the previous form's default (tablett/kapsel/ml/dråper/doser), killing the apparent Enhet/Form overlap; manual overrides like IU stick. Styrke stays Styrke — it holds '500 mg', which is neither unit nor form. Co-Authored-By: Claude Fable 5 --- .../no/naiv/meddetsamme/ui/MedEditScreen.kt | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/no/naiv/meddetsamme/ui/MedEditScreen.kt b/app/src/main/java/no/naiv/meddetsamme/ui/MedEditScreen.kt index 8a8ee95..17ac40e 100644 --- a/app/src/main/java/no/naiv/meddetsamme/ui/MedEditScreen.kt +++ b/app/src/main/java/no/naiv/meddetsamme/ui/MedEditScreen.kt @@ -3,6 +3,8 @@ package no.naiv.meddetsamme.ui import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth @@ -67,6 +69,19 @@ private val FORM_LABELS = mapOf( MedForm.OTHER to "Annet", ) +/** + * Enhet is what doses and stock COUNT (tablett, ml, …); Form is the + * pharmaceutical form. They coincide for tablets, which made the two fields + * look redundant — so Enhet auto-follows Form while it still holds the + * previous form's default, and stays untouched once manually overridden + * (IU, penner, …). + */ +private val DEFAULT_UNIT = mapOf( + MedForm.TABLET to "tablett", MedForm.CAPSULE to "kapsel", MedForm.LIQUID to "ml", + MedForm.INJECTION to "ml", MedForm.DROPS to "dråper", MedForm.SPRAY to "doser", + MedForm.OTHER to "dose", +) + /** Best-effort mapping of FEST's free-form text to our enum; user can override. */ private fun guessForm(festForm: String): MedForm = when { "tablett" in festForm.lowercase() -> MedForm.TABLET @@ -233,7 +248,12 @@ fun MedEditScreen(nav: Nav, initialMedId: Long?) { ) } - FormDropdown(form) { form = it } + FormDropdown(form) { newForm -> + if (unit.isBlank() || unit == DEFAULT_UNIT[form]) { + unit = DEFAULT_UNIT.getValue(newForm) + } + form = newForm + } Row( verticalAlignment = Alignment.CenterVertically, @@ -434,7 +454,7 @@ private fun ScheduleSection(medId: Long, doseTimes: List, onChanged: ( } } -@OptIn(ExperimentalMaterial3Api::class) +@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) @Composable private fun DoseTimeEditorDialog( medId: Long, @@ -482,9 +502,12 @@ private fun DoseTimeEditorDialog( label = { Text("Antall dager mellom doser") }, singleLine = true, ) } else { - // Monday-first row of toggles; bit 0 = Sunday underneath. - Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) { - listOf(1 to "M", 2 to "T", 3 to "O", 4 to "T", 5 to "F", 6 to "L", 0 to "S") + // Monday-first toggles; bit 0 = Sunday underneath. FlowRow wraps + // so the whole week is visible — a plain Row overflowed the dialog. + FlowRow( + horizontalArrangement = Arrangement.spacedBy(4.dp), + ) { + listOf(1 to "man", 2 to "tir", 3 to "ons", 4 to "tor", 5 to "fre", 6 to "lør", 0 to "søn") .forEach { (bit, label) -> val selected = mask and (1 shl bit) != 0 FilterChip(