From 09e39477278fd6880653598aee9041d9d190bd7e Mon Sep 17 00:00:00 2001 From: yuzhuo Date: Mon, 19 Sep 2016 19:09:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=BC=96=E8=AF=91=E8=BF=87?= =?UTF-8?q?=E4=BA=86=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base-adapter-library/base-adapter-library.iml | 26 +- base-adapter-library/build.gradle | 4 +- baseadapter-recyclerview/build.gradle | 4 +- .../recyclerview/wrapper/LoadmoreWrapper.java | 324 +++++++++--------- build.gradle | 2 +- sample/build.gradle | 6 +- sample/sample.iml | 28 +- 7 files changed, 208 insertions(+), 186 deletions(-) diff --git a/base-adapter-library/base-adapter-library.iml b/base-adapter-library/base-adapter-library.iml index 60006e3..758c081 100644 --- a/base-adapter-library/base-adapter-library.iml +++ b/base-adapter-library/base-adapter-library.iml @@ -65,14 +65,6 @@ - - - - - - - - @@ -81,14 +73,22 @@ + + + + + + + + - - + + @@ -103,8 +103,8 @@ - - - + + + \ No newline at end of file diff --git a/base-adapter-library/build.gradle b/base-adapter-library/build.gradle index 275ee00..a523f0c 100644 --- a/base-adapter-library/build.gradle +++ b/base-adapter-library/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.library' android { compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion "24.0.0" defaultConfig { minSdkVersion 10 @@ -21,7 +21,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:recyclerview-v7:23.2.0' + compile 'com.android.support:recyclerview-v7:23.2.1' } diff --git a/baseadapter-recyclerview/build.gradle b/baseadapter-recyclerview/build.gradle index a557009..0e4e90e 100644 --- a/baseadapter-recyclerview/build.gradle +++ b/baseadapter-recyclerview/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.novoda.bintray-release' android { compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion "24.0.0" defaultConfig { minSdkVersion 10 @@ -21,7 +21,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile 'com.android.support:recyclerview-v7:23.4.0' + compile 'com.android.support:recyclerview-v7:23.2.1' } publish { diff --git a/baseadapter-recyclerview/src/main/java/com/zhy/adapter/recyclerview/wrapper/LoadmoreWrapper.java b/baseadapter-recyclerview/src/main/java/com/zhy/adapter/recyclerview/wrapper/LoadmoreWrapper.java index 894b8d7..0fea2f8 100644 --- a/baseadapter-recyclerview/src/main/java/com/zhy/adapter/recyclerview/wrapper/LoadmoreWrapper.java +++ b/baseadapter-recyclerview/src/main/java/com/zhy/adapter/recyclerview/wrapper/LoadmoreWrapper.java @@ -1,162 +1,162 @@ -package com.zhy.adapter.recyclerview.wrapper; - -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.StaggeredGridLayoutManager; -import android.view.View; -import android.view.ViewGroup; - -import com.zhy.adapter.recyclerview.base.ViewHolder; -import com.zhy.adapter.recyclerview.utils.WrapperUtils; - - -/** - * Created by zhy on 16/6/23. - */ -public class LoadMoreWrapper extends RecyclerView.Adapter -{ - public static final int ITEM_TYPE_LOAD_MORE = Integer.MAX_VALUE - 2; - - private RecyclerView.Adapter mInnerAdapter; - private View mLoadMoreView; - private int mLoadMoreLayoutId; - - public LoadMoreWrapper(RecyclerView.Adapter adapter) - { - mInnerAdapter = adapter; - } - - private boolean hasLoadMore() - { - return mLoadMoreView != null || mLoadMoreLayoutId != 0; - } - - - private boolean isShowLoadMore(int position) - { - return hasLoadMore() && (position >= mInnerAdapter.getItemCount()); - } - - @Override - public int getItemViewType(int position) - { - if (isShowLoadMore(position)) - { - return ITEM_TYPE_LOAD_MORE; - } - return mInnerAdapter.getItemViewType(position); - } - - @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) - { - if (viewType == ITEM_TYPE_LOAD_MORE) - { - ViewHolder holder; - if (mLoadMoreView != null) - { - holder = ViewHolder.createViewHolder(parent.getContext(), mLoadMoreView); - } else - { - holder = ViewHolder.createViewHolder(parent.getContext(), parent, mLoadMoreLayoutId); - } - return holder; - } - return mInnerAdapter.onCreateViewHolder(parent, viewType); - } - - @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) - { - if (isShowLoadMore(position)) - { - if (mOnLoadMoreListener != null) - { - mOnLoadMoreListener.onLoadMoreRequested(); - } - return; - } - mInnerAdapter.onBindViewHolder(holder, position); - } - - @Override - public void onAttachedToRecyclerView(RecyclerView recyclerView) - { - WrapperUtils.onAttachedToRecyclerView(mInnerAdapter, recyclerView, new WrapperUtils.SpanSizeCallback() - { - @Override - public int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position) - { - if (isShowLoadMore(position)) - { - return layoutManager.getSpanCount(); - } - if (oldLookup != null) - { - return oldLookup.getSpanSize(position); - } - return 1; - } - }); - } - - - @Override - public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) - { - mInnerAdapter.onViewAttachedToWindow(holder); - - if (isShowLoadMore(holder.getLayoutPosition())) - { - setFullSpan(holder); - } - } - - private void setFullSpan(RecyclerView.ViewHolder holder) - { - ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); - - if (lp != null - && lp instanceof StaggeredGridLayoutManager.LayoutParams) - { - StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; - - p.setFullSpan(true); - } - } - - @Override - public int getItemCount() - { - return mInnerAdapter.getItemCount() + (hasLoadMore() ? 1 : 0); - } - - - public interface OnLoadMoreListener - { - void onLoadMoreRequested(); - } - - private OnLoadMoreListener mOnLoadMoreListener; - - public LoadMoreWrapper setOnLoadMoreListener(OnLoadMoreListener loadMoreListener) - { - if (loadMoreListener != null) - { - mOnLoadMoreListener = loadMoreListener; - } - return this; - } - - public LoadMoreWrapper setLoadMoreView(View loadMoreView) - { - mLoadMoreView = loadMoreView; - return this; - } - - public LoadMoreWrapper setLoadMoreView(int layoutId) - { - mLoadMoreLayoutId = layoutId; - return this; - } -} +package com.zhy.adapter.recyclerview.wrapper; + +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.StaggeredGridLayoutManager; +import android.view.View; +import android.view.ViewGroup; + +import com.zhy.adapter.recyclerview.base.ViewHolder; +import com.zhy.adapter.recyclerview.utils.WrapperUtils; + + +/** + * Created by zhy on 16/6/23. + */ +public class LoadMoreWrapper extends RecyclerView.Adapter +{ + public static final int ITEM_TYPE_LOAD_MORE = Integer.MAX_VALUE - 2; + + private RecyclerView.Adapter mInnerAdapter; + private View mLoadMoreView; + private int mLoadMoreLayoutId; + + public LoadMoreWrapper(RecyclerView.Adapter adapter) + { + mInnerAdapter = adapter; + } + + private boolean hasLoadMore() + { + return mLoadMoreView != null || mLoadMoreLayoutId != 0; + } + + + private boolean isShowLoadMore(int position) + { + return hasLoadMore() && (position >= mInnerAdapter.getItemCount()); + } + + @Override + public int getItemViewType(int position) + { + if (isShowLoadMore(position)) + { + return ITEM_TYPE_LOAD_MORE; + } + return mInnerAdapter.getItemViewType(position); + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) + { + if (viewType == ITEM_TYPE_LOAD_MORE) + { + ViewHolder holder; + if (mLoadMoreView != null) + { + holder = ViewHolder.createViewHolder(parent.getContext(), mLoadMoreView); + } else + { + holder = ViewHolder.createViewHolder(parent.getContext(), parent, mLoadMoreLayoutId); + } + return holder; + } + return mInnerAdapter.onCreateViewHolder(parent, viewType); + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) + { + if (isShowLoadMore(position)) + { + if (mOnLoadMoreListener != null) + { + mOnLoadMoreListener.onLoadMoreRequested(); + } + return; + } + mInnerAdapter.onBindViewHolder(holder, position); + } + + @Override + public void onAttachedToRecyclerView(RecyclerView recyclerView) + { + WrapperUtils.onAttachedToRecyclerView(mInnerAdapter, recyclerView, new WrapperUtils.SpanSizeCallback() + { + @Override + public int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position) + { + if (isShowLoadMore(position)) + { + return layoutManager.getSpanCount(); + } + if (oldLookup != null) + { + return oldLookup.getSpanSize(position); + } + return 1; + } + }); + } + + + @Override + public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) + { + mInnerAdapter.onViewAttachedToWindow(holder); + + if (isShowLoadMore(holder.getLayoutPosition())) + { + setFullSpan(holder); + } + } + + private void setFullSpan(RecyclerView.ViewHolder holder) + { + ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); + + if (lp != null + && lp instanceof StaggeredGridLayoutManager.LayoutParams) + { + StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; + + p.setFullSpan(true); + } + } + + @Override + public int getItemCount() + { + return mInnerAdapter.getItemCount() + (hasLoadMore() ? 1 : 0); + } + + + public interface OnLoadMoreListener + { + void onLoadMoreRequested(); + } + + private OnLoadMoreListener mOnLoadMoreListener; + + public LoadMoreWrapper setOnLoadMoreListener(OnLoadMoreListener loadMoreListener) + { + if (loadMoreListener != null) + { + mOnLoadMoreListener = loadMoreListener; + } + return this; + } + + public LoadMoreWrapper setLoadMoreView(View loadMoreView) + { + mLoadMoreView = loadMoreView; + return this; + } + + public LoadMoreWrapper setLoadMoreView(int layoutId) + { + mLoadMoreLayoutId = layoutId; + return this; + } +} diff --git a/build.gradle b/build.gradle index bf69489..9ceaa1f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.android.tools.build:gradle:2.1.2' classpath 'com.novoda:bintray-release:0.3.4' // NOTE: Do not place your application dependencies here; they belong diff --git a/sample/build.gradle b/sample/build.gradle index fef61a8..36ef518 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -2,11 +2,11 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion "24.0.0" defaultConfig { applicationId "com.zhy.sample" - minSdkVersion 10 + minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" @@ -22,7 +22,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.4.0' - compile 'com.android.support:recyclerview-v7:23.4.0' + compile 'com.android.support:recyclerview-v7:23.2.1' // compile 'com.zhy:base-adapter:3.0.2' // compile 'com.zhy:base-rvadapter:3.0.2' compile project(':base-adapter-library') diff --git a/sample/sample.iml b/sample/sample.iml index 3e7e715..63e1a86 100644 --- a/sample/sample.iml +++ b/sample/sample.iml @@ -80,20 +80,42 @@ + + + + + + + + + + + + + + + + + + + + + + - + - - + +