android / codelab-android-paging

Jetpack Paging codelab
Apache License 2.0
495 stars 268 forks source link

Auto scroll to bottom for initial loading and does not load subsequent page #165

Open anderscheow opened 3 years ago

anderscheow commented 3 years ago

Issues:

  1. When loading first page for the first time, recycler view scrolled to very bottom
  2. Sometimes does not load subsequent page after loading first page for the first time

https://drive.google.com/drive/folders/14aOosTqeY747SajXxcgwTrzLwD51NZNP?usp=sharing

johnjake commented 3 years ago

I encounter the same scenario where in subsequent page does not load only page 1, the reason because list table must align to remoteKeys table, take a look on Mediator code the getKeyForLastItem, getKeyForFirstItem, getKeyToCurrentPosition

    `database.remoteKeysDao().remoteKeysRepoId(userDB.id)` 

the paging uses 2 tables to cache the list, your list table and remotekeys table.

example:

UserDB----------------------------------------------- Remotekeys @PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
val uid: Int ---------------------------------- val repoId: Int val id: Int ------------------------------------ val prevKey: Int

In above example the UserDB has two Ids uid which is the autogenerated int when you insert a value in UserDB table, and the val id: int which is the list Id from your api endpoint. During loading data to mediator you are using the val id: Int to create or insert RemoteKeys repoId, prevKey and nextKey. Make sure you are using the same Id in remotekeys and userDB. If I change the database.remoteKeysDao().remoteKeysRepoId(userDB.uid) I will only get page 1 with no subsequent pages. As uid is not equal to repoId which is the val id: int of UserDB.

imSathish commented 2 years ago

@anderscheow Facing the same issue. Any update about the issue