square / cycler

Apache License 2.0
791 stars 27 forks source link

Paging Library support? #9

Open kuuuurt opened 4 years ago

kuuuurt commented 4 years ago

Great library! How can we use this library with AAC's paging?

helios175 commented 4 years ago

Thanks a lot!

I'll dive a little bit on AAC to know how it can work. I didn't look at it to be honest.

Anyway I can tell we are following certain patterns: we want all the data updating / asynchronous behavior to happen outside the View. The View is a dumb presenter (well, the square/worflow way. That means we don't let the View to take control of when/how to ask for more data, and how to update, but it's separate.

What we can do in such scenario is to leverage AAC's data retrieval, but don't use the PagedListAdapter (?). It is: not letting it take control of the recycler, just receiving the updates and controlling the data update from there.

What you can do right now is "adding data" to the recycler:

recycler.update {
  addChunk(someList)
  addChunk(someOtherList)
}

As long as you don't set the data it will understand those added chunks are added on the old data, and it will know how to notifyItemRangeInserted instead of doing a DiffUtil.

There's still some improvements as mentioned in #10 about making a more nicer update code, and I'm not sure if the calls to addChunk end up copying the original list which even if not the most pressing need, is not ideal. So there will be updates in the future to make for a hopefully optimal data source update via added chunks, not only via new list + diffing.