Väg-skärm: behåll mätresultatet vid sparfel (visa fel separat)
All checks were successful
release / build-release (push) Successful in 12m26s
All checks were successful
release / build-release (push) Successful in 12m26s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C2GA94E1f3cmrvdQLQhYdg
This commit is contained in:
@@ -316,6 +316,7 @@ class WeighViewModel(
|
||||
) : ViewModel() {
|
||||
val state = MutableStateFlow<WeighState>(WeighState.Idle)
|
||||
val saved = MutableStateFlow(false)
|
||||
val saveError = MutableStateFlow<String?>(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 ✓",
|
||||
|
||||
Reference in New Issue
Block a user