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() {
|
) : ViewModel() {
|
||||||
val state = MutableStateFlow<WeighState>(WeighState.Idle)
|
val state = MutableStateFlow<WeighState>(WeighState.Idle)
|
||||||
val saved = MutableStateFlow(false)
|
val saved = MutableStateFlow(false)
|
||||||
|
val saveError = MutableStateFlow<String?>(null)
|
||||||
val missingBodyData = MutableStateFlow(false)
|
val missingBodyData = MutableStateFlow(false)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -353,6 +354,7 @@ class WeighViewModel(
|
|||||||
fun start() {
|
fun start() {
|
||||||
state.value = WeighState.Working("Söker efter vågen…")
|
state.value = WeighState.Working("Söker efter vågen…")
|
||||||
saved.value = false
|
saved.value = false
|
||||||
|
saveError.value = null
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
missingBodyData.value = !scaleManager.hasBodyData()
|
missingBodyData.value = !scaleManager.hasBodyData()
|
||||||
val ok = scaleManager.connectSavedScale()
|
val ok = scaleManager.connectSavedScale()
|
||||||
@@ -368,6 +370,7 @@ class WeighViewModel(
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
fun pct(v: Float): Double? = if (v > 0f) String.format(java.util.Locale.US, "%.1f", v).toDouble() else null
|
fun pct(v: Float): Double? = if (v > 0f) String.format(java.util.Locale.US, "%.1f", v).toDouble() else null
|
||||||
try {
|
try {
|
||||||
|
saveError.value = null
|
||||||
repo.addBodyMeasurement(
|
repo.addBodyMeasurement(
|
||||||
weightKg = String.format(java.util.Locale.US, "%.1f", m.weight).toDouble(),
|
weightKg = String.format(java.util.Locale.US, "%.1f", m.weight).toDouble(),
|
||||||
dateIso = null,
|
dateIso = null,
|
||||||
@@ -377,7 +380,7 @@ class WeighViewModel(
|
|||||||
)
|
)
|
||||||
saved.value = true
|
saved.value = true
|
||||||
} catch (e: Exception) {
|
} 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 state by viewModel.state.collectAsStateWithLifecycle()
|
||||||
val saved by viewModel.saved.collectAsStateWithLifecycle()
|
val saved by viewModel.saved.collectAsStateWithLifecycle()
|
||||||
|
val saveError by viewModel.saveError.collectAsStateWithLifecycle()
|
||||||
val missingBodyData by viewModel.missingBodyData.collectAsStateWithLifecycle()
|
val missingBodyData by viewModel.missingBodyData.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@@ -519,6 +523,13 @@ fun WeighScreen(
|
|||||||
ResultRow("Benmassa", m.bone, " kg")
|
ResultRow("Benmassa", m.bone, " kg")
|
||||||
ResultRow("Bukfett (index)", m.visceralFat, "")
|
ResultRow("Bukfett (index)", m.visceralFat, "")
|
||||||
|
|
||||||
|
saveError?.let {
|
||||||
|
Text(
|
||||||
|
it,
|
||||||
|
color = MaterialTheme.colorScheme.error,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
)
|
||||||
|
}
|
||||||
if (saved) {
|
if (saved) {
|
||||||
Text(
|
Text(
|
||||||
"Sparad som kroppsmätning ✓",
|
"Sparad som kroppsmätning ✓",
|
||||||
|
|||||||
Reference in New Issue
Block a user