From 2a03256d466b5d76ab461481e7355d60c776615c Mon Sep 17 00:00:00 2001 From: crazysunj Date: Sat, 2 Nov 2019 13:50:09 +0800 Subject: [PATCH] =?UTF-8?q?v2.5.1=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.gradle | 2 +- multitypeadapter/build.gradle | 2 -- multitypeadapter/proguard-rules.pro | 17 ------------ .../helper/AdapterHelper.java | 23 ++++++++++++++++ .../helper/AsynAdapterHelper.java | 27 +++++++------------ .../helper/RecyclerViewAdapterHelper.java | 14 +++++++++- .../helper/SynAdapterHelper.java | 7 +++++ 7 files changed, 54 insertions(+), 38 deletions(-) delete mode 100644 multitypeadapter/proguard-rules.pro diff --git a/config.gradle b/config.gradle index 71ec635..55ce5c7 100644 --- a/config.gradle +++ b/config.gradle @@ -31,7 +31,7 @@ ext { userOrg : 'twsunj', groupId : 'com.crazysunj', uploadName : 'MultiTypeRecyclerViewAdapter', - publishVersion: '2.5.0', + publishVersion: '2.5.1', desc : 'MultiTypeRecyclerViewAdapter For Android', website : 'https://github.com/crazysunj/MultiTypeRecyclerViewAdapter', licences : ['Apache-2.0'] diff --git a/multitypeadapter/build.gradle b/multitypeadapter/build.gradle index e38ed24..1089a7a 100644 --- a/multitypeadapter/build.gradle +++ b/multitypeadapter/build.gradle @@ -10,8 +10,6 @@ android { defaultConfig { minSdkVersion configs.libMinSdkVersion targetSdkVersion configs.targetSdkVersion - versionCode 1 - versionName bintrays.publishVersion } lintOptions { diff --git a/multitypeadapter/proguard-rules.pro b/multitypeadapter/proguard-rules.pro deleted file mode 100644 index 8439a5d..0000000 --- a/multitypeadapter/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/sunjian/Downloads/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/AdapterHelper.java b/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/AdapterHelper.java index b67a872..5d665ef 100644 --- a/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/AdapterHelper.java +++ b/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/AdapterHelper.java @@ -314,6 +314,29 @@ public void action(RecyclerViewAdapterHelper helper) { }); } + /** + * 刷新全部数据 + * 详细见{@link RecyclerViewAdapterHelper#notifyDataSetDiffChanged(List)} + * + * @param data 传入集合 + * @return ActionAdapterHelper + */ + public ActionAdapterHelper allDiff(final List data) { + return create(new CallHandler() { + @Override + public void call(final ActionHandler actionHandler, RecyclerViewAdapterHelper helper) { + into(new ActionHandler() { + @SuppressWarnings("unchecked") + @Override + public void action(RecyclerViewAdapterHelper helper) { + helper.notifyDataSetDiffChanged(data); + actionHandler.action(helper); + } + }, helper); + } + }); + } + /** * 刷新全部数据 * 详细见{@link RecyclerViewAdapterHelper#notifyDataSetChanged(SparseArray)} diff --git a/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/AsynAdapterHelper.java b/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/AsynAdapterHelper.java index 968fc06..8037b10 100644 --- a/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/AsynAdapterHelper.java +++ b/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/AsynAdapterHelper.java @@ -25,10 +25,8 @@ import com.crazysunj.multitypeadapter.entity.MultiTypeEntity; import java.util.List; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; /** * @author: sunjian @@ -41,8 +39,7 @@ public class AsynAdapterHelper extends RecyclerViewAd private static final int HANDLE_DATA_UPDATE = 1; - protected ScheduledExecutorService mExecutor = Executors.newSingleThreadScheduledExecutor(); - protected ScheduledFuture mFuture; + protected ExecutorService mExecutor = Executors.newSingleThreadExecutor(); @SuppressLint("HandlerLeak") private Handler mHandler = new Handler() { @@ -55,35 +52,31 @@ public void handleMessage(Message msg) { } }; + public AsynAdapterHelper() { + } + + public AsynAdapterHelper(int mode) { + super(mode); + } + @Override protected void startRefresh(HandleBase refreshData) { - cancelFuture(); - mFuture = mExecutor.schedule(new HandleTask(refreshData), - 0, TimeUnit.MILLISECONDS); + mExecutor.execute(new HandleTask(refreshData)); } @Override public void release() { - cancelFuture(); if (!mExecutor.isShutdown()) { mExecutor.shutdown(); } super.release(); } - protected void cancelFuture() { - if (mFuture != null && !mFuture.isCancelled()) { - mFuture.cancel(true); - mFuture = null; - } - } - /** * 重置刷新队列 */ public void reset() { clearQueue(); - cancelFuture(); } private final class HandleTask implements Runnable { diff --git a/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/RecyclerViewAdapterHelper.java b/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/RecyclerViewAdapterHelper.java index c213729..2638a99 100644 --- a/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/RecyclerViewAdapterHelper.java +++ b/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/RecyclerViewAdapterHelper.java @@ -711,6 +711,18 @@ public void notifyDataSetChanged(@NonNull List list) { onEnd(); } + /** + * 专门用于混合模式的diff全局刷新 {@link RecyclerViewAdapterHelper#MODE_MIXED} + * + * @param list List + */ + public void notifyDataSetDiffChanged(@NonNull List list) { + checkAdapterBind(); + mCurrentMode = MODE_MIXED; + mNewData.clear(); + mNewData.addAll(list); + notifyModuleChanged(mNewData, null, null, REFRESH_TYPE_DATA_ALL, REFRESH_ALL); + } /** * 专门用于标准模式的全局刷新 {@link RecyclerViewAdapterHelper#MODE_STANDARD} @@ -1996,7 +2008,7 @@ private void checkStandardMode() { if (mCurrentMode == MODE_MIXED) { onEnd(); mRefreshQueue.clear(); - throw new RefreshException("Current refresh mode can't support random refresh mode !"); + throw new RefreshException("Current refresh mode can't support mixed refresh mode !"); } } diff --git a/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/SynAdapterHelper.java b/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/SynAdapterHelper.java index b4b40d8..167c226 100644 --- a/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/SynAdapterHelper.java +++ b/multitypeadapter/src/main/java/com/crazysunj/multitypeadapter/helper/SynAdapterHelper.java @@ -28,6 +28,13 @@ */ public class SynAdapterHelper extends RecyclerViewAdapterHelper { + public SynAdapterHelper() { + } + + public SynAdapterHelper(int mode) { + super(mode); + } + @Override protected void startRefresh(HandleBase refreshData) { handleResult(handleRefresh(refreshData.getNewData(), refreshData.getNewHeader(),