Show Toast when recipe favorite status is updated
This commit is contained in:
@@ -18,7 +18,7 @@ interface RecipeRepo {
|
||||
|
||||
suspend fun refreshRecipes()
|
||||
|
||||
suspend fun updateIsRecipeFavorite(recipeSlug: String, isFavorite: Boolean): Result<Unit>
|
||||
suspend fun updateIsRecipeFavorite(recipeSlug: String, isFavorite: Boolean): Result<Boolean>
|
||||
|
||||
suspend fun deleteRecipe(entity: RecipeSummaryEntity): Result<Unit>
|
||||
}
|
||||
@@ -75,12 +75,13 @@ class RecipeRepoImpl @Inject constructor(
|
||||
override suspend fun updateIsRecipeFavorite(
|
||||
recipeSlug: String,
|
||||
isFavorite: Boolean,
|
||||
): Result<Unit> = runCatchingExceptCancel {
|
||||
): Result<Boolean> = runCatchingExceptCancel {
|
||||
logger.v { "updateIsRecipeFavorite() called with: recipeSlug = $recipeSlug, isFavorite = $isFavorite" }
|
||||
dataSource.updateIsRecipeFavorite(recipeSlug, isFavorite)
|
||||
val favorites = dataSource.getFavoriteRecipes()
|
||||
storage.updateFavoriteRecipes(favorites)
|
||||
pagingSourceFactory.invalidate()
|
||||
favorites.contains(recipeSlug)
|
||||
}.onFailure {
|
||||
logger.e(it) { "Can't update recipe's is favorite status" }
|
||||
}
|
||||
|
||||
@@ -177,6 +177,15 @@ class RecipesListFragment : Fragment(R.layout.fragment_recipes_list) {
|
||||
logger.d { "onFavoriteClick: result is $it" }
|
||||
if (it.isFailure) {
|
||||
showLongToast(R.string.fragment_recipes_favorite_update_failed)
|
||||
} else {
|
||||
val name = event.recipeSummaryEntity.name
|
||||
val isFavorite = it.getOrThrow()
|
||||
val message = if (isFavorite) {
|
||||
getString(R.string.fragment_recipes_favorite_added, name)
|
||||
} else {
|
||||
getString(R.string.fragment_recipes_favorite_removed, name)
|
||||
}
|
||||
showLongToast(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user