AriaLyy 7 years ago
parent 582f4e96f0
commit ce36165e1d
  1. 4
      Aria/build.gradle
  2. 85
      Aria/src/main/java/com/arialyy/aria/core/TaskManager.java
  3. 14
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java
  4. 9
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java
  5. 2
      Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java
  6. 16
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  7. 19
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  8. 11
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java
  10. 7
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  11. 10
      README.md
  12. 1
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  13. 2
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  14. 2
      build.gradle

@ -23,8 +23,8 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':AriaAnnotations')
compile 'com.arialyy.aria:aria-ftp-plug:1.0.0'
// compile project(':AriaFtpPlug')
// compile 'com.arialyy.aria:aria-ftp-plug:1.0.0'
compile project(':AriaFtpPlug')
}
apply from: 'bintray-release.gradle'

@ -0,0 +1,85 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core;
import android.util.Log;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.util.CommonUtil;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by Aria.Lao on 2017/9/1.
* 任务管理器
*/
public class TaskManager {
private static final String TAG = "TaskManager";
private static volatile TaskManager INSTANCE = null;
private Map<String, AbsTask> map = new ConcurrentHashMap<>();
public TaskManager getInstance() {
if (INSTANCE == null) {
synchronized (AriaManager.LOCK) {
INSTANCE = new TaskManager();
}
}
return INSTANCE;
}
private TaskManager() {
}
/**
* 管理器添加任务
*
* @param key 任务的key下载为保存路径任务组为任务组名上传为文件上传路径
* @param task 任务
* @return {@code true}添加成功
*/
public boolean addTask(String key, AbsTask task) {
String hash = CommonUtil.keyToHashKey(key);
if (map.keySet().contains(hash)) {
Log.e(TAG, "任务【" + key + "】已存在");
return false;
}
map.put(CommonUtil.keyToHashKey(key), task);
return true;
}
/**
* 移除任务
*
* @param key 任务的key下载为保存路径任务组为任务组名上传为文件上传路径
*/
public void removeTask(String key) {
String hash = CommonUtil.keyToHashKey(key);
for (Iterator<Map.Entry<String, AbsTask>> iter = map.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, AbsTask> entry = iter.next();
if (entry.getKey().equals(hash)) iter.remove();
}
}
/**
* 通过key获取任务
*
* @return 入梅找不到任务返回null否则返回key对应的任务
*/
public AbsTask getTask(String key) {
return map.get(CommonUtil.keyToHashKey(key));
}
}

@ -27,7 +27,13 @@ import java.util.List;
* Created by AriaL on 2017/6/27.
* 删除所有任务并且删除所有回掉
*/
final class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
public class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
/**
* removeFile {@code true} 删除已经下载完成的任务不仅删除下载记录还会删除已经下载完成的文件{@code false}
* 如果文件已经下载完成只删除下载记录
*/
public boolean removeFile = false;
/**
* @param targetName 产生任务的对象名
*/
@ -39,7 +45,7 @@ final class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
removeAll();
if (mTaskEntity instanceof DownloadTaskEntity) {
handleDownloadRemove();
} else if (mTaskEntity instanceof UploadTaskEntity){
} else if (mTaskEntity instanceof UploadTaskEntity) {
handleUploadRemove();
}
}
@ -51,7 +57,7 @@ final class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
List<UploadTaskEntity> allEntity = DbEntity.findAllData(UploadTaskEntity.class);
if (allEntity == null || allEntity.size() == 0) return;
for (UploadTaskEntity entity : allEntity) {
CommonUtil.delUploadTaskConfig(mTaskEntity.removeFile, entity);
CommonUtil.delUploadTaskConfig(removeFile, entity);
}
}
@ -62,7 +68,7 @@ final class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
List<DownloadTaskEntity> allEntity = DbEntity.findAllData(DownloadTaskEntity.class);
if (allEntity == null || allEntity.size() == 0) return;
for (DownloadTaskEntity entity : allEntity) {
CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, entity);
CommonUtil.delDownloadTaskConfig(removeFile, entity);
}
}
}

@ -24,7 +24,13 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
* Created by lyy on 2016/9/20.
* 取消命令
*/
class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
public class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
/**
* removeFile {@code true} 删除已经下载完成的任务不仅删除下载记录还会删除已经下载完成的文件{@code false}
* 如果文件已经下载完成只删除下载记录
*/
public boolean removeFile = false;
CancelCmd(String targetName, T entity) {
super(targetName, entity);
}
@ -36,6 +42,7 @@ class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
task = createTask();
}
if (task != null) {
mTaskEntity.removeFile = removeFile;
if (!TextUtils.isEmpty(mTargetName)) {
task.setTargetName(mTargetName);
}

@ -161,8 +161,10 @@ abstract class BaseGroupTarget<TARGET extends AbsTarget, TASK_ENTITY extends Abs
List<DownloadEntity> entities = mEntity.getSubTask();
int i = 0;
for (DownloadEntity entity : entities) {
if (i < mSubTaskFileName.size()) {
String newName = mSubTaskFileName.get(i);
updateSubFileName(entity, newName);
}
i++;
}
}

@ -16,7 +16,9 @@
package com.arialyy.aria.core.download;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.normal.CancelAllCmd;
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.inf.AbsEntity;
@ -205,8 +207,10 @@ public class DownloadReceiver extends AbsReceiver {
*/
public DownloadTaskEntity getDownloadTask(String downloadUrl) {
CheckUtil.checkDownloadUrl(downloadUrl);
return DbEntity.findFirst(DownloadTaskEntity.class, "groupName=? and isGroupTask='false'",
downloadUrl);
DownloadEntity entity = getDownloadEntity(downloadUrl);
if (entity == null || TextUtils.isEmpty(entity.getDownloadPath())) return null;
return DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'",
entity.getDownloadPath());
}
/**
@ -295,9 +299,11 @@ public class DownloadReceiver extends AbsReceiver {
*/
@Override public void removeAllTask(boolean removeFile) {
final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP);
ariaManager.setCmd(CommonUtil.createCmd(targetName, new DownloadTaskEntity(),
NormalCmdFactory.TASK_CANCEL_ALL)).exe();
CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createCmd(targetName, new DownloadTaskEntity(),
NormalCmdFactory.TASK_CANCEL_ALL);
cancelCmd.removeFile = removeFile;
ariaManager.setCmd(cancelCmd).exe();
Set<String> keys = ariaManager.getReceiver().keySet();
for (String key : keys) {
ariaManager.getReceiver().remove(key);

@ -39,7 +39,7 @@ import java.util.concurrent.Executors;
* 任务组核心逻辑
*/
abstract class AbsGroupUtil implements IUtil {
private final String TAG = "DownloadGroupUtil";
private final String TAG = "AbsGroupUtil";
/**
* 任务组所有任务总大小
*/
@ -96,6 +96,7 @@ abstract class AbsGroupUtil implements IUtil {
DbEntity.findDatas(DownloadTaskEntity.class, "groupName=?", mTaskEntity.key);
if (tasks != null && !tasks.isEmpty()) {
for (DownloadTaskEntity te : tasks) {
te.removeFile = mTaskEntity.removeFile;
mTasksMap.put(te.getEntity().getUrl(), te);
}
}
@ -167,9 +168,21 @@ abstract class AbsGroupUtil implements IUtil {
private void delDownloadInfo() {
List<DownloadTaskEntity> tasks =
DbEntity.findDatas(DownloadTaskEntity.class, "groupName=?", mTaskEntity.key);
if (tasks == null || tasks.isEmpty()) return;
if (tasks != null && !tasks.isEmpty()) {
for (DownloadTaskEntity taskEntity : tasks) {
CommonUtil.delDownloadTaskConfig(taskEntity.removeFile, taskEntity);
CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, taskEntity);
}
}
File dir = new File(mTaskEntity.getEntity().getDirPath());
if (mTaskEntity.removeFile) {
if (dir.exists()) {
dir.delete();
}
} else {
if (!mTaskEntity.getEntity().isComplete()) {
dir.delete();
}
}
}

@ -19,8 +19,9 @@ import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.command.normal.CancelCmd;
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.util.CommonUtil;
import java.util.Map;
import java.util.Set;
@ -205,10 +206,10 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
* {@code false}如果任务已经完成只删除任务数据库记录
*/
public void cancel(boolean removeFile) {
mTaskEntity.removeFile = removeFile;
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL))
.exe();
CancelCmd cancelCmd =
(CancelCmd) CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL);
cancelCmd.removeFile = removeFile;
AriaManager.getInstance(AriaManager.APP).setCmd(cancelCmd).exe();
}
/**

@ -17,6 +17,7 @@ package com.arialyy.aria.core.inf;
import android.content.Context;
import android.os.Handler;
import com.arialyy.aria.orm.Ignore;
import com.arialyy.aria.util.CommonUtil;
/**
@ -35,7 +36,6 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
*/
private String mTargetName;
protected Context mContext;
protected boolean isHeighestTask = false;
/**

@ -27,10 +27,13 @@ import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.command.normal.AbsNormalCmd;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.orm.DbEntity;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
@ -214,7 +217,7 @@ public class CommonUtil {
}
/**
* 删除上传任务的配置包括
* 删除上传任务的配置
*
* @param removeFile {@code true} 不仅删除任务数据库记录还会删除已经删除完成的文件
* {@code false}如果任务已经完成只删除任务数据库记录
@ -236,7 +239,7 @@ public class CommonUtil {
}
/**
* 删除下载任务的配置包括
* 删除下载任务的配置
*
* @param removeFile {@code true} 不仅删除任务数据库记录还会删除已经下载完成的文件
* {@code false}如果任务已经完成只删除任务数据库记录

@ -28,8 +28,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.20'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.2.20'
compile 'com.arialyy.aria:aria-core:3.2.22'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.2.22'
```
***
@ -84,11 +84,11 @@ protected void onCreate(Bundle savedInstanceState) {
```
[更多注解使用方法](https://github.com/AriaLyy/Aria/wiki/%E6%B3%A8%E8%A7%A3%E4%BD%BF%E7%94%A8)
## [HTTP任务组下载\FTP下载;HTTP\FTP文件上传](https://github.com/AriaLyy/Aria/wiki/Aria%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8)
### [HTTP任务组下载\FTP下载;HTTP\FTP文件上传](https://github.com/AriaLyy/Aria/wiki/Aria%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8)
## [参数配置](https://github.com/AriaLyy/Aria/wiki/Aria%E5%8F%82%E6%95%B0%E9%85%8D%E7%BD%AE)
### [参数配置](https://github.com/AriaLyy/Aria/wiki/Aria%E5%8F%82%E6%95%B0%E9%85%8D%E7%BD%AE)
## [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki)
### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki)
## 混淆配置
```

@ -30,6 +30,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadTarget;
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.util.CommonUtil;
import com.arialyy.frame.util.show.L;

@ -83,7 +83,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
Aria.download(this).load(mUrls).stop();
break;
case R.id.cancel:
Aria.download(this).load(mUrls).cancel();
Aria.download(this).load(mUrls).cancel(true);
break;
}
}

@ -37,7 +37,7 @@ task clean(type: Delete) {
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = '3.2.22'
publishVersion = '3.2.23'
repoName='maven'
desc = 'android 下载框架'
website = 'https://github.com/AriaLyy/Aria'

Loading…
Cancel
Save