Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

05-paging #12

Open
wants to merge 1 commit into
base: 04-live-data-and-view-model
Choose a base branch
from
Open

05-paging #12

wants to merge 1 commit into from

Conversation

Serchinastico
Copy link
Contributor

@Serchinastico Serchinastico commented Feb 6, 2019

This PR is not meant to be merged

This is how to use the Paging component:

  • Return PagedList instead of a simple List of elements (in this case, SuperHero). Room already gives support to it and deals with pagination for you but it's up to the developer to have a backing data source that supports pagination.
  • Create a BoundaryCallback implementation. It is called whenever the LivePagedListBuilder created in the local data source runs out of elements. It has to fetch the new elements from somewhere, in our case from the RemoteSuperHeroDataSource and store them in the LocalSuperHeroDataSource. The API is too simple as it only returns the last item it found, that means that we have to deal with knowing what page is that in our system. In this PR we are just storing an index that is increasing with every new fetch but if the application would be more complex we'd have to create a fancier mechanism. BTW, the callback is a repository dependency because if I'd add it as a dependency of the local data source I'd be creating a dependency cycle.
  • Replace the regular RecyclerView.Adapter by a PagedListAdapter. It is this element the one really firing the event in case we need more elements. It relies on you calling the getItem method so you are forced to call it from your implementation adapter even if it's not used.
  • Because the paging adapter is using the diff'ing algorithm we are adding a short sleep in our tests to wait for animations to finish.

Copy link
Member

@davideme davideme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @Serchinastico !!!!

@Serchinastico Serchinastico force-pushed the 05-paging branch 4 times, most recently from 320c8d6 to 190583a Compare February 6, 2019 17:14
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch 2 times, most recently from 7482884 to 6100eb2 Compare March 15, 2019 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants