doum
6 天以前 2b287056e2f59518888d05a1bbc7e5a55fbd84d5
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
87
88
89
90
91
92
93
package com.doumee.lib_coremodel.base;
 
import android.content.Context;
 
import androidx.recyclerview.widget.RecyclerView;
 
import java.util.ArrayList;
import java.util.List;
 
public abstract class RcvBaseAdapter<D extends Object,T extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<T> {
    public interface DeletItemListener{
        void delet(int position);
    }
 
    public interface ItemLongClickListener{
        void onLongClick(int position);
    }
 
    public interface ItemClickListener{
        void onClick(int position);
    }
 
    protected ItemClickListener clickListener;
    protected Context context;
    protected List<D> datas=new ArrayList<>();
 
    public RcvBaseAdapter(Context context) {
        this.context = context;
    }
 
    public ItemClickListener getClickListener() {
        return clickListener;
    }
 
    public void setClickListener(ItemClickListener clickListener) {
        this.clickListener = clickListener;
    }
 
    public void addData(List<D> data1) {
        try {
            if (data1 != null) {
                int s=datas.size();
                datas.addAll(data1);
                if(s==0){
                    notifyDataSetChanged();
                }else {
                    notifyItemRangeInserted(s,data1.size());
                }
            }
        }catch (Exception e){
 
        }
 
    }
 
    public void refrenshData(List<D> data1) {
        if (data1 != null ) {
            datas.clear();
            addData(data1);
        }
    }
 
    public void removeDataByPosition(int position) {
        if (position >= 0 && position < datas.size()) {
            datas.remove(position);
            notifyItemRemoved(position);
        }
    }
 
    public D getDataByPosition(int position) {
        if (position >= 0 && position < datas.size()) {
            return datas.get(position);
        }
        return null;
    }
 
    public void clearData(){
        datas.clear();
        notifyDataSetChanged();
        //Phoenix.clearCaches();
    }
 
    public List<D> getDatas() {
        return datas;
    }
 
    @Override
    public int getItemCount() {
        return datas.size();
    }
 
 
}