From b7b55e42fc724ce984b50dffab250f45592dad62 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 15 Aug 2017 10:41:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E4=BF=A1=E6=81=AF=E7=9A=84api=20https://gith?= =?UTF-8?q?ub.com/AriaLyy/Aria/issues/89#issuecomment-322193785?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aria/core/download/DownloadReceiver.java | 44 ++++++++++++++++--- .../aria/core/download/DownloadTarget.java | 10 +++++ .../aria/core/download/FtpDownloadTarget.java | 5 +++ .../download/downloader/AbsFtpInfoThread.java | 4 +- .../core/download/downloader/Downloader.java | 15 ++++--- .../download/downloader/FtpDirInfoThread.java | 2 - .../downloader/FtpFileInfoThread.java | 8 ++++ .../downloader/HttpFileInfoThread.java | 8 ++-- .../downloader/SimpleDownloadUtil.java | 4 +- .../arialyy/aria/core/inf/AbsTaskEntity.java | 10 +++++ app/src/main/assets/aria_config.xml | 5 ++- .../simple/download/FtpDownloadActivity.java | 2 +- .../simple/download/SingleTaskActivity.java | 2 +- .../group/FTPDirDownloadActivity.java | 2 +- .../com/arialyy/aria/core/Configuration.java | 2 +- 15 files changed, 96 insertions(+), 27 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index 90088d3f..886fcb68 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -16,16 +16,14 @@ package com.arialyy.aria.core.download; import android.support.annotation.NonNull; -import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.command.normal.NormalCmdFactory; +import com.arialyy.aria.core.common.ProxyHelper; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsReceiver; -import com.arialyy.aria.core.inf.IReceiver; -import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulerListener; -import com.arialyy.aria.core.common.ProxyHelper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; @@ -53,17 +51,40 @@ public class DownloadReceiver extends AbsReceiver { /** * 使用下载实体执行下载操作 + * + * @param entity 下载实体 */ public DownloadTarget load(DownloadEntity entity) { - return new DownloadTarget(entity, targetName); + return load(entity, false); + } + + /** + * 使用下载实体执行下载操作 + * + * @param refreshInfo 是否刷新下载信息 + */ + public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) { + return new DownloadTarget(entity, targetName, refreshInfo); } /** * 加载Http、https单任务下载地址 + * + * @param url 下载地址 */ public DownloadTarget load(@NonNull String url) { + return load(url, false); + } + + /** + * 加载Http、https单任务下载地址 + * + * @param url 下载地址 + * @param refreshInfo 是否刷新下载信息 + */ + public DownloadTarget load(@NonNull String url, boolean refreshInfo) { CheckUtil.checkDownloadUrl(url); - return new DownloadTarget(url, targetName); + return new DownloadTarget(url, targetName, refreshInfo); } /** @@ -78,8 +99,17 @@ public class DownloadReceiver extends AbsReceiver { * 加载ftp单任务下载地址 */ public FtpDownloadTarget loadFtp(@NonNull String url) { + return loadFtp(url, false); + } + + /** + * 加载ftp单任务下载地址 + * + * @param refreshInfo 是否刷新下载信息 + */ + public FtpDownloadTarget loadFtp(@NonNull String url, boolean refreshInfo) { CheckUtil.checkDownloadUrl(url); - return new FtpDownloadTarget(url, targetName); + return new FtpDownloadTarget(url, targetName, refreshInfo); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java index 6303a43b..1c527810 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java @@ -33,16 +33,26 @@ public class DownloadTarget protected String url; DownloadTarget(DownloadEntity entity, String targetName) { + this(entity, targetName, false); + } + + DownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) { this.url = entity.getUrl(); mTargetName = targetName; initTask(entity); + mTaskEntity.refreshInfo = refreshInfo; } DownloadTarget(String url, String targetName) { + this(url, targetName, false); + } + + DownloadTarget(String url, String targetName, boolean refreshInfo) { this.url = url; mTargetName = targetName; DownloadEntity entity = getEntity(url); initTask(entity); + mTaskEntity.refreshInfo = refreshInfo; } private void initTask(DownloadEntity entity) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java index b7dea7cc..210528d5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java @@ -32,6 +32,10 @@ public class FtpDownloadTarget extends DownloadTarget { private int port; FtpDownloadTarget(String url, String targetName) { + this(url, targetName, false); + } + + FtpDownloadTarget(String url, String targetName, boolean refreshInfo) { super(url, targetName); String[] pp = url.split("/")[2].split(":"); this.serverIp = pp[0]; @@ -45,6 +49,7 @@ public class FtpDownloadTarget extends DownloadTarget { mTaskEntity.serverIp = serverIp; mTaskEntity.port = port; mEntity.setFileName(url.substring(lastIndex + 1, url.length())); + mTaskEntity.refreshInfo = refreshInfo; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsFtpInfoThread.java index b20909c7..20e9a834 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsFtpInfoThread.java @@ -40,6 +40,7 @@ abstract class AbsFtpInfoThread { } @Override protected void checkTask() { - if (!mTaskEntity.isSupportBP) { - isNewTask = true; - return; - } mConfigFile = new File(mContext.getFilesDir().getPath() + AriaManager.DOWNLOAD_TEMP_DIR + mEntity.getFileName() + ".properties"); mTempFile = new File(mEntity.getDownloadPath()); + if (!mTaskEntity.isSupportBP) { + isNewTask = true; + return; + } + if (mTaskEntity.isNewTask) { + isNewTask = true; + return; + } if (!mConfigFile.exists()) { //记录文件被删除,则重新下载 isNewTask = true; CommonUtil.createFile(mConfigFile.getPath()); } else if (!mTempFile.exists()) { isNewTask = true; - } else if (DbEntity.findFirst(DownloadEntity.class, "url=?", mEntity.getDownloadUrl()) - == null) { + } else if (DbEntity.findFirst(DownloadEntity.class, "url=?", mEntity.getUrl()) == null) { isNewTask = true; } else { isNewTask = checkConfigFile(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java index 963639de..d53c186d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java @@ -28,7 +28,6 @@ import org.apache.commons.net.ftp.FTPFile; * 获取ftp文件夹信息 */ class FtpDirInfoThread extends AbsFtpInfoThread { - private long mSize = 0; FtpDirInfoThread(DownloadGroupTaskEntity taskEntity, OnFileInfoCallback callback) { super(taskEntity, callback); @@ -36,7 +35,6 @@ class FtpDirInfoThread extends AbsFtpInfoThread extends DbEntity { @Ignore public String userName, userPw, account, serverIp; @Ignore public int port; + /** + * 刷新信息 {@code true} 重新刷新下载信息 + */ + @Ignore public boolean refreshInfo = false; + + /** + * 是否是新任务,{@code true} 新任务 + */ + @Ignore public boolean isNewTask = false; + /** * 请求类型 * {@link AbsTaskEntity#HTTP}、{@link AbsTaskEntity#FTP} diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index 621b0464..b2d0febd 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -31,7 +31,7 @@ - + @@ -51,6 +51,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java index a1bf4f89..a871366e 100644 --- a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java @@ -59,7 +59,7 @@ public class FtpDownloadActivity extends BaseActivity { switch (view.getId()) { case R.id.start: Aria.download(SingleTaskActivity.this) - .load(DOWNLOAD_URL) + .load(DOWNLOAD_URL, true) .addHeader("groupName", "value") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/gggg.apk") .start(); diff --git a/app/src/main/java/com/arialyy/simple/download/group/FTPDirDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/group/FTPDirDownloadActivity.java index f9b0000f..864adc59 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/FTPDirDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/group/FTPDirDownloadActivity.java @@ -35,7 +35,7 @@ import com.arialyy.simple.widget.SubStateLinearLayout; * Created by Aria.Lao on 2017/7/6. */ public class FTPDirDownloadActivity extends BaseActivity { - private static final String dir = "ftp://172.18.104.129:21/haha/"; + private static final String dir = "ftp://172.18.104.66:21/haha/"; @Bind(R.id.child_list) SubStateLinearLayout mChildList; diff --git a/aria/src/main/java/com/arialyy/aria/core/Configuration.java b/aria/src/main/java/com/arialyy/aria/core/Configuration.java index e8b6ba7a..e65f4218 100644 --- a/aria/src/main/java/com/arialyy/aria/core/Configuration.java +++ b/aria/src/main/java/com/arialyy/aria/core/Configuration.java @@ -70,7 +70,7 @@ class Configuration { * * @see QueueMod */ - String queueMod = "now"; + String queueMod = "wait"; public String getQueueMod() { return queueMod; From 18033f5c19a2e91903d3a0cf0e2024eee338f622 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 15 Aug 2017 10:53:09 +0800 Subject: [PATCH 2/3] 3.2.18 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 133f0556..da4f3c6e 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.2.17' + publishVersion = '3.2.18' repoName='maven' desc = 'android 下载框架' website = 'https://github.com/AriaLyy/Aria' From 3abb8d84f72fe3c55b92148df9bd5c040bd5200f Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 15 Aug 2017 11:13:04 +0800 Subject: [PATCH 3/3] 3.2.19 --- README.md | 4 +-- .../com/arialyy/aria/core/Configuration.java | 25 +++++++++++++------ build.gradle | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f6173e8b..50eb1804 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ Aria有以下特点: [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) ```java -compile 'com.arialyy.aria:aria-core:3.2.17' -annotationProcessor 'com.arialyy.aria:aria-compiler:3.2.17' +compile 'com.arialyy.aria:aria-core:3.2.19' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.2.19' ``` ## 示例 diff --git a/aria/src/main/java/com/arialyy/aria/core/Configuration.java b/aria/src/main/java/com/arialyy/aria/core/Configuration.java index e65f4218..3aeca30e 100644 --- a/aria/src/main/java/com/arialyy/aria/core/Configuration.java +++ b/aria/src/main/java/com/arialyy/aria/core/Configuration.java @@ -18,6 +18,7 @@ package com.arialyy.aria.core; import android.text.TextUtils; import com.arialyy.aria.core.common.QueueMod; import com.arialyy.aria.core.queue.DownloadTaskQueue; +import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.util.CommonUtil; import java.io.File; import java.lang.reflect.Field; @@ -86,14 +87,6 @@ class Configuration { return maxTaskNum; } - public BaseConfig setMaxTaskNum(int maxTaskNum) { - oldMaxTaskNum = this.maxTaskNum; - this.maxTaskNum = maxTaskNum; - saveKey("maxTaskNum", maxTaskNum + ""); - DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum); - return this; - } - public int getReTryNum() { return reTryNum; } @@ -250,6 +243,14 @@ class Configuration { */ double msxSpeed = 0.0; + public DownloadConfig setMaxTaskNum(int maxTaskNum) { + oldMaxTaskNum = this.maxTaskNum; + this.maxTaskNum = maxTaskNum; + saveKey("maxTaskNum", maxTaskNum + ""); + DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum); + return this; + } + public int getIOTimeOut() { return iOTimeOut; } @@ -332,6 +333,14 @@ class Configuration { private static UploadConfig INSTANCE = null; + public UploadConfig setMaxTaskNum(int maxTaskNum) { + oldMaxTaskNum = this.maxTaskNum; + this.maxTaskNum = maxTaskNum; + saveKey("maxTaskNum", maxTaskNum + ""); + UploadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum); + return this; + } + static UploadConfig getInstance() { if (INSTANCE == null) { synchronized (DownloadConfig.class) { diff --git a/build.gradle b/build.gradle index da4f3c6e..2b6a3686 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.2.18' + publishVersion = '3.2.19' repoName='maven' desc = 'android 下载框架' website = 'https://github.com/AriaLyy/Aria'