v3.7
laoyuyu 5 years ago
commit 651db90b99
  1. 10
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  2. 25
      Aria/src/main/java/com/arialyy/aria/core/command/CommandManager.java
  3. 9
      Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java
  4. 2
      Aria/src/main/java/com/arialyy/aria/core/common/BaseDelegate.java
  5. 14
      Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java
  6. 8
      Aria/src/main/java/com/arialyy/aria/core/common/RecordHandler.java
  7. 2
      Aria/src/main/java/com/arialyy/aria/core/common/RecordWrapper.java
  8. 2
      Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java
  9. 32
      Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java
  10. 2
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java
  11. 4
      Aria/src/main/java/com/arialyy/aria/core/download/AbsGroupConfigHandler.java
  12. 51
      Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java
  13. 10
      Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java
  14. 29
      Aria/src/main/java/com/arialyy/aria/core/download/CheckFtpDirEntityUtil.java
  15. 9
      Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java
  16. 10
      Aria/src/main/java/com/arialyy/aria/core/download/DNormalConfigHandler.java
  17. 8
      Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java
  18. 22
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  19. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java
  20. 15
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  21. 9
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  22. 12
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDirConfigHandler.java
  23. 6
      Aria/src/main/java/com/arialyy/aria/core/download/FtpNormalTarget.java
  24. 3
      Aria/src/main/java/com/arialyy/aria/core/download/FtpStartTarget.java
  25. 2
      Aria/src/main/java/com/arialyy/aria/core/download/GroupNormalTarget.java
  26. 2
      Aria/src/main/java/com/arialyy/aria/core/download/GroupStartTarget.java
  27. 16
      Aria/src/main/java/com/arialyy/aria/core/download/HttpGroupConfigHandler.java
  28. 1
      Aria/src/main/java/com/arialyy/aria/core/download/HttpNormalTarget.java
  29. 2
      Aria/src/main/java/com/arialyy/aria/core/download/HttpStartTarget.java
  30. 10
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java
  31. 20
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  32. 6
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java
  33. 22
      Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java
  34. 11
      Aria/src/main/java/com/arialyy/aria/core/download/group/ChildDLoadListener.java
  35. 5
      Aria/src/main/java/com/arialyy/aria/core/download/group/DGroupUtil.java
  36. 50
      Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java
  37. 7
      Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirInfoThread.java
  38. 6
      Aria/src/main/java/com/arialyy/aria/core/download/group/SubDLoadUtil.java
  39. 2
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java
  40. 2
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java
  41. 10
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java
  42. 8
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java
  43. 4
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java
  44. 26
      Aria/src/main/java/com/arialyy/aria/core/event/ErrorEvent.java
  45. 4
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java
  46. 3
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java
  47. 14
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskWrapper.java
  48. 18
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java
  49. 26
      Aria/src/main/java/com/arialyy/aria/core/inf/ICheckEntityUtil.java
  50. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java
  51. 14
      Aria/src/main/java/com/arialyy/aria/core/manager/DGTaskWrapperFactory.java
  52. 37
      Aria/src/main/java/com/arialyy/aria/core/manager/TaskWrapperManager.java
  53. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  54. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java
  55. 13
      Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java
  56. 5
      Aria/src/main/java/com/arialyy/aria/core/upload/UNormalConfigHandler.java
  57. 4
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
  58. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java
  59. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java
  60. 3
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java
  61. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  62. 3
      Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  63. 79
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  64. 35
      Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java
  65. 3
      DEV_LOG.md
  66. 1
      README.md
  67. 4
      app/src/main/assets/aria_config.xml
  68. 2
      app/src/main/assets/help_code/FtpDownload.java
  69. 36
      app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
  70. 15
      app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java
  71. 25
      app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  72. 43
      app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
  73. 56
      app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java
  74. 52
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  75. 2
      app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java
  76. 6
      app/src/main/java/com/arialyy/simple/core/download/multi_download/DownloadAdapter.java
  77. 4
      app/src/main/java/com/arialyy/simple/core/download/multi_download/MultiTaskActivity.java
  78. 55
      app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java
  79. 2
      app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java
  80. 35
      app/src/main/res/values/strings.xml
  81. 2
      build.gradle

@ -161,13 +161,11 @@ import org.xml.sax.SAXException;
* 初始化数据库 * 初始化数据库
*/ */
private void initDb(Context context) { private void initDb(Context context) {
// 这个地方错误了,获取数据库路径见:https://www.jianshu.com/p/815c9efc5449
String oldDbName = "AriaLyyDb"; String oldDbName = "AriaLyyDb";
String oldDbPath = context.getDatabasePath(oldDbName).getPath(); File oldDbFile = context.getDatabasePath(oldDbName);
File db = new File(oldDbPath); if (oldDbFile != null && oldDbFile.exists()) {
File dbConfig = new File(String.format("%s/%s", db.getParent(), "AriaLyyDb-journal")); File dbConfig = new File(String.format("%s/%s", oldDbFile.getParent(), "AriaLyyDb-journal"));
if (db.exists()) { oldDbFile.renameTo(new File(String.format("%s/%s", oldDbFile.getParent(), "AndroidAria.db")));
db.renameTo(new File(String.format("%s/%s", db.getParent(), "AndroidAria.db")));
// 如果数据库是在/data/data/{packagename}/databases/下面,journal文件因权限问题将无法删除和重命名 // 如果数据库是在/data/data/{packagename}/databases/下面,journal文件因权限问题将无法删除和重命名
if (dbConfig.exists()) { if (dbConfig.exists()) {
dbConfig.delete(); dbConfig.delete();

@ -43,7 +43,7 @@ public class CommandManager {
@Event @Event
public void add(AddCmd cmd) { public void add(AddCmd cmd) {
if (CommonUtil.isFastDoubleClick()){ if (CommonUtil.isFastDoubleClick()) {
return; return;
} }
cmd.executeCmd(); cmd.executeCmd();
@ -51,7 +51,7 @@ public class CommandManager {
@Event @Event
public void start(StartCmd cmd) { public void start(StartCmd cmd) {
if (CommonUtil.isFastDoubleClick()){ if (CommonUtil.isFastDoubleClick()) {
return; return;
} }
cmd.executeCmd(); cmd.executeCmd();
@ -59,23 +59,17 @@ public class CommandManager {
@Event @Event
public void stop(StopCmd cmd) { public void stop(StopCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
return;
}
cmd.executeCmd(); cmd.executeCmd();
} }
@Event @Event
public void cancel(CancelCmd cmd) { public void cancel(CancelCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
return;
}
cmd.executeCmd(); cmd.executeCmd();
} }
@Event @Event
public void stopAll(StopAllCmd cmd) { public void stopAll(StopAllCmd cmd) {
if (CommonUtil.isFastDoubleClick()){ if (CommonUtil.isFastDoubleClick()) {
return; return;
} }
cmd.executeCmd(); cmd.executeCmd();
@ -83,7 +77,7 @@ public class CommandManager {
@Event @Event
public void cancelAll(CancelAllCmd cmd) { public void cancelAll(CancelAllCmd cmd) {
if (CommonUtil.isFastDoubleClick()){ if (CommonUtil.isFastDoubleClick()) {
return; return;
} }
cmd.executeCmd(); cmd.executeCmd();
@ -91,7 +85,7 @@ public class CommandManager {
@Event @Event
public void reStart(ReStartCmd cmd) { public void reStart(ReStartCmd cmd) {
if (CommonUtil.isFastDoubleClick()){ if (CommonUtil.isFastDoubleClick()) {
return; return;
} }
cmd.executeCmd(); cmd.executeCmd();
@ -99,7 +93,7 @@ public class CommandManager {
@Event @Event
public void highestPriority(HighestPriorityCmd cmd) { public void highestPriority(HighestPriorityCmd cmd) {
if (CommonUtil.isFastDoubleClick()){ if (CommonUtil.isFastDoubleClick()) {
return; return;
} }
cmd.executeCmd(); cmd.executeCmd();
@ -107,7 +101,7 @@ public class CommandManager {
@Event @Event
public void resumeAll(ResumeAllCmd cmd) { public void resumeAll(ResumeAllCmd cmd) {
if (CommonUtil.isFastDoubleClick()){ if (CommonUtil.isFastDoubleClick()) {
return; return;
} }
cmd.executeCmd(); cmd.executeCmd();
@ -115,7 +109,7 @@ public class CommandManager {
@Event @Event
public void subStart(DGSubStartCmd cmd) { public void subStart(DGSubStartCmd cmd) {
if (CommonUtil.isFastDoubleClick()){ if (CommonUtil.isFastDoubleClick()) {
return; return;
} }
cmd.executeCmd(); cmd.executeCmd();
@ -123,9 +117,6 @@ public class CommandManager {
@Event @Event
public void subStop(DGSubStopCmd cmd) { public void subStop(DGSubStopCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
return;
}
cmd.executeCmd(); cmd.executeCmd();
} }
} }

@ -25,6 +25,7 @@ import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.manager.TaskWrapperManager; import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
@ -135,9 +136,9 @@ final class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
DbEntity.findDatas(DownloadGroupEntity.class, "state=?", "3"); DbEntity.findDatas(DownloadGroupEntity.class, "state=?", "3");
if (dEntities != null && !dEntities.isEmpty()) { if (dEntities != null && !dEntities.isEmpty()) {
for (DownloadGroupEntity e : dEntities) { for (DownloadGroupEntity e : dEntities) {
if (e.getTaskType() == AbsTaskWrapper.DG_HTTP) { if (e.getTaskType() == ITaskWrapper.DG_HTTP) {
waitList.add(tManager.getGroupWrapper(DGTaskWrapper.class, e.getId())); waitList.add(tManager.getGroupWrapper(DGTaskWrapper.class, e.getId()));
} else if (e.getTaskType() == AbsTaskWrapper.D_FTP_DIR) { } else if (e.getTaskType() == ITaskWrapper.D_FTP_DIR) {
waitList.add(tManager.getGroupWrapper(DGTaskWrapper.class, e.getId())); waitList.add(tManager.getGroupWrapper(DGTaskWrapper.class, e.getId()));
} }
} }
@ -160,8 +161,8 @@ final class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
AbsTask task = getTask(te.getKey()); AbsTask task = getTask(te.getKey());
if (task != null) continue; if (task != null) continue;
if (te instanceof DTaskWrapper) { if (te instanceof DTaskWrapper) {
if (te.getRequestType() == AbsTaskWrapper.D_FTP if (te.getRequestType() == ITaskWrapper.D_FTP
|| te.getRequestType() == AbsTaskWrapper.U_FTP) { || te.getRequestType() == ITaskWrapper.U_FTP) {
te.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey())); te.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey()));
} }
mQueue = DownloadTaskQueue.getInstance(); mQueue = DownloadTaskQueue.getInstance();

@ -45,7 +45,7 @@ public abstract class BaseDelegate<TARGET extends AbsTarget> {
* @param clazz {@link ControllerType#START_CONTROLLER}{@link ControllerType#NORMAL_CONTROLLER} * @param clazz {@link ControllerType#START_CONTROLLER}{@link ControllerType#NORMAL_CONTROLLER}
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public <T extends FeatureController> T controller(@ControllerType Class<T> clazz) { public synchronized <T extends FeatureController> T controller(@ControllerType Class<T> clazz) {
return FeatureController.newInstance(clazz, getTaskWrapper()); return FeatureController.newInstance(clazz, getTaskWrapper());
} }
} }

@ -16,8 +16,6 @@
package com.arialyy.aria.core.common; package com.arialyy.aria.core.common;
import android.os.Handler; import android.os.Handler;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.AbsTaskWrapper;
@ -26,12 +24,10 @@ import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.core.inf.ITaskWrapper; import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp; import com.arialyy.aria.util.ErrorHelp;
import com.arialyy.aria.util.RecordUtil;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
public abstract class BaseListener<ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>, public abstract class BaseListener<ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>,
@ -156,16 +152,6 @@ public abstract class BaseListener<ENTITY extends AbsEntity, TASK_WRAPPER extend
mEntity.setCurrentProgress(mEntity.getFileSize()); mEntity.setCurrentProgress(mEntity.getFileSize());
mEntity.setPercent(100); mEntity.setPercent(100);
handleSpeed(0); handleSpeed(0);
ALog.i(TAG, String.format("任务【%s】完成,将删除任务任务记录", mEntity.getKey()));
if (mEntity instanceof DownloadGroupEntity) {
RecordUtil.delGroupTaskRecord((DownloadGroupEntity) mEntity, false, false);
} else if (mEntity instanceof DownloadEntity) {
RecordUtil.delTaskRecord(((DownloadEntity) mEntity).getFilePath(),
RecordHandler.TYPE_DOWNLOAD, false, false);
} else if (mEntity instanceof UploadEntity) {
RecordUtil.delTaskRecord(((UploadEntity) mEntity).getFilePath(), RecordHandler.TYPE_UPLOAD,
false, false);
}
} }
/** /**

@ -152,7 +152,7 @@ public class RecordHandler {
ThreadRecord tr = mTaskRecord.threadRecords.get(0); ThreadRecord tr = mTaskRecord.threadRecords.get(0);
tr.startLocation = 0; tr.startLocation = 0;
tr.endLocation = mEntity.getFileSize(); tr.endLocation = mEntity.getFileSize();
tr.key = mTaskRecord.filePath; tr.taskKey = mTaskRecord.filePath;
tr.blockLen = tr.endLocation; tr.blockLen = tr.endLocation;
tr.isComplete = false; tr.isComplete = false;
} }
@ -164,7 +164,7 @@ public class RecordHandler {
File file = new File(mTaskRecord.filePath); File file = new File(mTaskRecord.filePath);
if (!file.exists()) { if (!file.exists()) {
ALog.w(TAG, String.format("文件【%s】不存在,重新分配线程区间", mTaskRecord.filePath)); ALog.w(TAG, String.format("文件【%s】不存在,重新分配线程区间", mTaskRecord.filePath));
DbEntity.deleteData(ThreadRecord.class, "key=?", mTaskRecord.filePath); DbEntity.deleteData(ThreadRecord.class, "taskKey=?", mTaskRecord.filePath);
initRecord(false); initRecord(false);
} }
} }
@ -290,7 +290,7 @@ public class RecordHandler {
File tempFile = new File(getFilePath()); File tempFile = new File(getFilePath());
for (int i = 0; i < threadNum; i++) { for (int i = 0; i < threadNum; i++) {
ThreadRecord tRecord = new ThreadRecord(); ThreadRecord tRecord = new ThreadRecord();
tRecord.key = mTaskRecord.filePath; tRecord.taskKey = mTaskRecord.filePath;
Object state = pro.getProperty(tempFile.getName() + STATE + i); Object state = pro.getProperty(tempFile.getName() + STATE + i);
Object record = pro.getProperty(tempFile.getName() + RECORD + i); Object record = pro.getProperty(tempFile.getName() + RECORD + i);
if (state != null && Integer.parseInt(String.valueOf(state)) == 1) { if (state != null && Integer.parseInt(String.valueOf(state)) == 1) {
@ -329,7 +329,7 @@ public class RecordHandler {
long startL = i * blockSize, endL = (i + 1) * blockSize; long startL = i * blockSize, endL = (i + 1) * blockSize;
ThreadRecord tr; ThreadRecord tr;
tr = new ThreadRecord(); tr = new ThreadRecord();
tr.key = mTaskRecord.filePath; tr.taskKey = mTaskRecord.filePath;
tr.threadId = i; tr.threadId = i;
tr.startLocation = startL; tr.startLocation = startL;
tr.isComplete = false; tr.isComplete = false;

@ -32,7 +32,7 @@ public class RecordWrapper extends AbsDbWrapper {
@One @One
public TaskRecord taskRecord; public TaskRecord taskRecord;
@Many(parentColumn = "filePath", entityColumn = "key") @Many(parentColumn = "filePath", entityColumn = "taskKey")
public List<ThreadRecord> threadRecords; public List<ThreadRecord> threadRecords;
@Override protected void handleConvert() { @Override protected void handleConvert() {

@ -26,7 +26,7 @@ public class ThreadRecord extends DbEntity {
/** /**
* 任务的文件路径不是当前线程记录的的分块文件路径 * 任务的文件路径不是当前线程记录的的分块文件路径
*/ */
public String key; public String taskKey;
/** /**
* 开始位置 * 开始位置

@ -24,12 +24,16 @@ import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.scheduler.UploadSchedulers; import com.arialyy.aria.core.scheduler.UploadSchedulers;
import com.arialyy.aria.core.upload.CheckUEntityUtil; import com.arialyy.aria.core.upload.CheckUEntityUtil;
import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.util.ALog;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -57,7 +61,8 @@ public abstract class FeatureController {
throw new IllegalArgumentException("对于不存在的任务(第一次下载),只能使用\"ControllerType.START_CONTROLLER\""); throw new IllegalArgumentException("对于不存在的任务(第一次下载),只能使用\"ControllerType.START_CONTROLLER\"");
} }
if (wrapper.getEntity().getId() != -1 && clazz != ControllerType.NORMAL_CONTROLLER) { if (wrapper.getEntity().getId() != -1 && clazz != ControllerType.NORMAL_CONTROLLER) {
throw new IllegalArgumentException("对于已存在的任务,只能使用\" ControllerType.NORMAL_CONTROLLER\""); throw new IllegalArgumentException(
"对于已存在的任务,只能使用\" ControllerType.NORMAL_CONTROLLER\",请检查是否重复调用#start()方法");
} }
Class[] paramTypes = { AbsTaskWrapper.class }; Class[] paramTypes = { AbsTaskWrapper.class };
@ -119,27 +124,24 @@ public abstract class FeatureController {
return UploadSchedulers.getInstance(); return UploadSchedulers.getInstance();
} }
if (mTaskWrapper instanceof DGTaskWrapper) { if (mTaskWrapper instanceof DGTaskWrapper) {
return DownloadSchedulers.getInstance(); return DownloadGroupSchedulers.getInstance();
} }
return null; return null;
} }
private boolean checkEntity() { private boolean checkEntity() {
ICheckEntityUtil checkUtil = null;
if (mTaskWrapper instanceof DTaskWrapper) { if (mTaskWrapper instanceof DTaskWrapper) {
return CheckDEntityUtil.newInstance((DTaskWrapper) mTaskWrapper).checkEntity(); checkUtil = CheckDEntityUtil.newInstance((DTaskWrapper) mTaskWrapper);
} } else if (mTaskWrapper instanceof DGTaskWrapper) {
if (mTaskWrapper instanceof DGTaskWrapper) { if (mTaskWrapper.getRequestType() == ITaskWrapper.D_FTP_DIR) {
if (mTaskWrapper.getRequestType() == AbsTaskWrapper.D_FTP_DIR) { checkUtil = CheckFtpDirEntityUtil.newInstance((DGTaskWrapper) mTaskWrapper);
return CheckFtpDirEntityUtil.newInstance((DGTaskWrapper) mTaskWrapper).checkEntity(); } else if (mTaskWrapper.getRequestType() == ITaskWrapper.DG_HTTP) {
} checkUtil = CheckDGEntityUtil.newInstance((DGTaskWrapper) mTaskWrapper);
if (mTaskWrapper.getRequestType() == AbsTaskWrapper.DG_HTTP) {
return CheckDGEntityUtil.newInstance((DGTaskWrapper) mTaskWrapper).checkEntity();
} }
} else if (mTaskWrapper instanceof UTaskWrapper) {
checkUtil = CheckUEntityUtil.newInstance((UTaskWrapper) mTaskWrapper);
} }
if (mTaskWrapper instanceof UTaskWrapper) { return checkUtil != null && checkUtil.checkEntity();
return CheckUEntityUtil.newInstance((UTaskWrapper) mTaskWrapper).checkEntity();
}
return false;
} }
} }

@ -384,7 +384,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
protected void handleFile(String remotePath, FTPFile ftpFile) { protected void handleFile(String remotePath, FTPFile ftpFile) {
} }
private void failDownload(BaseException e, boolean needRetry) { protected void failDownload(BaseException e, boolean needRetry) {
if (mCallback != null) { if (mCallback != null) {
mCallback.onFail(mEntity, e, needRetry); mCallback.onFail(mEntity, e, needRetry);
} }

@ -17,6 +17,7 @@ package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult; import android.support.annotation.CheckResult;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.event.ErrorEvent;
import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IConfigHandler; import com.arialyy.aria.core.inf.IConfigHandler;
import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.core.manager.SubTaskManager;
@ -40,6 +41,9 @@ abstract class AbsGroupConfigHandler<TARGET extends AbsTarget> implements IConfi
TAG = CommonUtil.getClassName(getClass()); TAG = CommonUtil.getClassName(getClass());
mTarget = target; mTarget = target;
mWrapper = TaskWrapperManager.getInstance().getGroupWrapper(DGTaskWrapper.class, taskId); mWrapper = TaskWrapperManager.getInstance().getGroupWrapper(DGTaskWrapper.class, taskId);
if (taskId != -1 && mWrapper.getEntity().getId() == -1) {
mWrapper.setErrorEvent(new ErrorEvent(taskId, String.format("没有id为%s的任务", taskId)));
}
mTarget.setTaskWrapper(mWrapper); mTarget.setTaskWrapper(mWrapper);
if (getEntity() != null) { if (getEntity() != null) {
getTaskWrapper().setDirPathTemp(getEntity().getDirPath()); getTaskWrapper().setDirPathTemp(getEntity().getDirPath());

@ -17,6 +17,8 @@ package com.arialyy.aria.core.download;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.common.RecordHandler; import com.arialyy.aria.core.common.RecordHandler;
import com.arialyy.aria.core.download.m3u8.M3U8Entity;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.core.inf.ITargetHandler; import com.arialyy.aria.core.inf.ITargetHandler;
import com.arialyy.aria.core.inf.ITaskWrapper; import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
@ -28,7 +30,7 @@ import java.io.File;
/** /**
* 检查下载任务实体 * 检查下载任务实体
*/ */
public class CheckDEntityUtil { public class CheckDEntityUtil implements ICheckEntityUtil {
private final String TAG = "CheckDLoadEntity"; private final String TAG = "CheckDLoadEntity";
private DTaskWrapper mWrapper; private DTaskWrapper mWrapper;
private DownloadEntity mEntity; private DownloadEntity mEntity;
@ -42,7 +44,13 @@ public class CheckDEntityUtil {
mEntity = mWrapper.getEntity(); mEntity = mWrapper.getEntity();
} }
@Override
public boolean checkEntity() { public boolean checkEntity() {
if (mWrapper.getErrorEvent() != null) {
ALog.e(TAG, mWrapper.getErrorEvent().errorMsg);
return false;
}
boolean b = checkFtps() && checkUrl() && checkFilePath(); boolean b = checkFtps() && checkUrl() && checkFilePath();
if (b) { if (b) {
mEntity.save(); mEntity.save();
@ -55,12 +63,19 @@ public class CheckDEntityUtil {
} }
private void handleM3U8() { private void handleM3U8() {
File file = new File(mWrapper.getmTempFilePath()); File file = new File(mWrapper.getTempFilePath());
// 缓存文件夹格式:问文件夹/.文件名_码率 // 缓存文件夹格式:问文件夹/.文件名_码率
String cacheDir = String.format("%s/.%s_%s", file.getParent(), file.getName(), String cacheDir = String.format("%s/.%s_%s", file.getParent(), file.getName(),
mWrapper.asM3U8().getBandWidth()); mWrapper.asM3U8().getBandWidth());
mWrapper.asM3U8().setCacheDir(cacheDir); mWrapper.asM3U8().setCacheDir(cacheDir);
mEntity.getM3U8Entity().setCacheDir(cacheDir); M3U8Entity m3U8Entity = mEntity.getM3U8Entity();
if (m3U8Entity == null) {
m3U8Entity = new M3U8Entity();
m3U8Entity.setFilePath(mEntity.getFilePath());
m3U8Entity.setPeerIndex(0);
m3U8Entity.setCacheDir(cacheDir);
m3U8Entity.insert();
}
if (mWrapper.getRequestType() == ITaskWrapper.M3U8_VOD) { if (mWrapper.getRequestType() == ITaskWrapper.M3U8_VOD) {
if (mEntity.getFileSize() == 0) { if (mEntity.getFileSize() == 0) {
ALog.w(TAG, ALog.w(TAG,
@ -80,7 +95,7 @@ public class CheckDEntityUtil {
} }
private boolean checkFilePath() { private boolean checkFilePath() {
String filePath = mWrapper.getmTempFilePath(); String filePath = mWrapper.getTempFilePath();
if (TextUtils.isEmpty(filePath)) { if (TextUtils.isEmpty(filePath)) {
ALog.e(TAG, "下载失败,文件保存路径为null"); ALog.e(TAG, "下载失败,文件保存路径为null");
return false; return false;
@ -124,7 +139,7 @@ public class CheckDEntityUtil {
RecordUtil.delTaskRecord(filePath, RecordHandler.TYPE_DOWNLOAD); RecordUtil.delTaskRecord(filePath, RecordHandler.TYPE_DOWNLOAD);
} }
} }
File oldFile = new File(mEntity.getFilePath());
File newFile = new File(filePath); File newFile = new File(filePath);
mEntity.setFilePath(filePath); mEntity.setFilePath(filePath);
mEntity.setFileName(newFile.getName()); mEntity.setFileName(newFile.getName());
@ -134,14 +149,17 @@ public class CheckDEntityUtil {
|| mWrapper.getRequestType() == ITaskWrapper.M3U8_LIVE) { || mWrapper.getRequestType() == ITaskWrapper.M3U8_LIVE) {
return true; return true;
} }
if (oldFile.exists()) { if (!TextUtils.isEmpty(mEntity.getFilePath())) {
// 处理普通任务的重命名 File oldFile = new File(mEntity.getFilePath());
RecordUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath()); if (oldFile.exists()) {
ALog.i(TAG, String.format("将任务重命名为:%s", newFile.getName())); // 处理普通任务的重命名
} else if (RecordUtil.blockTaskExists(oldFile.getPath())) { RecordUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath());
// 处理分块任务的重命名 ALog.i(TAG, String.format("将任务重命名为:%s", newFile.getName()));
RecordUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath()); } else if (RecordUtil.blockTaskExists(oldFile.getPath())) {
ALog.i(TAG, String.format("将分块任务重命名为:%s", newFile.getName())); // 处理分块任务的重命名
RecordUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath());
ALog.i(TAG, String.format("将分块任务重命名为:%s", newFile.getName()));
}
} }
} }
return true; return true;
@ -161,14 +179,15 @@ public class CheckDEntityUtil {
ALog.e(TAG, "下载失败,url【" + url + "】不合法"); ALog.e(TAG, "下载失败,url【" + url + "】不合法");
return false; return false;
} }
if (!TextUtils.isEmpty(mWrapper.getmTempUrl())) { if (!TextUtils.isEmpty(mWrapper.getTempUrl())) {
mEntity.setUrl(mWrapper.getmTempUrl()); mEntity.setUrl(mWrapper.getTempUrl());
} }
return true; return true;
} }
private boolean checkFtps() { private boolean checkFtps() {
if (mWrapper.asFtp().getUrlEntity().isFtps) { if (mWrapper.getRequestType() == ITaskWrapper.D_FTP && mWrapper.asFtp()
.getUrlEntity().isFtps) {
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) { if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) {
ALog.e(TAG, "证书路径为空"); ALog.e(TAG, "证书路径为空");
return false; return false;

@ -17,6 +17,7 @@ package com.arialyy.aria.core.download;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -28,7 +29,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public class CheckDGEntityUtil { public class CheckDGEntityUtil implements ICheckEntityUtil {
private final String TAG = "CheckDGEntityUtil"; private final String TAG = "CheckDGEntityUtil";
private DGTaskWrapper mWrapper; private DGTaskWrapper mWrapper;
@ -108,7 +109,13 @@ public class CheckDGEntityUtil {
} }
} }
@Override
public boolean checkEntity() { public boolean checkEntity() {
if (mWrapper.getErrorEvent() != null) {
ALog.e(TAG, mWrapper.getErrorEvent().errorMsg);
return false;
}
if (!checkDirPath()) { if (!checkDirPath()) {
return false; return false;
} }
@ -183,7 +190,6 @@ public class CheckDGEntityUtil {
*/ */
private boolean checkUrls() { private boolean checkUrls() {
if (mEntity.getUrls().isEmpty()) { if (mEntity.getUrls().isEmpty()) {
ALog.e(TAG, "下载失败,子任务下载列表为null"); ALog.e(TAG, "下载失败,子任务下载列表为null");
return false; return false;
} }

@ -16,12 +16,12 @@
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import java.io.File; import java.io.File;
public class CheckFtpDirEntityUtil { public class CheckFtpDirEntityUtil implements ICheckEntityUtil {
private final String TAG = "CheckFtpDirEntityUtil"; private final String TAG = "CheckFtpDirEntityUtil";
private DGTaskWrapper mWrapper; private DGTaskWrapper mWrapper;
private DownloadGroupEntity mEntity; private DownloadGroupEntity mEntity;
@ -72,29 +72,16 @@ public class CheckFtpDirEntityUtil {
return true; return true;
} }
@Override
public boolean checkEntity() { public boolean checkEntity() {
if (mWrapper.getErrorEvent() != null) {
ALog.e(TAG, mWrapper.getErrorEvent().errorMsg);
return false;
}
boolean b = checkDirPath() && checkUrl(); boolean b = checkDirPath() && checkUrl();
if (b) { if (b) {
mEntity.save(); mEntity.save();
if (mWrapper.getSubTaskWrapper() != null) {
//初始化子项的登录信息
FtpUrlEntity tUrlEntity = mWrapper.asFtp().getUrlEntity();
for (DTaskWrapper wrapper : mWrapper.getSubTaskWrapper()) {
FtpUrlEntity urlEntity = wrapper.asFtp().getUrlEntity();
urlEntity.needLogin = tUrlEntity.needLogin;
urlEntity.account = tUrlEntity.account;
urlEntity.user = tUrlEntity.user;
urlEntity.password = tUrlEntity.password;
// 处理ftps详细
if (tUrlEntity.isFtps) {
urlEntity.isFtps = true;
urlEntity.protocol = tUrlEntity.protocol;
urlEntity.storePath = tUrlEntity.storePath;
urlEntity.storePass = tUrlEntity.storePass;
urlEntity.keyAlias = tUrlEntity.keyAlias;
}
}
}
} }
if (mWrapper.asFtp().getUrlEntity().isFtps) { if (mWrapper.asFtp().getUrlEntity().isFtps) {
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) { if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) {

@ -26,7 +26,7 @@ import java.util.List;
*/ */
public class DGTaskWrapper extends AbsGroupTaskWrapper<DownloadGroupEntity, DTaskWrapper> { public class DGTaskWrapper extends AbsGroupTaskWrapper<DownloadGroupEntity, DTaskWrapper> {
private List<DTaskWrapper> subTaskEntities; private List<DTaskWrapper> subWrappers;
private boolean unknownSize = false; private boolean unknownSize = false;
@ -62,7 +62,7 @@ public class DGTaskWrapper extends AbsGroupTaskWrapper<DownloadGroupEntity, DTas
@Override @Override
public void setSubTaskWrapper(List<DTaskWrapper> subTaskEntities) { public void setSubTaskWrapper(List<DTaskWrapper> subTaskEntities) {
this.subTaskEntities = subTaskEntities; this.subWrappers = subTaskEntities;
} }
public boolean isUnknownSize() { public boolean isUnknownSize() {
@ -82,6 +82,9 @@ public class DGTaskWrapper extends AbsGroupTaskWrapper<DownloadGroupEntity, DTas
} }
@Override public List<DTaskWrapper> getSubTaskWrapper() { @Override public List<DTaskWrapper> getSubTaskWrapper() {
return subTaskEntities; if (subWrappers == null) {
subWrappers = new ArrayList<>();
}
return subWrappers;
} }
} }

@ -16,6 +16,7 @@
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.event.ErrorEvent;
import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IConfigHandler; import com.arialyy.aria.core.inf.IConfigHandler;
import com.arialyy.aria.core.manager.TaskWrapperManager; import com.arialyy.aria.core.manager.TaskWrapperManager;
@ -49,12 +50,15 @@ class DNormalConfigHandler<TARGET extends AbsTarget> implements IConfigHandler {
private void initTarget(long taskId, String targetName) { private void initTarget(long taskId, String targetName) {
mWrapper = TaskWrapperManager.getInstance().getNormalTaskWrapper(DTaskWrapper.class, taskId); mWrapper = TaskWrapperManager.getInstance().getNormalTaskWrapper(DTaskWrapper.class, taskId);
if (taskId != -1 && mWrapper.getEntity().getId() == -1) {
mWrapper.setErrorEvent(new ErrorEvent(taskId, String.format("没有id为%s的任务", taskId)));
}
mEntity = mWrapper.getEntity(); mEntity = mWrapper.getEntity();
mTarget.setTargetName(targetName); mTarget.setTargetName(targetName);
mTarget.setTaskWrapper(mWrapper); mTarget.setTaskWrapper(mWrapper);
if (mEntity != null) { if (mEntity != null) {
getWrapper().setmTempFilePath(mEntity.getFilePath()); getWrapper().setTempFilePath(mEntity.getFilePath());
} }
} }
@ -68,7 +72,7 @@ class DNormalConfigHandler<TARGET extends AbsTarget> implements IConfigHandler {
return mTarget; return mTarget;
} }
getWrapper().setRefreshInfo(true); getWrapper().setRefreshInfo(true);
getWrapper().setmTempUrl(newUrl); getWrapper().setTempUrl(newUrl);
return mTarget; return mTarget;
} }
@ -98,7 +102,7 @@ class DNormalConfigHandler<TARGET extends AbsTarget> implements IConfigHandler {
} }
void setTempFilePath(String tempFilePath) { void setTempFilePath(String tempFilePath) {
getWrapper().setmTempFilePath(tempFilePath); getWrapper().setTempFilePath(tempFilePath);
} }
private DTaskWrapper getWrapper() { private DTaskWrapper getWrapper() {

@ -93,19 +93,19 @@ public class DTaskWrapper extends AbsTaskWrapper<DownloadEntity> {
isGroupTask = groupTask; isGroupTask = groupTask;
} }
public String getmTempUrl() { public String getTempUrl() {
return mTempUrl; return mTempUrl;
} }
public void setmTempUrl(String mTempUrl) { public void setTempUrl(String mTempUrl) {
this.mTempUrl = mTempUrl; this.mTempUrl = mTempUrl;
} }
public String getmTempFilePath() { public String getTempFilePath() {
return mTempFilePath; return mTempFilePath;
} }
public void setmTempFilePath(String mTempFilePath) { public void setTempFilePath(String mTempFilePath) {
this.mTempFilePath = mTempFilePath; this.mTempFilePath = mTempFilePath;
} }

@ -21,7 +21,7 @@ import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.download.m3u8.M3U8Entity; import com.arialyy.aria.core.download.m3u8.M3U8Entity;
import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.annotation.Ignore; import com.arialyy.aria.orm.annotation.Ignore;
import com.arialyy.aria.orm.annotation.Unique; import com.arialyy.aria.orm.annotation.Unique;
@ -67,13 +67,6 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
if (m3U8Entity == null) { if (m3U8Entity == null) {
m3U8Entity = DbEntity.findFirst(M3U8Entity.class, "filePath=?", downloadPath); m3U8Entity = DbEntity.findFirst(M3U8Entity.class, "filePath=?", downloadPath);
} }
if (m3U8Entity == null) {
m3U8Entity = new M3U8Entity();
m3U8Entity.setFilePath(downloadPath);
m3U8Entity.setPeerIndex(0);
m3U8Entity.insert();
}
return m3U8Entity; return m3U8Entity;
} }
@ -82,7 +75,18 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
} }
@Override public int getTaskType() { @Override public int getTaskType() {
return getUrl().startsWith("ftp") ? AbsTaskWrapper.D_FTP : AbsTaskWrapper.D_HTTP; int type;
if (getUrl().startsWith("ftp")) {
type = ITaskWrapper.D_FTP;
} else {
M3U8Entity temp = getM3U8Entity();
if (temp == null) {
type = ITaskWrapper.D_HTTP;
} else {
type = temp.isLive() ? ITaskWrapper.M3U8_LIVE : ITaskWrapper.M3U8_VOD;
}
}
return type;
} }
public DownloadEntity() { public DownloadEntity() {

@ -19,6 +19,7 @@ import android.os.Parcel;
import com.arialyy.aria.core.inf.AbsGroupEntity; import com.arialyy.aria.core.inf.AbsGroupEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.orm.annotation.Ignore; import com.arialyy.aria.orm.annotation.Ignore;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -32,6 +33,9 @@ public class DownloadGroupEntity extends AbsGroupEntity {
* 子任务实体列表 * 子任务实体列表
*/ */
public List<DownloadEntity> getSubEntities() { public List<DownloadEntity> getSubEntities() {
if (subEntities == null) {
subEntities = new ArrayList<>();
}
return subEntities; return subEntities;
} }

@ -24,7 +24,7 @@ import com.arialyy.aria.core.download.group.DGroupUtil;
import com.arialyy.aria.core.download.group.FtpDirDownloadUtil; import com.arialyy.aria.core.download.group.FtpDirDownloadUtil;
import com.arialyy.aria.core.download.group.IDGroupListener; import com.arialyy.aria.core.download.group.IDGroupListener;
import com.arialyy.aria.core.inf.AbsGroupTask; import com.arialyy.aria.core.inf.AbsGroupTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
@ -55,13 +55,14 @@ public class DownloadGroupTask extends AbsGroupTask<DGTaskWrapper> {
} }
@Override protected synchronized IUtil createUtil() { @Override protected synchronized IUtil createUtil() {
switch (mTaskWrapper.getRequestType()) { int taskType = mTaskWrapper.getRequestType();
case AbsTaskWrapper.D_HTTP: if (taskType == ITaskWrapper.DG_HTTP) {
return new DGroupUtil((IDGroupListener) mListener, mTaskWrapper); return new DGroupUtil((IDGroupListener) mListener, mTaskWrapper);
case AbsTaskWrapper.D_FTP_DIR: } else if (taskType == ITaskWrapper.D_FTP_DIR) {
return new FtpDirDownloadUtil((IDGroupListener) mListener, mTaskWrapper); return new FtpDirDownloadUtil((IDGroupListener) mListener, mTaskWrapper);
} else {
throw new IllegalArgumentException(String.format("不识别的任务, 任务类型:%s", taskType));
} }
return null;
} }
public static class Builder { public static class Builder {

@ -95,12 +95,15 @@ public class DownloadTask extends AbsNormalTask<DTaskWrapper> {
} }
@Override protected synchronized IUtil createUtil() { @Override protected synchronized IUtil createUtil() {
if (mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_VOD) { int taskType = mTaskWrapper.getRequestType();
if (taskType == ITaskWrapper.M3U8_VOD) {
return new M3U8VodUtil(mTaskWrapper, (M3U8Listener) mListener); return new M3U8VodUtil(mTaskWrapper, (M3U8Listener) mListener);
} else if (mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_LIVE) { } else if (taskType == ITaskWrapper.M3U8_LIVE) {
return new M3U8LiveUtil(mTaskWrapper, (M3U8Listener) mListener); return new M3U8LiveUtil(mTaskWrapper, (M3U8Listener) mListener);
} else { } else if (taskType == ITaskWrapper.D_HTTP || taskType == ITaskWrapper.D_FTP) {
return new SimpleDownloadUtil(mTaskWrapper, (IDownloadListener) mListener); return new SimpleDownloadUtil(mTaskWrapper, (IDownloadListener) mListener);
} else {
throw new IllegalArgumentException(String.format("不识别的任务, 任务类型:%s", taskType));
} }
} }

@ -17,6 +17,8 @@ package com.arialyy.aria.core.download;
import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ITaskWrapper;
import java.util.List;
/** /**
* Created by lyy on 2017/4/9. * Created by lyy on 2017/4/9.
@ -26,6 +28,16 @@ class FtpDirConfigHandler<TARGET extends AbsTarget> extends AbsGroupConfigHandle
FtpDirConfigHandler(TARGET target, long taskId) { FtpDirConfigHandler(TARGET target, long taskId) {
super(target, taskId); super(target, taskId);
init();
}
private void init() {
getTaskWrapper().setRequestType(AbsTaskWrapper.D_FTP_DIR); getTaskWrapper().setRequestType(AbsTaskWrapper.D_FTP_DIR);
List<DTaskWrapper> wrappers = getTaskWrapper().getSubTaskWrapper();
if (!wrappers.isEmpty()) {
for (DTaskWrapper subWrapper : wrappers) {
subWrapper.setRequestType(ITaskWrapper.D_FTP);
}
}
} }
} }

@ -20,7 +20,7 @@ import android.support.annotation.NonNull;
import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate; import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
/** /**
@ -32,8 +32,8 @@ public class FtpNormalTarget extends AbsNormalTarget<FtpNormalTarget> {
FtpNormalTarget(long taskId, String targetName) { FtpNormalTarget(long taskId, String targetName) {
mConfigHandler = new DNormalConfigHandler<>(this, taskId, targetName); mConfigHandler = new DNormalConfigHandler<>(this, taskId, targetName);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(mConfigHandler.getUrl())); getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().setRequestType(AbsTaskWrapper.D_FTP); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP);
} }
/** /**

@ -21,6 +21,7 @@ import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate; import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
/** /**
@ -33,7 +34,7 @@ public class FtpStartTarget extends AbsStartTarget<FtpStartTarget> {
mConfigHandler = new DNormalConfigHandler<>(this, -1, targetName); mConfigHandler = new DNormalConfigHandler<>(this, -1, targetName);
mConfigHandler.setUrl(url); mConfigHandler.setUrl(url);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(url)); getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(url));
getTaskWrapper().setRequestType(AbsTaskWrapper.D_FTP); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP);
} }
/** /**

@ -19,6 +19,7 @@ import android.support.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate; import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.core.manager.SubTaskManager;
import java.util.List; import java.util.List;
@ -32,6 +33,7 @@ public class GroupNormalTarget extends AbsNormalTarget<GroupNormalTarget> {
GroupNormalTarget(long taskId, String targetName) { GroupNormalTarget(long taskId, String targetName) {
setTargetName(targetName); setTargetName(targetName);
mConfigHandler = new HttpGroupConfigHandler<>(this, taskId); mConfigHandler = new HttpGroupConfigHandler<>(this, taskId);
getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP);
} }
/** /**

@ -20,6 +20,7 @@ import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate; import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.inf.IHttpFileLenAdapter; import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import java.util.List; import java.util.List;
@ -34,6 +35,7 @@ public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
GroupStartTarget(List<String> urls, String targetName) { GroupStartTarget(List<String> urls, String targetName) {
setTargetName(targetName); setTargetName(targetName);
mConfigHandler = new HttpGroupConfigHandler<>(this, -1); mConfigHandler = new HttpGroupConfigHandler<>(this, -1);
getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP);
mConfigHandler.setGroupUrl(urls); mConfigHandler.setGroupUrl(urls);
} }

@ -17,6 +17,7 @@ package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult; import android.support.annotation.CheckResult;
import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.DbDataHelper; import com.arialyy.aria.util.DbDataHelper;
@ -53,7 +54,14 @@ class HttpGroupConfigHandler<TARGET extends AbsTarget> extends AbsGroupConfigHan
mUrls.addAll(urls); mUrls.addAll(urls);
String groupHash = CommonUtil.getMd5Code(urls); String groupHash = CommonUtil.getMd5Code(urls);
getEntity().setGroupHash(groupHash); getEntity().setGroupHash(groupHash);
getEntity().setSubEntities(DbDataHelper.createHttpSubTask(groupHash, mUrls)); List<DownloadEntity> subEntities = DbDataHelper.createHttpSubTask(groupHash, mUrls);
List<DTaskWrapper> wrappers = new ArrayList<>();
for (DownloadEntity subEntity : subEntities) {
wrappers.add(new DTaskWrapper(subEntity));
}
getEntity().setUrls(urls);
getEntity().setSubEntities(subEntities);
getTaskWrapper().setSubTaskWrapper(wrappers);
} }
/** /**
@ -91,13 +99,17 @@ class HttpGroupConfigHandler<TARGET extends AbsTarget> extends AbsGroupConfigHan
mUrls.clear(); mUrls.clear();
mUrls.addAll(urls); mUrls.addAll(urls);
String newHash = CommonUtil.getMd5Code(urls); String newHash = CommonUtil.getMd5Code(urls);
getEntity().setUrls(mUrls);
getEntity().setGroupHash(newHash); getEntity().setGroupHash(newHash);
getEntity().update(); getEntity().update();
if (getEntity().getSubEntities() != null && !getEntity().getSubEntities().isEmpty()) { if (getEntity().getSubEntities() != null && !getEntity().getSubEntities().isEmpty()) {
int i = 0;
for (DownloadEntity de : getEntity().getSubEntities()) { for (DownloadEntity de : getEntity().getSubEntities()) {
de.setUrl(mUrls.get(i));
de.setGroupHash(newHash); de.setGroupHash(newHash);
de.update(); i++;
} }
DbEntity.updateManyData(getEntity().getSubEntities());
} }
return getTarget(); return getTarget();
} }

@ -30,6 +30,7 @@ public class HttpNormalTarget extends AbsNormalTarget<HttpNormalTarget> {
HttpNormalTarget(long taskId, String targetName) { HttpNormalTarget(long taskId, String targetName) {
mConfigHandler = new DNormalConfigHandler<>(this, taskId, targetName); mConfigHandler = new DNormalConfigHandler<>(this, taskId, targetName);
getTaskWrapper().setRequestType(getTaskWrapper().getEntity().getTaskType());
} }
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)

@ -22,6 +22,7 @@ import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate; import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.download.m3u8.M3U8Delegate; import com.arialyy.aria.core.download.m3u8.M3U8Delegate;
import com.arialyy.aria.core.inf.IHttpFileLenAdapter; import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
import com.arialyy.aria.core.inf.ITaskWrapper;
public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> { public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
@ -29,6 +30,7 @@ public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
HttpStartTarget(String url, String targetName) { HttpStartTarget(String url, String targetName) {
mConfigHandler = new DNormalConfigHandler<>(this, -1, targetName); mConfigHandler = new DNormalConfigHandler<>(this, -1, targetName);
getTaskWrapper().setRequestType(ITaskWrapper.D_HTTP);
mConfigHandler.setUrl(url); mConfigHandler.setUrl(url);
} }

@ -19,12 +19,12 @@ import com.arialyy.aria.core.common.AbsThreadTask;
import com.arialyy.aria.core.common.NormalFileer; import com.arialyy.aria.core.common.NormalFileer;
import com.arialyy.aria.core.common.RecordHandler; import com.arialyy.aria.core.common.RecordHandler;
import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.event.Event; import com.arialyy.aria.core.event.Event;
import com.arialyy.aria.core.event.SpeedEvent; import com.arialyy.aria.core.event.SpeedEvent;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
@ -113,10 +113,10 @@ public class Downloader extends NormalFileer<DownloadEntity, DTaskWrapper> {
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<DTaskWrapper> config) { @Override protected AbsThreadTask selectThreadTask(SubThreadConfig<DTaskWrapper> config) {
switch (mTaskWrapper.getRequestType()) { switch (mTaskWrapper.getRequestType()) {
case AbsTaskWrapper.D_FTP: case ITaskWrapper.D_FTP:
case AbsTaskWrapper.D_FTP_DIR: case ITaskWrapper.D_FTP_DIR:
return new FtpThreadTask(config); return new FtpThreadTask(config);
case AbsTaskWrapper.D_HTTP: case ITaskWrapper.D_HTTP:
return new HttpThreadTask(config); return new HttpThreadTask(config);
} }
return null; return null;

@ -16,15 +16,16 @@
package com.arialyy.aria.core.download.downloader; package com.arialyy.aria.core.download.downloader;
import android.net.TrafficStats; import android.net.TrafficStats;
import android.net.Uri;
import android.os.Process; import android.os.Process;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.common.http.HttpTaskConfig;
import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.common.http.HttpTaskConfig;
import com.arialyy.aria.core.inf.IHttpFileLenAdapter; import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
@ -54,7 +55,7 @@ import java.util.UUID;
* 下载文件信息获取 * 下载文件信息获取
*/ */
public class HttpFileInfoThread implements Runnable { public class HttpFileInfoThread implements Runnable {
private final String TAG = "HttpFileInfoThread"; private static final String TAG = "HttpFileInfoThread";
private DownloadEntity mEntity; private DownloadEntity mEntity;
private DTaskWrapper mTaskWrapper; private DTaskWrapper mTaskWrapper;
private int mConnectTimeOut; private int mConnectTimeOut;
@ -83,6 +84,7 @@ public class HttpFileInfoThread implements Runnable {
conn.connect(); conn.connect();
handleConnect(conn); handleConnect(conn);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
failDownload(new AriaIOException(TAG, failDownload(new AriaIOException(TAG,
String.format("下载失败,filePath: %s, url: %s", mEntity.getDownloadPath(), mEntity.getUrl())), String.format("下载失败,filePath: %s, url: %s", mEntity.getDownloadPath(), mEntity.getUrl())),
true); true);
@ -119,7 +121,7 @@ public class HttpFileInfoThread implements Runnable {
} }
long len = lenAdapter.handleFileLen(conn.getHeaderFields()); long len = lenAdapter.handleFileLen(conn.getHeaderFields());
if (!CommonUtil.checkSDMemorySpace(mEntity.getDownloadPath(), len)) { if (!CommonUtil.checkSDMemorySpace(mEntity.getFilePath(), len)) {
failDownload(new TaskException(TAG, failDownload(new TaskException(TAG,
String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getDownloadPath(), String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getDownloadPath(),
mEntity.getUrl())), false); mEntity.getUrl())), false);
@ -284,13 +286,17 @@ public class HttpFileInfoThread implements Runnable {
*/ */
private void handleUrlReTurn(HttpURLConnection conn, String newUrl) throws IOException { private void handleUrlReTurn(HttpURLConnection conn, String newUrl) throws IOException {
ALog.d(TAG, "30x跳转,新url为【" + newUrl + "】"); ALog.d(TAG, "30x跳转,新url为【" + newUrl + "】");
if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null") || !newUrl.startsWith( if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) {
"http")) {
if (onFileInfoCallback != null) { if (onFileInfoCallback != null) {
onFileInfoCallback.onFail(mEntity, new TaskException(TAG, "获取重定向链接失败"), false); onFileInfoCallback.onFail(mEntity, new TaskException(TAG, "获取重定向链接失败"), false);
} }
return; return;
} }
if (newUrl.startsWith("/")) {
Uri uri = Uri.parse(mEntity.getUrl());
newUrl = uri.getHost() + newUrl;
}
if (!CheckUtil.checkUrlNotThrow(newUrl)) { if (!CheckUtil.checkUrlNotThrow(newUrl)) {
failDownload(new TaskException(TAG, "下载失败,重定向url错误"), false); failDownload(new TaskException(TAG, "下载失败,重定向url错误"), false);
return; return;
@ -334,6 +340,10 @@ public class HttpFileInfoThread implements Runnable {
private static class FileLenAdapter implements IHttpFileLenAdapter { private static class FileLenAdapter implements IHttpFileLenAdapter {
@Override public long handleFileLen(Map<String, List<String>> headers) { @Override public long handleFileLen(Map<String, List<String>> headers) {
if (headers == null || headers.isEmpty()) {
ALog.e(TAG, "header为空,获取文件长度失败");
return -1;
}
List<String> sLength = headers.get("Content-Length"); List<String> sLength = headers.get("Content-Length");
if (sLength == null || sLength.isEmpty()) { if (sLength == null || sLength.isEmpty()) {
return -1; return -1;

@ -21,8 +21,8 @@ import com.arialyy.aria.core.common.IUtil;
import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
/** /**
@ -110,7 +110,7 @@ public class SimpleDownloadUtil implements IUtil {
*/ */
private Runnable createInfoThread() { private Runnable createInfoThread() {
switch (mTaskWrapper.getRequestType()) { switch (mTaskWrapper.getRequestType()) {
case AbsTaskWrapper.D_FTP: case ITaskWrapper.D_FTP:
return new FtpFileInfoThread(mTaskWrapper, new OnFileInfoCallback() { return new FtpFileInfoThread(mTaskWrapper, new OnFileInfoCallback() {
@Override public void onComplete(String url, CompleteInfo info) { @Override public void onComplete(String url, CompleteInfo info) {
mDownloader.updateTempFile(); mDownloader.updateTempFile();
@ -122,7 +122,7 @@ public class SimpleDownloadUtil implements IUtil {
mDownloader.closeTimer(); mDownloader.closeTimer();
} }
}); });
case AbsTaskWrapper.D_HTTP: case ITaskWrapper.D_HTTP:
return new HttpFileInfoThread(mTaskWrapper, new OnFileInfoCallback() { return new HttpFileInfoThread(mTaskWrapper, new OnFileInfoCallback() {
@Override public void onComplete(String url, CompleteInfo info) { @Override public void onComplete(String url, CompleteInfo info) {
mDownloader.updateTempFile(); mDownloader.updateTempFile();

@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
* Created by AriaL on 2017/6/30. * Created by AriaL on 2017/6/30.
* 任务组核心逻辑 * 任务组核心逻辑
*/ */
public abstract class AbsGroupUtil implements IUtil, Runnable { public abstract class AbsGroupUtil implements IUtil {
private final String TAG = "AbsGroupUtil"; private final String TAG = "AbsGroupUtil";
/** /**
* FTP文件夹 * FTP文件夹
@ -59,16 +59,16 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
mListener = listener; mListener = listener;
mGTWrapper = groupWrapper; mGTWrapper = groupWrapper;
mUpdateInterval = Configuration.getInstance().downloadCfg.getUpdateInterval(); mUpdateInterval = Configuration.getInstance().downloadCfg.getUpdateInterval();
mState = new GroupRunState(groupWrapper.getKey(), mListener,
groupWrapper.getSubTaskWrapper().size(), mSubQueue);
mScheduler = new Handler(Looper.getMainLooper(), SimpleSchedulers.newInstance(mState));
initState();
} }
/** /**
* 初始化组合任务状态 * 初始化组合任务状态
*/ */
private void initState() { void initState() {
mState =
new GroupRunState(mGTWrapper.getKey(), mListener, mGTWrapper.getSubTaskWrapper().size(),
mSubQueue);
mScheduler = new Handler(Looper.getMainLooper(), SimpleSchedulers.newInstance(mState));
for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) { for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) {
if (wrapper.getEntity().getState() == IEntity.STATE_COMPLETE) { if (wrapper.getEntity().getState() == IEntity.STATE_COMPLETE) {
mState.updateCompleteNum(); mState.updateCompleteNum();
@ -164,7 +164,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
} }
@Override public boolean isRunning() { @Override public boolean isRunning() {
return mState.isRunning; return mState != null && mState.isRunning;
} }
@Override public void cancel() { @Override public void cancel() {
@ -203,19 +203,15 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
} }
@Override public void start() { @Override public void start() {
new Thread(this).start();
}
@Override public void run() {
if (isStop || isCancel) { if (isStop || isCancel) {
closeTimer(); closeTimer();
return; return;
} }
onStart(); onPreStart();
startRunningFlow(); startRunningFlow();
} }
protected void onStart() { protected void onPreStart() {
} }

@ -21,6 +21,7 @@ import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
/** /**
@ -48,25 +49,25 @@ class ChildDLoadListener implements IDownloadListener {
} }
@Override public void onPre() { @Override public void onPre() {
saveData(IEntity.STATE_PRE, -1); saveData(IEntity.STATE_PRE, subEntity.getCurrentProgress());
} }
@Override public void onPostPre(long fileSize) { @Override public void onPostPre(long fileSize) {
subEntity.setFileSize(fileSize); subEntity.setFileSize(fileSize);
subEntity.setConvertFileSize(CommonUtil.formatFileSize(fileSize)); subEntity.setConvertFileSize(CommonUtil.formatFileSize(fileSize));
saveData(IEntity.STATE_POST_PRE, -1); saveData(IEntity.STATE_POST_PRE, subEntity.getCurrentProgress());
sendToTarget(ISchedulers.POST_PRE, loader); sendToTarget(ISchedulers.POST_PRE, loader);
} }
@Override public void onResume(long resumeLocation) { @Override public void onResume(long resumeLocation) {
lastLen = resumeLocation; lastLen = resumeLocation;
saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING); saveData(IEntity.STATE_POST_PRE, subEntity.getCurrentProgress());
sendToTarget(ISchedulers.START, loader); sendToTarget(ISchedulers.START, loader);
} }
@Override public void onStart(long startLocation) { @Override public void onStart(long startLocation) {
lastLen = startLocation; lastLen = startLocation;
saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING); saveData(IEntity.STATE_POST_PRE, subEntity.getCurrentProgress());
sendToTarget(ISchedulers.START, loader); sendToTarget(ISchedulers.START, loader);
} }
@ -106,7 +107,7 @@ class ChildDLoadListener implements IDownloadListener {
@Override public void onFail(boolean needRetry, BaseException e) { @Override public void onFail(boolean needRetry, BaseException e) {
subEntity.setFailNum(subEntity.getFailNum() + 1); subEntity.setFailNum(subEntity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, lastLen); saveData(IEntity.STATE_FAIL, subEntity.getCurrentProgress());
handleSpeed(0); handleSpeed(0);
sendToTarget(ISchedulers.FAIL, loader); sendToTarget(ISchedulers.FAIL, loader);
} }

@ -68,8 +68,9 @@ public class DGroupUtil extends AbsGroupUtil implements IUtil {
return false; return false;
} }
@Override protected void onStart() { @Override protected void onPreStart() {
super.onStart(); super.onPreStart();
initState();
if (mState.getCompleteNum() == mState.getSubSize()) { if (mState.getCompleteNum() == mState.getSubSize()) {
mListener.onComplete(); mListener.onComplete();
} else { } else {

@ -15,6 +15,9 @@
*/ */
package com.arialyy.aria.core.download.group; package com.arialyy.aria.core.download.group;
import android.net.Uri;
import android.text.TextUtils;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.download.DGTaskWrapper;
@ -22,6 +25,8 @@ import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
/** /**
* Created by Aria.Lao on 2017/7/27. * Created by Aria.Lao on 2017/7/27.
@ -29,6 +34,8 @@ import com.arialyy.aria.exception.BaseException;
*/ */
public class FtpDirDownloadUtil extends AbsGroupUtil { public class FtpDirDownloadUtil extends AbsGroupUtil {
private String TAG = "FtpDirDownloadUtil"; private String TAG = "FtpDirDownloadUtil";
private ReentrantLock LOCK = new ReentrantLock();
private Condition condition = LOCK.newCondition();
public FtpDirDownloadUtil(IDGroupListener listener, DGTaskWrapper taskEntity) { public FtpDirDownloadUtil(IDGroupListener listener, DGTaskWrapper taskEntity) {
super(listener, taskEntity); super(listener, taskEntity);
@ -38,16 +45,15 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
return FTP_DIR; return FTP_DIR;
} }
@Override protected void onStart() { @Override protected void onPreStart() {
super.onStart(); super.onPreStart();
if (mGTWrapper.getEntity().getFileSize() > 1) { if (mGTWrapper.getEntity().getFileSize() > 1) {
startDownload(); startDownload(true);
} else { } else {
FtpDirInfoThread infoThread = new FtpDirInfoThread(mGTWrapper, new OnFileInfoCallback() { FtpDirInfoThread infoThread = new FtpDirInfoThread(mGTWrapper, new OnFileInfoCallback() {
@Override public void onComplete(String url, CompleteInfo info) { @Override public void onComplete(String url, CompleteInfo info) {
if (info.code >= 200 && info.code < 300) { if (info.code >= 200 && info.code < 300) {
startDownload(); startDownload(false);
} }
} }
@ -56,14 +62,46 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
} }
}); });
new Thread(infoThread).start(); new Thread(infoThread).start();
try {
LOCK.lock();
condition.await();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
LOCK.unlock();
}
} }
} }
private void startDownload() { /**
* @param needCloneInfo 第一次下载信息已经在{@link FtpDirInfoThread}中clone了
*/
private void startDownload(boolean needCloneInfo) {
try {
LOCK.lock();
condition.signalAll();
} finally {
LOCK.unlock();
}
initState();
for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) { for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) {
if (needCloneInfo) {
cloneInfo(wrapper);
}
if (wrapper.getState() != IEntity.STATE_COMPLETE) { if (wrapper.getState() != IEntity.STATE_COMPLETE) {
createAndStartSubLoader(wrapper); createAndStartSubLoader(wrapper);
} }
} }
} }
private void cloneInfo(DTaskWrapper subWrapper) {
FtpUrlEntity urlEntity = mGTWrapper.asFtp().getUrlEntity().clone();
Uri uri = Uri.parse(subWrapper.getEntity().getUrl());
String remotePath = uri.getPath();
urlEntity.remotePath = TextUtils.isEmpty(remotePath) ? "/" : remotePath;
subWrapper.asFtp().setUrlEntity(urlEntity);
subWrapper.asFtp().setCharSet(mGTWrapper.asFtp().getCharSet());
subWrapper.asFtp().setProxy(mGTWrapper.asFtp().getProxy());
}
} }

@ -25,7 +25,9 @@ import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.RecordUtil;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
@ -94,4 +96,9 @@ class FtpDirInfoThread extends AbsFtpInfoThread<DownloadGroupEntity, DGTaskWrapp
subWrapper.asFtp().setCharSet(mTaskWrapper.asFtp().getCharSet()); subWrapper.asFtp().setCharSet(mTaskWrapper.asFtp().getCharSet());
subWrapper.asFtp().setProxy(mTaskWrapper.asFtp().getProxy()); subWrapper.asFtp().setProxy(mTaskWrapper.asFtp().getProxy());
} }
@Override protected void failDownload(BaseException e, boolean needRetry) {
super.failDownload(e, needRetry);
RecordUtil.delGroupTaskRecord(mTaskWrapper.getEntity(), true, true);
}
} }

@ -24,7 +24,7 @@ import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.downloader.Downloader; import com.arialyy.aria.core.download.downloader.Downloader;
import com.arialyy.aria.core.download.downloader.HttpFileInfoThread; import com.arialyy.aria.core.download.downloader.HttpFileInfoThread;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
@ -106,7 +106,7 @@ class SubDLoadUtil implements IUtil {
} }
@Override public void start() { @Override public void start() {
if (mWrapper.getRequestType() == AbsTaskWrapper.D_HTTP) { if (mWrapper.getRequestType() == ITaskWrapper.D_HTTP) {
if (needGetInfo) { if (needGetInfo) {
new Thread(new HttpFileInfoThread(mWrapper, new OnFileInfoCallback() { new Thread(new HttpFileInfoThread(mWrapper, new OnFileInfoCallback() {
@ -123,7 +123,7 @@ class SubDLoadUtil implements IUtil {
mDownloader = new Downloader(mListener, mWrapper); mDownloader = new Downloader(mListener, mWrapper);
mDownloader.start(); mDownloader.start();
} }
} else if (mWrapper.getRequestType() == AbsTaskWrapper.D_FTP) { } else if (mWrapper.getRequestType() == ITaskWrapper.D_FTP) {
mDownloader = new Downloader(mListener, mWrapper); mDownloader = new Downloader(mListener, mWrapper);
mDownloader.start(); mDownloader.start();
} else { } else {

@ -53,7 +53,7 @@ import java.util.regex.Pattern;
* https://blog.csdn.net/Guofengpu/article/details/54922865 * https://blog.csdn.net/Guofengpu/article/details/54922865
*/ */
final class M3U8InfoThread implements Runnable { final class M3U8InfoThread implements Runnable {
private final String TAG = "M3U8FileInfoThread"; private final String TAG = "M3U8InfoThread";
private DownloadEntity mEntity; private DownloadEntity mEntity;
private DTaskWrapper mTaskWrapper; private DTaskWrapper mTaskWrapper;
private int mConnectTimeOut; private int mConnectTimeOut;

@ -127,7 +127,7 @@ public class M3U8LiveLoader extends BaseM3U8Loader {
*/ */
private M3U8ThreadTask createThreadTask(String cacheDir, int indexId, String tsUrl) { private M3U8ThreadTask createThreadTask(String cacheDir, int indexId, String tsUrl) {
ThreadRecord record = new ThreadRecord(); ThreadRecord record = new ThreadRecord();
record.key = mRecord.filePath; record.taskKey = mRecord.filePath;
record.isComplete = false; record.isComplete = false;
record.tsUrl = tsUrl; record.tsUrl = tsUrl;
record.threadType = TaskRecord.TYPE_M3U8_LIVE; record.threadType = TaskRecord.TYPE_M3U8_LIVE;

@ -95,10 +95,14 @@ public class M3U8LiveUtil implements IUtil {
if (mInfoThread != null) { if (mInfoThread != null) {
mInfoThread.setStop(true); mInfoThread.setStop(true);
closeTimer(); closeTimer();
if (mLoader.mergeFile()) { if (mWrapper.asM3U8().isMergeFile()) {
mListener.onComplete(); if (mLoader.mergeFile()) {
mListener.onComplete();
} else {
mListener.onFail(false, new M3U8Exception(TAG, "合并文件失败"));
}
} else { } else {
mListener.onFail(false, new M3U8Exception(TAG, "合并文件失败")); mListener.onComplete();
} }
} }
} }

@ -46,7 +46,7 @@ public class M3U8TaskConfig {
/** /**
* 合并处理器 * 合并处理器
*/ */
private WeakReference<ITsMergeHandler> mergeHandler; private ITsMergeHandler mergeHandler;
/** /**
* 已完成的ts分片数量 * 已完成的ts分片数量
@ -147,7 +147,7 @@ public class M3U8TaskConfig {
} }
public IBandWidthUrlConverter getBandWidthUrlConverter() { public IBandWidthUrlConverter getBandWidthUrlConverter() {
return bandWidthUrlConverter.get(); return bandWidthUrlConverter == null ? null : bandWidthUrlConverter.get();
} }
public void setBandWidthUrlConverter(IBandWidthUrlConverter bandWidthUrlConverter) { public void setBandWidthUrlConverter(IBandWidthUrlConverter bandWidthUrlConverter) {
@ -187,11 +187,11 @@ public class M3U8TaskConfig {
} }
public ITsMergeHandler getMergeHandler() { public ITsMergeHandler getMergeHandler() {
return mergeHandler.get(); return mergeHandler;
} }
public void setMergeHandler(ITsMergeHandler mergeHandler) { public void setMergeHandler(ITsMergeHandler mergeHandler) {
this.mergeHandler = new WeakReference<>(mergeHandler); this.mergeHandler = mergeHandler;
} }
public IVodTsUrlConverter getVodUrlConverter() { public IVodTsUrlConverter getVodUrlConverter() {

@ -619,6 +619,10 @@ public class M3U8VodLoader extends BaseM3U8Loader {
boolean isSuccess; boolean isSuccess;
if (mergeHandler != null) { if (mergeHandler != null) {
isSuccess = mergeHandler.merge(mTaskWrapper.asM3U8().getKeyInfo(), partPath); isSuccess = mergeHandler.merge(mTaskWrapper.asM3U8().getKeyInfo(), partPath);
if (mergeHandler.getClass().isAnonymousClass()) {
mTaskWrapper.asM3U8().setMergeHandler(null);
}
} else { } else {
isSuccess = FileUtil.mergeFile(taskRecord.filePath, partPath); isSuccess = FileUtil.mergeFile(taskRecord.filePath, partPath);
} }

@ -0,0 +1,26 @@
/*
* 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.event;
public class ErrorEvent {
public long taskId;
public String errorMsg;
public ErrorEvent(long taskId, String errorMsg) {
this.taskId = taskId;
this.errorMsg = errorMsg;
}
}

@ -191,8 +191,8 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable,
/** /**
* 实体驱动的下载任务类型 * 实体驱动的下载任务类型
* *
* @return {@link AbsTaskWrapper#D_FTP}{@link AbsTaskWrapper#D_FTP_DIR}{@link * @return {@link ITaskWrapper#D_FTP}{@link ITaskWrapper#D_FTP_DIR}{@link
* AbsTaskWrapper#U_HTTP}... * ITaskWrapper#U_HTTP}...
*/ */
public abstract int getTaskType(); public abstract int getTaskType();

@ -26,7 +26,8 @@ import java.util.List;
*/ */
public abstract class AbsGroupEntity extends AbsEntity implements Parcelable { public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
/** /**
* 为子任务地址相加的url的Md5 * 组合任务等hash为 为子任务地址相加的url的Md5
* ftpdir为ftpdir下载地址
*/ */
@Unique protected String groupHash; @Unique protected String groupHash;

@ -16,6 +16,7 @@
package com.arialyy.aria.core.inf; package com.arialyy.aria.core.inf;
import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.event.ErrorEvent;
import java.util.List; import java.util.List;
/** /**
@ -24,6 +25,19 @@ import java.util.List;
public abstract class AbsGroupTaskWrapper<ENTITY extends AbsEntity, SUB extends AbsTaskWrapper> public abstract class AbsGroupTaskWrapper<ENTITY extends AbsEntity, SUB extends AbsTaskWrapper>
extends AbsTaskWrapper<ENTITY> { extends AbsTaskWrapper<ENTITY> {
/**
* 错误信息
*/
private ErrorEvent errorEvent;
public ErrorEvent getErrorEvent() {
return errorEvent;
}
public void setErrorEvent(ErrorEvent errorEvent) {
this.errorEvent = errorEvent;
}
public AbsGroupTaskWrapper(ENTITY entity) { public AbsGroupTaskWrapper(ENTITY entity) {
super(entity); super(entity);
} }

@ -23,6 +23,7 @@ import com.arialyy.aria.core.config.DownloadConfig;
import com.arialyy.aria.core.config.UploadConfig; import com.arialyy.aria.core.config.UploadConfig;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.event.ErrorEvent;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
/** /**
@ -45,8 +46,8 @@ public abstract class AbsTaskWrapper<ENTITY extends AbsEntity>
private boolean isNewTask = false; private boolean isNewTask = false;
/** /**
* 请求类型 {@link AbsTaskWrapper#D_HTTP}{@link AbsTaskWrapper#D_FTP}{@link * 请求类型 {@link ITaskWrapper#D_HTTP}{@link ITaskWrapper#D_FTP}{@link
* AbsTaskWrapper#D_FTP_DIR} * ITaskWrapper#D_FTP_DIR}
*/ */
private int requestType = D_HTTP; private int requestType = D_HTTP;
@ -71,10 +72,23 @@ public abstract class AbsTaskWrapper<ENTITY extends AbsEntity>
*/ */
private ENTITY entity; private ENTITY entity;
/**
* 错误信息
*/
private ErrorEvent errorEvent;
public AbsTaskWrapper(ENTITY entity) { public AbsTaskWrapper(ENTITY entity) {
this.entity = entity; this.entity = entity;
} }
public ErrorEvent getErrorEvent() {
return errorEvent;
}
public void setErrorEvent(ErrorEvent errorEvent) {
this.errorEvent = errorEvent;
}
/** /**
* 任务识别标志 {@link AbsEntity#getKey()} * 任务识别标志 {@link AbsEntity#getKey()}
*/ */

@ -0,0 +1,26 @@
/*
* 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.inf;
public interface ICheckEntityUtil {
/**
* 检查实体对象
*
* @return true 成功false 失败
*/
boolean checkEntity();
}

@ -22,6 +22,8 @@ import com.arialyy.aria.core.download.DownloadGroupEntity;
*/ */
public interface ITaskWrapper<ENTITY extends AbsEntity> { public interface ITaskWrapper<ENTITY extends AbsEntity> {
int DEFAULT = 0;
/** /**
* HTTP单任务载 * HTTP单任务载
*/ */

@ -53,20 +53,6 @@ class DGTaskWrapperFactory implements IGroupWrapperFactory<DownloadGroupEntity,
return wrapper; return wrapper;
} }
//@Override public DGTaskWrapper getFtpDirWrapper(long taskId) {
// DownloadGroupEntity entity = DbDataHelper.getOrCreateFtpDGEntity(ftpUrl);
// DGTaskWrapper fte = new DGTaskWrapper(entity);
// fte.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(ftpUrl));
//
// if (fte.getEntity().getSubEntities() == null) {
// fte.getEntity().setSubEntities(new ArrayList<DownloadEntity>());
// }
// if (fte.getSubTaskWrapper() == null) {
// fte.setSubTaskWrapper(new ArrayList<DTaskWrapper>());
// }
// return fte;
//}
/** /**
* 获取组合任务实体 如果数据库不存在该实体则新创建一个新的任务组实体 * 获取组合任务实体 如果数据库不存在该实体则新创建一个新的任务组实体
*/ */

@ -29,7 +29,7 @@ import java.util.concurrent.locks.ReentrantLock;
* Created by Aria.Lao on 2017/11/1. 任务实体管理器 * Created by Aria.Lao on 2017/11/1. 任务实体管理器
*/ */
public class TaskWrapperManager { public class TaskWrapperManager {
private static final String TAG = "TaskManager"; private static final String TAG = "TaskWrapperManager";
private static volatile TaskWrapperManager INSTANCE = null; private static volatile TaskWrapperManager INSTANCE = null;
private LruCache<String, AbsTaskWrapper> cache = new LruCache<>(1024); private LruCache<String, AbsTaskWrapper> cache = new LruCache<>(1024);
private Lock lock; private Lock lock;
@ -37,7 +37,9 @@ public class TaskWrapperManager {
public static TaskWrapperManager getInstance() { public static TaskWrapperManager getInstance() {
if (INSTANCE == null) { if (INSTANCE == null) {
synchronized (TaskWrapperManager.class) { synchronized (TaskWrapperManager.class) {
INSTANCE = new TaskWrapperManager(); if (INSTANCE == null) {
INSTANCE = new TaskWrapperManager();
}
} }
} }
return INSTANCE; return INSTANCE;
@ -81,7 +83,7 @@ public class TaskWrapperManager {
return null; return null;
} }
wrapper = factory.create(taskId); wrapper = factory.create(taskId);
cache.put(convertKey(clazz, taskId), wrapper); putTaskWrapper(wrapper);
} }
return (TW) wrapper; return (TW) wrapper;
} finally { } finally {
@ -107,7 +109,7 @@ public class TaskWrapperManager {
return null; return null;
} }
tWrapper = factory.getGroupWrapper(taskId); tWrapper = factory.getGroupWrapper(taskId);
cache.put(convertKey(clazz, taskId), tWrapper); putTaskWrapper(tWrapper);
} }
return (TW) tWrapper; return (TW) tWrapper;
} finally { } finally {
@ -119,30 +121,17 @@ public class TaskWrapperManager {
* 更新任务Wrapper * 更新任务Wrapper
*/ */
public void putTaskWrapper(AbsTaskWrapper wrapper) { public void putTaskWrapper(AbsTaskWrapper wrapper) {
final Lock lock = this.lock;
lock.lock();
try {
cache.put(convertKey(wrapper.getClass(), wrapper.getEntity().getId()), wrapper);
} finally {
lock.unlock();
}
}
/**
* 向管理器中增加任务实体
*
* @return {@code false} 实体为null添加失败
*/
public boolean addTaskWrapper(AbsTaskWrapper wrapper) {
if (wrapper == null) { if (wrapper == null) {
ALog.e(TAG, "任务实体添加失败"); ALog.e(TAG, "任务实体添加失败");
return false; return;
}
if (wrapper.getEntity() == null || wrapper.getEntity().getId() == -1) {
return;
} }
final Lock lock = this.lock; final Lock lock = this.lock;
lock.lock(); lock.lock();
try { try {
return cache.put(convertKey(wrapper.getClass(), wrapper.getEntity().getId()), wrapper) cache.put(convertKey(wrapper.getClass(), wrapper.getEntity().getId()), wrapper);
!= null;
} finally { } finally {
lock.unlock(); lock.unlock();
} }
@ -151,11 +140,11 @@ public class TaskWrapperManager {
/** /**
* 通过key删除任务实体 当任务complete或删除记录时将删除缓存 * 通过key删除任务实体 当任务complete或删除记录时将删除缓存
*/ */
public AbsTaskWrapper removeTaskWrapper(AbsTaskWrapper wrapper) { public void removeTaskWrapper(AbsTaskWrapper wrapper) {
final Lock lock = this.lock; final Lock lock = this.lock;
lock.lock(); lock.lock();
try { try {
return cache.remove(convertKey(wrapper.getClass(), wrapper.getEntity().getId())); cache.remove(convertKey(wrapper.getClass(), wrapper.getEntity().getId()));
} finally { } finally {
lock.unlock(); lock.unlock();
} }

@ -177,7 +177,7 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
} }
@Override public TASK createTask(TASK_WRAPPER wrapper) { @Override public TASK createTask(TASK_WRAPPER wrapper) {
TaskWrapperManager.getInstance().addTaskWrapper(wrapper); TaskWrapperManager.getInstance().putTaskWrapper(wrapper);
return null; return null;
} }

@ -161,7 +161,7 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
@Override public TASK getTask(String key) { @Override public TASK getTask(String key) {
synchronized (LOCK) { synchronized (LOCK) {
if (TextUtils.isEmpty(key)) { if (TextUtils.isEmpty(key)) {
ALog.e(TAG, "key 为null"); ALog.e(TAG, "key为null");
return null; return null;
} }
return mExecuteMap.get(CommonUtil.keyToHashKey(key)); return mExecuteMap.get(CommonUtil.keyToHashKey(key));

@ -16,11 +16,13 @@
package com.arialyy.aria.core.upload; package com.arialyy.aria.core.upload;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import java.io.File; import java.io.File;
public class CheckUEntityUtil { public class CheckUEntityUtil implements ICheckEntityUtil {
private final String TAG = "CheckUEntityUtil"; private final String TAG = "CheckUEntityUtil";
private UTaskWrapper mWrapper; private UTaskWrapper mWrapper;
private UploadEntity mEntity; private UploadEntity mEntity;
@ -34,7 +36,13 @@ public class CheckUEntityUtil {
mEntity = mWrapper.getEntity(); mEntity = mWrapper.getEntity();
} }
@Override
public boolean checkEntity() { public boolean checkEntity() {
if (mWrapper.getErrorEvent() != null) {
ALog.e(TAG, mWrapper.getErrorEvent().errorMsg);
return false;
}
boolean b = checkFtps() && checkUrl() && checkFilePath(); boolean b = checkFtps() && checkUrl() && checkFilePath();
if (b) { if (b) {
mEntity.save(); mEntity.save();
@ -94,7 +102,8 @@ public class CheckUEntityUtil {
} }
private boolean checkFtps() { private boolean checkFtps() {
if (mWrapper.asFtp().getUrlEntity().isFtps) { if (mWrapper.getRequestType() == ITaskWrapper.U_FTP && mWrapper.asFtp()
.getUrlEntity().isFtps) {
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) { if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) {
ALog.e(TAG, "证书路径为空"); ALog.e(TAG, "证书路径为空");
return false; return false;

@ -16,6 +16,7 @@
package com.arialyy.aria.core.upload; package com.arialyy.aria.core.upload;
import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor; import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor;
import com.arialyy.aria.core.event.ErrorEvent;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IConfigHandler; import com.arialyy.aria.core.inf.IConfigHandler;
@ -42,6 +43,9 @@ class UNormalConfigHandler<TARGET extends AbsTarget> implements IConfigHandler {
private void initTarget(long taskId, String targetName) { private void initTarget(long taskId, String targetName) {
mWrapper = TaskWrapperManager.getInstance().getNormalTaskWrapper(UTaskWrapper.class, taskId); mWrapper = TaskWrapperManager.getInstance().getNormalTaskWrapper(UTaskWrapper.class, taskId);
if (taskId != -1 && mWrapper.getEntity().getId() == -1) {
mWrapper.setErrorEvent(new ErrorEvent(taskId, String.format("没有id为%s的任务", taskId)));
}
mEntity = mWrapper.getEntity(); mEntity = mWrapper.getEntity();
mTarget.setTargetName(targetName); mTarget.setTargetName(targetName);
mTarget.setTaskWrapper(mWrapper); mTarget.setTaskWrapper(mWrapper);
@ -50,6 +54,7 @@ class UNormalConfigHandler<TARGET extends AbsTarget> implements IConfigHandler {
void setFilePath(String filePath) { void setFilePath(String filePath) {
File file = new File(filePath); File file = new File(filePath);
mEntity.setFilePath(filePath);
mEntity.setFileName(file.getName()); mEntity.setFileName(file.getName());
mEntity.setFileSize(file.length()); mEntity.setFileSize(file.length());
} }

@ -18,7 +18,7 @@ package com.arialyy.aria.core.upload;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.orm.annotation.Primary; import com.arialyy.aria.orm.annotation.Primary;
/** /**
@ -57,7 +57,7 @@ public class UploadEntity extends AbsNormalEntity implements Parcelable {
} }
@Override public int getTaskType() { @Override public int getTaskType() {
return getUrl().startsWith("ftp") ? AbsTaskWrapper.D_FTP : AbsTaskWrapper.D_HTTP; return getUrl().startsWith("ftp") ? ITaskWrapper.D_FTP : ITaskWrapper.D_HTTP;
} }
public UploadEntity() { public UploadEntity() {

@ -144,7 +144,7 @@ class FtpFileInfoThread extends AbsFtpInfoThread<UploadEntity, UTaskWrapper> {
ThreadRecord threadRecord; ThreadRecord threadRecord;
if (record.threadRecords == null || record.threadRecords.isEmpty()) { if (record.threadRecords == null || record.threadRecords.isEmpty()) {
threadRecord = new ThreadRecord(); threadRecord = new ThreadRecord();
threadRecord.key = record.filePath; threadRecord.taskKey = record.filePath;
} else { } else {
threadRecord = record.threadRecords.get(0); threadRecord = record.threadRecords.get(0);
} }

@ -176,7 +176,7 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UTaskWrapper> {
fail(mChildCurrentLocation, fail(mChildCurrentLocation,
new AriaIOException(TAG, new AriaIOException(TAG,
String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply, String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply,
client.getReplyString(), getEntity().getFilePath()))); client.getReplyString(), getEntity().getFilePath())), false);
} }
if (client.isConnected()) { if (client.isConnected()) {
client.disconnect(); client.disconnect();

@ -22,7 +22,6 @@ import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IUploadListener; import com.arialyy.aria.core.inf.IUploadListener;
import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
@ -33,7 +32,6 @@ import com.arialyy.aria.util.CheckUtil;
public class SimpleUploadUtil implements IUtil, Runnable { public class SimpleUploadUtil implements IUtil, Runnable {
private static final String TAG = "SimpleUploadUtil"; private static final String TAG = "SimpleUploadUtil";
private UploadEntity mUploadEntity;
private UTaskWrapper mTaskWrapper; private UTaskWrapper mTaskWrapper;
private IUploadListener mListener; private IUploadListener mListener;
private Uploader mUploader; private Uploader mUploader;
@ -42,7 +40,6 @@ public class SimpleUploadUtil implements IUtil, Runnable {
public SimpleUploadUtil(UTaskWrapper taskWrapper, IUploadListener listener) { public SimpleUploadUtil(UTaskWrapper taskWrapper, IUploadListener listener) {
mTaskWrapper = taskWrapper; mTaskWrapper = taskWrapper;
CheckUtil.checkTaskEntity(taskWrapper); CheckUtil.checkTaskEntity(taskWrapper);
mUploadEntity = taskWrapper.getEntity();
if (listener == null) { if (listener == null) {
throw new IllegalArgumentException("上传监听不能为空"); throw new IllegalArgumentException("上传监听不能为空");
} }

@ -38,7 +38,7 @@ class DBConfig {
static boolean DEBUG = false; static boolean DEBUG = false;
static Map<String, Class> mapping = new LinkedHashMap<>(); static Map<String, Class> mapping = new LinkedHashMap<>();
static String DB_NAME; static String DB_NAME;
static int VERSION = 51; static int VERSION = 52;
/** /**
* 是否将数据库保存在Sd卡{@code true} * 是否将数据库保存在Sd卡{@code true}

@ -15,7 +15,6 @@
*/ */
package com.arialyy.aria.orm; package com.arialyy.aria.orm;
import android.annotation.SuppressLint;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils; import android.text.TextUtils;
@ -30,10 +29,8 @@ import java.lang.reflect.Field;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* Created by laoyuyu on 2018/3/22. * Created by laoyuyu on 2018/3/22.

@ -100,6 +100,8 @@ final class SqlHelper extends SQLiteOpenHelper {
handle360AriaUpdate(db); handle360AriaUpdate(db);
} else if (oldVersion < 51) { } else if (oldVersion < 51) {
handle365Update(db); handle365Update(db);
} else if (oldVersion < 52) {
handle366Update(db);
} else { } else {
handleDbUpdate(db, null, null); handleDbUpdate(db, null, null);
} }
@ -239,23 +241,43 @@ final class SqlHelper extends SQLiteOpenHelper {
*/ */
private void delRepeatThreadRecord(SQLiteDatabase db) { private void delRepeatThreadRecord(SQLiteDatabase db) {
String repeatSql = String repeatSql =
"DELETE FROM ThreadRecord WHERE (key, threadId, endLocation) " "DELETE FROM ThreadRecord WHERE (taskKey, threadId, endLocation) "
+ "IN (SELECT key, threadId, endLocation FROM ThreadRecord GROUP BY key, threadId, endLocation " + "IN (SELECT taskKey, threadId, endLocation FROM ThreadRecord GROUP BY taskKey, threadId, endLocation "
+ "HAVING COUNT(*) > 1) AND rowid " + "HAVING COUNT(*) > 1) AND rowid "
+ "NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY key, threadId, endLocation " + "NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY taskKey, threadId, endLocation "
+ "HAVING COUNT(*)> 1)"; + "HAVING COUNT(*)> 1)";
ALog.d(TAG, repeatSql); ALog.d(TAG, repeatSql);
db.execSQL(repeatSql); db.execSQL(repeatSql);
} }
/**
* 处理366版本以下的升级
*/
private void handle366Update(SQLiteDatabase db) {
Map<String, Map<String, String>> modifyMap = new HashMap<>();
// 处理ThreadRecord的key字段名修改
Map<String, String> threadRecordModify = new HashMap<>();
threadRecordModify.put("key", "taskKey");
modifyMap.put("ThreadRecord", threadRecordModify);
// 执行升级操作
handleDbUpdate(db, modifyMap, null);
}
/** /**
* 处理365版本以下的升级 * 处理365版本以下的升级
*/ */
private void handle365Update(SQLiteDatabase db) { private void handle365Update(SQLiteDatabase db) {
db.execSQL("UPDATE ThreadRecord SET threadId=0 WHERE threadId=-1"); db.execSQL("UPDATE ThreadRecord SET threadId=0 WHERE threadId=-1");
Map<String, Map<String, String>> modifyMap = new HashMap<>();
// 处理ThreadRecord的key字段名修改
Map<String, String> threadRecordModify = new HashMap<>();
threadRecordModify.put("key", "taskKey");
modifyMap.put("ThreadRecord", threadRecordModify);
// 执行升级操作 // 执行升级操作
handleDbUpdate(db, null, null); handleDbUpdate(db, modifyMap, null);
delRepeatThreadRecord(db); delRepeatThreadRecord(db);
} }
@ -271,19 +293,25 @@ final class SqlHelper extends SQLiteOpenHelper {
} }
} }
Map<String, Map<String, String>> columnMap = new HashMap<>(); Map<String, Map<String, String>> modifyMap = new HashMap<>();
// 处理DownloadEntity、DownloadGroupEntity的 groupName字段名的修改 // 处理DownloadEntity、DownloadGroupEntity的 groupName字段名的修改
Map<String, String> groupNameModify = new HashMap<>(); Map<String, String> entityModify = new HashMap<>();
groupNameModify.put("groupName", "groupHash"); entityModify.put("groupName", "groupHash");
columnMap.put("DownloadEntity", groupNameModify); modifyMap.put("DownloadEntity", entityModify);
columnMap.put("DownloadGroupEntity", groupNameModify); modifyMap.put("DownloadGroupEntity", entityModify);
// 处理TaskRecord的dGroupName字段名的修改 // 处理TaskRecord的dGroupName字段名的修改
Map<String, String> dGroupNameModify = new HashMap<>(); Map<String, String> taskRecordModify = new HashMap<>();
dGroupNameModify.put("dGroupName", "dGroupHash"); taskRecordModify.put("dGroupName", "dGroupHash");
columnMap.put("TaskRecord", dGroupNameModify); modifyMap.put("TaskRecord", taskRecordModify);
// 处理ThreadRecord的key字段名修改
Map<String, String> threadRecordModify = new HashMap<>();
threadRecordModify.put("key", "taskKey");
modifyMap.put("ThreadRecord", threadRecordModify);
// 执行升级操作 // 执行升级操作
handleDbUpdate(db, columnMap, null); handleDbUpdate(db, modifyMap, null);
delRepeatThreadRecord(db); delRepeatThreadRecord(db);
} }
@ -324,18 +352,19 @@ final class SqlHelper extends SQLiteOpenHelper {
i++; i++;
} }
Map<String, Map<String, String>> modifyColumnMap = new HashMap<>();
Map<String, String> dMap = new HashMap<>();
dMap.put("groupName", "groupHash");
// 处理数据库版本小于3的字段改变 // 处理数据库版本小于3的字段改变
dMap.put("downloadUrl", "url"); Map<String, Map<String, String>> modifyMap = new HashMap<>();
dMap.put("isDownloadComplete", "isComplete"); Map<String, String> dEntityModifyMap = new HashMap<>();
modifyColumnMap.put("DownloadEntity", dMap); dEntityModifyMap.put("groupName", "groupHash");
dEntityModifyMap.put("downloadUrl", "url");
Map<String, String> dGMap = new HashMap<>(); dEntityModifyMap.put("isDownloadComplete", "isComplete");
dGMap.put("groupName", "groupHash"); modifyMap.put("DownloadEntity", dEntityModifyMap);
modifyColumnMap.put("DownloadGroupEntity", dGMap);
Map<String, String> dGEntityModifyMap = new HashMap<>();
dGEntityModifyMap.put("groupName", "groupHash");
modifyMap.put("DownloadGroupEntity", dGEntityModifyMap);
// 删除字段
Map<String, List<String>> delColumnMap = new HashMap<>(); Map<String, List<String>> delColumnMap = new HashMap<>();
List<String> dEntityDel = new ArrayList<>(); List<String> dEntityDel = new ArrayList<>();
dEntityDel.add("taskKey"); dEntityDel.add("taskKey");
@ -344,6 +373,6 @@ final class SqlHelper extends SQLiteOpenHelper {
dgEntityDel.add("subtask"); dgEntityDel.add("subtask");
delColumnMap.put("DownloadGroupEntity", dgEntityDel); delColumnMap.put("DownloadGroupEntity", dgEntityDel);
handleDbUpdate(db, modifyColumnMap, delColumnMap); handleDbUpdate(db, modifyMap, delColumnMap);
} }
} }

@ -83,7 +83,7 @@ public class RecordUtil {
} }
} }
} }
DbEntity.deleteData(ThreadRecord.class, "key=?", record.taskRecord.filePath); DbEntity.deleteData(ThreadRecord.class, "taskKey=?", record.taskRecord.filePath);
record.taskRecord.deleteData(); record.taskRecord.deleteData();
} }
} }
@ -148,15 +148,14 @@ public class RecordUtil {
*/ */
if (!entity.isComplete()) { if (!entity.isComplete()) {
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件 if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件
String cacheDir = null; removeTsCache(targetFile, record.bandWidth);
if (!targetFile.isDirectory()) {
cacheDir = targetFile.getParent() + "/." + targetFile.getName();
}
removeTsCache(cacheDir);
} else if (record.isBlock) { // 删除分块文件 } else if (record.isBlock) { // 删除分块文件
removeBlockFile(record); removeBlockFile(record);
} }
} else if (removeFile) { // 处理任务完成情况 } else if (removeFile) { // 处理任务完成情况
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) {
removeTsCache(targetFile, record.bandWidth);
}
removeTargetFile(targetFile); removeTargetFile(targetFile);
} }
@ -209,16 +208,14 @@ public class RecordUtil {
*/ */
if (!entity.isComplete()) { if (!entity.isComplete()) {
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件 if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件
String cacheDir = null; removeTsCache(targetFile, record.bandWidth);
if (!targetFile.isDirectory()) {
cacheDir = String.format("%s/.%s_%s", targetFile.getParent(), targetFile.getName(),
record.bandWidth);
}
removeTsCache(cacheDir);
} else if (record.isBlock) { // 删除分块文件 } else if (record.isBlock) { // 删除分块文件
removeBlockFile(record); removeBlockFile(record);
} }
} else if (removeFile) { // 处理任务完成情况 } else if (removeFile) { // 处理任务完成情况
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) {
removeTsCache(targetFile, record.bandWidth);
}
removeTargetFile(targetFile); removeTargetFile(targetFile);
} }
@ -238,7 +235,7 @@ public class RecordUtil {
private static void removeRecord(String filePath) { private static void removeRecord(String filePath) {
ALog.i(TAG, "删除任务记录"); ALog.i(TAG, "删除任务记录");
DbEntity.deleteData(ThreadRecord.class, "key=?", filePath); DbEntity.deleteData(ThreadRecord.class, "taskKey=?", filePath);
DbEntity.deleteData(TaskRecord.class, "filePath=?", filePath); DbEntity.deleteData(TaskRecord.class, "filePath=?", filePath);
} }
@ -287,11 +284,17 @@ public class RecordUtil {
/** /**
* 删除ts文件 * 删除ts文件
*/ */
private static void removeTsCache(String cacheDir) { private static void removeTsCache(File targetFile, long bandWidth) {
String cacheDir = null;
if (!targetFile.isDirectory()) {
cacheDir =
String.format("%s/.%s_%s", targetFile.getParent(), targetFile.getName(), bandWidth);
}
if (!TextUtils.isEmpty(cacheDir)) { if (!TextUtils.isEmpty(cacheDir)) {
File cacheDirF = new File(cacheDir); File cacheDirF = new File(cacheDir);
if (!cacheDirF.exists()){ if (!cacheDirF.exists()) {
return; return;
} }
File[] files = cacheDirF.listFiles(); File[] files = cacheDirF.listFiles();
@ -348,7 +351,7 @@ public class RecordUtil {
// 修改线程记录 // 修改线程记录
if (record.threadRecords != null && !record.threadRecords.isEmpty()) { if (record.threadRecords != null && !record.threadRecords.isEmpty()) {
for (ThreadRecord tr : record.threadRecords) { for (ThreadRecord tr : record.threadRecords) {
tr.key = newPath; tr.taskKey = newPath;
File blockFile = new File(String.format(RecordHandler.SUB_PATH, oldPath, tr.threadId)); File blockFile = new File(String.format(RecordHandler.SUB_PATH, oldPath, tr.threadId));
if (blockFile.exists()) { if (blockFile.exists()) {
blockFile.renameTo(new File(String.format(RecordHandler.SUB_PATH, newPath, tr.threadId))); blockFile.renameTo(new File(String.format(RecordHandler.SUB_PATH, newPath, tr.threadId)));

@ -1,4 +1,7 @@
## 开发日志 ## 开发日志
+ v_3.7
- 适配androidX
- 修复组合任务,恢复下载,会出现进度显示为0的问题
+ v_3.6.5 + v_3.6.5
- fix bug https://github.com/AriaLyy/Aria/issues/403 - fix bug https://github.com/AriaLyy/Aria/issues/403
- fix bug https://github.com/AriaLyy/Aria/issues/414 - fix bug https://github.com/AriaLyy/Aria/issues/414

@ -158,7 +158,6 @@ protected void onCreate(Bundle savedInstanceState) {
## 其他 ## 其他
有任何问题,可以在[issues](https://github.com/AriaLyy/Aria/issues)给我留言反馈。</br> 有任何问题,可以在[issues](https://github.com/AriaLyy/Aria/issues)给我留言反馈。</br>
在提交问题前,希望你已经查看过[wiki](https://aria.laoyuyu.me/aria_doc/)或搜索过[issues](https://github.com/AriaLyy/Aria/issues)。</br> 在提交问题前,希望你已经查看过[wiki](https://aria.laoyuyu.me/aria_doc/)或搜索过[issues](https://github.com/AriaLyy/Aria/issues)。</br>
交流群:524329160
*** ***

@ -41,10 +41,10 @@
3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; 3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间;
对于3.4.1之前版本的未完成的老任务,依然采用原来的文件空间占用方式; 对于3.4.1之前版本的未完成的老任务,依然采用原来的文件空间占用方式;
--> -->
<threadNum value="3"/> <threadNum value="1"/>
<!--设置下载队列最大任务数, 默认为2--> <!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="1"/> <maxTaskNum value="3"/>
<!--设置下载失败,重试次数,默认为10--> <!--设置下载失败,重试次数,默认为10-->
<reTryNum value="1"/> <reTryNum value="1"/>

@ -40,7 +40,7 @@ public class FtpDownload extends BaseActivity<ActivityTestBinding> {
} }
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(DownloadTask task) {
Log.d(TAG, "onStart"); Log.d(TAG, "onPreStart");
} }
@Download.onTaskRunning protected void running(DownloadTask task) { @Download.onTaskRunning protected void running(DownloadTask task) {

@ -46,7 +46,7 @@ import java.io.IOException;
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> { public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
private String mUrl, mFilePath; private String mUrl, mFilePath;
private FtpDownloadModule mModule; private FtpDownloadModule mModule;
private DownloadEntity mEntity; private long mTaskId;
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState); super.init(savedInstanceState);
@ -60,10 +60,10 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
if (entity == null) { if (entity == null) {
return; return;
} }
mEntity = entity; mTaskId = entity.getId();
if (mEntity.getState() == IEntity.STATE_STOP) { if (entity.getState() == IEntity.STATE_STOP) {
getBinding().setStateStr(getString(R.string.resume)); getBinding().setStateStr(getString(R.string.resume));
} else if (mEntity.getState() == IEntity.STATE_RUNNING) { } else if (entity.getState() == IEntity.STATE_RUNNING) {
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
} }
@ -90,29 +90,34 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
if (!AppUtil.chekEntityValid(mEntity)) { if (mTaskId == -1) {
mTaskId = Aria.download(this).loadFtp(mUrl)
Aria.download(this).loadFtp(mUrl)
.setFilePath(mFilePath, true) .setFilePath(mFilePath, true)
.option().login("N0rI", "0qcK") .option()
.login("8L8e", "8guD")
.controller(ControllerType.START_CONTROLLER) .controller(ControllerType.START_CONTROLLER)
.start(); .start();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
break; break;
} }
if (Aria.download(this).load(mEntity.getId()).isRunning()) { if (Aria.download(this).load(mTaskId).isRunning()) {
getBinding().setStateStr(getString(R.string.resume)); getBinding().setStateStr(getString(R.string.resume));
Aria.download(this).loadFtp(mEntity.getId()).stop(); Aria.download(this).loadFtp(mTaskId).stop();
} else { } else {
Aria.download(this).loadFtp(mEntity.getId()).resume(); Aria.download(this)
.loadFtp(mTaskId)
.option()
.login("8L8e", "8guD")
.controller(ControllerType.NORMAL_CONTROLLER)
.resume();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
} }
break; break;
case R.id.cancel: case R.id.cancel:
if (AppUtil.chekEntityValid(mEntity)) { Aria.download(this).loadFtp(mTaskId).cancel();
Aria.download(this).loadFtp(mEntity.getId()).cancel(); getBinding().setStateStr(getString(R.string.start));
} mTaskId = -1;
break; break;
} }
} }
@ -162,12 +167,13 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
@Download.onTaskFail() void taskFail(DownloadTask task) { @Download.onTaskFail() void taskFail(DownloadTask task) {
L.d(TAG, "ftp task fail"); L.d(TAG, "ftp task fail");
getBinding().setStateStr(getString(R.string.resume));
} }
@Download.onTaskComplete() void taskComplete(DownloadTask task) { @Download.onTaskComplete() void taskComplete(DownloadTask task) {
getBinding().setSpeed(""); getBinding().setSpeed("");
getBinding().setProgress(100); getBinding().setProgress(100);
Log.d(TAG, "md5 ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); Log.d(TAG, "md5 ==> " + CommonUtil.getFileMD5(new File(task.getFilePath())));
T.showShort(this, "文件:" + task.getEntity().getFileName() + ",下载完成"); T.showShort(this, "文件:" + task.getEntity().getFileName() + ",下载完成");
} }

@ -16,7 +16,6 @@
package com.arialyy.simple.core.download; package com.arialyy.simple.core.download;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.Menu; import android.view.Menu;
@ -149,15 +148,11 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
if (AppUtil.chekEntityValid(mEntity)) { if (AppUtil.chekEntityValid(mEntity)) {
Aria.download(this) String text = ((TextView) view).getText().toString();
.load(DOWNLOAD_URL) if (text.equals("重新开始?") || text.equals("开始")) {
.setFilePath(Environment.getExternalStorageDirectory().getPath() } else {
+ "/Download/" Aria.download(this).load(mEntity.getId()).resume();
+ mTaskName }
+ ".apk")
.setHighestPriority();
} else {
Aria.download(this).load(mEntity.getId()).resume();
} }
((TextView) view).setText(getString(R.string.stop)); ((TextView) view).setText(getString(R.string.stop));
break; break;

@ -55,7 +55,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private String mUrl; private String mUrl;
private String mFilePath; private String mFilePath;
private HttpDownloadModule mModule; private HttpDownloadModule mModule;
private DownloadEntity mEntity; private long mTaskId = -1;
BroadcastReceiver receiver = new BroadcastReceiver() { BroadcastReceiver receiver = new BroadcastReceiver() {
@Override @Override
@ -95,11 +95,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
if (entity == null) { if (entity == null) {
return; return;
} }
mEntity = entity; mTaskId = entity.getId();
if (entity.getState() == IEntity.STATE_STOP) {
if (mEntity.getState() == IEntity.STATE_STOP) {
getBinding().setStateStr(getString(R.string.resume)); getBinding().setStateStr(getString(R.string.resume));
} else if (mEntity.getState() == IEntity.STATE_RUNNING) { } else if (entity.getState() == IEntity.STATE_RUNNING) {
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
} }
@ -231,6 +230,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Download.onTaskCancel @Download.onTaskCancel
void taskCancel(DownloadTask task) { void taskCancel(DownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
mTaskId = -1;
getBinding().setProgress(0); getBinding().setProgress(0);
getBinding().setStateStr(getString(R.string.start)); getBinding().setStateStr(getString(R.string.start));
getBinding().setSpeed(""); getBinding().setSpeed("");
@ -267,25 +267,24 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
if (!AppUtil.chekEntityValid(mEntity)) { if (mTaskId == -1) {
startD(); startD();
break;
} }
if (Aria.download(this).load(mEntity.getId()).isRunning()) { if (Aria.download(this).load(mTaskId).isRunning()) {
Aria.download(this).load(mEntity.getId()).stop(); Aria.download(this).load(mTaskId).stop();
} else { } else {
Aria.download(this).load(mEntity.getId()).resume(); Aria.download(this).load(mTaskId).resume();
} }
break; break;
case R.id.cancel: case R.id.cancel:
if (AppUtil.chekEntityValid(mEntity)) { Aria.download(this).load(mTaskId).cancel(true);
Aria.download(this).load(mEntity.getId()).cancel(true);
}
break; break;
} }
} }
private void startD() { private void startD() {
Aria.download(SingleTaskActivity.this) mTaskId = Aria.download(SingleTaskActivity.this)
.load(mUrl) .load(mUrl)
.useServerFileName(true) .useServerFileName(true)
.setFilePath(mFilePath, true) .setFilePath(mFilePath, true)

@ -32,7 +32,6 @@ import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityDownloadGroupBinding; import com.arialyy.simple.databinding.ActivityDownloadGroupBinding;
import com.arialyy.simple.util.AppUtil;
import com.arialyy.simple.widget.SubStateLinearLayout; import com.arialyy.simple.widget.SubStateLinearLayout;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -44,7 +43,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
private SubStateLinearLayout mChildList; private SubStateLinearLayout mChildList;
private List<String> mUrls; private List<String> mUrls;
private DownloadGroupEntity mEntity; private long mTaskId = -1;
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState); super.init(savedInstanceState);
@ -53,21 +52,22 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
mChildList = getBinding().childList; mChildList = getBinding().childList;
mUrls = getModule(GroupModule.class).getUrls(); mUrls = getModule(GroupModule.class).getUrls();
mEntity = Aria.download(this).getGroupEntity(mUrls); DownloadGroupEntity entity = Aria.download(this).getGroupEntity(mUrls);
if (mEntity != null) { if (entity != null) {
mChildList.addData(mEntity.getSubEntities()); mTaskId = entity.getId();
mChildList.addData(entity.getSubEntities());
getBinding().setStateStr( getBinding().setStateStr(
mEntity.getState() == IEntity.STATE_RUNNING ? getString(R.string.stop) entity.getState() == IEntity.STATE_RUNNING ? getString(R.string.stop)
: getString(R.string.resume)); : getString(R.string.resume));
getBinding().setFileSize(mEntity.getConvertFileSize()); getBinding().setFileSize(entity.getConvertFileSize());
if (mEntity.getFileSize() == 0) { if (entity.getFileSize() == 0) {
getBinding().setProgress(0); getBinding().setProgress(0);
} else { } else {
getBinding().setProgress(mEntity.isComplete() ? 100 getBinding().setProgress(entity.isComplete() ? 100
: (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize())); : (int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
} }
ALog.d(TAG, ALog.d(TAG,
"size = " + mEntity.getSubEntities().size() + "; len = " + mEntity.getConvertFileSize()); "size = " + entity.getSubEntities().size() + "; len = " + entity.getConvertFileSize());
} }
mChildList.setOnItemClickListener(new SubStateLinearLayout.OnItemClickListener() { mChildList.setOnItemClickListener(new SubStateLinearLayout.OnItemClickListener() {
@ -90,8 +90,8 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
if (!AppUtil.chekEntityValid(mEntity)) { if (mTaskId == -1) {
Aria.download(this) mTaskId = Aria.download(this)
.loadGroup(mUrls) .loadGroup(mUrls)
.setDirPath( .setDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_2") Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_2")
@ -117,17 +117,17 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
break; break;
} }
if (Aria.download(this).loadGroup(mEntity.getId()).isRunning()) { if (Aria.download(this).loadGroup(mTaskId).isRunning()) {
Aria.download(this).loadGroup(mEntity.getId()).stop(); Aria.download(this).loadGroup(mTaskId).stop();
getBinding().setStateStr(getString(R.string.resume));
} else { } else {
Aria.download(this).loadGroup(mEntity.getId()).resume(); Aria.download(this).loadGroup(mTaskId).resume();
getBinding().setStateStr(getString(R.string.stop));
} }
break; break;
case R.id.cancel: case R.id.cancel:
if (AppUtil.chekEntityValid(mEntity)) { Aria.download(this).loadGroup(mTaskId).cancel(true);
mTaskId = -1;
Aria.download(this).loadGroup(mEntity.getId()).cancel(true);
}
break; break;
} }
} }
@ -141,9 +141,6 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
} }
@DownloadGroup.onTaskPre() protected void onTaskPre(DownloadGroupTask task) { @DownloadGroup.onTaskPre() protected void onTaskPre(DownloadGroupTask task) {
if (mChildList.getSubData().size() <= 0) {
mChildList.addData(task.getEntity().getSubEntities());
}
L.d(TAG, "group task pre"); L.d(TAG, "group task pre");
getBinding().setFileSize(task.getConvertFileSize()); getBinding().setFileSize(task.getConvertFileSize());
if (mChildList.getSubData().size() <= 0) { if (mChildList.getSubData().size() <= 0) {

@ -23,37 +23,43 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.controller.ControllerType; import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityDownloadGroupBinding; import com.arialyy.simple.databinding.ActivityDownloadGroupBinding;
import com.arialyy.simple.util.AppUtil;
import com.arialyy.simple.widget.SubStateLinearLayout; import com.arialyy.simple.widget.SubStateLinearLayout;
/** /**
* Created by lyy on 2017/7/6. * Created by lyy on 2017/7/6.
*/ */
public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBinding> { public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBinding> {
private static final String dir = "ftp://9.9.9.50:21/upload/测试"; private static final String dir = "ftp://9.9.9.205:2121/upload/测试";
private SubStateLinearLayout mChildList; private SubStateLinearLayout mChildList;
private DownloadGroupEntity mEntity; private long mTaskId = -1;
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState); super.init(savedInstanceState);
Aria.download(this).register(); Aria.download(this).register();
setTitle("FTP文件夹下载"); setTitle("FTP文件夹下载");
mChildList = findViewById(R.id.child_list); mChildList = findViewById(R.id.child_list);
mEntity = Aria.download(this).getFtpDirEntity(dir); DownloadGroupEntity entity = Aria.download(this).getFtpDirEntity(dir);
if (mEntity != null) { if (entity != null) {
mChildList.addData(mEntity.getSubEntities()); mTaskId = entity.getId();
getBinding().setFileSize(mEntity.getConvertFileSize()); mChildList.addData(entity.getSubEntities());
if (mEntity.getFileSize() == 0) { getBinding().setFileSize(entity.getConvertFileSize());
if (entity.getState() == IEntity.STATE_RUNNING) {
getBinding().setStateStr(getString(R.string.stop));
} else {
getBinding().setStateStr(getString(R.string.start));
}
if (entity.getFileSize() == 0) {
getBinding().setProgress(0); getBinding().setProgress(0);
} else { } else {
getBinding().setProgress(mEntity.isComplete() ? 100 getBinding().setProgress(entity.isComplete() ? 100
: (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize())); : (int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
} }
} }
} }
@ -65,28 +71,35 @@ public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBi
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
if (!AppUtil.chekEntityValid(mEntity)) { if (mTaskId == -1) {
Aria.download(this) mTaskId = Aria.download(this)
.loadFtpDir(dir) .loadFtpDir(dir)
.setDirPath( .setDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/ftp_dir") Environment.getExternalStorageDirectory().getPath() + "/Download/ftp_dir")
.setGroupAlias("ftp文件夹下载") .setGroupAlias("ftp文件夹下载")
.option() .option()
.login("lao", "123456") .login("8L8e", "8guD")
.controller(ControllerType.START_CONTROLLER) .controller(ControllerType.START_CONTROLLER)
.start(); .start();
getBinding().setStateStr(getString(R.string.stop));
break; break;
} }
if (Aria.download(this).loadFtpDir(mEntity.getId()).isRunning()) { if (Aria.download(this).loadFtpDir(mTaskId).isRunning()) {
Aria.download(this).loadFtpDir(mEntity.getId()).stop(); Aria.download(this).loadFtpDir(mTaskId).stop();
getBinding().setStateStr(getString(R.string.resume));
} else { } else {
Aria.download(this).loadFtpDir(mEntity.getId()).resume(); Aria.download(this)
.loadFtpDir(mTaskId)
.option()
.login("8L8e", "8guD")
.controller(ControllerType.NORMAL_CONTROLLER)
.resume();
getBinding().setStateStr(getString(R.string.stop));
} }
break; break;
case R.id.cancel: case R.id.cancel:
if (AppUtil.chekEntityValid(mEntity)) { Aria.download(this).loadFtpDir(mTaskId).cancel();
Aria.download(this).loadFtpDir(mEntity.getId()).cancel(); mTaskId = -1;
}
break; break;
} }
} }
@ -99,12 +112,10 @@ public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBi
if (mChildList.getSubData().size() <= 0) { if (mChildList.getSubData().size() <= 0) {
mChildList.addData(task.getEntity().getSubEntities()); mChildList.addData(task.getEntity().getSubEntities());
} }
L.d(TAG, "group task pre");
getBinding().setFileSize(task.getConvertFileSize()); getBinding().setFileSize(task.getConvertFileSize());
} }
@DownloadGroup.onTaskStart() void taskStart(DownloadGroupTask task) { @DownloadGroup.onTaskStart() void taskStart(DownloadGroupTask task) {
L.d(TAG, "group task start");
} }
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) { @DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
@ -114,17 +125,16 @@ public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBi
} }
@DownloadGroup.onTaskResume() void taskResume(DownloadGroupTask task) { @DownloadGroup.onTaskResume() void taskResume(DownloadGroupTask task) {
L.d(TAG, "group task resume");
} }
@DownloadGroup.onTaskStop() void taskStop(DownloadGroupTask task) { @DownloadGroup.onTaskStop() void taskStop(DownloadGroupTask task) {
L.d(TAG, "group task stop");
getBinding().setSpeed(""); getBinding().setSpeed("");
} }
@DownloadGroup.onTaskCancel() void taskCancel(DownloadGroupTask task) { @DownloadGroup.onTaskCancel() void taskCancel(DownloadGroupTask task) {
getBinding().setSpeed(""); getBinding().setSpeed("");
getBinding().setProgress(0); getBinding().setProgress(0);
getBinding().setStateStr(getString(R.string.start));
} }
@DownloadGroup.onTaskFail() void taskFail(DownloadGroupTask task) { @DownloadGroup.onTaskFail() void taskFail(DownloadGroupTask task) {

@ -47,7 +47,6 @@ import com.arialyy.simple.common.ModifyPathDialog;
import com.arialyy.simple.common.ModifyUrlDialog; import com.arialyy.simple.common.ModifyUrlDialog;
import com.arialyy.simple.databinding.ActivityM3u8VodBinding; import com.arialyy.simple.databinding.ActivityM3u8VodBinding;
import com.arialyy.simple.to.PeerIndex; import com.arialyy.simple.to.PeerIndex;
import com.arialyy.simple.util.AppUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -61,7 +60,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
private String mFilePath; private String mFilePath;
private M3U8VodModule mModule; private M3U8VodModule mModule;
private VideoPlayerFragment mVideoFragment; private VideoPlayerFragment mVideoFragment;
private DownloadEntity mEntity; private long mTaskId;
@Override @Override
protected void init(Bundle savedInstanceState) { protected void init(Bundle savedInstanceState) {
@ -75,10 +74,10 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
if (entity == null) { if (entity == null) {
return; return;
} }
mEntity = entity; mTaskId = entity.getId();
if (mEntity.getState() == IEntity.STATE_STOP) { if (entity.getState() == IEntity.STATE_STOP) {
getBinding().setStateStr(getString(R.string.resume)); getBinding().setStateStr(getString(R.string.resume));
} else if (mEntity.getState() == IEntity.STATE_RUNNING) { } else if (entity.getState() == IEntity.STATE_RUNNING) {
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
} }
@ -272,26 +271,47 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
if (!AppUtil.chekEntityValid(mEntity)) { if (mTaskId == -1) {
startD(); startD();
break; break;
} }
if (Aria.download(this).load(mEntity.getId()).isRunning()) { if (Aria.download(this).load(mTaskId).isRunning()) {
Aria.download(this).load(mEntity.getId()).stop(); Aria.download(this).load(mTaskId).stop();
} else { } else {
Aria.download(this).load(mEntity.getId()).resume(); Aria.download(this)
.load(mTaskId)
.asM3U8()
.setBandWidthUrlConverter(new IBandWidthUrlConverter() {
@Override public String convert(String bandWidthUrl) {
int index = mUrl.lastIndexOf("/");
return mUrl.substring(0, index + 1) + bandWidthUrl;
}
})
.setTsUrlConvert(new IVodTsUrlConverter() {
@Override public List<String> convert(String m3u8Url, List<String> tsUrls) {
int index = m3u8Url.lastIndexOf("/");
String parentUrl = m3u8Url.substring(0, index + 1);
List<String> newUrls = new ArrayList<>();
for (String url : tsUrls) {
newUrls.add(parentUrl + url);
}
return newUrls;
}
})
.controller(ControllerType.NORMAL_CONTROLLER)
.resume();
} }
break; break;
case R.id.cancel: case R.id.cancel:
if (AppUtil.chekEntityValid(mEntity)) { Aria.download(this).load(mTaskId).cancel(true);
Aria.download(this).load(mEntity.getId()).cancel(true); mTaskId = -1;
}
break; break;
} }
} }
private void startD() { private void startD() {
Aria.download(M3U8VodDLoadActivity.this) mTaskId = Aria.download(M3U8VodDLoadActivity.this)
.load(mUrl) .load(mUrl)
.useServerFileName(true) .useServerFileName(true)
.setFilePath(mFilePath, true) .setFilePath(mFilePath, true)
@ -315,15 +335,13 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} }
}) })
.setMergeHandler(new ITsMergeHandler() { .setMergeHandler(new ITsMergeHandler() {
@Override public boolean merge(@Nullable M3U8KeyInfo keyInfo, List<String> tsPath) { public boolean merge(@Nullable M3U8KeyInfo keyInfo, List<String> tsPath) {
ALog.d(TAG, "合并TS....");
return false; return false;
} }
}) })
.controller(ControllerType.START_CONTROLLER) .controller(ControllerType.START_CONTROLLER)
.start(); .start();
//.start();
//.asVod().setPeerIndex(50)
//.start();
} }
private Class<StartController> c = StartController.class; private Class<StartController> c = StartController.class;

@ -55,7 +55,7 @@ public class VideoPlayerFragment extends BaseFragment<FragmentVideoPlayerBinding
getBinding().surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() { getBinding().surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override public void surfaceCreated(SurfaceHolder holder) { @Override public void surfaceCreated(SurfaceHolder holder) {
mSurfaceHolder = holder; mSurfaceHolder = holder;
startNewPlayer(mPlayers.valueAt(0)); //startNewPlayer(mPlayers.valueAt(0));
} }
@Override @Override

@ -207,10 +207,10 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
//删除按钮事件 //删除按钮事件
holder.cancel.setOnClickListener(new View.OnClickListener() { holder.cancel.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) { @Override public void onClick(View v) {
// mData.remove(entity); mData.remove(entity);
notifyDataSetChanged(); notifyDataSetChanged();
// cancel(entity); cancel(entity);
stop(entity); //stop(entity);
} }
}); });
//if (holder instanceof GroupHolder){ //if (holder instanceof GroupHolder){

@ -32,8 +32,8 @@ import com.arialyy.aria.util.ALog;
import com.arialyy.frame.util.FileUtil; import com.arialyy.frame.util.FileUtil;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiBinding;
import com.arialyy.simple.core.download.DownloadModule; import com.arialyy.simple.core.download.DownloadModule;
import com.arialyy.simple.databinding.ActivityMultiBinding;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -136,7 +136,7 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
} }
@DownloadGroup.onTaskFail void groupTaskFail(DownloadGroupTask task) { @DownloadGroup.onTaskFail void groupTaskFail(DownloadGroupTask task) {
if (task == null){ if (task == null) {
return; return;
} }
mAdapter.updateBtState(task.getKey(), true); mAdapter.updateBtState(task.getKey(), true);

@ -52,7 +52,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
private String mFilePath; private String mFilePath;
private String mUrl; private String mUrl;
private UploadModule mModule; private UploadModule mModule;
private UploadEntity mEntity; private long mTaskId = -1;
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
setTile("D_FTP 文件上传"); setTile("D_FTP 文件上传");
@ -67,8 +67,8 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
mModule = ViewModelProviders.of(this).get(UploadModule.class); mModule = ViewModelProviders.of(this).get(UploadModule.class);
mModule.getFtpInfo(this).observe(this, new Observer<UploadEntity>() { mModule.getFtpInfo(this).observe(this, new Observer<UploadEntity>() {
@Override public void onChanged(@Nullable UploadEntity entity) { @Override public void onChanged(@Nullable UploadEntity entity) {
mEntity = entity;
if (entity != null) { if (entity != null) {
mTaskId = entity.getId();
if (entity.getFileSize() != 0) { if (entity.getFileSize() != 0) {
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize())); getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
getBinding().setProgress(entity.isComplete() ? 100 getBinding().setProgress(entity.isComplete() ? 100
@ -79,7 +79,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
mUrl = entity.getUrl(); mUrl = entity.getUrl();
mFilePath = entity.getFilePath(); mFilePath = entity.getFilePath();
getBinding().setStateStr(getString( getBinding().setStateStr(getString(
entity.getState() == IEntity.STATE_RUNNING ? R.string.stop : R.string.resume)); entity.getState() == IEntity.STATE_RUNNING ? R.string.stop : R.string.start));
} else { } else {
getBinding().setStateStr(getString(R.string.resume)); getBinding().setStateStr(getString(R.string.resume));
} }
@ -113,38 +113,47 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
if (!AppUtil.chekEntityValid(mEntity)) { if (mTaskId == -1) {
Aria.upload(this).loadFtp(mFilePath).setUploadUrl(mUrl).setUploadInterceptor( mTaskId = Aria.upload(this)
new IFtpUploadInterceptor() { .loadFtp(mFilePath)
.setUploadUrl(mUrl)
@Override .setUploadInterceptor(
public FtpInterceptHandler onIntercept(UploadEntity entity, List<String> fileList) { new IFtpUploadInterceptor() {
FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder();
//builder.coverServerFile(); @Override
builder.resetFileName("test.zip"); public FtpInterceptHandler onIntercept(UploadEntity entity,
return builder.build(); List<String> fileList) {
} FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder();
}) //builder.coverServerFile();
builder.resetFileName("test.zip");
return builder.build();
}
})
.option() .option()
.login("N0rI", "0qcK") .login("8L8e", "8guD")
.controller(ControllerType.START_CONTROLLER) .controller(ControllerType.START_CONTROLLER)
.start(); .start();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
break; break;
} }
if (Aria.download(this).loadFtp(mEntity.getId()).isRunning()) { if (Aria.upload(this).loadFtp(mTaskId).isRunning()) {
Aria.download(this).loadFtp(mEntity.getId()).stop(); Aria.upload(this).loadFtp(mTaskId).stop();
getBinding().setStateStr(getString(R.string.resume)); getBinding().setStateStr(getString(R.string.resume));
} else { } else {
Aria.download(this).loadFtp(mEntity.getId()).resume(); Aria.upload(this)
.loadFtp(mTaskId)
.option()
.login("8L8e", "8guD")
.controller(ControllerType.NORMAL_CONTROLLER)
.resume();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
} }
break; break;
case R.id.cancel: case R.id.cancel:
if (AppUtil.chekEntityValid(mEntity)) { Aria.upload(this).loadFtp(mTaskId).cancel();
Aria.upload(this).loadFtp(mEntity.getId()).cancel(); mTaskId = -1;
} getBinding().setStateStr(getString(R.string.start));
break; break;
} }
} }
@ -179,6 +188,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
@Upload.onTaskFail public void taskFail(UploadTask task) { @Upload.onTaskFail public void taskFail(UploadTask task) {
Log.d(TAG, "上传失败"); Log.d(TAG, "上传失败");
getBinding().setStateStr(getString(R.string.resume));
} }
@Upload.onTaskRunning public void taskRunning(UploadTask task) { @Upload.onTaskRunning public void taskRunning(UploadTask task) {
@ -191,6 +201,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
getBinding().setProgress(100); getBinding().setProgress(100);
getBinding().setSpeed(""); getBinding().setSpeed("");
T.showShort(this, "文件:" + task.getEntity().getFileName() + ",上传完成"); T.showShort(this, "文件:" + task.getEntity().getFileName() + ",上传完成");
getBinding().setStateStr(getString(R.string.re_start));
} }
@Override protected void dataCallback(int result, Object data) { @Override protected void dataCallback(int result, Object data) {

@ -52,7 +52,7 @@ public class AnyRunnModule {
} }
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(DownloadTask task) {
Log.d(TAG, "onStart"); Log.d(TAG, "onPreStart");
} }
@Download.onTaskRunning protected void running(DownloadTask task) { @Download.onTaskRunning protected void running(DownloadTask task) {

@ -64,26 +64,16 @@
<string-array name="test_apk_download_url"> <string-array name="test_apk_download_url">
<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item> <!--300M的文件-->
<item>http://static.gaoshouyou.com/d/21/e8/61218d78d0e8b79df68dbc18dd484c97.apk</item>
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
<item>http://static.gaoshouyou.com/d/d4/4f/d6d48db3794fb9ecf47e83c346570881.apk</item> <item>http://static.gaoshouyou.com/d/d4/4f/d6d48db3794fb9ecf47e83c346570881.apk</item>
<!--<item>http://static.gaoshouyou.com/d/18/cf/ba18113bc6cf56c1c5863e761e717003.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/60/17/2460921367173ea7145f11194a6f2587.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/32/e0/1a32123ecbe0ee010d35479df248f90f.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk</item>-->
</string-array> </string-array>
<string-array name="file_nams"> <string-array name="file_nams">
<item>阴阳师</item> <item>王者荣耀</item>
<item>奇迹暖暖</item> <item>植物大战僵尸</item>
<item>幻影纹章</item> <item>部落冲突</item>
<item>史上最坑爹的游戏10</item> <item>瘟疫公司</item>
<item>鲜果消消乐</item> <item>水上公园大战</item>
<item>航海奇迹</item> <item>死亡之雨</item>
<item>test_1</item> <item>test_1</item>
<item>test_2</item> <item>test_2</item>
@ -91,13 +81,12 @@
</string-array> </string-array>
<string-array name="download_url"> <string-array name="download_url">
<item>https://g37.gdl.netease.com/onmyoji_netease_10_1.0.20.apk</item> <item>https://downs.muzhiwan.com/2019/06/28/com.tencent.tmgp.sgame5d15f9df3bb4d.gpk</item>
<item>http://static.gaoshouyou.com/d/eb/f2/dfeba30541f209ab8a50d847fc1661ce.apk</item> <item>https://downs.muzhiwan.com/2017/03/15/com.ea.game.pvz2_row58c8bfc00eea8.gpk</item>
<item>http://rs.0.gaoshouyou.com/d/51/46/58514d126c46b8a3f27fc8c7db3b09ec.apk</item> <item>https://downs.muzhiwan.com/2019/07/04/com.supercell.clashofclans.ewan.mzw_5d1da09397884.apk</item>
<item>http://rs.0.gaoshouyou.com/d/23/69/07238f952669727878d7a0e180534c8b.apk</item> <item>https://downs.muzhiwan.com/2019/02/28/com.miniclip.plagueinc_5c77596c79179.apk</item>
<item>http://rs.0.gaoshouyou.com/d/e7/3d/73e716d3353de5b479fcf7da8d36a5ef.apk</item> <item>https://downs.muzhiwan.com/2019/06/03/com.aqua.slide_5cf4b69e90e6a.apk</item>
<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item> <item>https://downs.muzhiwan.com/2019/05/07/com.tinydevbox.deadrain2_g_5cd14a8aedb2f.apk</item>
<item>http://dby-resource-android.duobeiyun.com/jz22a8508b4265466b9fb4bb29082eaa2d.zip</item> <item>http://dby-resource-android.duobeiyun.com/jz22a8508b4265466b9fb4bb29082eaa2d.zip</item>
<item>http://dby-resource-android.duobeiyun.com/jz05fa8faf068145fcb25c93c8091297ad.zip</item> <item>http://dby-resource-android.duobeiyun.com/jz05fa8faf068145fcb25c93c8091297ad.zip</item>
<item>http://dby-resource-android.duobeiyun.com/jz684e1b4c2f6b4576979e60fd95edebad.zip</item> <item>http://dby-resource-android.duobeiyun.com/jz684e1b4c2f6b4576979e60fd95edebad.zip</item>

@ -43,7 +43,7 @@ task clean(type: Delete) {
ext { ext {
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = '3.6.5' publishVersion = '3.6.6_beta_1'
// publishVersion = '1.0.4' //FTP插件 // publishVersion = '1.0.4' //FTP插件
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'

Loading…
Cancel
Save