mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
feat: support meal photo URIs and improve UI events
- Add `photoUris` field to `MealEntry` and update Firestore rules. - Implement `UiEvent` handling in `MainActivity` for navigation/links. - Remove sensitive email data from error logs and clean up manifest.
This commit is contained in:
1 parent
f0487453c9
commit
87bbb448c2
34 files changed
+2026
-1170
No files matched your search
@@ -2,6 +2,7 @@ package com.example.ui.journal
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.compose.foundation.Image
|
||||
import coil.compose.AsyncImage
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
@@ -64,9 +65,10 @@ import com.example.data.model.HungerSatietyScale
|
||||
import com.example.data.model.MealEntry
|
||||
import com.example.data.model.MealType
|
||||
import com.example.util.ImageUtils
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.Locale
|
||||
|
||||
@Composable
|
||||
@@ -115,14 +117,10 @@ fun JournalScreen(
|
||||
|
||||
is MealsUiState.Success -> {
|
||||
val meals = mealsUiState.meals
|
||||
val todayCalendar = Calendar.getInstance().apply {
|
||||
set(Calendar.HOUR_OF_DAY, 0)
|
||||
set(Calendar.MINUTE, 0)
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
}
|
||||
val todayStartMillis = todayCalendar.timeInMillis
|
||||
val todayEndMillis = todayStartMillis + (24L * 60 * 60 * 1000) - 1
|
||||
val zoneId = ZoneId.systemDefault()
|
||||
val todayLocalDate = LocalDate.now(zoneId)
|
||||
val todayStartMillis = todayLocalDate.atStartOfDay(zoneId).toInstant().toEpochMilli()
|
||||
val todayEndMillis = todayLocalDate.plusDays(1).atStartOfDay(zoneId).toInstant().toEpochMilli() - 1
|
||||
val todayMeals = meals.filter { it.mealTimestamp in todayStartMillis..todayEndMillis }
|
||||
|
||||
LazyColumn(
|
||||
@@ -236,9 +234,9 @@ fun JournalScreen(
|
||||
|
||||
@Composable
|
||||
private fun DailyOverviewCard(todayMeals: List<MealEntry>) {
|
||||
val dateFormat = remember { SimpleDateFormat("EEEE d MMMM", Locale.FRENCH) }
|
||||
val dateFormatter = remember { DateTimeFormatter.ofPattern("EEEE d MMMM", Locale.FRENCH) }
|
||||
val todayFormatted = remember {
|
||||
dateFormat.format(Date()).replaceFirstChar {
|
||||
dateFormatter.format(LocalDate.now()).replaceFirstChar {
|
||||
if (it.isLowerCase()) it.titlecase(Locale.FRENCH) else it.toString()
|
||||
}
|
||||
}
|
||||
@@ -338,7 +336,8 @@ private fun MealCardItem(
|
||||
) {
|
||||
var showMenu by remember { mutableStateOf(false) }
|
||||
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||
val dateTimeFormat = remember { SimpleDateFormat("EEE d MMM yyyy • HH:mm", Locale.FRENCH) }
|
||||
val dateTimeFormatter = remember { DateTimeFormatter.ofPattern("EEE d MMM yyyy • HH:mm", Locale.FRENCH) }
|
||||
val zoneId = remember { ZoneId.systemDefault() }
|
||||
val mealType = MealType.fromString(meal.mealType)
|
||||
val parsedFoods = remember(meal.foodItemsSerialized) { meal.parsedFoodItems() }
|
||||
|
||||
@@ -397,7 +396,7 @@ private fun MealCardItem(
|
||||
)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
Text(
|
||||
text = dateTimeFormat.format(Date(meal.mealTimestamp)).replaceFirstChar {
|
||||
text = dateTimeFormatter.format(Instant.ofEpochMilli(meal.mealTimestamp).atZone(zoneId)).replaceFirstChar {
|
||||
if (it.isLowerCase()) it.titlecase(Locale.FRENCH) else it.toString()
|
||||
},
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
@@ -544,23 +543,20 @@ private fun MealCardItem(
|
||||
}
|
||||
|
||||
// Photos Carousel
|
||||
if (meal.photosBase64.isNotEmpty()) {
|
||||
if (meal.displayPhotoUris.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.height(14.dp))
|
||||
LazyRow(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
items(meal.photosBase64) { b64 ->
|
||||
val bitmap: Bitmap? = remember(b64) { ImageUtils.base64ToBitmap(b64) }
|
||||
if (bitmap != null) {
|
||||
Image(
|
||||
bitmap = bitmap.asImageBitmap(),
|
||||
contentDescription = "Photo assiette",
|
||||
modifier = Modifier
|
||||
.size(76.dp)
|
||||
.clip(RoundedCornerShape(12.dp)),
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
}
|
||||
items(meal.displayPhotoUris) { photoUri ->
|
||||
AsyncImage(
|
||||
model = photoUri,
|
||||
contentDescription = "Photo du repas",
|
||||
modifier = Modifier
|
||||
.size(76.dp)
|
||||
.clip(RoundedCornerShape(12.dp)),
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user