优化代码,移除不必要的TaskEntity

v3.6.6
laoyuyu 6 years ago
parent 7f52271ee5
commit f6792b225a
  1. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  2. 8
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java
  3. 8
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  4. 70
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  6. 4
      Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java
  7. 6
      Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java
  8. 6
      Aria/src/main/java/com/arialyy/aria/core/download/DGEntityWrapper.java
  9. 10
      Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java
  10. 13
      Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java
  11. 5
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java
  12. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  13. 19
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  14. 4
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java
  15. 3
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java
  16. 44
      Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DGSTEWrapper.java
  17. 65
      Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DGTEWrapper.java
  18. 46
      Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DTEWrapper.java
  19. 4
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskWrapper.java
  20. 4
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  21. 16
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java
  22. 168
      Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java
  23. 90
      Aria/src/main/java/com/arialyy/aria/core/manager/DGTaskWrapperFactory.java
  24. 44
      Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java
  25. 179
      Aria/src/main/java/com/arialyy/aria/core/manager/TaskWrapperManager.java
  26. 43
      Aria/src/main/java/com/arialyy/aria/core/manager/UTaskWrapperFactory.java
  27. 10
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  28. 4
      Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java
  29. 13
      Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java
  30. 4
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  31. 4
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java
  32. 47
      Aria/src/main/java/com/arialyy/aria/core/upload/wrapper/UTEWrapper.java
  33. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  34. 3
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  35. 115
      Aria/src/main/java/com/arialyy/aria/util/DbDataHelper.java
  36. 42
      Aria/src/main/java/com/arialyy/aria/util/DbHelper.java
  37. 6
      app/src/main/AndroidManifest.xml
  38. 4
      app/src/main/java/com/arialyy/simple/DbTestActivity.java
  39. 6
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  40. 2
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java

@ -24,7 +24,7 @@ import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
@ -192,7 +192,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskWrapper> extends AbsCmd<T> {
* @return 创建的任务
*/
AbsTask createTask(AbsTaskWrapper taskEntity) {
TEManager.getInstance().addTEntity(taskEntity);
TaskWrapperManager.getInstance().addTaskWrapper(taskEntity);
return mQueue.createTask(taskEntity);
}
}

@ -21,7 +21,7 @@ import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
@ -64,7 +64,7 @@ public class CancelAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
DbEntity.findDatas(DownloadEntity.class, "isGroupChild=?", "false");
if (entities != null && !entities.isEmpty()) {
for (DownloadEntity entity : entities) {
remove(TEManager.getInstance().getTEntity(DTaskWrapper.class, entity.getKey()));
remove(TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, entity.getKey()));
}
}
}
@ -78,7 +78,7 @@ public class CancelAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
if (entities != null && !entities.isEmpty()) {
for (DownloadGroupEntity entity : entities) {
remove(
TEManager.getInstance().getGTEntity(DGTaskWrapper.class, entity.getUrls()));
TaskWrapperManager.getInstance().getDGTaskWrapper(DGTaskWrapper.class, entity.getUrls()));
}
}
}
@ -91,7 +91,7 @@ public class CancelAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
DbEntity.findDatas(UploadEntity.class, "isGroupChild=?", "false");
if (entities != null && !entities.isEmpty()) {
for (UploadEntity entity : entities) {
remove(TEManager.getInstance().getTEntity(UTaskWrapper.class, entity.getKey()));
remove(TaskWrapperManager.getInstance().getHttpTaskWrapper(UTaskWrapper.class, entity.getKey()));
}
}
}

@ -8,7 +8,7 @@ import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
@ -65,7 +65,7 @@ final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
//if (TextUtils.isEmpty(entity.getDownloadPath())){
// continue;
//}
resumeTask(TEManager.getInstance().getTEntity(DTaskWrapper.class, entity.getKey()));
resumeTask(TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, entity.getKey()));
}
}
} else if (type == 2) {
@ -74,7 +74,7 @@ final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
if (entities != null && !entities.isEmpty()) {
for (DownloadGroupEntity entity : entities) {
resumeTask(
TEManager.getInstance().getGTEntity(DGTaskWrapper.class, entity.getUrls()));
TaskWrapperManager.getInstance().getDGTaskWrapper(DGTaskWrapper.class, entity.getUrls()));
}
}
} else if (type == 3) {
@ -82,7 +82,7 @@ final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
DbEntity.findDatas(UploadEntity.class, "state!=? ORDER BY stopTime DESC", "1");
if (entities != null && !entities.isEmpty()) {
for (UploadEntity entity : entities) {
resumeTask(TEManager.getInstance().getTEntity(UTaskWrapper.class, entity.getKey()));
resumeTask(TaskWrapperManager.getInstance().getHttpTaskWrapper(UTaskWrapper.class, entity.getKey()));
}
}
}

@ -20,19 +20,22 @@ import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.wrapper.DGTEWrapper;
import com.arialyy.aria.core.download.wrapper.DTEWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.wrapper.UTEWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.AbsWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.DbDataHelper;
import com.arialyy.aria.util.NetUtils;
import java.util.ArrayList;
import java.util.List;
@ -69,7 +72,7 @@ class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
startTask();
} else if (mod.equals(QueueMod.WAIT.getTag())) {
int state = task.getState();
if (mQueue.getCurrentExePoolNum() < maxTaskNum){
if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
if (state == IEntity.STATE_STOP
|| task.getState() == IEntity.STATE_FAIL
|| task.getState() == IEntity.STATE_OTHER
@ -77,7 +80,7 @@ class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|| task.getState() == IEntity.STATE_POST_PRE
|| task.getState() == IEntity.STATE_COMPLETE) {
resumeTask();
}else {
} else {
startTask();
}
} else {
@ -117,28 +120,41 @@ class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
private List<AbsTaskWrapper> findWaitData(int type) {
List<AbsTaskWrapper> waitList = new ArrayList<>();
if (type == 1) {
List<DTEWrapper> wrappers = DbEntity.findRelationData(DTEWrapper.class,
"DTaskWrapper.isGroupTask=? and DTaskWrapper.state=?", "false", "3");
if (wrappers != null && !wrappers.isEmpty()) {
for (DTEWrapper w : wrappers) {
waitList.add(w.taskEntity);
}
}
} else if (type == 2) {
List<DGTEWrapper> wrappers =
DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.state=?", "3");
if (wrappers != null && !wrappers.isEmpty()) {
for (DGTEWrapper w : wrappers) {
waitList.add(w.taskEntity);
}
}
} else if (type == 3) {
List<UTEWrapper> wrappers = DbEntity.findRelationData(UTEWrapper.class,
"UTaskWrapper.state=?", "3");
if (wrappers != null && !wrappers.isEmpty()) {
for (UTEWrapper w : wrappers) {
waitList.add(w.taskEntity);
TaskWrapperManager tManager = TaskWrapperManager.getInstance();
if (type == 1) { // 普通下载任务
List<DownloadEntity> dEntities = DbEntity.findDatas(DownloadEntity.class,
"isGroupChild=? and state=?", "false", "3");
if (dEntities != null && !dEntities.isEmpty()) {
for (DownloadEntity e : dEntities) {
if (e.getTaskType() == AbsTaskWrapper.D_FTP) {
waitList.add(tManager.getFtpTaskWrapper(DTaskWrapper.class, e.getKey()));
} else if (e.getTaskType() == AbsTaskWrapper.D_HTTP) {
waitList.add(tManager.getHttpTaskWrapper(DTaskWrapper.class, e.getKey()));
}
}
}
} else if (type == 2) { // 组合任务
List<DownloadGroupEntity> dEntities =
DbEntity.findDatas(DownloadGroupEntity.class, "state=?", "3");
if (dEntities != null && !dEntities.isEmpty()) {
for (DownloadGroupEntity e : dEntities) {
if (e.getTaskType() == AbsTaskWrapper.DG_HTTP) {
waitList.add(tManager.getDGTaskWrapper(DGTaskWrapper.class, e.getUrls()));
} else if (e.getTaskType() == AbsTaskWrapper.D_FTP_DIR) {
waitList.add(tManager.getFtpTaskWrapper(DGTaskWrapper.class, e.getKey()));
}
}
}
} else if (type == 3) { //普通上传任务
List<UploadEntity> dEntities = DbEntity.findDatas(UploadEntity.class, "state=?", "3");
if (dEntities != null && !dEntities.isEmpty()) {
for (UploadEntity e : dEntities) {
if (e.getTaskType() == AbsTaskWrapper.D_FTP) {
waitList.add(tManager.getFtpTaskWrapper(UTaskWrapper.class, e.getKey()));
} else if (e.getTaskType() == AbsTaskWrapper.D_HTTP) {
waitList.add(tManager.getHttpTaskWrapper(UTaskWrapper.class, e.getKey()));
}
}
}
}

@ -28,7 +28,7 @@ import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.DbHelper;
import com.arialyy.aria.util.DbDataHelper;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
@ -305,7 +305,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
if (mConfigFile.exists()) {
convertDb();
} else {
mRecord = DbHelper.getTaskRecord(mTaskEntity.getKey());
mRecord = DbDataHelper.getTaskRecord(mTaskEntity.getKey());
if (mRecord == null) {
initRecord(true);
} else {

@ -62,8 +62,8 @@ public class StateConstance {
* 所有子线程是否都已经失败
*/
public boolean isFail() {
ALog.d(TAG, String.format("fail_num=%s; start_thread_num=%s; complete_num=%s", FAIL_NUM,
START_THREAD_NUM, COMPLETE_THREAD_NUM));
//ALog.d(TAG, String.format("fail_num=%s; start_thread_num=%s; complete_num=%s", FAIL_NUM,
// START_THREAD_NUM, COMPLETE_THREAD_NUM));
return COMPLETE_THREAD_NUM != START_THREAD_NUM
&& (FAIL_NUM == START_THREAD_NUM || FAIL_NUM + COMPLETE_THREAD_NUM == START_THREAD_NUM);
}

@ -16,7 +16,7 @@
package com.arialyy.aria.core.download;
import android.text.TextUtils;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
@ -40,7 +40,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
void initTarget(String url, String targetName) {
this.url = url;
mTargetName = targetName;
mTaskWrapper = TEManager.getInstance().getTEntity(DTaskWrapper.class, url);
mTaskWrapper = TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, url);
mEntity = mTaskWrapper.getEntity();
if (mEntity != null) {
@ -164,7 +164,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
} else {
ALog.w(TAG, "保存路径【" + filePath + "】已经被其它任务占用,当前任务将覆盖该路径的文件");
CommonUtil.delTaskRecord(filePath, 1);
mTaskWrapper = TEManager.getInstance().getTEntity(DTaskWrapper.class, url);
mTaskWrapper = TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, url);
}
}
File oldFile = new File(mEntity.getDownloadPath());

@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.wrapper;
package com.arialyy.aria.core.download;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.orm.AbsWrapper;
import com.arialyy.aria.orm.annotation.Many;
import com.arialyy.aria.orm.annotation.One;
@ -28,7 +26,7 @@ import java.util.List;
* 任务组实体和子任务实体的关系
*/
@Wrapper
public class DGEWrapper extends AbsWrapper {
public class DGEntityWrapper extends AbsWrapper {
@One
public DownloadGroupEntity groupEntity;

@ -23,18 +23,12 @@ import java.util.List;
*/
public class DGTaskWrapper extends AbsGroupTaskWrapper<DownloadGroupEntity, DTaskWrapper> {
private DownloadGroupEntity entity;
private List<DTaskWrapper> subTaskEntities;
private String key;
@Override public DownloadGroupEntity getEntity() {
return entity;
}
public void setEntity(DownloadGroupEntity entity) {
this.entity = entity;
public DGTaskWrapper(DownloadGroupEntity entity) {
super(entity);
}
@Override

@ -22,8 +22,6 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper;
*/
public class DTaskWrapper extends AbsTaskWrapper<DownloadEntity> {
private DownloadEntity entity;
/**
* 任务的url
*/
@ -44,11 +42,8 @@ public class DTaskWrapper extends AbsTaskWrapper<DownloadEntity> {
*/
private String key;
public DTaskWrapper() {
}
@Override public DownloadEntity getEntity() {
return entity;
public DTaskWrapper(DownloadEntity entity) {
super(entity);
}
@Override public String getKey() {
@ -71,10 +66,6 @@ public class DTaskWrapper extends AbsTaskWrapper<DownloadEntity> {
return isGroupTask;
}
public void setEntity(DownloadEntity entity) {
this.entity = entity;
}
public void setUrl(String url) {
this.url = url;
}

@ -22,15 +22,12 @@ import com.arialyy.aria.orm.annotation.Ignore;
import java.util.List;
/**
* Created by AriaL on 2017/6/29.
* 下载任务组实体
* Created by AriaL on 2017/6/29. 下载任务组实体
*/
public class DownloadGroupEntity extends AbsGroupEntity {
@Ignore private List<DownloadEntity> subEntities;
/**
* 子任务实体列表
*/

@ -22,7 +22,7 @@ import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.common.http.HttpHeaderDelegate;
import com.arialyy.aria.core.common.http.PostDelegate;
import com.arialyy.aria.core.inf.IHttpHeaderDelegate;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@ -67,7 +67,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
private void init() {
mGroupName = CommonUtil.getMd5Code(mUrls);
mTaskWrapper = TEManager.getInstance().getGTEntity(DGTaskWrapper.class, mUrls);
mTaskWrapper = TaskWrapperManager.getInstance().getDGTaskWrapper(DGTaskWrapper.class, mUrls);
mEntity = mTaskWrapper.getEntity();
if (mEntity != null) {
mDirPathTemp = mEntity.getDirPath();

@ -23,11 +23,10 @@ import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.normal.CancelAllCmd;
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.download.wrapper.DGEWrapper;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.ReceiverType;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.orm.DbEntity;
@ -243,7 +242,7 @@ public class DownloadReceiver extends AbsReceiver {
if (!taskExists(downloadUrl)) {
return null;
}
return TEManager.getInstance().getTEntity(DTaskWrapper.class, downloadUrl);
return TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, downloadUrl);
}
/**
@ -260,7 +259,7 @@ public class DownloadReceiver extends AbsReceiver {
if (!taskExists(urls)) {
return null;
}
return TEManager.getInstance().getGTEntity(DGTaskWrapper.class, urls);
return TaskWrapperManager.getInstance().getDGTaskWrapper(DGTaskWrapper.class, urls);
}
/**
@ -279,7 +278,7 @@ public class DownloadReceiver extends AbsReceiver {
if (!b) {
return null;
}
return TEManager.getInstance().getFDTEntity(DGTaskWrapper.class, dirUrl);
return TaskWrapperManager.getInstance().getFtpTaskWrapper(DGTaskWrapper.class, dirUrl);
}
/**
@ -336,12 +335,12 @@ public class DownloadReceiver extends AbsReceiver {
* @return 如果没有任务组列表则返回null
*/
public List<DownloadGroupEntity> getGroupTaskList() {
List<DGEWrapper> wrappers = DbEntity.findRelationData(DGEWrapper.class);
List<DGEntityWrapper> wrappers = DbEntity.findRelationData(DGEntityWrapper.class);
if (wrappers == null || wrappers.isEmpty()) {
return null;
}
List<DownloadGroupEntity> entities = new ArrayList<>();
for (DGEWrapper wrapper : wrappers) {
for (DGEntityWrapper wrapper : wrappers) {
entities.add(wrapper.groupEntity);
}
return entities;
@ -369,7 +368,7 @@ public class DownloadReceiver extends AbsReceiver {
public void stopAllTask() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(NormalCmdFactory.getInstance()
.createCmd(new DTaskWrapper(), NormalCmdFactory.TASK_STOP_ALL,
.createCmd(new DTaskWrapper(null), NormalCmdFactory.TASK_STOP_ALL,
ICmd.TASK_TYPE_DOWNLOAD))
.exe();
}
@ -382,7 +381,7 @@ public class DownloadReceiver extends AbsReceiver {
public void resumeAllTask() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(NormalCmdFactory.getInstance()
.createCmd(new DTaskWrapper(), NormalCmdFactory.TASK_RESUME_ALL,
.createCmd(new DTaskWrapper(null), NormalCmdFactory.TASK_RESUME_ALL,
ICmd.TASK_TYPE_DOWNLOAD))
.exe();
}
@ -396,7 +395,7 @@ public class DownloadReceiver extends AbsReceiver {
public void removeAllTask(boolean removeFile) {
final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP);
CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createNormalCmd(new DTaskWrapper(),
(CancelAllCmd) CommonUtil.createNormalCmd(new DTaskWrapper(null),
NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_DOWNLOAD);
cancelCmd.removeFile = removeFile;
ariaManager.setCmd(cancelCmd).exe();

@ -22,7 +22,7 @@ import com.arialyy.aria.core.common.ftp.FTPSConfig;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IFtpTarget;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.util.ALog;
import java.net.Proxy;
@ -41,7 +41,7 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
private void init(String key) {
mGroupName = key;
mTaskWrapper = TEManager.getInstance().getFDTEntity(DGTaskWrapper.class, key);
mTaskWrapper = TaskWrapperManager.getInstance().getFtpTaskWrapper(DGTaskWrapper.class, key);
mTaskWrapper.setRequestType(AbsTaskWrapper.D_FTP_DIR);
mEntity = mTaskWrapper.getEntity();
if (mEntity != null) {

@ -72,10 +72,9 @@ class FtpDirInfoThread extends AbsFtpInfoThread<DownloadGroupEntity, DGTaskWrapp
entity.setFileSize(ftpFile.getSize());
entity.insert();
DTaskWrapper taskEntity = new DTaskWrapper();
DTaskWrapper taskEntity = new DTaskWrapper(entity);
taskEntity.setKey(entity.getDownloadPath());
taskEntity.setUrl(entity.getUrl());
taskEntity.setEntity(entity);
taskEntity.setGroupTask(true);
taskEntity.setGroupName(mEntity.getGroupName());
taskEntity.setRequestType(AbsTaskWrapper.D_FTP);

@ -1,44 +0,0 @@
/*
* 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.download.wrapper;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.orm.AbsWrapper;
import com.arialyy.aria.orm.annotation.Many;
import com.arialyy.aria.orm.annotation.One;
import com.arialyy.aria.orm.annotation.Wrapper;
import java.util.List;
/**
* Created by laoyuyu on 2018/4/11.
* 任务组任务实体和任务组任务实体的子任务实体对应关系
*/
@Wrapper
public class DGSTEWrapper extends AbsWrapper {
@One
public DGTaskWrapper dgTaskEntity;
@Many(parentColumn = "key", entityColumn = "groupName")
public List<DTaskWrapper> subTaskEntity;
@Override protected void handleConvert() {
if (subTaskEntity != null && !subTaskEntity.isEmpty()) {
dgTaskEntity.setSubTaskWrapper(subTaskEntity);
}
}
}

@ -1,65 +0,0 @@
/*
* 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.download.wrapper;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.orm.AbsWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.annotation.Many;
import com.arialyy.aria.orm.annotation.One;
import com.arialyy.aria.orm.annotation.Wrapper;
import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Created by laoyuyu on 2018/3/30.
* 任务组实体和任务组任务实体的关系
*/
@Wrapper
public class DGTEWrapper extends AbsWrapper {
@One
public DownloadGroupEntity entity;
@Many(parentColumn = "groupName", entityColumn = "key")
private List<DGTaskWrapper> taskEntitys;
public DGTaskWrapper taskEntity;
@Override protected void handleConvert() {
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0);
if (taskEntity != null) {
taskEntity.setEntity(entity);
List<DTEWrapper> subWrappers =
DbEntity.findRelationData(DTEWrapper.class, "DTaskWrapper.groupName=?",
taskEntity.getKey());
if (subWrappers != null && !subWrappers.isEmpty()) {
List<DTaskWrapper> temp = new ArrayList<>();
for (DTEWrapper dw : subWrappers) {
if (dw.taskEntity.getRequestType() == AbsTaskWrapper.D_FTP) {
dw.taskEntity.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(dw.taskEntity.getUrl()));
}
temp.add(dw.taskEntity);
}
taskEntity.setSubTaskWrapper(temp);
}
}
}
}

@ -1,46 +0,0 @@
/*
* 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.download.wrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.orm.AbsWrapper;
import com.arialyy.aria.orm.annotation.Many;
import com.arialyy.aria.orm.annotation.One;
import com.arialyy.aria.orm.annotation.Wrapper;
import java.util.List;
/**
* Created by laoyuyu on 2018/3/30.
*/
@Wrapper
public class DTEWrapper extends AbsWrapper {
@One
public DownloadEntity entity;
@Many(parentColumn = "downloadPath", entityColumn = "key")
private List<DTaskWrapper> taskEntitys = null;
public DTaskWrapper taskEntity;
@Override public void handleConvert() {
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0);
if (taskEntity != null) {
taskEntity.setEntity(entity);
}
}
}

@ -24,6 +24,10 @@ import java.util.List;
public abstract class AbsGroupTaskWrapper<ENTITY extends AbsEntity, SUB extends AbsTaskWrapper>
extends AbsTaskWrapper<ENTITY> {
public AbsGroupTaskWrapper(ENTITY entity) {
super(entity);
}
public abstract List<SUB> getSubTaskWrapper();
public abstract void setSubTaskWrapper(List<SUB> subTaskWrapper);

@ -25,7 +25,7 @@ import com.arialyy.aria.core.common.TaskRecord;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
@ -78,7 +78,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
} else if (mEntity instanceof DownloadGroupEntity) {
CommonUtil.delGroupTaskRecord(mTaskWrapper.isRemoveFile(), ((DownloadGroupEntity) mEntity));
}
TEManager.getInstance().removeTEntity(mEntity.getKey());
TaskWrapperManager.getInstance().removeTaskWrapper(mEntity.getKey());
}
}

@ -17,6 +17,9 @@ package com.arialyy.aria.core.inf;
import com.arialyy.aria.core.common.ftp.FtpTaskDelegate;
import com.arialyy.aria.core.common.http.HttpTaskDelegate;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.upload.UploadEntity;
/**
* Created by lyy on 2017/2/23. 所有任务实体的父类
@ -64,10 +67,23 @@ public abstract class AbsTaskWrapper<ENTITY extends AbsEntity>
*/
private int code;
/**
* {@link DownloadEntity} or {@link UploadEntity} or {@link DownloadGroupEntity}
*/
private ENTITY entity;
public AbsTaskWrapper(ENTITY entity) {
this.entity = entity;
}
public abstract String getKey();
public abstract void setKey(String key);
@Override public ENTITY getEntity() {
return entity;
}
/**
* 设置或获取HTTP任务相关参数
*/

@ -1,168 +0,0 @@
/*
* 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.manager;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.wrapper.DGEWrapper;
import com.arialyy.aria.core.download.wrapper.DGTEWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Aria.Lao on 2017/11/1.
* 任务实体工厂
*/
class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DGTaskWrapper> {
private static final String TAG = "DTEFactory";
private static volatile DGTEFactory INSTANCE = null;
private DGTEFactory() {
}
public static DGTEFactory getInstance() {
if (INSTANCE == null) {
synchronized (DGTEFactory.class) {
INSTANCE = new DGTEFactory();
}
}
return INSTANCE;
}
@Override public DGTaskWrapper getGTE(String groupName, List<String> urls) {
DownloadGroupEntity entity = createDGroupEntity(groupName, urls);
List<DGTEWrapper> wrapper =
DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.key=?",
entity.getGroupName());
DGTaskWrapper gte;
if (wrapper != null && !wrapper.isEmpty()) {
gte = wrapper.get(0).taskEntity;
if (gte == null) {
// 创建新的任务组任务实体
gte = new DGTaskWrapper();
}
} else {
gte = new DGTaskWrapper();
}
gte.setSubTaskWrapper(createDGSubTaskEntity(entity));
gte.setKey(entity.getGroupName());
gte.setEntity(entity);
return gte;
}
@Override public DGTaskWrapper getFTE(String ftpUrl) {
List<DGTEWrapper> wrapper =
DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.key=?",
ftpUrl);
DGTaskWrapper fte;
if (wrapper != null && !wrapper.isEmpty()) {
fte = wrapper.get(0).taskEntity;
if (fte == null) {
fte = new DGTaskWrapper();
DownloadGroupEntity dge = new DownloadGroupEntity();
dge.setGroupName(ftpUrl);
fte.setEntity(dge);
} else if (fte.getEntity() == null) {
DownloadGroupEntity dge = new DownloadGroupEntity();
dge.setGroupName(ftpUrl);
fte.setEntity(dge);
}
} else {
fte = new DGTaskWrapper();
DownloadGroupEntity dge = new DownloadGroupEntity();
dge.setGroupName(ftpUrl);
fte.setEntity(dge);
}
fte.setKey(ftpUrl);
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;
}
/**
* 创建任务组子任务的任务实体
*/
private List<DTaskWrapper> createDGSubTaskEntity(DownloadGroupEntity dge) {
List<DTaskWrapper> list = new ArrayList<>();
for (DownloadEntity entity : dge.getSubEntities()) {
DTaskWrapper taskEntity = new DTaskWrapper();
taskEntity.setEntity(entity);
taskEntity.setKey(entity.getDownloadPath());
taskEntity.setGroupName(dge.getKey());
taskEntity.setGroupTask(true);
taskEntity.setUrl(entity.getUrl());
list.add(taskEntity);
}
return list;
}
/**
* 查询任务组实体如果数据库不存在该实体则新创建一个新的任务组实体
*/
private DownloadGroupEntity createDGroupEntity(String groupName, List<String> urls) {
List<DGEWrapper> wrapper =
DbEntity.findRelationData(DGEWrapper.class, "DownloadGroupEntity.groupName=?",
groupName);
DownloadGroupEntity groupEntity;
if (wrapper != null && !wrapper.isEmpty()) {
groupEntity = wrapper.get(0).groupEntity;
if (groupEntity == null) {
groupEntity = new DownloadGroupEntity();
groupEntity.setSubEntities(createSubTask(groupName, urls));
}
} else {
groupEntity = new DownloadGroupEntity();
groupEntity.setSubEntities(createSubTask(groupName, urls));
}
groupEntity.setGroupName(groupName);
groupEntity.setUrls(urls);
return groupEntity;
}
/**
* 创建子任务
*/
private List<DownloadEntity> createSubTask(String groupName, List<String> urls) {
List<DownloadEntity> list = new ArrayList<>();
for (int i = 0, len = urls.size(); i < len; i++) {
String url = urls.get(i);
DownloadEntity entity = new DownloadEntity();
entity.setUrl(url);
entity.setDownloadPath(groupName + "_" + i);
int lastIndex = url.lastIndexOf(File.separator);
entity.setFileName(url.substring(lastIndex + 1, url.length()));
entity.setGroupName(groupName);
entity.setGroupChild(true);
list.add(entity);
}
return list;
}
}

@ -0,0 +1,90 @@
/*
* 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.manager;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DGEntityWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.DbDataHelper;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Aria.Lao on 2017/11/1. 组合任务wrapper
*/
class DGTaskWrapperFactory implements IGTEFactory<DownloadGroupEntity, DGTaskWrapper> {
private static final String TAG = "DTaskWrapperFactory";
private static volatile DGTaskWrapperFactory INSTANCE = null;
private DGTaskWrapperFactory() {
}
public static DGTaskWrapperFactory getInstance() {
if (INSTANCE == null) {
synchronized (DGTaskWrapperFactory.class) {
INSTANCE = new DGTaskWrapperFactory();
}
}
return INSTANCE;
}
@Override public DGTaskWrapper getGTE(String groupName, List<String> urls) {
DownloadGroupEntity entity = DbDataHelper.getHttpDGEntity(groupName, urls);
DGTaskWrapper wrapper = new DGTaskWrapper(entity);
wrapper.setSubTaskWrapper(createDGSubTaskWrapper(entity));
wrapper.setKey(entity.getGroupName());
return wrapper;
}
@Override public DGTaskWrapper getFTE(String ftpUrl) {
DownloadGroupEntity entity = DbDataHelper.getFtpDGEntity(ftpUrl);
DGTaskWrapper fte = new DGTaskWrapper(entity);
fte.setKey(ftpUrl);
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;
}
/**
* 创建任务组子任务的任务实体
*/
private List<DTaskWrapper> createDGSubTaskWrapper(DownloadGroupEntity dge) {
List<DTaskWrapper> list = new ArrayList<>();
for (DownloadEntity entity : dge.getSubEntities()) {
DTaskWrapper taskEntity = new DTaskWrapper(entity);
taskEntity.setKey(entity.getDownloadPath());
taskEntity.setGroupName(dge.getKey());
taskEntity.setGroupTask(true);
taskEntity.setUrl(entity.getUrl());
list.add(taskEntity);
}
return list;
}
}

@ -15,33 +15,28 @@
*/
package com.arialyy.aria.core.manager;
import android.text.TextUtils;
import com.arialyy.aria.core.common.AbsFileer;
import com.arialyy.aria.core.common.TaskRecord;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.wrapper.DTEWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.orm.DbEntity;
import java.io.File;
import java.util.List;
import java.util.UUID;
/**
* Created by Aria.Lao on 2017/11/1.
* 任务实体工厂
* 创建下载任务wrapper Created by Aria.Lao on 2017/11/1.
*/
class DTEFactory implements INormalTEFactory<DownloadEntity, DTaskWrapper> {
private static final String TAG = "DTEFactory";
private static volatile DTEFactory INSTANCE = null;
class DTaskWrapperFactory implements INormalTEFactory<DownloadEntity, DTaskWrapper> {
private static final String TAG = "DTaskWrapperFactory";
private static volatile DTaskWrapperFactory INSTANCE = null;
private DTEFactory() {
private DTaskWrapperFactory() {
}
public static DTEFactory getInstance() {
public static DTaskWrapperFactory getInstance() {
if (INSTANCE == null) {
synchronized (DTEFactory.class) {
INSTANCE = new DTEFactory();
synchronized (DTaskWrapperFactory.class) {
INSTANCE = new DTaskWrapperFactory();
}
}
return INSTANCE;
@ -51,25 +46,10 @@ class DTEFactory implements INormalTEFactory<DownloadEntity, DTaskWrapper> {
* 通过下载实体创建任务实体
*/
private DTaskWrapper create(DownloadEntity entity) {
List<DTEWrapper> wrapper = DbEntity.findRelationData(DTEWrapper.class,
"DTaskWrapper.key=? and DTaskWrapper.isGroupTask='false' and DTaskWrapper.url=?",
entity.getDownloadPath(), entity.getUrl());
DTaskWrapper taskEntity;
if (wrapper != null && !wrapper.isEmpty()) {
taskEntity = wrapper.get(0).taskEntity;
if (taskEntity == null) {
taskEntity = new DTaskWrapper();
} else if (taskEntity.getEntity() == null || TextUtils.isEmpty(
taskEntity.getEntity().getUrl())) {
taskEntity.setEntity(entity);
}
} else {
taskEntity = new DTaskWrapper();
}
taskEntity.setKey(entity.getDownloadPath());
taskEntity.setUrl(entity.getUrl());
taskEntity.setEntity(entity);
return taskEntity;
DTaskWrapper wrapper = new DTaskWrapper(entity);
wrapper.setKey(entity.getDownloadPath());
wrapper.setUrl(entity.getUrl());
return wrapper;
}
/**

@ -27,106 +27,76 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* Created by Aria.Lao on 2017/11/1.
* 任务实体管理器
* Created by Aria.Lao on 2017/11/1. 任务实体管理器
*/
public class TEManager {
public class TaskWrapperManager {
private static final String TAG = "TaskManager";
private static volatile TEManager INSTANCE = null;
private static volatile TaskWrapperManager INSTANCE = null;
private LruCache<String, AbsTaskWrapper> cache = new LruCache<>(1024);
private Lock lock;
public static TEManager getInstance() {
public static TaskWrapperManager getInstance() {
if (INSTANCE == null) {
synchronized (TEManager.class) {
INSTANCE = new TEManager();
synchronized (TaskWrapperManager.class) {
INSTANCE = new TaskWrapperManager();
}
}
return INSTANCE;
}
private TEManager() {
private TaskWrapperManager() {
lock = new ReentrantLock();
}
/**
* 通过key创建任务只适应于单任务
*
* @return 如果任务实体创建失败返回null
*/
private <TE extends AbsTaskWrapper> TE createNormalTE(Class<TE> clazz, String key) {
final Lock lock = this.lock;
lock.lock();
try {
AbsTaskWrapper tEntity = cache.get(convertKey(key));
if (tEntity == null || tEntity.getClass() != clazz) {
INormalTEFactory factory = chooseNormalFactory(clazz);
if (factory == null) {
ALog.e(TAG, "任务实体创建失败");
return null;
}
tEntity = factory.create(key);
cache.put(convertKey(key), tEntity);
}
return (TE) tEntity;
} finally {
lock.unlock();
}
private IGTEFactory chooseGroupFactory(Class clazz) {
if (clazz == DGTaskWrapper.class) {
return DGTaskWrapperFactory.getInstance();
}
/**
* 通过key创建不需要缓存的任务实体只适应于单任务
*
* @return 如果任务实体创建失败返回null
*/
public <TE extends AbsTaskWrapper> TE createNormalNoCacheTE(Class<TE> clazz, String key) {
final Lock lock = this.lock;
lock.lock();
try {
INormalTEFactory factory = chooseNormalFactory(clazz);
if (factory == null) {
ALog.e(TAG, "任务实体创建失败");
return null;
}
AbsTaskWrapper tEntity = factory.create(key);
return (TE) tEntity;
} finally {
lock.unlock();
private INormalTEFactory chooseNormalFactory(Class clazz) {
if (clazz == DTaskWrapper.class) {
return DTaskWrapperFactory.getInstance();
} else if (clazz == UTaskWrapper.class) {
return UTaskWrapperFactory.getInstance();
}
return null;
}
/**
* 创建任务组
* 从缓存中获取单任务实体如果任务实体不存在则创建任务实体
*
* @return 如果任务实体创建失败返回null
* @param key 下载任务key为下载地址上传任务key为本地文件路径
* @return 创建失败返回null成功返回{@link DTaskWrapper}或者{@link UTaskWrapper}
*/
private <TE extends AbsTaskWrapper> TE createGTEntity(Class<TE> clazz, List<String> urls) {
public <TE extends AbsTaskWrapper> TE getHttpTaskWrapper(Class<TE> clazz, String key) {
final Lock lock = this.lock;
lock.lock();
try {
String groupName = CommonUtil.getMd5Code(urls);
AbsTaskWrapper tEntity = cache.get(convertKey(groupName));
if (tEntity == null || tEntity.getClass() != clazz) {
IGTEFactory factory = chooseGroupFactory(clazz);
AbsTaskWrapper wrapper = cache.get(convertKey(key));
if (wrapper == null || wrapper.getClass() != clazz) {
INormalTEFactory factory = chooseNormalFactory(clazz);
if (factory == null) {
ALog.e(TAG, "任务实体创建失败");
return null;
}
tEntity = factory.getGTE(groupName, urls);
cache.put(convertKey(groupName), tEntity);
wrapper = factory.create(key);
cache.put(convertKey(key), wrapper);
}
return (TE) tEntity;
return (TE) wrapper;
} finally {
lock.unlock();
}
}
/**
* 通过ftp文件夹路径创建FTP文件夹实体
* 从缓存中获取FTP文件夹任务实体如果任务实体不存在则创建任务实体
*
* @return 如果任务实体创建失败返回null
* @param key 下载任务key为下载地址上传任务key为本地文件路径
* @return 创建失败返回null成功返回{@link DTaskWrapper}
*/
private <TE extends AbsTaskWrapper> TE createFDTE(Class<TE> clazz, String key) {
public <TE extends AbsTaskWrapper> TE getFtpTaskWrapper(Class<TE> clazz, String key) {
final Lock lock = this.lock;
lock.lock();
try {
@ -146,70 +116,13 @@ public class TEManager {
}
}
private IGTEFactory chooseGroupFactory(Class clazz) {
if (clazz == DGTaskWrapper.class) {
return DGTEFactory.getInstance();
}
return null;
}
private INormalTEFactory chooseNormalFactory(Class clazz) {
if (clazz == DTaskWrapper.class) {
return DTEFactory.getInstance();
} else if (clazz == UTaskWrapper.class) {
return UTEFactory.getInstance();
}
return null;
}
/**
* 从缓存中获取单任务实体如果任务实体不存在则创建任务实体
*
* @return 创建失败返回null成功返回{@link DTaskWrapper}或者{@link UTaskWrapper}
*/
public <TE extends AbsTaskWrapper> TE getTEntity(Class<TE> clazz, String key) {
final Lock lock = this.lock;
lock.lock();
try {
AbsTaskWrapper tEntity = cache.get(convertKey(key));
if (tEntity == null) {
return createNormalTE(clazz, key);
} else {
return (TE) tEntity;
}
} finally {
lock.unlock();
}
}
/**
* 从缓存中获取FTP文件夹任务实体如果任务实体不存在则创建任务实体
*
* @return 创建失败返回null成功返回{@link DTaskWrapper}
*/
public <TE extends AbsTaskWrapper> TE getFDTEntity(Class<TE> clazz, String key) {
final Lock lock = this.lock;
lock.lock();
try {
AbsTaskWrapper tEntity = cache.get(convertKey(key));
if (tEntity == null) {
return createFDTE(clazz, key);
} else {
return (TE) tEntity;
}
} finally {
lock.unlock();
}
}
/**
* 从缓存中获取HTTP任务组的任务实体如果任务实体不存在则创建任务实体
* 获取{}
* 从缓存中获取HTTP任务组的任务实体如果任务实体不存在则创建任务实体 获取{}
*
* @param urls HTTP任务组的子任务下载地址列表
* @return 地址列表为null或创建实体失败返回null成功返回{@link DGTaskWrapper}
*/
public <TE extends AbsTaskWrapper> TE getGTEntity(Class<TE> clazz, List<String> urls) {
public <TE extends AbsTaskWrapper> TE getDGTaskWrapper(Class<TE> clazz, List<String> urls) {
if (urls == null || urls.isEmpty()) {
ALog.e(TAG, "获取HTTP任务组实体失败:任务组的子任务下载地址列表为null");
return null;
@ -218,21 +131,26 @@ public class TEManager {
lock.lock();
try {
String groupName = CommonUtil.getMd5Code(urls);
AbsTaskWrapper tEntity = cache.get(convertKey(groupName));
if (tEntity == null) {
return createGTEntity(clazz, urls);
} else {
return (TE) tEntity;
AbsTaskWrapper tWrapper = cache.get(convertKey(groupName));
if (tWrapper == null || tWrapper.getClass() != clazz) {
IGTEFactory factory = chooseGroupFactory(clazz);
if (factory == null) {
ALog.e(TAG, "任务实体创建失败");
return null;
}
tWrapper = factory.getGTE(groupName, urls);
cache.put(convertKey(groupName), tWrapper);
}
return (TE) tWrapper;
} finally {
lock.unlock();
}
}
/**
* 更新任务实体
* 更新任务Wrapper
*/
public void putTEntity(String key, AbsTaskWrapper tEntity) {
public void putTaskWrapper(String key, AbsTaskWrapper tEntity) {
final Lock lock = this.lock;
lock.lock();
try {
@ -247,7 +165,7 @@ public class TEManager {
*
* @return {@code false} 实体为null添加失败
*/
public boolean addTEntity(AbsTaskWrapper te) {
public boolean addTaskWrapper(AbsTaskWrapper te) {
if (te == null) {
ALog.e(TAG, "任务实体添加失败");
return false;
@ -262,10 +180,9 @@ public class TEManager {
}
/**
* 通过key删除任务实体
* 当任务complete或删除记录时将删除缓存
* 通过key删除任务实体 当任务complete或删除记录时将删除缓存
*/
public AbsTaskWrapper removeTEntity(String key) {
public AbsTaskWrapper removeTaskWrapper(String key) {
final Lock lock = this.lock;
lock.lock();
try {

@ -15,55 +15,34 @@
*/
package com.arialyy.aria.core.manager;
import android.text.TextUtils;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.wrapper.UTEWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.Regular;
import java.util.List;
import java.util.regex.Pattern;
/**
* Created by Aria.Lao on 2017/11/1.
* 任务实体工厂
* Created by Aria.Lao on 2017/11/1. 任务实体工厂
*/
class UTEFactory implements INormalTEFactory<UploadEntity, UTaskWrapper> {
private static final String TAG = "DTEFactory";
private static volatile UTEFactory INSTANCE = null;
class UTaskWrapperFactory implements INormalTEFactory<UploadEntity, UTaskWrapper> {
private static final String TAG = "UTaskWrapperFactory";
private static volatile UTaskWrapperFactory INSTANCE = null;
private UTEFactory() {
private UTaskWrapperFactory() {
}
public static UTEFactory getInstance() {
public static UTaskWrapperFactory getInstance() {
if (INSTANCE == null) {
synchronized (UTEFactory.class) {
INSTANCE = new UTEFactory();
synchronized (UTaskWrapperFactory.class) {
INSTANCE = new UTaskWrapperFactory();
}
}
return INSTANCE;
}
private UTaskWrapper create(UploadEntity entity) {
List<UTEWrapper> wrapper =
DbEntity.findRelationData(UTEWrapper.class, "UTaskWrapper.key=?",
entity.getFilePath());
UTaskWrapper uTaskEntity = null;
if (wrapper != null && !wrapper.isEmpty()) {
uTaskEntity = wrapper.get(0).taskEntity;
if (uTaskEntity == null) {
uTaskEntity = new UTaskWrapper();
uTaskEntity.setEntity(entity);
} else if (uTaskEntity.getEntity() == null || TextUtils.isEmpty(
uTaskEntity.getEntity().getFilePath())) {
uTaskEntity.setEntity(entity);
}
} else {
uTaskEntity = new UTaskWrapper();
uTaskEntity.setEntity(entity);
}
uTaskEntity.setKey(entity.getFilePath());
return uTaskEntity;
UTaskWrapper wrapper = new UTaskWrapper(entity);
wrapper.setKey(entity.getFilePath());
return wrapper;
}
@Override public UTaskWrapper create(String key) {

@ -30,7 +30,7 @@ import com.arialyy.aria.core.inf.GroupSendParams;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.ALog;
@ -199,10 +199,10 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends Ab
break;
}
if (what == CANCEL || what == COMPLETE) {
TEManager.getInstance().removeTEntity(task.getKey());
TaskWrapperManager.getInstance().removeTaskWrapper(task.getKey());
} else {
if (what != RUNNING) {
TEManager.getInstance().putTEntity(task.getKey(), task.getTaskWrapper());
TaskWrapperManager.getInstance().putTaskWrapper(task.getKey(), task.getTaskWrapper());
}
}
if (what != FAIL) {
@ -340,7 +340,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends Ab
|| task.getTaskWrapper().getEntity().getFailNum() > reTryNum) {
mQueue.removeTaskFormQueue(task.getKey());
startNextTask(task);
TEManager.getInstance().removeTEntity(task.getKey());
TaskWrapperManager.getInstance().removeTaskWrapper(task.getKey());
callback(FAIL, task);
return;
}
@ -359,7 +359,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends Ab
} else {
mQueue.removeTaskFormQueue(task.getKey());
startNextTask(task);
TEManager.getInstance().removeTEntity(task.getKey());
TaskWrapperManager.getInstance().removeTaskWrapper(task.getKey());
}
}
};

@ -18,7 +18,7 @@ package com.arialyy.aria.core.upload;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.util.ALog;
import java.io.File;
@ -32,7 +32,7 @@ abstract class BaseNormalTarget<TARGET extends AbsUploadTarget>
protected String mTempUrl;
void initTarget(String filePath) {
mTaskWrapper = TEManager.getInstance().getTEntity(UTaskWrapper.class, filePath);
mTaskWrapper = TaskWrapperManager.getInstance().getHttpTaskWrapper(UTaskWrapper.class, filePath);
mEntity = mTaskWrapper.getEntity();
File file = new File(filePath);
mEntity.setFileName(file.getName());

@ -22,27 +22,18 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper;
*/
public class UTaskWrapper extends AbsTaskWrapper<UploadEntity> {
private UploadEntity entity;
private String filePath;
private String key;
public UTaskWrapper() {
}
@Override public UploadEntity getEntity() {
return entity;
public UTaskWrapper(UploadEntity entity) {
super(entity);
}
@Override public String getKey() {
return key;
}
public void setEntity(UploadEntity entity) {
this.entity = entity;
}
public String getFilePath() {
return filePath;
}

@ -123,7 +123,7 @@ public class UploadReceiver extends AbsReceiver {
public void stopAllTask() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(NormalCmdFactory.getInstance()
.createCmd(new UTaskWrapper(), NormalCmdFactory.TASK_STOP_ALL,
.createCmd(new UTaskWrapper(null), NormalCmdFactory.TASK_STOP_ALL,
ICmd.TASK_TYPE_UPLOAD))
.exe();
}
@ -137,7 +137,7 @@ public class UploadReceiver extends AbsReceiver {
public void removeAllTask(boolean removeFile) {
final AriaManager am = AriaManager.getInstance(AriaManager.APP);
CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createNormalCmd(new UTaskWrapper(),
(CancelAllCmd) CommonUtil.createNormalCmd(new UTaskWrapper(null),
NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_UPLOAD);
cancelCmd.removeFile = removeFile;
am.setCmd(cancelCmd).exe();

@ -24,7 +24,7 @@ import com.arialyy.aria.core.common.ThreadRecord;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.DbHelper;
import com.arialyy.aria.util.DbDataHelper;
import java.util.ArrayList;
/**
@ -71,7 +71,7 @@ class FtpFileInfoThread extends AbsFtpInfoThread<UploadEntity, UTaskWrapper> {
mTaskWrapper.setNewTask(false);
// 修改记录
TaskRecord record = DbHelper.getTaskRecord(mTaskWrapper.getKey());
TaskRecord record = DbDataHelper.getTaskRecord(mTaskWrapper.getKey());
if (record == null) {
record = new TaskRecord();
record.fileName = mEntity.getFileName();

@ -1,47 +0,0 @@
/*
* 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.upload.wrapper;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.AbsWrapper;
import com.arialyy.aria.orm.annotation.Many;
import com.arialyy.aria.orm.annotation.One;
import com.arialyy.aria.orm.annotation.Wrapper;
import java.util.List;
/**
* Created by laoyuyu on 2018/3/30.
*/
@Wrapper
public class UTEWrapper extends AbsWrapper {
@One
public UploadEntity entity;
@Many(parentColumn = "filePath", entityColumn = "key")
private List<UTaskWrapper> taskEntitys = null;
public UTaskWrapper taskEntity;
@Override public void handleConvert() {
//taskEntity.entity = (tEntity == null || tEntity.isEmpty()) ? null : tEntity.get(0);
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0);
if (taskEntity != null) {
taskEntity.setEntity(entity);
}
}
}

@ -35,7 +35,7 @@ class DBConfig {
/*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/
static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME;
static int VERSION = 42;
static int VERSION = 43;
/**
* 是否将数据库保存在Sd卡{@code true}

@ -35,7 +35,6 @@ import com.arialyy.aria.core.common.AbsFileer;
import com.arialyy.aria.core.common.TaskRecord;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
@ -1143,7 +1142,7 @@ public class CommonUtil {
ALog.w(TAG, "修改任务记录失败,新文件路径和旧文件路径一致");
return;
}
TaskRecord record = DbHelper.getTaskRecord(oldPath);
TaskRecord record = DbDataHelper.getTaskRecord(oldPath);
if (record == null) {
if (new File(oldPath).exists()) {
ALog.w(TAG, "修改任务记录失败,文件【" + oldPath + "】对应的任务记录不存在");

@ -0,0 +1,115 @@
/*
* 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.util;
import com.arialyy.aria.core.common.RecordWrapper;
import com.arialyy.aria.core.common.TaskRecord;
import com.arialyy.aria.core.download.DGEntityWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.orm.DbEntity;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* 数据库帮助类
*/
public class DbDataHelper {
/**
* 获取任务记录
*
* @param filePath 文件地址
* @return 没有记录返回null有记录则返回任务记录
*/
public static TaskRecord getTaskRecord(String filePath) {
List<RecordWrapper> records =
DbEntity.findRelationData(RecordWrapper.class, "TaskRecord.filePath=?", filePath);
if (records == null || records.size() == 0) {
return null;
}
return records.get(0).taskRecord;
}
/**
* 获取组合任务实体 如果数据库不存在该实体则新创建一个新的任务组实体
*
* @param groupName 组合任务名称
* @param urls 子任务url列表
*/
public static DownloadGroupEntity getHttpDGEntity(String groupName, List<String> urls) {
List<DGEntityWrapper> wrapper =
DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.groupName=?",
groupName);
DownloadGroupEntity groupEntity;
if (wrapper != null && !wrapper.isEmpty()) {
groupEntity = wrapper.get(0).groupEntity;
if (groupEntity == null) {
groupEntity = new DownloadGroupEntity();
groupEntity.setSubEntities(createHttpSubTask(groupName, urls));
}
} else {
groupEntity = new DownloadGroupEntity();
groupEntity.setSubEntities(createHttpSubTask(groupName, urls));
}
groupEntity.setGroupName(groupName);
groupEntity.setUrls(urls);
return groupEntity;
}
/**
* 创建HTTP子任务实体
*/
private static List<DownloadEntity> createHttpSubTask(String groupName, List<String> urls) {
List<DownloadEntity> list = new ArrayList<>();
for (int i = 0, len = urls.size(); i < len; i++) {
String url = urls.get(i);
DownloadEntity entity = new DownloadEntity();
entity.setUrl(url);
entity.setDownloadPath(groupName + "_" + i);
int lastIndex = url.lastIndexOf(File.separator);
entity.setFileName(url.substring(lastIndex + 1));
entity.setGroupName(groupName);
entity.setGroupChild(true);
list.add(entity);
}
return list;
}
/**
* 通过Ftp下载地址获取组合任务实体
*
* @param ftpUrl ftp下载地址
*/
public static DownloadGroupEntity getFtpDGEntity(String ftpUrl) {
List<DGEntityWrapper> wrapper =
DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.groupName=?",
ftpUrl);
DownloadGroupEntity groupEntity;
if (wrapper != null && !wrapper.isEmpty()) {
groupEntity = wrapper.get(0).groupEntity;
if (groupEntity == null) {
groupEntity = new DownloadGroupEntity();
}
} else {
groupEntity = new DownloadGroupEntity();
}
groupEntity.setGroupName(ftpUrl);
return groupEntity;
}
}

@ -1,42 +0,0 @@
/*
* 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.util;
import com.arialyy.aria.core.common.RecordWrapper;
import com.arialyy.aria.core.common.TaskRecord;
import com.arialyy.aria.orm.DbEntity;
import java.util.List;
/**
* 数据库帮助类
*/
public class DbHelper {
/**
* 获取任务记录
*
* @param filePath 文件地址
* @return 没有记录返回null有记录则返回任务记录
*/
public static TaskRecord getTaskRecord(String filePath) {
List<RecordWrapper> records =
DbEntity.findRelationData(RecordWrapper.class, "TaskRecord.filePath=?", filePath);
if (records == null || records.size() == 0) {
return null;
}
return records.get(0).taskRecord;
}
}

@ -20,7 +20,7 @@
<!--android:name=".download.group.DownloadGroupActivity"-->
<!--android:name=".MainActivity"-->
<activity
android:name=".DbTestActivity"
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -30,7 +30,7 @@
</activity>
<activity android:name=".download.DownloadActivity"/>
<!--<activity android:name=".download.SingleTaskActivity"/>-->
<activity android:name=".download.SingleTaskActivity"/>
<activity android:name=".download.multi_download.MultiTaskActivity"/>
<activity android:name=".download.fragment_download.FragmentActivity"/>
<activity android:name=".download.multi_download.MultiDownloadActivity"/>
@ -40,7 +40,7 @@
<activity android:name=".download.FtpDownloadActivity"/>
<activity android:name=".download.group.FTPDirDownloadActivity"/>
<activity android:name=".upload.HttpUploadActivity"/>
<!--<activity android:name=".upload.FtpUploadActivity"/>-->
<activity android:name=".upload.FtpUploadActivity"/>
<service android:name=".download.service_download.DownloadService"/>
</application>

@ -58,13 +58,11 @@ public class DbTestActivity extends BaseActivity<ActivityDbTestBinding> {
entity.setFileName("ssssssssssssssssss");
entity.setDownloadPath(key);
DTaskWrapper dte = new DTaskWrapper();
DTaskWrapper dte = new DTaskWrapper(entity);
dte.setUrl(url);
dte.setKey(key);
dte.setEntity(entity);
datas.add(entity);
datas.add(dte);
}
//AbsEntity.insertManyData(DownloadEntity.class, datas);

@ -58,7 +58,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apks";
//"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip";
//"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip";
//"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk";
"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk";
//"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
//"https://static.donguo.me/video/ip/course/pfys_1.mp4";
//"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864";
@ -67,7 +67,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
//"http://9.9.9.50:5000/download1";
//"http://9.9.9.50:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
"http://v2.qingdian1.com/m_20180730_991/2/2B9FB34A4BCD8CE61481D1C8418EFE36_1080P.m3u8";
//"http://v2.qingdian1.com/m_20180730_991/2/2B9FB34A4BCD8CE61481D1C8418EFE36_1080P.m3u8";
//"https://firmwareapi.azurewebsites.net/firmware-overview?name=A19_Filament_W_IMG0038_00102411-encrypted.ota";
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@ -93,7 +93,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Override protected void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
//unregisterReceiver(receiver);
Aria.download(this).unRegister();
}

@ -183,7 +183,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
//Log.e(TAG, "gHash = "
// + groupTask.getEntity().getSubEntities().get(0).hashCode()
// + "; subHash = "
// + groupTask.getTaskWrapper().getSubTaskEntities().get(0).getEntity().hashCode() +
// + groupTask.getHttpTaskWrapper().getSubTaskEntities().get(0).getEntity().hashCode() +
// "; subHash = " + subEntity.hashCode());
//int percent = subEntity.getPercent();
////如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 mb/s

Loading…
Cancel
Save