/** * if setHeadView will be return 1 if not will be return 0. * notice: Deprecated! Use {@link ViewGroup#getChildCount()} of {@link #getHeaderLayout()} to replace. * * @return */ @Deprecated public int getHeaderViewsCount() { return getHeaderLayoutCount(); }
private int getFooterViewPosition() { //Return to footer view notify position if (getEmptyViewCount() == 1) { int position = 1; if (mHeadAndEmptyEnable && getHeaderLayoutCount() != 0) { position++; } if (mFootAndEmptyEnable) { return position; } } else { return getHeaderLayoutCount() + mData.size(); } return -1; }
/** * add one new data */ public void addData(T data) { mData.add(data); notifyItemInserted(mData.size() + getHeaderLayoutCount()); }
/** * additional data; * * @param newData */ public void addData(List<T> newData) { this.mData.addAll(newData); notifyItemRangeInserted(mData.size() - newData.size() + getHeaderLayoutCount(), newData.size()); }
@Override public int getSpanSize(int position) { int type = getItemViewType(position); if (mSpanSizeLookup == null) return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type == LOADING_VIEW) ? gridManager.getSpanCount() : 1; else return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type == LOADING_VIEW) ? gridManager.getSpanCount() : mSpanSizeLookup.getSpanSize(gridManager, position - getHeaderLayoutCount()); } });
/** * remove all header view from mHeaderLayout and set null to mHeaderLayout */ public void removeAllHeaderView() { if (getHeaderLayoutCount() == 0) return; mHeaderLayout.removeAllViews(); int position = getHeaderViewPosition(); if (position != -1) { notifyItemRemoved(position); } }
/** * add new data in to certain location * * @param position */ public void addData(int position, List<T> data) { if (isEmpty()) { return; } position = getPosition(position); mData.addAll(position, data); notifyItemRangeInserted(position + getHeaderLayoutCount(), data.size()); }
@Override public int getItemCount() { int count; if (getEmptyViewCount() == 1) { count = 1; if (mHeadAndEmptyEnable && getHeaderLayoutCount() != 0) { count++; } if (mFootAndEmptyEnable && getFooterLayoutCount() != 0) { count++; } } else { count = getHeaderLayoutCount() + mData.size() + getFooterLayoutCount() + getLoadMoreViewCount(); } return count; }
/** * add one new data in to certain location * * @param position */ public void addData(int position, T data) { if (isEmpty()) { return; } position = getPosition(position); mData.add(position, data); notifyItemInserted(position + getHeaderLayoutCount()); }
/** * remove the item associated with the specified position of adapter * * @param position */ public void remove(int position) { if (isEmpty()) { return; } position = getPosition(position); mData.remove(position); notifyItemRemoved(position + getHeaderLayoutCount()); }
/** * insert a item associated with the specified position of adapter * * @param position * @param item */ public void add(int position, T item) { if (isEmpty()) { return; } position = getPosition(position); mData.add(position, item); notifyItemInserted(position + getHeaderLayoutCount()); }
/** * remove header view from mHeaderLayout. * When the child count of mHeaderLayout is 0, mHeaderLayout will be set to null. * * @param header */ public void removeHeaderView(View header) { if (getHeaderLayoutCount() == 0) return; mHeaderLayout.removeView(header); if (mHeaderLayout.getChildCount() == 0) { int position = getHeaderViewPosition(); if (position != -1) { notifyItemRemoved(position); } } }
public void setEmptyView(View emptyView) { boolean insert = false; if (mEmptyLayout == null) { mEmptyLayout = new FrameLayout(emptyView.getContext()); final LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); final ViewGroup.LayoutParams lp = emptyView.getLayoutParams(); if (lp != null) { layoutParams.width = lp.width; layoutParams.height = lp.height; } mEmptyLayout.setLayoutParams(layoutParams); insert = true; } mEmptyLayout.removeAllViews(); mEmptyLayout.addView(emptyView); mIsUseEmpty = true; if (insert) { if (getEmptyViewCount() == 1) { int position = 0; if (mHeadAndEmptyEnable && getHeaderLayoutCount() != 0) { position++; } notifyItemInserted(position); } } }
/** * Refresh complete */ public void loadMoreComplete() { if (getLoadMoreViewCount() == 0) { return; } mLoading = false; mLoadMoreView.setLoadMoreStatus(LoadMoreView.STATUS_DEFAULT); notifyItemChanged(getHeaderLayoutCount() + mData.size() + getFooterLayoutCount()); }
/** * Refresh failed */ public void loadMoreFail() { if (getLoadMoreViewCount() == 0) { return; } mLoading = false; mLoadMoreView.setLoadMoreStatus(LoadMoreView.STATUS_FAIL); notifyItemChanged(getHeaderLayoutCount() + mData.size() + getFooterLayoutCount()); }
@Override public void onClick(View v) { if (mLoadMoreView.getLoadMoreStatus() == LoadMoreView.STATUS_FAIL) { mLoadMoreView.setLoadMoreStatus(LoadMoreView.STATUS_DEFAULT); notifyItemChanged(getHeaderLayoutCount() + mData.size() + getFooterLayoutCount()); } } });
/** * Refresh end, no more data * * @param gone if true gone the load more view */ public void loadMoreEnd(boolean gone) { if (getLoadMoreViewCount() == 0) { return; } mLoading = false; mNextLoadEnable = false; mLoadMoreView.setLoadMoreEndGone(gone); if (gone) { notifyItemRemoved(getHeaderLayoutCount() + mData.size() + getFooterLayoutCount()); } else { mLoadMoreView.setLoadMoreStatus(LoadMoreView.STATUS_END); notifyItemChanged(getHeaderLayoutCount() + mData.size() + getFooterLayoutCount()); } }
convert(holder, mData.get(holder.getLayoutPosition() - getHeaderLayoutCount())); break; case LOADING_VIEW: case TRANS_2_VIEW: default: convert(holder, mData.get(holder.getLayoutPosition() - getHeaderLayoutCount())); break;
/** * Set the enabled state of load more. * * @param enable True if load more is enabled, false otherwise. */ public void setEnableLoadMore(boolean enable) { int oldLoadMoreCount = getLoadMoreViewCount(); mLoadMoreEnable = enable; int newLoadMoreCount = getLoadMoreViewCount(); if (oldLoadMoreCount == 1) { if (newLoadMoreCount == 0) { notifyItemRemoved(getHeaderLayoutCount() + mData.size() + getFooterLayoutCount()); } } else { if (newLoadMoreCount == 1) { mLoadMoreView.setLoadMoreStatus(LoadMoreView.STATUS_DEFAULT); notifyItemInserted(getHeaderLayoutCount() + mData.size() + getFooterLayoutCount()); } } }
/** * Collapse an expandable item that has been expanded.. * * @param position the position of the item, which includes the header layout count. * @param animate collapse with animation or not. * @param notify notify the recyclerView refresh UI or not. * @return the number of subItems collapsed. */ public int collapse(@IntRange(from = 0) int position, boolean animate, boolean notify) { position -= getHeaderLayoutCount(); IExpandable expandable = getExpandableItem(position); if (expandable == null) { return 0; } int subItemCount = recursiveCollapse(position); expandable.setExpanded(false); int parentPos = position + getHeaderLayoutCount(); if (notify) { if (animate) { notifyItemChanged(parentPos); notifyItemRangeRemoved(parentPos + 1, subItemCount); } else { notifyDataSetChanged(); } } return subItemCount; }