TagTyping #2

Merged
Azea_Avenbright merged 2 commits from TagTyping into master 2025-02-26 14:52:56 -05:00
7 changed files with 127 additions and 103 deletions

View file

@ -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"
}
}

View file

@ -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<String>() }
val recipeTags by remember { mutableStateOf(mutableListOf<String>()) }
val recipeTags by remember { mutableStateOf(mutableMapOf<String, TagType>()) }
var book by remember { mutableStateOf("") }
for (recipe in getRecipeList()) {
for (tag in recipe.tags) {
if (!recipeTags.contains(tag))
recipeTags.add(tag)
if (!recipeTags.contains(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<String>
) {
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)
}
}
}
}
}
}

View file

@ -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.TECHNIQUE
),
image = Res.drawable.Chicken_And_Waffles,
bgImage = null,

View file

@ -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
)
),
)

View file

@ -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 {
COURSE, // Breads, Apps, Desserts, Entrees, etc
CUISINE, // Country or Ethnicity of Origin
FLAVOUR, // Spicy, Sweet, Sour, Umami, Delicious
TECHNIQUE, // 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<String>,
val instructions: List<String>,
val tags: List<String>,
val tags: Map<String, TagType>,
val image: DrawableResource,
val bgImage: DrawableResource? = null,
val bgImageLarge: DrawableResource? = null,

View file

@ -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<String, TagType>
) {
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)
}
}
}
}
}
}
}

View file

@ -20,7 +20,7 @@ fun getFilteredRecipeList(
) : List<Recipe> {
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)