BaseRecyclerAdapter.java
2.17 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
78
79
80
81
82
83
84
85
86
package com.cnlive.im.adapter.base;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import java.util.ArrayList;
import java.util.List;
/**
* Created by zuoxian on 15/9/7.
*/
public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
protected List<Object> mItems ;
protected Context mContext;
public LayoutInflater inflater;
public BaseRecyclerAdapter(Context context){
this.mContext = context;
inflater = LayoutInflater.from(context);
mItems = new ArrayList<>();
}
public List<Object> getList() {
return mItems;
}
public void addItem(@Nullable Object item) {
if(item == null) return ;
mItems.add(mItems.size(), item);
notifyItemInserted(mItems.size());
}
public void addItems(@Nullable List<Object> items){
if(items == null) return ;
this.mItems.addAll(items);
notifyDataSetChanged();
}
public boolean containsAll(@NonNull List<Object> items){
return mItems.containsAll(items);
}
public void updateItem(@Nullable Object tasks, int position) {
if(tasks == null) return ;
mItems.set(position, tasks);
notifyItemChanged(position);
}
public void updateItems(@Nullable List<Object> items){
if(items == null) return;
this.mItems.clear();
this.mItems.addAll(items);
Log.v("getItemCount",mItems.size()+"");
notifyDataSetChanged();
}
public void removeItem(int index) {
mItems.remove(index);
notifyItemRemoved(index);
}
public void getView(int position , RecyclerView.ViewHolder viewHolder, int type, Object item){}
public Object getItem(int location) {
return mItems.get(location);
}
@Override
public int getItemCount() {
Log.v("getItemCount",mItems.size()+"");
return mItems == null ? 0 : mItems.size();
}
public void clear(){
mItems.clear();
notifyDataSetChanged();
}
}