Created
July 11, 2021 06:48
-
-
Save oddlyspaced/8e8721c5891875796f465c38604d6818 to your computer and use it in GitHub Desktop.
Reference code for converting list to Paging source for Paging Adapters
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
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