任务最高优先级开发
This commit is contained in:
@ -22,7 +22,7 @@ import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/5/22.
|
||||
* Created by lyy on 2017/5/22.
|
||||
* 读取配置文件
|
||||
*/
|
||||
public class ConfigHelper extends DefaultHandler {
|
||||
|
@ -25,7 +25,7 @@ import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2016/12/8.
|
||||
* Created by lyy on 2016/12/8.
|
||||
* 信息配置
|
||||
*/
|
||||
class Configuration {
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.arialyy.aria.core;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/23.
|
||||
* Created by lyy on 2017/1/23.
|
||||
* url请求方式,目前支持GET、POST
|
||||
*/
|
||||
public enum RequestEnum {
|
||||
|
@ -24,7 +24,7 @@ import com.arialyy.aria.util.CommonUtil;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/7.
|
||||
* Created by lyy on 2017/2/7.
|
||||
* 为组件添加生命周期
|
||||
*/
|
||||
final class WidgetLiftManager {
|
||||
|
@ -38,13 +38,13 @@ public abstract class AbsCmd<T extends ITaskEntity> implements ICmd {
|
||||
/**
|
||||
* 能否执行命令
|
||||
*/
|
||||
boolean cancelExe = true;
|
||||
boolean canExeCmd = true;
|
||||
|
||||
/**
|
||||
* @param targetName 产生任务的对象名
|
||||
*/
|
||||
AbsCmd(String targetName, T entity) {
|
||||
cancelExe = CheckUtil.checkCmdEntity(entity,
|
||||
canExeCmd = CheckUtil.checkCmdEntity(entity,
|
||||
!(this instanceof CancelCmd) || !(this instanceof StopCmd));
|
||||
mTargetName = targetName;
|
||||
mEntity = entity;
|
||||
|
@ -31,7 +31,7 @@ class AddCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
if (!canExeCmd) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
mQueue.createTask(mTargetName, mEntity);
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.arialyy.aria.core.command;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.core.inf.ITaskEntity;
|
||||
|
||||
@ -29,13 +30,13 @@ class CancelCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
if (!canExeCmd) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
}
|
||||
if (task != null) {
|
||||
if (mTargetName != null) {
|
||||
if (!TextUtils.isEmpty(mTargetName)) {
|
||||
task.setTargetName(mTargetName);
|
||||
}
|
||||
mQueue.cancelTask(task);
|
||||
|
@ -43,6 +43,11 @@ public class CmdFactory {
|
||||
* 停止任务
|
||||
*/
|
||||
public static final int TASK_STOP = 0x125;
|
||||
/**
|
||||
* 设置任务为最高优先级
|
||||
*/
|
||||
public static final int TASK_HIGHEST_PRIORITY = 0x128;
|
||||
|
||||
public static final int TASK_SINGLE = 0x126;
|
||||
|
||||
private static final Object LOCK = new Object();
|
||||
@ -65,59 +70,25 @@ public class CmdFactory {
|
||||
* @param target 创建任务的对象
|
||||
* @param entity 下载实体
|
||||
* @param type 命令类型{@link #TASK_CREATE}、{@link #TASK_START}、{@link #TASK_CANCEL}、{@link
|
||||
* #TASK_STOP}
|
||||
* #TASK_STOP}、{@link #TASK_HIGHEST_PRIORITY}
|
||||
*/
|
||||
public <T extends ITaskEntity> AbsCmd createCmd(String target, T entity, int type) {
|
||||
switch (type) {
|
||||
case TASK_CREATE:
|
||||
return createAddCmd(target, entity);
|
||||
return new AddCmd(target, entity);
|
||||
case TASK_RESUME:
|
||||
case TASK_START:
|
||||
return createStartCmd(target, entity);
|
||||
return new StartCmd(target, entity);
|
||||
case TASK_CANCEL:
|
||||
return createCancelCmd(target, entity);
|
||||
return new CancelCmd(target, entity);
|
||||
case TASK_STOP:
|
||||
return createStopCmd(target, entity);
|
||||
return new StopCmd(target, entity);
|
||||
case TASK_HIGHEST_PRIORITY:
|
||||
return new HighestPriorityCmd(target, entity);
|
||||
case TASK_SINGLE:
|
||||
//return new SingleCmd(target, entity);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建停止命令
|
||||
*
|
||||
* @return {@link StopCmd}
|
||||
*/
|
||||
private <T extends ITaskEntity> StopCmd createStopCmd(String target, T entity) {
|
||||
return new StopCmd(target, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建下载任务命令
|
||||
*
|
||||
* @return {@link AddCmd}
|
||||
*/
|
||||
private <T extends ITaskEntity> AddCmd createAddCmd(String target, T entity) {
|
||||
return new AddCmd(target, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建启动下载命令
|
||||
*
|
||||
* @return {@link StartCmd}
|
||||
*/
|
||||
private <T extends ITaskEntity> StartCmd createStartCmd(String target, T entity) {
|
||||
return new StartCmd(target, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建启动下载命令
|
||||
*
|
||||
* @return {@link StartCmd}
|
||||
*/
|
||||
private <T extends ITaskEntity> CancelCmd createCancelCmd(String target, T entity) {
|
||||
return new CancelCmd(target, entity);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core.command;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.core.inf.ITaskEntity;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/6/2.
|
||||
* 最高优先级命令,最高优先级命令有以下属性
|
||||
* 1、在下载队列中,有且只有一个最高优先级任务
|
||||
* 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成
|
||||
* 3、任务调度器不会暂停最高优先级任务
|
||||
* 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效
|
||||
* 5、如果下载队列中已经满了,则会停止队尾的任务
|
||||
* 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务
|
||||
*/
|
||||
final class HighestPriorityCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
/**
|
||||
* @param targetName 产生任务的对象名
|
||||
*/
|
||||
HighestPriorityCmd(String targetName, T entity) {
|
||||
super(targetName, entity);
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!canExeCmd) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
}
|
||||
if (task != null) {
|
||||
if (!TextUtils.isEmpty(mTargetName)) {
|
||||
task.setTargetName(mTargetName);
|
||||
}
|
||||
task.setHighestPriority(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
|
||||
package com.arialyy.aria.core.command;
|
||||
|
||||
import android.util.Log;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.core.inf.ITaskEntity;
|
||||
|
||||
@ -31,15 +31,16 @@ class StartCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
if (!canExeCmd) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
}
|
||||
if (task != null) {
|
||||
task.setTargetName(mTargetName);
|
||||
if (!TextUtils.isEmpty(mTargetName)) {
|
||||
task.setTargetName(mTargetName);
|
||||
}
|
||||
mQueue.startTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -33,7 +33,7 @@ class StopCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
if (!canExeCmd) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
if (mEntity.getEntity().getState() == IEntity.STATE_RUNNING) {
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
/**
|
||||
* @author lyy
|
||||
*/
|
||||
class DownloadListener implements IDownloadListener {
|
||||
|
||||
@Override public void onResume(long resumeLocation) {
|
||||
|
@ -45,6 +45,19 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
|
||||
super.resume();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将任务设置为最高优先级任务,最高优先级任务有以下特点:
|
||||
* 1、在下载队列中,有且只有一个最高优先级任务
|
||||
* 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成
|
||||
* 3、任务调度器不会暂停最高优先级任务
|
||||
* 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效
|
||||
* 5、如果下载队列中已经满了,则会停止队尾的任务
|
||||
* 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务
|
||||
*/
|
||||
@Override public void setHighestPriority() {
|
||||
super.setHighestPriority();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重定向后,新url的key,默认为location
|
||||
*/
|
||||
|
@ -44,6 +44,7 @@ public class DownloadTask implements ITask {
|
||||
private Handler mOutHandler;
|
||||
private IDownloadUtil mUtil;
|
||||
private Context mContext;
|
||||
private boolean isHeighestTask = false;
|
||||
|
||||
private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) {
|
||||
mEntity = taskEntity.downloadEntity;
|
||||
@ -142,6 +143,14 @@ public class DownloadTask implements ITask {
|
||||
return mEntity.getDownloadUrl();
|
||||
}
|
||||
|
||||
@Override public void setHighestPriority(boolean isHighestPriority) {
|
||||
isHeighestTask = isHighestPriority;
|
||||
}
|
||||
|
||||
@Override public boolean isHighestPriorityTask() {
|
||||
return isHeighestTask;
|
||||
}
|
||||
|
||||
@Override public String getKey() {
|
||||
return getDownloadUrl();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.inf.ITaskEntity;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/23.
|
||||
* Created by lyy on 2017/1/23.
|
||||
* 下载任务实体
|
||||
*/
|
||||
public class DownloadTaskEntity extends ITaskEntity {
|
||||
|
@ -430,7 +430,6 @@ class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
private void addSingleTask(int i, long startL, long endL, long fileLength) {
|
||||
ConfigEntity entity = new ConfigEntity();
|
||||
entity.FILE_SIZE = fileLength;
|
||||
//entity.DOWNLOAD_URL = mDownloadEntity.getDownloadUrl();
|
||||
entity.DOWNLOAD_URL = mDownloadEntity.isRedirect() ? mDownloadEntity.getRedirectUrl()
|
||||
: mDownloadEntity.getDownloadUrl();
|
||||
entity.TEMP_FILE = mDownloadFile;
|
||||
|
@ -17,7 +17,7 @@
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
/**
|
||||
* Created by “AriaLyy@outlook.com” on 2016/10/31.
|
||||
* Created by lyy on 2016/10/31.
|
||||
* 抽象的下载接口
|
||||
*/
|
||||
interface IDownloadUtil {
|
||||
|
@ -244,7 +244,7 @@ final class SingleThreadTask implements Runnable {
|
||||
* 将记录写入到配置文件
|
||||
*/
|
||||
private void writeConfig(String key, long record) throws IOException {
|
||||
if (record != -1 && record != 0) {
|
||||
if (record > 0) {
|
||||
File configFile = new File(mConfigFPath);
|
||||
Properties pro = CommonUtil.loadConfig(configFile);
|
||||
pro.setProperty(key, String.valueOf(record));
|
||||
|
@ -33,7 +33,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/28.
|
||||
* Created by lyy on 2017/2/28.
|
||||
*/
|
||||
public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity> {
|
||||
protected ENTITY entity;
|
||||
@ -41,10 +41,18 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
|
||||
protected String targetName;
|
||||
|
||||
/**
|
||||
* 将该任务优先级提到最高
|
||||
* 将任务设置为最高优先级任务,最高优先级任务有以下特点:
|
||||
* 1、在下载队列中,有且只有一个最高优先级任务
|
||||
* 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成
|
||||
* 3、任务调度器不会暂停最高优先级任务
|
||||
* 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效
|
||||
* 5、如果下载队列中已经满了,则会停止队尾的任务
|
||||
* 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务
|
||||
*/
|
||||
protected void setToFirst(){
|
||||
|
||||
protected void setHighestPriority() {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_HIGHEST_PRIORITY))
|
||||
.exe();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.arialyy.aria.core.inf;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/9.
|
||||
* Created by lyy on 2017/2/9.
|
||||
*/
|
||||
|
||||
public interface ICmd {
|
||||
|
@ -18,7 +18,7 @@ package com.arialyy.aria.core.inf;
|
||||
import com.arialyy.aria.orm.Ignore;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/23.
|
||||
* Created by lyy on 2017/2/23.
|
||||
*/
|
||||
|
||||
public interface IEntity {
|
||||
|
@ -18,7 +18,7 @@ package com.arialyy.aria.core.inf;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/6.
|
||||
* Created by lyy on 2017/2/6.
|
||||
*/
|
||||
public interface IReceiver<ENTITY extends IEntity> {
|
||||
/**
|
||||
|
@ -16,11 +16,23 @@
|
||||
package com.arialyy.aria.core.inf;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/13.
|
||||
* Created by lyy on 2017/2/13.
|
||||
*/
|
||||
|
||||
public interface ITask {
|
||||
|
||||
/**
|
||||
* 设置任务为最高优先级任务,在下载队列中,有且只有一个最高优先级任务
|
||||
*/
|
||||
public void setHighestPriority(boolean isHighestPriority);
|
||||
|
||||
/**
|
||||
* 该任务是否是最高优先级任务
|
||||
*
|
||||
* @return {@code true} 任务为最高优先级任务
|
||||
*/
|
||||
public boolean isHighestPriorityTask();
|
||||
|
||||
/**
|
||||
* 唯一标识符,DownloadTask 为下载地址,UploadTask 为文件路径
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/23.
|
||||
* Created by lyy on 2017/2/23.
|
||||
*/
|
||||
|
||||
public abstract class ITaskEntity {
|
||||
|
@ -24,7 +24,7 @@ import com.arialyy.aria.core.queue.pool.CachePool;
|
||||
import com.arialyy.aria.core.queue.pool.ExecutePool;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/23.
|
||||
* Created by lyy on 2017/2/23.
|
||||
* 任务队列
|
||||
*/
|
||||
abstract class AbsTaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity, ENTITY extends IEntity>
|
||||
@ -65,6 +65,10 @@ abstract class AbsTaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity,
|
||||
return mExecutePool.size();
|
||||
}
|
||||
|
||||
@Override public void setTaskHighestPriority(TASK task) {
|
||||
|
||||
}
|
||||
|
||||
@Override public TASK getTask(String url) {
|
||||
TASK task = mExecutePool.getTask(url);
|
||||
if (task == null) {
|
||||
|
@ -25,6 +25,8 @@ import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.queue.pool.ExecutePool;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/8/17.
|
||||
@ -49,16 +51,40 @@ public class DownloadTaskQueue
|
||||
mExecutePool = new ExecutePool<>(true);
|
||||
}
|
||||
|
||||
@Override public void setTaskHighestPriority(DownloadTask task) {
|
||||
int maxSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
|
||||
int currentSize = mExecutePool.size();
|
||||
if (currentSize == 0 || currentSize < maxSize) {
|
||||
startTask(task);
|
||||
} else {
|
||||
Set<DownloadTask> tempTasks = new LinkedHashSet<>();
|
||||
for (int i = 0; i < maxSize; i++) {
|
||||
DownloadTask oldTsk = mExecutePool.pollTask();
|
||||
if (oldTsk != null && oldTsk.isRunning()) {
|
||||
oldTsk.stop();
|
||||
tempTasks.add(oldTsk);
|
||||
}
|
||||
}
|
||||
startTask(task);
|
||||
int i = 0, len = tempTasks.size() - 1;
|
||||
for (DownloadTask oldTask : tempTasks) {
|
||||
if (i < len) {
|
||||
startTask(oldTask);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void setMaxTaskNum(int downloadNum) {
|
||||
//原始长度
|
||||
int size = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
|
||||
int diff = downloadNum - size;
|
||||
if (size == downloadNum) {
|
||||
int oldMaxSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
|
||||
int diff = downloadNum - oldMaxSize;
|
||||
if (oldMaxSize == downloadNum) {
|
||||
Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");
|
||||
return;
|
||||
}
|
||||
//设置的任务数小于配置任务数
|
||||
if (diff <= -1 && mExecutePool.size() >= size) {
|
||||
if (diff <= -1 && mExecutePool.size() >= oldMaxSize) {
|
||||
for (int i = 0, len = Math.abs(diff); i < len; i++) {
|
||||
DownloadTask eTask = mExecutePool.pollTask();
|
||||
if (eTask != null) {
|
||||
@ -103,5 +129,4 @@ public class DownloadTaskQueue
|
||||
Log.d(TAG, "从缓存池删除任务,删除" + (mCachePool.removeTask(task) ? "成功" : "失败"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -32,6 +32,12 @@ import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
*/
|
||||
public interface ITaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity, ENTITY extends IEntity> {
|
||||
|
||||
/**
|
||||
* 设置任务为最高优先级任务
|
||||
* @param task {@link DownloadTask}、{@link UploadTask}
|
||||
*/
|
||||
void setTaskHighestPriority(TASK task);
|
||||
|
||||
/**
|
||||
* 开始任务
|
||||
*
|
||||
|
@ -25,7 +25,7 @@ import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/27.
|
||||
* Created by lyy on 2017/2/27.
|
||||
* 上传任务队列
|
||||
*/
|
||||
public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity, UploadEntity> {
|
||||
|
@ -115,6 +115,9 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
|
||||
Log.e(TAG, "移除任务失败");
|
||||
return false;
|
||||
}
|
||||
if (oldTask.isHighestPriorityTask()) {
|
||||
return false;
|
||||
}
|
||||
oldTask.stop();
|
||||
String key = CommonUtil.keyToHashKey(oldTask.getKey());
|
||||
mExecuteArray.remove(key);
|
||||
|
@ -18,7 +18,7 @@ package com.arialyy.aria.core.scheduler;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/4/5.
|
||||
* Created by lyy on 2017/4/5.
|
||||
*/
|
||||
public interface IDownloadSchedulerListener<TASK extends ITask> extends ISchedulerListener<TASK> {
|
||||
|
||||
|
@ -20,7 +20,7 @@ import android.os.Handler;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
|
||||
/**
|
||||
* Created by “AriaLyy@outlook.com” on 2016/11/2.
|
||||
* Created by lyy on 2016/11/2.
|
||||
* 调度器功能接口
|
||||
*/
|
||||
public interface ISchedulers<Task extends ITask> extends Handler.Callback {
|
||||
|
@ -29,7 +29,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/27.
|
||||
* Created by lyy on 2017/2/27.
|
||||
* 上传任务调度器
|
||||
*/
|
||||
public class UploadSchedulers implements ISchedulers<UploadTask> {
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.arialyy.aria.core.upload;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/9.
|
||||
* Created by lyy on 2017/2/9.
|
||||
* 上传监听
|
||||
*/
|
||||
public interface IUploadListener {
|
||||
|
@ -22,7 +22,7 @@ import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.orm.Ignore;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/9.
|
||||
* Created by lyy on 2017/2/9.
|
||||
* 上传文件实体
|
||||
*/
|
||||
public class UploadEntity extends DbEntity implements IEntity, Parcelable {
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.arialyy.aria.core.upload;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/23.
|
||||
* Created by lyy on 2017/2/23.
|
||||
*/
|
||||
|
||||
public class UploadListener implements IUploadListener {
|
||||
|
@ -32,7 +32,7 @@ import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/6.
|
||||
* Created by lyy on 2017/2/6.
|
||||
* 上传功能接收器
|
||||
*/
|
||||
public class UploadReceiver implements IReceiver<UploadEntity> {
|
||||
|
@ -23,7 +23,7 @@ import com.arialyy.aria.orm.DbEntity;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/28.
|
||||
* Created by lyy on 2017/2/28.
|
||||
*/
|
||||
public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
|
||||
|
||||
|
@ -30,7 +30,7 @@ import com.arialyy.aria.util.CommonUtil;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/23.
|
||||
* Created by lyy on 2017/2/23.
|
||||
* 上传任务
|
||||
*/
|
||||
public class UploadTask implements ITask {
|
||||
@ -41,6 +41,7 @@ public class UploadTask implements ITask {
|
||||
|
||||
private UploadUtil mUtil;
|
||||
private UListener mListener;
|
||||
private boolean isHeighestTask = false;
|
||||
|
||||
private UploadTask(UploadTaskEntity taskEntity, Handler outHandler) {
|
||||
mOutHandler = outHandler;
|
||||
@ -57,6 +58,14 @@ public class UploadTask implements ITask {
|
||||
mUploadEntity.deleteData();
|
||||
}
|
||||
|
||||
@Override public void setHighestPriority(boolean isHighestPriority) {
|
||||
isHeighestTask = isHighestPriority;
|
||||
}
|
||||
|
||||
@Override public boolean isHighestPriorityTask() {
|
||||
return isHeighestTask;
|
||||
}
|
||||
|
||||
@Override public String getKey() {
|
||||
return mUploadEntity.getFilePath();
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/9.
|
||||
* Created by lyy on 2017/2/9.
|
||||
* 上传任务实体
|
||||
*/
|
||||
public class UploadTaskEntity extends ITaskEntity {
|
||||
|
@ -32,7 +32,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/9.
|
||||
* Created by lyy on 2017/2/9.
|
||||
* 上传工具
|
||||
*/
|
||||
final class UploadUtil implements Runnable {
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.arialyy.aria.exception;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/18.
|
||||
* Created by lyy on 2017/1/18.
|
||||
* Aria 文件异常
|
||||
*/
|
||||
public class FileException extends NullPointerException {
|
||||
|
@ -22,7 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/4/6.
|
||||
* Created by lyy on 2017/4/6.
|
||||
* 数据库配置信息
|
||||
*/
|
||||
public class DBConfig {
|
||||
|
@ -27,7 +27,7 @@ import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by AriaLyy on 2015/2/11.
|
||||
* Created by lyy on 2015/2/11.
|
||||
* 数据库操作工具
|
||||
*/
|
||||
public class DbUtil {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package com.arialyy.aria.util;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/11.
|
||||
* Created by lyy on 2017/1/11.
|
||||
*/
|
||||
|
||||
public class CAConfiguration {
|
||||
|
@ -97,17 +97,18 @@ public class CheckUtil {
|
||||
/**
|
||||
* 检查命令实体
|
||||
*
|
||||
* @param checkPath 删除命令不需要检查下载路径和文件名
|
||||
* @param checkType 删除命令和停止命令不需要检查下载链接和保存路径
|
||||
* @return {@code false}实体无效
|
||||
*/
|
||||
public static boolean checkCmdEntity(ITaskEntity entity, boolean checkPath) {
|
||||
public static boolean checkCmdEntity(ITaskEntity entity, boolean checkType) {
|
||||
boolean b = false;
|
||||
if (entity instanceof DownloadTaskEntity) {
|
||||
DownloadEntity entity1 = ((DownloadTaskEntity) entity).downloadEntity;
|
||||
if (entity1 == null) {
|
||||
Log.e(TAG, "下载实体不能为空");
|
||||
} else if (checkPath && TextUtils.isEmpty(entity1.getDownloadUrl())) {
|
||||
} else if (checkType && TextUtils.isEmpty(entity1.getDownloadUrl())) {
|
||||
Log.e(TAG, "下载链接不能为空");
|
||||
} else if (checkPath && TextUtils.isEmpty(entity1.getDownloadPath())) {
|
||||
} else if (checkType && TextUtils.isEmpty(entity1.getDownloadPath())) {
|
||||
Log.e(TAG, "保存路径不能为空");
|
||||
} else {
|
||||
b = true;
|
||||
|
@ -31,7 +31,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/3/21.
|
||||
* Created by lyy on 2017/3/21.
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
|
@ -23,7 +23,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by “AriaLyy@outlook.com” on 2015/7/30.
|
||||
* Created by lyy on 2015/7/30.
|
||||
* 反射工具类
|
||||
*/
|
||||
public class ReflectionUtil {
|
||||
|
@ -38,7 +38,7 @@ import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/11.
|
||||
* Created by lyy on 2017/1/11.
|
||||
* SSL证书工具
|
||||
*/
|
||||
public class SSLContextUtil {
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.arialyy.aria.util;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/3/6.
|
||||
* Created by lyy on 2017/3/6.
|
||||
*/
|
||||
public enum Speed {
|
||||
/**
|
||||
|
@ -30,10 +30,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/3/21.
|
||||
* Created by lyy on 2017/3/21.
|
||||
* 文件选择
|
||||
*/
|
||||
public class AriaFileChangeActivity extends FragmentActivity {
|
||||
class AriaFileChangeActivity extends FragmentActivity {
|
||||
final String ROOT_PAT = Environment.getExternalStorageDirectory().getPath();
|
||||
ListView mList;
|
||||
FileChangeAdapter mAdapter;
|
||||
|
@ -29,7 +29,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/3/21.
|
||||
* Created by lyy on 2017/3/21.
|
||||
*/
|
||||
final class FileChangeAdapter extends BaseAdapter {
|
||||
|
||||
|
@ -18,10 +18,10 @@ package com.arialyy.aria.window;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/3/21.
|
||||
* Created by lyy on 2017/3/21.
|
||||
*/
|
||||
|
||||
public class FileEntity {
|
||||
class FileEntity {
|
||||
public String fileName;
|
||||
public String fileInfo;
|
||||
public int fileIcon;
|
||||
|
Reference in New Issue
Block a user