From 5d64e950a98094f6059f1dca5f89ab398f6d9414 Mon Sep 17 00:00:00 2001 From: Azea Date: Wed, 26 Feb 2025 14:20:08 -0500 Subject: [PATCH 1/2] Switched to Maps --- desktopApp/build.gradle.kts | 2 +- shared/src/commonMain/kotlin/App.kt | 4 +- .../commonMain/kotlin/model/AmericanData.kt | 11 +++-- .../commonMain/kotlin/model/ExampleData.kt | 44 +++++++++---------- shared/src/commonMain/kotlin/model/Recipe.kt | 11 ++++- .../src/commonMain/kotlin/view/GetRecipe.kt | 2 +- 6 files changed, 40 insertions(+), 34 deletions(-) diff --git a/desktopApp/build.gradle.kts b/desktopApp/build.gradle.kts index e70e5a4..421c549 100644 --- a/desktopApp/build.gradle.kts +++ b/desktopApp/build.gradle.kts @@ -24,7 +24,7 @@ compose.desktop { nativeDistributions { targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) - packageName = "Allbright_Cookbook" + packageName = "Baker's Menagerie" packageVersion = "1.0.0" } } diff --git a/shared/src/commonMain/kotlin/App.kt b/shared/src/commonMain/kotlin/App.kt index 6a81972..d347948 100644 --- a/shared/src/commonMain/kotlin/App.kt +++ b/shared/src/commonMain/kotlin/App.kt @@ -86,8 +86,8 @@ fun App(sensorManager: SensorManager?, isLarge: Boolean = false) { for (recipe in getRecipeList()) { for (tag in recipe.tags) { - if (!recipeTags.contains(tag)) - recipeTags.add(tag) + if (!recipeTags.contains(tag.key)) + recipeTags.add(tag.key) } } diff --git a/shared/src/commonMain/kotlin/model/AmericanData.kt b/shared/src/commonMain/kotlin/model/AmericanData.kt index 271e2a2..399d1c7 100644 --- a/shared/src/commonMain/kotlin/model/AmericanData.kt +++ b/shared/src/commonMain/kotlin/model/AmericanData.kt @@ -42,12 +42,11 @@ val americanList = listOf( "In a small saucepan, melt butter over medium heat with honey, chili powder, and kosher salt. Whisk well until the mixture is incorporated and homogenized.", "Lower the temperature to 'warm/low' heat and keep for serving. [Make sure to keep warm, as sauce will solidify very quickly]", ), - tags = listOf( - "American", - "Dinner", - "Spicy", - "Fried", - + tags = mapOf( + "American" to TagType.CUISINE, + "Entree" to TagType.COURSE, + "Spicy" to TagType.FLAVOUR, + "Fried" to TagType.COOKING ), image = Res.drawable.Chicken_And_Waffles, bgImage = null, diff --git a/shared/src/commonMain/kotlin/model/ExampleData.kt b/shared/src/commonMain/kotlin/model/ExampleData.kt index be9e2f6..c3539e0 100644 --- a/shared/src/commonMain/kotlin/model/ExampleData.kt +++ b/shared/src/commonMain/kotlin/model/ExampleData.kt @@ -40,9 +40,9 @@ val exampleList = listOf( bgImage = Res.drawable._01_lemon_cheesecake_bg, bgImageLarge = Res.drawable._01_lemon_cheesecake_bg_lg, bgColor = Color(0xffFFEF7D), - tags = listOf( - "Dessert", - "Example", + tags = mapOf( + "Dessert" to TagType.COURSE, + "Example" to TagType.EXAMPLES ) ), Recipe( @@ -80,9 +80,9 @@ val exampleList = listOf( image = Res.drawable._05_macaroons, bgImage = null, bgColor = lightColorScheme().primary, - tags = listOf( - "Dessert", - "Example", + tags = mapOf( + "Dessert" to TagType.COURSE, + "Example" to TagType.EXAMPLES ) ), Recipe( @@ -107,9 +107,9 @@ val exampleList = listOf( ), image = Res.drawable._02_chocolate_cake_1, bgColor = lightColorScheme().secondary, - tags = listOf( - "Dessert", - "Example", + tags = mapOf( + "Dessert" to TagType.COURSE, + "Example" to TagType.EXAMPLES ) ), Recipe( @@ -142,9 +142,9 @@ val exampleList = listOf( image = Res.drawable._03_chocolate_donuts, bgImage = null, bgColor = lightColorScheme().primary, - tags = listOf( - "Dessert", - "Example", + tags = mapOf( + "Dessert" to TagType.COURSE, + "Example" to TagType.EXAMPLES ) ), Recipe( @@ -177,9 +177,9 @@ val exampleList = listOf( image = Res.drawable._04_fluffy_cake, bgImage = null, bgColor = lightColorScheme().secondary, - tags = listOf( - "Dessert", - "Example", + tags = mapOf( + "Dessert" to TagType.COURSE, + "Example" to TagType.EXAMPLES ) ), Recipe( @@ -216,9 +216,9 @@ val exampleList = listOf( image = Res.drawable._06_white_cream_cake, bgImage = null, bgColor = lightColorScheme().primary, - tags = listOf( - "Dessert", - "Example", + tags = mapOf( + "Dessert" to TagType.COURSE, + "Example" to TagType.EXAMPLES ) ), Recipe( @@ -256,9 +256,9 @@ val exampleList = listOf( image = Res.drawable._07_honey_cake, bgImage = null, bgColor = darkColorScheme().primary, - tags = listOf( - "Dessert", - "Example", - ) + tags = mapOf( + "Dessert" to TagType.COURSE, + "Example" to TagType.EXAMPLES + ) ), ) \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/model/Recipe.kt b/shared/src/commonMain/kotlin/model/Recipe.kt index 7753d06..370b105 100644 --- a/shared/src/commonMain/kotlin/model/Recipe.kt +++ b/shared/src/commonMain/kotlin/model/Recipe.kt @@ -4,9 +4,16 @@ import androidx.compose.ui.graphics.Color import org.jetbrains.compose.resources.DrawableResource import org.jetbrains.compose.resources.ExperimentalResourceApi +enum class TagType { + CUISINE, // Country or Ethnicity of Origin + COURSE, // Breads, Apps, Desserts, Entrees, etc + FLAVOUR, // Spicy, Sweet, Sour, Umami, Delicious + COOKING, // Fried, Baked, Boiled, Poached, etc + EXAMPLES, // Example Recipes that might only appear in debug mode? +} /** - * Created by abdulbasit on 18/06/2023. + * Sourced from abdulbasit */ data class Recipe @OptIn(ExperimentalResourceApi::class) constructor( @@ -15,7 +22,7 @@ data class Recipe @OptIn(ExperimentalResourceApi::class) constructor( val description: String, val ingredients: List, val instructions: List, - val tags: List, + val tags: Map, val image: DrawableResource, val bgImage: DrawableResource? = null, val bgImageLarge: DrawableResource? = null, diff --git a/shared/src/commonMain/kotlin/view/GetRecipe.kt b/shared/src/commonMain/kotlin/view/GetRecipe.kt index d24abed..b8983a6 100644 --- a/shared/src/commonMain/kotlin/view/GetRecipe.kt +++ b/shared/src/commonMain/kotlin/view/GetRecipe.kt @@ -20,7 +20,7 @@ fun getFilteredRecipeList( ) : List { val items = getRecipeList() - var recipes = items.filter { it.tags.containsAll(tags) } + var recipes = items.filter { it.tags.keys.containsAll(tags) } recipes = recipes.filter { it.title.contains(search) || it.ingredients.containsPartial(search) -- 2.47.2 From 96cf759d75219ee132f1d8381ce330c3f4150931 Mon Sep 17 00:00:00 2001 From: Azea Date: Wed, 26 Feb 2025 14:52:14 -0500 Subject: [PATCH 2/2] Organised the Bookshelf by Category --- shared/src/commonMain/kotlin/App.kt | 75 ++--------------- .../commonMain/kotlin/model/AmericanData.kt | 2 +- shared/src/commonMain/kotlin/model/Recipe.kt | 4 +- .../src/commonMain/kotlin/view/Bookshelf.kt | 83 +++++++++++++++++++ 4 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 shared/src/commonMain/kotlin/view/Bookshelf.kt diff --git a/shared/src/commonMain/kotlin/App.kt b/shared/src/commonMain/kotlin/App.kt index d347948..f288ece 100644 --- a/shared/src/commonMain/kotlin/App.kt +++ b/shared/src/commonMain/kotlin/App.kt @@ -1,21 +1,10 @@ import androidx.compose.animation.ExperimentalSharedTransitionApi import androidx.compose.animation.SharedTransitionLayout import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.width -import androidx.compose.foundation.layout.windowInsetsPadding -import androidx.compose.foundation.lazy.grid.GridCells -import androidx.compose.foundation.lazy.grid.LazyVerticalGrid -import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.material.Button import androidx.compose.material.Scaffold import androidx.compose.material.Text @@ -25,19 +14,17 @@ import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import androidx.navigation.NavType import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController -import androidx.navigation.navArgument import details.RecipeDetails +import model.TagType import recipeslist.RecipesListScreen import sensor.SensorManager import ui.theme.MainTheme +import view.BookShelf import view.FilterCard import view.HomeScreen import view.InputFieldState @@ -81,18 +68,18 @@ fun App(sensorManager: SensorManager?, isLarge: Boolean = false) { var searchBar by remember { mutableStateOf(false) } var search by remember { mutableStateOf("") } val tags = remember { mutableStateListOf() } - val recipeTags by remember { mutableStateOf(mutableListOf()) } + val recipeTags by remember { mutableStateOf(mutableMapOf()) } var book by remember { mutableStateOf("") } for (recipe in getRecipeList()) { for (tag in recipe.tags) { if (!recipeTags.contains(tag.key)) - recipeTags.add(tag.key) + recipeTags[tag.key] = tag.value } } if (show) { - FilterCard(recipeTags) { + FilterCard(recipeTags.keys.toList()) { tags.removeAll(tags) tags.addAll(it) show = false @@ -184,55 +171,3 @@ fun App(sensorManager: SensorManager?, isLarge: Boolean = false) { } } } - -@Composable -fun BookShelf( - onClick: (String) -> Unit, - isLarge: Boolean, - tags: List -) { - - val sorted = tags.sorted() - - Box( - modifier = Modifier - .fillMaxSize() - ) { - Column( - modifier = Modifier - .fillMaxWidth() - .fillMaxSize() - .padding(top = 10.dp) - .align(Alignment.Center), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center, - ) { - - Text(text = "What Do You Want To Cook Today?", textAlign = TextAlign.Center) - - Button(onClick = { onClick("") }) { - Text("Anything") - } - - val listState = rememberLazyGridState() - LazyVerticalGrid( - columns = GridCells.Fixed(if (isLarge) 2 else 2), - state = listState - ) - { - if (isLarge.not()) { - item { - Spacer(modifier = Modifier.windowInsetsPadding(WindowInsets.systemBars)) - } - } - items(sorted.size) { item -> - val tag = sorted[item] - Button(onClick = { onClick(tag) }) { - Text(tag) - } - } - } - - } - } -} diff --git a/shared/src/commonMain/kotlin/model/AmericanData.kt b/shared/src/commonMain/kotlin/model/AmericanData.kt index 399d1c7..53731b0 100644 --- a/shared/src/commonMain/kotlin/model/AmericanData.kt +++ b/shared/src/commonMain/kotlin/model/AmericanData.kt @@ -46,7 +46,7 @@ val americanList = listOf( "American" to TagType.CUISINE, "Entree" to TagType.COURSE, "Spicy" to TagType.FLAVOUR, - "Fried" to TagType.COOKING + "Fried" to TagType.TECHNIQUE ), image = Res.drawable.Chicken_And_Waffles, bgImage = null, diff --git a/shared/src/commonMain/kotlin/model/Recipe.kt b/shared/src/commonMain/kotlin/model/Recipe.kt index 370b105..9f7cc0b 100644 --- a/shared/src/commonMain/kotlin/model/Recipe.kt +++ b/shared/src/commonMain/kotlin/model/Recipe.kt @@ -5,10 +5,10 @@ import org.jetbrains.compose.resources.DrawableResource import org.jetbrains.compose.resources.ExperimentalResourceApi enum class TagType { - CUISINE, // Country or Ethnicity of Origin COURSE, // Breads, Apps, Desserts, Entrees, etc + CUISINE, // Country or Ethnicity of Origin FLAVOUR, // Spicy, Sweet, Sour, Umami, Delicious - COOKING, // Fried, Baked, Boiled, Poached, etc + TECHNIQUE, // Fried, Baked, Boiled, Poached, etc EXAMPLES, // Example Recipes that might only appear in debug mode? } diff --git a/shared/src/commonMain/kotlin/view/Bookshelf.kt b/shared/src/commonMain/kotlin/view/Bookshelf.kt new file mode 100644 index 0000000..08c609c --- /dev/null +++ b/shared/src/commonMain/kotlin/view/Bookshelf.kt @@ -0,0 +1,83 @@ +package view + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.systemBars +import androidx.compose.foundation.layout.windowInsetsPadding +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.foundation.lazy.grid.rememberLazyGridState +import androidx.compose.material.Button +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import model.TagType + + +@Composable +fun BookShelf( + onClick: (String) -> Unit, + isLarge: Boolean, + tags: Map +) { + + Box( + modifier = Modifier + .fillMaxSize() + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .fillMaxSize() + .padding(top = 10.dp) + .align(Alignment.Center), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + ) { + + Text(text = "What Do You Want To Cook Today?", textAlign = TextAlign.Center) + + Button(onClick = { onClick("") }) { + Text("Anything") + } + + for (type in tags.values.toSet().toList().sorted()) // get all unique tag types + { + var list = + tags.filterValues { it == type }.keys.toList() // get list of all keys that have this value + list = list.sorted() + + Text("Cook By ".plus(type.name)) + + val listState = rememberLazyGridState() + + LazyVerticalGrid( + columns = GridCells.Fixed(if (isLarge) 4 else 2), + state = listState + ) { + if (isLarge.not()) { + item { + Spacer(modifier = Modifier.windowInsetsPadding(WindowInsets.systemBars)) + } + } + items(list.size) { item -> + val tag = list[item] + Button(onClick = { onClick(tag) }) { + Text(tag) + } + } + } + } + + } + } +} \ No newline at end of file -- 2.47.2