Skip to content

Commit

Permalink
Merge pull request #1405 from FrankKwok/master
Browse files Browse the repository at this point in the history
fix #1402
  • Loading branch information
CymChad authored Aug 8, 2017
2 parents 00095c3 + dd6229b commit d976640
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public ExpandableItemAdapter(List<MultiItemEntity> data) {
}



@Override
protected void convert(final BaseViewHolder holder, final MultiItemEntity item) {
switch (holder.getItemViewType()) {
Expand All @@ -54,7 +53,7 @@ protected void convert(final BaseViewHolder holder, final MultiItemEntity item)
holder.setImageResource(R.id.iv_head, R.mipmap.head_img2);
break;
}
final Level0Item lv0 = (Level0Item)item;
final Level0Item lv0 = (Level0Item) item;
holder.setText(R.id.title, lv0.title)
.setText(R.id.sub_title, lv0.subTitle)
.setImageResource(R.id.iv, lv0.isExpanded() ? R.mipmap.arrow_b : R.mipmap.arrow_r);
Expand All @@ -69,14 +68,14 @@ public void onClick(View v) {
// if (pos % 3 == 0) {
// expandAll(pos, false);
// } else {
expand(pos);
expand(pos);
// }
}
}
});
break;
case TYPE_LEVEL_1:
final Level1Item lv1 = (Level1Item)item;
final Level1Item lv1 = (Level1Item) item;
holder.setText(R.id.title, lv1.title)
.setText(R.id.sub_title, lv1.subTitle)
.setImageResource(R.id.iv, lv1.isExpanded() ? R.mipmap.arrow_b : R.mipmap.arrow_r);
Expand All @@ -94,15 +93,17 @@ public void onClick(View v) {
});
break;
case TYPE_PERSON:
final Person person = (Person)item;
final Person person = (Person) item;
holder.setText(R.id.tv, person.name + " parent pos: " + getParentPosition(person));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int cp = getParentPosition(person);
((Level1Item)getData().get(cp)).removeSubItem(person);
getData().remove(holder.getLayoutPosition());
notifyItemRemoved(holder.getLayoutPosition());
if (cp != -1) {
((Level1Item) getData().get(cp)).removeSubItem(person);
getData().remove(holder.getLayoutPosition());
notifyItemRemoved(holder.getLayoutPosition());
}
}
});
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public void setNotDoAnimationCount(int count) {
/**
* Set custom load more
*
* @param loadingView
* @param loadingView 加载视图
*/
public void setLoadMoreView(LoadMoreView loadingView) {
this.mLoadMoreView = loadingView;
Expand Down Expand Up @@ -568,8 +568,11 @@ public void addData(@NonNull Collection<? extends T> newData) {
* @param data data collection
*/
public void replaceData(@NonNull Collection<? extends T> data) {
mData.clear();
mData.addAll(data);
// 不是同一个引用才清空列表
if (data != mData) {
mData.clear();
mData.addAll(data);
}
notifyDataSetChanged();
}

Expand All @@ -588,7 +591,7 @@ private void compatibilityDataSizeChanged(int size) {
/**
* Get the data of list
*
* @return
* @return 列表数据
*/
@NonNull
public List<T> getData() {
Expand Down Expand Up @@ -1713,7 +1716,7 @@ public int expandAll(int position, boolean init) {
}

public void expandAll() {
for (int i = mData.size() - 1; i >= 0 + getHeaderLayoutCount(); i--) {
for (int i = mData.size() - 1; i >= getHeaderLayoutCount(); i--) {
expandAll(i, false, false);
}
}
Expand Down

0 comments on commit d976640

Please sign in to comment.