-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Improve paging experience #1022
Comments
for synch lists, I think |
@martinsawicki this is a valid point.
int size = pagedList.size();
for (int i = 0; i != pagedList.size(); ++i) {
doStuff(pagedList.get(i));
} |
I think #1 will be confusing. I don't think anyone expects |
Yes we could. |
I assume as a part of implementing this - If user choose [1] then we should be able to provide normal expected behavior for following methods: .size()
.loadAll()
.toArray()
.lastIndexOf() But if he choose [2] then I think it's ok to throw exceptions from the above methods as it was user's choice not to cache the entire pages. Just my thought on this. |
The question is which should be the default? |
i.e. exposing two separate methods in SDK, one return |
You can't have return type overloads in Java. |
yes, got that, was thinking like |
Released with beta3. |
Status quo
Synchronous
list()
calls return an instance ofPagedList
which contains only the 1st page of the items. As usersindexOf()
the list grows only if necessary.
As users
.size()
or.loadAll()
or.toArray()
or.lastIndexOf()
the list gets fully populated.
Asynchronous
listAsync()
accepts aListOperationCallback
which allows users to handle every page and the entire list. The call automatically makes subsequent calls to list all the pages untilListOperationCallback.progress()
defined by the user returns aPagingBehavior.STOP
. The method returns aServiceCall
object that ties to the current REST call to fetch a single page.Problems to fix
STOP
Proposed solution
Synchronous
The following call will iterate through the entire list, with only a maximum of 2 pages stored in memory. One page is for the current page. The other is the cached next page, if available. This provides an accurate representation of
hasNext()
even whennextPageLink
points to an empty last page.The following calls will throw exception:
.size()
.loadAll()
.toArray()
.lastIndexOf()
In order to use them,
PagedList
exposes aentireList()
method that returns the entire list. Developers can use this when necessary with caution.Asynchronous
ListOperationCallback
's 3 methods user can override will be changed tothe callback object doesn't store the entire list of items - developers are responsible of doing that themselves.
A sample code for pausing and resuming:
As you see, we end up having a potential callback hell. We may resolve this by returning an Observable, but that's in the longer term.
The text was updated successfully, but these errors were encountered: