-
Notifications
You must be signed in to change notification settings - Fork 554
5.x | On Load More
- Introduction
- Automatic load more
- Load more upon a user request
- Load more per section
EndlessScroll / On Load More is achieved by an innovative mechanism where no ScrollListener is implemented! The call is done in the onBindViewHolder()
of the Adapter, by checking the current position if matches with the last position minus the threshold.
This elaboration is irrelevant compared to the callback for the ScrollListener classic implementation especially if the progress item is not set, but you will not have the RecyclerView widget translated through y-axis.
Two scenarios are foreseen for this feature:
- Automatic loading, where the trigger to load more items, is done automatically :-)
- Load more upon a user request, where the developer gives the possibility to the user to choose to load more items or not by simply clicking an inner view in the item.
When no items are loaded, the progressItem will be notified about the change: notifyItemChanged()
will be called before the removal. Optionally the item can be removed after a custom delay to give time to read an eventual message from the item. In bindViewHolder()
you should be able to display the messages based on the result status.
This feature is achieved by calling setEndlessScrollListener()
method.
You will have to provide a Listener and the progress item.
-
Create a progress item layout that displays a custom progress bar; A TextView* for the custom messages.
To be continued -
Create the Java item with its ViewHolder. The mapping takes in consideration the messages for statuses: loading (progress indicator), noMoreLoad, onError*, onCancel*
To be continued -
Implement the
EndlessScrollListener
listener so the methodonLoadMore()
will be called. Here, you have your call to the network service to load more items.
To be continued -
You will be handling the following cases:
-
onSuccess with items: call
onLoadMoreComplete(newItems)
- ProgressItem is removed immediately.
- Items are added to the end of the list.
- ProgressItem is removed immediately.
-
onSuccess no items: call
onLoadMoreComplete(empty list or null, delay*)
- Internal call to
noMoreLoad()
.
- ProgressItem may display the updated message for a certain delay.
- Internal call to
-
onCancel*: call
onLoadMoreComplete(empty list or null, delay*)
- Internal call to
noMoreLoad().
- ProgressItem may display the cancelled message for a certain delay.
- Internal call to
-
onError*: call
onLoadMoreComplete(empty list or null, delay*)
- Internal call to
noMoreLoad()
.
- ProgressItem may display the error message for a certain delay.
- Internal call to
-
onSuccess with items: call
* = Optional with the following behaviours:
- Providing a delay
-1
ProgressItem is kept in the list. Also, EndlessScroll will be completely disabled!
- Providing a custom delay, ProgressItem is kept to display the message, then automatically removed after the delay.
- Not providing any delay or
0
delay, ProgressItem is removed immediately and when the user scrolls again, the item will be displayed again, a new call toonLoadMore()
is being triggered.
This feature is achieved by calling setEndlessProgressItem()
method that distinguishes the manual loading from the automatic loading by the fact that no listener is involved.
-
Create a progress item layout that supports a Button to start the loading with onClick event; A custom progress bar that becomes visible when user taps the button, the button disappears; A TextView* for the custom messages.
To be continued -
Create the Java item with the its ViewHolder. The mapping takes in consideration: the current status loading (true/false) for the button and the progress indicator; the statuses: noMoreLoad, onError, onCancel for the messages.
To be continued -
Don't implement the
EndlessScrollListener
listener (there's no listener involved...), so the methodonLoadMore()
won't be called.
To be continued -
Same as Automatic loading.
* = Optional
You will have to handle all the steps for manual loading PLUS the addition and the removal of the progress item by yourself as last element of the section.
Note: This cannot be reached by the library since it is a custom event inside your custom item.
- Update Data Set
- Selection modes
- Headers and Sections
- Scrollable Headers and Footers
- Expandable items
- Drag&Drop and Swipe
- EndlessScroll / On Load More
- Search Filter
- FastScroller
- Adapter Animations
- Third party Layout Managers
- Payload
- Smooth Layout Managers
- Flexible Item Decoration
- Utils
- ActionModeHelper
- AnimatorHelper
- EmptyViewHelper
- UndoHelper
* = Under revision!