mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-04-17 20:31:23 +00:00
Merge pull request #13418 from Ecomont/fix/offline-comments-crash
Fix crash when loading offline comments in CommentRepliesSource
This commit is contained in:
@@ -15,12 +15,20 @@ class CommentRepliesSource(
|
||||
private val service = NewPipe.getService(commentInfo.serviceId)
|
||||
|
||||
override suspend fun load(params: LoadParams<Page>): LoadResult<Page, CommentsInfoItem> {
|
||||
// params.key is null the first time load() is called, and we need to return the first page
|
||||
val repliesPage = params.key ?: commentInfo.replies
|
||||
val info = withContext(Dispatchers.IO) {
|
||||
CommentsInfo.getMoreItems(service, commentInfo.url, repliesPage)
|
||||
return try {
|
||||
// params.key is null the first time load() is called, and we need to return the first page
|
||||
val repliesPage = params.key ?: commentInfo.replies
|
||||
|
||||
val info = withContext(Dispatchers.IO) {
|
||||
CommentsInfo.getMoreItems(service, commentInfo.url, repliesPage)
|
||||
}
|
||||
|
||||
LoadResult.Page(info.items, null, info.nextPage)
|
||||
} catch (e: Exception) {
|
||||
// Catches UnknownHostException (offline) or any extraction errors
|
||||
// and tells Paging3 to show the error state in the UI.
|
||||
LoadResult.Error(e)
|
||||
}
|
||||
return LoadResult.Page(info.items, null, info.nextPage)
|
||||
}
|
||||
|
||||
override fun getRefreshKey(state: PagingState<Page, CommentsInfoItem>) = null
|
||||
|
||||
Reference in New Issue
Block a user