Skip to content
Davide Steduto edited this page Jul 8, 2016 · 21 revisions

In this page

  • Introduction
  • Automatic load more
  • Load more upon a user request
  • Load more per section

Introduction

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.

Automatic load more (From beta6)

This feature is achieved by calling setEndlessScrollListener() method. You will have to provide a Listener and the progress item.

  1. Create a progress item layout that displays a custom progress bar; A TextView* for the custom messages.
    To be continued

  2. 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

  3. Implement the EndlessScrollListener listener so the method onLoadMore() will be called. Here, you have your call to the network service to load more items.
    To be continued

  4. 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.
    • onSuccess no items: call onLoadMoreComplete(empty list or null, delay*)
      • Internal call to noMoreLoad().
      • ProgressItem may display the updated message for a certain delay.
    • onCancel*: call onLoadMoreComplete(empty list or null, delay*)
      • Internal call to noMoreLoad().
      • ProgressItem may display the cancelled message for a certain delay.
    • onError*: call onLoadMoreComplete(empty list or null, delay*)
      • Internal call to noMoreLoad().
      • ProgressItem may display the error message for a certain delay.

* = 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 to onLoadMore() is being triggered.

Load more upon a user request (From beta8)

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.

  1. 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

  2. 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

  3. Don't implement the EndlessScrollListener listener (there's no listener involved...), so the method onLoadMore() won't be called.
    To be continued

  4. Same as Automatic loading.

* = Optional

Load more per section (From beta8)

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.

Clone this wiki locally