Android pagination library (updated 01.05.2018)

Overview

NoPaginate

Android Arsenal androidweekly.cn Download API

Android pagination library, based on @MarkoMilos repository Paginate

Loading Item Error Item

Gradle

implementation 'ru.alexbykov:nopaginate:0.9.9'

Install

  NoPaginate noPaginate = NoPaginate.with(recyclerView)
                .setOnLoadMoreListener(new OnLoadMoreListener() {
                    @Override
                    public void onLoadMore() {
                        //http or db request
                    }
                })
                .build();

If you use MVP or Clean Architecture, don't forget implement PaginateView. You can see example of implementation with MVP here

Actions

   noPaginate.showLoading(show);
   noPaginate.showError(show);
   noPaginate.setNoMoreItems(set); //Method onLoadMore will not to call
   noPaginate.unbind(); //Don't forget call it on onDestroy();

Custom Loading and Error

For custom error and loaging item just implement the interfaces ErrorItem or LoadingItem

Custom error:

public class CustomErrorItem implements ErrorItem {

           @Override
           public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
               View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_error, parent, false);
               return new RecyclerView.ViewHolder(view) {
               };
           }

           @Override
           public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, final OnRepeatListener repeatListener) {
               Button btnRepeat = (Button) holder.itemView.findViewById(R.id.btnRepeat);
               btnRepeat.setOnClickListener(new View.OnClickListener() {
                   @Override
                   public void onClick(View v) {
                       if (repeatListener != null) {
                           repeatListener.onClickRepeat(); //call onLoadMore
                       }
                   }
               });
           }
}

Custom loading:

public class CustomLoadingItem implements LoadingItem {
   
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_loading, parent, false);
            return new RecyclerView.ViewHolder(view) {
            };
        }
        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
   
        }
   
}

Install with custom items and trigger threshold

  NoPaginate noPaginate = NoPaginate.with(recyclerView)
                .setOnLoadMoreListener(new OnLoadMoreListener() {
                    @Override
                    public void onLoadMore() {
                        //http or db request
                    }
                })
                .setLoadingTriggerThreshold(5) //0 by default
                .setCustomErrorItem(new CustomErrorItem())
                .setCustomLoadingItem(new CustomLoadingItem())
                .build();

Idea

This repository is a slightly modified version of Paginate library. Author: @MarkoMilos

We decided to modify it a little, so that developers could easily use it with MVP or Clean Architecture

Roadmap

  1. Double-sided pagination
  2. Delegate for Presenter or Interactor, with implementation Limit/Offset and Page pagination
  3. Unit tests
  4. Wiki

Contributing

If you find any bug, or you have suggestions, don't be shy to create issues or make a PRs in the develop branch. You can read contribution guidelines here

My other libraries:

  1. NoPermission — Simple Android permission library, consist of only one class
  2. NoRecyclerViewAdapter — Simple base adapter for recyclerView

License

Copyright 2017 Alex Bykov
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Add an item to show that Adapter is empty

    Add an item to show that Adapter is empty

    Can you add an Item in adapter to show that Adapter is empty? View can notify Paginate that the item-count has changed. If user enables this Empty Item and item-count reaches 0, you can show this item.

    I use a layout to show Empty Adapter, but it is shown on top of RecyclerView in FrameLayout. I want to have it in Adapter, and be able to turn it on/off manually.

    Thanks. Your library works amazingly even without this feature.

    layout-2018-03-16-174829

    enhancement 
    opened by rupinderjeet 4
  • RecyclerView inside NestedScrollView weird behavior

    RecyclerView inside NestedScrollView weird behavior

    Hi @NoNews ,

    I am using noPaginate lib ti handle a list of accounts movements, if I use the recyclerView [alone] the onLoadMore listener works fine when a reach the last item of the list, but when a Try to use NestedScrollView with RecyclerView the onLoadMore is called before I scroll down.

    I hope you can Help me about this issue.

    Cheers.

    PD: I need to use NestedScrollView in order to use CollapsinToolbarLayout.

    help wanted 
    opened by MitchDroid 3
  • Changed to remove scrollListener when unbind

    Changed to remove scrollListener when unbind

    Thank you for making a good library.

    If you create a paginate using the PaginateBuilder again after unbind, the onLoadMore event occurs twice.

    The cause is that the scrollListener registered in the recyclerView is not cleared.

    I used removeOnScrollListener because .clear () on the scrollListener also clears the user's registered scrollListener.

    This issue also occurs in the 'master branch' and can be addressed in the same way.

    bug 
    opened by Chazo826 3
  • OnLoadMore called two times for lesser data

    OnLoadMore called two times for lesser data

    Firstly thanks for the great library i was able to remove a lot of boilerplate from my code.👍

    My api call is supposed to load 10 items per page but since the data coming from first call is only 4 items this results in onLoadMorebeing called one more time.

    help wanted 
    opened by aqibgatoo 2
  • Custom view when there is not more items to show

    Custom view when there is not more items to show

    Hi @NoNews its me again.. lol.

    Just one question,:

    is it possible to show a custom view when there is not more items to show.?..I mean something like "There is not more items to show for the moment"

    PD: something like the custom error view.

    Regards.

    help wanted 
    opened by MitchDroid 1
  • Cannot call this method in a scroll callback

    Cannot call this method in a scroll callback

    I received an exception while scrolling horizontally. I modified ErrorItem and LoadingItem for Horizontal and Vertical scrolls.

    public interface LoadingItem extends BaseLinearLayoutManagerItem {
    
        LoadingItem VERTICAL = new LoadingItem() {
    
            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    
                View view = LayoutInflater.from(parent.getContext()).inflate(
                        R.layout.pagination_item_loading, parent, false
                );
    
                return new RecyclerView.ViewHolder(view) {};
            }
    
            @Override
            public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {}
        };
    
        LoadingItem HORIZONTAL = new LoadingItem() {
    
            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    
                View view = LayoutInflater.from(parent.getContext()).inflate(
                        R.layout.pagination_item_loading_horizontal_scroll, parent, false
                );
    
                return new RecyclerView.ViewHolder(view) {};
            }
    
            @Override
            public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {}
        };
    }
    

    And, then, I setOrientation() using PaginateBuilder:

    
    
        public PaginateBuilder setOrientation (PaginateOrientation orientation) {
    
            if (orientation == PaginateOrientation.HORIZONTAL) {
                setCustomErrorItem(ErrorItem.HORIZONTAL);
                setCustomLoadingItem(LoadingItem.HORIZONTAL);
            }
            else {
                setCustomErrorItem(ErrorItem.VERTICAL);
                setCustomLoadingItem(LoadingItem.VERTICAL);
            }
    
            return this;
        }
    

    This is the exception I get:

    03-24 10:06:48.274 W/RecyclerView: Cannot call this method in a scroll callback. Scroll callbacks mightbe run during a measure & layout pass where you cannot change theRecyclerView data. Any method call that might change the structureof the RecyclerView or the adapter contents should be postponed tothe next frame.
                                       java.lang.IllegalStateException:  android.support.v7.widget.RecyclerView{a136c97 VFED..... ......ID 0,0-450,273}, adapter:com.xxxxx.xxxx.utils.pagination.paginate.WrapperAdapter@9256e84, layout:android.support.v7.widget.LinearLayoutManager@ab4766d, context:com.xxxxx.xxxxx.view.modules.ecommerce.ShopActivity@5d48e36
                                           at android.support.v7.widget.RecyclerView.assertNotInLayoutOrScroll(RecyclerView.java:2673)
                                           at android.support.v7.widget.RecyclerView$RecyclerViewDataObserver.onChanged(RecyclerView.java:5055)
                                           at android.support.v7.widget.RecyclerView$AdapterDataObservable.notifyChanged(RecyclerView.java:11540)
                                           at android.support.v7.widget.RecyclerView$Adapter.notifyDataSetChanged(RecyclerView.java:6762)
                                           at com.xxxxx.xxxxx.utils.pagination.paginate.WrapperAdapterObserver.onChanged(WrapperAdapterObserver.java:50)
                                           at android.support.v7.widget.RecyclerView$AdapterDataObservable.notifyChanged(RecyclerView.java:11540)
                                           at android.support.v7.widget.RecyclerView$Adapter.notifyDataSetChanged(RecyclerView.java:6762)
                                           at com.xxxxx.xxxxx.view.base.base_adapters.recycler_view_adapters.BaseListAdapter.informDataSetChanged(BaseListAdapter.java:902)
                                           at com.xxxxx.xxxxx.view.base.base_adapters.recycler_view_adapters.BaseListAdapter.setItems(BaseListAdapter.java:701)
                                           at com.xxxxxx.xxxxx.view.modules.ecommerce.features.product_similar.SimilarProductFragment.fetchSimilarProducts(SimilarProductFragment.java:97)
                                           at com.xxxxx.xxxx.view.modules.ecommerce.features.product_similar.SimilarProductFragment.onLoadMore(SimilarProductFragment.java:274)
                                           at com.xxxxx.xxxx.utils.pagination.paginate.Paginate.checkAdapterState(Paginate.java:76)
                                           at com.xxxxx.xxxxxx.utils.pagination.paginate.Paginate.checkScroll(Paginate.java:101)
                                           at com.xxxxx.xxxxx.utils.pagination.paginate.Paginate.access$000(Paginate.java:15)
                                           at com.xxxxx.xxxxx.utils.pagination.paginate.Paginate$1.onScrolled(Paginate.java:68)
                                           at android.support.v7.widget.RecyclerView.dispatchOnScrolled(RecyclerView.java:4722)
                                           at android.support.v7.widget.RecyclerView.scrollByInternal(RecyclerView.java:1787)
                                           at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2970)
                                           at android.view.View.dispatchTouchEvent(View.java:9303)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2555)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2242)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2256)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2256)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2256)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2256)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2256)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2256)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2256)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2256)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2256)
                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2561)
                                       	at android.vi
    

    Proposed solution is to wrap these calls in a Handler.post() maybe.

    help wanted 
    opened by rupinderjeet 1
  • First call for data

    First call for data

    I noticed the load more calls without scroll, I initially had a first call to Retrofit to load data before scroll to load more.

    So is there away to load initial data where I can have my loading view of choice? Then when user scrolls, more are loaded??

    opened by skyestudiosDev 0
  • Support for SwipeRefreshLayout or reloading whole list

    Support for SwipeRefreshLayout or reloading whole list

    I tried to implement swiperefresh with your library via this code

    if (!isRefresh) {
        showProgressBar();
    } else if (noPaginate != null) {
        noPaginate.unbind();
    }
    noPaginate = NoPaginate.with(listNews)
        .setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore() {
               //network code
            }
        })
        .setLoadingTriggerThreshold(5)
        .build();
    

    but it is not working, paginate is not going into the load more method

    opened by raghavsatyadev 3
  • NotifyDataSetChanged with payload not working

    NotifyDataSetChanged with payload not working

    Hello,

    First of all thanks for this library.

    One thing noticed when I called notifyItemChanged(position, payload) it will call onBindViewHolder(holder, position) not onBindViewHolder(holder, position, payload) . Please handle this scenario.

    Similarly other methods like onViewRecycled(), onViewAttachedToWindow(), onViewDetachedFromWindow() related methods are also not fired.

    Thanks

    enhancement 
    opened by pankaj89 1
  • forget to calculate loadmore item count

    forget to calculate loadmore item count

    when I add code in your MianActivitylike :

     @Override
        protected void onPostCreate(@Nullable Bundle savedInstanceState) {
            super.onPostCreate(savedInstanceState);
    
            new Handler().postDelayed(() -> mainActivityPresenter.addItems(), 500);
        }
    

    notice,it‘s a async action,now recyclerview only have one child(loadmore item), so it will cause load more twice,becase your code didn't calculcate loadmore item count(1)

    research needed 
    opened by HelloVass 3
  • Not working with reverse recyclerview

    Not working with reverse recyclerview

    Keep:

            layoutManager.setStackFromEnd(true);
            layoutManager.setReverseLayout(true);
    

    Now pagination is trigger initially. Is there any workaround?

    research needed 
    opened by kagile 0
Releases(v.0.9.9)
  • v.0.9.9(May 1, 2018)

    Refactoring:

    • Paginate is deprecated. Use NoPaginate
    • PaginateBuilder is deprecated. Use factory method NoPaginate.with(recyclerView)

    Bug:

    • Remove scroll listener when unbind #7 @darker826
    Source code(tar.gz)
    Source code(zip)
  • v.0.4.4(Dec 18, 2017)

    Refactoring:

    • Method unSubscribe is deprecated. Use unbind
    • Method setCallback is deprecated. Use setOnLoadMoreListener
    • Method setPaginateNoMoreItems is deprecated. Use setNoMoreItems

    New:

    • Default state of loadingTriggerThreshold is 0 to avoid confusion (it was 5) (#1, #3)
    • Added Javadoc
    Source code(tar.gz)
    Source code(zip)
Owner
Alexey Bykov
Android Software Engineer at Revolut. You can contact me at [email protected]
Alexey Bykov
Pagination-RecyclerView - Simple and easy way to Paginating a RecyclerView

Pagination-RecyclerView Simple and easy way to Paginating a RecyclerView Android

Rakshit Nawani 0 Jan 3, 2022
An Android Animation library which easily add itemanimator to RecyclerView items.

RecyclerView Animators RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel

Daichi Furiya 11.2k Jan 8, 2023
Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

RecyclerView-FlexibleDivider Android library providing simple way to control divider items of RecyclerView Release Note [Release Note] (https://github

Yoshihito Ikeda 2.4k Dec 18, 2022
Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Nikhil Panju 1k Dec 29, 2022
Dividers is a simple Android library to create easy separators for your RecyclerViews

Dividers Dividers is an Android library to easily create separators for your RecyclerViews. It supports a wide range of dividers from simple ones, tha

Karumi 490 Dec 28, 2022
Android library defining adapter classes of RecyclerView to manage multiple view types

RecyclerView-MultipleViewTypeAdapter RecyclerView adapter classes for managing multiple view types Release Note [Release Note] (https://github.com/yqr

Yoshihito Ikeda 414 Nov 21, 2022
Android library for RecyclerView to manage order of items and multiple view types.

recyclerview-binder Android Library for RecyclerView to manage order of items and multiple view types. Features Insert any items to wherever you want

Satoru Fujiwara 185 Nov 15, 2022
Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Nikhil Panju 1k Dec 29, 2022
Epoxy is an Android library for building complex screens in a RecyclerView

Epoxy Epoxy is an Android library for building complex screens in a RecyclerView. Models are automatically generated from custom views or databinding

Airbnb 8.1k Dec 29, 2022
A customizable and easy-to-use Timeline View library for Android

TimelineView A customizable and easy-to-use Timeline View library for Android Can be used as a standalone view or as a RecyclerView decorator Setup 1.

Riccardo Lattarulo 189 Dec 10, 2022
An android library for quick setup of RecyclerView

SmartRecyclerView for Android An android library to quickly setup RecyclerView(List) with SwipeRefreshLayout Support, written entirely in Kotlin. Supp

Kunal Pasricha 16 Oct 18, 2022
RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Advanced RecyclerView This RecyclerView extension library provides Google's Inbox app like swiping, Play Music app like drag-and-drop sorting and expa

Haruki Hasegawa 5.2k Dec 23, 2022
The library that removes all boilerplate code allowing you to display lists with few lines of code.

VsRecyclerView The library that removes all boilerplate code allowing you to display lists with few lines of code. Gradle androidExtensions { expe

Valeriy Shtaits 13 Jun 19, 2021
An efficient TabLayout library implemented with RecyclerView.

RecyclerTabLayout An efficient TabLayout library implemented with RecyclerView. Features Efficient when having many tabs Easy setup with ViewPager (sa

Shinichi Nishimura 1.3k Dec 9, 2022
the library is a loop RecyclerView(expression), can show some effects when display

CircleRecyclerView the library is a loop RecyclerView, can show some effects when display screenshot CircularViewMode ScaleXViewMode & ScaleYViewMode

Matt Yao 704 Jan 5, 2023
Elegant design and convenient to use RecyclerView adapter library based on Kotlin DSL.

xAdapter: Kotlin DSL 风格的 Adapter 封装 1、简介 该项目是 KotlinDSL 风格的 Adapter 框架封装,用来简化 Adapter 调用,思想是采用工厂和构建者方式获取 Adapter 避免代码中定义大量的 Adapter 类。该项目在 BRVAH 的 Ada

ShouHeng 17 Oct 9, 2022
Organize your images in beautiful collage with this library!

CollageImageView This app is an example. how to create collages with RecyclerView. See an example, how it's working: device-2021-04-24-015545.mp4 Inst

Sergey Grishin 16 Oct 14, 2022
Yet another adapter delegate library.

Yet another adapter delegate library. repositories { ... maven { url 'https://jitpack.io' } } ... dependencies { implementation("com.git

Mike 10 Dec 26, 2022
A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.

UltimateRecyclerView Master branch: Dev branch: Project website:https://github.com/cymcsg/UltimateRecyclerView Description UltimateRecyclerView is a R

MarshalChen 7.2k Jan 2, 2023