Android paging Jetpack Paging3 RemoteMediator在加载时返回相同的分页数据

Android paging Jetpack Paging3 RemoteMediator在加载时返回相同的分页数据,android-paging,android-paging-library,android-paging-3,Android Paging,Android Paging Library,Android Paging 3,下面我将使用github API和本地数据库构建一个paging3应用程序。虽然前两页加载良好,但在尝试加载第三页时,当滚动到底部时,中介器会遇到一个循环-相同的PagingState会一遍又一遍地传递给load函数 只是想知道是否有人知道这里可能的根本原因是什么 一些实施细节: RemoteMediator:prevPage和currentPage来自github API并保存到本地数据库 // RepositoryMediator override suspend fun load(

下面我将使用github API和本地数据库构建一个paging3应用程序。虽然前两页加载良好,但在尝试加载第三页时,当滚动到底部时,中介器会遇到一个循环-相同的PagingState会一遍又一遍地传递给load函数

只是想知道是否有人知道这里可能的根本原因是什么

一些实施细节:

RemoteMediator:prevPage和currentPage来自github API并保存到本地数据库

// RepositoryMediator
override suspend fun load(
    loadType: LoadType,
    state: PagingState<Int, Repository>
): MediatorResult {
    return when (loadType) {
        LoadType.REFRESH -> {
            fireRequestForPage(1, true /*clear DB*/)
            return Success(endOfPaginationReached = false)
        }

        LoadType.APPEND -> {
            // !!!!!!! kept getting the same state when APPEND is triggered, resulting in same currentPage and nextPage
            // get currentPage, nextPage from state.lastItemOrNull
            if(currentPage < nextPage) {
              fireRequestForPage(nextPage)
              Success(endOfPaginationReached = false)
            } else {
              return Success(endOfPaginationReached = true)
            }
        LoadType.PREPEND -> {
            // get currentPage, prevPage from state.firstItemOrNull
            if(currentPage > prevPage) {
              fireRequestForPage(prevPage)
              Success(endOfPaginationReached = false)
            } else {
              return Success(endOfPaginationReached = true)
            }
        }
    }
}
道:只是一个简单的查询

@Query("SELECT * FROM repository_table WHERE login = :ownerLoginName")
fun getRepositoriesOfUser(ownerLoginName: String): PagingSource<Int, Repository>

对于任何感兴趣的人来说,修复程序来自Dao,需要更新查询以按reponame排序,否则查询将返回PagingSource的相同最后一页,即使有新项插入到DB中,也会混淆中介程序

@Query("SELECT * FROM repository_table WHERE login = :ownerLoginName ORDER BY repository_name ASC")
fun getRepositoriesOfUser(ownerLoginName: String): PagingSource<Int, Repository>
@Query("SELECT * FROM repository_table WHERE login = :ownerLoginName ORDER BY repository_name ASC")
fun getRepositoriesOfUser(ownerLoginName: String): PagingSource<Int, Repository>