feat: integrate Firebase AI and food preferences

- Enable Firebase AI and App Check dependencies
- Configure App Check in MainActivity
- Add FoodPreference entity and DAO methods
- Bump Room database version to 5 for new table migration
This commit is contained in:
bleackstorm committed 2026-11-21 23:30:54 +01:00
1 parent d4d5d77d71
commit 1331fae119
23 files changed
+3077 -161

No files matched your search

@@ -25,6 +25,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.MenuBook
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.AutoAwesome
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.People
import androidx.compose.material.icons.filled.Schedule
@@ -59,8 +60,14 @@ import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.example.data.model.CustomFoodEntry
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.RecipeCategoryTag
import com.example.data.model.RecipeEntry
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.badgeBorderColor
import com.example.ui.common.badgeContainerColor
@@ -68,15 +75,34 @@ import com.example.ui.common.badgeTextColor
import com.example.ui.common.isSatieaDarkTheme
import java.util.Locale
private enum class RecipesSubTab(val label: String) {
BOOK("Mes recettes"),
IDEAS("Idées & Goûts")
}
@Composable
fun RecipesScreen(
recipes: List<RecipeEntry>,
customFoods: List<CustomFoodEntry>,
foodPreferences: List<FoodPreferenceEntry>,
selectedIdeaMealType: MealType,
dailyBenchmarkGap: DailyBenchmarkGap,
suggestionUiState: SuggestionUiState,
savedSuggestionIds: Set<String>,
onAddRecipeClick: () -> Unit,
onRecipeClick: (RecipeEntry) -> Unit
onRecipeClick: (RecipeEntry) -> Unit,
onSavePreference: (name: String, status: FoodPreferenceStatus, category: FoodCategory?) -> Unit,
onRemovePreference: (slugId: String) -> Unit,
onSelectIdeaMealType: (MealType) -> Unit,
onGenerateIdeas: (cravingNote: String) -> Unit,
onSaveSuggestedRecipe: (RecipeSuggestion) -> Unit,
onLogSuggestedRecipe: (RecipeSuggestion, MealType) -> Unit,
onLikeSuggestedRecipeIngredients: (RecipeSuggestion) -> Unit
) {
var activeSubTab by rememberSaveable { mutableStateOf(RecipesSubTab.BOOK) }
var searchQuery by rememberSaveable { mutableStateOf("") }
var selectedTag by rememberSaveable { mutableStateOf<String?>(null) }
var cravingNote by rememberSaveable { mutableStateOf("") }
val customCategoryLookup = remember(customFoods) {
customFoods.associate { it.name.lowercase(Locale.FRENCH).trim() to it.resolvedCategory() }
@@ -113,152 +139,249 @@ fun RecipesScreen(
) {
// Header
item {
Column {
Text(
text = "Mon Recueil de Recettes",
style = MaterialTheme.typography.headlineMedium,
color = MaterialTheme.colorScheme.onBackground,
fontWeight = FontWeight.Bold
)
Text(
text = if (recipes.isEmpty()) {
"Conservez vos recettes préférées et notez-les en 1 clic"
} else {
"${recipes.size} recette${if (recipes.size > 1) "s" else ""} • ingrédients colorés & portions ajustables"
},
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.7f)
)
}
}
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
Column {
Text(
text = if (activeSubTab == RecipesSubTab.BOOK) {
"Mon Recueil de Recettes"
} else {
"Idées & Mes Goûts"
},
style = MaterialTheme.typography.headlineMedium,
color = MaterialTheme.colorScheme.onBackground,
fontWeight = FontWeight.Bold
)
Text(
text = if (activeSubTab == RecipesSubTab.BOOK) {
if (recipes.isEmpty()) {
"Conservez vos recettes préférées et notez-les en 1 clic"
} else {
"${recipes.size} recette${if (recipes.size > 1) "s" else ""} • ingrédients colorés & portions ajustables"
}
} else {
"Vos envies & vos repères alimentaires du jour réunis"
},
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.7f)
)
}
// Search bar & Category filter chips
if (recipes.isNotEmpty()) {
item {
OutlinedTextField(
value = searchQuery,
onValueChange = { if (it.length <= 60) searchQuery = it },
// Segmented sub-tab switcher
Surface(
shape = RoundedCornerShape(16.dp),
color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.55f),
modifier = Modifier
.fillMaxWidth()
.testTag("recipe_search_input"),
placeholder = { Text("Rechercher une recette ou un ingrédient...") },
leadingIcon = {
Icon(
imageVector = Icons.Default.Search,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary
)
},
trailingIcon = {
if (searchQuery.isNotEmpty()) {
IconButton(onClick = { searchQuery = "" }) {
Icon(
imageVector = Icons.Default.Close,
contentDescription = "Effacer la recherche"
)
.testTag("recipes_subtab_switcher")
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(4.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
RecipesSubTab.entries.forEach { tab ->
val isSelected = activeSubTab == tab
Surface(
onClick = { activeSubTab = tab },
modifier = Modifier
.weight(1f)
.height(48.dp)
.testTag("recipes_subtab_${tab.name.lowercase()}"),
shape = RoundedCornerShape(12.dp),
color = if (isSelected) {
MaterialTheme.colorScheme.surface
} else {
MaterialTheme.colorScheme.surface.copy(alpha = 0f)
},
tonalElevation = if (isSelected) 3.dp else 0.dp
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Icon(
imageVector = if (tab == RecipesSubTab.BOOK) {
Icons.AutoMirrored.Filled.MenuBook
} else {
Icons.Default.AutoAwesome
},
contentDescription = null,
tint = if (isSelected) {
MaterialTheme.colorScheme.primary
} else {
MaterialTheme.colorScheme.onSurfaceVariant
},
modifier = Modifier.size(17.dp)
)
Spacer(modifier = Modifier.width(6.dp))
Text(
text = tab.label,
style = MaterialTheme.typography.labelLarge,
color = if (isSelected) {
MaterialTheme.colorScheme.onSurface
} else {
MaterialTheme.colorScheme.onSurfaceVariant
},
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium
)
}
}
}
},
singleLine = true,
shape = RoundedCornerShape(14.dp)
)
}
item {
LazyRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.fillMaxWidth()
) {
item {
FilterChip(
selected = selectedTag == null,
onClick = { selectedTag = null },
label = { Text("Toutes") },
colors = FilterChipDefaults.filterChipColors(
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
selectedLabelColor = MaterialTheme.colorScheme.onPrimaryContainer
)
)
}
items(RecipeCategoryTag.entries, key = { it.name }) { tag ->
FilterChip(
selected = selectedTag == tag.name,
onClick = {
selectedTag = if (selectedTag == tag.name) null else tag.name
},
label = { Text(tag.displayName) },
colors = FilterChipDefaults.filterChipColors(
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
selectedLabelColor = MaterialTheme.colorScheme.onPrimaryContainer
)
)
}
}
}
}
// Content
if (recipes.isEmpty()) {
item {
EmptyRecipesView(onAddRecipeClick = onAddRecipeClick)
}
} else if (filteredRecipes.isEmpty()) {
item {
Surface(
shape = RoundedCornerShape(18.dp),
color = MaterialTheme.colorScheme.surface,
modifier = Modifier.fillMaxWidth()
) {
Column(
if (activeSubTab == RecipesSubTab.IDEAS) {
ideasAndTastesItems(
preferences = foodPreferences,
customFoods = customFoods,
selectedMealType = selectedIdeaMealType,
benchmarkGap = dailyBenchmarkGap,
suggestionUiState = suggestionUiState,
savedSuggestionIds = savedSuggestionIds,
cravingNote = cravingNote,
onCravingNoteChange = { cravingNote = it },
onSelectMealType = onSelectIdeaMealType,
onSavePreference = onSavePreference,
onRemovePreference = onRemovePreference,
onGenerateIdeas = { onGenerateIdeas(cravingNote) },
onSaveSuggestedRecipe = onSaveSuggestedRecipe,
onLogSuggestedRecipe = onLogSuggestedRecipe,
onLikeRecipeIngredients = onLikeSuggestedRecipeIngredients
)
} else {
// Search bar & Category filter chips
if (recipes.isNotEmpty()) {
item {
OutlinedTextField(
value = searchQuery,
onValueChange = { if (it.length <= 60) searchQuery = it },
modifier = Modifier
.fillMaxWidth()
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Aucune recette ne correspond à ce filtre",
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface,
fontWeight = FontWeight.SemiBold
)
Spacer(modifier = Modifier.height(8.dp))
TextButton(
onClick = {
searchQuery = ""
selectedTag = null
.testTag("recipe_search_input"),
placeholder = { Text("Rechercher une recette ou un ingrédient...") },
leadingIcon = {
Icon(
imageVector = Icons.Default.Search,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary
)
},
trailingIcon = {
if (searchQuery.isNotEmpty()) {
IconButton(onClick = { searchQuery = "" }) {
Icon(
imageVector = Icons.Default.Close,
contentDescription = "Effacer la recherche"
)
}
}
) {
Text("Réinitialiser les filtres")
},
singleLine = true,
shape = RoundedCornerShape(14.dp)
)
}
item {
LazyRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.fillMaxWidth()
) {
item {
FilterChip(
selected = selectedTag == null,
onClick = { selectedTag = null },
label = { Text("Toutes") },
colors = FilterChipDefaults.filterChipColors(
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
selectedLabelColor = MaterialTheme.colorScheme.onPrimaryContainer
)
)
}
items(RecipeCategoryTag.entries, key = { it.name }) { tag ->
FilterChip(
selected = selectedTag == tag.name,
onClick = {
selectedTag = if (selectedTag == tag.name) null else tag.name
},
label = { Text(tag.displayName) },
colors = FilterChipDefaults.filterChipColors(
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
selectedLabelColor = MaterialTheme.colorScheme.onPrimaryContainer
)
)
}
}
}
}
} else {
items(filteredRecipes, key = { it.id }) { recipe ->
RecipeCardItem(
recipe = recipe,
customCategoryLookup = customCategoryLookup,
onClick = { onRecipeClick(recipe) }
)
// Content
if (recipes.isEmpty()) {
item {
EmptyRecipesView(onAddRecipeClick = onAddRecipeClick)
}
} else if (filteredRecipes.isEmpty()) {
item {
Surface(
shape = RoundedCornerShape(18.dp),
color = MaterialTheme.colorScheme.surface,
modifier = Modifier.fillMaxWidth()
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Aucune recette ne correspond à ce filtre",
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface,
fontWeight = FontWeight.SemiBold
)
Spacer(modifier = Modifier.height(8.dp))
TextButton(
onClick = {
searchQuery = ""
selectedTag = null
}
) {
Text("Réinitialiser les filtres")
}
}
}
}
} else {
items(filteredRecipes, key = { it.id }) { recipe ->
RecipeCardItem(
recipe = recipe,
customCategoryLookup = customCategoryLookup,
onClick = { onRecipeClick(recipe) }
)
}
}
}
}
FloatingActionButton(
onClick = onAddRecipeClick,
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(24.dp)
.testTag("add_recipe_fab"),
containerColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary,
shape = CircleShape
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = "Créer une recette",
modifier = Modifier.size(28.dp)
)
if (activeSubTab == RecipesSubTab.BOOK) {
FloatingActionButton(
onClick = onAddRecipeClick,
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(24.dp)
.testTag("add_recipe_fab"),
containerColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary,
shape = CircleShape
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = "Créer une recette",
modifier = Modifier.size(28.dp)
)
}
}
}
}