Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadCym committed May 5, 2016
1 parent a53b95a commit 7ad4b3d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* https://github.com/CymChad/BaseRecyclerViewAdapterHelper
*/
public abstract class BaseMultiItemQuickAdapter<T extends MultiItemEntity> extends BaseQuickAdapter {
protected List<T> mData;
private SparseArray<Integer> layouts;

/**
Expand All @@ -32,7 +31,7 @@ public BaseMultiItemQuickAdapter(Context context, List<T> data) {

@Override
protected int getDefItemViewType(int position) {
return mData.get(position).getItemType();
return ((MultiItemEntity)mData.get(position)).getItemType();
}


Expand All @@ -54,6 +53,8 @@ protected void addItmeType(int type, int layoutResId) {
layouts.put(type, layoutResId);
}



@Override
protected void convert(BaseViewHolder helper, Object item) {
convert(helper, (T) item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public abstract class BaseQuickAdapter<T> extends RecyclerView.Adapter<RecyclerV

protected int mLayoutResId;

protected LayoutInflater mLayoutInflater;

protected List<T> mData;

private Interpolator mInterpolator = new LinearInterpolator();
Expand Down Expand Up @@ -198,6 +200,7 @@ public void onClick(View v) {
public BaseQuickAdapter(Context context, int layoutResId, List<T> data) {
this.mData = data == null ? new ArrayList<T>() : new ArrayList<T>(data);
this.mContext = context;
this.mLayoutInflater = LayoutInflater.from(context);
if (layoutResId != 0) {
this.mLayoutResId = layoutResId;
}
Expand Down Expand Up @@ -417,22 +420,22 @@ public void notifyDataChangedAfterLoadMore(boolean isNextLoad) {


@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int positions) {

if (holder instanceof ContentViewHolder) {
int index = position - getHeaderViewsCount();
int index = holder.getLayoutPosition() - getHeaderViewsCount();
BaseViewHolder baseViewHolder = (BaseViewHolder) holder;
convert(baseViewHolder, mData.get(index));
if (onRecyclerViewItemClickListener != null) {
baseViewHolder.convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onRecyclerViewItemClickListener.onItemClick(v, position - getHeaderViewsCount());
onRecyclerViewItemClickListener.onItemClick(v, holder.getLayoutPosition() - getHeaderViewsCount());
}
});
}
if (mOpenAnimationEnable) {
if (!mFirstOnlyEnable || position > mLastPosition) {
if (!mFirstOnlyEnable || holder.getLayoutPosition() > mLastPosition) {
BaseAnimation animation = null;
if (mCustomAnimation != null) {
animation = mCustomAnimation;
Expand All @@ -443,7 +446,7 @@ public void onClick(View v) {
anim.setDuration(mDuration).start();
anim.setInterpolator(mInterpolator);
}
mLastPosition = position;
mLastPosition = holder.getLayoutPosition();
}
}
} else if (holder instanceof FooterViewHolder) {
Expand All @@ -461,7 +464,7 @@ public void onClick(View v) {
} else if (holder instanceof EmptyViewHolder) {

} else {
int index = position - getHeaderViewsCount();
int index = holder.getLayoutPosition() - getHeaderViewsCount();
BaseViewHolder baseViewHolder = (BaseViewHolder) holder;
onBindDefViewHolder(baseViewHolder, mData.get(index));
}
Expand All @@ -472,8 +475,7 @@ private boolean isLoadMore() {
}

protected View getItemView(int layoutResId, ViewGroup parent) {
return LayoutInflater.from(parent.getContext()).inflate(
layoutResId, parent, false);
return mLayoutInflater.inflate(layoutResId, parent, false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public abstract class BaseSectionQuickAdapter<T extends SectionEntity> extends B


protected int mSectionHeadResId;
protected List<T> mData;
protected static final int SECTION_HEADER_VIEW = 0x00000444;

/**
Expand All @@ -39,7 +38,7 @@ public BaseSectionQuickAdapter(Context context, int layoutResId, int sectionHead

@Override
protected int getDefItemViewType(int position) {
return mData.get(position).isHeader ? SECTION_HEADER_VIEW : 0;
return ((SectionEntity)mData.get(position)).isHeader ? SECTION_HEADER_VIEW : 0;
}

@Override
Expand Down Expand Up @@ -69,6 +68,7 @@ protected void onBindDefViewHolder(BaseViewHolder holder, Object item) {
}
}


@Override
protected void convert(BaseViewHolder helper, Object item) {
convert(helper, (T) item);
Expand Down

0 comments on commit 7ad4b3d

Please sign in to comment.