Fix crash when loading offline comments in CommentRepliesSource

This commit is contained in:
h
2026-04-14 06:35:35 +02:00
parent 25c12ef81e
commit 064458cccd
@@ -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