From 652b53c8372d6d20ebc1c03891de001dc85b9caf Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Thu, 6 Sep 2018 21:43:44 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug=20https://github.com/AriaLyy/Aria/iss?= =?UTF-8?q?ues/302=20fix=20bug=20https://github.com/AriaLyy/Aria/issues/28?= =?UTF-8?q?3=20fix=20bug=20https://github.com/AriaLyy/Aria/issues/305=20?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=EF=BC=8C=E5=81=9C=E6=AD=A2=E6=89=80=E6=9C=89?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=EF=BC=8C=E6=9C=AA=E5=BC=80=E5=A7=8B=E7=9A=84?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81=E5=B0=86=E5=8F=98=E4=B8=BA?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=20=E4=BC=98=E5=8C=96=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/command/normal/ResumeAllCmd.java | 4 ++ .../arialyy/aria/core/common/AbsFileer.java | 67 ++++++++++++------- .../aria/core/download/BaseDListener.java | 6 +- .../aria/core/download/DownloadGroupTask.java | 39 ++--------- .../aria/core/download/DownloadTask.java | 66 +----------------- .../core/download/downloader/Downloader.java | 5 +- .../arialyy/aria/core/inf/AbsGroupTask.java | 4 +- .../arialyy/aria/core/inf/AbsNormalTask.java | 11 +-- .../com/arialyy/aria/core/inf/AbsTask.java | 59 ++++++++++++++-- .../java/com/arialyy/aria/core/inf/ITask.java | 15 +++-- .../aria/core/inf/TaskSchedulerType.java | 22 ++++++ .../aria/core/manager/ThreadTaskManager.java | 22 +++--- .../arialyy/aria/core/queue/AbsTaskQueue.java | 11 ++- .../aria/core/queue/DownloadTaskQueue.java | 4 +- .../aria/core/scheduler/AbsSchedulers.java | 18 +++-- .../aria/core/upload/BaseUListener.java | 7 +- .../com/arialyy/aria/util/CommonUtil.java | 7 +- .../com/arialyy/compiler/EventProxyFiler.java | 31 ++++++++- DEV_LOG.md | 5 ++ app/src/main/AndroidManifest.xml | 3 +- .../simple/download/SingleTaskActivity.java | 23 ++++++- .../arialyy/aria/core/upload/UploadTask.java | 38 +---------- 22 files changed, 253 insertions(+), 214 deletions(-) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/inf/TaskSchedulerType.java diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java index 2d183fd0..cb4c0eba 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java @@ -1,5 +1,6 @@ package com.arialyy.aria.core.command.normal; +import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupEntity; @@ -62,6 +63,9 @@ final class ResumeAllCmd extends AbsNormalCmd { "isGroupChild=? AND state!=? ORDER BY stopTime DESC", "false", "1"); if (entities != null && !entities.isEmpty()) { for (DownloadEntity entity : entities) { + //if (TextUtils.isEmpty(entity.getDownloadPath())){ + // continue; + //} resumeTask(TEManager.getInstance().getTEntity(DownloadTaskEntity.class, entity.getKey())); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index 8308f6b4..b5c5aed8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -30,10 +30,8 @@ import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.DbHelper; import java.io.File; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.Timer; @@ -191,7 +189,7 @@ public abstract class AbsFileer, TASK extends AbsTask> +class BaseDListener, TASK extends AbsTask> implements IDownloadListener { private static final String TAG = "BaseDListener"; WeakReference outHandler; @@ -42,7 +43,6 @@ class BaseDListener { - private final String TAG = "DownloadGroupTask"; - private DownloadGroupListener mListener; +public class DownloadGroupTask extends AbsGroupTask { private DownloadGroupTask(DownloadGroupTaskEntity taskEntity, Handler outHandler) { mTaskEntity = taskEntity; @@ -43,48 +42,18 @@ public class DownloadGroupTask extends AbsGroupTask { mListener = new DownloadGroupListener(this, mOutHandler); switch (taskEntity.getRequestType()) { case AbsTaskEntity.D_HTTP: - mUtil = new DownloadGroupUtil(mListener, mTaskEntity); + mUtil = new DownloadGroupUtil((IDownloadGroupListener) mListener, mTaskEntity); break; case AbsTaskEntity.D_FTP_DIR: - mUtil = new FtpDirDownloadUtil(mListener, mTaskEntity); + mUtil = new FtpDirDownloadUtil((IDownloadGroupListener) mListener, mTaskEntity); break; } } - @Override public boolean isRunning() { - return mUtil.isRunning(); - } - public DownloadGroupEntity getEntity() { return mTaskEntity.getEntity(); } - @Override public void start() { - if (mUtil.isRunning()) { - ALog.d(TAG, "任务正在下载"); - } else { - mUtil.start(); - } - } - - @Override public void stop() { - super.stop(); - if (!mUtil.isRunning()) { - mListener.onStop(getCurrentProgress()); - } else { - mUtil.stop(); - } - } - - @Override public void cancel() { - super.cancel(); - if (!mUtil.isRunning()) { - mListener.onCancel(); - } else { - mUtil.cancel(); - } - } - @Override public String getTaskName() { return "任务组->" + (TextUtils.isEmpty(mTaskEntity.getEntity().getAlias()) ? mTaskEntity.getEntity().getGroupName() : mTaskEntity.getEntity().getAlias()); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index 411bb131..07d904ff 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -19,9 +19,9 @@ package com.arialyy.aria.core.download; import android.os.Handler; import android.os.Looper; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil; import com.arialyy.aria.core.inf.AbsNormalTask; +import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.ALog; import java.io.File; @@ -30,18 +30,15 @@ import java.io.File; * Created by lyy on 2016/8/11. * 下载任务类 */ -public class DownloadTask extends AbsNormalTask { +public class DownloadTask extends AbsNormalTask { public static final String TAG = "DownloadTask"; - private DownloadListener mListener; - private DownloadEntity mEntity; - private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) { mTaskEntity = taskEntity; mOutHandler = outHandler; mContext = AriaManager.APP; mListener = new DownloadListener(this, mOutHandler); - mUtil = new SimpleDownloadUtil(taskEntity, mListener); + mUtil = new SimpleDownloadUtil(taskEntity, (IDownloadListener) mListener); mEntity = taskEntity.getEntity(); } @@ -75,67 +72,10 @@ public class DownloadTask extends AbsNormalTask { return mEntity.getUrl(); } - /** - * 是否真正下载 - * - * @return {@code true} 真正下载 - */ - @Override public boolean isRunning() { - return mUtil.isRunning(); - } - public DownloadEntity getDownloadEntity() { return mEntity; } - /** - * 暂停任务,并让任务处于等待状态 - */ - @Override public void stopAndWait() { - stop(true); - } - - /** - * 开始下载 - */ - @Override public void start() { - mListener.isWait = false; - if (mUtil.isRunning()) { - ALog.d(TAG, "任务正在下载"); - } else { - mUtil.start(); - } - } - - /** - * 停止下载 - */ - @Override public void stop() { - super.stop(); - stop(false); - } - - private void stop(boolean isWait) { - mListener.isWait = isWait; - if (mUtil.isRunning()) { - mUtil.stop(); - } else { - mListener.onStop(mEntity.getCurrentProgress()); - } - } - - /** - * 取消下载 - */ - @Override public void cancel() { - super.cancel(); - if (mUtil.isRunning()) { - mUtil.cancel(); - } else { - mListener.onCancel(); - } - } - @Override public String getTaskName() { return mEntity.getFileName(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java index caa53482..0072d5c0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java @@ -58,7 +58,10 @@ class Downloader extends AbsFileer { @Override protected boolean handleNewTask() { if (!mRecord.isBlock) { - CommonUtil.createFile(mTempFile.getPath()); + if (mTempFile.exists()){ + mTempFile.delete(); + } + //CommonUtil.createFile(mTempFile.getPath()); } BufferedRandomAccessFile file = null; try { diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java index 89ba2b05..ce2e5f8c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java @@ -21,8 +21,8 @@ import com.arialyy.aria.core.download.downloader.AbsGroupUtil; * Created by AriaL on 2017/6/29. * 任务组任务抽象类 */ -public abstract class AbsGroupTask - extends AbsTask { +public abstract class AbsGroupTask + extends AbsTask { @Override public String getKey() { return mTaskEntity.getEntity().getKey(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java index 7b86e535..3fd15067 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java @@ -18,15 +18,8 @@ package com.arialyy.aria.core.inf; /** * Created by lyy on 2017/6/3. */ -public abstract class AbsNormalTask - extends AbsTask { - - /** - * 暂停任务,并让任务处于等待状态 - */ - public void stopAndWait() { - - } +public abstract class AbsNormalTask + extends AbsTask { /** * 最高优先级命令,最高优先级命令有以下属性 diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java index fbc8e7d9..b4b33053 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java @@ -18,24 +18,36 @@ package com.arialyy.aria.core.inf; import android.content.Context; import android.os.Handler; import com.arialyy.aria.core.common.IUtil; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; /** * Created by AriaL on 2017/6/29. */ -public abstract class AbsTask implements ITask { - +public abstract class AbsTask + implements ITask { /** * 是否需要重试,默认为true */ public boolean needRetry = true; protected TASK_ENTITY mTaskEntity; protected Handler mOutHandler; - protected Context mContext; boolean isHeighestTask = false; private boolean isCancel = false, isStop = false; protected IUtil mUtil; + /** + * 该任务的调度类型 + */ + @TaskSchedulerType + private int mSchedulerType = TaskSchedulerType.TYPE_DEFAULT; + protected IEventListener mListener; + protected ENTITY mEntity; + protected String TAG; + + protected AbsTask() { + TAG = CommonUtil.getClassName(this); + } public Handler getOutHandler() { return mOutHandler; @@ -127,16 +139,55 @@ public abstract class AbsTask implements ITas * * @return 如果实体不存在,则返回null,否则返回扩展字段 */ - @Override public String getExtendField() { + public String getExtendField() { return mTaskEntity.getEntity() == null ? null : mTaskEntity.getEntity().getStr(); } + @Override public void start() { + if (mUtil.isRunning()) { + ALog.d(TAG, "任务正在下载"); + } else { + mUtil.start(); + } + } + @Override public void stop() { + stop(TaskSchedulerType.TYPE_DEFAULT); + } + + @Override public void stop(@TaskSchedulerType int type) { isStop = true; + mSchedulerType = type; + if (mUtil.isRunning()) { + mUtil.stop(); + } else { + mListener.onStop(mEntity.getCurrentProgress()); + } } @Override public void cancel() { isCancel = true; + if (!mUtil.isRunning()) { + mListener.onCancel(); + } else { + mUtil.cancel(); + } + } + + /** + * 是否真正下载 + * + * @return {@code true} 真正下载 + */ + @Override public boolean isRunning() { + return mUtil.isRunning(); + } + + /** + * 任务的调度类型 + */ + public int getSchedulerType() { + return mSchedulerType; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java index 21685b0d..d8d0dad2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java @@ -25,11 +25,6 @@ public interface ITask { */ int getState(); - /** - * 获取扩展字段 - */ - String getExtendField(); - /** * 唯一标识符,DownloadTask 为下载地址,UploadTask 为文件路径 */ @@ -49,8 +44,17 @@ public interface ITask { void start(); + /** + * 停止任务 + */ void stop(); + /** + * 停止任务 + * @param type {@code 0}默认操作,{@code 1}停止任务不自动执行下一任务 + */ + void stop(int type); + void cancel(); /** @@ -89,5 +93,4 @@ public interface ITask { * @return 返回 3mb */ String getConvertCurrentProgress(); - } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/TaskSchedulerType.java b/Aria/src/main/java/com/arialyy/aria/core/inf/TaskSchedulerType.java new file mode 100644 index 00000000..b25496b7 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/TaskSchedulerType.java @@ -0,0 +1,22 @@ +package com.arialyy.aria.core.inf; + +import android.support.annotation.IntDef; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@IntDef({ + TaskSchedulerType.TYPE_DEFAULT, + TaskSchedulerType.TYPE_STOP_NOT_NEXT, + TaskSchedulerType.TYPE_STOP_AND_WAIT +}) +@Retention(RetentionPolicy.SOURCE) public @interface TaskSchedulerType { + int TYPE_DEFAULT = 1; + /** + * 停止当前任务并且不自动启动下一任务 + */ + int TYPE_STOP_NOT_NEXT = 2; + /** + * 停止任务并让当前任务处于等待状态 + */ + int TYPE_STOP_AND_WAIT = 3; +} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java b/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java index 9efa6b15..84e21e6a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java @@ -83,19 +83,21 @@ public class ThreadTaskManager { } key = getKey(key); Set temp = mThreadTasks.get(key); - try { - for (Future future : temp) { - if (future.isDone() || future.isCancelled()) { - continue; + if (temp != null && temp.size() > 0) { + try { + for (Future future : temp) { + if (future.isDone() || future.isCancelled()) { + continue; + } + AbsThreadTask task = (AbsThreadTask) future.get(); + task.setInterrupted(true); + future.cancel(true); } - AbsThreadTask task = (AbsThreadTask) future.get(); - task.setInterrupted(true); - future.cancel(true); + } catch (Exception e) { + ALog.e(TAG, e); } - } catch (Exception e) { - ALog.e(TAG, e); + temp.clear(); } - temp.clear(); mThreadTasks.remove(key); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java index 80cb9a77..27efbd20 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java @@ -19,6 +19,7 @@ package com.arialyy.aria.core.queue; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.queue.pool.BaseCachePool; import com.arialyy.aria.core.queue.pool.BaseExecutePool; import com.arialyy.aria.util.ALog; @@ -69,7 +70,6 @@ abstract class AbsTaskQueue, +abstract class AbsSchedulers> implements ISchedulers { private final String TAG = "AbsSchedulers"; @@ -169,13 +170,13 @@ abstract class AbsSchedulers reTryNum) { callback(FAIL, task); mQueue.removeTaskFormQueue(task.getKey()); - startNextTask(); + startNextTask(task); ALog.d(TAG, "retry_next"); TEManager.getInstance().removeTEntity(task.getKey()); return; @@ -303,7 +304,7 @@ abstract class AbsSchedulers, TASK extends AbsTask> +class BaseUListener, TASK extends AbsTask> implements IUploadListener { private WeakReference outHandler; private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度 @@ -41,7 +42,6 @@ class BaseUListener type = new HashSet<>(); //添加注解方法 for (TaskEnum te : entity.methods.keySet()) { Map, String> temp = entity.methods.get(te); + //if (entity.proxyClassName.contains(TaskEnum.DOWNLOAD.proxySuffix)) { + // type.add(1); + //} else if (entity.proxyClassName.contains(TaskEnum.DOWNLOAD_GROUP.proxySuffix)) { + // type.add(2); + //} else if (entity.proxyClassName.contains(TaskEnum.UPLOAD.proxySuffix)) { + // type.add(3); + //} else if (entity.proxyClassName.contains(TaskEnum.UPLOAD_GROUP.proxySuffix)) { + // type.add(4); + //} if (temp != null) { for (Class annotation : temp.keySet()) { MethodSpec method = createProxyMethod(te, annotation, temp.get(annotation)); @@ -189,6 +200,24 @@ final class EventProxyFiler { sb.append("keyMapping.put(\"").append(methodName).append("\", ").append("set);\n"); cb.add(sb.toString(), ClassName.get(HashSet.class)); } + //注册当前类 + //for (Integer i : type) { + // String str = null; + // switch (i) { + // case 1: + // case 2: + // str = "$T.download(obj).register();\n"; + // break; + // case 3: + // case 4: + // str = "$T.upload(obj).register();\n"; + // break; + // } + // if (str != null) { + // cb.add(str, ClassName.get("com.arialyy.aria.core", "Aria")); + // } + //} + MethodSpec structure = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addCode(cb.build()).build(); builder.addMethod(structure); diff --git a/DEV_LOG.md b/DEV_LOG.md index ba49504a..e7702797 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,9 @@ ## 开发日志 + + v_3.4.17 + - fix bug https://github.com/AriaLyy/Aria/issues/302 + - fix bug https://github.com/AriaLyy/Aria/issues/283 + - 现在,停止所有任务,未开始的任务状态将变为停止 + - 优化停止任务的速度 + v_3.4.12 - fix bug https://github.com/AriaLyy/Aria/issues/286 - 优化线程池任务 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 434990a3..ea9f281d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,12 +13,11 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme.NoActionBar"> - - + diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index 38d01617..6ac0832b 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -17,6 +17,7 @@ package com.arialyy.simple.download; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.util.Log; @@ -47,7 +48,9 @@ public class SingleTaskActivity extends BaseActivity { 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://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; + //"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip"; + "http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk"; //"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载 //"https://static.donguo.me//video/ip/course/pfys_1.mp4"; //"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864"; @@ -188,6 +191,11 @@ public class SingleTaskActivity extends BaseActivity { L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath()); L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL)); + //Intent install = new Intent(Intent.ACTION_VIEW); + //install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + //File apkFile = new File(task.getDownloadPath()); + //install.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); + //startActivity(install); } } @@ -228,7 +236,7 @@ public class SingleTaskActivity extends BaseActivity { //Aria.download(this).load(DOWNLOAD_URL).removeRecord(); break; case R.id.cancel: - Aria.download(this).load(DOWNLOAD_URL).cancel(); + Aria.download(this).load(DOWNLOAD_URL).cancel(true); //Aria.download(this).load(DOWNLOAD_URL).removeRecord(); break; } @@ -237,6 +245,12 @@ public class SingleTaskActivity extends BaseActivity { private void startD() { //Aria.get(this).setLogLevel(ALog.LOG_CLOSE); //Aria.download(this).load("aaaa.apk"); + String path = Environment.getExternalStorageDirectory().getPath() + "/ggsg8.apk"; + //File file = new File(path); + //if (file.exists()){ + // file.delete(); + //} + Aria.download(SingleTaskActivity.this) .load(DOWNLOAD_URL) //.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") @@ -245,7 +259,10 @@ public class SingleTaskActivity extends BaseActivity { //.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0") //.useServerFileName(true) //.setRequestMode(RequestEnum.GET) - .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg4.apk") + .setFilePath(path) + //.setExtendField("{\n" + // + "\"id\":\"你的样子\"\n< > " + // + "}") //.resetState() .start(); //.add(); diff --git a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java index 0f87fafc..4ea9b707 100644 --- a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java +++ b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java @@ -18,6 +18,7 @@ package com.arialyy.aria.core.upload; import android.os.Handler; import android.os.Looper; import com.arialyy.aria.core.inf.AbsNormalTask; +import com.arialyy.aria.core.inf.IUploadListener; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil; import com.arialyy.aria.util.ALog; @@ -26,56 +27,23 @@ import com.arialyy.aria.util.ALog; * Created by lyy on 2017/2/23. * 上传任务 */ -public class UploadTask extends AbsNormalTask { - private static final String TAG = "UploadTask"; - - private BaseUListener mListener; +public class UploadTask extends AbsNormalTask { private UploadTask(UploadTaskEntity taskEntity, Handler outHandler) { mTaskEntity = taskEntity; mOutHandler = outHandler; mListener = new BaseUListener<>(this, mOutHandler); - mUtil = new SimpleUploadUtil(taskEntity, mListener); + mUtil = new SimpleUploadUtil(taskEntity, (IUploadListener) mListener); } @Override public String getKey() { return mTaskEntity.getEntity().getFilePath(); } - @Override public boolean isRunning() { - return mUtil.isRunning(); - } - public UploadEntity getEntity() { return mTaskEntity.getEntity(); } - @Override public void start() { - if (mUtil.isRunning()) { - ALog.d(TAG, "任务正在下载"); - } else { - mUtil.start(); - } - } - - @Override public void stop() { - super.stop(); - if (mUtil.isRunning()) { - mUtil.stop(); - } else { - mListener.onStop(getCurrentProgress()); - } - } - - @Override public void cancel() { - super.cancel(); - if (mUtil.isRunning()) { - mUtil.cancel(); - } else { - mListener.onCancel(); - } - } - @Override public String getTaskName() { return mTaskEntity.getEntity().getFileName(); }