-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The previous implementation was skipping the first page of comments
- Loading branch information
Showing
3 changed files
with
41 additions
and
28 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/src/main/java/org/schabi/newpipe/paging/CommentRepliesSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.schabi.newpipe.paging | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.schabi.newpipe.extractor.NewPipe | ||
import org.schabi.newpipe.extractor.Page | ||
import org.schabi.newpipe.extractor.comments.CommentsInfo | ||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem | ||
|
||
class CommentRepliesSource( | ||
private val commentInfo: CommentsInfoItem, | ||
) : PagingSource<Page, CommentsInfoItem>() { | ||
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 LoadResult.Page(info.items, null, info.nextPage) | ||
} | ||
|
||
override fun getRefreshKey(state: PagingState<Page, CommentsInfoItem>) = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters