• Stars
    star
    2,028
  • Rank 22,829 (Top 0.5 %)
  • Language
    Java
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ArrayAdapter,pull to refresh,auto load more,Header/Footer,EmptyView,ProgressView,ErrorView

EasyRecyclerView

中文English

Encapsulate many API about RecyclerView into the library,such as arrayAdapter,pull to refresh,auto load more,no more and error in the end,header&footer.
The library uses a new usage of ViewHolder,decoupling the ViewHolder and Adapter.
Adapter will do less work,adapter only direct the ViewHolder,if you use MVP,you can put adapter into presenter.ViewHolder only show the item,then you can use one ViewHolder for many Adapter.
Part of the code modified from Malinskiy/SuperRecyclerView,make more functions handed by Adapter.

Dependency

compile 'com.jude:easyrecyclerview:4.4.2'

ScreenShot

recycler.gif

Usage

EasyRecyclerView

<com.jude.easyrecyclerview.EasyRecyclerView
  android:id="@+id/recyclerView"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  app:layout_empty="@layout/view_empty"
  app:layout_progress="@layout/view_progress"
  app:layout_error="@layout/view_error"
  app:recyclerClipToPadding="true"
  app:recyclerPadding="8dp"
  app:recyclerPaddingTop="8dp"
  app:recyclerPaddingBottom="8dp"
  app:recyclerPaddingLeft="8dp"
  app:recyclerPaddingRight="8dp"
  app:scrollbarStyle="insideOverlay"//insideOverlay or insideInset or outsideOverlay or outsideInset
  app:scrollbars="none"//none or vertical or horizontal
  />

Attention EasyRecyclerView is not a RecyclerView just contain a RecyclerView.use 'getRecyclerView()' to get the RecyclerView;

EmptyView&LoadingView&ErrorView
xml:

app:layout_empty="@layout/view_empty"
app:layout_progress="@layout/view_progress"
app:layout_error="@layout/view_error"

code:

void setEmptyView(View emptyView)
void setProgressView(View progressView)
void setErrorView(View errorView)

then you can show it by this whenever:

void showEmpty()
void showProgress()  
void showError()  
void showRecycler()

scrollToPosition

void scrollToPosition(int position); // such as scroll to top

control the pullToRefresh

void setRefreshing(boolean isRefreshing);
void setRefreshing(final boolean isRefreshing, final boolean isCallback); //second params is callback immediately

##RecyclerArrayAdapter
there is no relation between RecyclerArrayAdapter and EasyRecyclerView.you can user any Adapter for the EasyRecyclerView,and use the RecyclerArrayAdapter for any RecyclerView.

Data Manage

void add(T object);
void addAll(Collection<? extends T> collection);
void addAll(T ... items);
void insert(T object, int index);
void update(T object, int index);
void remove(T object);
void clear();
void sort(Comparator<? super T> comparator);

Header&Footer

void addHeader(ItemView view)
void addFooter(ItemView view)  

ItemView is not a view but a view creator;

public interface ItemView {
     View onCreateView(ViewGroup parent);
     void onBindView(View itemView);
}

The onCreateView and onBindView correspond the callback in RecyclerView's Adapter,so adapter will call onCreateView once and onBindView more than once;
It recommend that add the ItemView to Adapter after the data is loaded,initialization View in onCreateView and nothing in onBindView.

Header and Footer support LinearLayoutManager,GridLayoutManager,StaggeredGridLayoutManager.
In GridLayoutManager you must add this:

//make adapter obtain a LookUp for LayoutManager,param is maxSpan。
gridLayoutManager.setSpanSizeLookup(adapter.obtainGridSpanSizeLookUp(2));

OnItemClickListener&OnItemLongClickListener

adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
    @Override
    public void onItemClick(int position) {
        //position not contain Header
    }
});

adapter.setOnItemLongClickListener(new RecyclerArrayAdapter.OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(int position) {
        return true;
    }
});

equal 'itemview.setOnClickListener()' in ViewHolder.
if you set listener after RecyclerView has layout.you should use 'notifyDataSetChange()';

###the API below realized by add a Footer。

LoadMore

void setMore(final int res,OnMoreListener listener);
void setMore(final View view,OnMoreListener listener);

Attention when you add null or the length of data you add is 0 ,it will finish LoadMore and show NoMore;
also you can show NoMore manually adapter.stopMore();

LoadError

void setError(final int res,OnErrorListener listener)
void setError(final View view,OnErrorListener listener)

use adapter.pauseMore() to show Error,when your loading throw an error;
if you add data when showing Error.it will resume to load more;
when the ErrorView display to screen again,it will resume to load more too,and callback the OnLoadMoreListener(retry).
adapter.resumeMore()you can resume to load more manually,it will callback the OnLoadMoreListener immediately.
you can put resumeMore() into the OnClickListener of ErrorView to realize click to retry.

NoMore

void setNoMore(final int res,OnNoMoreListener listener)
void setNoMore(final View view,OnNoMoreListener listener)

when loading is finished(add null or empty or stop manually),it while show in the end.

BaseViewHolder<M>

decoupling the ViewHolder and Adapter,new ViewHolder in Adapter and inflate view in ViewHolder.
Example:

public class PersonViewHolder extends BaseViewHolder<Person> {
    private TextView mTv_name;
    private SimpleDraweeView mImg_face;
    private TextView mTv_sign;


    public PersonViewHolder(ViewGroup parent) {
        super(parent,R.layout.item_person);
        mTv_name = $(R.id.person_name);
        mTv_sign = $(R.id.person_sign);
        mImg_face = $(R.id.person_face);
    }

    @Override
    public void setData(final Person person){
        mTv_name.setText(person.getName());
        mTv_sign.setText(person.getSign());
        mImg_face.setImageURI(Uri.parse(person.getFace()));
    }
}

-----------------------------------------------------------------------

public class PersonAdapter extends RecyclerArrayAdapter<Person> {
    public PersonAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new PersonViewHolder(parent);
    }
}

Decoration

Now there are three commonly used decoration provide for you.
DividerDecoration
Usually used in LinearLayoutManager.add divider between items.

DividerDecoration itemDecoration = new DividerDecoration(Color.GRAY, Util.dip2px(this,0.5f), Util.dip2px(this,72),0);//color & height & paddingLeft & paddingRight
itemDecoration.setDrawLastItem(true);//sometimes you don't want draw the divider for the last item,default is true.
itemDecoration.setDrawHeaderFooter(false);//whether draw divider for header and footer,default is false.
recyclerView.addItemDecoration(itemDecoration);

this is the demo:

SpaceDecoration
Usually used in GridLayoutManager and StaggeredGridLayoutManager.add space between items.

SpaceDecoration itemDecoration = new SpaceDecoration((int) Utils.convertDpToPixel(8,this));//params is height
itemDecoration.setPaddingEdgeSide(true);//whether add space for left and right adge.default is true.
itemDecoration.setPaddingStart(true);//whether add top space for the first line item(exclude header).default is true.
itemDecoration.setPaddingHeaderFooter(false);//whether add space for header and footer.default is false.
recyclerView.addItemDecoration(itemDecoration);

this is the demo:

StickHeaderDecoration
Group the items,add a GroupHeaderView for each group.The usage of StickyHeaderAdapter is the same with RecyclerView.Adapter. this part is modified from edubarr/header-decor

StickyHeaderDecoration decoration = new StickyHeaderDecoration(new StickyHeaderAdapter(this));
decoration.setIncludeHeader(false);
recyclerView.addItemDecoration(decoration);

for example:

for detail,see the demo

License

Copyright 2015 Jude

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.

More Repositories

1

SwipeBackHelper

make your activity can swipe to close
Java
1,382
star
2

RollViewPager

A ViewPager can auto play and loop
Java
913
star
3

Beam

MVP开发框架
Java
617
star
4

Utils

android 各种工具库
Java
287
star
5

Joy

豆逼APP源码
Java
122
star
6

FitSystemWindowLayout

适应Statusbar与NavigationBar的各种Layout
Java
119
star
7

RequestVolley

基于Volley的便捷网络请求库
Java
91
star
8

JCenter

上传Jcenter的gradle配置
60
star
9

Fishing

空钩 APP
Java
57
star
10

Ferryman

Android页面路由跳转框架
Java
42
star
11

SMSSDK

一个可以便捷使用短信验证的库
Java
31
star
12

Know

问答社区APP。新技术Demo向。
Java
30
star
13

Interceptor

Java
21
star
14

ImageProvider

图片提供者,从系统,相册,网络提供图片。
Java
17
star
15

ExGridView

可动态添加高度适应的GridView
Java
16
star
16

FloatActionView

基于Adapter的Float Action Button.仿Evernote
Java
13
star
17

TAGView

colorful tag with icon
Java
12
star
18

GeassClient

Android Root开发支持库
Java
11
star
19

KeyChain

PasswordBox APP
Java
11
star
20

ActivitySlider

activity跟随手势滑动关闭
Java
11
star
21

EmotionShow

外包!!!
Java
10
star
22

lifeline

Java
9
star
23

LifeGame

生命游戏Android版
Java
9
star
24

know_web

逼乎web端
PHP
8
star
25

JobGod2

诚客兼职APP
Java
8
star
26

2016WinterHomeWork

红岩移动Android2016寒假作业
6
star
27

Jarvis

Java
5
star
28

Texas

华为杯智能大赛德克萨斯扑克AI
Java
4
star
29

AndroidFrameWork

Android部分机制原理的简单模型
Java
4
star
30

Automobile

上云配
Java
3
star
31

SBReader

String Buffer Analysis Tool
Java
3
star
32

LBSChat

地图社交demo
Java
3
star
33

Jude95.github.io

CSS
3
star
34

EasyCrypto

Crypto tool for java
Java
3
star
35

Happiness

半个外包只是一部分界面
Java
2
star
36

FunctionGraph

逗B的控制台版函数图像显示器
Java
2
star
37

Album

Java
1
star
38

rollup-plugin-workbox-build

Rollup plugin to apply workbox-build
JavaScript
1
star