Group Group Group Group Group Group Group Group Group

Paging Library for Android With Kotlin: Creating Infinite Lists | Ray Wenderlich

In this tutorial, you will build up a simple Reddit Clone that loads pages of information gradually into an infinite list using the Paging library and Room.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/6948-paging-library-for-android-with-kotlin-creating-infinite-lists

You have an error in this code block when implementing Room:

  private fun initializedPagedListBuilder(config: PagedList.Config):
          LivePagedListBuilder<Int, RedditPost> {

    val livePageListBuilder = LivePagedListBuilder<Int, RedditPost>(
            database.postDao().posts(),
            config)
    return livePageListBuilder
  }

Should contain the line:

    val database = RedditDb.create(this)

I just checked the final code to see this missing bit

@alexsullivan Can you please help with this when you get a chance? Thank you - much appreciated! :]

Good catch! I’ve updated the tutorial accordingly.

A nice feature to add in this tutorial is to keep the recyclerView position after device rotation.

I’m managing this onSaveInstanceState and onResume() methods, but maybe there is a better solution with LiveData that I’m not aware.

@andrezizu That’s a good idea! I think your best bet is going to be exposing the LiveData from a jetpack ViewModel object. The ViewModel will then be saved on rotation and your list should display immediately.

Great post. How do you deal with stale data? When you restart the app you get a old copy of your data in the recycler view.