mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-09-20 08:00:40 +00:00
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)
|
private val service = NewPipe.getService(commentInfo.serviceId)
|
||||||
|
|
||||||
override suspend fun load(params: LoadParams<Page>): LoadResult<Page, CommentsInfoItem> {
|
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
|
return try {
|
||||||
val repliesPage = params.key ?: commentInfo.replies
|
// params.key is null the first time load() is called, and we need to return the first page
|
||||||
val info = withContext(Dispatchers.IO) {
|
val repliesPage = params.key ?: commentInfo.replies
|
||||||
CommentsInfo.getMoreItems(service, commentInfo.url, repliesPage)
|
|
||||||
|
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
|
override fun getRefreshKey(state: PagingState<Page, CommentsInfoItem>) = null
|
||||||
|
|||||||
Reference in New Issue
Block a user