我正在使用分页库(android jetpack的一部分),并覆盖PageKeyedDataSource。此类有三种方法,我必须获取当前页面令牌,但找不到任何方法来获取当前页面令牌。
override fun loadInitial(params: LoadInitialParams<String>, callback: LoadInitialCallback<String, Item>) {
updateState(State.LOADING)
compositeDisposable.add(
networkService.getPlaylistVideos(Constants.PLAYLIST_ID
,""
,Constants.API_KEY)
.subscribe( { response ->
updateState(State.DONE)
callback.onResult(response.items, response.prevPageToken, response.nextPageToken)
},
{
updateState(State.ERROR)
setRetry(Action { loadInitial(params,callback) })
}
)
)
}
override fun loadAfter(params: LoadParams<String>, callback: LoadCallback<String, Item>) {
updateState(State.LOADING)
compositeDisposable.add(
networkService.getPlaylistVideos(Constants.PLAYLIST_ID, params.key,Constants.API_KEY)
.subscribe(
{ response ->
updateState(State.DONE)
callback.onResult(response.items
,response.nextPageToken)
}, {
updateState(State.ERROR)
setRetry(Action { loadAfter(params, callback) })
})
)
}
override fun loadBefore(params: LoadParams<String>, callback: LoadCallback<String, Item>) {
updateState(State.LOADING)
compositeDisposable.add(
networkService.getPlaylistVideos(Constants.PLAYLIST_ID,params.key,Constants.API_KEY)
.subscribe({ response ->
updateState(State.DONE)
callback.onResult(response.items
,response.prevPageToken)
},{
updateState(State.ERROR)
setRetry(Action { loadBefore(params, callback) })
})
)
}
有什么方法可以获取页面令牌?如何从我的活动/视图模型中的此PageKeyedDataSource获取当前加载的Page令牌。