package com.taro.headerrecycle.adapter;
import android.support.annotation.NonNull;
import android.support.v4.util.ArrayMap;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import com.taro.headerrecycle.stickerheader.StickHeaderItemDecoration;
import com.taro.headerrecycle.layoutmanager.HeaderSpanSizeLookup;
import java.util.AbstractMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Created by taro on 16/5/19.
*/
public class ExtraViewWrapAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements StickHeaderItemDecoration.IStickerHeaderDecoration, HeaderSpanSizeLookup.ISpanSizeHandler {
public static final int VIEW_HEADER_REFRESH = Integer.MAX_VALUE / 3;
public static final int VIEW_FOOTER_LOAD_MORE = Integer.MIN_VALUE / 3;
private HeaderFooterViewCache mHeaderOption = null;
private HeaderFooterViewCache mFooterOption = null;
private StickHeaderItemDecoration.IStickerHeaderDecoration mIStickHeaderDecoration = null;
private HeaderSpanSizeLookup.ISpanSizeHandler mISpanSizeLookup = null;
private View mRefreshHeader = null;
private View mLoadMoreFooter = null;
private boolean mIsRefreshing = false;
private boolean mIsLoading = false;
private RecyclerView.Adapter mInnerAdapter;
private boolean mIsFootViewEnable = true;
private boolean mIsHeaderViewEnable = true;
public static final void setRrefreshingViewStatus(boolean isRefreshing, boolean isScrollToStart, RecyclerView recyclerView) {
if (recyclerView == null) {
return;
} else {
RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter != null && adapter instanceof ExtraViewWrapAdapter) {
ExtraViewWrapAdapter wrapAdapter = (ExtraViewWrapAdapter) adapter;
wrapAdapter.setRefreshingStatus(isRefreshing);
if (isScrollToStart) {
recyclerView.scrollToPosition(0);
}
}
}
}
public static final void setLoadingViewStatus(boolean isLoading, boolean isScrollToEnd, RecyclerView recyclerView) {
if (recyclerView == null) {
return;
} else {
RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter != null && adapter instanceof ExtraViewWrapAdapter) {
ExtraViewWrapAdapter wrapAdapter = (ExtraViewWrapAdapter) adapter;
wrapAdapter.setLoadingStatus(isLoading);
if (isScrollToEnd) {
recyclerView.scrollToPosition(wrapAdapter.getItemCount() - 1);
}
}
}
}
public static final void setHeaderViewEnable(boolean isHeaderEnable, boolean isScrollToHeader, RecyclerView recycleView) {
if (recycleView == null) {
return;
} else {
RecyclerView.Adapter adapter = recycleView.getAdapter();
if (adapter != null && adapter instanceof ExtraViewWrapAdapter) {
ExtraViewWrapAdapter wrapAdapter = (ExtraViewWrapAdapter) adapter;
wrapAdapter.setHeaderViewEnable(isHeaderEnable);
if (isScrollToHeader) {
recycleView.scrollToPosition(0);
}
}
}
}
public static final void setFooterViewEnable(boolean isFooterEnable, boolean isScrollToFooter, RecyclerView recyclerView) {
if (recyclerView == null) {
return;
} else {
RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter != null && adapter instanceof ExtraViewWrapAdapter) {
ExtraViewWrapAdapter wrapAdapter = (ExtraViewWrapAdapter) adapter;
wrapAdapter.setFootViewEnable(isFooterEnable);
if (isScrollToFooter) {
recyclerView.scrollToPosition(wrapAdapter.getItemCount() - 1);
}
}
}
}
/**
* 默认创建多头部/尾部包装类的adapter,头部/尾部都可显示
*
* @param innerAdapter
*/
public ExtraViewWrapAdapter(@NonNull RecyclerView.Adapter innerAdapter) {
this(innerAdapter, true, true);
}
/**
* 创建多头部/尾部包装类的adapter,使用此adapter包装内部adapter时会改变内部adapter的某些操作,当不再需要时请使用{@link #unregisterInnerAdatperDataObserver()}还原内部adapter的操作
*
* @param innerAdapter 内部引用的adapter,不可为null
* @param isHeaderViewEnable 头部view是否可用
* @param isFootViewEnable 尾部view是否可用
*/
public ExtraViewWrapAdapter(@NonNull RecyclerView.Adapter innerAdapter, boolean isHeaderViewEnable, boolean isFootViewEnable) {
this.setInnerAdapter(innerAdapter);
mIsHeaderViewEnable = isHeaderViewEnable;
mIsFootViewEnable = isFootViewEnable;
mHeaderOption = new HeaderFooterViewCache();
mFooterOption = new HeaderFooterViewCache();
mInnerAdapter.registerAdapterDataObserver(mDataObserver);
}
/**
* 设置固定头部item渲染的接口回调
*
* @param decoration 固定头部接口,用于回调判断当前项是否为头部/是否需要显示及绘制固定头部
*/
public void setIStickHeaderItemDecoration(StickHeaderItemDecoration.IStickerHeaderDecoration decoration) {
mIStickHeaderDecoration = decoration;
}
/**
* 设置 gridLayoutManager 需要显示的spanSizeLookup
*
* @param spanSizeLookup 用于正确显示item占用的网格数
*/
public void setISpanSizeLookup(HeaderSpanSizeLookup.ISpanSizeHandler spanSizeLookup) {
mISpanSizeLookup = spanSizeLookup;
}
/**
* 设置内置的innerAdapter,不可为null
*
* @param innerAdapter recycleView.Adapter,若该adapter已经实现了 {@link StickHeaderItemDecoration.IStickerHeaderDecoration}或者是{@link com.taro.headerrecycle.layoutmanager.HeaderSpanSizeLookup.ISpanSizeHandler}
* 将直接引用此实例,不需要再重新设置一次两个接口
*/
public void setInnerAdapter(@NonNull RecyclerView.Adapter innerAdapter) {
mInnerAdapter = innerAdapter;
if (mInnerAdapter != null && mInnerAdapter instanceof StickHeaderItemDecoration.IStickerHeaderDecoration) {
mIStickHeaderDecoration = (StickHeaderItemDecoration.IStickerHeaderDecoration) mInnerAdapter;
}
if (mInnerAdapter != null && mInnerAdapter instanceof HeaderSpanSizeLookup.ISpanSizeHandler) {
mISpanSizeLookup = (HeaderSpanSizeLookup.ISpanSizeHandler) mInnerAdapter;
}
}
/**
* 反注册内部innerAdapter的数据更新observer
*/
public void unregisterInnerAdatperDataObserver() {
if (mInnerAdapter != null) {
mInnerAdapter.unregisterAdapterDataObserver(mDataObserver);
}
}
/**
* 重新注册内部innerAdapter的数据更新observer
*/
public void reregisterInnerAdapterDataObserver() {
if (mInnerAdapter != null) {
mInnerAdapter.registerAdapterDataObserver(mDataObserver);
}
}
/**
* 获取当前WrapAdapter位置在InnerAdapter中对应的位置,即除去headerView及refreshView
*
* @param wrapAdapterPosition 当前WrapAdapter的位置
* @return
*/
public int getInnerAdapterPosition(int wrapAdapterPosition) {
int refreshViewCount = getRefreshingViewCount();
int headerViewCount = getHeaderViewCount();
return wrapAdapterPosition - refreshViewCount - headerViewCount;
}
/**
* 设置刷新头部view
*
* @param refreshingView
*/
public void setRefreshingHeaderView(View refreshingView) {
mRefreshHeader = refreshingView;
}
/**
* 设置加载尾部v
疯狂小芋头
- 粉丝: 20
- 资源: 2
最新资源
- 机器学习-05-利用python建立汽车销售厂商偷漏税用户识别模型(包括数据和代码)
- keil5新建STM32工程,STM32固件库
- SourceCounter下载
- sealos工具包,用户离线安装部署k8s+docker集群环境
- 计算机视觉-01-基于SegNet和U-Net的遥感图像语义分割(包含代码和数据)
- 机械设计多功能采摘作业平台(含cad)sw12可编辑非常好的设计图纸100%好用.zip
- 42.圣诞树2.doc
- 机械设计动车组转向架模型动态展示台sw14可编辑非常好的设计图纸100%好用.zip
- 计算机视觉-02-基于U-Net的肝脏肿瘤分割(包含数据和代码)
- 2024.12.25記錄1111
- 基于springboot学习平台答辩PPT.ppt
- 机械设计干燥鼓风机sw16可编辑非常好的设计图纸100%好用.zip
- 机械设计钢制的储气罐sw18可编辑非常好的设计图纸100%好用.zip
- 《王道计算机考研 操作系统》思维导图
- 计算机视觉-03-使用U-Net实现肾脏CT分割(包含数据和代码)
- 网络园区实验1 HCIP
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈