Code Monkey home page Code Monkey logo

simplerecyclerview's Introduction

SimpleRecyclerView

Simplest RecyclerView extention for implementing pagination (on reach list bottom listener, displaying progress bar) and empty view (nothing found) with RecyclerView

Download

dependencies {
   compile 'com.myhexaville:simple-recyclerview:1.2.0'
}

Setup

Add SimpleRecycerView in XML

<com.myhexaville.simplerecyclerview.SimpleRecyclerView
            android:layout_width="match_parent"
            android:id="@+id/list"
            android:layout_height="match_parent"/>

Implement SimpleRecyclerView.Adapter, RecyclerView.ViewHolder implementation is same as with default RecyclerView

public class Adapter extends SimpleRecyclerView.Adapter<Holder> {
    public List<String> list;

    public Adapter(List<String> list) {
        this.list = list;
    }

    @Override
    public Holder onCreateHolder(ViewGroup parent) {
       // create View Holder just like you did before
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public void onBindHolder(Holder holder, int position) {
        // bind view holder just like you did before
    }
}

Setup in Java

simpleRecyclerView.setLayoutManager(new LinearLayoutManager(context));
simpleRecyclerView.setAdapter(new Adapter(list));

Features

Pagination

By default pagination and footer ProgressBar is disabled, to enable it simply add those lines

simpleRecyclerView.setOnLoadMoreListener(() -> {
  // fetch data from your server and add to your list
  
  // this will do notifyItemRangeInserted
  // no need to notify recyclerView adapter yourself
  simpleRecyclerView.setDoneFetching();
});

This listener will be called each time you reach bottom of the list and will display default ProgressBar footer

ezgif com-resize

Custom ProgressBar footer

If you want to use your own ProgressBar footer - create your own progress_footer.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
</FrameLayout>

and pass to SimpleRecyclerView

<com.myhexaville.simplerecyclerview.SimpleRecyclerView
            android:layout_width="match_parent"
            android:id="@+id/list"
            app:progress_layout="@layout/progress_footer"
            android:layout_height="match_parent"/>

No More To Fetch

If you server returns no items and you don't want setOnLoadMoreListener listener to be called anymore just like don't display ProgressBar any more - call this method

simpleRecyclerView.setOnLoadMoreListener(() -> {
  ...
  if (noStuffFetchedFromServer) {
     simpleRecyclerView.setNoMoreToFetch();
  }
});

Empty View

By default empty view (Nothing found, when list is empty) is disabled. To display it - create your empty_layout.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Nothing Found" />
</FrameLayout>

And pass to SimpleRecyclerView

<com.myhexaville.simplerecyclerview.SimpleRecyclerView
            android:layout_width="match_parent"
            android:id="@+id/list"
            app:empty_layout="@layout/empty_layout"
            android:layout_height="match_parent"/>

Initial ProgressBar

Initial ProgressBar in the center is enabled by default. To hide it after you fetched your data call this method

simpleRecyclerView.setDoneFetching();

Call this method even if you have data preloaded and just set it during SimpleRecyclerView setup

To disable initial ProgressBar - use this attribute

<com.myhexaville.simplerecyclerview.SimpleRecyclerView
            ...
            app:initial_progress_bar_enabled="false"/>

Inside NestedScrollView

If you have SimpleRecyclerView inside of NestedScrollView - here's few initial tips and how to manage setOnLoadMoreListener with it

<NestedScrollView
   ...
   android:fillViewport="true"/>
<com.myhexaville.simplerecyclerview.SimpleRecyclerView
    ...
    android:nestedScrollingEnabled="false"/>
simpleRecyclerView.setInsideNestedScrollView(nestedScrollView);

Sample

There's a sample of using this library in this repo

simplerecyclerview's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simplerecyclerview's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.