83 lines
2.2 KiB
Java
83 lines
2.2 KiB
Java
package com.recyclelib.adapter;
|
|
|
|
import android.content.Context;
|
|
import android.util.SparseArray;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter<BaseViewHolder> {
|
|
protected Context mContext;
|
|
protected LayoutInflater mInflater;
|
|
protected List<T> mList;
|
|
|
|
protected static class BaseViewHolder extends RecyclerView.ViewHolder {
|
|
private SparseArray<View> a;
|
|
private View b;
|
|
|
|
public BaseViewHolder(View view) {
|
|
super(view);
|
|
this.a = new SparseArray<>();
|
|
this.b = view;
|
|
}
|
|
|
|
public <K extends View> K getView(int i) {
|
|
K k = (K) this.a.get(i);
|
|
if (k != null) {
|
|
return k;
|
|
}
|
|
K k2 = (K) this.b.findViewById(i);
|
|
this.a.put(i, k2);
|
|
return k2;
|
|
}
|
|
}
|
|
|
|
protected BaseRecyclerAdapter(Context context, List<T> list) {
|
|
this.mList = list;
|
|
if (this.mList == null) {
|
|
this.mList = new ArrayList();
|
|
}
|
|
this.mContext = context;
|
|
this.mInflater = LayoutInflater.from(context);
|
|
}
|
|
|
|
public List<T> getData() {
|
|
if (this.mList == null) {
|
|
this.mList = new ArrayList();
|
|
}
|
|
return this.mList;
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public int getItemCount() {
|
|
List<T> list = this.mList;
|
|
if (list == null) {
|
|
return 0;
|
|
}
|
|
return list.size();
|
|
}
|
|
|
|
public abstract int layoutId();
|
|
|
|
public void notifyChanged(List<T> list) {
|
|
if (list == null) {
|
|
return;
|
|
}
|
|
if (this.mList == null) {
|
|
this.mList = new ArrayList();
|
|
}
|
|
this.mList.clear();
|
|
this.mList.addAll(list);
|
|
notifyDataSetChanged();
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public BaseViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
return new BaseViewHolder(this.mInflater.inflate(layoutId(), viewGroup, false));
|
|
}
|
|
}
|