Skip to content

Commit

Permalink
Merge pull request #1076 from FrankKwok/master
Browse files Browse the repository at this point in the history
remove redundant convertView and add annotations
  • Loading branch information
CymChad authored Apr 28, 2017
2 parents babb09e + 9930dff commit b33fac7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public MovieViewHolder(View view) {
}

public ViewDataBinding getBinding() {
return (ViewDataBinding) getConvertView().getTag(R.id.BaseQuickAdapter_databinding_support);
return (ViewDataBinding) itemView.getTag(R.id.BaseQuickAdapter_databinding_support);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void convert(final BaseViewHolder helper, final ClickEntity item) {
case ClickEntity.NEST_CLICK_ITEM_CHILD_VIEW:
helper.setNestView(R.id.item_click); // u can set nestview id
final RecyclerView recyclerView = helper.getView(R.id.nest_list);
recyclerView.setLayoutManager(new LinearLayoutManager(helper.getConvertView().getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setLayoutManager(new LinearLayoutManager(helper.itemView.getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setHasFixedSize(true);

nestAdapter = new NestAdapter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.animation.Animator;
import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.IntDef;
import android.support.annotation.IntRange;
import android.support.annotation.LayoutRes;
Expand Down Expand Up @@ -471,7 +472,7 @@ public void setData(@IntRange(from = 0) int index, @NonNull T data) {
*
* @param position
*/
public void addData(@IntRange(from = 0) int position, @Nullable List<T> data) {
public void addData(@IntRange(from = 0) int position, @NonNull List<T> data) {
mData.addAll(position, data);
notifyItemRangeInserted(position + getHeaderLayoutCount(), data.size());
compatibilityDataSizeChanged(data.size());
Expand All @@ -482,7 +483,7 @@ public void addData(@IntRange(from = 0) int position, @Nullable List<T> data) {
*
* @param newData
*/
public void addData(@Nullable List<T> newData) {
public void addData(@NonNull List<T> newData) {
this.mData.addAll(newData);
notifyItemRangeInserted(mData.size() - newData.size() + getHeaderLayoutCount(), newData.size());
compatibilityDataSizeChanged(newData.size());
Expand Down Expand Up @@ -517,8 +518,9 @@ public List<T> getData() {
* data set.
* @return The data at the specified position.
*/
@Nullable
public T getItem(@IntRange(from = 0) int position) {
if (position != -1)
if (position < mData.size())
return mData.get(position);
else
return null;
Expand Down Expand Up @@ -829,14 +831,14 @@ private void bindViewClickListener(final BaseViewHolder baseViewHolder) {
if (baseViewHolder == null) {
return;
}
final View view = baseViewHolder.getConvertView();
final View view = baseViewHolder.itemView;
if (view == null) {
return;
}
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getOnItemClickListener() != null && baseViewHolder != null) {
if (getOnItemClickListener() != null) {

getOnItemClickListener().onItemClick(BaseQuickAdapter.this, v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
}
Expand All @@ -846,11 +848,8 @@ public void onClick(View v) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (getOnItemLongClickListener() != null && baseViewHolder != null) {
return getOnItemLongClickListener().onItemLongClick(BaseQuickAdapter.this, v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
}
return false;

return getOnItemLongClickListener() != null &&
getOnItemLongClickListener().onItemLongClick(BaseQuickAdapter.this, v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
}
});
}
Expand Down Expand Up @@ -884,6 +883,7 @@ protected K createBaseViewHolder(ViewGroup parent, int layoutResId) {
* @param view view
* @return new ViewHolder
*/
@SuppressWarnings("unchecked")
protected K createBaseViewHolder(View view) {
Class temp = getClass();
Class z = null;
Expand All @@ -902,6 +902,7 @@ protected K createBaseViewHolder(View view) {
* @param view
* @return
*/
@SuppressWarnings("unchecked")
private K createGenericKInstance(Class z, View view) {
try {
Constructor constructor;
Expand Down Expand Up @@ -1349,7 +1350,7 @@ protected void startAnim(Animator anim, int index) {
* hierarchy
* @return view will be return
*/
protected View getItemView(int layoutResId, ViewGroup parent) {
protected View getItemView(@LayoutRes int layoutResId, ViewGroup parent) {
return mLayoutInflater.inflate(layoutResId, parent, false);
}

Expand Down Expand Up @@ -1432,12 +1433,12 @@ public void isFirstOnly(boolean firstOnly) {
*
* @see #bindToRecyclerView(RecyclerView)
*/
public View getViewByPosition(int position, int viewId) {
public View getViewByPosition(int position, @IdRes int viewId) {
checkNotNull();
return getViewByPosition(getRecyclerView(), position, viewId);
}

public View getViewByPosition(RecyclerView recyclerView, int position, int viewId) {
public View getViewByPosition(RecyclerView recyclerView, int position, @IdRes int viewId) {
if (recyclerView == null) {
return null;
}
Expand All @@ -1459,6 +1460,7 @@ public long getItemId(int position) {
return position;
}

@SuppressWarnings("unchecked")
private int recursiveExpand(int position, @NonNull List list) {
int count = 0;
int pos = position + list.size() - 1;
Expand Down Expand Up @@ -1486,6 +1488,7 @@ private int recursiveExpand(int position, @NonNull List list) {
* yourself.
* @return the number of items that have been added.
*/
@SuppressWarnings("unchecked")
public int expand(@IntRange(from = 0) int position, boolean animate, boolean shouldNotify) {
position -= getHeaderLayoutCount();

Expand Down Expand Up @@ -1592,6 +1595,7 @@ public void expandAll() {
}
}

@SuppressWarnings("unchecked")
private int recursiveCollapse(@IntRange(from = 0) int position) {
T item = getItem(position);
if (!isExpandable(item)) {
Expand Down
Loading

0 comments on commit b33fac7

Please sign in to comment.