任务组事件和普通任务事件同时使用
This commit is contained in:
@ -76,7 +76,7 @@ artifacts {
|
||||
//################################# jcenter 上传配置 start #########################################
|
||||
bintray {
|
||||
// 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
|
||||
key = BINTRAY_KEY
|
||||
configurations = ['archives']
|
||||
|
@ -56,7 +56,7 @@ class GroupStartCmd<T extends AbsTaskEntity> extends AbsGroupCmd<T> {
|
||||
if (mod.equals(QueueMod.NOW.getTag())) {
|
||||
mQueue.startTask(task);
|
||||
} else if (mod.equals(QueueMod.WAIT.getTag())) {
|
||||
if (mQueue.getExePoolSize() < maxTaskNum) {
|
||||
if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
|
||||
mQueue.startTask(task);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
List<DownloadEntity> allEntity =
|
||||
DbEntity.findDatas(DownloadEntity.class, "state=?", IEntity.STATE_STOP + "");
|
||||
for (DownloadEntity entity : allEntity) {
|
||||
int exeNum = mQueue.getExePoolSize();
|
||||
int exeNum = mQueue.getCurrentExePoolNum();
|
||||
if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) {
|
||||
AbsTask task = createTask(entity);
|
||||
mQueue.startTask(task);
|
||||
|
@ -19,9 +19,15 @@ package com.arialyy.aria.core.command.normal;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
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.IEntity;
|
||||
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.
|
||||
@ -57,14 +63,13 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
if (mod.equals(QueueMod.NOW.getTag())) {
|
||||
mQueue.startTask(task);
|
||||
} else if (mod.equals(QueueMod.WAIT.getTag())) {
|
||||
if (mQueue.getExePoolSize() < maxTaskNum) {
|
||||
if (mQueue.getCurrentExePoolNum() < maxTaskNum || task.getState() == IEntity.STATE_STOP) {
|
||||
mQueue.startTask(task);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 任务不存在时,根据配置不同,对任务执行操作
|
||||
if (!task.isRunning() && mod.equals(QueueMod.WAIT.getTag()) && (task.getState()
|
||||
== IEntity.STATE_WAIT || task.getState() == IEntity.STATE_STOP)) {
|
||||
if (!task.isRunning()) {
|
||||
mQueue.startTask(task);
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,10 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
|
||||
*/
|
||||
private String serverFileName = "";
|
||||
|
||||
@Override public String getKey() {
|
||||
return downloadUrl;
|
||||
}
|
||||
|
||||
public DownloadEntity() {
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.os.Parcel;
|
||||
import com.arialyy.aria.core.inf.AbsGroupEntity;
|
||||
import com.arialyy.aria.orm.NormalList;
|
||||
import com.arialyy.aria.orm.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -27,16 +28,26 @@ import java.util.List;
|
||||
*/
|
||||
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 = "";
|
||||
|
||||
public List<DownloadEntity> getSubTask() {
|
||||
return subtask;
|
||||
}
|
||||
|
||||
public void setSubTasks(List<DownloadEntity> subTasks) {
|
||||
void setSubTasks(List<DownloadEntity> subTasks) {
|
||||
this.subtask = subTasks;
|
||||
}
|
||||
|
||||
@ -48,6 +59,18 @@ public class DownloadGroupEntity extends AbsGroupEntity {
|
||||
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() {
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ package com.arialyy.aria.core.download;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTarget;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -40,14 +41,26 @@ public class DownloadGroupTarget
|
||||
*/
|
||||
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) {
|
||||
this.mTargetName = targetName;
|
||||
this.mUrls = urls;
|
||||
mGroupName = CommonUtil.getMd5Code(urls);
|
||||
mTaskEntity = DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", mGroupName);
|
||||
init(CommonUtil.getMd5Code(urls));
|
||||
}
|
||||
|
||||
private void init(String key) {
|
||||
mGroupName = key;
|
||||
mTaskEntity = DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", key);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = new DownloadGroupTaskEntity();
|
||||
mTaskEntity.key = mGroupName;
|
||||
mTaskEntity.key = key;
|
||||
mTaskEntity.entity = getDownloadGroupEntity();
|
||||
mTaskEntity.insert();
|
||||
}
|
||||
@ -57,18 +70,43 @@ public class DownloadGroupTarget
|
||||
mEntity = mTaskEntity.entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务组实体,如果数据库不存在该实体,则新创建一个新的任务组实体
|
||||
*/
|
||||
private DownloadGroupEntity getDownloadGroupEntity() {
|
||||
DownloadGroupEntity entity =
|
||||
DbEntity.findFirst(DownloadGroupEntity.class, "groupName=?", mGroupName);
|
||||
if (entity == null) {
|
||||
entity = new DownloadGroupEntity();
|
||||
entity.setGroupName(mGroupName);
|
||||
entity.setUrlmd5(mGroupName);
|
||||
entity.setUrls(mUrls);
|
||||
entity.insert();
|
||||
}
|
||||
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中,任务组的所有子任务都会下载到以任务组组名的文件夹中。
|
||||
* 如:groupDirPath = "/mnt/sdcard/download/group_test"
|
||||
|
@ -17,6 +17,7 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
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.IReceiver;
|
||||
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.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -71,6 +73,16 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
return new DownloadGroupTarget(urls, targetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用任务组实体执行任务组的实体执行任务组的下载操作
|
||||
*
|
||||
* @param groupEntity 如果加载的任务实体没有子项的下载地址,
|
||||
* 那么你需要使用{@link DownloadGroupTarget#setGroupUrl(List)}设置子项的下载地址
|
||||
*/
|
||||
public DownloadGroupTarget load(DownloadGroupEntity groupEntity) {
|
||||
return new DownloadGroupTarget(groupEntity, targetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将当前类注册到Aria
|
||||
*/
|
||||
@ -144,7 +156,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
*/
|
||||
public DownloadTaskEntity getDownloadTask(String downloadUrl) {
|
||||
CheckUtil.checkDownloadUrl(downloadUrl);
|
||||
return DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'",
|
||||
return DbEntity.findFirst(DownloadTaskEntity.class, "groupName=? and isGroupTask='false'",
|
||||
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");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务组列表
|
||||
*/
|
||||
public List<DownloadGroupTaskEntity> getGroupTaskList() {
|
||||
return DownloadEntity.findAllData(DownloadGroupTaskEntity.class);
|
||||
public List<DownloadGroupEntity> getGroupTaskList() {
|
||||
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.setFileName(file.getName());
|
||||
mTaskEntity.key = downloadPath;
|
||||
mEntity.update();
|
||||
mTaskEntity.update();
|
||||
return this;
|
||||
}
|
||||
|
@ -142,6 +142,11 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable
|
||||
this.completeTime = completeTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实体唯一标识符
|
||||
*/
|
||||
public abstract String getKey();
|
||||
|
||||
public AbsEntity() {
|
||||
}
|
||||
|
||||
@ -174,5 +179,4 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable
|
||||
this.completeTime = in.readLong();
|
||||
this.isComplete = in.readByte() != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,30 +24,29 @@ import com.arialyy.aria.orm.Primary;
|
||||
*/
|
||||
public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
|
||||
/**
|
||||
* 组名
|
||||
* 组名,组名为任务地址相加的urlMd5
|
||||
*/
|
||||
@Primary
|
||||
private String groupName = "";
|
||||
@Primary protected String groupName = "";
|
||||
|
||||
/**
|
||||
* 任务地址相加的urlmd5
|
||||
* 任务组别名
|
||||
*/
|
||||
private String urlmd5 = "";
|
||||
|
||||
public String getUrlmd5() {
|
||||
return urlmd5;
|
||||
}
|
||||
|
||||
public void setUrlmd5(String urlmd5) {
|
||||
this.urlmd5 = urlmd5;
|
||||
}
|
||||
private String alias = "";
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
this.groupName = groupName;
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
@Override public String getKey() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public AbsGroupEntity() {
|
||||
@ -60,12 +59,12 @@ public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
|
||||
@Override public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(this.groupName);
|
||||
dest.writeString(this.urlmd5);
|
||||
dest.writeString(this.alias);
|
||||
}
|
||||
|
||||
protected AbsGroupEntity(Parcel in) {
|
||||
super(in);
|
||||
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.
|
||||
*/
|
||||
|
||||
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 获取缓存的任务数
|
||||
*/
|
||||
@Override public int getCachePoolSize() {
|
||||
@Override public int getCurrentCachePoolNum() {
|
||||
return mCachePool.size();
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
|
||||
*
|
||||
* @return 当前正在执行的任务数
|
||||
*/
|
||||
@Override public int getExePoolSize() {
|
||||
@Override public int getCurrentExePoolNum() {
|
||||
return mExecutePool.size();
|
||||
}
|
||||
|
||||
|
@ -88,14 +88,14 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
|
||||
void reTryStart(TASK task);
|
||||
|
||||
/**
|
||||
* 获取执行池中的任务数量
|
||||
* 获取当前执行池中的任务数量
|
||||
*/
|
||||
int getExePoolSize();
|
||||
int getCurrentExePoolNum();
|
||||
|
||||
/**
|
||||
* 获取任务缓存池中的任务数量
|
||||
* 获取当前任务缓存池中的任务数量
|
||||
*/
|
||||
int getCachePoolSize();
|
||||
int getCurrentCachePoolNum();
|
||||
|
||||
/**
|
||||
* 设置执行池可执行的最大任务数
|
||||
|
@ -16,7 +16,6 @@
|
||||
package com.arialyy.aria.core.scheduler;
|
||||
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
@ -140,7 +139,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
|
||||
}
|
||||
case CANCEL:
|
||||
mQueue.removeTask(entity);
|
||||
if (mQueue.getExePoolSize() < AriaManager.getInstance(AriaManager.APP)
|
||||
if (mQueue.getCurrentExePoolNum() < AriaManager.getInstance(AriaManager.APP)
|
||||
.getUploadConfig()
|
||||
.getMaxTaskNum()) {
|
||||
startNextTask();
|
||||
@ -206,11 +205,6 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
|
||||
listener.onTaskCancel(task);
|
||||
break;
|
||||
case COMPLETE:
|
||||
//new Handler().postDelayed(new Runnable() {
|
||||
// @Override public void run() {
|
||||
// listener.onTaskComplete(task);
|
||||
// }
|
||||
//}, 1000);
|
||||
listener.onTaskComplete(task);
|
||||
break;
|
||||
case FAIL:
|
||||
@ -280,7 +274,14 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
|
||||
*
|
||||
* @return {@code true} 有,{@code false} 无
|
||||
*/
|
||||
protected boolean hasNextTask() {
|
||||
return mQueue.getCachePoolSize() > 0;
|
||||
boolean hasNextTask() {
|
||||
return mQueue.getCurrentCachePoolNum() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取正在执行的队列数
|
||||
*/
|
||||
int getExeTaskNum() {
|
||||
return mQueue.getCurrentExePoolNum();
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,11 @@
|
||||
package com.arialyy.aria.core.scheduler;
|
||||
|
||||
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.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 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_GROUP = 0xa2;
|
||||
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;
|
||||
|
||||
@ -79,4 +80,10 @@ public class DQueueMapping {
|
||||
}
|
||||
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.
|
||||
* 任务组调度器
|
||||
*/
|
||||
public class DownloadGroupSchedulers extends
|
||||
AbsSchedulers<DownloadGroupTaskEntity, DownloadGroupEntity, DownloadGroupTask, DownloadGroupTaskQueue> {
|
||||
@ -51,6 +52,10 @@ public class DownloadGroupSchedulers extends
|
||||
}
|
||||
|
||||
@Override protected void startNextTask() {
|
||||
if (getExeTaskNum() + DownloadSchedulers.getInstance().getExeTaskNum()
|
||||
>= AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum()) {
|
||||
return;
|
||||
}
|
||||
if (!DownloadSchedulers.getInstance().hasNextTask()) {
|
||||
nextSelf();
|
||||
} else {
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.arialyy.aria.core.scheduler;
|
||||
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
@ -55,6 +56,10 @@ public class DownloadSchedulers
|
||||
}
|
||||
|
||||
@Override protected void startNextTask() {
|
||||
if (getExeTaskNum() + DownloadGroupSchedulers.getInstance().getExeTaskNum()
|
||||
>= AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum()) {
|
||||
return;
|
||||
}
|
||||
if (!DownloadGroupSchedulers.getInstance().hasNextTask()) {
|
||||
nextSelf();
|
||||
} else {
|
||||
|
@ -38,6 +38,10 @@ public class UploadEntity extends AbsNormalEntity implements Parcelable {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
@Override public String getKey() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public UploadEntity() {
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
|
||||
return DbEntity.findFirst(UploadEntity.class, "filePath=?", filePath) != null;
|
||||
}
|
||||
|
||||
@Override public List<UploadEntity> getTaskList() {
|
||||
@Override public List<UploadEntity> getSimpleTaskList() {
|
||||
return DbEntity.findAllData(UploadEntity.class);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class UploadTarget extends AbsNormalTarget<UploadTarget, UploadEntity, Up
|
||||
|
||||
UploadTarget(String filePath, String targetName) {
|
||||
this.mTargetName = targetName;
|
||||
mTaskEntity = DbEntity.findFirst(UploadTaskEntity.class, "key=?", filePath);
|
||||
mTaskEntity = DbEntity.findFirst(UploadTaskEntity.class, "groupName=?", filePath);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = new UploadTaskEntity();
|
||||
mTaskEntity.entity = new UploadEntity();
|
||||
|
@ -32,7 +32,7 @@ import java.util.Map;
|
||||
public class DBConfig {
|
||||
static Map<String, Class> mapping = new HashMap<>();
|
||||
static String DB_NAME;
|
||||
static int VERSION = 9;
|
||||
static int VERSION = 10;
|
||||
|
||||
static {
|
||||
if (TextUtils.isEmpty(DB_NAME)) {
|
||||
|
@ -171,7 +171,11 @@ public class DbEntity {
|
||||
if (SqlHelper.isOneToOne(field)) {
|
||||
values.add(SqlHelper.getOneToOneParams(field));
|
||||
} 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) {
|
||||
values.add(SqlHelper.map2Str((Map<String, String>) field.get(this)));
|
||||
} else {
|
||||
|
@ -187,7 +187,7 @@ public class DbUtil {
|
||||
Log.e(TAG, "请输入删除条件");
|
||||
return -1;
|
||||
} else if (wheres.length != values.length) {
|
||||
Log.e(TAG, "key 和 vaule 长度不相等");
|
||||
Log.e(TAG, "groupName 和 vaule 长度不相等");
|
||||
return -1;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
32
Aria/src/main/java/com/arialyy/aria/orm/NormalList.java
Normal file
32
Aria/src/main/java/com/arialyy/aria/orm/NormalList.java
Normal file
@ -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.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -220,7 +220,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
Log.e(TAG, "请输入查询条件");
|
||||
return null;
|
||||
} else if (wheres.length != values.length) {
|
||||
Log.e(TAG, "key 和 vaule 长度不相等");
|
||||
Log.e(TAG, "groupName 和 vaule 长度不相等");
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@ -297,7 +297,11 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
if (type == Map.class) {
|
||||
value = map2Str((Map<String, String>) field.get(dbEntity));
|
||||
} else if (type == List.class) {
|
||||
value = getListElementParams(field);
|
||||
if (isOneToMany(field)) {
|
||||
value = getOneToManyElementParams(field);
|
||||
} else {
|
||||
value = list2Str(dbEntity, field);
|
||||
}
|
||||
} else if (isOneToOne(field)) {
|
||||
value = getOneToOneParams(field);
|
||||
} else {
|
||||
@ -354,7 +358,11 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
if (type == Map.class) {
|
||||
sb.append(map2Str((Map<String, String>) field.get(dbEntity)));
|
||||
} 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)) {
|
||||
sb.append(getOneToOneParams(field));
|
||||
} else {
|
||||
@ -373,13 +381,6 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
close(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存一对一的数据
|
||||
*/
|
||||
private void saveOneToOneFile(Field field) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一对一参数
|
||||
*/
|
||||
@ -396,10 +397,10 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
*
|
||||
* @param field list反射字段
|
||||
*/
|
||||
static String getListElementParams(Field field) {
|
||||
static String getOneToManyElementParams(Field field) {
|
||||
OneToMany oneToMany = field.getAnnotation(OneToMany.class);
|
||||
if (oneToMany == null) {
|
||||
throw new IllegalArgumentException("List中元素必须被@OneToMany注解");
|
||||
throw new IllegalArgumentException("一对多元素必须被@OneToMany注解");
|
||||
}
|
||||
//关联的表名
|
||||
String tableName = oneToMany.table().getName();
|
||||
@ -408,6 +409,63 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
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的主键字段
|
||||
*
|
||||
@ -510,23 +568,6 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
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,19 +639,23 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
} else if (type == Map.class) {
|
||||
field.set(entity, str2Map(cursor.getString(column)));
|
||||
} else if (type == List.class) {
|
||||
//主键字段
|
||||
String primaryKey = getPrimaryName(clazz);
|
||||
if (TextUtils.isEmpty(primaryKey)) {
|
||||
throw new IllegalArgumentException("List中的元素对象必须需要@Primary注解的字段");
|
||||
String value = cursor.getString(column);
|
||||
if (isOneToMany(field)) {
|
||||
//主键字段
|
||||
String primaryKey = getPrimaryName(clazz);
|
||||
if (TextUtils.isEmpty(primaryKey)) {
|
||||
throw new IllegalArgumentException("List中的元素对象必须需要@Primary注解的字段");
|
||||
}
|
||||
//list字段保存的数据
|
||||
int kc = cursor.getColumnIndex(primaryKey);
|
||||
String primaryData = cursor.getString(kc);
|
||||
if (TextUtils.isEmpty(primaryData)) continue;
|
||||
List<T> list = findForeignData(db, primaryData, value);
|
||||
if (list == null) continue;
|
||||
field.set(entity, findForeignData(db, primaryData, value));
|
||||
} else {
|
||||
field.set(entity, str2List(value, field));
|
||||
}
|
||||
//list字段保存的数据
|
||||
int kc = cursor.getColumnIndex(primaryKey);
|
||||
String params = cursor.getString(column);
|
||||
String primaryData = cursor.getString(kc);
|
||||
if (TextUtils.isEmpty(primaryData)) continue;
|
||||
List<T> list = findForeignData(db, primaryData, params);
|
||||
if (list == null) continue;
|
||||
field.set(entity, findForeignData(db, primaryData, params));
|
||||
} else if (isOneToOne(field)) {
|
||||
String primaryKey = getPrimaryName(clazz);
|
||||
if (TextUtils.isEmpty(primaryKey)) {
|
||||
|
@ -50,6 +50,7 @@ import javax.lang.model.util.Elements;
|
||||
* 元素处理
|
||||
*/
|
||||
class ElementHandler {
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private Filer mFiler;
|
||||
private Elements mElementUtil;
|
||||
@ -170,16 +171,25 @@ class ElementHandler {
|
||||
Set<String> keys = mMethods.keySet();
|
||||
for (String key : keys) {
|
||||
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 {
|
||||
Set<String> keys = mListenerClass.keySet();
|
||||
@ -212,8 +222,7 @@ class ElementHandler {
|
||||
ProxyConstance.COUNT_DOWNLOAD_GROUP));
|
||||
|
||||
JavaFile jf = JavaFile.builder(ProxyConstance.PROXY_COUNTER_PACKAGE, builder.build()).build();
|
||||
jf.writeTo(mFiler);
|
||||
//jf.writeTo(System.out);
|
||||
createFile(jf);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -287,8 +296,7 @@ class ElementHandler {
|
||||
/**
|
||||
* 创建代理类
|
||||
*/
|
||||
private TypeSpec createProxyClass(ProxyMethodParam entity) {
|
||||
TaskEnum taskEnum = entity.taskEnum;
|
||||
private TypeSpec createProxyClass(ProxyMethodParam entity, TaskEnum taskEnum) {
|
||||
TypeSpec.Builder builder = TypeSpec.classBuilder(entity.className + taskEnum.getProxySuffix())
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
|
||||
@ -305,9 +313,12 @@ class ElementHandler {
|
||||
builder.addField(mappingField);
|
||||
|
||||
//添加注解方法
|
||||
for (Class<? extends Annotation> annotation : entity.methods.keySet()) {
|
||||
MethodSpec method = createProxyMethod(taskEnum, annotation, entity.methods.get(annotation));
|
||||
builder.addMethod(method);
|
||||
Map<Class<? extends Annotation>, String> temp = entity.methods.get(taskEnum);
|
||||
if (temp != null) {
|
||||
for (Class<? extends Annotation> annotation : temp.keySet()) {
|
||||
MethodSpec method = createProxyMethod(taskEnum, annotation, temp.get(annotation));
|
||||
builder.addMethod(method);
|
||||
}
|
||||
}
|
||||
|
||||
//增加构造函数
|
||||
@ -345,8 +356,7 @@ class ElementHandler {
|
||||
//创建父类参数
|
||||
ClassName superClass = ClassName.get("com.arialyy.aria.core.scheduler", "AbsSchedulerListener");
|
||||
//创建泛型
|
||||
ClassName typeVariableName =
|
||||
ClassName.get(entity.taskEnum.getPkg(), entity.taskEnum.getClassName());
|
||||
ClassName typeVariableName = ClassName.get(taskEnum.getPkg(), taskEnum.getClassName());
|
||||
builder.superclass(ParameterizedTypeName.get(superClass, typeVariableName));
|
||||
builder.addMethod(listener);
|
||||
return builder.build();
|
||||
@ -373,12 +383,16 @@ class ElementHandler {
|
||||
ProxyMethodParam proxyEntity = mMethods.get(className);
|
||||
if (proxyEntity == null) {
|
||||
proxyEntity = new ProxyMethodParam();
|
||||
proxyEntity.taskEnum = taskEnum;
|
||||
proxyEntity.taskEnums = new HashSet<>();
|
||||
proxyEntity.packageName = packageElement.getQualifiedName().toString();
|
||||
proxyEntity.className = classElement.getSimpleName().toString();
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import java.util.Set;
|
||||
class ProxyMethodParam {
|
||||
String packageName;
|
||||
String className;
|
||||
TaskEnum taskEnum;
|
||||
Set<TaskEnum> taskEnums;
|
||||
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 {
|
||||
DOWNLOAD("com.arialyy.aria.core.download", "DownloadTask", "$$DownloadListenerProxy"),
|
||||
DOWNLOAD_GROUP("com.arialyy.aria.core.download", "DownloadGroupTask", "$$DownloadGroupListenerProxy"),
|
||||
UPLOAD("com.arialyy.aria.core.upload", "UploadTask", "$$UploadListenerProxy"),
|
||||
UPLOAD_GROUP("com.arialyy.aria.core.upload", "UploadGroupTask", "$$UploadGroupListenerProxy");
|
||||
DOWNLOAD("com.arialyy.aria.core.download", "DownloadTask",
|
||||
"$$DownloadListenerProxy"), DOWNLOAD_GROUP("com.arialyy.aria.core.download",
|
||||
"DownloadGroupTask", "$$DownloadGroupListenerProxy"), UPLOAD("com.arialyy.aria.core.upload",
|
||||
"UploadTask", "$$UploadListenerProxy"), UPLOAD_GROUP("com.arialyy.aria.core.upload",
|
||||
"UploadGroupTask", "$$UploadGroupListenerProxy");
|
||||
|
||||
String pkg, className, proxySuffix;
|
||||
|
||||
@ -49,5 +50,4 @@ enum TaskEnum {
|
||||
this.className = className;
|
||||
this.proxySuffix = proxySuffix;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
package com.arialyy.simple.base.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.databinding.ViewDataBinding;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -45,6 +47,9 @@ public abstract class AbsRVAdapter<T, Holder extends AbsHolder>
|
||||
@Override public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view =
|
||||
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);
|
||||
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.DownloadTarget;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
@ -58,7 +59,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
||||
private static final String DOWNLOAD_URL =
|
||||
"https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk";
|
||||
private DownloadAdapter mAdapter;
|
||||
private List<DownloadEntity> mData = new ArrayList<>();
|
||||
private List<AbsEntity> mData = new ArrayList<>();
|
||||
private Set<String> mRecord = new HashSet<>();
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
@ -83,7 +84,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
||||
setBtState(false);
|
||||
}
|
||||
mSize.setText(target.getConvertFileSize());
|
||||
List<DownloadEntity> temp = Aria.download(this).getTaskList();
|
||||
List<DownloadEntity> temp = Aria.download(this).getSimpleTaskList();
|
||||
if (temp != null && !temp.isEmpty()) {
|
||||
for (DownloadEntity entity : temp) {
|
||||
if (entity.getDownloadUrl().equals(DOWNLOAD_URL)) continue;
|
||||
|
@ -190,7 +190,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
if (text.equals("重新开始?") || text.equals("开始")) {
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.addHeader("key", "value")
|
||||
.addHeader("groupName", "value")
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
.start();
|
||||
} else if (text.equals("恢复")) {
|
||||
|
@ -38,8 +38,8 @@ public class GroupModule extends BaseModule {
|
||||
return urls;
|
||||
}
|
||||
|
||||
//List<String> convertPath(List<String> urls){
|
||||
// List<String> paths = new ArrayList<>();
|
||||
//NormalList<String> convertPath(NormalList<String> urls){
|
||||
// NormalList<String> paths = new ArrayList<>();
|
||||
//
|
||||
// for (String url : urls){
|
||||
//
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.arialyy.simple.download.multi_download;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
@ -24,12 +25,15 @@ import android.widget.TextView;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
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.util.CommonUtil;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.adapter.AbsHolder;
|
||||
import com.arialyy.simple.base.adapter.AbsRVAdapter;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
import com.arialyy.simple.widget.NoScrollListView;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -39,21 +43,32 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* 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 Map<String, Integer> mPositions = new ConcurrentHashMap<>();
|
||||
|
||||
public DownloadAdapter(Context context, List<DownloadEntity> data) {
|
||||
public DownloadAdapter(Context context, List<AbsEntity> data) {
|
||||
super(context, data);
|
||||
int i = 0;
|
||||
for (DownloadEntity entity : data) {
|
||||
mPositions.put(entity.getDownloadUrl(), i);
|
||||
for (AbsEntity entity : data) {
|
||||
mPositions.put(getKey(entity), i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected MyHolder getViewHolder(View convertView, int viewType) {
|
||||
return new MyHolder(convertView);
|
||||
private String getKey(AbsEntity entity) {
|
||||
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) {
|
||||
@ -61,21 +76,33 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
||||
mPositions.put(entity.getDownloadUrl(), mPositions.size());
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId(int type) {
|
||||
return R.layout.item_download;
|
||||
@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;
|
||||
}
|
||||
|
||||
public synchronized void updateState(DownloadEntity entity) {
|
||||
@Override protected int setLayoutId(int type) {
|
||||
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(AbsEntity entity) {
|
||||
if (entity.getState() == DownloadEntity.STATE_CANCEL) {
|
||||
mPositions.clear();
|
||||
int i = 0;
|
||||
for (DownloadEntity entity_1 : mData) {
|
||||
mPositions.put(entity_1.getDownloadUrl(), i);
|
||||
for (AbsEntity entity_1 : mData) {
|
||||
mPositions.put(getKey(entity_1), i);
|
||||
i++;
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
} else {
|
||||
int position = indexItem(entity.getDownloadUrl());
|
||||
int position = indexItem(getKey(entity));
|
||||
if (position == -1 || position >= mData.size()) {
|
||||
return;
|
||||
}
|
||||
@ -84,8 +111,8 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setProgress(DownloadEntity entity) {
|
||||
String url = entity.getDownloadUrl();
|
||||
public synchronized void setProgress(AbsEntity entity) {
|
||||
String url = entity.getKey();
|
||||
int position = indexItem(url);
|
||||
if (position == -1 || position >= mData.size()) {
|
||||
return;
|
||||
@ -105,53 +132,67 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override protected void bindData(MyHolder holder, int position, final DownloadEntity item) {
|
||||
long size = item.getFileSize();
|
||||
int current = 0;
|
||||
long progress = item.getCurrentProgress();
|
||||
current = size == 0 ? 0 : (int) (progress * 100 / size);
|
||||
holder.progress.setProgress(current);
|
||||
BtClickListener listener = new BtClickListener(item);
|
||||
holder.bt.setOnClickListener(listener);
|
||||
holder.name.setText("文件名:" + item.getFileName());
|
||||
holder.url.setText("下载地址:" + item.getDownloadUrl());
|
||||
holder.path.setText("保持路径:" + item.getDownloadPath());
|
||||
@Override protected void bindData(SimpleHolder holder, int position, final AbsEntity item) {
|
||||
handleProgress(holder, item);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void handleProgress(SimpleHolder holder, final AbsEntity entity) {
|
||||
String str = "";
|
||||
int color = android.R.color.holo_green_light;
|
||||
switch (item.getState()) {
|
||||
case DownloadEntity.STATE_WAIT:
|
||||
case DownloadEntity.STATE_OTHER:
|
||||
case DownloadEntity.STATE_FAIL:
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_WAIT:
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
str = "开始";
|
||||
break;
|
||||
case DownloadEntity.STATE_STOP:
|
||||
case IEntity.STATE_STOP:
|
||||
str = "恢复";
|
||||
color = android.R.color.holo_blue_light;
|
||||
break;
|
||||
case DownloadEntity.STATE_PRE:
|
||||
case DownloadEntity.STATE_POST_PRE:
|
||||
case DownloadEntity.STATE_RUNNING:
|
||||
case IEntity.STATE_PRE:
|
||||
case IEntity.STATE_POST_PRE:
|
||||
case IEntity.STATE_RUNNING:
|
||||
str = "暂停";
|
||||
color = android.R.color.holo_red_light;
|
||||
break;
|
||||
case DownloadEntity.STATE_COMPLETE:
|
||||
case IEntity.STATE_COMPLETE:
|
||||
str = "重新开始?";
|
||||
holder.progress.setProgress(100);
|
||||
break;
|
||||
}
|
||||
long size = entity.getFileSize();
|
||||
long progress = entity.getCurrentProgress();
|
||||
int current = size == 0 ? 0 : (int) (progress * 100 / size);
|
||||
holder.bt.setText(str);
|
||||
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.cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
mData.remove(item);
|
||||
mData.remove(entity);
|
||||
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) {
|
||||
if (currentSize < 0) return "0";
|
||||
return CommonUtil.formatFileSize(currentSize);
|
||||
@ -161,49 +202,67 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
||||
return Resources.getSystem().getColor(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按钮事件
|
||||
*/
|
||||
private class BtClickListener implements View.OnClickListener {
|
||||
private DownloadEntity entity;
|
||||
private AbsEntity entity;
|
||||
|
||||
BtClickListener(DownloadEntity entity) {
|
||||
BtClickListener(AbsEntity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override public void onClick(View v) {
|
||||
switch (entity.getState()) {
|
||||
case DownloadEntity.STATE_WAIT:
|
||||
case DownloadEntity.STATE_OTHER:
|
||||
case DownloadEntity.STATE_FAIL:
|
||||
case DownloadEntity.STATE_STOP:
|
||||
case DownloadEntity.STATE_COMPLETE:
|
||||
case DownloadEntity.STATE_POST_PRE:
|
||||
case IEntity.STATE_WAIT:
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
case IEntity.STATE_STOP:
|
||||
case IEntity.STATE_COMPLETE:
|
||||
case IEntity.STATE_PRE:
|
||||
case IEntity.STATE_POST_PRE:
|
||||
start(entity);
|
||||
break;
|
||||
case DownloadEntity.STATE_RUNNING:
|
||||
case IEntity.STATE_RUNNING:
|
||||
stop(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void start(DownloadEntity entity) {
|
||||
Aria.download(getContext()).load(entity).start();
|
||||
private void start(AbsEntity entity) {
|
||||
if (isSimpleDownload(entity)) {
|
||||
Aria.download(getContext()).load((DownloadEntity) entity).start();
|
||||
} else {
|
||||
Aria.download(getContext()).load((DownloadGroupEntity) entity).start();
|
||||
}
|
||||
}
|
||||
|
||||
private void stop(DownloadEntity entity) {
|
||||
Aria.download(getContext()).load(entity).pause();
|
||||
private void stop(AbsEntity entity) {
|
||||
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.bt) Button bt;
|
||||
@Bind(R.id.speed) TextView speed;
|
||||
@Bind(R.id.fileSize) TextView fileSize;
|
||||
@Bind(R.id.del) TextView cancel;
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
|
||||
Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show();
|
||||
Aria.download(getContext())
|
||||
.load(item.downloadUrl)
|
||||
.setDownloadName(item.name)
|
||||
.setFileName(item.name)
|
||||
.setDownloadPath(item.downloadPath)
|
||||
.start();
|
||||
}
|
||||
|
@ -23,9 +23,12 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
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.inf.AbsEntity;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
@ -39,12 +42,7 @@ import java.util.List;
|
||||
public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBinding> {
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
private DownloadAdapter mAdapter;
|
||||
private List<DownloadEntity> 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"
|
||||
};
|
||||
private List<AbsEntity> mData = new ArrayList<>();
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_multi_download;
|
||||
@ -54,7 +52,7 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
setTitle("下载列表");
|
||||
List<DownloadEntity> temps = Aria.download(this).getTaskList();
|
||||
List<AbsEntity> temps = Aria.download(this).getTotleTaskList();
|
||||
if (temps != null && !temps.isEmpty()) {
|
||||
mData.addAll(temps);
|
||||
}
|
||||
@ -74,37 +72,68 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
|
||||
}
|
||||
|
||||
@Download.onPre void onPre(DownloadTask task) {
|
||||
L.d(TAG, "download onPre");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
mAdapter.updateState(task.getEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskStart void taskStart(DownloadTask task) {
|
||||
L.d(TAG, "download start");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
mAdapter.updateState(task.getEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskResume void taskResume(DownloadTask task) {
|
||||
L.d(TAG, "download resume");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
mAdapter.updateState(task.getEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskStop void taskStop(DownloadTask task) {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
mAdapter.updateState(task.getEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
mAdapter.updateState(task.getEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskFail void taskFail(DownloadTask task) {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
mAdapter.updateState(task.getEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
mAdapter.updateState(task.getEntity());
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
super.dataCallback(result, data);
|
||||
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);
|
||||
}
|
||||
}
|
18
app/src/main/res/layout/item_group_download.xml
Normal file
18
app/src/main/res/layout/item_group_download.xml
Normal file
@ -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>
|
9
app/src/main/res/layout/item_simple_download.xml
Normal file
9
app/src/main/res/layout/item_simple_download.xml
Normal file
@ -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"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
@ -75,22 +74,4 @@
|
||||
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>
|
Reference in New Issue
Block a user