Skip to content
This repository has been archived by the owner on Nov 9, 2024. It is now read-only.

Commit

Permalink
Fix showing loading indicator for shopping lists
Browse files Browse the repository at this point in the history
  • Loading branch information
kirmanak committed Jan 29, 2023
1 parent 1a741ee commit 3e2bbba
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private fun ShoppingListScreenContent(
val snackbarHostState: SnackbarHostState = remember { SnackbarHostState() }

val isListEmpty = items.itemCount == 0
val isContentRefreshing = items.isMediatorAppending()
val isContentRefreshing = items.isLoading()

logger.d { "ShoppingListScreenContent: itemCount = ${items.itemCount}, loadStates = ${items.loadState}" }

Expand All @@ -124,7 +124,7 @@ private fun ShoppingListScreenContent(
.fillMaxSize()

when {
isListEmpty && (isContentRefreshing || isRefreshing) -> {
isListEmpty && isContentRefreshing -> {
CenteredProgressIndicator(modifier = innerModifier)
}
isListEmpty -> {
Expand Down Expand Up @@ -284,12 +284,19 @@ private fun <T : Any> LazyPagingItems<T>.isMediatorRefreshing(): Boolean {
return loadState.mediator?.refresh is LoadState.Loading
}

private fun <T : Any> LazyPagingItems<T>.isMediatorAppending(): Boolean {
return loadState.mediator?.append is LoadState.Loading
private fun <T : Any> LazyPagingItems<T>.isLoading(): Boolean {
return listOf(
loadState.mediator?.refresh,
loadState.mediator?.append,
loadState.append,
loadState.refresh,
loadState.source.refresh,
loadState.source.append,
).any { it is LoadState.Loading }
}

private fun <T : Any> LazyPagingItems<T>.firstMediatorErrorOrNull(): Throwable? {
return listOfNotNull(
return listOf(
loadState.mediator?.refresh,
loadState.mediator?.append,
).filterIsInstance<LoadState.Error>().firstOrNull()?.error
Expand Down

0 comments on commit 3e2bbba

Please sign in to comment.