任务组事件和普通任务事件同时使用

pull/330/head
AriaLyy 7 years ago
parent 71a0ae4492
commit 041df07617
  1. 2
      Aria/jcenter.gradle
  2. 2
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  4. 11
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  6. 29
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java
  7. 46
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  8. 40
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  9. 1
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  10. 6
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java
  11. 27
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java
  12. 19
      Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java
  13. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/IReceiver.java
  14. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  15. 8
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  16. 19
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  17. 11
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DQueueMapping.java
  18. 5
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadGroupSchedulers.java
  19. 5
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  20. 4
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
  21. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  22. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  23. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  24. 6
      Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
  25. 2
      Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java
  26. 32
      Aria/src/main/java/com/arialyy/aria/orm/NormalList.java
  27. 111
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  28. 42
      AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java
  29. 4
      AriaCompiler/src/main/java/com/arialyy/compiler/ProxyMethodParam.java
  30. 10
      AriaCompiler/src/main/java/com/arialyy/compiler/TaskEnum.java
  31. 5
      app/src/main/java/com/arialyy/simple/base/adapter/AbsRVAdapter.java
  32. 5
      app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java
  33. 2
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  34. 4
      app/src/main/java/com/arialyy/simple/download/group/GroupModule.java
  35. 165
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  36. 2
      app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java
  37. 65
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  38. 33
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiEntity.java
  39. 29
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiModule.java
  40. 3
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java
  41. 43
      app/src/main/java/com/arialyy/simple/widget/NoScrollListView.java
  42. 18
      app/src/main/res/layout/item_group_download.xml
  43. 9
      app/src/main/res/layout/item_simple_download.xml
  44. 19
      app/src/main/res/layout/layout_item_progress.xml

@ -76,7 +76,7 @@ artifacts {
//################################# jcenter start ######################################### //################################# jcenter start #########################################
bintray { bintray {
// user = hasProperty("bintrayUser") ? getProperty("bintrayUser") : getProperty("BINTRAY_USER") // user = hasProperty("bintrayUser") ? getProperty("bintrayUser") : getProperty("BINTRAY_USER")
// key = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY") // groupName = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY")
user = BINTRAY_USER user = BINTRAY_USER
key = BINTRAY_KEY key = BINTRAY_KEY
configurations = ['archives'] configurations = ['archives']

@ -56,7 +56,7 @@ class GroupStartCmd<T extends AbsTaskEntity> extends AbsGroupCmd<T> {
if (mod.equals(QueueMod.NOW.getTag())) { if (mod.equals(QueueMod.NOW.getTag())) {
mQueue.startTask(task); mQueue.startTask(task);
} else if (mod.equals(QueueMod.WAIT.getTag())) { } else if (mod.equals(QueueMod.WAIT.getTag())) {
if (mQueue.getExePoolSize() < maxTaskNum) { if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
mQueue.startTask(task); mQueue.startTask(task);
} }
} }

@ -27,7 +27,7 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
List<DownloadEntity> allEntity = List<DownloadEntity> allEntity =
DbEntity.findDatas(DownloadEntity.class, "state=?", IEntity.STATE_STOP + ""); DbEntity.findDatas(DownloadEntity.class, "state=?", IEntity.STATE_STOP + "");
for (DownloadEntity entity : allEntity) { for (DownloadEntity entity : allEntity) {
int exeNum = mQueue.getExePoolSize(); int exeNum = mQueue.getCurrentExePoolNum();
if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) { if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) {
AbsTask task = createTask(entity); AbsTask task = createTask(entity);
mQueue.startTask(task); mQueue.startTask(task);

@ -19,9 +19,15 @@ package com.arialyy.aria.core.command.normal;
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.QueueMod; import com.arialyy.aria.core.QueueMod;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.scheduler.DQueueMapping;
import com.arialyy.aria.orm.Primary;
/** /**
* Created by lyy on 2016/8/22. * Created by lyy on 2016/8/22.
@ -57,14 +63,13 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
if (mod.equals(QueueMod.NOW.getTag())) { if (mod.equals(QueueMod.NOW.getTag())) {
mQueue.startTask(task); mQueue.startTask(task);
} else if (mod.equals(QueueMod.WAIT.getTag())) { } else if (mod.equals(QueueMod.WAIT.getTag())) {
if (mQueue.getExePoolSize() < maxTaskNum) { if (mQueue.getCurrentExePoolNum() < maxTaskNum || task.getState() == IEntity.STATE_STOP) {
mQueue.startTask(task); mQueue.startTask(task);
} }
} }
} else { } else {
// 任务不存在时,根据配置不同,对任务执行操作 // 任务不存在时,根据配置不同,对任务执行操作
if (!task.isRunning() && mod.equals(QueueMod.WAIT.getTag()) && (task.getState() if (!task.isRunning()) {
== IEntity.STATE_WAIT || task.getState() == IEntity.STATE_STOP)) {
mQueue.startTask(task); mQueue.startTask(task);
} }
} }

@ -53,6 +53,10 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
*/ */
private String serverFileName = ""; private String serverFileName = "";
@Override public String getKey() {
return downloadUrl;
}
public DownloadEntity() { public DownloadEntity() {
} }

@ -17,6 +17,7 @@ package com.arialyy.aria.core.download;
import android.os.Parcel; import android.os.Parcel;
import com.arialyy.aria.core.inf.AbsGroupEntity; import com.arialyy.aria.core.inf.AbsGroupEntity;
import com.arialyy.aria.orm.NormalList;
import com.arialyy.aria.orm.OneToMany; import com.arialyy.aria.orm.OneToMany;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -27,16 +28,26 @@ import java.util.List;
*/ */
public class DownloadGroupEntity extends AbsGroupEntity { public class DownloadGroupEntity extends AbsGroupEntity {
@OneToMany(table = DownloadEntity.class, key = "groupName") private List<DownloadEntity> subtask = new ArrayList<>(); @OneToMany(table = DownloadEntity.class, key = "groupName") private List<DownloadEntity> subtask =
new ArrayList<>();
//任务组下载文件的文件夹地址 /**
* 子任务链接组
*/
@NormalList(clazz = String.class) private List<String> urls = new ArrayList<>();
/**
* 任务组下载文件的文件夹地址
*
* @see DownloadGroupTarget#setDownloadDirPath(String)
*/
private String dirPath = ""; private String dirPath = "";
public List<DownloadEntity> getSubTask() { public List<DownloadEntity> getSubTask() {
return subtask; return subtask;
} }
public void setSubTasks(List<DownloadEntity> subTasks) { void setSubTasks(List<DownloadEntity> subTasks) {
this.subtask = subTasks; this.subtask = subTasks;
} }
@ -48,6 +59,18 @@ public class DownloadGroupEntity extends AbsGroupEntity {
this.dirPath = dirPath; this.dirPath = dirPath;
} }
public List<String> getUrls() {
return urls;
}
void setUrls(List<String> urls) {
this.urls = urls;
}
void setGroupName(String key) {
this.groupName = key;
}
public DownloadGroupEntity() { public DownloadGroupEntity() {
} }

@ -18,6 +18,7 @@ package com.arialyy.aria.core.download;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.inf.AbsGroupTarget; import com.arialyy.aria.core.inf.AbsGroupTarget;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -40,14 +41,26 @@ public class DownloadGroupTarget
*/ */
private boolean isSetDirPathed = false; private boolean isSetDirPathed = false;
DownloadGroupTarget(DownloadGroupEntity groupEntity, String targetName) {
this.mTargetName = targetName;
if (groupEntity.getUrls() != null && !groupEntity.getUrls().isEmpty()) {
this.mUrls.addAll(groupEntity.getUrls());
}
init(groupEntity.getGroupName());
}
DownloadGroupTarget(List<String> urls, String targetName) { DownloadGroupTarget(List<String> urls, String targetName) {
this.mTargetName = targetName; this.mTargetName = targetName;
this.mUrls = urls; this.mUrls = urls;
mGroupName = CommonUtil.getMd5Code(urls); init(CommonUtil.getMd5Code(urls));
mTaskEntity = DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", mGroupName); }
private void init(String key) {
mGroupName = key;
mTaskEntity = DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", key);
if (mTaskEntity == null) { if (mTaskEntity == null) {
mTaskEntity = new DownloadGroupTaskEntity(); mTaskEntity = new DownloadGroupTaskEntity();
mTaskEntity.key = mGroupName; mTaskEntity.key = key;
mTaskEntity.entity = getDownloadGroupEntity(); mTaskEntity.entity = getDownloadGroupEntity();
mTaskEntity.insert(); mTaskEntity.insert();
} }
@ -57,18 +70,43 @@ public class DownloadGroupTarget
mEntity = mTaskEntity.entity; mEntity = mTaskEntity.entity;
} }
/**
* 查询任务组实体如果数据库不存在该实体则新创建一个新的任务组实体
*/
private DownloadGroupEntity getDownloadGroupEntity() { private DownloadGroupEntity getDownloadGroupEntity() {
DownloadGroupEntity entity = DownloadGroupEntity entity =
DbEntity.findFirst(DownloadGroupEntity.class, "groupName=?", mGroupName); DbEntity.findFirst(DownloadGroupEntity.class, "groupName=?", mGroupName);
if (entity == null) { if (entity == null) {
entity = new DownloadGroupEntity(); entity = new DownloadGroupEntity();
entity.setGroupName(mGroupName); entity.setGroupName(mGroupName);
entity.setUrlmd5(mGroupName); entity.setUrls(mUrls);
entity.insert(); entity.insert();
} }
return entity; return entity;
} }
/**
* 设置任务组别名
*/
public DownloadGroupTarget setGroupAlias(String alias) {
if (TextUtils.isEmpty(alias)) return this;
mEntity.setAlias(alias);
mEntity.update();
return this;
}
/**
* 如果你是使用{@link DownloadReceiver#load(DownloadGroupEntity)}进行下载操作那么你需要设置任务组的下载地址
*/
public DownloadGroupTarget setGroupUrl(List<String> urls) {
CheckUtil.checkDownloadUrls(urls);
mUrls.clear();
mUrls.addAll(urls);
mEntity.setGroupName(CommonUtil.getMd5Code(urls));
mEntity.update();
return this;
}
/** /**
* 设置任务组的文件夹路径在Aria中任务组的所有子任务都会下载到以任务组组名的文件夹中 * 设置任务组的文件夹路径在Aria中任务组的所有子任务都会下载到以任务组组名的文件夹中
* groupDirPath = "/mnt/sdcard/download/group_test" * groupDirPath = "/mnt/sdcard/download/group_test"

@ -17,6 +17,7 @@ package com.arialyy.aria.core.download;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.IReceiver; import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
@ -27,6 +28,7 @@ import com.arialyy.aria.core.upload.ProxyHelper;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -49,9 +51,9 @@ public class DownloadReceiver extends AbsReceiver {
} }
/** /**
* {@link #load(String)}请使用该方法 * 使用下载实体执行下载操作
*/ */
@Deprecated public DownloadTarget load(DownloadEntity entity) { public DownloadTarget load(DownloadEntity entity) {
return new DownloadTarget(entity, targetName); return new DownloadTarget(entity, targetName);
} }
@ -71,6 +73,16 @@ public class DownloadReceiver extends AbsReceiver {
return new DownloadGroupTarget(urls, targetName); return new DownloadGroupTarget(urls, targetName);
} }
/**
* 使用任务组实体执行任务组的实体执行任务组的下载操作
*
* @param groupEntity 如果加载的任务实体没有子项的下载地址
* 那么你需要使用{@link DownloadGroupTarget#setGroupUrl(List)}设置子项的下载地址
*/
public DownloadGroupTarget load(DownloadGroupEntity groupEntity) {
return new DownloadGroupTarget(groupEntity, targetName);
}
/** /**
* 将当前类注册到Aria * 将当前类注册到Aria
*/ */
@ -144,7 +156,7 @@ public class DownloadReceiver extends AbsReceiver {
*/ */
public DownloadTaskEntity getDownloadTask(String downloadUrl) { public DownloadTaskEntity getDownloadTask(String downloadUrl) {
CheckUtil.checkDownloadUrl(downloadUrl); CheckUtil.checkDownloadUrl(downloadUrl);
return DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'", return DbEntity.findFirst(DownloadTaskEntity.class, "groupName=? and isGroupTask='false'",
downloadUrl); downloadUrl);
} }
@ -167,15 +179,31 @@ public class DownloadReceiver extends AbsReceiver {
/** /**
* 获取普通下载任务列表 * 获取普通下载任务列表
*/ */
@Override public List<DownloadEntity> getTaskList() { @Override public List<DownloadEntity> getSimpleTaskList() {
return DownloadEntity.findDatas(DownloadEntity.class, "isGroupChild=?", "false"); return DownloadEntity.findDatas(DownloadEntity.class, "isGroupChild=?", "false");
} }
/** /**
* 获取任务组列表 * 获取任务组列表
*/ */
public List<DownloadGroupTaskEntity> getGroupTaskList() { public List<DownloadGroupEntity> getGroupTaskList() {
return DownloadEntity.findAllData(DownloadGroupTaskEntity.class); return DownloadEntity.findAllData(DownloadGroupEntity.class);
}
/**
* 获取普通任务和任务组的任务列表
*/
public List<AbsEntity> getTotleTaskList() {
List<AbsEntity> list = new ArrayList<>();
List<DownloadEntity> simpleTask = getSimpleTaskList();
List<DownloadGroupEntity> groupTask = getGroupTaskList();
if (simpleTask != null && !simpleTask.isEmpty()) {
list.addAll(simpleTask);
}
if (groupTask != null && !groupTask.isEmpty()) {
list.addAll(groupTask);
}
return list;
} }
/** /**

@ -112,6 +112,7 @@ public class DownloadTarget
mEntity.setDownloadPath(downloadPath); mEntity.setDownloadPath(downloadPath);
mEntity.setFileName(file.getName()); mEntity.setFileName(file.getName());
mTaskEntity.key = downloadPath; mTaskEntity.key = downloadPath;
mEntity.update();
mTaskEntity.update(); mTaskEntity.update();
return this; return this;
} }

@ -142,6 +142,11 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable
this.completeTime = completeTime; this.completeTime = completeTime;
} }
/**
* 实体唯一标识符
*/
public abstract String getKey();
public AbsEntity() { public AbsEntity() {
} }
@ -174,5 +179,4 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable
this.completeTime = in.readLong(); this.completeTime = in.readLong();
this.isComplete = in.readByte() != 0; this.isComplete = in.readByte() != 0;
} }
} }

@ -24,30 +24,29 @@ import com.arialyy.aria.orm.Primary;
*/ */
public abstract class AbsGroupEntity extends AbsEntity implements Parcelable { public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
/** /**
* 组名 * 组名组名为任务地址相加的urlMd5
*/ */
@Primary @Primary protected String groupName = "";
private String groupName = "";
/** /**
* 任务地址相加的urlmd5 * 任务组别名
*/ */
private String urlmd5 = ""; private String alias = "";
public String getUrlmd5() { public String getGroupName() {
return urlmd5; return groupName;
} }
public void setUrlmd5(String urlmd5) { public String getAlias() {
this.urlmd5 = urlmd5; return alias;
} }
public String getGroupName() { @Override public String getKey() {
return groupName; return groupName;
} }
public void setGroupName(String groupName) { public void setAlias(String alias) {
this.groupName = groupName; this.alias = alias;
} }
public AbsGroupEntity() { public AbsGroupEntity() {
@ -60,12 +59,12 @@ public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
@Override public void writeToParcel(Parcel dest, int flags) { @Override public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags); super.writeToParcel(dest, flags);
dest.writeString(this.groupName); dest.writeString(this.groupName);
dest.writeString(this.urlmd5); dest.writeString(this.alias);
} }
protected AbsGroupEntity(Parcel in) { protected AbsGroupEntity(Parcel in) {
super(in); super(in);
this.groupName = in.readString(); this.groupName = in.readString();
this.urlmd5 = in.readString(); this.alias = in.readString();
} }
} }

@ -20,42 +20,41 @@ import com.arialyy.aria.orm.Ignore;
/** /**
* Created by lyy on 2017/2/23. * Created by lyy on 2017/2/23.
*/ */
public interface IEntity { public interface IEntity {
/** /**
* 其它状态 * 其它状态
*/ */
@Ignore public static final int STATE_OTHER = -1; @Ignore int STATE_OTHER = -1;
/** /**
* 失败状态 * 失败状态
*/ */
@Ignore public static final int STATE_FAIL = 0; @Ignore int STATE_FAIL = 0;
/** /**
* 完成状态 * 完成状态
*/ */
@Ignore public static final int STATE_COMPLETE = 1; @Ignore int STATE_COMPLETE = 1;
/** /**
* 停止状态 * 停止状态
*/ */
@Ignore public static final int STATE_STOP = 2; @Ignore int STATE_STOP = 2;
/** /**
* 等待状态 * 等待状态
*/ */
@Ignore public static final int STATE_WAIT = 3; @Ignore int STATE_WAIT = 3;
/** /**
* 下载中 * 下载中
*/ */
@Ignore public static final int STATE_RUNNING = 4; @Ignore int STATE_RUNNING = 4;
/** /**
* 预处理 * 预处理
*/ */
@Ignore public static final int STATE_PRE = 5; @Ignore int STATE_PRE = 5;
/** /**
* 预处理完成 * 预处理完成
*/ */
@Ignore public static final int STATE_POST_PRE = 6; @Ignore int STATE_POST_PRE = 6;
/** /**
* 取消下载 * 取消下载
*/ */
@Ignore public static final int STATE_CANCEL = 7; @Ignore int STATE_CANCEL = 7;
} }

@ -56,5 +56,5 @@ public interface IReceiver<ENTITY extends IEntity> {
/** /**
* 获取任务列表 * 获取任务列表
*/ */
public List<ENTITY> getTaskList(); public List<ENTITY> getSimpleTaskList();
} }

@ -102,7 +102,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
* *
* @return 获取缓存的任务数 * @return 获取缓存的任务数
*/ */
@Override public int getCachePoolSize() { @Override public int getCurrentCachePoolNum() {
return mCachePool.size(); return mCachePool.size();
} }
@ -111,7 +111,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
* *
* @return 当前正在执行的任务数 * @return 当前正在执行的任务数
*/ */
@Override public int getExePoolSize() { @Override public int getCurrentExePoolNum() {
return mExecutePool.size(); return mExecutePool.size();
} }

@ -88,14 +88,14 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
void reTryStart(TASK task); void reTryStart(TASK task);
/** /**
* 获取执行池中的任务数量 * 获取当前执行池中的任务数量
*/ */
int getExePoolSize(); int getCurrentExePoolNum();
/** /**
* 获取任务缓存池中的任务数量 * 获取当前任务缓存池中的任务数量
*/ */
int getCachePoolSize(); int getCurrentCachePoolNum();
/** /**
* 设置执行池可执行的最大任务数 * 设置执行池可执行的最大任务数

@ -16,7 +16,6 @@
package com.arialyy.aria.core.scheduler; package com.arialyy.aria.core.scheduler;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
@ -140,7 +139,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
} }
case CANCEL: case CANCEL:
mQueue.removeTask(entity); mQueue.removeTask(entity);
if (mQueue.getExePoolSize() < AriaManager.getInstance(AriaManager.APP) if (mQueue.getCurrentExePoolNum() < AriaManager.getInstance(AriaManager.APP)
.getUploadConfig() .getUploadConfig()
.getMaxTaskNum()) { .getMaxTaskNum()) {
startNextTask(); startNextTask();
@ -206,11 +205,6 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
listener.onTaskCancel(task); listener.onTaskCancel(task);
break; break;
case COMPLETE: case COMPLETE:
//new Handler().postDelayed(new Runnable() {
// @Override public void run() {
// listener.onTaskComplete(task);
// }
//}, 1000);
listener.onTaskComplete(task); listener.onTaskComplete(task);
break; break;
case FAIL: case FAIL:
@ -280,7 +274,14 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
* *
* @return {@code true} {@code false} * @return {@code true} {@code false}
*/ */
protected boolean hasNextTask() { boolean hasNextTask() {
return mQueue.getCachePoolSize() > 0; return mQueue.getCurrentCachePoolNum() > 0;
}
/**
* 获取正在执行的队列数
*/
int getExeTaskNum() {
return mQueue.getCurrentExePoolNum();
} }
} }

@ -16,10 +16,11 @@
package com.arialyy.aria.core.scheduler; package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* Created by Aria.Lao on 2017/7/13. * Created by Aria.Lao on 2017/7/13.
@ -30,7 +31,7 @@ public class DQueueMapping {
public static final int QUEUE_TYPE_DOWNLOAD = 0xa1; public static final int QUEUE_TYPE_DOWNLOAD = 0xa1;
public static final int QUEUE_TYPE_DOWNLOAD_GROUP = 0xa2; public static final int QUEUE_TYPE_DOWNLOAD_GROUP = 0xa2;
public static final int QUEUE_NONE = 0xab2; public static final int QUEUE_NONE = 0xab2;
LinkedHashMap<String, Integer> types = new LinkedHashMap<>(); private LinkedHashMap<String, Integer> types = new LinkedHashMap<>();
private static volatile DQueueMapping instance = null; private static volatile DQueueMapping instance = null;
@ -79,4 +80,10 @@ public class DQueueMapping {
} }
return QUEUE_NONE; return QUEUE_NONE;
} }
public boolean canStart() {
return DownloadTaskQueue.getInstance().getCurrentExePoolNum()
+ DownloadGroupTaskQueue.getInstance().getCurrentExePoolNum() >= AriaManager.getInstance(
AriaManager.APP).getDownloadConfig().getMaxTaskNum();
}
} }

@ -23,6 +23,7 @@ import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
/** /**
* Created by AriaL on 2017/7/2. * Created by AriaL on 2017/7/2.
* 任务组调度器
*/ */
public class DownloadGroupSchedulers extends public class DownloadGroupSchedulers extends
AbsSchedulers<DownloadGroupTaskEntity, DownloadGroupEntity, DownloadGroupTask, DownloadGroupTaskQueue> { AbsSchedulers<DownloadGroupTaskEntity, DownloadGroupEntity, DownloadGroupTask, DownloadGroupTaskQueue> {
@ -51,6 +52,10 @@ public class DownloadGroupSchedulers extends
} }
@Override protected void startNextTask() { @Override protected void startNextTask() {
if (getExeTaskNum() + DownloadSchedulers.getInstance().getExeTaskNum()
>= AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum()) {
return;
}
if (!DownloadSchedulers.getInstance().hasNextTask()) { if (!DownloadSchedulers.getInstance().hasNextTask()) {
nextSelf(); nextSelf();
} else { } else {

@ -16,6 +16,7 @@
package com.arialyy.aria.core.scheduler; package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
@ -55,6 +56,10 @@ public class DownloadSchedulers
} }
@Override protected void startNextTask() { @Override protected void startNextTask() {
if (getExeTaskNum() + DownloadGroupSchedulers.getInstance().getExeTaskNum()
>= AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum()) {
return;
}
if (!DownloadGroupSchedulers.getInstance().hasNextTask()) { if (!DownloadGroupSchedulers.getInstance().hasNextTask()) {
nextSelf(); nextSelf();
} else { } else {

@ -38,6 +38,10 @@ public class UploadEntity extends AbsNormalEntity implements Parcelable {
this.filePath = filePath; this.filePath = filePath;
} }
@Override public String getKey() {
return filePath;
}
public UploadEntity() { public UploadEntity() {
} }

@ -62,7 +62,7 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
return DbEntity.findFirst(UploadEntity.class, "filePath=?", filePath) != null; return DbEntity.findFirst(UploadEntity.class, "filePath=?", filePath) != null;
} }
@Override public List<UploadEntity> getTaskList() { @Override public List<UploadEntity> getSimpleTaskList() {
return DbEntity.findAllData(UploadEntity.class); return DbEntity.findAllData(UploadEntity.class);
} }

@ -28,7 +28,7 @@ public class UploadTarget extends AbsNormalTarget<UploadTarget, UploadEntity, Up
UploadTarget(String filePath, String targetName) { UploadTarget(String filePath, String targetName) {
this.mTargetName = targetName; this.mTargetName = targetName;
mTaskEntity = DbEntity.findFirst(UploadTaskEntity.class, "key=?", filePath); mTaskEntity = DbEntity.findFirst(UploadTaskEntity.class, "groupName=?", filePath);
if (mTaskEntity == null) { if (mTaskEntity == null) {
mTaskEntity = new UploadTaskEntity(); mTaskEntity = new UploadTaskEntity();
mTaskEntity.entity = new UploadEntity(); mTaskEntity.entity = new UploadEntity();

@ -32,7 +32,7 @@ import java.util.Map;
public class DBConfig { public class DBConfig {
static Map<String, Class> mapping = new HashMap<>(); static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME; static String DB_NAME;
static int VERSION = 9; static int VERSION = 10;
static { static {
if (TextUtils.isEmpty(DB_NAME)) { if (TextUtils.isEmpty(DB_NAME)) {

@ -171,7 +171,11 @@ public class DbEntity {
if (SqlHelper.isOneToOne(field)) { if (SqlHelper.isOneToOne(field)) {
values.add(SqlHelper.getOneToOneParams(field)); values.add(SqlHelper.getOneToOneParams(field));
} else if (type == List.class) { } else if (type == List.class) {
values.add(SqlHelper.getListElementParams(field)); if (SqlHelper.isOneToMany(field)) {
values.add(SqlHelper.getOneToManyElementParams(field));
} else {
values.add(SqlHelper.list2Str(this, field));
}
} else if (type == Map.class) { } else if (type == Map.class) {
values.add(SqlHelper.map2Str((Map<String, String>) field.get(this))); values.add(SqlHelper.map2Str((Map<String, String>) field.get(this)));
} else { } else {

@ -187,7 +187,7 @@ public class DbUtil {
Log.e(TAG, "请输入删除条件"); Log.e(TAG, "请输入删除条件");
return -1; return -1;
} else if (wheres.length != values.length) { } else if (wheres.length != values.length) {
Log.e(TAG, "key 和 vaule 长度不相等"); Log.e(TAG, "groupName 和 vaule 长度不相等");
return -1; return -1;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

@ -0,0 +1,32 @@
/*
* 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.orm;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by AriaL on 2017/7/4.
* 基本类型的List只能用于常见的数据类型如果是一对多的复杂数据结构需要使用{@link OneToMany}
*/
@Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface NormalList {
/**
* 数据类型
*/
Class clazz();
}

@ -29,10 +29,10 @@ import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -220,7 +220,7 @@ final class SqlHelper extends SQLiteOpenHelper {
Log.e(TAG, "请输入查询条件"); Log.e(TAG, "请输入查询条件");
return null; return null;
} else if (wheres.length != values.length) { } else if (wheres.length != values.length) {
Log.e(TAG, "key 和 vaule 长度不相等"); Log.e(TAG, "groupName 和 vaule 长度不相等");
return null; return null;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -297,7 +297,11 @@ final class SqlHelper extends SQLiteOpenHelper {
if (type == Map.class) { if (type == Map.class) {
value = map2Str((Map<String, String>) field.get(dbEntity)); value = map2Str((Map<String, String>) field.get(dbEntity));
} else if (type == List.class) { } else if (type == List.class) {
value = getListElementParams(field); if (isOneToMany(field)) {
value = getOneToManyElementParams(field);
} else {
value = list2Str(dbEntity, field);
}
} else if (isOneToOne(field)) { } else if (isOneToOne(field)) {
value = getOneToOneParams(field); value = getOneToOneParams(field);
} else { } else {
@ -354,7 +358,11 @@ final class SqlHelper extends SQLiteOpenHelper {
if (type == Map.class) { if (type == Map.class) {
sb.append(map2Str((Map<String, String>) field.get(dbEntity))); sb.append(map2Str((Map<String, String>) field.get(dbEntity)));
} else if (type == List.class) { } else if (type == List.class) {
sb.append(getListElementParams(field)); if (isOneToMany(field)) {
sb.append(getOneToManyElementParams(field));
} else {
sb.append(list2Str(dbEntity, field));
}
} else if (isOneToOne(field)) { } else if (isOneToOne(field)) {
sb.append(getOneToOneParams(field)); sb.append(getOneToOneParams(field));
} else { } else {
@ -373,13 +381,6 @@ final class SqlHelper extends SQLiteOpenHelper {
close(db); close(db);
} }
/**
* 保存一对一的数据
*/
private void saveOneToOneFile(Field field) {
}
/** /**
* 获取一对一参数 * 获取一对一参数
*/ */
@ -396,10 +397,10 @@ final class SqlHelper extends SQLiteOpenHelper {
* *
* @param field list反射字段 * @param field list反射字段
*/ */
static String getListElementParams(Field field) { static String getOneToManyElementParams(Field field) {
OneToMany oneToMany = field.getAnnotation(OneToMany.class); OneToMany oneToMany = field.getAnnotation(OneToMany.class);
if (oneToMany == null) { if (oneToMany == null) {
throw new IllegalArgumentException("List中元素必须被@OneToMany注解"); throw new IllegalArgumentException("一对多元素必须被@OneToMany注解");
} }
//关联的表名 //关联的表名
String tableName = oneToMany.table().getName(); String tableName = oneToMany.table().getName();
@ -408,6 +409,63 @@ final class SqlHelper extends SQLiteOpenHelper {
return tableName + "$$" + key; return tableName + "$$" + key;
} }
/**
* 列表数据转字符串
*
* @param field list反射字段
*/
static String list2Str(DbEntity dbEntity, Field field) throws IllegalAccessException {
NormalList normalList = field.getAnnotation(NormalList.class);
if (normalList == null) {
throw new IllegalArgumentException("List中元素必须被@NormalList注解");
}
List list = (List) field.get(dbEntity);
if (list == null || list.isEmpty()) return "";
StringBuilder sb = new StringBuilder();
for (Object aList : list) {
sb.append(aList).append("$$");
}
return sb.toString();
}
/**
* 字符串转列表
*
* @param str 数据库中的字段
* @return 如果str为null则返回null
*/
private static List str2List(String str, Field field) {
NormalList normalList = field.getAnnotation(NormalList.class);
if (normalList == null) {
throw new IllegalArgumentException("List中元素必须被@NormalList注解");
}
if (TextUtils.isEmpty(str)) return null;
String[] datas = str.split("$$");
List list = new ArrayList();
String type = normalList.clazz().getName();
for (String data : datas) {
list.add(checkData(data, type));
}
return list;
}
private static Object checkData(String type, String data) {
switch (type) {
case "String":
return data;
case "int":
case "Integer":
return Integer.parseInt(data);
case "double":
case "Double":
return Double.parseDouble(data);
case "float":
case "Float":
return Float.parseFloat(data);
}
return null;
}
/** /**
* 查找class的主键字段 * 查找class的主键字段
* *
@ -510,23 +568,6 @@ final class SqlHelper extends SQLiteOpenHelper {
close(db); close(db);
} }
///**
// * 通过字段类型和获取保存在数据库表字段名
// */
//private static String getFieldName(Class<?> type, Field field) {
// String fieldName;
// if (type == Map.class) {
// fieldName = MAP_FIELD + field.getName();
// } else if (type == List.class) {
// fieldName = LIST_FIELD + field.getName();
// } else if (isGeneric(field)) {
// fieldName = GENERIC_FIELD + field.getName();
// } else {
// fieldName = field.getName();
// }
// return fieldName;
//}
/** /**
* 打印数据库日志 * 打印数据库日志
* *
@ -598,6 +639,8 @@ final class SqlHelper extends SQLiteOpenHelper {
} else if (type == Map.class) { } else if (type == Map.class) {
field.set(entity, str2Map(cursor.getString(column))); field.set(entity, str2Map(cursor.getString(column)));
} else if (type == List.class) { } else if (type == List.class) {
String value = cursor.getString(column);
if (isOneToMany(field)) {
//主键字段 //主键字段
String primaryKey = getPrimaryName(clazz); String primaryKey = getPrimaryName(clazz);
if (TextUtils.isEmpty(primaryKey)) { if (TextUtils.isEmpty(primaryKey)) {
@ -605,12 +648,14 @@ final class SqlHelper extends SQLiteOpenHelper {
} }
//list字段保存的数据 //list字段保存的数据
int kc = cursor.getColumnIndex(primaryKey); int kc = cursor.getColumnIndex(primaryKey);
String params = cursor.getString(column);
String primaryData = cursor.getString(kc); String primaryData = cursor.getString(kc);
if (TextUtils.isEmpty(primaryData)) continue; if (TextUtils.isEmpty(primaryData)) continue;
List<T> list = findForeignData(db, primaryData, params); List<T> list = findForeignData(db, primaryData, value);
if (list == null) continue; if (list == null) continue;
field.set(entity, findForeignData(db, primaryData, params)); field.set(entity, findForeignData(db, primaryData, value));
} else {
field.set(entity, str2List(value, field));
}
} else if (isOneToOne(field)) { } else if (isOneToOne(field)) {
String primaryKey = getPrimaryName(clazz); String primaryKey = getPrimaryName(clazz);
if (TextUtils.isEmpty(primaryKey)) { if (TextUtils.isEmpty(primaryKey)) {

@ -50,6 +50,7 @@ import javax.lang.model.util.Elements;
* 元素处理 * 元素处理
*/ */
class ElementHandler { class ElementHandler {
private static final boolean DEBUG = false;
private Filer mFiler; private Filer mFiler;
private Elements mElementUtil; private Elements mElementUtil;
@ -170,16 +171,25 @@ class ElementHandler {
Set<String> keys = mMethods.keySet(); Set<String> keys = mMethods.keySet();
for (String key : keys) { for (String key : keys) {
ProxyMethodParam entity = mMethods.get(key); ProxyMethodParam entity = mMethods.get(key);
JavaFile jf = JavaFile.builder(entity.packageName, createProxyClass(entity)).build(); for (TaskEnum taskEnum : entity.taskEnums) {
JavaFile jf =
JavaFile.builder(entity.packageName, createProxyClass(entity, taskEnum)).build();
createFile(jf);
}
}
}
jf.writeTo(mFiler); private void createFile(JavaFile jf) throws IOException {
if (DEBUG) {
// 如果需要在控制台打印生成的文件,则去掉下面的注释 // 如果需要在控制台打印生成的文件,则去掉下面的注释
//jf.writeTo(System.out); jf.writeTo(System.out);
} else {
jf.writeTo(mFiler);
} }
} }
/** /**
* 每一种注解的类集合 * 每一种注解对应的类集合
*/ */
private void createProxyClassFile() throws IOException { private void createProxyClassFile() throws IOException {
Set<String> keys = mListenerClass.keySet(); Set<String> keys = mListenerClass.keySet();
@ -212,8 +222,7 @@ class ElementHandler {
ProxyConstance.COUNT_DOWNLOAD_GROUP)); ProxyConstance.COUNT_DOWNLOAD_GROUP));
JavaFile jf = JavaFile.builder(ProxyConstance.PROXY_COUNTER_PACKAGE, builder.build()).build(); JavaFile jf = JavaFile.builder(ProxyConstance.PROXY_COUNTER_PACKAGE, builder.build()).build();
jf.writeTo(mFiler); createFile(jf);
//jf.writeTo(System.out);
} }
/** /**
@ -287,8 +296,7 @@ class ElementHandler {
/** /**
* 创建代理类 * 创建代理类
*/ */
private TypeSpec createProxyClass(ProxyMethodParam entity) { private TypeSpec createProxyClass(ProxyMethodParam entity, TaskEnum taskEnum) {
TaskEnum taskEnum = entity.taskEnum;
TypeSpec.Builder builder = TypeSpec.classBuilder(entity.className + taskEnum.getProxySuffix()) TypeSpec.Builder builder = TypeSpec.classBuilder(entity.className + taskEnum.getProxySuffix())
.addModifiers(Modifier.PUBLIC, Modifier.FINAL); .addModifiers(Modifier.PUBLIC, Modifier.FINAL);
@ -305,10 +313,13 @@ class ElementHandler {
builder.addField(mappingField); builder.addField(mappingField);
//添加注解方法 //添加注解方法
for (Class<? extends Annotation> annotation : entity.methods.keySet()) { Map<Class<? extends Annotation>, String> temp = entity.methods.get(taskEnum);
MethodSpec method = createProxyMethod(taskEnum, annotation, entity.methods.get(annotation)); if (temp != null) {
for (Class<? extends Annotation> annotation : temp.keySet()) {
MethodSpec method = createProxyMethod(taskEnum, annotation, temp.get(annotation));
builder.addMethod(method); builder.addMethod(method);
} }
}
//增加构造函数 //增加构造函数
CodeBlock.Builder cb = CodeBlock.builder(); CodeBlock.Builder cb = CodeBlock.builder();
@ -345,8 +356,7 @@ class ElementHandler {
//创建父类参数 //创建父类参数
ClassName superClass = ClassName.get("com.arialyy.aria.core.scheduler", "AbsSchedulerListener"); ClassName superClass = ClassName.get("com.arialyy.aria.core.scheduler", "AbsSchedulerListener");
//创建泛型 //创建泛型
ClassName typeVariableName = ClassName typeVariableName = ClassName.get(taskEnum.getPkg(), taskEnum.getClassName());
ClassName.get(entity.taskEnum.getPkg(), entity.taskEnum.getClassName());
builder.superclass(ParameterizedTypeName.get(superClass, typeVariableName)); builder.superclass(ParameterizedTypeName.get(superClass, typeVariableName));
builder.addMethod(listener); builder.addMethod(listener);
return builder.build(); return builder.build();
@ -373,12 +383,16 @@ class ElementHandler {
ProxyMethodParam proxyEntity = mMethods.get(className); ProxyMethodParam proxyEntity = mMethods.get(className);
if (proxyEntity == null) { if (proxyEntity == null) {
proxyEntity = new ProxyMethodParam(); proxyEntity = new ProxyMethodParam();
proxyEntity.taskEnum = taskEnum; proxyEntity.taskEnums = new HashSet<>();
proxyEntity.packageName = packageElement.getQualifiedName().toString(); proxyEntity.packageName = packageElement.getQualifiedName().toString();
proxyEntity.className = classElement.getSimpleName().toString(); proxyEntity.className = classElement.getSimpleName().toString();
mMethods.put(className, proxyEntity); mMethods.put(className, proxyEntity);
} }
proxyEntity.methods.put(annotationClazz, methodName); proxyEntity.taskEnums.add(taskEnum);
if (proxyEntity.methods.get(taskEnum) == null) {
proxyEntity.methods.put(taskEnum, new HashMap<Class<? extends Annotation>, String>());
}
proxyEntity.methods.get(taskEnum).put(annotationClazz, methodName);
proxyEntity.keyMappings.put(methodName, getValues(taskEnum, method, annotationType)); proxyEntity.keyMappings.put(methodName, getValues(taskEnum, method, annotationType));
} }
} }

@ -27,7 +27,7 @@ import java.util.Set;
class ProxyMethodParam { class ProxyMethodParam {
String packageName; String packageName;
String className; String className;
TaskEnum taskEnum; Set<TaskEnum> taskEnums;
Map<String, Set<String>> keyMappings = new HashMap<>(); Map<String, Set<String>> keyMappings = new HashMap<>();
Map<Class<? extends Annotation>, String> methods = new HashMap<>(); Map<TaskEnum, Map<Class<? extends Annotation>, String>> methods = new HashMap<>();
} }

@ -20,10 +20,11 @@ package com.arialyy.compiler;
* 任务类型枚举 * 任务类型枚举
*/ */
enum TaskEnum { enum TaskEnum {
DOWNLOAD("com.arialyy.aria.core.download", "DownloadTask", "$$DownloadListenerProxy"), DOWNLOAD("com.arialyy.aria.core.download", "DownloadTask",
DOWNLOAD_GROUP("com.arialyy.aria.core.download", "DownloadGroupTask", "$$DownloadGroupListenerProxy"), "$$DownloadListenerProxy"), DOWNLOAD_GROUP("com.arialyy.aria.core.download",
UPLOAD("com.arialyy.aria.core.upload", "UploadTask", "$$UploadListenerProxy"), "DownloadGroupTask", "$$DownloadGroupListenerProxy"), UPLOAD("com.arialyy.aria.core.upload",
UPLOAD_GROUP("com.arialyy.aria.core.upload", "UploadGroupTask", "$$UploadGroupListenerProxy"); "UploadTask", "$$UploadListenerProxy"), UPLOAD_GROUP("com.arialyy.aria.core.upload",
"UploadGroupTask", "$$UploadGroupListenerProxy");
String pkg, className, proxySuffix; String pkg, className, proxySuffix;
@ -49,5 +50,4 @@ enum TaskEnum {
this.className = className; this.className = className;
this.proxySuffix = proxySuffix; this.proxySuffix = proxySuffix;
} }
} }

@ -16,6 +16,8 @@
package com.arialyy.simple.base.adapter; package com.arialyy.simple.base.adapter;
import android.content.Context; import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -45,6 +47,9 @@ public abstract class AbsRVAdapter<T, Holder extends AbsHolder>
@Override public Holder onCreateViewHolder(ViewGroup parent, int viewType) { @Override public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = View view =
LayoutInflater.from(parent.getContext()).inflate(setLayoutId(viewType), parent, false); LayoutInflater.from(parent.getContext()).inflate(setLayoutId(viewType), parent, false);
//LayoutInflater inflater = LayoutInflater.from(parent.getContext());
//VD binding = DataBindingUtil.inflate(inflater, setLayoutId(viewType), parent, false);
//;
holder = getViewHolder(view, viewType); holder = getViewHolder(view, viewType);
return holder; return holder;
} }

@ -29,6 +29,7 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R; import com.arialyy.simple.R;
@ -58,7 +59,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
private static final String DOWNLOAD_URL = private static final String DOWNLOAD_URL =
"https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk"; "https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk";
private DownloadAdapter mAdapter; private DownloadAdapter mAdapter;
private List<DownloadEntity> mData = new ArrayList<>(); private List<AbsEntity> mData = new ArrayList<>();
private Set<String> mRecord = new HashSet<>(); private Set<String> mRecord = new HashSet<>();
@Override protected int setLayoutId() { @Override protected int setLayoutId() {
@ -83,7 +84,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
setBtState(false); setBtState(false);
} }
mSize.setText(target.getConvertFileSize()); mSize.setText(target.getConvertFileSize());
List<DownloadEntity> temp = Aria.download(this).getTaskList(); List<DownloadEntity> temp = Aria.download(this).getSimpleTaskList();
if (temp != null && !temp.isEmpty()) { if (temp != null && !temp.isEmpty()) {
for (DownloadEntity entity : temp) { for (DownloadEntity entity : temp) {
if (entity.getDownloadUrl().equals(DOWNLOAD_URL)) continue; if (entity.getDownloadUrl().equals(DOWNLOAD_URL)) continue;

@ -190,7 +190,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
if (text.equals("重新开始?") || text.equals("开始")) { if (text.equals("重新开始?") || text.equals("开始")) {
Aria.download(this) Aria.download(this)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
.addHeader("key", "value") .addHeader("groupName", "value")
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
.start(); .start();
} else if (text.equals("恢复")) { } else if (text.equals("恢复")) {

@ -38,8 +38,8 @@ public class GroupModule extends BaseModule {
return urls; return urls;
} }
//List<String> convertPath(List<String> urls){ //NormalList<String> convertPath(NormalList<String> urls){
// List<String> paths = new ArrayList<>(); // NormalList<String> paths = new ArrayList<>();
// //
// for (String url : urls){ // for (String url : urls){
// //

@ -16,6 +16,7 @@
package com.arialyy.simple.download.multi_download; package com.arialyy.simple.download.multi_download;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.view.View; import android.view.View;
@ -24,12 +25,15 @@ import android.widget.TextView;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
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.inf.AbsEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.adapter.AbsHolder; import com.arialyy.simple.base.adapter.AbsHolder;
import com.arialyy.simple.base.adapter.AbsRVAdapter; import com.arialyy.simple.base.adapter.AbsRVAdapter;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
import com.arialyy.simple.widget.NoScrollListView;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -39,21 +43,32 @@ import java.util.concurrent.ConcurrentHashMap;
* Created by Lyy on 2016/9/27. * Created by Lyy on 2016/9/27.
* 下载列表适配器 * 下载列表适配器
*/ */
public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> { public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.SimpleHolder> {
private static final String TAG = "DownloadAdapter"; private static final String TAG = "DownloadAdapter";
private Map<String, Integer> mPositions = new ConcurrentHashMap<>(); private Map<String, Integer> mPositions = new ConcurrentHashMap<>();
public DownloadAdapter(Context context, List<DownloadEntity> data) { public DownloadAdapter(Context context, List<AbsEntity> data) {
super(context, data); super(context, data);
int i = 0; int i = 0;
for (DownloadEntity entity : data) { for (AbsEntity entity : data) {
mPositions.put(entity.getDownloadUrl(), i); mPositions.put(getKey(entity), i);
i++; i++;
} }
} }
@Override protected MyHolder getViewHolder(View convertView, int viewType) { private String getKey(AbsEntity entity) {
return new MyHolder(convertView); if (entity instanceof DownloadEntity) {
return ((DownloadEntity) entity).getDownloadUrl();
} else if (entity instanceof DownloadGroupEntity) {
return ((DownloadGroupEntity) entity).getGroupName();
}
return "";
}
@Override protected SimpleHolder getViewHolder(View convertView, int viewType) {
if (viewType == 1) return new SimpleHolder(convertView);
if (viewType == 2) return new GroupHolder(convertView);
return null;
} }
public void addDownloadEntity(DownloadEntity entity) { public void addDownloadEntity(DownloadEntity entity) {
@ -61,21 +76,33 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
mPositions.put(entity.getDownloadUrl(), mPositions.size()); mPositions.put(entity.getDownloadUrl(), mPositions.size());
} }
@Override public int getItemViewType(int position) {
AbsEntity entity = mData.get(position);
if (entity instanceof DownloadEntity) return 1;
if (entity instanceof DownloadGroupEntity) return 2;
return -1;
}
@Override protected int setLayoutId(int type) { @Override protected int setLayoutId(int type) {
return R.layout.item_download; if (type == 1) {
return R.layout.item_simple_download;
} else if (type == 2) {
return R.layout.item_group_download;
}
return android.R.layout.simple_list_item_2;
} }
public synchronized void updateState(DownloadEntity entity) { public synchronized void updateState(AbsEntity entity) {
if (entity.getState() == DownloadEntity.STATE_CANCEL) { if (entity.getState() == DownloadEntity.STATE_CANCEL) {
mPositions.clear(); mPositions.clear();
int i = 0; int i = 0;
for (DownloadEntity entity_1 : mData) { for (AbsEntity entity_1 : mData) {
mPositions.put(entity_1.getDownloadUrl(), i); mPositions.put(getKey(entity_1), i);
i++; i++;
} }
notifyDataSetChanged(); notifyDataSetChanged();
} else { } else {
int position = indexItem(entity.getDownloadUrl()); int position = indexItem(getKey(entity));
if (position == -1 || position >= mData.size()) { if (position == -1 || position >= mData.size()) {
return; return;
} }
@ -84,8 +111,8 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
} }
} }
public synchronized void setProgress(DownloadEntity entity) { public synchronized void setProgress(AbsEntity entity) {
String url = entity.getDownloadUrl(); String url = entity.getKey();
int position = indexItem(url); int position = indexItem(url);
if (position == -1 || position >= mData.size()) { if (position == -1 || position >= mData.size()) {
return; return;
@ -105,53 +132,67 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
return -1; return -1;
} }
@Override protected void bindData(MyHolder holder, int position, final DownloadEntity item) { @Override protected void bindData(SimpleHolder holder, int position, final AbsEntity item) {
long size = item.getFileSize(); handleProgress(holder, item);
int current = 0; }
long progress = item.getCurrentProgress();
current = size == 0 ? 0 : (int) (progress * 100 / size); @SuppressLint("SetTextI18n")
holder.progress.setProgress(current); private void handleProgress(SimpleHolder holder, final AbsEntity entity) {
BtClickListener listener = new BtClickListener(item);
holder.bt.setOnClickListener(listener);
holder.name.setText("文件名:" + item.getFileName());
holder.url.setText("下载地址:" + item.getDownloadUrl());
holder.path.setText("保持路径:" + item.getDownloadPath());
String str = ""; String str = "";
int color = android.R.color.holo_green_light; int color = android.R.color.holo_green_light;
switch (item.getState()) { switch (entity.getState()) {
case DownloadEntity.STATE_WAIT: case IEntity.STATE_WAIT:
case DownloadEntity.STATE_OTHER: case IEntity.STATE_OTHER:
case DownloadEntity.STATE_FAIL: case IEntity.STATE_FAIL:
str = "开始"; str = "开始";
break; break;
case DownloadEntity.STATE_STOP: case IEntity.STATE_STOP:
str = "恢复"; str = "恢复";
color = android.R.color.holo_blue_light; color = android.R.color.holo_blue_light;
break; break;
case DownloadEntity.STATE_PRE: case IEntity.STATE_PRE:
case DownloadEntity.STATE_POST_PRE: case IEntity.STATE_POST_PRE:
case DownloadEntity.STATE_RUNNING: case IEntity.STATE_RUNNING:
str = "暂停"; str = "暂停";
color = android.R.color.holo_red_light; color = android.R.color.holo_red_light;
break; break;
case DownloadEntity.STATE_COMPLETE: case IEntity.STATE_COMPLETE:
str = "重新开始?"; str = "重新开始?";
holder.progress.setProgress(100); holder.progress.setProgress(100);
break; break;
} }
long size = entity.getFileSize();
long progress = entity.getCurrentProgress();
int current = size == 0 ? 0 : (int) (progress * 100 / size);
holder.bt.setText(str); holder.bt.setText(str);
holder.bt.setTextColor(getColor(color)); holder.bt.setTextColor(getColor(color));
holder.speed.setText(item.getConvertSpeed()); holder.progress.setProgress(current);
BtClickListener listener = new BtClickListener(entity);
holder.bt.setOnClickListener(listener);
String name = (isSimpleDownload(entity) ? ((DownloadEntity) entity).getFileName()
: ((DownloadGroupEntity) entity).getAlias());
holder.name.setText("文件名:" + name);
holder.speed.setText(entity.getConvertSpeed());
holder.fileSize.setText(covertCurrentSize(progress) + "/" + CommonUtil.formatFileSize(size)); holder.fileSize.setText(covertCurrentSize(progress) + "/" + CommonUtil.formatFileSize(size));
//删除按钮事件
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(item); mData.remove(entity);
notifyDataSetChanged(); notifyDataSetChanged();
Aria.download(getContext()).load(item).cancel(); if (isSimpleDownload(entity)) {
Aria.download(getContext()).load((DownloadEntity) entity).cancel();
} else {
Aria.download(getContext()).load((DownloadGroupEntity) entity).cancel();
}
} }
}); });
} }
private boolean isSimpleDownload(AbsEntity entity) {
return entity instanceof DownloadEntity;
}
private String covertCurrentSize(long currentSize) { private String covertCurrentSize(long currentSize) {
if (currentSize < 0) return "0"; if (currentSize < 0) return "0";
return CommonUtil.formatFileSize(currentSize); return CommonUtil.formatFileSize(currentSize);
@ -161,49 +202,67 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
return Resources.getSystem().getColor(color); return Resources.getSystem().getColor(color);
} }
/**
* 按钮事件
*/
private class BtClickListener implements View.OnClickListener { private class BtClickListener implements View.OnClickListener {
private DownloadEntity entity; private AbsEntity entity;
BtClickListener(DownloadEntity entity) { BtClickListener(AbsEntity entity) {
this.entity = entity; this.entity = entity;
} }
@Override public void onClick(View v) { @Override public void onClick(View v) {
switch (entity.getState()) { switch (entity.getState()) {
case DownloadEntity.STATE_WAIT: case IEntity.STATE_WAIT:
case DownloadEntity.STATE_OTHER: case IEntity.STATE_OTHER:
case DownloadEntity.STATE_FAIL: case IEntity.STATE_FAIL:
case DownloadEntity.STATE_STOP: case IEntity.STATE_STOP:
case DownloadEntity.STATE_COMPLETE: case IEntity.STATE_COMPLETE:
case DownloadEntity.STATE_POST_PRE: case IEntity.STATE_PRE:
case IEntity.STATE_POST_PRE:
start(entity); start(entity);
break; break;
case DownloadEntity.STATE_RUNNING: case IEntity.STATE_RUNNING:
stop(entity); stop(entity);
break; break;
} }
} }
private void start(DownloadEntity entity) { private void start(AbsEntity entity) {
Aria.download(getContext()).load(entity).start(); if (isSimpleDownload(entity)) {
Aria.download(getContext()).load((DownloadEntity) entity).start();
} else {
Aria.download(getContext()).load((DownloadGroupEntity) entity).start();
}
} }
private void stop(DownloadEntity entity) { private void stop(AbsEntity entity) {
Aria.download(getContext()).load(entity).pause(); if (isSimpleDownload(entity)) {
Aria.download(getContext()).load((DownloadEntity) entity).stop();
} else {
Aria.download(getContext()).load((DownloadGroupEntity) entity).stop();
}
} }
} }
class MyHolder extends AbsHolder { class SimpleHolder extends AbsHolder {
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress; @Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress;
@Bind(R.id.bt) Button bt; @Bind(R.id.bt) Button bt;
@Bind(R.id.speed) TextView speed; @Bind(R.id.speed) TextView speed;
@Bind(R.id.fileSize) TextView fileSize; @Bind(R.id.fileSize) TextView fileSize;
@Bind(R.id.del) TextView cancel; @Bind(R.id.del) TextView cancel;
@Bind(R.id.name) TextView name; @Bind(R.id.name) TextView name;
@Bind(R.id.download_url) TextView url;
@Bind(R.id.download_path) TextView path;
MyHolder(View itemView) { SimpleHolder(View itemView) {
super(itemView);
}
}
class GroupHolder extends SimpleHolder {
@Bind(R.id.child_list) NoScrollListView childList;
GroupHolder(View itemView) {
super(itemView); super(itemView);
} }
} }

@ -68,7 +68,7 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show();
Aria.download(getContext()) Aria.download(getContext())
.load(item.downloadUrl) .load(item.downloadUrl)
.setDownloadName(item.name) .setFileName(item.name)
.setDownloadPath(item.downloadPath) .setDownloadPath(item.downloadPath)
.start(); .start();
} }

@ -23,9 +23,12 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
@ -39,12 +42,7 @@ import java.util.List;
public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBinding> { public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBinding> {
@Bind(R.id.list) RecyclerView mList; @Bind(R.id.list) RecyclerView mList;
private DownloadAdapter mAdapter; private DownloadAdapter mAdapter;
private List<DownloadEntity> mData = new ArrayList<>(); private List<AbsEntity> mData = new ArrayList<>();
String[] mFilterStr = new String[] {
"https://g37.gdl.netease.com/onmyoji_netease_10_1.0.20.apk",
"http://static.gaoshouyou.com/d/eb/f2/dfeba30541f209ab8a50d847fc1661ce.apk"
};
@Override protected int setLayoutId() { @Override protected int setLayoutId() {
return R.layout.activity_multi_download; return R.layout.activity_multi_download;
@ -54,7 +52,7 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
super.init(savedInstanceState); super.init(savedInstanceState);
Aria.download(this).register(); Aria.download(this).register();
setTitle("下载列表"); setTitle("下载列表");
List<DownloadEntity> temps = Aria.download(this).getTaskList(); List<AbsEntity> temps = Aria.download(this).getTotleTaskList();
if (temps != null && !temps.isEmpty()) { if (temps != null && !temps.isEmpty()) {
mData.addAll(temps); mData.addAll(temps);
} }
@ -74,37 +72,68 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
} }
@Download.onPre void onPre(DownloadTask task) { @Download.onPre void onPre(DownloadTask task) {
L.d(TAG, "download onPre"); mAdapter.updateState(task.getEntity());
mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(DownloadTask task) {
L.d(TAG, "download start"); mAdapter.updateState(task.getEntity());
mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskResume void taskResume(DownloadTask task) { @Download.onTaskResume void taskResume(DownloadTask task) {
L.d(TAG, "download resume"); mAdapter.updateState(task.getEntity());
mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskStop void taskStop(DownloadTask task) { @Download.onTaskStop void taskStop(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskCancel void taskCancel(DownloadTask task) { @Download.onTaskCancel void taskCancel(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskFail void taskFail(DownloadTask task) { @Download.onTaskFail void taskFail(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskComplete void taskComplete(DownloadTask task) { @Download.onTaskComplete void taskComplete(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskRunning() void taskRunning(DownloadTask task) { @Download.onTaskRunning() void taskRunning(DownloadTask task) {
mAdapter.setProgress(task.getDownloadEntity()); mAdapter.setProgress(task.getEntity());
}
//////////////////////////////////// 下面为任务组的处理 /////////////////////////////////////////
@DownloadGroup.onPre void onGroupPre(DownloadGroupTask task) {
mAdapter.updateState(task.getEntity());
}
@DownloadGroup.onTaskStart void groupTaskStart(DownloadGroupTask task) {
mAdapter.updateState(task.getEntity());
}
@DownloadGroup.onTaskResume void groupTaskResume(DownloadGroupTask task) {
mAdapter.updateState(task.getEntity());
}
@DownloadGroup.onTaskStop void groupTaskStop(DownloadGroupTask task) {
mAdapter.updateState(task.getEntity());
}
@DownloadGroup.onTaskCancel void groupTaskCancel(DownloadGroupTask task) {
mAdapter.updateState(task.getEntity());
}
@DownloadGroup.onTaskFail void groupTaskFail(DownloadGroupTask task) {
mAdapter.updateState(task.getEntity());
}
@DownloadGroup.onTaskComplete void groupTaskComplete(DownloadGroupTask task) {
mAdapter.updateState(task.getEntity());
}
@DownloadGroup.onTaskRunning() void groupTaskRunning(DownloadGroupTask task) {
mAdapter.setProgress(task.getEntity());
} }
} }

@ -0,0 +1,33 @@
/*
* 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.simple.download.multi_download;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
/**
* Created by Aria.Lao on 2017/7/14.
*/
public class MultiEntity {
public static final int SIMPLE_DOWNLOAD = 0xa1;
public static final int GROUP_DOWNLOAD = 0xa2;
DownloadEntity simpleEntity;
DownloadGroupEntity groupEntity;
String key;
int type = -1;
}

@ -0,0 +1,29 @@
/*
* 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.simple.download.multi_download;
import android.content.Context;
import com.arialyy.simple.base.BaseModule;
/**
* Created by Aria.Lao on 2017/7/14.
*/
public class MultiModule extends BaseModule{
public MultiModule(Context context) {
super(context);
}
}

@ -97,9 +97,6 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
mAdapter.updateBtState(task.getKey(), true); mAdapter.updateBtState(task.getKey(), true);
} }
@Override protected void dataCallback(int result, Object data) { @Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data); super.dataCallback(result, data);
if (result == DownloadNumDialog.RESULT_CODE) { if (result == DownloadNumDialog.RESULT_CODE) {

@ -0,0 +1,43 @@
/*
* 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.simple.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
/**
* Created by lyy on 2015/4/22.
* 不带有滑动功能的ListView
*/
public class NoScrollListView extends ListView {
public NoScrollListView(Context context) {
super(context);
}
public NoScrollListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NoScrollListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<include layout="@layout/layout_item_progress"
android:id="@+id/include"
/>
<com.arialyy.simple.widget.NoScrollListView
android:id="@+id/child_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/include"
/>
</RelativeLayout>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<include layout="@layout/layout_item_progress"/>
</RelativeLayout>

@ -65,7 +65,6 @@
android:textColor="@color/bt_selector_cancel" android:textColor="@color/bt_selector_cancel"
/> />
</RelativeLayout> </RelativeLayout>
<TextView <TextView
android:id="@+id/name" android:id="@+id/name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -75,22 +74,4 @@
android:text="name" android:text="name"
/> />
<TextView
android:id="@+id/download_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:maxLines="2"
/>
<TextView
android:id="@+id/download_path"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/download_url"
android:layout_marginTop="5dp"
/>
</RelativeLayout> </RelativeLayout>
Loading…
Cancel
Save