修复暂停后删除任务闪退问题,添加删除记录api
This commit is contained in:
@ -7,8 +7,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 23
|
||||
versionCode 101
|
||||
versionName "3.0.2"
|
||||
versionCode 102
|
||||
versionName "3.0.3"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@ -35,12 +35,17 @@ public abstract class AbsCmd<T extends ITaskEntity> implements ICmd {
|
||||
T mEntity;
|
||||
String TAG;
|
||||
String mTargetName;
|
||||
/**
|
||||
* 能否执行命令
|
||||
*/
|
||||
boolean cancelExe = true;
|
||||
|
||||
/**
|
||||
* @param targetName 产生任务的对象名
|
||||
*/
|
||||
AbsCmd(String targetName, T entity) {
|
||||
CheckUtil.checkCmdEntity(entity);
|
||||
cancelExe = CheckUtil.checkCmdEntity(entity,
|
||||
!(this instanceof CancelCmd) || !(this instanceof StopCmd));
|
||||
mTargetName = targetName;
|
||||
mEntity = entity;
|
||||
TAG = CommonUtil.getClassName(this);
|
||||
|
@ -31,6 +31,7 @@ class AddCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
mQueue.createTask(mTargetName, mEntity);
|
||||
@ -39,20 +40,4 @@ class AddCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
}
|
||||
|
||||
//AddCmd(DownloadTaskEntity entity) {
|
||||
// super(entity);
|
||||
//}
|
||||
//
|
||||
//AddCmd(String targetName, DownloadTaskEntity entity) {
|
||||
// super(targetName, entity);
|
||||
//}
|
||||
//
|
||||
//@Override public void executeCmd() {
|
||||
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
|
||||
// if (task == null) {
|
||||
// mQueue.createTask(mTargetName, mEntity);
|
||||
// } else {
|
||||
// Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
|
||||
// }
|
||||
//}
|
||||
}
|
@ -29,6 +29,7 @@ class CancelCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
@ -40,25 +41,4 @@ class CancelCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
mQueue.cancelTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
//CancelCmd(DownloadTaskEntity entity) {
|
||||
// super(entity);
|
||||
//}
|
||||
//
|
||||
//CancelCmd(String targetName, DownloadTaskEntity entity) {
|
||||
// super(targetName, entity);
|
||||
//}
|
||||
//
|
||||
//@Override public void executeCmd() {
|
||||
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
|
||||
// if (task == null) {
|
||||
// task = mQueue.createTask(mTargetName, mEntity);
|
||||
// }
|
||||
// if (task != null) {
|
||||
// if (mTargetName != null) {
|
||||
// task.setTargetName(mTargetName);
|
||||
// }
|
||||
// mQueue.cancelTask(task);
|
||||
// }
|
||||
//}
|
||||
}
|
@ -31,6 +31,7 @@ class StartCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
@ -41,22 +42,4 @@ class StartCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
}
|
||||
|
||||
//StartCmd(DownloadTaskEntity entity) {
|
||||
// super(entity);
|
||||
//}
|
||||
//
|
||||
//StartCmd(String targetName, DownloadTaskEntity entity) {
|
||||
// super(targetName, entity);
|
||||
//}
|
||||
//
|
||||
//@Override public void executeCmd() {
|
||||
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
|
||||
// if (task == null) {
|
||||
// task = mQueue.createTask(mTargetName, mEntity);
|
||||
// }
|
||||
// if (task != null) {
|
||||
// task.setTargetName(mTargetName);
|
||||
// mQueue.startTask(task);
|
||||
// }
|
||||
//}
|
||||
}
|
@ -33,6 +33,7 @@ class StopCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
if (mEntity.getEntity().getState() == IEntity.STATE_RUNNING) {
|
||||
@ -48,29 +49,4 @@ class StopCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
mQueue.stopTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
//StopCmd(DownloadTaskEntity entity) {
|
||||
// super(entity);
|
||||
//}
|
||||
//
|
||||
//StopCmd(String targetName, DownloadTaskEntity entity) {
|
||||
// super(targetName, entity);
|
||||
//}
|
||||
//
|
||||
//@Override public void executeCmd() {
|
||||
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
|
||||
// if (task == null) {
|
||||
// if (mEntity.downloadEntity.getState() == DownloadEntity.STATE_RUNNING) {
|
||||
// task = mQueue.createTask(mTargetName, mEntity);
|
||||
// mQueue.stopTask(task);
|
||||
// } else {
|
||||
// Log.w(TAG, "停止命令执行失败,【调度器中没有该任务】");
|
||||
// }
|
||||
// } else {
|
||||
// if (!TextUtils.isEmpty(mTargetName)) {
|
||||
// task.setTargetName(mTargetName);
|
||||
// }
|
||||
// mQueue.stopTask(task);
|
||||
// }
|
||||
//}
|
||||
}
|
@ -137,6 +137,10 @@ public class DownloadTask implements ITask {
|
||||
this.mTargetName = targetName;
|
||||
}
|
||||
|
||||
@Override public void removeRecord() {
|
||||
mEntity.deleteData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止下载
|
||||
*/
|
||||
@ -161,10 +165,7 @@ public class DownloadTask implements ITask {
|
||||
* 取消下载
|
||||
*/
|
||||
@Override public void cancel() {
|
||||
if (mUtil.isDownloading()) {
|
||||
mUtil.cancelDownload();
|
||||
} else {
|
||||
// 如果任务不是下载状态
|
||||
if (!mEntity.isDownloadComplete()) {
|
||||
mUtil.cancelDownload();
|
||||
mUtil.delConfigFile();
|
||||
mUtil.delTempFile();
|
||||
@ -177,6 +178,22 @@ public class DownloadTask implements ITask {
|
||||
intent.putExtra(Aria.ENTITY, mEntity);
|
||||
mContext.sendBroadcast(intent);
|
||||
}
|
||||
//if (mEntity.isDownloadComplete()) {
|
||||
// //mUtil.cancelDownload();
|
||||
//} else {
|
||||
// // 如果任务不是下载状态
|
||||
// mUtil.cancelDownload();
|
||||
// mUtil.delConfigFile();
|
||||
// mUtil.delTempFile();
|
||||
// mEntity.deleteData();
|
||||
// if (mOutHandler != null) {
|
||||
// mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget();
|
||||
// }
|
||||
// //发送取消下载的广播
|
||||
// Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL);
|
||||
// intent.putExtra(Aria.ENTITY, mEntity);
|
||||
// mContext.sendBroadcast(intent);
|
||||
//}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@ -186,7 +203,8 @@ public class DownloadTask implements ITask {
|
||||
String targetName;
|
||||
|
||||
public Builder(String targetName, DownloadTaskEntity taskEntity) {
|
||||
CheckUtil.checkDownloadTaskEntity(taskEntity.downloadEntity);
|
||||
//CheckUtil.checkDownloadTaskEntity(taskEntity.downloadEntity);
|
||||
CheckUtil.checkTaskEntity(taskEntity);
|
||||
this.targetName = targetName;
|
||||
this.taskEntity = taskEntity;
|
||||
}
|
||||
|
@ -65,7 +65,8 @@ public class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
|
||||
DownloadUtil(Context context, DownloadTaskEntity entity, IDownloadListener downloadListener,
|
||||
int threadNum) {
|
||||
CheckUtil.checkDownloadTaskEntity(entity.downloadEntity);
|
||||
//CheckUtil.checkDownloadTaskEntity(entity.downloadEntity);
|
||||
CheckUtil.checkTaskEntity(entity);
|
||||
mDownloadEntity = entity.downloadEntity;
|
||||
mContext = context.getApplicationContext();
|
||||
mDownloadTaskEntity = entity;
|
||||
|
@ -51,6 +51,17 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
|
||||
taskEntity.redirectUrlKey = redirectUrlKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
*/
|
||||
public void removeRecord() {
|
||||
if (entity instanceof DownloadEntity) {
|
||||
((DownloadEntity) entity).deleteData();
|
||||
} else if (entity instanceof UploadEntity) {
|
||||
((UploadEntity) entity).deleteData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务文件大小
|
||||
*
|
||||
|
@ -51,4 +51,6 @@ public interface ITask {
|
||||
public long getCurrentProgress();
|
||||
|
||||
public void setTargetName(String targetName);
|
||||
|
||||
public void removeRecord();
|
||||
}
|
||||
|
@ -55,6 +55,10 @@ public class UploadTask implements ITask {
|
||||
mTargetName = targetName;
|
||||
}
|
||||
|
||||
@Override public void removeRecord() {
|
||||
mUploadEntity.deleteData();
|
||||
}
|
||||
|
||||
@Override public String getKey() {
|
||||
return mUploadEntity.getFilePath();
|
||||
}
|
||||
@ -87,9 +91,8 @@ public class UploadTask implements ITask {
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
if (mUtil.isRunning()) {
|
||||
mUtil.cancel();
|
||||
} else {
|
||||
|
||||
if (!mUploadEntity.isComplete()) {
|
||||
// 如果任务不是下载状态
|
||||
mUtil.cancel();
|
||||
mUploadEntity.deleteData();
|
||||
@ -101,6 +104,21 @@ public class UploadTask implements ITask {
|
||||
intent.putExtra(Aria.ENTITY, mUploadEntity);
|
||||
AriaManager.APP.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
//if (mUtil.isRunning()) {
|
||||
// mUtil.cancel();
|
||||
//} else {
|
||||
// // 如果任务不是下载状态
|
||||
// mUtil.cancel();
|
||||
// mUploadEntity.deleteData();
|
||||
// if (mOutHandler != null) {
|
||||
// mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget();
|
||||
// }
|
||||
// //发送取消下载的广播
|
||||
// Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), Aria.ACTION_CANCEL);
|
||||
// intent.putExtra(Aria.ENTITY, mUploadEntity);
|
||||
// AriaManager.APP.sendBroadcast(intent);
|
||||
//}
|
||||
}
|
||||
|
||||
public String getTargetName() {
|
||||
|
@ -50,7 +50,7 @@ final class UploadUtil implements Runnable {
|
||||
|
||||
UploadUtil(UploadTaskEntity taskEntity, IUploadListener listener) {
|
||||
mTaskEntity = taskEntity;
|
||||
CheckUtil.checkUploadTaskEntity(taskEntity.uploadEntity);
|
||||
CheckUtil.checkTaskEntity(taskEntity);
|
||||
mUploadEntity = taskEntity.uploadEntity;
|
||||
if (listener == null) {
|
||||
throw new IllegalArgumentException("上传监听不能为空");
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.arialyy.aria.util;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.ITaskEntity;
|
||||
@ -95,31 +96,39 @@ public class CheckUtil {
|
||||
|
||||
/**
|
||||
* 检查命令实体
|
||||
*
|
||||
* @param checkPath 删除命令不需要检查下载路径和文件名
|
||||
*/
|
||||
public static void checkCmdEntity(ITaskEntity entity) {
|
||||
public static boolean checkCmdEntity(ITaskEntity entity, boolean checkPath) {
|
||||
boolean b = false;
|
||||
if (entity instanceof DownloadTaskEntity) {
|
||||
DownloadEntity entity1 = ((DownloadTaskEntity) entity).downloadEntity;
|
||||
if (entity1 == null) {
|
||||
throw new NullPointerException("下载实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity1.getDownloadUrl())) {
|
||||
throw new IllegalArgumentException("下载链接不能为空");
|
||||
} else if (TextUtils.isEmpty(entity1.getDownloadPath())) {
|
||||
throw new IllegalArgumentException("保存路径不能为空");
|
||||
Log.e(TAG, "下载实体不能为空");
|
||||
} else if (checkPath && TextUtils.isEmpty(entity1.getDownloadUrl())) {
|
||||
Log.e(TAG, "下载链接不能为空");
|
||||
} else if (checkPath && TextUtils.isEmpty(entity1.getDownloadPath())) {
|
||||
Log.e(TAG, "保存路径不能为空");
|
||||
} else {
|
||||
b = true;
|
||||
}
|
||||
} else if (entity instanceof UploadTaskEntity) {
|
||||
UploadEntity entity1 = ((UploadTaskEntity) entity).uploadEntity;
|
||||
if (entity1 == null) {
|
||||
throw new NullPointerException("上传实体不能为空");
|
||||
Log.e(TAG, "上传实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity1.getFilePath())) {
|
||||
throw new IllegalArgumentException("上传文件路径不能为空");
|
||||
Log.e(TAG, "上传文件路径不能为空");
|
||||
} else {
|
||||
b = true;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查上传实体是否合法
|
||||
*/
|
||||
public static void checkUploadTaskEntity(UploadEntity entity) {
|
||||
private static void checkUploadTaskEntity(UploadEntity entity) {
|
||||
if (entity == null) {
|
||||
throw new NullPointerException("上传实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity.getFilePath())) {
|
||||
@ -135,7 +144,7 @@ public class CheckUtil {
|
||||
*
|
||||
* @param entity 下载实体
|
||||
*/
|
||||
public static void checkDownloadTaskEntity(DownloadEntity entity) {
|
||||
private static void checkDownloadTaskEntity(DownloadEntity entity) {
|
||||
if (entity == null) {
|
||||
throw new NullPointerException("下载实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity.getDownloadUrl())) {
|
||||
|
@ -20,7 +20,7 @@ Aria怎样使用?
|
||||
## 下载
|
||||
[](https://bintray.com/arialyy/maven/Aria/_latestVersion)</br>
|
||||
```java
|
||||
compile 'com.arialyy.aria:Aria:3.0.2'
|
||||
compile 'com.arialyy.aria:Aria:3.0.3'
|
||||
```
|
||||
|
||||
## 示例
|
||||
@ -143,6 +143,7 @@ compile 'com.arialyy.aria:Aria:3.0.2'
|
||||
***
|
||||
|
||||
## 开发日志
|
||||
+ v_3.0.3 修复暂停后删除任务,闪退问题,添加删除记录的api
|
||||
+ v_3.0.2 支持30x重定向链接下载
|
||||
+ v_3.0.0 添加上传任务支持,修复一些已发现的bug
|
||||
+ v_2.4.4 修复不支持断点的下载链接拿不到文件大小的问题
|
||||
|
@ -55,10 +55,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
private static final String DOWNLOAD_URL =
|
||||
//"http://kotlinlang.org/docs/kotlin-docs.pdf";
|
||||
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
|
||||
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
//不支持断点的链接
|
||||
//"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
|
||||
"http://172.18.104.50:8080/download/_302turn";
|
||||
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
//"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk";
|
||||
//不支持断点的链接
|
||||
//"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
|
||||
//"http://172.18.104.50:8080/download/_302turn";
|
||||
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
|
||||
@Bind(R.id.start) Button mStart;
|
||||
@Bind(R.id.stop) Button mStop;
|
||||
@ -233,6 +234,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
private void stop() {
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
|
Reference in New Issue
Block a user