Paginate


Source link: https://github.com/MarkoMilos/Paginate

Paginate

Android library for creating simple pagination functionality (aka infinite scrolling) upon RecyclerView or AbsListView.

Features

  • Configuration allows you to setup automatic adding/removing of the loading list item (enabled by default)
  • Custom loading list item - inflate and bind (default loading list item view will be used if custom one is not provided)
  • Custom SpanSizeLookup for the loading list item when GridLayoutManager is used (by default loading list item will use full span)
  • Custom loading trigger threshold
  • Support RecyclerView (using linear, grid and staggered LayoutManager) and AbsListView ( ListView | GridView)

Demo

For a working implementation of this project see the paginate-sample/ folder.

Setup

Gradle:

compile 'com.github.markomilos:paginate:0.5.1'

or Maven:

<dependency>
<groupId>com.github.markomilos</groupId>
<artifactId>paginate</artifactId>
<version>0.5.1</version> </dependency>

Usage

Implement Paginate.Callbacks

Paginate.Callbacks callbacks = new Paginate.Callbacks() {

  @Override
  public void onLoadMore() {

// Load next page of data (e.g. network or database)
  
}

@Override
  public boolean isLoading() {

// Indicate whether new page loading is in progress or not

return loadingInProgress;
  
}

@Override
  public boolean hasLoadedAllItems() {

// Indicate whether all data (pages) are loaded or not

return hasLoadedAllItems;
  
}
 
}
;

RecyclerView

Paginate.with(recyclerView, callbacks)

.setLoadingTriggerThreshold(2)

.addLoadingListItem(true)

.setLoadingListItemCreator(new CustomLoadingListItemCreator())

.setLoadingListItemSpanSizeLookup(new CustomLoadingListItemSpanLookup())

.build();

Note: LayoutManager and RecyclerView.Adapter needs to be set before calling the code above.

Implement LoadingListItemCreator in order to provide custom loading row view.

private class CustomLoadingListItemCreator implements LoadingListItemCreator {

  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

LayoutInflater inflater = LayoutInflater.from(parent.getContext());

View view = inflater.inflate(R.layout.custom_loading_list_item, parent, false);

return new VH(view);

  
}

@Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

// Bind custom loading row if needed
  
}
 
}

AbsListView

Paginate.with(absListView, callbacks)

.setOnScrollListener(scrollListener) // Delegate scroll listener

.setLoadingTriggerThreshold(2)

.addLoadingListItem(true)

.setLoadingListItemCreator(new CustomLoadingListItemCreator())

.build();

Note: Adapter needs to be set before calling the code above.

Implement LoadingListItemCreator in order to provide custom loading row view.

private class CustomLoadingListItemCreator implements LoadingListItemCreator {

  @Override
  public View newView(int position, ViewGroup parent) {

LayoutInflater inflater = LayoutInflater.from(parent.getContext());

View view = inflater.inflate(R.layout.custom_loading_list_item, parent, false);

view.setTag(new VH(view));

return view;
  
}

@Override
  public void bindView(int position, View view) {

// Bind custom loading row if needed
  
}
 
}

Paginate instance

Calling build() upon Paginate.Builder will return Paginate instance which will allow you to:

  • unbind() - Call unbind to detach list ( RecyclerView or AbsListView) from Paginate when pagination functionality is no longer needed on the list. Paginate is using scroll listeners and adapter data observers in order to perform required checks (when list is scrolled to the end or when new data is added to source adapter). It wraps original (source) adapter with new adapter that provides loading row if loading row is used. When unbind is called original adapter will be set on the list and scroll listeners and data observers will be detached. You need to call unbind() if you re-setup recycler view (e.g. change adapter, layout manager etc)

  • setHasMoreDataToLoad(boolean) - if you are using loading row (which is default setup), each time when you add data to adapter check will be performed and if there is no more data to load loading row will be removed. That means that loading row will be added/removed automatically. Use this method to explicitly (manually) notify that there is no more item to load.

Developed By

Marko Milos ( [email protected])

License

Copyright 2015 Marko Milos  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. 

Resources

Simple command pattern helper class.

InfiniteListView is a custom Android ListView that gets extended at each time new items are loaded by swiping to the bottom of list. It also supports swipe-to-refresh behavior.

Material design FAB action animations.

Event bus for Android with fine-grained thread control.

A helper to work with StatusBar and NavigationBar.

This is a tiny library for Android which makes it simple to monitor when your app becomes visible or hidden, in a cool RxJava way.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes