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 04-live-data-and-view-model branch from ed51a17 to e5b3c72 Compare February 6, 2019 12:13
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch from e5b3c72 to 592849a Compare February 6, 2019 14:21
@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 from 592849a to 2a59248 Compare March 15, 2019 11:32
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch from 2a59248 to d9da96b Compare March 15, 2019 16:38
@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
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch from 6100eb2 to 5a956ff Compare March 15, 2019 17:32
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch from 5a956ff to e80f6af Compare March 15, 2019 17:35
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch from e80f6af to 2fa910d Compare March 15, 2019 17:45
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch from 2fa910d to 46cf2b2 Compare March 15, 2019 18:42
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch from 46cf2b2 to 7ac91df Compare May 21, 2019 10:29
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch from 7ac91df to dd31b7c Compare May 21, 2019 15:53
@Serchinastico Serchinastico force-pushed the 04-live-data-and-view-model branch from dd31b7c to e3f613c Compare May 22, 2019 16:44
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