From 6530625241604b303e799e5fd87b4585fa8bd108 Mon Sep 17 00:00:00 2001 From: Allen Date: Sun, 19 Jun 2016 22:32:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/base/BaseQuickAdapter.java | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java index ab753e559..9dd34c1d0 100755 --- a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java +++ b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java @@ -383,6 +383,15 @@ public int getItemCount() { return count; } + /** + * Get the type of View that will be created by {@link #getItemView(int, ViewGroup)} for the specified item. + * + * @param position The position of the item within the adapter's data set whose view type we + * want. + * @return An integer representing the type of View. Two views should share the same type if one + * can be converted to the other in {@link #getItemView(int, ViewGroup)}. Note: Integers must be in the + * range 0 to {@link #getItemCount()} - 1. + */ @Override public int getItemViewType(int position) { /** @@ -480,6 +489,12 @@ private BaseViewHolder getLoadingView(ViewGroup parent) { return new BaseViewHolder(mLoadingView); } + /** + * Called when a view created by this adapter has been attached to a window. + * simple to solve item will layout using all + * {@link #setFullSpan(RecyclerView.ViewHolder)} + * @param holder + */ @Override public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { super.onViewAttachedToWindow(holder); @@ -489,6 +504,13 @@ public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { } } + /** + * When set to true, the item will layout using all span area. That means, if orientation + * is vertical, the view will have full width; if orientation is horizontal, the view will + * have full height. + * if the hold view use StaggeredGridLayoutManager they should using all span area + * @param holder True if this item should traverse all spans. + */ protected void setFullSpan(RecyclerView.ViewHolder holder) { if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) { StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams(); @@ -496,6 +518,12 @@ protected void setFullSpan(RecyclerView.ViewHolder holder) { } } + /** + * To bind different types of holder and solve different the bind events + * @see #getDefItemViewType(int) + * @param holder + * @param positions + */ @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, int positions) { @@ -532,12 +560,18 @@ protected BaseViewHolder createBaseViewHolder(ViewGroup parent, int layoutResId) return new BaseViewHolder(mContentView); } - + /** + * easy to show a simple headView + * @param header + */ public void addHeaderView(View header) { this.mHeaderView = header; this.notifyDataSetChanged(); } - + /** + * easy to show a simple footerView + * @param footer + */ public void addFooterView(View footer) { mNextLoadEnable = false; this.mFooterView = footer; @@ -551,6 +585,11 @@ public void setEmptyView(View emptyView) { setEmptyView(false, false, emptyView); } + /** + * + * @param isHeadAndEmpty false will not show headView if the data is empty true will show emptyView and headView + * @param emptyView + */ public void setEmptyView(boolean isHeadAndEmpty, View emptyView) { setEmptyView(isHeadAndEmpty, false, emptyView); } @@ -593,6 +632,11 @@ public void isNextLoad(boolean isNextLoad) { } + /** + * @param isNextLoad true + * if true when loading more data can show loadingView + + */ public void notifyDataChangedAfterLoadMore(boolean isNextLoad) { mNextLoadEnable = isNextLoad; mLoadingMoreEnable = false; @@ -600,6 +644,11 @@ public void notifyDataChangedAfterLoadMore(boolean isNextLoad) { } + /** + * add more data + * @param data + * @param isNextLoad + */ public void notifyDataChangedAfterLoadMore(List data, boolean isNextLoad) { mData.addAll(data); notifyDataChangedAfterLoadMore(isNextLoad); @@ -614,6 +663,10 @@ private void addLoadMore(RecyclerView.ViewHolder holder) { } } + /** + * init the baseViewHolder to register onRecyclerViewItemClickListener and onRecyclerViewItemLongClickListener + * @param baseViewHolder + */ private void initItemClickListener(final BaseViewHolder baseViewHolder) { if (onRecyclerViewItemClickListener != null) { baseViewHolder.itemView.setOnClickListener(new View.OnClickListener() { @@ -633,6 +686,10 @@ public boolean onLongClick(View v) { } } + /** + * add animation when you want to show time + * @param holder + */ private void addAnimation(RecyclerView.ViewHolder holder) { if (mOpenAnimationEnable) { if (!mFirstOnlyEnable || holder.getLayoutPosition() > mLastPosition) { @@ -651,7 +708,7 @@ private void addAnimation(RecyclerView.ViewHolder holder) { } /** - * + * set anim to start when loading * @param anim * @param index */ From a8d978d9067569dc36ffce75cac5efa700d3b0d6 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Mon, 20 Jun 2016 14:23:48 +0800 Subject: [PATCH 2/2] update README.md --- README-cn.md | 4 ++-- README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README-cn.md b/README-cn.md index c3eff27fc..a10ea2a6c 100644 --- a/README-cn.md +++ b/README-cn.md @@ -44,8 +44,8 @@ ![demo](http://upload-images.jianshu.io/upload_images/972352-54bd17d3680a4cf9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ``` public class QuickAdapter extends BaseQuickAdapter { - public QuickAdapter(Context context) { - super(context, R.layout.tweet, DataServer.getSampleData()); + public QuickAdapter() { + super(R.layout.tweet, DataServer.getSampleData()); } @Override diff --git a/README.md b/README.md index 27fba8b69..52b733071 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ dependencies { ```java public class QuickAdapter extends BaseQuickAdapter { - public QuickAdapter(Context context) { - super(context, R.layout.tweet, DataServer.getSampleData()); + public QuickAdapter() { + super(R.layout.tweet, DataServer.getSampleData()); } @Override