Fix absent recipe refresh on authorization

This commit is contained in:
Kirill Kamakin
2022-11-13 15:38:45 +01:00
parent 280f282972
commit 32d366b8fd
5 changed files with 33 additions and 36 deletions

View File

@@ -15,4 +15,6 @@ interface RecipeRepo {
suspend fun loadRecipeInfo(recipeId: String): FullRecipeEntity?
fun updateNameQuery(name: String?)
suspend fun refreshRecipes()
}

View File

@@ -25,7 +25,11 @@ class RecipeRepoImpl @Inject constructor(
override fun createPager(): Pager<Int, RecipeSummaryEntity> {
logger.v { "createPager() called" }
val pagingConfig = PagingConfig(pageSize = LOAD_PAGE_SIZE, enablePlaceholders = true)
val pagingConfig = PagingConfig(
pageSize = LOAD_PAGE_SIZE,
enablePlaceholders = true,
initialLoadSize = INITIAL_LOAD_PAGE_SIZE,
)
return Pager(
config = pagingConfig,
remoteMediator = mediator,
@@ -59,7 +63,17 @@ class RecipeRepoImpl @Inject constructor(
pagingSourceFactory.setQuery(name)
}
override suspend fun refreshRecipes() {
logger.v { "refreshRecipes() called" }
runCatchingExceptCancel {
storage.refreshAll(dataSource.requestRecipes(0, INITIAL_LOAD_PAGE_SIZE))
}.onFailure {
logger.e(it) { "Can't refresh recipes" }
}
}
companion object {
private const val LOAD_PAGE_SIZE = 50
private const val INITIAL_LOAD_PAGE_SIZE = LOAD_PAGE_SIZE * 3
}
}