Ignore ingredients with empty note
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -4,6 +4,7 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import androidx.lifecycle.asFlow
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import gq.kirmanak.mealient.data.recipes.RecipeRepo
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import gq.kirmanak.mealient.test.FakeLogger
|
||||
import gq.kirmanak.mealient.test.RecipeImplTestData.FULL_CAKE_INFO_ENTITY
|
||||
@@ -54,11 +55,19 @@ class RecipeInfoViewModelTest {
|
||||
|
||||
@Test
|
||||
fun `when recipe is found then UI state has data`() = runTest {
|
||||
coEvery { recipeRepo.loadRecipeInfo(eq(RECIPE_ID)) } returns FULL_CAKE_INFO_ENTITY
|
||||
val emptyNoteIngredient = RecipeIngredientEntity(recipeId = "42", note = "")
|
||||
val returnedEntity = FULL_CAKE_INFO_ENTITY.copy(
|
||||
recipeIngredients = FULL_CAKE_INFO_ENTITY.recipeIngredients + emptyNoteIngredient
|
||||
)
|
||||
coEvery { recipeRepo.loadRecipeInfo(eq(RECIPE_ID)) } returns returnedEntity
|
||||
val expected = RecipeInfoUiState(
|
||||
areIngredientsVisible = true,
|
||||
areInstructionsVisible = true,
|
||||
recipeInfo = FULL_CAKE_INFO_ENTITY
|
||||
showIngredients = true,
|
||||
showInstructions = true,
|
||||
summaryEntity = FULL_CAKE_INFO_ENTITY.recipeSummaryEntity,
|
||||
recipeIngredients = FULL_CAKE_INFO_ENTITY.recipeIngredients,
|
||||
recipeInstructions = FULL_CAKE_INFO_ENTITY.recipeInstructions,
|
||||
title = FULL_CAKE_INFO_ENTITY.recipeSummaryEntity.name,
|
||||
description = FULL_CAKE_INFO_ENTITY.recipeSummaryEntity.description,
|
||||
)
|
||||
val actual = createSubject().uiState.asFlow().first()
|
||||
assertThat(actual).isEqualTo(expected)
|
||||
|
||||
Reference in New Issue
Block a user