diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index d5e8084..7e8ad69 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/modules.xml b/.idea/modules.xml
index dbf27ef..7dea083 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -4,7 +4,6 @@
-
diff --git a/RefreshRecyclerView/build.gradle b/RefreshRecyclerView/build.gradle
index 131020c..a3a8d7f 100644
--- a/RefreshRecyclerView/build.gradle
+++ b/RefreshRecyclerView/build.gradle
@@ -1,14 +1,14 @@
apply plugin: 'com.android.library'
android {
- compileSdkVersion 26
+ compileSdkVersion 25
buildToolsVersion '27.0.3'
defaultConfig {
- minSdkVersion 16
- targetSdkVersion 26
- versionCode 5
- versionName "1.2.0"
+ minSdkVersion 15
+ targetSdkVersion 25
+ versionCode 6
+ versionName "1.3.0"
}
buildTypes {
release {
@@ -19,7 +19,7 @@ android {
}
dependencies {
- implementation 'com.android.support:recyclerview-v7:26+'
+ implementation 'com.android.support:recyclerview-v7:25.0.0'
}
ext {
@@ -28,7 +28,7 @@ ext {
publishedGroupId = 'cn.lemon'
artifact = 'RefreshRecyclerView'
- libraryVersion = '1.2.0'
+ libraryVersion = '1.4.1'
siteUrl = 'https://github.com/llxdaxia/RefreshRecyclerView'
gitUrl = 'https://github.com/llxdaxia/RefreshRecyclerView.git'
diff --git a/RefreshRecyclerView/src/main/java/cn/lemon/view/RefreshRecyclerView.java b/RefreshRecyclerView/src/main/java/cn/lemon/view/RefreshRecyclerView.java
index 3729514..70e3ad7 100644
--- a/RefreshRecyclerView/src/main/java/cn/lemon/view/RefreshRecyclerView.java
+++ b/RefreshRecyclerView/src/main/java/cn/lemon/view/RefreshRecyclerView.java
@@ -12,7 +12,8 @@ import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
-
+import java.util.ArrayList;
+import java.util.List;
import cn.lemon.view.adapter.Action;
import cn.lemon.view.adapter.RecyclerAdapter;
@@ -20,13 +21,15 @@ import cn.lemon.view.adapter.RecyclerAdapter;
/**
* Created by linlongxin on 2016/1/24.
*/
-public class RefreshRecyclerView extends FrameLayout {
+public class RefreshRecyclerView extends FrameLayout implements SwipeRefreshLayout.OnRefreshListener{
private final String TAG = "RefreshRecyclerView";
private SwipeRefreshLayout mSwipeRefreshLayout;
private RecyclerView mRecyclerView;
private RecyclerAdapter mAdapter;
- private boolean loadMoreAble;
+ private List mRefreshActions;
+ private boolean mLoadMoreEnable;
+ private boolean mShowNoMoreEnable;
public RefreshRecyclerView(Context context) {
this(context, null);
@@ -39,20 +42,29 @@ public class RefreshRecyclerView extends FrameLayout {
public RefreshRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
View view = inflate(context, R.layout.view_refresh_recycler, this);
- mRecyclerView = view.findViewById(cn.lemon.view.R.id.recycler_view);
- mSwipeRefreshLayout = view.findViewById(R.id.refresh_layout);
+ mRecyclerView = (RecyclerView) view.findViewById(R.id.lemon_recycler_view);
+ mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.lemon_refresh_layout);
+
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RefreshRecyclerView);
- boolean refreshAble = typedArray.getBoolean(R.styleable.RefreshRecyclerView_refresh_able, true);
- loadMoreAble = typedArray.getBoolean(R.styleable.RefreshRecyclerView_load_more_able, true);
- if (!refreshAble) {
+ mLoadMoreEnable = typedArray.getBoolean(R.styleable.RefreshRecyclerView_load_more_enable, true);
+ mShowNoMoreEnable = typedArray.getBoolean(R.styleable.RefreshRecyclerView_show_no_more_enable, true);
+ boolean refreshEnable = typedArray.getBoolean(R.styleable.RefreshRecyclerView_refresh_enable, true);
+ if (!refreshEnable) {
mSwipeRefreshLayout.setEnabled(false);
+ } else {
+ mSwipeRefreshLayout.setOnRefreshListener(this);
}
+ typedArray.recycle();
}
public void setAdapter(RecyclerAdapter adapter) {
+ if (adapter == null) {
+ return;
+ }
mRecyclerView.setAdapter(adapter);
mAdapter = adapter;
- mAdapter.loadMoreAble = loadMoreAble;
+ mAdapter.setLoadMoreEnable(mLoadMoreEnable);
+ mAdapter.setShowNoMoreEnable(mShowNoMoreEnable);
}
public void setLayoutManager(final RecyclerView.LayoutManager layoutManager) {
@@ -74,24 +86,32 @@ public class RefreshRecyclerView extends FrameLayout {
}
}
- public void setRefreshAction(final Action action) {
- mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override
- public void onRefresh() {
- action.onAction();
- }
- });
+ public void addRefreshAction(final Action action) {
+ if (action == null) {
+ return;
+ }
+ if (mRefreshActions == null) {
+ mRefreshActions = new ArrayList<>();
+ }
+ mRefreshActions.add(action);
}
public void setLoadMoreAction(final Action action) {
Log.d(TAG, "setLoadMoreAction");
- if (mAdapter.isShowNoMore || !loadMoreAble) {
+ if (mAdapter.isShowNoMoring() || !mLoadMoreEnable) {
return;
}
- mAdapter.loadMoreAble = true;
mAdapter.setLoadMoreAction(action);
}
+ public void setLoadMoreErrorAction(final Action action) {
+ Log.d(TAG, "setLoadMoreErrorAction");
+ if (mAdapter.isShowNoMoring() || !mLoadMoreEnable) {
+ return;
+ }
+ mAdapter.setLoadMoreErrorAction(action);
+ }
+
public void showNoMore() {
mAdapter.showNoMore();
}
@@ -112,10 +132,6 @@ public class RefreshRecyclerView extends FrameLayout {
return mSwipeRefreshLayout;
}
- public TextView getNoMoreView() {
- return mAdapter.mNoMoreView;
- }
-
public void setSwipeRefreshColorsFromRes(@ColorRes int... colors) {
mSwipeRefreshLayout.setColorSchemeResources(colors);
}
@@ -134,4 +150,11 @@ public class RefreshRecyclerView extends FrameLayout {
public void dismissSwipeRefresh() {
mSwipeRefreshLayout.setRefreshing(false);
}
+
+ @Override
+ public void onRefresh() {
+ for (Action a : mRefreshActions) {
+ a.onAction();
+ }
+ }
}
diff --git a/RefreshRecyclerView/src/main/java/cn/lemon/view/adapter/BaseViewHolder.java b/RefreshRecyclerView/src/main/java/cn/lemon/view/adapter/BaseViewHolder.java
index a04b9ec..a74b306 100644
--- a/RefreshRecyclerView/src/main/java/cn/lemon/view/adapter/BaseViewHolder.java
+++ b/RefreshRecyclerView/src/main/java/cn/lemon/view/adapter/BaseViewHolder.java
@@ -13,14 +13,21 @@ import android.view.ViewGroup;
public class BaseViewHolder extends RecyclerView.ViewHolder{
private final String TAG = "BaseViewHolder";
+ private T mData;
+
+ public BaseViewHolder(ViewGroup parent, int layoutId) {
+ this(LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false));
+ }
public BaseViewHolder(View itemView) {
super(itemView);
- }
-
- public BaseViewHolder(ViewGroup parent, int layoutId) {
- super(LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false));
onInitializeView();
+ itemView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onItemViewClick(mData);
+ }
+ });
}
public void onInitializeView() {
@@ -28,24 +35,25 @@ public class BaseViewHolder extends RecyclerView.ViewHolder{
}
public T findViewById(@IdRes int resId) {
- return (T) itemView.findViewById(resId);
+ if (itemView != null) {
+ return (T) itemView.findViewById(resId);
+ } else {
+ return null;
+ }
}
public void setData(final T data) {
- itemView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- onItemViewClick(data);
- }
- });
+ if (data == null) {
+ return;
+ }
+ mData = data;
+ }
+
+ public T getData() {
+ return mData;
}
public void onItemViewClick(T data) {
}
-
- public void setTag(Object tag){
- itemView.setTag(tag);
- }
-
}
diff --git a/RefreshRecyclerView/src/main/java/cn/lemon/view/adapter/MultiTypeAdapter.java b/RefreshRecyclerView/src/main/java/cn/lemon/view/adapter/MultiTypeAdapter.java
index 8548afb..ce9707e 100644
--- a/RefreshRecyclerView/src/main/java/cn/lemon/view/adapter/MultiTypeAdapter.java
+++ b/RefreshRecyclerView/src/main/java/cn/lemon/view/adapter/MultiTypeAdapter.java
@@ -2,18 +2,17 @@ package cn.lemon.view.adapter;
import android.content.Context;
import android.util.Log;
-import android.util.SparseIntArray;
-import android.view.View;
import android.view.ViewGroup;
import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 复杂的数据类型列表 Adapter , 没有 Header , Footer 的概念,所有的 item 都对应一个 ViewHolder
+ * 通过反射自动处理 onCreateViewHolder 过程,如需避免反射调用请使用 CustomMultiTypeAdapter
+ *
* Created by linlongxin on 2016/8/22.
*/
@@ -21,79 +20,34 @@ public class MultiTypeAdapter extends RecyclerAdapter {
private final String TAG = "MultiTypeAdapter";
private List