diff --git a/app/src/main/java/gq/kirmanak/mealient/data/recipes/impl/RecipeRepoImpl.kt b/app/src/main/java/gq/kirmanak/mealient/data/recipes/impl/RecipeRepoImpl.kt index 5a9b37ac..df46b6a7 100644 --- a/app/src/main/java/gq/kirmanak/mealient/data/recipes/impl/RecipeRepoImpl.kt +++ b/app/src/main/java/gq/kirmanak/mealient/data/recipes/impl/RecipeRepoImpl.kt @@ -48,6 +48,7 @@ class RecipeRepoImpl @Inject constructor( return runCatchingExceptCancel { val recipe = dataSource.requestRecipe(recipeSlug) val entity = modelMapper.toRecipeEntity(recipe) + val settings = modelMapper.toRecipeSettingsEntity(recipe.settings) val ingredients = recipe.ingredients.map { modelMapper.toRecipeIngredientEntity(it, entity.remoteId) } @@ -63,7 +64,7 @@ class RecipeRepoImpl @Inject constructor( ) } } - storage.saveRecipeInfo(entity, ingredients, instructions, ingredientToInstruction) + storage.saveRecipeInfo(entity, settings, ingredients, instructions, ingredientToInstruction) }.onFailure { logger.e(it) { "loadRecipeInfo: can't update full recipe info" } } diff --git a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/HeaderSection.kt b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/HeaderSection.kt index b97ff94d..ca5defcc 100644 --- a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/HeaderSection.kt +++ b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/HeaderSection.kt @@ -2,10 +2,14 @@ package gq.kirmanak.mealient.ui.recipes.info import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.text.ClickableText +import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -19,15 +23,33 @@ import androidx.compose.ui.unit.dp import coil.compose.AsyncImage import gq.kirmanak.mealient.R import gq.kirmanak.mealient.ui.Dimens +import androidx.compose.material3.OutlinedTextField +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.modifier.modifierLocalConsumer +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.text.style.TextAlign +import gq.kirmanak.mealient.ui.AppTheme +import gq.kirmanak.mealient.ui.preview.ColorSchemePreview +import okhttp3.internal.http2.Header @Composable internal fun HeaderSection( imageUrl: String?, - title: String?, - description: String?, + title: String, + description: String, + isEditMode: Boolean, ) { val imageFallback = painterResource(id = R.drawable.placeholder_recipe) + var bHeaderExpanded by remember { + mutableStateOf(false) + } + Column( verticalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Top), ) { @@ -51,22 +73,79 @@ internal fun HeaderSection( contentScale = ContentScale.Crop, ) - if (!title.isNullOrEmpty()) { - Text( - modifier = Modifier - .padding(horizontal = Dimens.Small), - text = title, - style = MaterialTheme.typography.headlineSmall, + + if (isEditMode) { + // ToDo: Only for Testing + var titleValue by remember { + mutableStateOf(TextFieldValue(title)) + } + + OutlinedTextField( + value = titleValue, + onValueChange = { titleValue = it }, + modifier = Modifier.fillMaxWidth(), + label = { Text(text = "title")} + ) + OutlinedTextField( + value = description, + onValueChange = { /* TODO */ }, + modifier = Modifier.fillMaxWidth(), + label = { Text(text = "description")} ) + } else { + if (!title.isNullOrEmpty()) { + Text( + modifier = Modifier + .padding(horizontal = Dimens.Small), + text = title, + style = MaterialTheme.typography.headlineSmall, + ) + } + if (!description.isNullOrEmpty()) { + Text( + modifier = Modifier + .padding(horizontal = Dimens.Small), + text = description, + style = MaterialTheme.typography.bodyLarge, + ) + } } - if (!description.isNullOrEmpty()) { - Text( - modifier = Modifier - .padding(horizontal = Dimens.Small), - text = description, - style = MaterialTheme.typography.bodyLarge, + val sExpandText = + if (bHeaderExpanded) stringResource(id = R.string.hideDetails) else stringResource(id = R.string.showDetails) + ClickableText( + text = buildAnnotatedString { + append(sExpandText) + }, + onClick = { bHeaderExpanded = !bHeaderExpanded }, + modifier = Modifier + .padding(top = 4.dp, start = 4.dp, bottom = 4.dp) + .fillMaxWidth(), + style = TextStyle( + textAlign = TextAlign.Center, color = MaterialTheme.colorScheme.primary ) + ) + + if (bHeaderExpanded) { + // ToDo: Show categories, tags, settings, required tools and nutrition + Button( + onClick = { /*TODO*/ }, + ) { + Text(text = "Settings") + } } } +} + +@ColorSchemePreview +@Composable +private fun HeaderSectionPreview() { + AppTheme { + HeaderSection( + imageUrl = "", + title = "Test Recipe", + description = "test Test Test test", + isEditMode = true, + ) + } } \ No newline at end of file diff --git a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/IngredientsSection.kt b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/IngredientsSection.kt index fc7aeb42..5da40e17 100644 --- a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/IngredientsSection.kt +++ b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/IngredientsSection.kt @@ -5,10 +5,17 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ArrowDownward +import androidx.compose.material.icons.filled.ArrowUpward import androidx.compose.material3.Card import androidx.compose.material3.Checkbox import androidx.compose.material3.Divider +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -18,6 +25,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp import gq.kirmanak.mealient.R import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity import gq.kirmanak.mealient.ui.Dimens @@ -25,6 +33,7 @@ import gq.kirmanak.mealient.ui.Dimens @Composable internal fun IngredientsSection( ingredients: List, + isEditMode: Boolean, ) { Column( verticalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Top), @@ -47,9 +56,14 @@ internal fun IngredientsSection( .padding(Dimens.Small), verticalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Top), ) { + var ingredientsCount = 0 ingredients.forEach { item -> + val isLastItem = (ingredientsCount == ingredients.size -1) IngredientListItem( item = item, + index = ingredientsCount++, + isEditMode = isEditMode, + isLastItem = isLastItem, ) } } @@ -60,44 +74,88 @@ internal fun IngredientsSection( @Composable private fun IngredientListItem( item: RecipeIngredientEntity, + index: Int, modifier: Modifier = Modifier, + isEditMode: Boolean, + isLastItem: Boolean, ) { - var isChecked by rememberSaveable { mutableStateOf(false) } + val title = item.title ?: "" - val title = item.title - if (!title.isNullOrBlank()) { - Text( - modifier = modifier - .padding(horizontal = Dimens.Medium), - text = title, - style = MaterialTheme.typography.titleMedium, - ) - - Divider() + if (isEditMode) { + Row { + OutlinedTextField( + value = title, + label = { Text(text = "title") }, + onValueChange = { /*ToDo*/ } + ) + if (!isLastItem) { + IconButton( + onClick = { /*TODO*/ }, + modifier = Modifier.padding(4.dp).size(64.dp) + ) { + Icon(Icons.Default.ArrowDownward, contentDescription = "Save") + } + } + if (index > 0) { + IconButton( + onClick = { /*TODO*/ }, + modifier = Modifier.padding(4.dp).size(64.dp) + ) { + Icon(Icons.Default.ArrowUpward, contentDescription = "Save") + } + } + } + if (item.disableAmount) { + OutlinedTextField( + value = item.display, + label = { Text(text = "ingredient")}, + onValueChange = { /*ToDo*/ } ) + } + else { + OutlinedTextField( + value = item.note, + label = { Text(text = "ingredient")}, + onValueChange = { /*ToDo*/ } ) + } } + else { - Row( - modifier = modifier, - horizontalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Start), - verticalAlignment = Alignment.CenterVertically, - ) { - Checkbox( - checked = isChecked, - onCheckedChange = { isChecked = it }, - ) + var isChecked by rememberSaveable { mutableStateOf(false) } - val (text, note) = item.textAndNote - Column { + if (!title.isNullOrBlank()) { Text( - text = text, - style = MaterialTheme.typography.bodyLarge, + modifier = modifier + .padding(horizontal = Dimens.Medium), + text = title, + style = MaterialTheme.typography.titleMedium, + ) + + Divider() + } + + Row( + modifier = modifier, + horizontalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Start), + verticalAlignment = Alignment.CenterVertically, + ) { + Checkbox( + checked = isChecked, + onCheckedChange = { isChecked = it }, ) - if (note.isNotBlank()) { + val (text, note) = item.textAndNote + Column { Text( - text = item.note, - style = MaterialTheme.typography.bodyMedium, + text = text, + style = MaterialTheme.typography.bodyLarge, ) + + if (note.isNotBlank()) { + Text( + text = item.note, + style = MaterialTheme.typography.bodyMedium, + ) + } } } } diff --git a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/InstructionsSection.kt b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/InstructionsSection.kt index 1fe146d9..3b80ec09 100644 --- a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/InstructionsSection.kt +++ b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/InstructionsSection.kt @@ -2,24 +2,37 @@ package gq.kirmanak.mealient.ui.recipes.info import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ArrowDownward +import androidx.compose.material.icons.filled.ArrowUpward +import androidx.compose.material.icons.filled.Save +import androidx.compose.material3.Button import androidx.compose.material3.Card import androidx.compose.material3.Divider +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.Dp import gq.kirmanak.mealient.R import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity import gq.kirmanak.mealient.ui.Dimens +import androidx.compose.ui.unit.dp @Composable internal fun InstructionsSection( instructions: Map>, + isEditMode: Boolean ) { Column( verticalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Top), @@ -33,12 +46,15 @@ internal fun InstructionsSection( var stepCount = 0 instructions.forEach { (instruction, ingredients) -> + val isLastItem = (stepCount == instructions.size -1) InstructionListItem( modifier = Modifier .padding(horizontal = Dimens.Small), item = instruction, ingredients = ingredients, index = stepCount++, + isEditMode = isEditMode, + isLastItem = isLastItem, ) } } @@ -50,49 +66,108 @@ private fun InstructionListItem( index: Int, ingredients: List, modifier: Modifier = Modifier, + isEditMode: Boolean, + isLastItem: Boolean, ) { - val title = item.title - if (!title.isNullOrBlank()) { - Text( - modifier = modifier - .padding(horizontal = Dimens.Medium), - text = title, - style = MaterialTheme.typography.titleMedium, - ) + val title = item.title ?: "" - } + if (isEditMode) { + Row { + OutlinedTextField( + value = title, + onValueChange = { /* TODO */ }, + label = { Text(text = "title") } + ) + if (!isLastItem) { + IconButton( + onClick = { /*TODO*/ }, + modifier = Modifier.padding(4.dp).size(64.dp) + ) { + Icon(Icons.Default.ArrowDownward, contentDescription = "Save") + } + } + if (index > 0) { + IconButton( + onClick = { /*TODO*/ }, + modifier = Modifier.padding(4.dp).size(64.dp) + ) { + Icon(Icons.Default.ArrowUpward, contentDescription = "Save") + } + } + } - Card( - modifier = modifier - .fillMaxWidth(), - ) { - Column( - modifier = Modifier - .padding(Dimens.Medium), - verticalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Top), + Card( + modifier = modifier + .fillMaxWidth(), ) { + Column( + modifier = Modifier + .padding(Dimens.Medium), + verticalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Top), + ) { + OutlinedTextField( + value = item.text.trim(), + label = { Text( text = stringResource( + R.string.view_holder_recipe_instructions_step, + index + 1 + )) }, + onValueChange = { /* TODO */ }, + ) + + if (ingredients.isNotEmpty()) { + Divider() + ingredients.forEach { ingredient -> + Text( + text = ingredient.display, + style = MaterialTheme.typography.bodyMedium, + ) + } + } + } + } + } + else { + if (title.isNullOrBlank()) { Text( - text = stringResource( - R.string.view_holder_recipe_instructions_step, - index + 1 - ), + modifier = modifier + .padding(horizontal = Dimens.Medium), + text = title, style = MaterialTheme.typography.titleMedium, ) + } + + Card( + modifier = modifier + .fillMaxWidth(), + ) { + Column( + modifier = Modifier + .padding(Dimens.Medium), + verticalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Top), + ) { + Text( + text = stringResource( + R.string.view_holder_recipe_instructions_step, + index + 1 + ), + style = MaterialTheme.typography.titleMedium, + ) + + } Text( text = item.text.trim(), style = MaterialTheme.typography.bodyLarge, ) - - if (ingredients.isNotEmpty()) { - Divider() - ingredients.forEach { ingredient -> - Text( - text = ingredient.display, - style = MaterialTheme.typography.bodyMedium, - ) - } + } + if (ingredients.isNotEmpty()) { + Divider() + ingredients.forEach { ingredient -> + Text( + text = ingredient.display, + style = MaterialTheme.typography.bodyMedium, + ) } } } diff --git a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/PreviewData.kt b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/PreviewData.kt index 22fb68d8..5c88a982 100644 --- a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/PreviewData.kt +++ b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/PreviewData.kt @@ -28,6 +28,14 @@ internal val SUMMARY_ENTITY = RecipeSummaryEntity( dateUpdated = LocalDateTime(2021, 1, 1, 1, 1, 1), imageId = null, isFavorite = false, + groupId = "1", + userId = "1", + cookTime = "", + performTime = "", + prepTime = "", + totalTime = "", + recipeYield = "2 Pieces", + rating = 3 ) internal val INGREDIENT_ONE = RecipeIngredientEntity( diff --git a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeInfoUiState.kt b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeInfoUiState.kt index 3fe0f9b8..18646389 100644 --- a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeInfoUiState.kt +++ b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeInfoUiState.kt @@ -2,16 +2,21 @@ package gq.kirmanak.mealient.ui.recipes.info import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity +import gq.kirmanak.mealient.database.recipe.entity.RecipeSettingsEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity data class RecipeInfoUiState( val showIngredients: Boolean = false, val showInstructions: Boolean = false, val summaryEntity: RecipeSummaryEntity? = null, + val recipeSettings: RecipeSettingsEntity? = null, val recipeIngredients: List = emptyList(), val recipeInstructions: Map> = emptyMap(), val title: String? = null, val description: String? = null, val disableAmounts: Boolean = true, val imageUrl: String? = null, + val rating: Long? = null, + val locked: Boolean = false, + val editable: Boolean = true, ) diff --git a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeInfoViewModel.kt b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeInfoViewModel.kt index 8ad1df5f..93aebe40 100644 --- a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeInfoViewModel.kt +++ b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeInfoViewModel.kt @@ -43,6 +43,8 @@ internal class RecipeInfoViewModel @Inject constructor( title = entity.recipeSummaryEntity.name, description = entity.recipeSummaryEntity.description, imageUrl = imageUrl, + rating = entity.recipeSummaryEntity.rating, + locked = entity.recipeSettingsEntity.locked ) } ?: RecipeInfoUiState() emit(state) diff --git a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeScreen.kt b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeScreen.kt index 2a63990d..659d1209 100644 --- a/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeScreen.kt +++ b/app/src/main/java/gq/kirmanak/mealient/ui/recipes/info/RecipeScreen.kt @@ -1,14 +1,28 @@ package gq.kirmanak.mealient.ui.recipes.info +import android.annotation.SuppressLint import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Cancel +import androidx.compose.material.icons.filled.Edit +import androidx.compose.material.icons.filled.Save +import androidx.compose.material3.FloatingActionButton +import androidx.compose.material3.Icon +import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +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.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import com.ramcosta.composedestinations.annotation.Destination import gq.kirmanak.mealient.ui.AppTheme @@ -29,48 +43,94 @@ internal fun RecipeScreen( ) { val state by viewModel.uiState.collectAsState() + var isEditMode by remember { mutableStateOf(false ) } + BaseScreen { modifier -> RecipeScreen( modifier = modifier, state = state, + changeEditMode = { isEditMode = !isEditMode }, + isEditMode = isEditMode ) } } +@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") @Composable private fun RecipeScreen( state: RecipeInfoUiState, modifier: Modifier = Modifier, + changeEditMode: () -> Unit, + isEditMode: Boolean, ) { KeepScreenOn() - Column( - modifier = modifier - .verticalScroll( - state = rememberScrollState(), - ), - verticalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Top), - ) { - HeaderSection( - imageUrl = state.imageUrl, - title = state.title, - description = state.description, - ) - - if (state.showIngredients) { - IngredientsSection( - ingredients = state.recipeIngredients, - ) + Scaffold( + floatingActionButton = { + Row { + FloatingActionButton( + onClick = { + changeEditMode() + }, + modifier = Modifier.padding( horizontal = 8.dp) + ) { + if (isEditMode) { + Icon(Icons.Default.Cancel, contentDescription = "Cancel") + } else { + Icon(Icons.Default.Edit, contentDescription = "Edit") + } + } + if (isEditMode) { + FloatingActionButton( + onClick = { + changeEditMode() + save() + }, + modifier = Modifier.padding( horizontal = 8.dp) + ) { + Icon(Icons.Default.Save, contentDescription = "Save") + } + } + } } - - if (state.showInstructions) { - InstructionsSection( - instructions = state.recipeInstructions, + ) + { + Column( + modifier = modifier + .verticalScroll( + state = rememberScrollState(), + ), + verticalArrangement = Arrangement.spacedBy(Dimens.Small, Alignment.Top), + ) { + HeaderSection( + imageUrl = state.imageUrl, + title = state.title ?: "", + description = state.description ?: "", + isEditMode = isEditMode, ) + + if (state.showIngredients) { + IngredientsSection( + ingredients = state.recipeIngredients, + isEditMode = isEditMode, + ) + } + + if (state.showInstructions) { + InstructionsSection( + instructions = state.recipeInstructions, + isEditMode = isEditMode, + ) + } } } } +private fun save( ) { + +} + + @ColorSchemePreview @Composable private fun RecipeScreenPreview() { @@ -84,7 +144,11 @@ private fun RecipeScreenPreview() { recipeInstructions = INSTRUCTIONS, title = "Recipe title", description = "Recipe description", - ) + locked = false, + editable = true, + ), + changeEditMode = {}, + isEditMode = false, ) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b3d921fc..1a6b840b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -81,4 +81,6 @@ Are you sure you want to log yourself out? Log out Cancel + Details + Hide details \ No newline at end of file diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/AppDb.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/AppDb.kt index 911b3c28..1dcb00e7 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/AppDb.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/AppDb.kt @@ -8,13 +8,15 @@ import gq.kirmanak.mealient.database.recipe.entity.RecipeEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientToInstructionEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity +import gq.kirmanak.mealient.database.recipe.entity.RecipeSettingsEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity @Database( - version = 12, + version = 13, entities = [ RecipeSummaryEntity::class, RecipeEntity::class, + RecipeSettingsEntity::class, RecipeIngredientEntity::class, RecipeInstructionEntity::class, RecipeIngredientToInstructionEntity::class, diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeDao.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeDao.kt index 4123025d..3e3aa2d5 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeDao.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeDao.kt @@ -16,6 +16,10 @@ internal interface RecipeDao { @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertRecipeSummaries(recipeSummaryEntity: Iterable) + @Transaction + @Insert(onConflict = OnConflictStrategy.REPLACE) + suspend fun insertRecipeSettings(recipeSettingsEntity: RecipeSettingsEntity) + @Transaction @Query("DELETE FROM recipe_summaries") suspend fun removeAllRecipes() diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeStorage.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeStorage.kt index e24ce99f..523205fd 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeStorage.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeStorage.kt @@ -5,6 +5,7 @@ import gq.kirmanak.mealient.database.recipe.entity.RecipeEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientToInstructionEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity +import gq.kirmanak.mealient.database.recipe.entity.RecipeSettingsEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeWithSummaryAndIngredientsAndInstructions @@ -19,6 +20,7 @@ interface RecipeStorage { suspend fun saveRecipeInfo( recipe: RecipeEntity, + recipeSettings: RecipeSettingsEntity, ingredients: List, instructions: List, ingredientToInstruction: List, diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeStorageImpl.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeStorageImpl.kt index 56a635d6..334187c1 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeStorageImpl.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeStorageImpl.kt @@ -7,6 +7,7 @@ import gq.kirmanak.mealient.database.recipe.entity.RecipeEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientToInstructionEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity +import gq.kirmanak.mealient.database.recipe.entity.RecipeSettingsEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeWithSummaryAndIngredientsAndInstructions import gq.kirmanak.mealient.logging.Logger @@ -44,6 +45,7 @@ internal class RecipeStorageImpl @Inject constructor( override suspend fun saveRecipeInfo( recipe: RecipeEntity, + recipeSettings: RecipeSettingsEntity, ingredients: List, instructions: List, ingredientToInstruction: List, @@ -52,6 +54,8 @@ internal class RecipeStorageImpl @Inject constructor( db.withTransaction { recipeDao.insertRecipe(recipe) + recipeDao.insertRecipeSettings(recipeSettings) + recipeDao.deleteRecipeIngredients(recipe.remoteId) recipeDao.insertRecipeIngredients(ingredients) diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeEntity.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeEntity.kt index 1b93e207..6f16b94c 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeEntity.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeEntity.kt @@ -7,6 +7,4 @@ import androidx.room.PrimaryKey @Entity(tableName = "recipe") data class RecipeEntity( @PrimaryKey @ColumnInfo(name = "recipe_id") val remoteId: String, - @ColumnInfo(name = "recipe_yield") val recipeYield: String, - @ColumnInfo(name = "recipe_disable_amounts", defaultValue = "true") val disableAmounts: Boolean, ) diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSettingsEntity.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSettingsEntity.kt new file mode 100644 index 00000000..05652685 --- /dev/null +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSettingsEntity.kt @@ -0,0 +1,17 @@ +package gq.kirmanak.mealient.database.recipe.entity + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "recipe_settings") +data class RecipeSettingsEntity( + @PrimaryKey @ColumnInfo(name = "recipe_id") val remoteId: String, + @ColumnInfo(name = "public") val public: Boolean, + @ColumnInfo(name = "show_nutrition") val showNutrition: Boolean, + @ColumnInfo(name = "show_assets") val showAssets: Boolean, + @ColumnInfo(name = "landscape_view") val landscapeView: Boolean, + @ColumnInfo(name = "disable_comments") val disableComments: Boolean, + @ColumnInfo(name = "disable_amounts", defaultValue = "true") val disableAmounts: Boolean, + @ColumnInfo(name = "locked") val locked: Boolean, +) diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSummaryEntity.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSummaryEntity.kt index d9ff3393..79cac7c1 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSummaryEntity.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSummaryEntity.kt @@ -12,8 +12,16 @@ data class RecipeSummaryEntity( @ColumnInfo(name = "recipe_summaries_name") val name: String, @ColumnInfo(name = "recipe_summaries_slug") val slug: String, @ColumnInfo(name = "recipe_summaries_description") val description: String, + @ColumnInfo(name = "recipe_summaries_yield") val recipeYield: String, @ColumnInfo(name = "recipe_summaries_date_added") val dateAdded: LocalDate, @ColumnInfo(name = "recipe_summaries_date_updated") val dateUpdated: LocalDateTime, @ColumnInfo(name = "recipe_summaries_image_id") val imageId: String?, @ColumnInfo(name = "recipe_summaries_is_favorite") val isFavorite: Boolean, + @ColumnInfo(name = "recipe_summaries_rating") val rating: Long, + @ColumnInfo(name = "recipe_summaries_userId") val userId: String, + @ColumnInfo(name = "recipe_summaries_groupId") val groupId: String, + @ColumnInfo(name = "recipe_summaries_totalTime") val totalTime: String = "", + @ColumnInfo(name = "recipe_summaries_prepTime") val prepTime: String = "", + @ColumnInfo(name = "recipe_summaries_cookTime") val cookTime: String = "", + @ColumnInfo(name = "recipe_summaries_performTime") val performTime: String = "", ) \ No newline at end of file diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeWithSummaryAndIngredientsAndInstructions.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeWithSummaryAndIngredientsAndInstructions.kt index a3d2982e..4079a0c5 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeWithSummaryAndIngredientsAndInstructions.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeWithSummaryAndIngredientsAndInstructions.kt @@ -14,6 +14,11 @@ data class RecipeWithSummaryAndIngredientsAndInstructions( parentColumn = "recipe_id", entityColumn = "recipe_id" ) + val recipeSettingsEntity: RecipeSettingsEntity, + @Relation( + parentColumn = "recipe_id", + entityColumn = "recipe_id" + ) val recipeIngredients: List, @Relation( parentColumn = "recipe_id", diff --git a/database_test/src/main/kotlin/gq/kirmanak/mealient/database/TestData.kt b/database_test/src/main/kotlin/gq/kirmanak/mealient/database/TestData.kt index 388aef9c..ebea2793 100644 --- a/database_test/src/main/kotlin/gq/kirmanak/mealient/database/TestData.kt +++ b/database_test/src/main/kotlin/gq/kirmanak/mealient/database/TestData.kt @@ -4,6 +4,7 @@ import gq.kirmanak.mealient.database.recipe.entity.RecipeEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientToInstructionEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity +import gq.kirmanak.mealient.database.recipe.entity.RecipeSettingsEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeWithSummaryAndIngredientsAndInstructions import kotlinx.datetime.LocalDate @@ -18,6 +19,14 @@ val CAKE_RECIPE_SUMMARY_ENTITY = RecipeSummaryEntity( dateUpdated = LocalDateTime.parse("2021-11-13T15:30:13"), imageId = "1", isFavorite = false, + rating = 0, + recipeYield = "", + totalTime = "", + prepTime = "", + performTime = "", + cookTime = "", + groupId = "", + userId = "" ) val PORRIDGE_RECIPE_SUMMARY_ENTITY = RecipeSummaryEntity( @@ -29,6 +38,14 @@ val PORRIDGE_RECIPE_SUMMARY_ENTITY = RecipeSummaryEntity( dateUpdated = LocalDateTime.parse("2021-10-13T17:35:23"), imageId = "2", isFavorite = false, + rating = 0, + userId = "", + groupId = "", + recipeYield = "4 servings", + totalTime = "", + prepTime = "", + performTime = "", + cookTime = "", ) val TEST_RECIPE_SUMMARY_ENTITIES = @@ -62,8 +79,17 @@ val MIX_BREAD_RECIPE_INGREDIENT_INSTRUCTION_ENTITY = RecipeIngredientToInstructi val CAKE_RECIPE_ENTITY = RecipeEntity( remoteId = "1", - recipeYield = "4 servings", +) + +val CAKE_RECIPE_SETTINGS_ENTITY = RecipeSettingsEntity( disableAmounts = true, + locked = false, + remoteId = "1", + landscapeView = false, + showNutrition = true, + showAssets = true, + disableComments = false, + public = true ) val CAKE_SUGAR_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity( @@ -94,6 +120,7 @@ val CAKE_BREAD_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity( val FULL_CAKE_INFO_ENTITY = RecipeWithSummaryAndIngredientsAndInstructions( recipeEntity = CAKE_RECIPE_ENTITY, + recipeSettingsEntity = CAKE_RECIPE_SETTINGS_ENTITY, recipeSummaryEntity = CAKE_RECIPE_SUMMARY_ENTITY, recipeIngredients = listOf( CAKE_SUGAR_RECIPE_INGREDIENT_ENTITY, @@ -111,8 +138,17 @@ val FULL_CAKE_INFO_ENTITY = RecipeWithSummaryAndIngredientsAndInstructions( val PORRIDGE_RECIPE_ENTITY_FULL = RecipeEntity( remoteId = "2", - recipeYield = "3 servings", +) + +val PORRIDGE_RECIPE_SETTINGS_ENTITY = RecipeSettingsEntity( disableAmounts = true, + locked = false, + remoteId = "1", + landscapeView = false, + showNutrition = true, + showAssets = true, + disableComments = false, + public = true, ) val PORRIDGE_MILK_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity( @@ -158,6 +194,7 @@ val PORRIDGE_BOIL_RECIPE_INSTRUCTION_ENTITY = RecipeInstructionEntity( val FULL_PORRIDGE_INFO_ENTITY = RecipeWithSummaryAndIngredientsAndInstructions( recipeEntity = PORRIDGE_RECIPE_ENTITY_FULL, recipeSummaryEntity = PORRIDGE_RECIPE_SUMMARY_ENTITY, + recipeSettingsEntity = PORRIDGE_RECIPE_SETTINGS_ENTITY, recipeIngredients = listOf( PORRIDGE_SUGAR_RECIPE_INGREDIENT_ENTITY, PORRIDGE_MILK_RECIPE_INGREDIENT_ENTITY, diff --git a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/models/GetRecipeResponse.kt b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/models/GetRecipeResponse.kt index 3007789c..509f33cb 100644 --- a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/models/GetRecipeResponse.kt +++ b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/models/GetRecipeResponse.kt @@ -11,11 +11,25 @@ data class GetRecipeResponse( @SerialName("recipeIngredient") val ingredients: List = emptyList(), @SerialName("recipeInstructions") val instructions: List = emptyList(), @SerialName("settings") val settings: GetRecipeSettingsResponse? = null, + @SerialName("rating") val rating: Long? = null, + @SerialName("userId") val userId: String, + @SerialName("groupId") val groupId: String, + @SerialName("totalTime") val totalTime: String = "", + @SerialName("prepTime") val prepTime: String = "", + @SerialName("cookTime") val cookTime: String = "", + @SerialName("performTime") val performTime: String = "", ) @Serializable data class GetRecipeSettingsResponse( + @SerialName("id") val remoteId: String, + @SerialName("public") val public: Boolean, + @SerialName("showNutrition") val showNutrition: Boolean, + @SerialName("showAssets") val showAssets: Boolean, + @SerialName("landscapeView") val landscapeView: Boolean, + @SerialName("disableComments") val disableComments: Boolean, @SerialName("disableAmount") val disableAmount: Boolean, + @SerialName("locked") val locked: Boolean, ) @Serializable diff --git a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/models/GetRecipeSummaryResponse.kt b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/models/GetRecipeSummaryResponse.kt index c01bab5f..3700b90f 100644 --- a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/models/GetRecipeSummaryResponse.kt +++ b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/models/GetRecipeSummaryResponse.kt @@ -11,6 +11,14 @@ data class GetRecipeSummaryResponse( @SerialName("name") val name: String, @SerialName("slug") val slug: String, @SerialName("description") val description: String = "", + @SerialName("recipeYield") val recipeYield: String = "", @SerialName("dateAdded") val dateAdded: LocalDate, - @SerialName("dateUpdated") val dateUpdated: LocalDateTime + @SerialName("dateUpdated") val dateUpdated: LocalDateTime, + @SerialName("rating") val rating: Long?, + @SerialName("userId") val userId: String, + @SerialName("groupId") val groupId: String, + @SerialName("totalTime") val totalTime: String = "", + @SerialName("prepTime") val prepTime: String = "", + @SerialName("cookTime") val cookTime: String = "", + @SerialName("performTime") val performTime: String = "", ) \ No newline at end of file diff --git a/datasource_test/src/main/kotlin/gq/kirmanak/mealient/datasource_test/TestData.kt b/datasource_test/src/main/kotlin/gq/kirmanak/mealient/datasource_test/TestData.kt index a517707f..9ceb485a 100644 --- a/datasource_test/src/main/kotlin/gq/kirmanak/mealient/datasource_test/TestData.kt +++ b/datasource_test/src/main/kotlin/gq/kirmanak/mealient/datasource_test/TestData.kt @@ -25,6 +25,14 @@ val RECIPE_SUMMARY_CAKE = GetRecipeSummaryResponse( description = "A tasty cake", dateAdded = LocalDate.parse("2021-11-13"), dateUpdated = LocalDateTime.parse("2021-11-13T15:30:13"), + rating = null, + recipeYield = "4", + totalTime = "", + prepTime = "", + performTime = "", + cookTime = "", + userId = "1", + groupId = "1", ) val RECIPE_SUMMARY_PORRIDGE = GetRecipeSummaryResponse( @@ -34,6 +42,14 @@ val RECIPE_SUMMARY_PORRIDGE = GetRecipeSummaryResponse( description = "A tasty porridge", dateAdded = LocalDate.parse("2021-11-12"), dateUpdated = LocalDateTime.parse("2021-10-13T17:35:23"), + rating = null, + recipeYield = "4", + totalTime = "", + prepTime = "", + performTime = "", + cookTime = "", + userId = "1", + groupId = "1", ) val TEST_RECIPE_SUMMARIES = listOf(RECIPE_SUMMARY_CAKE, RECIPE_SUMMARY_PORRIDGE) @@ -70,6 +86,14 @@ val PORRIDGE_RECIPE_SUMMARY_RESPONSE = GetRecipeSummaryResponse( description = "A tasty porridge", dateAdded = LocalDate.parse("2021-11-12"), dateUpdated = LocalDateTime.parse("2021-10-13T17:35:23"), + rating = null, + recipeYield = "4", + totalTime = "", + prepTime = "", + performTime = "", + cookTime = "", + userId = "1", + groupId = "1", ) val MILK_RECIPE_INGREDIENT_RESPONSE = GetRecipeIngredientResponse( @@ -132,7 +156,16 @@ val BOIL_RECIPE_INSTRUCTION_RESPONSE = GetRecipeInstructionResponse( ingredientReferences = emptyList() ) -val NO_AMOUNT_RECIPE_SETTINGS_RESPONSE = GetRecipeSettingsResponse(disableAmount = true) +val NO_AMOUNT_RECIPE_SETTINGS_RESPONSE = GetRecipeSettingsResponse( + remoteId = "1", + disableAmount = true, + locked = false, + public = false, + disableComments = false, + showAssets = true, + showNutrition = true, + landscapeView = false, +) val CAKE_RECIPE_RESPONSE = GetRecipeResponse( remoteId = "1", @@ -140,6 +173,8 @@ val CAKE_RECIPE_RESPONSE = GetRecipeResponse( recipeYield = "4 servings", ingredients = listOf(SUGAR_RECIPE_INGREDIENT_RESPONSE, BREAD_RECIPE_INGREDIENT_RESPONSE), instructions = listOf(MIX_RECIPE_INSTRUCTION_RESPONSE, BAKE_RECIPE_INSTRUCTION_RESPONSE), + groupId = "123094870213", + userId = "12374879", settings = NO_AMOUNT_RECIPE_SETTINGS_RESPONSE, ) @@ -147,6 +182,8 @@ val PORRIDGE_RECIPE_RESPONSE = GetRecipeResponse( remoteId = "2", recipeYield = "3 servings", name = "Porridge", + groupId = "123094870213", + userId = "12374879", ingredients = listOf( SUGAR_RECIPE_INGREDIENT_RESPONSE, MILK_RECIPE_INGREDIENT_RESPONSE, diff --git a/model_mapper/src/main/kotlin/gq/kirmanak/mealient/model_mapper/ModelMapper.kt b/model_mapper/src/main/kotlin/gq/kirmanak/mealient/model_mapper/ModelMapper.kt index 2e575b2f..d583774b 100644 --- a/model_mapper/src/main/kotlin/gq/kirmanak/mealient/model_mapper/ModelMapper.kt +++ b/model_mapper/src/main/kotlin/gq/kirmanak/mealient/model_mapper/ModelMapper.kt @@ -3,6 +3,7 @@ package gq.kirmanak.mealient.model_mapper import gq.kirmanak.mealient.database.recipe.entity.RecipeEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity +import gq.kirmanak.mealient.database.recipe.entity.RecipeSettingsEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity import gq.kirmanak.mealient.datasource.models.AddRecipeInfo import gq.kirmanak.mealient.datasource.models.AddRecipeIngredient @@ -15,6 +16,7 @@ import gq.kirmanak.mealient.datasource.models.CreateRecipeRequest import gq.kirmanak.mealient.datasource.models.GetRecipeIngredientResponse import gq.kirmanak.mealient.datasource.models.GetRecipeInstructionResponse import gq.kirmanak.mealient.datasource.models.GetRecipeResponse +import gq.kirmanak.mealient.datasource.models.GetRecipeSettingsResponse import gq.kirmanak.mealient.datasource.models.GetRecipeSummaryResponse import gq.kirmanak.mealient.datasource.models.UpdateRecipeRequest import gq.kirmanak.mealient.datastore.recipe.AddRecipeDraft @@ -23,6 +25,8 @@ interface ModelMapper { fun toRecipeEntity(getRecipeResponse: GetRecipeResponse): RecipeEntity + fun toRecipeSettingsEntity(getRecipeSettingsResponse: GetRecipeSettingsResponse): RecipeSettingsEntity + fun toRecipeIngredientEntity( ingredientResponse: GetRecipeIngredientResponse, recipeId: String ): RecipeIngredientEntity diff --git a/model_mapper/src/main/kotlin/gq/kirmanak/mealient/model_mapper/ModelMapperImpl.kt b/model_mapper/src/main/kotlin/gq/kirmanak/mealient/model_mapper/ModelMapperImpl.kt index fc6431c2..dbdfd1db 100644 --- a/model_mapper/src/main/kotlin/gq/kirmanak/mealient/model_mapper/ModelMapperImpl.kt +++ b/model_mapper/src/main/kotlin/gq/kirmanak/mealient/model_mapper/ModelMapperImpl.kt @@ -3,6 +3,7 @@ package gq.kirmanak.mealient.model_mapper import gq.kirmanak.mealient.database.recipe.entity.RecipeEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity +import gq.kirmanak.mealient.database.recipe.entity.RecipeSettingsEntity import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity import gq.kirmanak.mealient.datasource.models.AddRecipeInfo import gq.kirmanak.mealient.datasource.models.AddRecipeIngredient @@ -15,6 +16,7 @@ import gq.kirmanak.mealient.datasource.models.CreateRecipeRequest import gq.kirmanak.mealient.datasource.models.GetRecipeIngredientResponse import gq.kirmanak.mealient.datasource.models.GetRecipeInstructionResponse import gq.kirmanak.mealient.datasource.models.GetRecipeResponse +import gq.kirmanak.mealient.datasource.models.GetRecipeSettingsResponse import gq.kirmanak.mealient.datasource.models.GetRecipeSummaryResponse import gq.kirmanak.mealient.datasource.models.UpdateRecipeRequest import gq.kirmanak.mealient.datastore.recipe.AddRecipeDraft @@ -26,8 +28,19 @@ class ModelMapperImpl @Inject constructor() : ModelMapper { override fun toRecipeEntity(getRecipeResponse: GetRecipeResponse) = RecipeEntity( remoteId = getRecipeResponse.remoteId, - recipeYield = getRecipeResponse.recipeYield, - disableAmounts = getRecipeResponse.settings?.disableAmount ?: true, + ) + + override fun toRecipeSettingsEntity( + settingsResponse: GetRecipeSettingsResponse + ) = RecipeSettingsEntity( + remoteId = settingsResponse.remoteId, + public = settingsResponse.public, + showNutrition = settingsResponse.showNutrition, + showAssets = settingsResponse.showAssets, + landscapeView = settingsResponse.landscapeView, + disableComments = settingsResponse.disableComments, + disableAmounts = settingsResponse.disableAmount, + locked = settingsResponse.public, ) override fun toRecipeIngredientEntity( @@ -69,6 +82,14 @@ class ModelMapperImpl @Inject constructor() : ModelMapper { dateUpdated = recipeSummaryInfo.dateUpdated, imageId = recipeSummaryInfo.remoteId, isFavorite = isFavorite, + rating = recipeSummaryInfo.rating ?: 0, + recipeYield = recipeSummaryInfo.recipeYield ?: "", + userId = recipeSummaryInfo.userId ?: "", + groupId = recipeSummaryInfo.groupId ?: "", + cookTime = recipeSummaryInfo.cookTime, + performTime = recipeSummaryInfo.cookTime, + prepTime = recipeSummaryInfo.cookTime, + totalTime = recipeSummaryInfo.cookTime, ) override fun toAddRecipeInfo(addRecipeDraft: AddRecipeDraft) = AddRecipeInfo(