|
@@ -12,18 +12,21 @@ import android.view.ViewGroup;
|
|
|
|
|
|
import com.example.zhpan.banner.R;
|
|
|
import com.example.zhpan.banner.recyclerview.listener.ICustomClickListener;
|
|
|
-import com.example.zhpan.banner.recyclerview.module.ViewConfig;
|
|
|
+import com.example.zhpan.banner.recyclerview.module.RecyclerViewConfig;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
+import static com.example.zhpan.banner.recyclerview.module.RecyclerViewConfig.FOOTVIEW_TYPE;
|
|
|
+import static com.example.zhpan.banner.recyclerview.module.RecyclerViewConfig.HEADVIEW_TYPE;
|
|
|
+
|
|
|
/**
|
|
|
* 自定义RecyclerView,主要用于添加不同类型的Head和Foot
|
|
|
*/
|
|
|
public class CustomRecyclerView extends RecyclerView {
|
|
|
//保存头部的view
|
|
|
- private ArrayList<ViewConfig> mHeaderCouListInfo;
|
|
|
+ private ArrayList<RecyclerViewConfig> mHeaderCouListInfo;
|
|
|
//保存尾部的view
|
|
|
- private ArrayList<ViewConfig> mFooterCouListInfo;
|
|
|
+ private ArrayList<RecyclerViewConfig> mFooterCouListInfo;
|
|
|
//记录head的个数
|
|
|
private int headerCount;
|
|
|
//记录foot的个数
|
|
@@ -31,7 +34,7 @@ public class CustomRecyclerView extends RecyclerView {
|
|
|
//adapter,可能是CustomAdapter, 可能是自定义adapter
|
|
|
private Adapter mAdapter;
|
|
|
private Context mContext;
|
|
|
- private ICustomClickListener customClickListener;
|
|
|
+ //private ICustomClickListener customClickListener;
|
|
|
|
|
|
public CustomRecyclerView(@NonNull Context context) {
|
|
|
this(context, null);
|
|
@@ -52,24 +55,23 @@ public class CustomRecyclerView extends RecyclerView {
|
|
|
mContext = context;
|
|
|
}
|
|
|
|
|
|
- public ArrayList<ViewConfig> getmHeadCouListInfo() {
|
|
|
+ public ArrayList<RecyclerViewConfig> getHeadCouListInfo() {
|
|
|
return mHeaderCouListInfo;
|
|
|
}
|
|
|
|
|
|
- public ArrayList<ViewConfig> getmFootCouListInfo() {
|
|
|
+ public ArrayList<RecyclerViewConfig> getFootCouListInfo() {
|
|
|
return mFooterCouListInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加HeadView的方法
|
|
|
*/
|
|
|
-
|
|
|
public void addHeaderView(View view) {
|
|
|
addHeaderView(view, false);
|
|
|
}
|
|
|
|
|
|
public void addHeaderView(View view, boolean isCache) {
|
|
|
- setHeadViewConfig(view, ViewConfig.HEADVIEW, headerCount, 100000, isCache);
|
|
|
+ setHeadViewConfig(view, RecyclerViewConfig.HEADVIEW, headerCount, HEADVIEW_TYPE, isCache);
|
|
|
headerCount = mHeaderCouListInfo.size();
|
|
|
|
|
|
if (mAdapter != null) {
|
|
@@ -80,7 +82,7 @@ public class CustomRecyclerView extends RecyclerView {
|
|
|
}
|
|
|
|
|
|
public void addFootView(View view) {
|
|
|
- setFootViewConfig(view, ViewConfig.FOOTVIEW, footerCount, 100000);
|
|
|
+ setFootViewConfig(view, RecyclerViewConfig.FOOTVIEW, footerCount, FOOTVIEW_TYPE);
|
|
|
footerCount = mFooterCouListInfo.size();
|
|
|
if (mAdapter != null) {
|
|
|
if (!(mAdapter instanceof CustomAdapter)) {
|
|
@@ -98,17 +100,16 @@ public class CustomRecyclerView extends RecyclerView {
|
|
|
|
|
|
@Override
|
|
|
public void setAdapter(@Nullable Adapter adapter) {
|
|
|
- if (mHeaderCouListInfo.size() > 0 || mFooterCouListInfo.size() > 0) {
|
|
|
+ //if (mHeaderCouListInfo.size() > 0 || mFooterCouListInfo.size() > 0) {
|
|
|
mAdapter = new CustomAdapter(mHeaderCouListInfo, mFooterCouListInfo, adapter, mContext, this);
|
|
|
- } else {
|
|
|
- mAdapter = adapter;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 设置头尾的两个缓存为size 变相解决复用问题
|
|
|
- */
|
|
|
- getRecycledViewPool().setMaxRecycledViews(ViewConfig.FOOTVIEW_TYPE,
|
|
|
+ //} else {
|
|
|
+ // mAdapter = adapter;
|
|
|
+ //}
|
|
|
+
|
|
|
+ // 设置头尾的两个缓存为size 变相解决复用问题
|
|
|
+ getRecycledViewPool().setMaxRecycledViews(FOOTVIEW_TYPE,
|
|
|
mFooterCouListInfo.size() + 1);
|
|
|
- getRecycledViewPool().setMaxRecycledViews(ViewConfig.HEADVIEW_TYPE,
|
|
|
+ getRecycledViewPool().setMaxRecycledViews(HEADVIEW_TYPE,
|
|
|
mHeaderCouListInfo.size() + 1);
|
|
|
|
|
|
super.setAdapter(mAdapter);
|
|
@@ -119,7 +120,7 @@ public class CustomRecyclerView extends RecyclerView {
|
|
|
*/
|
|
|
private void setHeadViewConfig(View view, String type, int count, int headCount,
|
|
|
boolean isCache) {
|
|
|
- ViewConfig viewConfig = new ViewConfig();
|
|
|
+ RecyclerViewConfig viewConfig = new RecyclerViewConfig();
|
|
|
viewConfig.setTag(view.getClass() + type + count);
|
|
|
viewConfig.setType(headCount);
|
|
|
viewConfig.setView(R.layout.item_head_foot_parent);
|
|
@@ -136,7 +137,7 @@ public class CustomRecyclerView extends RecyclerView {
|
|
|
* 配置尾部view的信息
|
|
|
*/
|
|
|
private void setFootViewConfig(View view, String type, int count, int headCount) {
|
|
|
- ViewConfig viewConfig = new ViewConfig();
|
|
|
+ RecyclerViewConfig viewConfig = new RecyclerViewConfig();
|
|
|
viewConfig.setTag(view.getClass() + type + count);
|
|
|
viewConfig.setType(headCount);
|
|
|
viewConfig.setView(R.layout.item_head_foot_parent);
|
|
@@ -153,20 +154,26 @@ public class CustomRecyclerView extends RecyclerView {
|
|
|
}
|
|
|
|
|
|
public void setCustomClickListener(ICustomClickListener customClickListener) {
|
|
|
- this.customClickListener = customClickListener;
|
|
|
+ //this.customClickListener = customClickListener;
|
|
|
getHeadAndFootAdapter().setCustomClickListener(customClickListener);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 移除最后一个View, 就是加载更多的哪一个
|
|
|
*/
|
|
|
- public void removeLastFootView(int foorIndex) {
|
|
|
- this.mFooterCouListInfo.remove(foorIndex);
|
|
|
- footerCount = mFooterCouListInfo.size();
|
|
|
+ public void removeFooterView(int footerIndex) {
|
|
|
+ if (footerIndex < mFooterCouListInfo.size()) {
|
|
|
+ this.mFooterCouListInfo.remove(footerIndex);
|
|
|
+ footerCount = mFooterCouListInfo.size();
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public void removeFirstHeadView() {
|
|
|
- this.mHeaderCouListInfo.remove(0);
|
|
|
- headerCount = mHeaderCouListInfo.size();
|
|
|
+ public void removeFirstHeaderView() {
|
|
|
+ if (mHeaderCouListInfo.size() > 0) {
|
|
|
+ this.mHeaderCouListInfo.remove(0);
|
|
|
+ headerCount = mHeaderCouListInfo.size();
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
}
|
|
|
}
|