Scroll Endless

Additional

Language
Java
Version
N/A
Created
Jun 11, 2017
Updated
Oct 23, 2017 (Retired)
Owner
Rafael Felipe (rafaelcrz)
Contributor
Rafael Felipe (rafaelcrz)
1
Activity
Badge
Generate
Download
Source code
APK file

Promotion

Android Endless Scroll

This project is a EndlessScroll for using on RecyclerView

Preview

The ProgressDialog is optional

This project has a sample

Activity sample using Endless

Integrating into your project

This project is available in JitPack.io repository.

Add into build.gradle

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

Add into app/build.gradle

dependencies {
  compile 'com.github.rafaelcrz:android_scroll_endless:master-SNAPSHOT'
}

Usage

Endeles Scroll

  • Configure the RecyclerView with the Adapter and LayoutManager before use the ScrollEndeless
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(layoutManager);
  • Declare ScrollEndless like this
endless = new ScrollEndless(mContext, recyclerView, layoutManager);
  • Set the total page. Default is 1 The total pages value you can get it from your response, setting in a global variable.
endless.setTotalPage(total);
  • This is importante. Make your requestCall before get the EndlessListener. For popule the adapter.
yourRequestCall();
  • Get the ScrollEndless listener.
endless.addScrollEndless(new ScrollEndless.EndlessScrollListener() {
    @Override
    public void onLoadMore() {
        //Get the next page when is available
        yourRequestMethod();
    }

    @Override
    public void onLoadAllFinish() {
        //Is the last page. Load all itens
    }
});
  • In your requestMetohd, is very important set the following methods. In your requestMethod, before 'response', use it: The ScrollEndless needs know when the request is executing.
endless.isLoading(true);

If you want, use it for show a simple ProgressDialog

endless.showProgressDialog("title", "message", cancelable: boolean); 

For close it, use

endless.closeProgressDialog() 

In the onResponse or when the data item are complete in adapter

endless.isLoading(false); 

If you want, use it for close the ProgressDialog

endless.closeProgressDialog(); 

Set the next Page (before the increment)

endless.setPage(page);

Increment the page

page = endless.getPage() + 1;

ScrollManagerDirection

Use it for manage the Scroll direction and do something when scroll up / scroll down. For example, show or hide a FloatButton

        //Recyclerview down/up
        endless.addScrollManagerDirection(new ScrollEndless.ScrollManagerDirectionListener() {
            @Override
            public void onScrollUp() {
                //do something
                floatingActionButton.hide();
                floatingActionButton.animate();
            }

            @Override
            public void onScrollDown() {
                //do something
                floatingActionButton.show();
                floatingActionButton.animate();
            }
        });