mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
- 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.
67 lines
2.3 KiB
Kotlin
67 lines
2.3 KiB
Kotlin
package com.example.util
|
|
|
|
import com.example.data.model.HungerSatietyScale
|
|
import com.example.data.model.MealEntry
|
|
import com.example.data.model.MealType
|
|
import java.time.Instant
|
|
import java.time.ZoneId
|
|
import java.time.format.DateTimeFormatter
|
|
import java.util.Locale
|
|
|
|
object GoogleSheetsDataFormatter {
|
|
|
|
val HEADERS: List<String> = listOf(
|
|
"Date",
|
|
"Heure",
|
|
"Type de repas",
|
|
"Faim avant (/10)",
|
|
"Ressenti faim",
|
|
"Satiété après (/10)",
|
|
"Ressenti satiété",
|
|
"Aliments & Poids",
|
|
"Note globale",
|
|
"Photos jointes"
|
|
)
|
|
|
|
private val dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRENCH)
|
|
private val timeFormatter = DateTimeFormatter.ofPattern("HH:mm", Locale.FRENCH)
|
|
|
|
fun formatMealsToRows(meals: List<MealEntry>, zoneId: ZoneId = ZoneId.systemDefault()): List<List<Any>> {
|
|
val rows = mutableListOf<List<Any>>()
|
|
// Header row
|
|
rows.add(HEADERS)
|
|
|
|
// Sorted by descending timestamp (most recent first)
|
|
val sortedMeals = meals.sortedByDescending { it.mealTimestamp }
|
|
|
|
for (meal in sortedMeals) {
|
|
val zonedDateTime = Instant.ofEpochMilli(meal.mealTimestamp).atZone(zoneId)
|
|
val dateStr = dateFormatter.format(zonedDateTime)
|
|
val timeStr = timeFormatter.format(zonedDateTime)
|
|
val mealTypeLabel = MealType.fromString(meal.mealType).displayName
|
|
val hungerLabel = HungerSatietyScale.getHungerLabel(meal.hungerBefore)
|
|
val satietyLabel = HungerSatietyScale.getSatietyLabel(meal.satietyAfter)
|
|
val foodsFormatted = meal.parsedFoodItems().joinToString(" ; ") { it.displayCsv() }
|
|
val cleanNote = meal.note.replace("\r\n", " ").replace("\n", " ").trim()
|
|
val photosCount = meal.displayPhotoUris.size
|
|
|
|
rows.add(
|
|
listOf(
|
|
dateStr,
|
|
timeStr,
|
|
mealTypeLabel,
|
|
meal.hungerBefore,
|
|
hungerLabel,
|
|
meal.satietyAfter,
|
|
satietyLabel,
|
|
foodsFormatted,
|
|
cleanNote,
|
|
photosCount
|
|
)
|
|
)
|
|
}
|
|
|
|
return rows
|
|
}
|
|
}
|