This commit is contained in:
AriaLyy
2017-07-06 17:48:11 +08:00
parent c2ab04b67b
commit 5533742855
11 changed files with 226 additions and 23 deletions

View File

@ -29,31 +29,57 @@ import java.util.List;
public class DownloadGroupTarget
extends AbsGroupTarget<DownloadGroupTarget, DownloadGroupEntity, DownloadGroupTaskEntity> {
private List<String> mUrls;
private String mGroupName;
DownloadGroupTarget(List<String> urls, String targetName) {
this.mTargetName = targetName;
this.mUrls = urls;
mTaskEntity =
DbEntity.findData(DownloadGroupTaskEntity.class, "key=?", CommonUtil.getMd5Code(urls));
mGroupName = CommonUtil.getMd5Code(urls);
mTaskEntity = DbEntity.findData(DownloadGroupTaskEntity.class, "key=?", mGroupName);
if (mTaskEntity == null) {
mTaskEntity = new DownloadGroupTaskEntity();
mTaskEntity.key = mGroupName;
mTaskEntity.entity = new DownloadGroupEntity();
}
if (mTaskEntity.entity == null) {
mTaskEntity.entity = getDownloadGroupEntity(urls);
mTaskEntity.entity = getDownloadGroupEntity();
}
mEntity = mTaskEntity.entity;
}
private DownloadGroupEntity getDownloadGroupEntity(List<String> urls) {
private DownloadGroupEntity getDownloadGroupEntity() {
DownloadGroupEntity entity =
DbEntity.findData(DownloadGroupEntity.class, "urlHash=?", CommonUtil.getMd5Code(urls));
DbEntity.findData(DownloadGroupEntity.class, "groupName=?", mGroupName);
if (entity == null) {
entity = new DownloadGroupEntity();
}
return entity;
}
/**
* 设置任务组的文件夹路径在Aria中任务组的所有子任务都会下载到以任务组组名的文件夹中。
* 如groupDirPath = "/mnt/sdcard/download/", groupName = "group_test"
* <pre>
* {@code
* + mnt
* + sdcard
* + download
* + group_test
* - task1.apk
* - task2.apk
* - task3.apk
* ....
*
* }
* </pre>
*
* @param groupDirPath 任务组保存文件夹路径
*/
public DownloadGroupTarget setDownloadPath(String groupDirPath) {
return this;
}
/**
* 设置保存路径组
*/

View File

@ -35,7 +35,7 @@ import java.util.concurrent.Executors;
* 任务组下载工具
*/
public class DownloadGroupUtil implements IDownloadUtil {
private static final String TAG = "DownloadGroupUtil";
private final String TAG = "DownloadGroupUtil";
/**
* 任务组所有任务总大小
*/

View File

@ -134,7 +134,7 @@ class Downloader implements Runnable, IDownloadUtil {
task.cancel();
}
}
CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, mEntity);
CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, mTaskEntity);
}
@Override public void stopDownload() {

View File

@ -19,7 +19,16 @@ package com.arialyy.aria.core.inf;
* Created by AriaL on 2017/6/29.
* 任务组超类
*/
public abstract class AbsGroupTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
public abstract class AbsGroupTarget<TARGET extends AbsGroupTarget, ENTITY extends AbsGroupEntity, TASK_ENTITY extends AbsTaskEntity>
extends AbsTarget<TARGET, ENTITY, TASK_ENTITY> {
/**
* 设置任务组的组名如果不设置任务组Aria会自动将任务组的所有子任务的key相加取md5码作为任务组组名
*
* @param groupName 任务组组名
*/
public TARGET setGroupName(String groupName) {
mEntity.setGroupName(groupName);
return (TARGET) this;
}
}