From fc8dd1f9b1813392f61cc6deacc2a941193d9e8c Mon Sep 17 00:00:00 2001 From: lijian Date: Wed, 26 Jul 2017 16:08:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ESimpleDownloadListener?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +-- .../downloader/MultiDownloadActivity.java | 28 ++++++++++- downloadlibrary/build.gradle | 6 +-- .../service/SimpleDownloadListener.java | 47 +++++++++++++++++++ 4 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 downloadlibrary/src/main/java/com/codyy/download/service/SimpleDownloadListener.java diff --git a/README.md b/README.md index 1c44471..73b3599 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ allprojects { ``` dependencies { //如果项目中已有com.android.support.*包,则从Downloader中剔除; - compile('com.github.CodyyAndroid:Downloader:1.1.5') { + compile('com.github.CodyyAndroid:Downloader:1.1.6') { exclude group: 'com.android.support' } //如果项目中无com.android.support.*包,则保留; - compile('com.github.CodyyAndroid:Downloader:1.1.5') + compile('com.github.CodyyAndroid:Downloader:1.1.6') } ``` -## [API](https://jitpack.io/com/github/CodyyAndroid/Downloader/1.1.5/javadoc/) +## [API](https://jitpack.io/com/github/CodyyAndroid/Downloader/1.1.6/javadoc/) diff --git a/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java b/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java index 642dc49..d29b5ca 100644 --- a/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java +++ b/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java @@ -25,6 +25,7 @@ import com.codyy.download.service.DownLoadListener; import com.codyy.download.service.DownloadRateListener; import com.codyy.download.service.DownloadStatus; +import com.codyy.download.service.SimpleDownloadListener; import java.util.ArrayList; import java.util.List; @@ -252,7 +253,30 @@ public void onClick(View v) { public void setDataToView(FileEntity data) { tvName.setText(data.getName()); tvUrl.setText(data.getUrl()); - Downloader.getInstance(itemView.getContext()).receiveDownloadStatus(tvUrl.getText().toString(), new DownLoadListener() { + Downloader.getInstance(itemView.getContext()).receiveDownloadStatus(tvUrl.getText().toString(), new SimpleDownloadListener() { + @Override + public void onWaiting() { + btn.setText("等待"); + } + + @Override + public void onProgress(DownloadStatus status) { + pb.setProgress((int) status.getPercentNumber()); + tvName.setText(status.getFormatStatusString()); + } + + @Override + public void onPause() { + btn.setText("下载"); + } + + @Override + public void onComplete() { + btn.setText("完成"); + } + + }); + /* Downloader.getInstance(itemView.getContext()).receiveDownloadStatus(tvUrl.getText().toString(), new DownLoadListener() { @Override public void onStart() { btn.setText("暂停"); @@ -296,7 +320,7 @@ public void onFailure(int code) { public void onError(Exception e) { Log.e("Download", " onError :" + e.getMessage()); } - }); + });*/ } } diff --git a/downloadlibrary/build.gradle b/downloadlibrary/build.gradle index 8d96505..0e36d49 100644 --- a/downloadlibrary/build.gradle +++ b/downloadlibrary/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 26 - versionCode 48 - versionName "1.1.5" + versionCode 49 + versionName "1.1.6" 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.5" + title "下载库1.1.6" } } // 制作文档(Javadoc) diff --git a/downloadlibrary/src/main/java/com/codyy/download/service/SimpleDownloadListener.java b/downloadlibrary/src/main/java/com/codyy/download/service/SimpleDownloadListener.java new file mode 100644 index 0000000..643ab3c --- /dev/null +++ b/downloadlibrary/src/main/java/com/codyy/download/service/SimpleDownloadListener.java @@ -0,0 +1,47 @@ +package com.codyy.download.service; + +/** + * Created by lijian on 2017/7/26. + */ + +public abstract class SimpleDownloadListener implements DownLoadListener { + @Override + public void onStart() { + + } + + @Override + public void onWaiting() { + + } + + @Override + public void onProgress(DownloadStatus status) { + + } + + @Override + public void onPause() { + + } + + @Override + public void onComplete() { + + } + + @Override + public void onDelete() { + + } + + @Override + public void onFailure(int code) { + + } + + @Override + public void onError(Exception e) { + + } +}