80 lines
2.3 KiB
Java
80 lines
2.3 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 MultiRecyclerAdapter<T> extends RecyclerView.Adapter<MultiViewHolder> {
|
|
protected Context mContext;
|
|
protected LayoutInflater mInflater;
|
|
protected List<T> mList;
|
|
|
|
protected static class MultiViewHolder extends RecyclerView.ViewHolder {
|
|
private SparseArray<View> a;
|
|
private View b;
|
|
|
|
public MultiViewHolder(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 MultiRecyclerAdapter(Context context, List<T> list) {
|
|
this.mList = list == null ? new ArrayList<>() : list;
|
|
this.mContext = context;
|
|
this.mInflater = LayoutInflater.from(context);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public int getItemCount() {
|
|
List<T> list = this.mList;
|
|
if (list == null) {
|
|
return 0;
|
|
}
|
|
return list.size();
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public int getItemViewType(int i) {
|
|
return getLayoutId(i);
|
|
}
|
|
|
|
public abstract int getLayoutId(int i);
|
|
|
|
public void notifyChanged(List<T> list) {
|
|
if (this.mList == null) {
|
|
this.mList = new ArrayList();
|
|
}
|
|
this.mList.clear();
|
|
this.mList.addAll(list);
|
|
notifyDataSetChanged();
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public MultiViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
return new MultiViewHolder(this.mInflater.inflate(i, viewGroup, false));
|
|
}
|
|
|
|
protected MultiRecyclerAdapter(Context context) {
|
|
this.mContext = context;
|
|
this.mInflater = LayoutInflater.from(context);
|
|
}
|
|
}
|