Initial commit
This commit is contained in:
82
sources/com/recyclelib/adapter/BaseRecyclerAdapter.java
Normal file
82
sources/com/recyclelib/adapter/BaseRecyclerAdapter.java
Normal file
@@ -0,0 +1,82 @@
|
||||
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));
|
||||
}
|
||||
}
|
79
sources/com/recyclelib/adapter/MultiRecyclerAdapter.java
Normal file
79
sources/com/recyclelib/adapter/MultiRecyclerAdapter.java
Normal file
@@ -0,0 +1,79 @@
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user