我一直在努力研究如何解决我的RemoteMediator's问题APPEND LoadType。
在空的 Room DB 上,LoadType流程如下:REFRESH -> PREPEND -> APPEND (remoteKeys = null, endOfPaginationReached = true)
实体和远程键表至少有 10 行,LoadType流程如下:REFRESH -> PREPEND -> APPEND (remoteKeys = prev=null, next=2, endOfPaginationReached = false)
显然,我的问题出在新安装的设备上(带有空的 Room DB),用户不会看到超过 10 个项目,因为APPEND'sstate.lastItemOrNull()正在返回null。
到目前为止,这是我的代码:
private suspend fun getRemoteKeysForLastItem(state: PagingState<Int, MovieCache>): MovieRemoteKeys? {
return state.lastItemOrNull()?.let { movie ->
appDatabase.withTransaction {
appDatabase.remoteKeysDao().remoteKeysByImdbId(movie.imdbId)
}
}
}
Run Code Online (Sandbox Code Playgroud)
对于我的load()功能:
val loadKey = when (loadType) {
LoadType.REFRESH -> …Run Code Online (Sandbox Code Playgroud) android android-paging android-paging-library android-paging-3