Ignore ingredients with empty note

This commit is contained in:
Kirill Kamakin
2022-11-06 20:02:51 +01:00
parent 377509d160
commit 0c0248dbbc
4 changed files with 38 additions and 21 deletions

View File

@@ -62,15 +62,13 @@ class RecipeInfoFragment : BottomSheetDialogFragment() {
private fun onUiStateChange(uiState: RecipeInfoUiState) = with(binding) {
logger.v { "onUiStateChange() called" }
ingredientsHolder.isVisible = uiState.areIngredientsVisible
instructionsGroup.isVisible = uiState.areInstructionsVisible
uiState.recipeInfo?.let {
recipeImageLoader.loadRecipeImage(image, it.recipeSummaryEntity)
title.text = it.recipeSummaryEntity.name
description.text = it.recipeSummaryEntity.description
ingredientsAdapter.submitList(it.recipeIngredients)
instructionsAdapter.submitList(it.recipeInstructions)
}
ingredientsHolder.isVisible = uiState.showIngredients
instructionsGroup.isVisible = uiState.showInstructions
recipeImageLoader.loadRecipeImage(image, uiState.summaryEntity)
title.text = uiState.title
description.text = uiState.description
ingredientsAdapter.submitList(uiState.recipeIngredients)
instructionsAdapter.submitList(uiState.recipeInstructions)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog =

View File

@@ -1,9 +1,15 @@
package gq.kirmanak.mealient.ui.recipes.info
import gq.kirmanak.mealient.database.recipe.entity.FullRecipeEntity
import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity
import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
data class RecipeInfoUiState(
val areIngredientsVisible: Boolean = false,
val areInstructionsVisible: Boolean = false,
val recipeInfo: FullRecipeEntity? = null,
val showIngredients: Boolean = false,
val showInstructions: Boolean = false,
val summaryEntity: RecipeSummaryEntity? = null,
val recipeIngredients: List<RecipeIngredientEntity> = emptyList(),
val recipeInstructions: List<RecipeInstructionEntity> = emptyList(),
val title: String? = null,
val description: String? = null,
)

View File

@@ -20,11 +20,15 @@ class RecipeInfoViewModel @Inject constructor(
val uiState: LiveData<RecipeInfoUiState> = liveData {
logger.v { "Initializing UI state with args = $args" }
val state = recipeRepo.loadRecipeInfo(args.recipeId)?.let {
val state = recipeRepo.loadRecipeInfo(args.recipeId)?.let { entity ->
RecipeInfoUiState(
areIngredientsVisible = it.recipeIngredients.isNotEmpty(),
areInstructionsVisible = it.recipeInstructions.isNotEmpty(),
recipeInfo = it,
showIngredients = entity.recipeIngredients.isNotEmpty(),
showInstructions = entity.recipeInstructions.isNotEmpty(),
summaryEntity = entity.recipeSummaryEntity,
recipeIngredients = entity.recipeIngredients.filter { it.note.isNotBlank() },
recipeInstructions = entity.recipeInstructions.filter { it.text.isNotBlank() },
title = entity.recipeSummaryEntity.name,
description = entity.recipeSummaryEntity.description,
)
} ?: RecipeInfoUiState()
emit(state)