Skip to content

Instantly share code, notes, and snippets.

@oddlyspaced
Created July 11, 2021 06:48
Show Gist options
  • Save oddlyspaced/8e8721c5891875796f465c38604d6818 to your computer and use it in GitHub Desktop.
Save oddlyspaced/8e8721c5891875796f465c38604d6818 to your computer and use it in GitHub Desktop.
Reference code for converting list to Paging source for Paging Adapters
viewModel.results.observe(viewLifecycleOwner, { posts ->
CoroutineScope(Dispatchers.Default).launch {
adapter.submitData(
Pager(PagingConfig(10)) {
object : PagingSource<Int, Post>() {
override fun getRefreshKey(state: PagingState<Int, Post>): Int? {
return null
}
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Post> {
return LoadResult.Page(posts, null, null)
}
}
}.flow.first()
)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment