Awesome Open Source
Awesome Open Source

paginator

The simplest way to make your recycler view paginable.

It will automatically detect if content loading is complete or not. You don't need to implement a method like hasFinishLoading!

Example

See full example here.

Installation

Your top-level build.gradle:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

In module-level build.gradle:

dependencies {
    implementation 'com.github.mu29:paginator:1.0'
}

Because this library uses support library 27.1.0, you may get errors if you are already using a different version. In that case, exclude support library:

dependencies {
    implementation ('com.github.mu29:paginator:1.0') {
        exclude group: "com.android.support"
    }
}

Usage

1. Define view in your layout

<net.yeoubi.paginator.PagingRecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="45dp"
    app:progressColor="@color/gray_30"
    app:innerClipToPadding="false"
    app:innerPaddingTop="24dp"/>

The progressColor attribute must exist and is reference type. You can't define it just like "#FFF".

2. Implement OnPaginateListener

class MyActivity extends AppCompatActivity implements PagingRecyclerView.OnPaginateListener {

    private PagingRecyclerView itemList;
    private YourCustomAdapter adapter;

    private void setRecyclerView() {
        // Adapter must be set before the OnPaginateListener.
        itemList.setAdapter(adapter);
        itemList.setOnPaginateListener(this);
    }
    
    @Override
    public void onPaginate(int page) {
        // ...fetch data from database, network, etc...
        adapter.notifyDataSetChanged();
    }
}

As mentioned above, you must set the adapter before the OnPaginateListener.

Author

InJung Chung / @mu29

License

MIT


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Java (710,532
Android (41,173
Recyclerview (1,343
Pagination (886
Infinite Scroll (295
Paging (164
Related Projects