From 93844516a357bda56028af5465650fa566489f88 Mon Sep 17 00:00:00 2001
From: laoyuyu <511455842@QQ.com>
Date: Thu, 25 May 2017 23:26:46 +0800
Subject: [PATCH 1/4] Update DownloadApi.md
---
DownloadApi.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/DownloadApi.md b/DownloadApi.md
index 45134f3d..5ec2421b 100644
--- a/DownloadApi.md
+++ b/DownloadApi.md
@@ -1,7 +1,7 @@
## 关于Aria,你还需要知道的一些东西
- 设置下载任务数,Aria默认下载任务为**2**
- ```java
+ ```java
Aria.get(getContext()).setMaxDownloadNum(num);
```
- 停止所有下载
From 4b315063f7e5547612af841f6d59ff5339d7450d Mon Sep 17 00:00:00 2001
From: AriaLyy <511455842@qq.com>
Date: Wed, 31 May 2017 21:20:32 +0800
Subject: [PATCH 2/4] ..
---
.idea/misc.xml | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5d199810..d2e67251 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -27,17 +27,7 @@
-
-
-
-
-
-
-
-
-
-
-
+
From 6202f0d4e3bd9e1454173c8041a505dbf30edb37 Mon Sep 17 00:00:00 2001
From: AriaLyy <511455842@qq.com>
Date: Wed, 31 May 2017 22:31:05 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=B9=BF=E6=92=AD=E7=9A=84=E4=B8=80?=
=?UTF-8?q?=E4=B8=AAbug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/misc.xml | 2 +-
.idea/modules.xml | 2 +-
.../main/java/com/arialyy/aria/core/Aria.java | 6 +-
.../com/arialyy/aria/core/Configuration.java | 2 +-
.../aria/core/download/DownloadEntity.java | 1 +
.../aria/core/download/DownloadTask.java | 8 +-
.../com/arialyy/aria/core/inf/AbsTarget.java | 7 ++
.../com/arialyy/aria/core/inf/IEntity.java | 2 +
.../arialyy/aria/core/queue/AbsTaskQueue.java | 82 ++++++++++++++++++
.../aria/core/queue/DownloadTaskQueue.java | 86 +------------------
.../arialyy/aria/core/queue/ITaskQueue.java | 27 +++---
.../aria/core/queue/UploadTaskQueue.java | 51 +----------
.../core/scheduler/DownloadSchedulers.java | 2 +-
.../aria/core/scheduler/UploadSchedulers.java | 2 +-
.../aria/core/upload/UploadEntity.java | 2 +-
.../arialyy/aria/core/upload/UploadTask.java | 6 +-
.../simple/download/DownloadModule.java | 2 +-
17 files changed, 130 insertions(+), 160 deletions(-)
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d2e67251..cbd46bd1 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -27,7 +27,7 @@
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 9f4bd159..5f6de159 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,8 +2,8 @@
-
+
diff --git a/Aria/src/main/java/com/arialyy/aria/core/Aria.java b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
index c1b20207..4b3fb688 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
@@ -100,7 +100,11 @@ import com.arialyy.aria.core.upload.UploadTask;
/**
* 下载实体
*/
- public static final String ENTITY = "DOWNLOAD_ENTITY";
+ public static final String DOWNLOAD_ENTITY = "DOWNLOAD_ENTITY";
+ /**
+ * 上传实体
+ */
+ public static final String UPLOAD_ENTITY = "UPLOAD_ENTITY";
/**
* 位置
*/
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 ccc040c0..8bdc1c30 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/Configuration.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/Configuration.java
@@ -86,7 +86,7 @@ class Configuration {
oldMaxTaskNum = this.maxTaskNum;
this.maxTaskNum = maxTaskNum;
saveKey("maxTaskNum", maxTaskNum + "");
- DownloadTaskQueue.getInstance().setDownloadNum(maxTaskNum);
+ DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum);
return this;
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
index 65dcfc28..f937d321 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
@@ -69,6 +69,7 @@ public class DownloadEntity extends DbEntity implements Parcelable, IEntity {
return failNum;
}
+ @Override
public void setFailNum(int failNum) {
this.failNum = failNum;
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
index 8611e1fe..385220f5 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
@@ -208,7 +208,7 @@ public class DownloadTask implements ITask {
// 发送停止下载的广播
Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_STOP);
intent.putExtra(Aria.CURRENT_LOCATION, mEntity.getCurrentProgress());
- intent.putExtra(Aria.ENTITY, mEntity);
+ intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity);
mContext.sendBroadcast(intent);
}
}
@@ -227,7 +227,7 @@ public class DownloadTask implements ITask {
}
//发送取消下载的广播
Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL);
- intent.putExtra(Aria.ENTITY, mEntity);
+ intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity);
mContext.sendBroadcast(intent);
}
}
@@ -285,7 +285,7 @@ public class DownloadTask implements ITask {
this.task = wTask.get();
this.downloadEntity = this.task.getDownloadEntity();
sendIntent = CommonUtil.createIntent(context.getPackageName(), Aria.ACTION_RUNNING);
- sendIntent.putExtra(Aria.ENTITY, downloadEntity);
+ sendIntent.putExtra(Aria.DOWNLOAD_ENTITY, downloadEntity);
final AriaManager manager = AriaManager.getInstance(context);
isOpenBroadCast = manager.getDownloadConfig().isOpenBreadCast();
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
@@ -406,7 +406,7 @@ public class DownloadTask implements ITask {
downloadEntity.update();
if (!isOpenBroadCast) return;
Intent intent = CommonUtil.createIntent(context.getPackageName(), action);
- intent.putExtra(Aria.ENTITY, downloadEntity);
+ intent.putExtra(Aria.DOWNLOAD_ENTITY, downloadEntity);
if (location != -1) {
intent.putExtra(Aria.CURRENT_LOCATION, location);
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
index 02feaab0..0941d294 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
@@ -40,6 +40,13 @@ public class AbsTarget
protected TASK_ENTITY taskEntity;
protected String targetName;
+ /**
+ * 将该任务优先级提到最高
+ */
+ protected void setToFirst(){
+
+ }
+
/**
* 重定向后,新url的key,默认为location
*/
diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java
index 992d21a5..fcca2e5e 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java
@@ -60,4 +60,6 @@ public interface IEntity {
@Ignore public static final int STATE_CANCEL = 7;
public int getState();
+
+ public void setFailNum(int failNum);
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
index 7fc1d722..bdccfe9c 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
@@ -16,6 +16,7 @@
package com.arialyy.aria.core.queue;
+import android.util.Log;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.ITaskEntity;
@@ -24,8 +25,89 @@ import com.arialyy.aria.core.queue.pool.ExecutePool;
/**
* Created by Aria.Lao on 2017/2/23.
+ * 任务队列
*/
abstract class AbsTaskQueue
implements ITaskQueue {
+ private final String TAG = "AbsTaskQueue";
CachePool mCachePool = new CachePool<>();
+ ExecutePool mExecutePool = null;
+
+ /**
+ * 获取任务执行池
+ */
+ public ExecutePool getExecutePool() {
+ return mExecutePool;
+ }
+
+ /**
+ * 获取缓存池
+ */
+ public CachePool getCachePool() {
+ return mCachePool;
+ }
+
+ /**
+ * 获取缓存任务数
+ *
+ * @return 获取缓存的任务数
+ */
+ @Override public int cachePoolSize() {
+ return mCachePool.size();
+ }
+
+ /**
+ * 获取当前运行的任务数
+ *
+ * @return 当前正在执行的任务数
+ */
+ @Override public int executePoolSize() {
+ return mExecutePool.size();
+ }
+
+ @Override public TASK getTask(String url) {
+ TASK task = mExecutePool.getTask(url);
+ if (task == null) {
+ task = mCachePool.getTask(url);
+ }
+ return task;
+ }
+
+ @Override public void startTask(TASK task) {
+ if (mExecutePool.putTask(task)) {
+ mCachePool.removeTask(task);
+ task.getEntity().setFailNum(0);
+ task.start();
+ }
+ }
+
+ @Override public void stopTask(TASK task) {
+ if (!task.isRunning()) Log.w(TAG, "停止任务失败,【任务已经停止】");
+ if (mExecutePool.removeTask(task)) {
+ task.stop();
+ } else {
+ task.stop();
+ Log.w(TAG, "停止任务失败,【任务已经停止】");
+ }
+ }
+
+ @Override public void reTryStart(TASK task) {
+ if (task == null) {
+ Log.w(TAG, "重试下载失败,task 为null");
+ return;
+ }
+ if (!task.isRunning()) {
+ task.start();
+ } else {
+ Log.w(TAG, "任务没有完全停止,重试下载失败");
+ }
+ }
+
+ @Override public void cancelTask(TASK task) {
+ task.cancel();
+ }
+
+ @Override public TASK getNextTask() {
+ return mCachePool.pollTask();
+ }
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
index 210b835e..0986e74a 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
@@ -23,7 +23,6 @@ import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.core.queue.pool.CachePool;
import com.arialyy.aria.core.queue.pool.ExecutePool;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
@@ -36,7 +35,6 @@ public class DownloadTaskQueue
private static final String TAG = "DownloadTaskQueue";
private static volatile DownloadTaskQueue INSTANCE = null;
private static final Object LOCK = new Object();
- private ExecutePool mExecutePool = new ExecutePool<>(true);
public static DownloadTaskQueue getInstance() {
if (INSTANCE == null) {
@@ -48,79 +46,10 @@ public class DownloadTaskQueue
}
private DownloadTaskQueue() {
+ mExecutePool = new ExecutePool<>(true);
}
- /**
- * 获取任务执行池
- */
- public ExecutePool getExecutePool() {
- return mExecutePool;
- }
-
- /**
- * 获取缓存池
- */
- public CachePool getCachePool() {
- return mCachePool;
- }
-
- /**
- * 获取当前运行的任务数
- *
- * @return 当前正在执行的任务数
- */
- public int getCurrentTaskNum() {
- return mExecutePool.size();
- }
-
- /**
- * 获取缓存任务数
- *
- * @return 获取缓存的任务数
- */
- public int getCacheTaskNum() {
- return mCachePool.size();
- }
-
- @Override public void startTask(DownloadTask task) {
- if (mExecutePool.putTask(task)) {
- mCachePool.removeTask(task);
- task.getDownloadEntity().setFailNum(0);
- task.start();
- }
- }
-
- @Override public void stopTask(DownloadTask task) {
- if (!task.isRunning()) Log.w(TAG, "停止任务失败,【任务已经停止】");
- if (mExecutePool.removeTask(task)) {
- task.stop();
- } else {
- task.stop();
- Log.w(TAG, "停止任务失败,【任务已经停止】");
- }
- }
-
- @Override public void cancelTask(DownloadTask task) {
- task.cancel();
- }
-
- @Override public void reTryStart(DownloadTask task) {
- if (task == null) {
- Log.w(TAG, "重试下载失败,task 为null");
- return;
- }
- if (!task.isRunning()) {
- task.start();
- } else {
- Log.w(TAG, "任务没有完全停止,重试下载失败");
- }
- }
-
- @Override public int size() {
- return mExecutePool.size();
- }
-
- @Override public void setDownloadNum(int downloadNum) {
+ @Override public void setMaxTaskNum(int downloadNum) {
//原始长度
int size = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
int diff = downloadNum - size;
@@ -164,14 +93,6 @@ public class DownloadTaskQueue
return getTask(entity.getDownloadUrl());
}
- @Override public DownloadTask getTask(String url) {
- DownloadTask task = mExecutePool.getTask(url);
- if (task == null) {
- task = mCachePool.getTask(url);
- }
- return task;
- }
-
@Override public void removeTask(DownloadEntity entity) {
DownloadTask task = mExecutePool.getTask(entity.getDownloadUrl());
if (task != null) {
@@ -183,7 +104,4 @@ public class DownloadTaskQueue
}
}
- @Override public DownloadTask getNextTask() {
- return mCachePool.pollTask();
- }
}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
index 8469cb0f..95da95f3 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
@@ -37,40 +37,45 @@ public interface ITaskQueue {
case STOP:
case CANCEL:
mQueue.removeTask(entity);
- if (mQueue.size() < AriaManager.getInstance(AriaManager.APP)
+ if (mQueue.executePoolSize() < AriaManager.getInstance(AriaManager.APP)
.getUploadConfig()
.getMaxTaskNum()) {
startNextTask();
diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
index 0b2dd657..ef6b0b72 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
@@ -171,7 +171,7 @@ public class UploadSchedulers implements ISchedulers {
case STOP:
case CANCEL:
mQueue.removeTask(entity);
- if (mQueue.size() < AriaManager.getInstance(AriaManager.APP)
+ if (mQueue.executePoolSize() < AriaManager.getInstance(AriaManager.APP)
.getUploadConfig()
.getMaxTaskNum()) {
startNextTask();
diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
index 816cb24c..f3d86e57 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
@@ -81,7 +81,7 @@ public class UploadEntity extends DbEntity implements IEntity, Parcelable {
return failNum;
}
- public void setFailNum(int failNum) {
+ @Override public void setFailNum(int failNum) {
this.failNum = failNum;
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
index 8a23431c..f8146a41 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
@@ -99,7 +99,7 @@ public class UploadTask implements ITask {
}
//发送取消下载的广播
Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), Aria.ACTION_CANCEL);
- intent.putExtra(Aria.ENTITY, mUploadEntity);
+ intent.putExtra(Aria.UPLOAD_ENTITY, mUploadEntity);
AriaManager.APP.sendBroadcast(intent);
}
}
@@ -201,7 +201,7 @@ public class UploadTask implements ITask {
this.task = new WeakReference<>(task);
uploadEntity = this.task.get().getUploadEntity();
sendIntent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), Aria.ACTION_RUNNING);
- sendIntent.putExtra(Aria.ENTITY, uploadEntity);
+ sendIntent.putExtra(Aria.UPLOAD_ENTITY, uploadEntity);
context = AriaManager.APP;
final AriaManager manager = AriaManager.getInstance(context);
isOpenBroadCast = manager.getUploadConfig().isOpenBreadCast();
@@ -301,7 +301,7 @@ public class UploadTask implements ITask {
uploadEntity.update();
if (!isOpenBroadCast) return;
Intent intent = CommonUtil.createIntent(context.getPackageName(), action);
- intent.putExtra(Aria.ENTITY, uploadEntity);
+ intent.putExtra(Aria.UPLOAD_ENTITY, uploadEntity);
if (location != -1) {
intent.putExtra(Aria.CURRENT_LOCATION, location);
}
diff --git a/app/src/main/java/com/arialyy/simple/download/DownloadModule.java b/app/src/main/java/com/arialyy/simple/download/DownloadModule.java
index aa9dab49..8269134b 100644
--- a/app/src/main/java/com/arialyy/simple/download/DownloadModule.java
+++ b/app/src/main/java/com/arialyy/simple/download/DownloadModule.java
@@ -176,7 +176,7 @@ public class DownloadModule extends BaseModule {
String action = intent.getAction();
switch (action) {
case Aria.ACTION_POST_PRE:
- DownloadEntity entity = intent.getParcelableExtra(Aria.ENTITY);
+ DownloadEntity entity = intent.getParcelableExtra(Aria.DOWNLOAD_ENTITY);
len = entity.getFileSize();
L.d(TAG, "download pre");
handler.obtainMessage(SingleTaskActivity.DOWNLOAD_PRE, len).sendToTarget();
From e9d6baa38bbb17c2158157b4f1c49b056f35f52c Mon Sep 17 00:00:00 2001
From: AriaLyy <511455842@qq.com>
Date: Wed, 31 May 2017 22:45:47 +0800
Subject: [PATCH 4/4] 3.1.2
---
.idea/misc.xml | 2 +-
Aria/build.gradle | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/.idea/misc.xml b/.idea/misc.xml
index cbd46bd1..d2e67251 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -27,7 +27,7 @@
-
+
diff --git a/Aria/build.gradle b/Aria/build.gradle
index 87935d12..4f351abc 100644
--- a/Aria/build.gradle
+++ b/Aria/build.gradle
@@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
- versionCode 311
- versionName "3.1.1"
+ versionCode 312
+ versionName "3.1.2"
}
buildTypes {
release {
@@ -23,4 +23,4 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
-apply from: 'jcenter.gradle'
+//apply from: 'jcenter.gradle'