Refresh favorite recipes on change
This commit is contained in:
@@ -17,4 +17,6 @@ interface RecipeStorage {
|
||||
suspend fun saveRecipeInfo(recipe: FullRecipeInfo)
|
||||
|
||||
suspend fun queryRecipeInfo(recipeId: String): FullRecipeEntity?
|
||||
|
||||
suspend fun updateFavoriteRecipes(favorites: List<String>)
|
||||
}
|
||||
@@ -72,4 +72,12 @@ class RecipeStorageImpl @Inject constructor(
|
||||
logger.v { "queryRecipeInfo() returned: $fullRecipeInfo" }
|
||||
return fullRecipeInfo
|
||||
}
|
||||
|
||||
override suspend fun updateFavoriteRecipes(favorites: List<String>) {
|
||||
logger.v { "updateFavoriteRecipes() called with: favorites = $favorites" }
|
||||
db.withTransaction {
|
||||
recipeDao.setFavorite(favorites)
|
||||
recipeDao.setNonFavorite(favorites)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,7 @@ class RecipeRepoImpl @Inject constructor(
|
||||
logger.v { "updateIsRecipeFavorite() called with: recipeSlug = $recipeSlug, isFavorite = $isFavorite" }
|
||||
runCatchingExceptCancel {
|
||||
dataSource.updateIsRecipeFavorite(recipeSlug, isFavorite)
|
||||
mediator.onFavoritesChange()
|
||||
}.onFailure {
|
||||
logger.e(it) { "Can't update recipe's is favorite status" }
|
||||
}
|
||||
|
||||
@@ -79,4 +79,10 @@ class RecipesRemoteMediator @Inject constructor(
|
||||
else storage.saveRecipes(entities)
|
||||
recipes.size
|
||||
}
|
||||
|
||||
suspend fun onFavoritesChange() {
|
||||
val favorites = network.getFavoriteRecipes()
|
||||
storage.updateFavoriteRecipes(favorites)
|
||||
pagingSourceFactory.invalidate()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user