rk
昨天 4a8ff39b0fab0627ef8f7459587d514cc01c3676
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
package com.doumee.lib_coremodel.view.recyclerview.adapter;
 
import android.content.Context;
 
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.DiffUtil;
 
import java.util.ArrayList;
import java.util.List;
 
public abstract class DiffBindingAdapter<T,DVB extends ViewDataBinding> extends DiffBaseRecyclerAdapter<T, BindingHolder<DVB>> {
 
    public DiffBindingAdapter(Context context, int layoutId, DiffUtil.ItemCallback<T> DIFF_CALLBACK) {
        super(context, layoutId,DIFF_CALLBACK);
    }
 
 
    public T getItem(int position) {
        if(position<getItemCount()){
            return getListData().get(position);
        }
        return null;
    }
 
    public void refreshData(List<T> list){
        if(list!=null){
            setListData(list);
        }else{
            setListData(new ArrayList<>());
        }
    }
 
    public T getDataByPosition(int position) {
        if (position >= 0 && position < getListData().size()) {
            return getListData().get(position);
        }
        return null;
    }
 
    public void clearData(){
        setListData(new ArrayList<>());
    }
}