Initialize recipe removal feature
This commit is contained in:
@@ -47,6 +47,10 @@ class RecipeViewHolder @AssistedInject constructor(
|
||||
override val recipeSummaryEntity: RecipeSummaryEntity
|
||||
) : ClickEvent()
|
||||
|
||||
data class DeleteClick(
|
||||
override val recipeSummaryEntity: RecipeSummaryEntity
|
||||
) : ClickEvent()
|
||||
|
||||
}
|
||||
|
||||
private val loadingPlaceholder by lazy {
|
||||
@@ -62,6 +66,7 @@ class RecipeViewHolder @AssistedInject constructor(
|
||||
logger.d { "bind: item clicked $entity" }
|
||||
clickListener(ClickEvent.RecipeClick(entity))
|
||||
}
|
||||
|
||||
binding.favoriteIcon.isVisible = showFavoriteIcon
|
||||
binding.favoriteIcon.setOnClickListener {
|
||||
clickListener(ClickEvent.FavoriteClick(entity))
|
||||
@@ -80,6 +85,10 @@ class RecipeViewHolder @AssistedInject constructor(
|
||||
R.string.view_holder_recipe_non_favorite_content_description
|
||||
}
|
||||
)
|
||||
|
||||
binding.deleteIcon.setOnClickListener {
|
||||
clickListener(ClickEvent.DeleteClick(item))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ class RecipesListFragment : Fragment(R.layout.fragment_recipes_list) {
|
||||
is RecipeViewHolder.ClickEvent.RecipeClick -> {
|
||||
onRecipeClicked(it.recipeSummaryEntity)
|
||||
}
|
||||
is RecipeViewHolder.ClickEvent.DeleteClick -> {
|
||||
onDeleteClick(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +142,16 @@ class RecipesListFragment : Fragment(R.layout.fragment_recipes_list) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDeleteClick(event: RecipeViewHolder.ClickEvent) {
|
||||
logger.v { "onDeleteClick() called with: event = $event" }
|
||||
viewModel.onDeleteConfirm(event.recipeSummaryEntity).observe(viewLifecycleOwner) {
|
||||
logger.d { "onDeleteClick: result is $it" }
|
||||
if (it.isFailure) {
|
||||
showLongToast(R.string.fragment_recipes_delete_recipe_failed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onFavoriteClick(event: RecipeViewHolder.ClickEvent) {
|
||||
logger.v { "onFavoriteClick() called with: event = $event" }
|
||||
viewModel.onFavoriteIconClick(event.recipeSummaryEntity).observe(viewLifecycleOwner) {
|
||||
|
||||
@@ -49,4 +49,9 @@ class RecipesListViewModel @Inject constructor(
|
||||
isFavorite = recipeSummaryEntity.isFavorite.not(),
|
||||
).also { emit(it) }
|
||||
}
|
||||
|
||||
fun onDeleteConfirm(recipeSummaryEntity: RecipeSummaryEntity) = liveData {
|
||||
logger.v { "onDeleteConfirm() called with: recipeSummaryEntity = $recipeSummaryEntity" }
|
||||
recipeRepo.deleteRecipe(recipeSummaryEntity.slug).also { emit(it) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user