Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions app/src/main/java/com/pulseloop/ui/screens/MealAnalysisSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -62,6 +63,8 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -290,6 +293,8 @@ fun MealAnalysisDialog(
Column(
Modifier
.fillMaxSize()
// Lift the form above the keyboard so the field being typed in stays visible.
.imePadding()
.verticalScroll(rememberScrollState())
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
Expand Down Expand Up @@ -444,13 +449,28 @@ fun MealAnalysisDialog(
.padding(12.dp),
)
}
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
Text("Review & adjust", fontWeight = FontWeight.SemiBold, color = PulseColors.calories)
EditRow("Name", name) { name = it }
EditRow("Calories (kcal)", calories) { calories = it }
EditRow("Protein (g)", protein) { protein = it }
EditRow("Carbs (g)", carbs) { carbs = it }
EditRow("Fat (g)", fat) { fat = it }
// The name is text, full width, and may wrap: a dish name is often long.
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Meal name") },
modifier = Modifier.fillMaxWidth(),
minLines = 1,
maxLines = 3,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text,
capitalization = KeyboardCapitalization.Sentences,
imeAction = ImeAction.Next,
),
)
NumberField("Calories", "kcal", calories, Modifier.fillMaxWidth()) { calories = it }
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
NumberField("Protein", "g", protein, Modifier.weight(1f)) { protein = it }
NumberField("Carbs", "g", carbs, Modifier.weight(1f)) { carbs = it }
NumberField("Fat", "g", fat, Modifier.weight(1f)) { fat = it }
}
}
val canSave = MealAnalysisLogic.canSave(name, calories)
Button(
Expand Down Expand Up @@ -503,18 +523,24 @@ fun MealAnalysisDialog(
}
}

/**
* A labelled number with its unit inside the field. Only digits and one decimal point get in, so
* the save never meets a value it can't read.
*/
@Composable
private fun EditRow(label: String, value: String, onChange: (String) -> Unit) {
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Text(label, fontSize = 14.sp, color = PulseColors.textSecondary, modifier = Modifier.weight(1f))
OutlinedTextField(
value = value,
onValueChange = onChange,
modifier = Modifier.width(140.dp),
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
)
}
private fun NumberField(label: String, unit: String, value: String, modifier: Modifier, onChange: (String) -> Unit) {
OutlinedTextField(
value = value,
onValueChange = { raw ->
val cleaned = raw.replace(',', '.').filter { it.isDigit() || it == '.' }
if (cleaned.count { it == '.' } <= 1) onChange(cleaned)
},
label = { Text(label, maxLines = 1) },
suffix = { Text(unit, color = PulseColors.textMuted) },
modifier = modifier,
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal, imeAction = ImeAction.Next),
)
}

/** iOS \(Int(value.rounded())) for the review fields (MealAnalysisSheet.swift:273-276). */
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/pulseloop/ui/screens/NutritionScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,19 @@ fun MealLogDialog(
// iOS inlineNotice copy (MealLogSheet.swift:128-130 / :259).
Text(it, fontSize = 12.sp, color = PulseColors.warning)
}
OutlinedTextField(value = name, onValueChange = { name = it }, label = { Text("Name") }, modifier = Modifier.fillMaxWidth(), singleLine = true)
OutlinedTextField(value = name, onValueChange = { name = it }, label = { Text("Name") }, modifier = Modifier.fillMaxWidth(), maxLines = 3, keyboardOptions = androidx.compose.foundation.text.KeyboardOptions(capitalization = androidx.compose.ui.text.input.KeyboardCapitalization.Sentences))
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
listOf("breakfast", "lunch", "dinner", "snack").forEach { t ->
FilterChip(selected = type == t, onClick = { type = t }, label = { Text(t.replaceFirstChar { it.uppercase() }) })
}
}
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OutlinedTextField(value = cal, onValueChange = { cal = it }, label = { Text("kcal") }, modifier = Modifier.weight(1f), singleLine = true)
OutlinedTextField(value = protein, onValueChange = { protein = it }, label = { Text("P(g)") }, modifier = Modifier.weight(1f), singleLine = true)
OutlinedTextField(value = cal, onValueChange = { cal = it }, label = { Text("kcal") }, modifier = Modifier.weight(1f), singleLine = true, keyboardOptions = androidx.compose.foundation.text.KeyboardOptions(keyboardType = androidx.compose.ui.text.input.KeyboardType.Decimal))
OutlinedTextField(value = protein, onValueChange = { protein = it }, label = { Text("P(g)") }, modifier = Modifier.weight(1f), singleLine = true, keyboardOptions = androidx.compose.foundation.text.KeyboardOptions(keyboardType = androidx.compose.ui.text.input.KeyboardType.Decimal))
}
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OutlinedTextField(value = carbs, onValueChange = { carbs = it }, label = { Text("C(g)") }, modifier = Modifier.weight(1f), singleLine = true)
OutlinedTextField(value = fat, onValueChange = { fat = it }, label = { Text("F(g)") }, modifier = Modifier.weight(1f), singleLine = true)
OutlinedTextField(value = carbs, onValueChange = { carbs = it }, label = { Text("C(g)") }, modifier = Modifier.weight(1f), singleLine = true, keyboardOptions = androidx.compose.foundation.text.KeyboardOptions(keyboardType = androidx.compose.ui.text.input.KeyboardType.Decimal))
OutlinedTextField(value = fat, onValueChange = { fat = it }, label = { Text("F(g)") }, modifier = Modifier.weight(1f), singleLine = true, keyboardOptions = androidx.compose.foundation.text.KeyboardOptions(keyboardType = androidx.compose.ui.text.input.KeyboardType.Decimal))
}
}
},
Expand Down
Loading