android_scroll_endless
rafaelcrz
12
Visit GitHub RepoScroll Views

Android Endless Scroll

Android Arsenal

This project is a EndlessScroll for using on RecyclerView

Preview

The ProgressDialog is optional

Sample

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();
            }
        });
Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT