CNBaseRecyclerAdapter.java
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.cnlive.goldenline.ui.base;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
/**
* Created by vclub on 15/5/11.
*/
public abstract class CNBaseRecyclerAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
protected List<T> mItems ;
protected Context mContext;
public CNBaseRecyclerAdapter(Context context){
this.mContext = context;
mItems = new ArrayList<>();
}
public List<T> getList() {
return mItems;
}
public void addItem(T item) {
if(item == null) return ;
mItems.add(mItems.size(), item);
notifyItemInserted(mItems.size());
}
public void addItems(List<T> items){
if(items == null) return ;
this.mItems.addAll(items);
notifyDataSetChanged();
}
public boolean containsAll(List<T> items){
return mItems.containsAll(items);
}
public void updateItem(T tasks, int position) {
if(tasks == null) return ;
mItems.set(position, tasks);
notifyItemChanged(position);
}
public void updateItems(List<T> items){
if(items == null) return;
this.mItems.clear();
this.mItems.addAll(items);
notifyDataSetChanged();
}
public void removeItem(int index) {
mItems.remove(index);
notifyItemRemoved(index);
}
public void removeAllItems(){
mItems.clear();
notifyDataSetChanged();
}
public void getView(int position , RecyclerView.ViewHolder viewHolder, int type, T item){}
public T getItem(int location) {
return mItems.get(location);
}
@Override
public int getItemCount() {
return mItems == null ? 0 : mItems.size();
}
}