From c4c1f2c86f6f87dd4bb6d23f76cbf5e09b3c4f66 Mon Sep 17 00:00:00 2001 From: lijian Date: Wed, 26 Jul 2017 16:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A7=BB=E9=99=A4=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E7=8A=B6=E6=80=81=E7=9B=91=E5=90=AC=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?;=E9=81=BF=E5=85=8D=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++--- .../com/codyy/downloader/ExampleUnitTest.java | 9 ++++++- downloadlibrary/build.gradle | 6 ++--- .../java/com/codyy/download/Downloader.java | 25 +++++++++++++++++-- .../download/service/DownloadService.java | 21 +++++++++++++++- 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 73b3599..35b7f5b 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ allprojects { ``` dependencies { //如果项目中已有com.android.support.*包,则从Downloader中剔除; - compile('com.github.CodyyAndroid:Downloader:1.1.6') { + compile('com.github.CodyyAndroid:Downloader:1.1.7') { exclude group: 'com.android.support' } //如果项目中无com.android.support.*包,则保留; - compile('com.github.CodyyAndroid:Downloader:1.1.6') + compile('com.github.CodyyAndroid:Downloader:1.1.7') } ``` -## [API](https://jitpack.io/com/github/CodyyAndroid/Downloader/1.1.6/javadoc/) +## [API](https://jitpack.io/com/github/CodyyAndroid/Downloader/1.1.7/javadoc/) diff --git a/app/src/test/java/com/codyy/downloader/ExampleUnitTest.java b/app/src/test/java/com/codyy/downloader/ExampleUnitTest.java index 3081560..0d85e1c 100644 --- a/app/src/test/java/com/codyy/downloader/ExampleUnitTest.java +++ b/app/src/test/java/com/codyy/downloader/ExampleUnitTest.java @@ -2,6 +2,9 @@ import org.junit.Test; +import java.util.HashMap; +import java.util.Map; + import static org.junit.Assert.*; /** @@ -12,6 +15,10 @@ public class ExampleUnitTest { @Test public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); + Map map=new HashMap<>(); + map.put("1","111"); + map.put("2","2222"); + map.remove("1"); + assertEquals(1,map.size()); } } \ No newline at end of file diff --git a/downloadlibrary/build.gradle b/downloadlibrary/build.gradle index 0e36d49..f95bf34 100644 --- a/downloadlibrary/build.gradle +++ b/downloadlibrary/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 26 - versionCode 49 - versionName "1.1.6" + versionCode 50 + versionName "1.1.7" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -56,7 +56,7 @@ javadoc { author true version true links "http://docs.oracle.com/javase/7/docs/api" - title "下载库1.1.6" + title "下载库1.1.7" } } // 制作文档(Javadoc) diff --git a/downloadlibrary/src/main/java/com/codyy/download/Downloader.java b/downloadlibrary/src/main/java/com/codyy/download/Downloader.java index 831832f..db24431 100644 --- a/downloadlibrary/src/main/java/com/codyy/download/Downloader.java +++ b/downloadlibrary/src/main/java/com/codyy/download/Downloader.java @@ -25,7 +25,7 @@ * 文件下载器 * Created by lijian on 2017/6/7. * - * @version 1.1.5 + * @version 1.1.7 */ public class Downloader { @@ -132,6 +132,7 @@ public void onServiceDisconnected(ComponentName name) { /** * 同步已下载的记录 + * * @param entity 下载记录 * @return true:同步成功;false:服务未启动或同步失败 */ @@ -274,7 +275,7 @@ public void deleteAll() { /** * 接收下载状态 * - * @param id 下载地址 + * @param id 下载资源ID * @param loadListener 状态监听 */ public void receiveDownloadStatus(@NonNull String id, @NonNull DownLoadListener loadListener) { @@ -286,6 +287,26 @@ public void receiveDownloadStatus(@NonNull String id, @NonNull DownLoadListener } } + /** + * 移除下载状态监听 + * + * @param id 下载资源ID + */ + public void removeDownloadStatusListener(@NonNull String id) { + if (mDownloadService != null) { + mDownloadService.removeDownloadStatusListener(id); + } + } + + /** + * 移除所有下载状态监听 + */ + public void removeAllDownloadStatusListener() { + if (mDownloadService != null) { + mDownloadService.removeAllDownloadStatusListener(); + } + } + /** * 监听下载速率和正在下载的任务数{@link DownloadRateListener#onRate(String, int)} * 监听下载成功后返回下载结果{@link DownloadRateListener#onComplete(DownloadEntity)} diff --git a/downloadlibrary/src/main/java/com/codyy/download/service/DownloadService.java b/downloadlibrary/src/main/java/com/codyy/download/service/DownloadService.java index 28ac910..966966e 100644 --- a/downloadlibrary/src/main/java/com/codyy/download/service/DownloadService.java +++ b/downloadlibrary/src/main/java/com/codyy/download/service/DownloadService.java @@ -98,6 +98,7 @@ public void onDestroy() { mDownloadDao.closeDB(); } mHandler = null; + mDownLoadListeners.clear(); Cog.d(TAG, "DownloadService onDestroy"); } @@ -190,13 +191,31 @@ private String getSavePath(@NonNull String downloadUrl, String path) { /** * 接收下载状态 * - * @param id 下载地址 + * @param id 资源id * @param loadListener 监听 */ public void receiveDownloadStatus(@NonNull String id, @NonNull DownLoadListener loadListener) { mDownLoadListeners.put(id, loadListener); } + /** + * 移除下载监听 + * + * @param id 资源id + */ + public void removeDownloadStatusListener(@NonNull String id) { + if (mDownLoadListeners.containsKey(id)) { + mDownLoadListeners.remove(id); + } + } + + /** + * 移除所有下载监听 + */ + public void removeAllDownloadStatusListener() { + mDownLoadListeners.clear(); + } + /** * 增加下载速率监听 *