Solution for Network-Database (Room) Paging with Paging library, LiveData and Coroutine

Why did I write this article?

I missed one thing in my journey.

How to implement Network-Database (Room) structure list with Paging library from Jetpack and Coroutine.

Pulling data from ROOM local database:

Pulling data from Network with coroutine.

private suspend fun loadFromZero(subName: String, loadSize: Int) =
redditAPI.getTop(subreddit = subName, limit = loadSize)
.data
.children
.map {
it
.data
}
private suspend fun loadMorePosts(
subName: String,
after: String,
loadSize: Int
) = redditAPI.getTopAfter(subreddit = subName, after = after, limit = loadSize)
.data
.children
.map {
it
.data
}
loadMoreState: MutableLiveData<State>

Let’s connect them together.

Photo by Alexandre Debiève on Unsplash

Conclusion.

Dad, Husband, Android Developer, Manga/Video Game Lover, Unity3d learner.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store