Skip to content

Commit a44e65e

Browse files
authored
Merge pull request #13448 from TeamNewPipe/comment-crash
fix app crash on loading comment section with no internet
2 parents 7b98b40 + 188ba0a commit a44e65e

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

app/src/main/java/org/schabi/newpipe/paging/CommentsSource.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ class CommentsSource(private val commentInfo: CommentInfo) : PagingSource<Page,
2020
if (params.key == null) {
2121
return LoadResult.Page(commentInfo.comments, null, commentInfo.nextPage)
2222
} else {
23-
val info = withContext(Dispatchers.IO) {
24-
CommentsInfo.getMoreItems(service, commentInfo.url, params.key)
23+
return try {
24+
val info = withContext(Dispatchers.IO) {
25+
CommentsInfo.getMoreItems(service, commentInfo.url, params.key)
26+
}
27+
LoadResult.Page(info.items, null, info.nextPage)
28+
} catch (exception: Exception) {
29+
LoadResult.Error(exception)
2530
}
26-
27-
return LoadResult.Page(info.items, null, info.nextPage)
2831
}
2932
}
3033

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,37 @@ private fun CommentSection(
139139
items(comments.itemCount) {
140140
Comment(comment = comments[it]!!) {}
141141
}
142+
143+
// handle append (next page) errors
144+
when (comments.loadState.append) {
145+
is LoadState.Error -> {
146+
item {
147+
ErrorPanel(
148+
errorInfo = ErrorInfo(
149+
throwable = (comments.loadState.append as LoadState.Error).error,
150+
userAction = UserAction.REQUESTED_COMMENTS,
151+
request = "comments"
152+
),
153+
onRetry = { comments.retry() },
154+
modifier = Modifier.fillMaxWidth()
155+
)
156+
}
157+
}
158+
159+
// show loading indicator while appending
160+
is LoadState.Loading -> {
161+
item {
162+
LoadingIndicator(
163+
modifier = Modifier.padding(
164+
top = 8.dp,
165+
bottom = 8.dp
166+
)
167+
)
168+
}
169+
}
170+
171+
else -> {}
172+
}
142173
}
143174
}
144175
}

0 commit comments

Comments
 (0)