Skip to content

Commit

Permalink
Merge pull request #609 from 1109993488/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
CymChad authored Dec 8, 2016
2 parents 51f8a91 + bc2f3a1 commit f9a8ea5
Showing 1 changed file with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public abstract class BaseQuickAdapter<T, K extends BaseViewHolder> extends Recy
private LinearLayout mHeaderLayout;
private LinearLayout mFooterLayout;
//empty
private FrameLayout mEmptyView;
private FrameLayout mEmptyLayout;
private boolean mIsUseEmpty = true;
private boolean mHeadAndEmptyEnable;
private boolean mFootAndEmptyEnable;
Expand Down Expand Up @@ -311,12 +311,8 @@ public void setNewData(List<T> data) {
* @param position
*/
public void addData(int position, T data) {
if (0 <= position && position < mData.size()) {
mData.add(position, data);
notifyItemInserted(position + getHeaderLayoutCount());
} else {
throw new ArrayIndexOutOfBoundsException("inserted position most greater than 0 and less than data size");
}
mData.add(position, data);
notifyItemInserted(position + getHeaderLayoutCount());
}

/**
Expand All @@ -333,12 +329,8 @@ public void addData(T data) {
* @param position
*/
public void addData(int position, List<T> data) {
if (0 <= position && position < mData.size()) {
mData.addAll(position, data);
notifyItemRangeInserted(position + getHeaderLayoutCount(), data.size());
} else {
throw new ArrayIndexOutOfBoundsException("inserted position most greater than 0 and less than data size");
}
mData.addAll(position, data);
notifyItemRangeInserted(position + getHeaderLayoutCount(), data.size());
}

/**
Expand Down Expand Up @@ -414,12 +406,12 @@ public int getFooterLayoutCount() {
}

/**
* if mEmptyView will be return 1 or not will be return 0
* if show empty view will be return 1 or not will be return 0
*
* @return
*/
public int getEmptyViewCount() {
if (mEmptyView == null || mEmptyView.getChildCount() == 0) {
if (mEmptyLayout == null || mEmptyLayout.getChildCount() == 0) {
return 0;
}
if(!mIsUseEmpty){
Expand Down Expand Up @@ -507,7 +499,7 @@ public K onCreateViewHolder(ViewGroup parent, int viewType) {
baseViewHolder = createBaseViewHolder(mHeaderLayout);
break;
case EMPTY_VIEW:
baseViewHolder = createBaseViewHolder(mEmptyView);
baseViewHolder = createBaseViewHolder(mEmptyLayout);
break;
case FOOTER_VIEW:
baseViewHolder = createBaseViewHolder(mFooterLayout);
Expand Down Expand Up @@ -839,13 +831,19 @@ private int getFooterViewPosition() {

public void setEmptyView(View emptyView) {
boolean insert = false;
if (mEmptyView == null) {
mEmptyView = new FrameLayout(emptyView.getContext());
mEmptyView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
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;
}
mEmptyView.removeAllViews();
mEmptyView.addView(emptyView);
mEmptyLayout.removeAllViews();
mEmptyLayout.addView(emptyView);
mIsUseEmpty = true;
if (insert) {
if (getEmptyViewCount() == 1) {
Expand Down Expand Up @@ -894,7 +892,7 @@ public void isUseEmpty(boolean isUseEmpty) {
* @return The view to show if the adapter is empty.
*/
public View getEmptyView() {
return mEmptyView;
return mEmptyLayout;
}

private int mAutoLoadMoreSize = 1;
Expand Down

0 comments on commit f9a8ea5

Please sign in to comment.