Last active
November 2, 2018 14:01
-
-
Save chetdeva/ce1598c0456c5e7c468ef0c2c8f09a3d to your computer and use it in GitHub Desktop.
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
/** | |
* A data source that uses the before/after keys returned in page requests. | |
*/ | |
class GithubPageKeyedDataSource : PageKeyedDataSource<Int, Item>() { | |
override fun loadInitial(params: LoadInitialParams<Int>, | |
callback: LoadInitialCallback<Int, Item>) { | |
val currentPage = 1 | |
val nextPage = currentPage + 1 | |
val request = githubApi.searchUsers( | |
query = searchQuery, | |
page = currentPage, | |
perPage = params.requestedLoadSize) | |
// Retrofit Call onResponse omitted | |
callback.onResult(items, null, nextPage) | |
} | |
override fun loadAfter(params: LoadParams<Int>, | |
callback: LoadCallback<Int, Item>) { | |
val currentPage = params.key | |
val nextPage = currentPage + 1 | |
val request = githubApi.searchUsersAsync( | |
query = searchQuery, | |
page = currentPage, | |
perPage = params.requestedLoadSize) | |
// Retrofit Call onResponse omitted | |
callback.onResult(items, nextPage) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment