//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.chad.library.adapter.base;
import android.animation.Animator;
import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.IntRange;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.chad.library.adapter.base.animation.AlphaInAnimation;
import com.chad.library.adapter.base.animation.BaseAnimation;
import com.chad.library.adapter.base.animation.ScaleInAnimation;
import com.chad.library.adapter.base.animation.SlideInBottomAnimation;
import com.chad.library.adapter.base.animation.SlideInLeftAnimation;
import com.chad.library.adapter.base.animation.SlideInRightAnimation;
import com.chad.library.adapter.base.entity.IExpandable;
import com.chad.library.adapter.base.loadmore.LoadMoreView;
import com.chad.library.adapter.base.loadmore.SimpleLoadMoreView;
import com.chad.library.adapter.base.util.MultiTypeDelegate;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public abstract class BaseQuickAdapter<T, K extends BaseViewHolder> extends Adapter<K> {
private boolean mNextLoadEnable;
private boolean mLoadMoreEnable;
private boolean mLoading;
private LoadMoreView mLoadMoreView;
private BaseQuickAdapter.RequestLoadMoreListener mRequestLoadMoreListener;
private boolean mEnableLoadMoreEndClick;
public static final int ALPHAIN = 1;
public static final int SCALEIN = 2;
public static final int SLIDEIN_BOTTOM = 3;
public static final int SLIDEIN_LEFT = 4;
public static final int SLIDEIN_RIGHT = 5;
private BaseQuickAdapter.OnItemClickListener mOnItemClickListener;
private BaseQuickAdapter.OnItemLongClickListener mOnItemLongClickListener;
private BaseQuickAdapter.OnItemChildClickListener mOnItemChildClickListener;
private BaseQuickAdapter.OnItemChildLongClickListener mOnItemChildLongClickListener;
private boolean mFirstOnlyEnable;
private boolean mOpenAnimationEnable;
private Interpolator mInterpolator;
private int mDuration;
private int mLastPosition;
private BaseAnimation mCustomAnimation;
private BaseAnimation mSelectAnimation;
private LinearLayout mHeaderLayout;
private LinearLayout mFooterLayout;
private FrameLayout mEmptyLayout;
private boolean mIsUseEmpty;
private boolean mHeadAndEmptyEnable;
private boolean mFootAndEmptyEnable;
protected static final String TAG = BaseQuickAdapter.class.getSimpleName();
protected Context mContext;
protected int mLayoutResId;
protected LayoutInflater mLayoutInflater;
protected List<T> mData;
public static final int HEADER_VIEW = 273;
public static final int LOADING_VIEW = 546;
public static final int FOOTER_VIEW = 819;
public static final int EMPTY_VIEW = 1365;
private RecyclerView mRecyclerView;
private boolean mUpFetchEnable;
private boolean mUpFetching;
private BaseQuickAdapter.UpFetchListener mUpFetchListener;
private int mStartUpFetchPosition;
private boolean headerViewAsFlow;
private boolean footerViewAsFlow;
private BaseQuickAdapter.SpanSizeLookup mSpanSizeLookup;
private MultiTypeDelegate<T> mMultiTypeDelegate;
private int mPreLoadNumber;
protected RecyclerView getRecyclerView() {
return this.mRecyclerView;
}
private void setRecyclerView(RecyclerView recyclerView) {
this.mRecyclerView = recyclerView;
}
private void checkNotNull() {
if(this.getRecyclerView() == null) {
throw new RuntimeException("please bind recyclerView first!");
}
}
public void bindToRecyclerView(RecyclerView recyclerView) {
if(this.getRecyclerView() != null) {
throw new RuntimeException("Don't bind twice");
} else {
this.setRecyclerView(recyclerView);
this.getRecyclerView().setAdapter(this);
}
}
/** @deprecated */
@Deprecated
public void setOnLoadMoreListener(BaseQuickAdapter.RequestLoadMoreListener requestLoadMoreListener) {
this.openLoadMore(requestLoadMoreListener);
}
private void openLoadMore(BaseQuickAdapter.RequestLoadMoreListener requestLoadMoreListener) {
this.mRequestLoadMoreListener = requestLoadMoreListener;
this.mNextLoadEnable = true;
this.mLoadMoreEnable = true;
this.mLoading = false;
}
public void setOnLoadMoreListener(BaseQuickAdapter.RequestLoadMoreListener requestLoadMoreListener, RecyclerView recyclerView) {
this.openLoadMore(requestLoadMoreListener);
if(this.getRecyclerView() == null) {
this.setRecyclerView(recyclerView);
}
}
public void disableLoadMoreIfNotFullPage() {
this.checkNotNull();
this.disableLoadMoreIfNotFullPage(this.getRecyclerView());
}
public void disableLoadMoreIfNotFullPage(RecyclerView recyclerView) {
this.setEnableLoadMore(false);
if(recyclerView != null) {
LayoutManager manager = recyclerView.getLayoutManager();
if(manager != null) {
if(manager instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager)manager;
recyclerView.postDelayed(new Runnable() {
public void run() {
if(linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1 != BaseQuickAdapter.this.getItemCount()) {
BaseQuickAdapter.this.setEnableLoadMore(true);
}
}
}, 50L);
} else if(manager instanceof StaggeredGridLayoutManager) {
final StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager)manager;
recyclerView.postDelayed(new Runnable() {
public void run() {
int[] positions = new int[staggeredGridLayoutManager.getSpanCount()];
staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(positions);
int pos = BaseQuickAdapter.this.getTheBiggestNumber(positions) + 1;
if(pos != BaseQuickAdapter.this.getItemCount()) {
BaseQuickAdapter.this.setEnableLoadMore(true);
}
}
}, 50L);
}
}
}
}
private int getTheBiggestNumber(int[] numbers) {
int tmp = -1;
if(numbers != null && numbers.length != 0) {
int[] var3 = numbers;
int var4 = numbers.length;
for(int var5 = 0; var5 < var4; ++var5) {
int num = var3[var5];
if(num > tmp) {
tmp = num;
}
}
return tmp;
} else {
return tmp;
}
}
public void setUpFetchEnable(boolean upFetch) {
this.mUpFetchEnable = upFetch;
}
public boolean isUpFetchEnable() {
return this.mUpFetchEnable;
}
public void setStartUpFetchPosition(int startUpFetchPosition) {
this.mStartUpFetchPosition = startUpFetchPosition;
}
private void autoUpFetch(int positions) {
if(this.isUpFetchEnable() && !this.isUpFetching()) {
if(positions <= this.mStartUpFetchPosition && this.mUpFetchListener != null) {
this.mUpFetchListener.onUpFetch();
}
}
}
public boolean isUpFetching() {
return this.mUpFetching;
}
public void setUpFetching(boolean upFetching) {
this.mUpFetching = upFetching;
}
public void setUpFetchListener(BaseQuickAdapter.UpFetchListener upFetchListener) {
this.mUpFetchListener = upFetchListener;
}
public void setNotDoAnimationCount(int count) {
this.mLastPosition = count;
}
public void setLoadMoreView(LoadMoreView loadingView) {
this.mLoadMoreView = loadingView;
}
public int getLoadMoreViewCount() {
return this.mRequestLoadMoreListener != null && this.mLoadMoreEnable?(!this.mNextLoadEnable && this.mLoadMoreView.isLoadEndMoreGone()?0:(this.mData.size() == 0?0:1)):0;
}
public int getLoadMoreViewPosition() {
return this.getHeaderLayoutCount() + this.mData.size() + this.getFooterLayoutCount();
}
public boolean isLoading() {
return this.mLoading;
}
public void loadMoreEnd() {
this.loadMoreEnd(false);
}
public void loadMoreEnd(boolean gone) {
if(this.getLoadMoreViewCount() != 0) {
this.mLoading = false;
this.mNextLoadEnable = false;
this.mLoadMoreView.setLoadMoreEndGone(gone);
if(gone) {
this.notifyItemRemoved(this.getLoadMoreViewPosition());
} else {
this.mLoadMoreView.setLoadMoreStatus(4);
this.notifyItemChanged(this.getLoadMoreViewPosition());
}
}
}
public void loadMoreComplete() {
if(this.getLoadMoreViewCount() != 0) {
this.mLoading = false;
this.mNextLoadEnable = true;
this.mLoadMoreView.setLoadMoreStatus(1);
this.notifyItemChanged(this.getLoadMoreViewPosition());
}
}
public void loadMoreFail() {
if(this.getLoadMoreViewCount() != 0) {
this.mLoading = false;
this.mLoadMoreView.setLoadMoreStatus(3);
this.notifyItemChanged(this.getLoadMoreViewPosition());
}
}
public void setEnableLoadMore(boolean enable) {
int oldLoadMoreCount = this.getLoadMoreViewCount();
this.mLoadMoreEnable = enable;
int newLoadMoreCount = this.getLoadMoreViewCount();
if(oldLoadMoreCount == 1) {
if(newLoadMoreCount == 0) {
this.notifyItemRemoved(this.getLoadMoreViewPosition());
}
} else if(newLoadMoreCount == 1) {
this.mLoadMoreView.setLoadMoreStatus(1);
this.notifyItemInserted(this.getLoadMoreViewPosition());
}
}
public boolean isLoadMoreEnable() {
return this.mLoadMoreEnable;
}
public void setDuration(int duration) {
this.mDuration = duration;
}
public BaseQuickAdapter(@LayoutRes int layoutResId, @Nullable List<T> data) {
this.mNextLoadEnable = false;
this.mLoadMoreEnable = false;
this.mLoading = false;
this.mLoadMoreView = new SimpleLoadMoreView();
this.mEnableLoadMoreEndClick = false;
this.mFirstOnlyEnable = true;
this.mOpenAnimationEnable = false;
this.mInterpolator = new LinearInterpolator();
this.mDuration = 300;
this.mLastPosition = -1;
this.mSelectAnimation = new AlphaInAnimation();
this.mIsUseEmpty = true;
this.mStartUpFetchPosition = 1;
this.mPreLoadNumber = 1;
this.mData = (List)(data == null?new ArrayList():data);
if(layoutResId != 0) {
this.mLayoutResId = layoutResId;
}
}
public BaseQuickAdapter(@Nullable List<T> data) {
this(0, data);
}
public BaseQuickAdapter(@LayoutRes int layoutResId) {
this(layoutResId, (List)null);
}
public void setNewData(@Nullable List<T> data) {
this.mData = (List)(data == null?new ArrayList():data);
if(this.mRequestLoadMoreListener != null) {
this.mNextLoadEnable = true;
this.mLoadMoreEnable = true;
this.mLoading = false;
this.mLoadMoreView.setLoadMoreStatus(1);
}
this.mLastPosition = -1;
this.notifyDataSetChanged();
}
/** @deprecated */
@Deprecated
public void add(@IntRange(from = 0L) int position, @NonNull T item) {
this.addData(position, item);
}
public void addData(@IntRange(from = 0L) int position, @NonNull T data) {
this.mData.add(position, data);
this.notifyItemInserted(position + this.getHeaderLayoutCount());
this.compatibilityDataSizeChanged(1);
}
public void addData(@NonNull T data) {
this.mData.add(data);
this.notifyItemInserted(this.mData.size() + this.getHeaderLayoutCount());
this.compatibilityDataSizeChanged(1);
}
public void remove(@IntRange(from = 0L) int position) {
this.mData.remove(position);
int internalPosition = position + this.getHeaderLayoutCount();
this.notifyItemRemoved(internalPosition);
this.compatibilityDataSizeChanged(0);
this.notifyItemRangeChanged(internalPosition, this.mData.size() - internalPosition);
}
public void setData(@IntRange(from = 0L) int index, @NonNull T data) {
this.mData.set(index, data);
this.notifyItemChanged(index + this.getHeaderLayoutCount());
}
public void addData(@IntRange(from = 0L) int position, @NonNull Collection<? extends T> newData) {
this.mData.addAll(position, newData);
this.notifyItemRangeInserted(position + this.getHeaderLayoutCount(), newData.size());
this.compatibilityDataSizeChanged(newData.size());
}
public void addData(@NonNull Collection<? extends T> newData) {
this.mData.addAll(newData);
this.notifyItemRangeInserted(this.mData.size() - newData.size() + this.getHeaderLayoutCount(), newData.size());
this.compatibilityDataSizeChanged(newData.size());
}
public void replaceData(@NonNull Collection<? extends T> data) {
if(data != this.mData) {
this.mData.clear();
this.mData.addAll(data);
}
this.notifyDataSetChanged();
}
private void compatibilityDataSizeChanged(int size) {
int dataSize = this.mData == null?0:this.mData.size();
if(dataSize == size) {
this.notifyDataSetChanged();
}
}
@NonNull
public List<T> getData() {
return this.mData;
}
@Nullable
public T getItem(@IntRange(from = 0L) int position) {
return position < this.mData.size()?this.mData.get(position):null;
}
/** @deprecated */
@Deprecated
public int getHeaderViewsCount() {
return this.getHeaderLayoutCount();
}
/** @deprecated */
@Deprecated
public int getFooterViewsCount() {
return this.getFooterLayoutCount();
}
public int getHeaderLayoutCount() {
return this.mHeaderLayout != null && this.mHeaderLayout.getChildCount() != 0?1:0;
}
public int getFooterLayoutCount() {
return this.mFooterLayout != null && this.mFooterLayout.getChildCount() != 0?1:0;
}
public int getEmptyViewCount() {
return this.mEmptyLayout != null && this.mEmptyLayout.getChildCount() != 0?(!this.mIsUseEmpty?0:(this.mData.size() != 0?0:1)):0;
}
public int getItemCount() {
int count;
if(this.getEmptyViewCount() == 1) {
count = 1;
if(this.mHeadAndEmptyEnable && this.getHeaderLayoutCount() != 0) {
++count;
}
if(this.mFootAndEmptyEnable && this.getFooterLayoutCount() != 0) {
++count;
}
} else {
count = this.getHeaderLayoutCount() + this.mData.size() + this.getFooterLayoutCount() + this.getLoadMoreViewCount();
}
return count;
}
public int getItemViewType(int position) {
if(this.getEmptyViewCount() != 1) {
int numHeaders = this.getHeaderLayoutCount();
if(position < numHeaders) {
return 273;
} else {
int adjPosition = position - numHeaders;
int adapterCount = this.mData.size();
if(adjPosition < adapterCount) {
return this.getDefItemViewType(adjPosition);
} else {
adjPosition -= adapterCount;
int numFooters = this.getFooterLayoutCount();
return adjPosition < numFooters?819:546;
}
}
} else {
boolean header = this.mHeadAndEmptyEnable && this.getHeaderLayoutCount() != 0;
switch(position) {
case 0:
if(header) {
return 273;
}
return 1365;
case 1:
if(header) {
return 1365;
}
return 819;
case 2:
return 819;
default:
return 1365;
}
}
}
protected int getDefItemViewType(int position) {
return this.mMultiTypeDelegate != null?this.mMultiTypeDelegate.getDefItemViewType(this.mData, position):super.getItemViewType(position);
}
public K onCreateViewHolder(ViewGroup parent, int viewType) {
K baseViewHolder = null;
this.mContext = parent.getContext();
this.mLayoutInflater = LayoutInflater.from(this.mContext);
switch(viewType) {
case 273:
baseViewHolder = this.createBaseViewHolder(this.mHeaderLayout);
break;
case 546:
baseViewHolder = this.getLoadingView(parent);
break;
case 819:
baseViewHolder = this.createBaseViewHolder(this.mFooterLayout);
break;
case 1365:
baseViewHolder = this.createBaseViewHolder(this.mEmptyLayout);
break;
default:
baseViewHolder = this.onCreateDefViewHolder(parent, viewType);
this.bindViewClickListener(baseViewHolder);
}
baseViewHolder.setAdapter(this);
return baseViewHolder;
}
private K getLoadingView(ViewGroup parent) {
View view = this.getItemView(this.mLoadMoreView.getLayoutId(), parent);
K holder = this.createBaseViewHolder(view);
holder.itemView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(BaseQuickAdapter.this.mLoadMoreView.getLoadMoreStatus() == 3) {
BaseQuickAdapter.this.notifyLoadMoreToLoading();
}
if(BaseQuickAdapter.this.mEnableLoadMoreEndClick && BaseQuickAdapter.this.mLoadMoreView.getLoadMoreStatus() == 4) {
BaseQuickAdapter.this.notifyLoadMoreToLoading();
}
}
});
return holder;
}
public void notifyLoadMoreToLoading() {
if(this.mLoadMoreView.getLoadMoreStatus() != 2) {
this.mLoadMoreView.setLoadMoreStatus(1);
this.notifyItemChanged(this.getLoadMoreViewPosition());
}
}
public void enableLoadMoreEndClick(boolean enable) {
this.mEnableLoadMoreEndClick = enable;
}
public void onViewAttachedToWindow(K holder) {
super.onViewAttachedToWindow(holder);
int type = holder.getItemViewType();
if(type != 1365 && type != 273 && type != 819 && type != 546) {
this.addAnimation(holder);
} else {
this.setFullSpan(holder);
}
}
protected void setFullSpan(ViewHolder holder) {
if(holder.itemView.getLayoutParams() instanceof LayoutParams) {
LayoutParams params = (LayoutParams)holder.itemView.getLayoutParams();
params.setFullSpan(true);
}
}
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
LayoutManager manager = recyclerView.getLayoutManager();
if(manager instanceof GridLayoutManager) {
final GridLayoutManager gridManager = (GridLayoutManager)manager;
gridManager.setSpanSizeLookup(new android.support.v7.widget.GridLayoutManager.SpanSizeLookup() {
public int getSpanSize(int position) {
int type = BaseQuickAdapter.this.getItemViewType(position);
return type == 273 && BaseQuickAdapter.this.isHeaderViewAsFlow()?1:(type == 819 && BaseQuickAdapter.this.isFooterViewAsFlow()?1:(BaseQuickAdapter.this.mSpanSizeLookup == null?(BaseQuickAdapter.this.isFixedViewType(type)?gridManager.getSpanCount():1):(BaseQuickAdapter.this.isFixedViewType(type)?gridManager.getSpanCount():BaseQuickAdapter.this.mSpanSizeLookup.getSpanSize(gridManager, position - BaseQuickAdapter.this.getHeaderLayoutCount()))));
}
});
}
}
protected boolean isFixedViewType(int type) {
return type == 1365 || type == 273 || type == 819 || type == 546;
}
public void setHeaderViewAsFlow(boolean headerViewAsFlow) {
this.headerViewAsFlow = headerViewAsFlow;
}
public boolean isHeaderViewAsFlow() {
return this.headerViewAsFlow;
}
public void setFooterViewAsFlow(boolean footerViewAsFlow) {
this.footerViewAsFlow = footerViewAsFlow;
}
public boolean isFooterViewAsFlow() {
return this.footerViewAsFlow;
}
public void setSpanSizeLookup(BaseQuickAdapter.SpanSizeLookup spanSizeLookup) {
this.mSpanSizeLookup = spanSizeLookup;
}
public void onBindViewHolder(K holder, int position) {
this.autoUpFetch(position);
this.autoLoadMore(position);
int viewType = holder.getItemViewType();
switch(viewType) {
case 0:
this.convert(holder, this.getItem(position - this.getHeaderLayoutCount()));
case 273:
case 819:
case 1365:
break;
case 546:
this.mLoadMoreView.convert(holder);
break;
default:
this.convert(holder, this.getItem(position - this.getHeaderLayoutCount()));
}
}
private void bindViewClickListener(final BaseViewHolder baseViewHolder) {
if(baseViewHolder != null) {
View view = baseViewHolder.itemView;
if(view != null) {
if(this.getOnItemClickListener() != null) {
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
BaseQuickAdapter.this.getOnItemClickListener().onItemClick(BaseQuickAdapter.this, v, baseViewHolder.getLayoutPosition() - BaseQuickAdapter.this.getHeaderLayoutCount());
}
});
}
if(this.getOnItemLongClickListener() != null) {
view.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
return BaseQuickAdapter.this.getOnItemLongClickListener().onItemLongClick(BaseQuickAdapter.this, v, baseViewHolder.getLayoutPosition() - BaseQuickAdapter.this.getHeaderLayoutCount());
}
});
}
}
}
}
public void setMultiTypeDelegate(MultiTypeDelegate<T> multiTypeDelegate) {
this.mMultiTypeDelegate = multiTypeDelegate;
}
public MultiTypeDelegate<T> getMultiTypeDelegate() {
return this.mMultiTypeDelegate;
}
protected K onCreateDefViewHolder(ViewGroup parent, int viewType) {
int layoutId = this.mLayoutResId;
if(this.mMultiTypeDelegate != null) {
layoutId = this.mMultiTypeDelegate.getLayoutId(viewType);
}
return this.createBaseViewHolder(parent, layoutId);
}
protected K createBaseViewHolder(ViewGroup parent, int layoutResId) {
return this.createBaseViewHolder(this.getItemView(layoutResId, parent));
}
protected K createBaseViewHolder(View view) {
Class temp = this.getClass();
Class z;
for(z = null; z == null && null != temp; temp = temp.getSuperclass()) {
z = this.getInstancedGenericKClass(temp);
}
BaseViewHolder k;
if(z == null) {
k = new BaseViewHolder(view);
} else {
k = this.createGenericKInstance(z, view);
}
return k != null?k:new BaseViewHolder(view);
}
private K createGenericKInstance(Class z, View view) {
try {
Constructor constructor;
if(z.isMemberClass() && !Modifier.isStatic(z.getModifiers())) {
constructor = z.getDeclaredConstructor(new Class[]{this.getClass(), View.class});
constructor.setAccessible(true);
return (BaseViewHolder)constructor.newInstance(new Object[]{this, view});
}
constructor = z.getDeclaredConstructor(new Class[]{View.class});
constructor.setAccessible(true);
return (BaseViewHolder)constructor.newInstance(new Object[]{view});
} catch (NoSuchMethodException var4) {
var4.printStackTrace();
} catch (IllegalAccessException var5) {
var5.printStackTrace();
} catch (InstantiationException var6) {
var6.printStackTrace();
} catch (InvocationTargetException var7) {
var7.printStackTrace();
}
return null;
}
private Class getInstancedGenericKClass(Class z) {
Type type = z.getGenericSuperclass();
if(type instanceof ParameterizedType) {
Type[] types = ((ParameterizedType)type).getActualTypeArguments();
Type[] var4 = types;
int var5 = types.length;
for(int var6 = 0; var6 < var5; ++var6) {
Type temp = var4[var6];
if(temp instanceof Class) {
Class tempClass = (Class)temp;
if(BaseViewHolder.class.isAssignableFrom(tempClass)) {
return tempClass;
}
}
}
}
return null;
}
public LinearLayout getHeaderLayout() {
return this.mHeaderLayout;
}
public LinearLayout getFooterLayout() {
return this.mFooterLayout;
}
public int addHeaderView(View header) {
return this.addHeaderView(header, -1);
}
public int addHeaderView(View header, int index) {
return this.addHeaderView(header, index, 1);
}
public int addHeaderView(View header, int index, int orientation) {
if(this.mHeaderLayout == null) {
this.mHeaderLayout = new LinearLayout(header.getContext());
if(orientation == 1) {
this.mHeaderLayout.setOrientation(1);
this.mHeaderLayout.setLayoutParams(new android.support.v7.widget.RecyclerView.LayoutParams(-1, -2));
} else {
this.mHeaderLayout.setOrientation(0);
this.mHeaderLayout.setLayoutParams(new android.support.v7.widget.RecyclerView.LayoutParams(-2, -1));
}
}
int childCount = this.mHeaderLayout.getChildCount();
if(index < 0 || index > childCount) {
index = childCount;
}
this.mHeaderLayout.addView(header, index);
if(this.mHeaderLayout.getChildCount() == 1) {
int position = this.getHeaderViewPosition();
if(position != -1) {
this.notifyItemInserted(position);
}
}
return index;
}
public int setHeaderView(View header) {
return this.setHeaderView(header, 0, 1);
}
public int setHeaderView(View header, int index) {
return this.setHeaderView(header, index, 1);
}
public int setHeaderView(View header, int index, int orientation) {
if(this.mHeaderLayout != null && this.mHeaderLayout.getChildCount() > index) {
this.mHeaderLayout.removeViewAt(index);
this.mHeaderLayout.addView(header, index);
return index;
} else {
return this.addHeaderView(header, index, orientation);
}
}
public int addFooterView(View footer) {
return this.addFooterView(footer, -1, 1);
}
public int addFooterView(View footer, int index) {
return this.addFooterView(footer, index, 1);
}
public int addFooterView(View footer, int index, int orientation) {
if(this.mFooterLayout == null) {
this.mFooterLayout = new LinearLayout(footer.getContext());
if(orientation == 1) {
this.mFooterLayout.setOrientation(1);
this.mFooterLayout.setLayoutParams(new android.support.v7.widget.RecyclerView.LayoutParams(-1, -2));
} else {
this.mFooterLayout.setOrientation(0);
this.mFooterLayout.setLayoutParams(new android.support.v7.widget.RecyclerView.LayoutParams(-2, -1));
}
}
int childCount = this.mFooterLayout.getChildCount();
if(index < 0 || index > childCount) {
index = childCount;
}
this.mFooterLayout.addView(footer, index);
if(this.mFooterLayout.getChildCount() == 1) {
int position = this.getFooterViewPosition();
if(position != -1) {
this.notifyItemInserted(position);
}
}
return index;
}
public int setFooterView(View header) {
return this.setFooterView(header, 0, 1);
}
public int setFooterView(View header, int index) {
return this.setFooterView(header, index, 1);
}
public int setFooterView(View header, int index, int orientation) {
if(this.mFooterLayout != null && this.mFooterLayout.getChildCount() > index) {
this.mFooterLayout.removeViewAt(index);
this.mFooterLayout.addView(header, index);
return index;
} else {
return this.addFooterView(header, index, orientation);
}
}
public void removeHeaderView(View header) {
if(this.getHeaderLayoutCount() != 0) {
this.mHeaderLayout.removeView(header);
if(this.mHeaderLayout.getChildCount() == 0) {
int position = this.getHeaderViewPosition();
if(position != -1) {
this.notifyItemRemoved(position);
}
}
}
}
public void removeFooterView(View footer) {
if(this.getFooterLayoutCount() != 0) {
this.mFooterLayout.removeView(footer);
if(this.mFooterLayout.getChildCount() == 0) {
int position = this.getFooterViewPosition();
if(position != -1) {
this.notifyItemRemoved(position);
}
}
}
}
public void removeAllHeaderView() {
if(this.getHeaderLayoutCount() != 0) {
this.mHeaderLayout.removeAllViews();
int position = this.getHeaderViewPosition();
if(position != -1) {
this.notifyItemRemoved(position);
}
}
}
public void removeAllFooterView() {
if(this.getFooterLayoutCount() != 0) {
this.mFooterLayout.removeAllViews();
int position = this.getFooterViewPosition();
if(position != -1) {
this.notifyItemRemoved(position);
}
}
}
private int getHeaderViewPosition() {
return this.getEmptyViewCount() == 1?(this.mHeadAndEmptyEnable?0:-1):0;
}
private int getFooterViewPosition() {
if(this.getEmptyViewCount() == 1) {
int position = 1;
if(this.mHeadAndEmptyEnable && this.getHeaderLayoutCount() != 0) {
++position;
}
return this.mFootAndEmptyEnable?position:-1;
} else {
return this.getHeaderLayoutCount() + this.mData.size();
}
}
public void setEmptyView(int layoutResId, ViewGroup viewGroup) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(layoutResId, viewGroup, false);
this.setEmptyView(view);
}
public void setEmptyView(int layoutResId) {
this.checkNotNull();
this.setEmptyView(layoutResId, this.getRecyclerView());
}
public void setEmptyView(View emptyView) {
boolean insert = false;
if(this.mEmptyLayout == null) {
this.mEmptyLayout = new FrameLayout(emptyView.getContext());
android.support.v7.widget.RecyclerView.LayoutParams layoutParams = new android.support.v7.widget.RecyclerView.LayoutParams(-1, -1);
android.view.ViewGroup.LayoutParams lp = emptyView.getLayoutParams();
if(lp != null) {
layoutParams.width = lp.width;
layoutParams.height = lp.height;
}
this.mEmptyLayout.setLayoutParams(layoutParams);
insert = true;
}
this.mEmptyLayout.removeAllViews();
this.mEmptyLayout.addView(emptyView);
this.mIsUseEmpty = true;
if(insert && this.getEmptyViewCount() == 1) {
int position = 0;
if(this.mHeadAndEmptyEnable && this.getHeaderLayoutCount() != 0) {
++position;
}
this.notifyItemInserted(position);
}
}
public void setHeaderAndEmpty(boolean isHeadAndEmpty) {
this.setHeaderFooterEmpty(isHeadAndEmpty, false);
}
public void setHeaderFooterEmpty(boolean isHeadAndEmpty, boolean isFootAndEmpty) {
this.mHeadAndEmptyEnable = isHeadAndEmpty;
this.mFootAndEmptyEnable = isFootAndEmpty;
}
public void isUseEmpty(boolean isUseEmpty) {
this.mIsUseEmpty = isUseEmpty;
}
public View getEmptyView() {
return this.mEmptyLayout;
}
/** @deprecated */
@Deprecated
public void setAutoLoadMoreSize(int preLoadNumber) {
this.setPreLoadNumber(preLoadNumber);
}
public void setPreLoadNumber(int preLoadNumber) {
if(preLoadNumber > 1) {
this.mPreLoadNumber = preLoadNumber;
}
}
private void autoLoadMore(int position) {
if(this.getLoadMoreViewCount() != 0) {
if(position >= this.getItemCount() - this.mPreLoadNumber) {
if(this.mLoadMoreView.getLoadMoreStatus() == 1) {
this.mLoadMoreView.setLoadMoreStatus(2);
if(!this.mLoading) {
this.mLoading = true;
if(this.getRecyclerView() != null) {
this.getRecyclerView().post(new Runnable() {
public void run() {
BaseQuickAdapter.this.mRequestLoadMoreListener.onLoadMoreRequested();
}
});
} else {
this.mRequestLoadMoreListener.onLoadMoreRequested();
}
}
}
}
}
}
private void addAnimation(ViewHolder holder) {
if(this.mOpenAnimationEnable && (!this.mFirstOnlyEnable || holder.getLayoutPosition() > this.mLastPosition)) {
BaseAnimation animation = null;
if(this.mCustomAnimation != null) {
animation = this.mCustomAnimation;
} else {
animation = this.mSelectAnimation;
}
Animator[] var3 = animation.getAnimators(holder.itemView);
int var4 = var3.length;
for(int var5 = 0; var5 < var4; ++var5) {
Animator anim = var3[var5];
this.startAnim(anim, holder.getLayoutPosition());
}
this.mLastPosition = holder.getLayoutPosition();
}
}
protected void startAnim(Animator anim, int index) {
anim.setDuration((long)this.mDuration).start();
anim.setInterpolator(this.mInterpolator);
}
protected View getItemView(@LayoutRes int layoutResId, ViewGroup parent) {
return this.mLayoutInflater.inflate(layoutResId, parent, false);
}
public void openLoadAnimation(int animationType) {
this.mOpenAnimationEnable = true;
this.mCustomAnimation = null;
switch(animationType) {
case 1:
this.mSelectAnimation = new AlphaInAnimation();
break;
case 2:
this.mSelectAnimation = new ScaleInAnimation();
break;
case 3:
this.mSelectAnimation = new SlideInBottomAnimation();
break;
case 4:
this.mSelectAnimation = new SlideInLeftAnimation();
break;
case 5:
this.mSelectAnimation = new SlideInRightAnimation();
}
}
public void openLoadAnimation(BaseAnimation animation) {
this.mOpenAnimationEnable = true;
this.mCustomAnimation = animation;
}
public void openLoadAnimation() {
this.mOpenAnimationEnable = true;
}
public void isFirstOnly(boolean firstOnly) {
this.mFirstOnlyEnable = firstOnly;
}
protected abstract void convert(K var1, T var2);
@Nullable
public View getViewByPosition(int position, @IdRes int viewId) {
this.checkNotNull();
return this.getViewByPosition(this.getRecyclerView(), position, viewId);
}
@Nullable
public View getViewByPosition(RecyclerView recyclerView, int position, @IdRes int viewId) {
if(recyclerView == null) {
return null;
} else {
BaseViewHolder viewHolder = (BaseViewHolder)recyclerView.findViewHolderForLayoutPosition(position);
return viewHolder == null?null:viewHolder.getView(viewId);
}
}
public long getItemId(int position) {
return (long)position;
}
private int recursiveExpand(int position, @NonNull List list) {
int count = 0;
int pos = position + list.size() - 1;
for(int i = list.size() - 1; i >= 0; --pos) {
if(list.get(i) instanceof IExpandable) {
IExpandable item = (IExpandable)list.get(i);
if(item.isExpanded() && this.hasSubItems(item)) {
List subList = item.getSubItems();
this.mData.addAll(pos + 1, subList);
int subItemCount = this.recursiveExpand(pos + 1, subList);
count += subItemCount;
}
}
--i;
}
return count;
}
public int expand(@IntRange(from = 0L) int position, boolean animate, boolean shouldNotify) {
position -= this.getHeaderLayoutCount();
IExpandable expandable = this.getExpandableItem(position);
if(expandable == null) {
return 0;
} else if(!this.hasSubItems(expandable)) {
expandable.setExpanded(false);
return 0;
} else {
int subItemCount = 0;
if(!expandable.isExpanded()) {
List list = expandable.getSubItems();
this.mData.addAll(position + 1, list);
subItemCount += this.recursiveExpand(position + 1, list);
expandable.setExpanded(true);
subItemCount += list.size();
}
int parentPos = position + this.getHeaderLayoutCount();
if(shouldNotify) {
if(animate) {
this.notifyItemChanged(parentPos);
this.notifyItemRangeInserted(parentPos + 1, subItemCount);
} else {
this.notifyDataSetChanged();
}
}
return subItemCount;
}
}
public int expand(@IntRange(from = 0L) int position, boolean animate) {
return this.expand(position, animate, true);
}
public int expand(@IntRange(from = 0L) int position) {
return this.expand(position, true, true);
}
public int expandAll(int position, boolean animate, boolean notify) {
position -= this.getHeaderLayoutCount();
T endItem = null;
if(position + 1 < this.mData.size()) {
endItem = this.getItem(position + 1);
}
IExpandable expandable = this.getExpandableItem(position);
if(expandable != null && this.hasSubItems(expandable)) {
int count = this.expand(position + this.getHeaderLayoutCount(), false, false);
for(int i = position + 1; i < this.mData.size(); ++i) {
T item = this.getItem(i);
if(item == endItem) {
break;
}
if(this.isExpandable(item)) {
count += this.expand(i + this.getHeaderLayoutCount(), false, false);
}
}
if(notify) {
if(animate) {
this.notifyItemRangeInserted(position + this.getHeaderLayoutCount() + 1, count);
} else {
this.notifyDataSetChanged();
}
}
return count;
} else {
return 0;
}
}
public int expandAll(int position, boolean init) {
return this.expandAll(position, true, !init);
}
public void expandAll() {
for(int i = this.mData.size() - 1; i >= this.getHeaderLayoutCount(); --i) {
this.expandAll(i, false, false);
}
}
private int recursiveCollapse(@IntRange(from = 0L) int position) {
T item = this.getItem(position);
if(!this.isExpandable(item)) {
return 0;
} else {
IExpandable expandable = (IExpandable)item;
int subItemCount = 0;
if(expandable.isExpanded()) {
List<T> subItems = expandable.getSubItems();
for(int i = subItems.size() - 1; i >= 0; --i) {
T subItem = subItems.get(i);
int pos = this.getItemPosition(subItem);
if(pos >= 0) {
if(subItem instanceof IExpandable) {
subItemCount += this.recursiveCollapse(pos);
}
this.mData.remove(pos);
++subItemCount;
}
}
}
return subItemCount;
}
}
public int collapse(@IntRange(from = 0L) int position, boolean animate, boolean notify) {
position -= this.getHeaderLayoutCount();
IExpandable expandable = this.getExpandableItem(position);
if(expandable == null) {
return 0;
} else {
int subItemCount = this.recursiveCollapse(position);
expandable.setExpanded(false);
int parentPos = position + this.getHeaderLayoutCount();
if(notify) {
if(animate) {
this.notifyItemChanged(parentPos);
this.notifyItemRangeRemoved(parentPos + 1, subItemCount);
} else {
this.notifyDataSetChanged();
}
}
return subItemCount;
}
}
public int collapse(@IntRange(from = 0L) int position) {
return this.collapse(position, true, true);
}
public int collapse(@IntRange(from = 0L) int position, boolean animate) {
return this.collapse(position, animate, true);
}
private int getItemPosition(T item) {
return item != null && this.mData != null && !this.mData.isEmpty()?this.mData.indexOf(item):-1;
}
private boolean hasSubItems(IExpandable item) {
if(item == null) {
return false;
} else {
List list = item.getSubItems();
return list != null && list.size() > 0;
}
}
public boolean isExpandable(T item) {
return item != null && item instanceof IExpandable;
}
private IExpandable getExpandableItem(int position) {
T item = this.getItem(position);
return this.isExpandable(item)?(IExpandable)item:null;
}
public int getParentPosition(@NonNull T item) {
int position = this.getItemPosition(item);
if(position == -1) {
return -1;
} else {
int level;
if(item instanceof IExpandable) {
level = ((IExpandable)item).getLevel();
} else {
level = 2147483647;
}
if(level == 0) {
return position;
} else if(level == -1) {
return -1;
} else {
for(int i = position; i >= 0; --i) {
T temp = this.mData.get(i);
if(temp instanceof IExpandable) {
IExpandable expandable = (IExpandable)temp;
if(expandable.getLevel() >= 0 && expandable.getLevel() < level) {
return i;
}
}
}
return -1;
}
}
}
public void setOnItemClickListener(@Nullable BaseQuickAdapter.OnItemClickListener listener) {
this.mOnItemClickListener = listener;
}
public void setOnItemChildClickListener(BaseQuickAdapter.OnItemChildClickListener listener) {
this.mOnItemChildClickListener = listener;
}
public void setOnItemLongClickListener(BaseQuickAdapter.OnItemLongClickListener listener) {
this.mOnItemLongClickListener = listener;
}
public void setOnItemChildLongClickListener(BaseQuickAdapter.OnItemChildLongClickListener listener) {
this.mOnItemChildLongClickListener = listener;
}
public final BaseQuickAdapter.OnItemLongClickListener getOnItemLongClickListener() {
return this.mOnItemLongClickListener;
}
public final BaseQuickAdapter.OnItemClickListener getOnItemClickListener() {
return this.mOnItemClickListener;
}
@Nullable
public final BaseQuickAdapter.OnItemChildClickListener getOnItemChildClickListener() {
return this.mOnItemChildClickListener;
}
@Nullable
public final BaseQuickAdapter.OnItemChildLongClickListener getOnItemChildLongClickListener() {
return this.mOnItemChildLongClickListener;
}
public interface OnItemClickListener {
void onItemClick(BaseQuickAdapter var1, View var2, int var3);
}
public interface OnItemLongClickListener {
boolean onItemLongClick(BaseQuickAdapter var1, View var2, int var3);
}
public interface OnItemChildLongClickListener {
boolean onItemChildLongClick(BaseQuickAdapter var1, View var2, int var3);
}
public interface OnItemChildClickListener {
void onItemChildClick(BaseQuickAdapter var1, View var2, int var3);
}
public interface RequestLoadMoreListener {
void onLoadMoreRequested();
}
public interface SpanSizeLookup {
int getSpanSize(GridLayoutManager var1, int var2);
}
public interface UpFetchListener {
void onUpFetch();
}
@Retention(RetentionPolicy.SOURCE)
public @interface AnimationType {
}
}
BarView
最新推荐文章于 2022-05-18 07:50:27 发布