Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/src/main/java/org/schabi/newpipe/paging/CommentsSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ class CommentsSource(private val commentInfo: CommentInfo) : PagingSource<Page,
if (params.key == null) {
return LoadResult.Page(commentInfo.comments, null, commentInfo.nextPage)
} else {
val info = withContext(Dispatchers.IO) {
CommentsInfo.getMoreItems(service, commentInfo.url, params.key)
return try {
val info = withContext(Dispatchers.IO) {
CommentsInfo.getMoreItems(service, commentInfo.url, params.key)
}
LoadResult.Page(info.items, null, info.nextPage)
} catch (exception: Exception) {
LoadResult.Error(exception)
}

return LoadResult.Page(info.items, null, info.nextPage)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,37 @@ private fun CommentSection(
items(comments.itemCount) {
Comment(comment = comments[it]!!) {}
}

// handle append (next page) errors
when (comments.loadState.append) {
is LoadState.Error -> {
item {
ErrorPanel(
errorInfo = ErrorInfo(
throwable = (comments.loadState.append as LoadState.Error).error,
userAction = UserAction.REQUESTED_COMMENTS,
request = "comments"
),
onRetry = { comments.retry() },
modifier = Modifier.fillMaxWidth()
)
}
}

// show loading indicator while appending
is LoadState.Loading -> {
item {
LoadingIndicator(
modifier = Modifier.padding(
top = 8.dp,
bottom = 8.dp
)
)
}
}

else -> {}
}
}
}
}
Expand Down
Loading