mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
feat: implement weekly meal planning and inventory
- Add Planning module with UI and ViewModel - Update database schema to support planned meals and inventory - Add camera permission for future features - Refactor food category handling to support multiple tags
This commit is contained in:
1 parent
1331fae119
commit
8e794e6da7
46 files changed
+6335
-192
No files matched your search
@@ -0,0 +1,137 @@
|
||||
package com.example.data.model
|
||||
|
||||
import com.example.domain.IngredientMatcher
|
||||
import java.util.UUID
|
||||
|
||||
enum class StorageLocation(val displayName: String) {
|
||||
FRIDGE("Frigo"),
|
||||
FREEZER("Congélateur"),
|
||||
PANTRY("Placard");
|
||||
|
||||
companion object {
|
||||
fun fromString(raw: String?): StorageLocation {
|
||||
if (raw.isNullOrBlank()) return PANTRY
|
||||
val trimmed = raw.trim()
|
||||
return entries.firstOrNull {
|
||||
it.name.equals(trimmed, ignoreCase = true) ||
|
||||
it.displayName.equals(trimmed, ignoreCase = true)
|
||||
} ?: PANTRY
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class PlannedMealEntry(
|
||||
val id: String = "",
|
||||
val dateEpochDay: Long,
|
||||
val mealType: MealType,
|
||||
val recipeId: String? = null,
|
||||
val customTitle: String = "",
|
||||
val servings: Double = 1.0,
|
||||
val itemsSerialized: List<String> = emptyList(),
|
||||
val isConsumed: Boolean = false,
|
||||
val updatedAt: Long = System.currentTimeMillis()
|
||||
) {
|
||||
fun parsedItems(): List<MealFoodItem> {
|
||||
return itemsSerialized.mapNotNull { MealFoodItem.deserialize(it) }
|
||||
}
|
||||
|
||||
fun resolvedTitle(recipesById: Map<String, RecipeEntry>): String {
|
||||
val recipeTitle = recipeId?.let { recipesById[it]?.title }
|
||||
return when {
|
||||
!recipeTitle.isNullOrBlank() -> recipeTitle
|
||||
customTitle.isNotBlank() -> customTitle
|
||||
itemsSerialized.isNotEmpty() -> parsedItems().joinToString(", ") { it.name }
|
||||
else -> mealType.displayName
|
||||
}
|
||||
}
|
||||
|
||||
fun resolvedFoodItems(recipesById: Map<String, RecipeEntry>): List<MealFoodItem> {
|
||||
val recipe = recipeId?.let { recipesById[it] }
|
||||
return if (recipe != null) {
|
||||
recipe.scaledIngredients(servings.coerceAtLeast(0.5))
|
||||
} else {
|
||||
parsedItems()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class InventoryItem(
|
||||
val id: String = "",
|
||||
val name: String,
|
||||
val normalizedName: String = IngredientMatcher.normalize(name),
|
||||
val quantity: Double,
|
||||
val unit: FoodUnit = FoodUnit.G,
|
||||
val category: FoodCategory = FoodCategory.OTHER,
|
||||
val location: StorageLocation = StorageLocation.PANTRY,
|
||||
val updatedAt: Long = System.currentTimeMillis()
|
||||
) {
|
||||
fun formatQuantity(): String = IngredientMatcher.formatQuantity(quantity, unit)
|
||||
}
|
||||
|
||||
data class ManualShoppingItem(
|
||||
val id: String = "",
|
||||
val name: String,
|
||||
val quantity: Double? = null,
|
||||
val unit: FoodUnit = FoodUnit.PORTION,
|
||||
val category: FoodCategory = FoodCategory.OTHER,
|
||||
val isChecked: Boolean = false,
|
||||
val updatedAt: Long = System.currentTimeMillis()
|
||||
) {
|
||||
fun formatQuantity(): String? = quantity?.takeIf { it > 0.0 }?.let {
|
||||
IngredientMatcher.formatQuantity(it, unit)
|
||||
}
|
||||
}
|
||||
|
||||
enum class ShoppingItemSource {
|
||||
FROM_PLAN,
|
||||
MANUAL,
|
||||
BOTH
|
||||
}
|
||||
|
||||
data class ShoppingListItem(
|
||||
val key: String,
|
||||
val name: String,
|
||||
val normalizedName: String,
|
||||
val missingQuantity: Double?,
|
||||
val requiredQuantity: Double?,
|
||||
val inStockQuantity: Double,
|
||||
val unit: FoodUnit,
|
||||
val category: FoodCategory,
|
||||
val source: ShoppingItemSource,
|
||||
val manualItemId: String? = null,
|
||||
val isChecked: Boolean = false,
|
||||
val relatedMealsCount: Int = 0
|
||||
) {
|
||||
fun formatMissingQuantity(): String? = missingQuantity?.takeIf { it > 0.0 }?.let {
|
||||
IngredientMatcher.formatQuantity(it, unit)
|
||||
}
|
||||
|
||||
fun formatInStockQuantity(): String? = inStockQuantity.takeIf { it > 0.0 }?.let {
|
||||
IngredientMatcher.formatQuantity(it, unit)
|
||||
}
|
||||
}
|
||||
|
||||
data class ScannedReceiptItem(
|
||||
val id: String = UUID.randomUUID().toString().take(8),
|
||||
val rawLabel: String,
|
||||
val name: String,
|
||||
val quantity: Double,
|
||||
val unit: FoodUnit = FoodUnit.PORTION,
|
||||
val category: FoodCategory = FoodCategory.OTHER,
|
||||
val location: StorageLocation = StorageLocation.PANTRY,
|
||||
val selected: Boolean = true
|
||||
)
|
||||
|
||||
data class StockDeductionProposal(
|
||||
val inventoryItem: InventoryItem,
|
||||
val deductAmount: Double,
|
||||
val remainingAfter: Double,
|
||||
val selected: Boolean = true
|
||||
)
|
||||
|
||||
sealed interface ReceiptScanUiState {
|
||||
data object Idle : ReceiptScanUiState
|
||||
data object Scanning : ReceiptScanUiState
|
||||
data class Preview(val items: List<ScannedReceiptItem>) : ReceiptScanUiState
|
||||
data class Error(val message: String) : ReceiptScanUiState
|
||||
}
|
||||
Reference in new issue
Block a user