paug / AndroidMakersApp

📱Official companion app for Android Makers by droidcon 🇫🇷
https://androidmakers.droidcon.com/
117 stars 27 forks source link

Paginate sessions #313

Closed BoD closed 1 month ago

BoD commented 1 month ago

Loads the sessions by pages of 10, instead of loading the whole list immediately.

This is meant to look at how the Apollo Kotlin pagination system can be implemented in a real project.

Caveat: the pages are based on the contents of the list: when getting the first few items, we only know about Day 1, and only when scrolling to the end of Day 1 do we know that there's a Day 2, and the pager gets updated. Because of this, this can't be merged and I'll close the PR right now - at least it's a reference at how to use the pagination system that will be in the PR history.

The steps were:

  1. depend on the incubating artifacts
  2. update extra.graphqls 2.1 mark sessions as embedded 2.2 mark sessions.first and .after as pagination args 2.3 mark pageInfo as embedded
  3. implement a MetaDataGenerator to keep track of endCursor and after
  4. implement a FieldMerger to merge the nodes lists
  5. watch the sessions, so the UI is refreshed when a page is appended
  6. add a fetchNextSessionsPage fun and call it from the UI when reaching the end of the LazyColumn

Note: steps 2-4 would have been simpler if the schema were following the Relay pagination spec - the rest would have been the same.

pagination.webm