mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
- 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
828 lines
36 KiB
Kotlin
828 lines
36 KiB
Kotlin
package com.example.ui.recipes
|
|
|
|
import androidx.compose.animation.AnimatedVisibility
|
|
import androidx.compose.foundation.BorderStroke
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
|
import androidx.compose.foundation.layout.FlowRow
|
|
import androidx.compose.foundation.layout.PaddingValues
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.Spacer
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.size
|
|
import androidx.compose.foundation.layout.width
|
|
import androidx.compose.foundation.lazy.LazyListScope
|
|
import androidx.compose.foundation.lazy.LazyRow
|
|
import androidx.compose.foundation.lazy.items
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.filled.AutoAwesome
|
|
import androidx.compose.material.icons.filled.Block
|
|
import androidx.compose.material.icons.filled.BookmarkAdded
|
|
import androidx.compose.material.icons.filled.BookmarkBorder
|
|
import androidx.compose.material.icons.filled.Check
|
|
import androidx.compose.material.icons.filled.ErrorOutline
|
|
import androidx.compose.material.icons.filled.ExpandLess
|
|
import androidx.compose.material.icons.filled.ExpandMore
|
|
import androidx.compose.material.icons.filled.Favorite
|
|
import androidx.compose.material.icons.filled.FavoriteBorder
|
|
import androidx.compose.material.icons.filled.People
|
|
import androidx.compose.material.icons.filled.Refresh
|
|
import androidx.compose.material.icons.filled.Restaurant
|
|
import androidx.compose.material.icons.filled.Schedule
|
|
import androidx.compose.material3.Button
|
|
import androidx.compose.material3.ButtonDefaults
|
|
import androidx.compose.material3.Card
|
|
import androidx.compose.material3.CardDefaults
|
|
import androidx.compose.material3.CircularProgressIndicator
|
|
import androidx.compose.material3.FilledTonalButton
|
|
import androidx.compose.material3.FilterChip
|
|
import androidx.compose.material3.FilterChipDefaults
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.OutlinedButton
|
|
import androidx.compose.material3.OutlinedTextField
|
|
import androidx.compose.material3.Surface
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.TextButton
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.saveable.rememberSaveable
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.platform.testTag
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
import androidx.compose.ui.unit.dp
|
|
import com.example.data.model.CustomFoodEntry
|
|
import com.example.data.model.DiscoverySuggestion
|
|
import com.example.data.model.FoodCategory
|
|
import com.example.data.model.FoodPreferenceEntry
|
|
import com.example.data.model.FoodPreferenceStatus
|
|
import com.example.data.model.MealType
|
|
import com.example.data.model.RecipeSuggestion
|
|
import com.example.data.model.SuggestionUiState
|
|
import com.example.domain.DailyBenchmarkGap
|
|
import com.example.ui.common.FoodCategoryColorDot
|
|
import com.example.ui.common.FoodCategoryColorDotsRow
|
|
import com.example.ui.common.badgeBorderColor
|
|
import com.example.ui.common.badgeContainerColor
|
|
import com.example.ui.common.badgeTextColor
|
|
import com.example.ui.common.isSatieaDarkTheme
|
|
|
|
fun LazyListScope.ideasAndTastesItems(
|
|
preferences: List<FoodPreferenceEntry>,
|
|
customFoods: List<CustomFoodEntry>,
|
|
selectedMealType: MealType,
|
|
benchmarkGap: DailyBenchmarkGap,
|
|
suggestionUiState: SuggestionUiState,
|
|
savedSuggestionIds: Set<String>,
|
|
cravingNote: String,
|
|
onCravingNoteChange: (String) -> Unit,
|
|
onSelectMealType: (MealType) -> Unit,
|
|
onSavePreference: (name: String, status: FoodPreferenceStatus, category: FoodCategory?) -> Unit,
|
|
onRemovePreference: (slugId: String) -> Unit,
|
|
onGenerateIdeas: () -> Unit,
|
|
onSaveSuggestedRecipe: (RecipeSuggestion) -> Unit,
|
|
onLogSuggestedRecipe: (RecipeSuggestion, MealType) -> Unit,
|
|
onLikeRecipeIngredients: (RecipeSuggestion) -> Unit
|
|
) {
|
|
// 1. Taste Profile Editor Card
|
|
item(key = "taste_profile_card") {
|
|
TasteProfileCard(
|
|
preferences = preferences,
|
|
customFoods = customFoods,
|
|
onSavePreference = onSavePreference,
|
|
onRemovePreference = onRemovePreference
|
|
)
|
|
}
|
|
|
|
// 2. Daily Benchmarks Context & Generator Card
|
|
item(key = "benchmark_generator_card") {
|
|
BenchmarkGeneratorCard(
|
|
selectedMealType = selectedMealType,
|
|
benchmarkGap = benchmarkGap,
|
|
cravingNote = cravingNote,
|
|
isLoading = suggestionUiState is SuggestionUiState.Loading,
|
|
onCravingNoteChange = onCravingNoteChange,
|
|
onSelectMealType = onSelectMealType,
|
|
onGenerateIdeas = onGenerateIdeas
|
|
)
|
|
}
|
|
|
|
// 3. Results Section
|
|
when (suggestionUiState) {
|
|
is SuggestionUiState.Idle -> {
|
|
item(key = "ideas_idle_hint") {
|
|
Surface(
|
|
shape = RoundedCornerShape(18.dp),
|
|
color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.35f),
|
|
modifier = Modifier.fillMaxWidth()
|
|
) {
|
|
Column(
|
|
modifier = Modifier.padding(18.dp),
|
|
verticalArrangement = Arrangement.spacedBy(6.dp)
|
|
) {
|
|
Text(
|
|
text = "Votre inspiration sur mesure",
|
|
style = MaterialTheme.typography.titleSmall,
|
|
color = MaterialTheme.colorScheme.onSurface,
|
|
fontWeight = FontWeight.Bold
|
|
)
|
|
Text(
|
|
text = "Satiéa croise vos aliments aimés, vos exclusions et vos repères manquants du jour pour imaginer des recettes simples et de nouvelles idées à goûter — sans calcul de calories.",
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
is SuggestionUiState.Loading -> {
|
|
item(key = "ideas_loading_card") {
|
|
Card(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.testTag("ideas_loading_card"),
|
|
shape = RoundedCornerShape(20.dp),
|
|
colors = CardDefaults.cardColors(
|
|
containerColor = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.4f)
|
|
)
|
|
) {
|
|
Row(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(20.dp),
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
|
) {
|
|
CircularProgressIndicator(
|
|
modifier = Modifier.size(28.dp),
|
|
strokeWidth = 3.dp,
|
|
color = MaterialTheme.colorScheme.primary
|
|
)
|
|
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
|
Text(
|
|
text = "Préparation de vos idées…",
|
|
style = MaterialTheme.typography.titleSmall,
|
|
color = MaterialTheme.colorScheme.onSurface,
|
|
fontWeight = FontWeight.Bold
|
|
)
|
|
Text(
|
|
text = "Analyse de vos goûts et de vos repères pour ce ${selectedMealType.displayName.lowercase()}.",
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
is SuggestionUiState.Error -> {
|
|
item(key = "ideas_error_card") {
|
|
Card(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.testTag("ideas_error_card"),
|
|
shape = RoundedCornerShape(20.dp),
|
|
colors = CardDefaults.cardColors(
|
|
containerColor = MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.65f)
|
|
)
|
|
) {
|
|
Column(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(18.dp),
|
|
verticalArrangement = Arrangement.spacedBy(10.dp)
|
|
) {
|
|
Row(
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
) {
|
|
Icon(
|
|
imageVector = Icons.Default.ErrorOutline,
|
|
contentDescription = null,
|
|
tint = MaterialTheme.colorScheme.onErrorContainer
|
|
)
|
|
Text(
|
|
text = "Génération interrompue",
|
|
style = MaterialTheme.typography.titleSmall,
|
|
color = MaterialTheme.colorScheme.onErrorContainer,
|
|
fontWeight = FontWeight.Bold
|
|
)
|
|
}
|
|
Text(
|
|
text = suggestionUiState.message,
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onErrorContainer
|
|
)
|
|
FilledTonalButton(
|
|
onClick = onGenerateIdeas,
|
|
modifier = Modifier.testTag("ideas_retry_button")
|
|
) {
|
|
Icon(
|
|
imageVector = Icons.Default.Refresh,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(16.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(6.dp))
|
|
Text("Réessayer")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
is SuggestionUiState.Success -> {
|
|
if (suggestionUiState.contextSummary.isNotBlank()) {
|
|
item(key = "ideas_context_summary") {
|
|
Surface(
|
|
shape = RoundedCornerShape(16.dp),
|
|
color = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.5f),
|
|
modifier = Modifier.fillMaxWidth()
|
|
) {
|
|
Text(
|
|
text = suggestionUiState.contextSummary,
|
|
style = MaterialTheme.typography.bodyMedium,
|
|
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
modifier = Modifier.padding(14.dp)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (suggestionUiState.recipes.isNotEmpty()) {
|
|
item(key = "ideas_recipes_header") {
|
|
Text(
|
|
text = "Idées de recettes sur mesure",
|
|
style = MaterialTheme.typography.titleLarge,
|
|
color = MaterialTheme.colorScheme.onBackground,
|
|
fontWeight = FontWeight.Bold,
|
|
modifier = Modifier.padding(top = 4.dp)
|
|
)
|
|
}
|
|
|
|
items(suggestionUiState.recipes, key = { it.id }) { suggestion ->
|
|
SuggestedRecipeCard(
|
|
suggestion = suggestion,
|
|
isSaved = suggestion.id in savedSuggestionIds,
|
|
onSaveToBook = { onSaveSuggestedRecipe(suggestion) },
|
|
onLogToJournal = { onLogSuggestedRecipe(suggestion, suggestionUiState.targetMealType) },
|
|
onLikeIngredients = { onLikeRecipeIngredients(suggestion) }
|
|
)
|
|
}
|
|
}
|
|
|
|
if (suggestionUiState.discoveries.isNotEmpty()) {
|
|
item(key = "ideas_discoveries_header") {
|
|
Column(modifier = Modifier.padding(top = 6.dp)) {
|
|
Text(
|
|
text = "Nouvelles découvertes à tester",
|
|
style = MaterialTheme.typography.titleLarge,
|
|
color = MaterialTheme.colorScheme.onBackground,
|
|
fontWeight = FontWeight.Bold
|
|
)
|
|
Text(
|
|
text = "Pour varier vos assiettes et enrichir vos repères en douceur",
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.7f)
|
|
)
|
|
}
|
|
}
|
|
|
|
items(suggestionUiState.discoveries, key = { it.id }) { discovery ->
|
|
val slug = FoodPreferenceEntry.buildSlugId(discovery.foodName)
|
|
val existingStatus = preferences.firstOrNull { it.slugId == slug }?.status
|
|
DiscoverySuggestionCard(
|
|
discovery = discovery,
|
|
currentStatus = existingStatus,
|
|
onSetStatus = { newStatus ->
|
|
onSavePreference(discovery.foodName, newStatus, discovery.category)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@OptIn(ExperimentalLayoutApi::class)
|
|
@Composable
|
|
private fun BenchmarkGeneratorCard(
|
|
selectedMealType: MealType,
|
|
benchmarkGap: DailyBenchmarkGap,
|
|
cravingNote: String,
|
|
isLoading: Boolean,
|
|
onCravingNoteChange: (String) -> Unit,
|
|
onSelectMealType: (MealType) -> Unit,
|
|
onGenerateIdeas: () -> Unit
|
|
) {
|
|
val isDark = isSatieaDarkTheme()
|
|
|
|
Card(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.testTag("benchmark_generator_card"),
|
|
shape = RoundedCornerShape(22.dp),
|
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
|
|
border = BorderStroke(1.dp, MaterialTheme.colorScheme.primary.copy(alpha = 0.3f))
|
|
) {
|
|
Column(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(18.dp),
|
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
|
) {
|
|
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
|
Text(
|
|
text = "Repères du jour à compléter",
|
|
style = MaterialTheme.typography.titleLarge,
|
|
color = MaterialTheme.colorScheme.onSurface,
|
|
fontWeight = FontWeight.Bold
|
|
)
|
|
Text(
|
|
text = benchmarkGap.gentleSummary,
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
)
|
|
}
|
|
|
|
// Meal type selector row
|
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
items(MealType.entries, key = { it.name }) { type ->
|
|
FilterChip(
|
|
selected = selectedMealType == type,
|
|
onClick = { onSelectMealType(type) },
|
|
label = { Text(type.displayName) },
|
|
colors = FilterChipDefaults.filterChipColors(
|
|
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
|
|
selectedLabelColor = MaterialTheme.colorScheme.onPrimaryContainer
|
|
),
|
|
modifier = Modifier.testTag("idea_meal_type_${type.name.lowercase()}")
|
|
)
|
|
}
|
|
}
|
|
|
|
// Visual badges of priority categories to complete
|
|
if (benchmarkGap.priorityMissingCategories.isNotEmpty()) {
|
|
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
|
Text(
|
|
text = "Pistes ciblées pour ce repas :",
|
|
style = MaterialTheme.typography.labelMedium,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
fontWeight = FontWeight.SemiBold
|
|
)
|
|
FlowRow(
|
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
|
verticalArrangement = Arrangement.spacedBy(6.dp)
|
|
) {
|
|
benchmarkGap.priorityMissingCategories.forEach { cat ->
|
|
Surface(
|
|
shape = RoundedCornerShape(10.dp),
|
|
color = cat.badgeContainerColor(isDark),
|
|
border = BorderStroke(1.dp, cat.badgeBorderColor(isDark))
|
|
) {
|
|
Row(
|
|
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp),
|
|
verticalAlignment = Alignment.CenterVertically
|
|
) {
|
|
FoodCategoryColorDot(category = cat, size = 7.dp)
|
|
Spacer(modifier = Modifier.width(5.dp))
|
|
Text(
|
|
text = cat.shortLabel,
|
|
style = MaterialTheme.typography.labelSmall,
|
|
color = cat.badgeTextColor(isDark),
|
|
fontWeight = FontWeight.Medium
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Optional craving / mood input
|
|
OutlinedTextField(
|
|
value = cravingNote,
|
|
onValueChange = { if (it.length <= 100) onCravingNoteChange(it) },
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.testTag("idea_craving_input"),
|
|
placeholder = { Text("Envie du moment (optionnel : rapide 15 min, chaud, sucré-salé…)") },
|
|
singleLine = true,
|
|
shape = RoundedCornerShape(14.dp)
|
|
)
|
|
|
|
// Primary Generate CTA
|
|
Button(
|
|
onClick = onGenerateIdeas,
|
|
enabled = !isLoading,
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.height(52.dp)
|
|
.testTag("generate_ideas_button"),
|
|
shape = RoundedCornerShape(16.dp),
|
|
colors = ButtonDefaults.buttonColors(
|
|
containerColor = MaterialTheme.colorScheme.primary,
|
|
contentColor = MaterialTheme.colorScheme.onPrimary
|
|
)
|
|
) {
|
|
if (isLoading) {
|
|
CircularProgressIndicator(
|
|
modifier = Modifier.size(18.dp),
|
|
strokeWidth = 2.dp,
|
|
color = MaterialTheme.colorScheme.onPrimary
|
|
)
|
|
Spacer(modifier = Modifier.width(10.dp))
|
|
Text("Recherche d'idées en cours…")
|
|
} else {
|
|
Icon(
|
|
imageVector = Icons.Default.AutoAwesome,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(18.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(8.dp))
|
|
Text(
|
|
text = "Proposer des idées & découvertes",
|
|
style = MaterialTheme.typography.labelLarge
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@OptIn(ExperimentalLayoutApi::class)
|
|
@Composable
|
|
private fun SuggestedRecipeCard(
|
|
suggestion: RecipeSuggestion,
|
|
isSaved: Boolean,
|
|
onSaveToBook: () -> Unit,
|
|
onLogToJournal: () -> Unit,
|
|
onLikeIngredients: () -> Unit
|
|
) {
|
|
val isDark = isSatieaDarkTheme()
|
|
var stepsExpanded by rememberSaveable(suggestion.id) { mutableStateOf(false) }
|
|
|
|
Card(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.testTag("suggested_recipe_card_${suggestion.id}"),
|
|
shape = RoundedCornerShape(22.dp),
|
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
|
|
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.35f))
|
|
) {
|
|
Column(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(18.dp),
|
|
verticalArrangement = Arrangement.spacedBy(10.dp)
|
|
) {
|
|
// Tag + Time + Servings row
|
|
Row(
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
|
) {
|
|
Surface(
|
|
shape = RoundedCornerShape(9.dp),
|
|
color = MaterialTheme.colorScheme.primaryContainer
|
|
) {
|
|
Text(
|
|
text = suggestion.categoryTag.displayName,
|
|
style = MaterialTheme.typography.labelSmall,
|
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
fontWeight = FontWeight.Bold,
|
|
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp)
|
|
)
|
|
}
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
Icon(
|
|
imageVector = Icons.Default.Schedule,
|
|
contentDescription = null,
|
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
modifier = Modifier.size(14.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(4.dp))
|
|
Text(
|
|
text = "${suggestion.prepTimeMinutes} min",
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
)
|
|
}
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
Icon(
|
|
imageVector = Icons.Default.People,
|
|
contentDescription = null,
|
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
modifier = Modifier.size(14.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(4.dp))
|
|
Text(
|
|
text = "${suggestion.servings} portion${if (suggestion.servings > 1) "s" else ""}",
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
)
|
|
}
|
|
}
|
|
|
|
Text(
|
|
text = suggestion.title,
|
|
style = MaterialTheme.typography.titleLarge,
|
|
color = MaterialTheme.colorScheme.onSurface,
|
|
fontWeight = FontWeight.Bold
|
|
)
|
|
|
|
if (suggestion.whyItFits.isNotBlank()) {
|
|
Text(
|
|
text = suggestion.whyItFits,
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
)
|
|
}
|
|
|
|
// Completed dietary benchmark badges
|
|
if (suggestion.completedCategories.isNotEmpty()) {
|
|
FlowRow(
|
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
|
verticalArrangement = Arrangement.spacedBy(6.dp)
|
|
) {
|
|
suggestion.completedCategories.forEach { cat ->
|
|
Surface(
|
|
shape = RoundedCornerShape(9.dp),
|
|
color = cat.badgeContainerColor(isDark),
|
|
border = BorderStroke(1.dp, cat.badgeBorderColor(isDark))
|
|
) {
|
|
Row(
|
|
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp),
|
|
verticalAlignment = Alignment.CenterVertically
|
|
) {
|
|
FoodCategoryColorDot(category = cat, size = 7.dp)
|
|
Spacer(modifier = Modifier.width(5.dp))
|
|
Text(
|
|
text = cat.shortLabel,
|
|
style = MaterialTheme.typography.labelSmall,
|
|
color = cat.badgeTextColor(isDark),
|
|
fontWeight = FontWeight.Medium
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Color-coded ingredients list
|
|
if (suggestion.ingredients.isNotEmpty()) {
|
|
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
|
Text(
|
|
text = "Ingrédients (${suggestion.servings} portion${if (suggestion.servings > 1) "s" else ""})",
|
|
style = MaterialTheme.typography.labelMedium,
|
|
color = MaterialTheme.colorScheme.onSurface,
|
|
fontWeight = FontWeight.SemiBold
|
|
)
|
|
suggestion.ingredients.forEach { item ->
|
|
Row(
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
) {
|
|
FoodCategoryColorDotsRow(
|
|
categories = item.resolvedCategories(),
|
|
dotSize = 8.dp,
|
|
spacing = 2.dp
|
|
)
|
|
Text(
|
|
text = item.displayBadge(),
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurface
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Expandable steps
|
|
if (suggestion.steps.isNotEmpty()) {
|
|
Row(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.clickable { stepsExpanded = !stepsExpanded }
|
|
.padding(vertical = 4.dp),
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
horizontalArrangement = Arrangement.SpaceBetween
|
|
) {
|
|
Text(
|
|
text = if (stepsExpanded) "Masquer les étapes" else "Voir les ${suggestion.steps.size} étapes de préparation",
|
|
style = MaterialTheme.typography.labelMedium,
|
|
color = MaterialTheme.colorScheme.primary,
|
|
fontWeight = FontWeight.SemiBold
|
|
)
|
|
Icon(
|
|
imageVector = if (stepsExpanded) Icons.Default.ExpandLess else Icons.Default.ExpandMore,
|
|
contentDescription = null,
|
|
tint = MaterialTheme.colorScheme.primary
|
|
)
|
|
}
|
|
|
|
AnimatedVisibility(visible = stepsExpanded) {
|
|
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
|
suggestion.steps.forEachIndexed { idx, step ->
|
|
Text(
|
|
text = "${idx + 1}. $step",
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.9f)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Action buttons row
|
|
FlowRow(
|
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
|
modifier = Modifier.fillMaxWidth()
|
|
) {
|
|
FilledTonalButton(
|
|
onClick = onSaveToBook,
|
|
enabled = !isSaved,
|
|
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
|
|
modifier = Modifier.testTag("save_suggested_recipe_${suggestion.id}")
|
|
) {
|
|
Icon(
|
|
imageVector = if (isSaved) Icons.Default.BookmarkAdded else Icons.Default.BookmarkBorder,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(16.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(6.dp))
|
|
Text(if (isSaved) "Enregistrée ✓" else "Enregistrer")
|
|
}
|
|
|
|
Button(
|
|
onClick = onLogToJournal,
|
|
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
|
|
modifier = Modifier.testTag("log_suggested_recipe_${suggestion.id}")
|
|
) {
|
|
Icon(
|
|
imageVector = Icons.Default.Restaurant,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(16.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(6.dp))
|
|
Text("Noter au journal")
|
|
}
|
|
|
|
OutlinedButton(
|
|
onClick = onLikeIngredients,
|
|
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
|
|
modifier = Modifier.testTag("like_suggested_recipe_${suggestion.id}")
|
|
) {
|
|
Icon(
|
|
imageVector = Icons.Default.FavoriteBorder,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(16.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(6.dp))
|
|
Text("Aimer")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@OptIn(ExperimentalLayoutApi::class)
|
|
@Composable
|
|
private fun DiscoverySuggestionCard(
|
|
discovery: DiscoverySuggestion,
|
|
currentStatus: FoodPreferenceStatus?,
|
|
onSetStatus: (FoodPreferenceStatus) -> Unit
|
|
) {
|
|
val isDark = isSatieaDarkTheme()
|
|
|
|
Card(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.testTag("discovery_card_${discovery.id}"),
|
|
shape = RoundedCornerShape(18.dp),
|
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
|
|
border = BorderStroke(1.dp, discovery.category.badgeBorderColor(isDark).copy(alpha = 0.7f))
|
|
) {
|
|
Column(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(16.dp),
|
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
) {
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
horizontalArrangement = Arrangement.SpaceBetween
|
|
) {
|
|
Row(
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
modifier = Modifier.weight(1f)
|
|
) {
|
|
FoodCategoryColorDot(category = discovery.category, size = 11.dp)
|
|
Spacer(modifier = Modifier.width(8.dp))
|
|
Text(
|
|
text = discovery.foodName,
|
|
style = MaterialTheme.typography.titleMedium,
|
|
color = MaterialTheme.colorScheme.onSurface,
|
|
fontWeight = FontWeight.Bold
|
|
)
|
|
}
|
|
|
|
Surface(
|
|
shape = RoundedCornerShape(8.dp),
|
|
color = discovery.category.badgeContainerColor(isDark)
|
|
) {
|
|
Text(
|
|
text = discovery.category.shortLabel,
|
|
style = MaterialTheme.typography.labelSmall,
|
|
color = discovery.category.badgeTextColor(isDark),
|
|
fontWeight = FontWeight.Medium,
|
|
modifier = Modifier.padding(horizontal = 8.dp, vertical = 3.dp)
|
|
)
|
|
}
|
|
}
|
|
|
|
if (discovery.benchmarkReason.isNotBlank()) {
|
|
Text(
|
|
text = discovery.benchmarkReason,
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
)
|
|
}
|
|
|
|
if (discovery.pairingIdea.isNotBlank()) {
|
|
Surface(
|
|
shape = RoundedCornerShape(10.dp),
|
|
color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.45f),
|
|
modifier = Modifier.fillMaxWidth()
|
|
) {
|
|
Text(
|
|
text = "Idée simple : ${discovery.pairingIdea}",
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = MaterialTheme.colorScheme.onSurface,
|
|
modifier = Modifier.padding(horizontal = 10.dp, vertical = 7.dp)
|
|
)
|
|
}
|
|
}
|
|
|
|
FlowRow(
|
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
|
verticalArrangement = Arrangement.spacedBy(6.dp)
|
|
) {
|
|
val isToTry = currentStatus == FoodPreferenceStatus.TO_TRY
|
|
val isLiked = currentStatus == FoodPreferenceStatus.LIKED
|
|
val isDisliked = currentStatus == FoodPreferenceStatus.DISLIKED
|
|
|
|
FilledTonalButton(
|
|
onClick = { onSetStatus(FoodPreferenceStatus.TO_TRY) },
|
|
contentPadding = PaddingValues(horizontal = 10.dp, vertical = 6.dp)
|
|
) {
|
|
Icon(
|
|
imageVector = if (isToTry) Icons.Default.Check else Icons.Default.AutoAwesome,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(15.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(5.dp))
|
|
Text(if (isToTry) "À tester ✓" else "+ À tester")
|
|
}
|
|
|
|
OutlinedButton(
|
|
onClick = { onSetStatus(FoodPreferenceStatus.LIKED) },
|
|
contentPadding = PaddingValues(horizontal = 10.dp, vertical = 6.dp)
|
|
) {
|
|
Icon(
|
|
imageVector = if (isLiked) Icons.Default.Favorite else Icons.Default.FavoriteBorder,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(15.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(5.dp))
|
|
Text(if (isLiked) "Aimé ✓" else "J'aime")
|
|
}
|
|
|
|
TextButton(
|
|
onClick = { onSetStatus(FoodPreferenceStatus.DISLIKED) },
|
|
contentPadding = PaddingValues(horizontal = 10.dp, vertical = 6.dp)
|
|
) {
|
|
Icon(
|
|
imageVector = Icons.Default.Block,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(15.dp)
|
|
)
|
|
Spacer(modifier = Modifier.width(4.dp))
|
|
Text(if (isDisliked) "Évité ✓" else "J'évite")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|