diff --git a/app/src/main/java/eu/brassepc/fitnessdroid/ui/scale/ScaleScreens.kt b/app/src/main/java/eu/brassepc/fitnessdroid/ui/scale/ScaleScreens.kt index 7ddc293..c77a815 100644 --- a/app/src/main/java/eu/brassepc/fitnessdroid/ui/scale/ScaleScreens.kt +++ b/app/src/main/java/eu/brassepc/fitnessdroid/ui/scale/ScaleScreens.kt @@ -316,6 +316,7 @@ class WeighViewModel( ) : ViewModel() { val state = MutableStateFlow(WeighState.Idle) val saved = MutableStateFlow(false) + val saveError = MutableStateFlow(null) val missingBodyData = MutableStateFlow(false) init { @@ -353,6 +354,7 @@ class WeighViewModel( fun start() { state.value = WeighState.Working("Söker efter vågen…") saved.value = false + saveError.value = null viewModelScope.launch { missingBodyData.value = !scaleManager.hasBodyData() val ok = scaleManager.connectSavedScale() @@ -368,6 +370,7 @@ class WeighViewModel( viewModelScope.launch { fun pct(v: Float): Double? = if (v > 0f) String.format(java.util.Locale.US, "%.1f", v).toDouble() else null try { + saveError.value = null repo.addBodyMeasurement( weightKg = String.format(java.util.Locale.US, "%.1f", m.weight).toDouble(), dateIso = null, @@ -377,7 +380,7 @@ class WeighViewModel( ) saved.value = true } catch (e: Exception) { - state.value = WeighState.Failed("Kunde inte spara mätningen — offline?") + saveError.value = "Kunde inte spara mätningen — offline? Prova igen." } } } @@ -404,6 +407,7 @@ fun WeighScreen( ) { val state by viewModel.state.collectAsStateWithLifecycle() val saved by viewModel.saved.collectAsStateWithLifecycle() + val saveError by viewModel.saveError.collectAsStateWithLifecycle() val missingBodyData by viewModel.missingBodyData.collectAsStateWithLifecycle() val context = LocalContext.current @@ -519,6 +523,13 @@ fun WeighScreen( ResultRow("Benmassa", m.bone, " kg") ResultRow("Bukfett (index)", m.visceralFat, "") + saveError?.let { + Text( + it, + color = MaterialTheme.colorScheme.error, + style = MaterialTheme.typography.bodySmall, + ) + } if (saved) { Text( "Sparad som kroppsmätning ✓",