1

I am using paging library (part of android jetpack), and override PageKeyedDataSource. This class have three methods ,and i have to get the current page Token but did not find any a way to get current page token.

   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) })
            })
    )
}

Is there any method to get Page Token? how can i get the current loaded Page token from this PageKeyedDataSource in my activity/viewmodel.

Hussnain Haidar
  • 2,200
  • 19
  • 30

0 Answers0