项目作者: rafaelcrz

项目描述 :
Scroll endless for Android recyclerview
高级语言: Java
项目地址: git://github.com/rafaelcrz/android_scroll_endless.git
创建时间: 2017-06-10T19:25:56Z
项目社区:https://github.com/rafaelcrz/android_scroll_endless

开源协议:

下载


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

  1. allprojects {
  2. repositories {
  3. jcenter()
  4. maven { url "https://jitpack.io" }
  5. }
  6. }

Add into app/build.gradle

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

Usage

Endeles Scroll

  • Configure the RecyclerView with the Adapter and LayoutManager before use the ScrollEndeless
    1. recyclerView.setAdapter(adapter);
    2. recyclerView.setLayoutManager(layoutManager);
  • Declare ScrollEndless like this

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

    1. endless.setTotalPage(total);
  • This is importante. Make your requestCall before get the EndlessListener. For popule the adapter.

    1. yourRequestCall();
  • Get the ScrollEndless listener.
  1. endless.addScrollEndless(new ScrollEndless.EndlessScrollListener() {
  2. @Override
  3. public void onLoadMore() {
  4. //Get the next page when is available
  5. yourRequestMethod();
  6. }
  7. @Override
  8. public void onLoadAllFinish() {
  9. //Is the last page. Load all itens
  10. }
  11. });
  • 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.
    1. endless.isLoading(true);

If you want, use it for show a simple ProgressDialog

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

For close it, use

  1. endless.closeProgressDialog()

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

  1. endless.isLoading(false);

If you want, use it for close the ProgressDialog

  1. endless.closeProgressDialog();

Set the next Page (before the increment)

  1. endless.setPage(page);

Increment the page

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

  1. //Recyclerview down/up
  2. endless.addScrollManagerDirection(new ScrollEndless.ScrollManagerDirectionListener() {
  3. @Override
  4. public void onScrollUp() {
  5. //do something
  6. floatingActionButton.hide();
  7. floatingActionButton.animate();
  8. }
  9. @Override
  10. public void onScrollDown() {
  11. //do something
  12. floatingActionButton.show();
  13. floatingActionButton.animate();
  14. }
  15. });