mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
feat(planning): implement meal plan prediction engine
Introduce WeeklyMealPredictor and related data models to suggest meals, add prediction state management to the ViewModel, and update the UI to support meal planning automation.
This commit is contained in:
1 parent
8e794e6da7
commit
a2f59f15d4
13 files changed
+2247
-17
No files matched your search
@@ -58,11 +58,13 @@ import com.example.data.model.FoodUnit
|
||||
import com.example.data.model.InventoryItem
|
||||
import com.example.data.model.MealType
|
||||
import com.example.data.model.PlannedMealEntry
|
||||
import com.example.data.model.PredictionMealScope
|
||||
import com.example.data.model.ReceiptScanUiState
|
||||
import com.example.data.model.RecipeEntry
|
||||
import com.example.data.model.ScannedReceiptItem
|
||||
import com.example.data.model.ShoppingListItem
|
||||
import com.example.data.model.StorageLocation
|
||||
import com.example.data.model.WeekPredictionUiState
|
||||
import com.example.util.ImageUtils
|
||||
import java.time.LocalDate
|
||||
|
||||
@@ -82,6 +84,7 @@ fun PlanningScreen(
|
||||
recipes: List<RecipeEntry>,
|
||||
customFoods: List<CustomFoodEntry>,
|
||||
receiptScanState: ReceiptScanUiState,
|
||||
weekPredictionState: WeekPredictionUiState,
|
||||
onPreviousWeek: () -> Unit,
|
||||
onNextWeek: () -> Unit,
|
||||
onGoToCurrentWeek: () -> Unit,
|
||||
@@ -95,8 +98,14 @@ fun PlanningScreen(
|
||||
onAddManualShoppingItem: (name: String, quantity: Double?, unit: FoodUnit, category: FoodCategory) -> Unit,
|
||||
onToggleShoppingItemChecked: (ShoppingListItem, Boolean) -> Unit,
|
||||
onAddShoppingItemToStock: (ShoppingListItem, Double, FoodUnit, StorageLocation) -> Unit,
|
||||
onFinishShoppingAndAddToStock: (List<ShoppingListItem>, Map<String, StorageLocation>) -> Unit,
|
||||
onDeleteManualShoppingItem: (String) -> Unit,
|
||||
onClearCheckedShoppingItems: () -> Unit,
|
||||
onPredictWeekMeals: (PredictionMealScope, Double) -> Unit,
|
||||
onTogglePredictedMeal: (String) -> Unit,
|
||||
onUpdatePredictedMealServings: (String, Double) -> Unit,
|
||||
onConfirmPredictedMeals: () -> Unit,
|
||||
onDismissWeekPrediction: () -> Unit,
|
||||
onScanReceiptUri: (Uri) -> Unit,
|
||||
onUpdateScannedItem: (ScannedReceiptItem) -> Unit,
|
||||
onRemoveScannedItem: (String) -> Unit,
|
||||
@@ -120,6 +129,8 @@ fun PlanningScreen(
|
||||
var pendingCaptureUri by remember { mutableStateOf<Uri?>(null) }
|
||||
|
||||
var shoppingItemForStockPrompt by remember { mutableStateOf<ShoppingListItem?>(null) }
|
||||
var showPredictWeekSheet by rememberSaveable { mutableStateOf(false) }
|
||||
var showShoppingMode by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
val recipesById = remember(recipes) { recipes.associateBy { it.id } }
|
||||
|
||||
@@ -271,6 +282,7 @@ fun PlanningScreen(
|
||||
onPreviousWeek = onPreviousWeek,
|
||||
onNextWeek = onNextWeek,
|
||||
onGoToCurrentWeek = onGoToCurrentWeek,
|
||||
onPredictWeekClick = { showPredictWeekSheet = true },
|
||||
onPlanMealClick = { date, mealType ->
|
||||
editingPlannedMeal = null
|
||||
planTargetDate = date
|
||||
@@ -306,6 +318,7 @@ fun PlanningScreen(
|
||||
PlanningSubTab.SHOPPING -> {
|
||||
ShoppingListTab(
|
||||
shoppingItems = shoppingItems,
|
||||
hasPlannedMeals = plannedMeals.isNotEmpty(),
|
||||
onAddManualItem = onAddManualShoppingItem,
|
||||
onToggleItemChecked = { item, nowChecked ->
|
||||
if (nowChecked) {
|
||||
@@ -316,7 +329,12 @@ fun PlanningScreen(
|
||||
},
|
||||
onDeleteManualItem = onDeleteManualShoppingItem,
|
||||
onClearChecked = onClearCheckedShoppingItems,
|
||||
onScanReceiptClick = { showReceiptSourceDialog = true }
|
||||
onScanReceiptClick = { showReceiptSourceDialog = true },
|
||||
onOpenShoppingModeClick = { showShoppingMode = true },
|
||||
onPredictWeekClick = {
|
||||
activeSubTab = PlanningSubTab.WEEK
|
||||
showPredictWeekSheet = true
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -456,6 +474,41 @@ fun PlanningScreen(
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// AI Weekly Meal Prediction Sheet
|
||||
if (showPredictWeekSheet || weekPredictionState !is WeekPredictionUiState.Idle) {
|
||||
PredictWeekSheet(
|
||||
weekStartDate = weekStartDate,
|
||||
existingWeekMeals = plannedMeals,
|
||||
predictionState = weekPredictionState,
|
||||
onGenerate = { scope, servings -> onPredictWeekMeals(scope, servings) },
|
||||
onToggleProposal = onTogglePredictedMeal,
|
||||
onUpdateServings = onUpdatePredictedMealServings,
|
||||
onConfirm = {
|
||||
onConfirmPredictedMeals()
|
||||
showPredictWeekSheet = false
|
||||
},
|
||||
onResetToConfig = { onDismissWeekPrediction() },
|
||||
onDismiss = {
|
||||
showPredictWeekSheet = false
|
||||
onDismissWeekPrediction()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Fullscreen In-Store Shopping Mode
|
||||
if (showShoppingMode) {
|
||||
ShoppingModeScreen(
|
||||
shoppingItems = shoppingItems,
|
||||
onToggleItemChecked = onToggleShoppingItemChecked,
|
||||
onAddQuickItem = { name, category ->
|
||||
onAddManualShoppingItem(name, null, FoodUnit.PORTION, category)
|
||||
},
|
||||
onFinishAndAddToStock = onFinishShoppingAndAddToStock,
|
||||
onScanReceiptInstead = { showReceiptSourceDialog = true },
|
||||
onDismiss = { showShoppingMode = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -473,7 +526,7 @@ private fun AddPurchasedItemToStockDialog(
|
||||
}
|
||||
var selectedUnit by remember(item.key) { mutableStateOf(item.unit) }
|
||||
var selectedLocation by remember(item.key) {
|
||||
mutableStateOf(suggestStorageLocation(item.category))
|
||||
mutableStateOf(StorageLocation.defaultForCategory(item.category))
|
||||
}
|
||||
|
||||
val parsedQty = qtyText.replace(',', '.').toDoubleOrNull()?.takeIf { it > 0.0 }
|
||||
@@ -554,13 +607,3 @@ private fun AddPurchasedItemToStockDialog(
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun suggestStorageLocation(category: FoodCategory): StorageLocation {
|
||||
return when (category) {
|
||||
FoodCategory.PROTEIN,
|
||||
FoodCategory.DAIRY,
|
||||
FoodCategory.CHEESE,
|
||||
FoodCategory.VEGETABLE -> StorageLocation.FRIDGE
|
||||
else -> StorageLocation.PANTRY
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user