From 062f124cae1865228754340ac6f3c186d11de95d Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Mon, 22 Jul 2019 19:25:08 +0800 Subject: [PATCH 1/2] fix bug https://github.com/AriaLyy/Aria/issues/423 https://github.com/AriaLyy/Aria/issues/426 https://github.com/AriaLyy/Aria/issues/427 https://github.com/AriaLyy/Aria/issues/428 --- .../main/java/com/arialyy/aria/core/Aria.java | 308 +++++------ .../aria/core/command/CommandManager.java | 25 +- .../aria/core/common/BaseListener.java | 14 - .../aria/core/common/RecordHandler.java | 8 +- .../aria/core/common/RecordWrapper.java | 2 +- .../aria/core/common/ThreadRecord.java | 2 +- .../downloader/HttpFileInfoThread.java | 10 +- .../core/download/m3u8/M3U8InfoThread.java | 2 +- .../core/download/m3u8/M3U8LiveLoader.java | 2 +- .../aria/core/download/m3u8/M3U8LiveUtil.java | 10 +- .../aria/core/upload/AbsUploadTarget.java | 54 +- .../upload/uploader/FtpFileInfoThread.java | 2 +- .../aria/exception/ParamException.java | 48 +- .../java/com/arialyy/aria/orm/DBConfig.java | 2 +- .../java/com/arialyy/aria/orm/SqlHelper.java | 79 ++- .../com/arialyy/aria/util/RecordUtil.java | 35 +- app/src/main/assets/aria_config.xml | 2 +- .../download/HighestPriorityActivity.java | 488 +++++++++--------- .../download/m3u8/M3U8VodDLoadActivity.java | 2 + .../download/m3u8/VideoPlayerFragment.java | 2 +- .../multi_download/DownloadAdapter.java | 6 +- .../multi_download/MultiTaskActivity.java | 10 +- .../core/test/TestMutilTaskSysDownload.java | 160 +++--- app/src/main/res/values/strings.xml | 35 +- gradle.properties | 52 +- 25 files changed, 687 insertions(+), 673 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/Aria.java b/Aria/src/main/java/com/arialyy/aria/core/Aria.java index e7381e54..efdbce23 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java +++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java @@ -1,154 +1,154 @@ -/* - * 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; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.app.Application; -import android.app.Dialog; -import android.app.Service; -import android.content.Context; -import android.os.Build; -import android.support.v4.app.DialogFragment; -import android.support.v4.app.Fragment; -import android.widget.PopupWindow; -import com.arialyy.aria.core.download.DownloadReceiver; -import com.arialyy.aria.core.upload.UploadReceiver; -import com.arialyy.aria.util.ALog; - -/** - * Created by lyy on 2016/12/1. - * - * @see Aria - * @see Aria doc - * Aria启动,管理全局任务 - *
- *   
- *   //下载
- *   Aria.download(this)
- *       .load(URL)     //下载地址,必填
- *       //文件保存路径,必填
- *       .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
- *       .start();
- *   
- *   
- *    //上传
- *    Aria.upload(this)
- *        .load(filePath)     //文件路径,必填
- *        .setTempUrl(uploadUrl)  //上传路径,必填
- *        .setAttachment(fileKey)   //服务器读取文件的key,必填
- *        .start();
- *   
- * 
- * - * 如果你需要在【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】 - * 之外的java中使用Aria,那么你应该在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化 - * 然后才能使用{@link #download(Object)}、{@link #upload(Object)} - * - *
- *   
- *       Aria.init(this);
- *
- *      Aria.download(this)
- *       .load(URL)     //下载地址,必填
- *       //文件保存路径,必填
- *       .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
- *       .start();
- *
- *   
- *
- * 
- */ -@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria { - - private Aria() { - } - - /** - * 下载,在当前类中调用Aria方法,参数需要使用this,否则将 - * 如果不是【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】对象,那么你 - * 需要在对象中初始化下载前,在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化 - * - * @param obj 观察者对象,为本类对象,使用{@code this} - */ - public static DownloadReceiver download(Object obj) { - if (AriaManager.getInstance() != null){ - return AriaManager.getInstance().download(obj); - } - return get(convertContext(obj)).download(obj); - } - - /** - * 上传 - * 如果不是【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】对象,那么你 - * 需要在对象中初始化下载前,在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化 - * - * @param obj 观察者对象,为本类对象,使用{@code this} - */ - public static UploadReceiver upload(Object obj) { - if (AriaManager.getInstance() != null){ - return AriaManager.getInstance().upload(obj); - } - return get(convertContext(obj)).upload(obj); - } - - /** - * 处理通用事件 - */ - public static AriaManager get(Context context) { - if (context == null) { - throw new NullPointerException("context 无效,在非【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】," - + "请参考【https://aria.laoyuyu.me/aria_doc/start/any_java.html】,参数请使用 download(this) 或 upload(this);" - + "不要使用 download(getContext()) 或 upload(getContext())"); - } - return AriaManager.getInstance(context); - } - - /** - * 初始化Aria,如果你需要在【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】 - * 之外的java中使用Aria,那么你应该在Application或Activity初始化的时候调用本方法对Aria进行初始化 - * 只需要初始化一次就可以 - * {@link #download(Object)}、{@link #upload(Object)} - */ - public static AriaManager init(Context context) { - return AriaManager.getInstance(context); - } - - private static Context convertContext(Object obj) { - if (obj instanceof Application) { - return (Application) obj; - } else if (obj instanceof Service) { - return (Service) obj; - } else if (obj instanceof Activity) { - return (Activity) obj; - } else if (obj instanceof DialogFragment) { - return ((DialogFragment) obj).getContext(); - } else if (obj instanceof android.app.DialogFragment) { - return ((android.app.DialogFragment) obj).getActivity(); - } else if (obj instanceof android.support.v4.app.Fragment) { - return ((Fragment) obj).getContext(); - } else if (obj instanceof android.app.Fragment) { - return ((android.app.Fragment) obj).getActivity(); - } else if (obj instanceof Dialog) { - return ((Dialog) obj).getContext(); - } else if (obj instanceof PopupWindow) { - return ((PopupWindow) obj).getContentView().getContext(); - } - ALog.e("Aria", "请使用download(this)或upload(this)"); - return null; - } -} +/* + * 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; + +import android.annotation.TargetApi; +import android.app.Activity; +import android.app.Application; +import android.app.Dialog; +import android.app.Service; +import android.content.Context; +import android.os.Build; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.widget.PopupWindow; +import com.arialyy.aria.core.download.DownloadReceiver; +import com.arialyy.aria.core.upload.UploadReceiver; +import com.arialyy.aria.util.ALog; + +/** + * Created by lyy on 2016/12/1. + * + * @see Aria + * @see Aria doc + * Aria启动,管理全局任务 + *
+ *   
+ *   //下载
+ *   Aria.download(this)
+ *       .load(URL)     //下载地址,必填
+ *       //文件保存路径,必填
+ *       .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
+ *       .start();
+ *   
+ *   
+ *    //上传
+ *    Aria.upload(this)
+ *        .load(filePath)     //文件路径,必填
+ *        .setTempUrl(uploadUrl)  //上传路径,必填
+ *        .setAttachment(fileKey)   //服务器读取文件的key,必填
+ *        .start();
+ *   
+ * 
+ * + * 如果你需要在【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】 + * 之外的java中使用Aria,那么你应该在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化 + * 然后才能使用{@link #download(Object)}、{@link #upload(Object)} + * + *
+ *   
+ *       Aria.init(this);
+ *
+ *      Aria.download(this)
+ *       .load(URL)     //下载地址,必填
+ *       //文件保存路径,必填
+ *       .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
+ *       .start();
+ *
+ *   
+ *
+ * 
+ */ +@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria { + + private Aria() { + } + + /** + * 下载,在当前类中调用Aria方法,参数需要使用this,否则将 + * 如果不是【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】对象,那么你 + * 需要在对象中初始化下载前,在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化 + * + * @param obj 观察者对象,为本类对象,使用{@code this} + */ + public static DownloadReceiver download(Object obj) { + if (AriaManager.getInstance() != null){ + return AriaManager.getInstance().download(obj); + } + return get(convertContext(obj)).download(obj); + } + + /** + * 上传 + * 如果不是【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】对象,那么你 + * 需要在对象中初始化下载前,在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化 + * + * @param obj 观察者对象,为本类对象,使用{@code this} + */ + public static UploadReceiver upload(Object obj) { + if (AriaManager.getInstance() != null){ + return AriaManager.getInstance().upload(obj); + } + return get(convertContext(obj)).upload(obj); + } + + /** + * 处理通用事件 + */ + public static AriaManager get(Context context) { + if (context == null) { + throw new NullPointerException("context 无效,在非【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】," + + "请参考【https://aria.laoyuyu.me/aria_doc/start/any_java.html】,参数请使用 download(this) 或 upload(this);" + + "不要使用 download(getContext()) 或 upload(getContext())"); + } + return AriaManager.getInstance(context); + } + + /** + * 初始化Aria,如果你需要在【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】 + * 之外的java中使用Aria,那么你应该在Application或Activity初始化的时候调用本方法对Aria进行初始化 + * 只需要初始化一次就可以 + * {@link #download(Object)}、{@link #upload(Object)} + */ + public static AriaManager init(Context context) { + return AriaManager.getInstance(context); + } + + private static Context convertContext(Object obj) { + if (obj instanceof Application) { + return (Application) obj; + } else if (obj instanceof Service) { + return (Service) obj; + } else if (obj instanceof Activity) { + return (Activity) obj; + } else if (obj instanceof DialogFragment) { + return ((DialogFragment) obj).getContext(); + } else if (obj instanceof android.app.DialogFragment) { + return ((android.app.DialogFragment) obj).getActivity(); + } else if (obj instanceof android.support.v4.app.Fragment) { + return ((Fragment) obj).getContext(); + } else if (obj instanceof android.app.Fragment) { + return ((android.app.Fragment) obj).getActivity(); + } else if (obj instanceof Dialog) { + return ((Dialog) obj).getContext(); + } else if (obj instanceof PopupWindow) { + return ((PopupWindow) obj).getContentView().getContext(); + } + ALog.e("Aria", "请使用download(this)或upload(this)"); + return null; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/CommandManager.java b/Aria/src/main/java/com/arialyy/aria/core/command/CommandManager.java index 786e0d51..6ca3a813 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/CommandManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/CommandManager.java @@ -43,7 +43,7 @@ public class CommandManager { @Event public void add(AddCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ + if (CommonUtil.isFastDoubleClick()) { return; } cmd.executeCmd(); @@ -51,7 +51,7 @@ public class CommandManager { @Event public void start(StartCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ + if (CommonUtil.isFastDoubleClick()) { return; } cmd.executeCmd(); @@ -59,23 +59,17 @@ public class CommandManager { @Event public void stop(StopCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ - return; - } cmd.executeCmd(); } @Event public void cancel(CancelCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ - return; - } cmd.executeCmd(); } @Event public void stopAll(StopAllCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ + if (CommonUtil.isFastDoubleClick()) { return; } cmd.executeCmd(); @@ -83,7 +77,7 @@ public class CommandManager { @Event public void cancelAll(CancelAllCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ + if (CommonUtil.isFastDoubleClick()) { return; } cmd.executeCmd(); @@ -91,7 +85,7 @@ public class CommandManager { @Event public void reStart(ReStartCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ + if (CommonUtil.isFastDoubleClick()) { return; } cmd.executeCmd(); @@ -99,7 +93,7 @@ public class CommandManager { @Event public void highestPriority(HighestPriorityCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ + if (CommonUtil.isFastDoubleClick()) { return; } cmd.executeCmd(); @@ -107,7 +101,7 @@ public class CommandManager { @Event public void resumeAll(ResumeAllCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ + if (CommonUtil.isFastDoubleClick()) { return; } cmd.executeCmd(); @@ -115,7 +109,7 @@ public class CommandManager { @Event public void subStart(DGSubStartCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ + if (CommonUtil.isFastDoubleClick()) { return; } cmd.executeCmd(); @@ -123,9 +117,6 @@ public class CommandManager { @Event public void subStop(DGSubStopCmd cmd) { - if (CommonUtil.isFastDoubleClick()){ - return; - } cmd.executeCmd(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java b/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java index 58040931..b29789e0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java @@ -16,8 +16,6 @@ package com.arialyy.aria.core.common; import android.os.Handler; -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.AbsTask; import com.arialyy.aria.core.inf.AbsTaskWrapper; @@ -26,12 +24,10 @@ import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.inf.ITaskWrapper; import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.scheduler.ISchedulers; -import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.ErrorHelp; -import com.arialyy.aria.util.RecordUtil; import java.lang.ref.WeakReference; public abstract class BaseListener, @@ -156,16 +152,6 @@ public abstract class BaseListener threadRecords; @Override protected void handleConvert() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java b/Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java index 7e408b00..ec29e4fd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java @@ -26,7 +26,7 @@ public class ThreadRecord extends DbEntity { /** * 任务的文件路径,不是当前线程记录的的分块文件路径 */ - public String key; + public String taskKey; /** * 开始位置 diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 3bd63673..78f7a229 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -22,9 +22,9 @@ import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.RequestEnum; +import com.arialyy.aria.core.common.http.HttpTaskConfig; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.common.http.HttpTaskConfig; import com.arialyy.aria.core.inf.IHttpFileLenAdapter; import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.BaseException; @@ -54,7 +54,7 @@ import java.util.UUID; * 下载文件信息获取 */ public class HttpFileInfoThread implements Runnable { - private final String TAG = "HttpFileInfoThread"; + private static final String TAG = "HttpFileInfoThread"; private DownloadEntity mEntity; private DTaskWrapper mTaskWrapper; private int mConnectTimeOut; @@ -119,7 +119,7 @@ public class HttpFileInfoThread implements Runnable { } long len = lenAdapter.handleFileLen(conn.getHeaderFields()); - if (!CommonUtil.checkSDMemorySpace(mEntity.getDownloadPath(), len)) { + if (!CommonUtil.checkSDMemorySpace(mEntity.getFilePath(), len)) { failDownload(new TaskException(TAG, String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getDownloadPath(), mEntity.getUrl())), false); @@ -334,6 +334,10 @@ public class HttpFileInfoThread implements Runnable { private static class FileLenAdapter implements IHttpFileLenAdapter { @Override public long handleFileLen(Map> headers) { + if (headers == null || headers.isEmpty()) { + ALog.e(TAG, "header为空,获取文件长度失败"); + return -1; + } List sLength = headers.get("Content-Length"); if (sLength == null || sLength.isEmpty()) { return -1; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java index c4007657..aa1fd357 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java @@ -53,7 +53,7 @@ import java.util.regex.Pattern; * https://blog.csdn.net/Guofengpu/article/details/54922865 */ final class M3U8InfoThread implements Runnable { - private final String TAG = "M3U8FileInfoThread"; + private final String TAG = "M3U8InfoThread"; private DownloadEntity mEntity; private DTaskWrapper mTaskWrapper; private int mConnectTimeOut; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java index 162d5bb2..e31ea849 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java @@ -127,7 +127,7 @@ public class M3U8LiveLoader extends BaseM3U8Loader { */ private M3U8ThreadTask createThreadTask(String cacheDir, int indexId, String tsUrl) { ThreadRecord record = new ThreadRecord(); - record.key = mRecord.filePath; + record.taskKey = mRecord.filePath; record.isComplete = false; record.tsUrl = tsUrl; record.threadType = TaskRecord.TYPE_M3U8_LIVE; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java index 84b38c77..45fa8f5b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java @@ -95,10 +95,14 @@ public class M3U8LiveUtil implements IUtil { if (mInfoThread != null) { mInfoThread.setStop(true); closeTimer(); - if (mLoader.mergeFile()) { - mListener.onComplete(); + if (mWrapper.asM3U8().isMergeFile()) { + if (mLoader.mergeFile()) { + mListener.onComplete(); + } else { + mListener.onFail(false, new M3U8Exception(TAG, "合并文件失败")); + } } else { - mListener.onFail(false, new M3U8Exception(TAG, "合并文件失败")); + mListener.onComplete(); } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java index 8893bbef..1becf4fe 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java @@ -1,27 +1,27 @@ -/* - * 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.upload; - -import com.arialyy.aria.core.inf.AbsTarget; - -/** - * Created by AriaL on 2017/6/29. - * 普通上传任务接收器 - */ -abstract class AbsUploadTarget extends AbsTarget { - - -} +/* + * 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.upload; + +import com.arialyy.aria.core.inf.AbsTarget; + +/** + * Created by AriaL on 2017/6/29. + * 普通上传任务接收器 + */ +abstract class AbsUploadTarget extends AbsTarget { + + +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java index fbe55682..3be4fbb1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java @@ -144,7 +144,7 @@ class FtpFileInfoThread extends AbsFtpInfoThread { ThreadRecord threadRecord; if (record.threadRecords == null || record.threadRecords.isEmpty()) { threadRecord = new ThreadRecord(); - threadRecord.key = record.filePath; + threadRecord.taskKey = record.filePath; } else { threadRecord = record.threadRecords.get(0); } diff --git a/Aria/src/main/java/com/arialyy/aria/exception/ParamException.java b/Aria/src/main/java/com/arialyy/aria/exception/ParamException.java index fb77a9e0..b2299c2f 100644 --- a/Aria/src/main/java/com/arialyy/aria/exception/ParamException.java +++ b/Aria/src/main/java/com/arialyy/aria/exception/ParamException.java @@ -1,24 +1,24 @@ -/* - * 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.exception; - -public class ParamException extends RuntimeException { - private static final String ARIA_NET_EXCEPTION = "Aria Params Exception:"; - - public ParamException(String message) { - super(String.format("%s%s", ARIA_NET_EXCEPTION, message)); - } -} +/* + * 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.exception; + +public class ParamException extends RuntimeException { + private static final String ARIA_NET_EXCEPTION = "Aria Params Exception:"; + + public ParamException(String message) { + super(String.format("%s%s", ARIA_NET_EXCEPTION, message)); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java index cedd69d8..e50113e7 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -38,7 +38,7 @@ class DBConfig { static boolean DEBUG = false; static Map mapping = new LinkedHashMap<>(); static String DB_NAME; - static int VERSION = 51; + static int VERSION = 52; /** * 是否将数据库保存在Sd卡,{@code true} 是 diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index 5957d750..1795cb79 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -100,6 +100,8 @@ final class SqlHelper extends SQLiteOpenHelper { handle360AriaUpdate(db); } else if (oldVersion < 51) { handle365Update(db); + } else if (oldVersion < 52) { + handle366Update(db); } else { handleDbUpdate(db, null, null); } @@ -239,23 +241,43 @@ final class SqlHelper extends SQLiteOpenHelper { */ private void delRepeatThreadRecord(SQLiteDatabase db) { String repeatSql = - "DELETE FROM ThreadRecord WHERE (key, threadId, endLocation) " - + "IN (SELECT key, threadId, endLocation FROM ThreadRecord GROUP BY key, threadId, endLocation " + "DELETE FROM ThreadRecord WHERE (taskKey, threadId, endLocation) " + + "IN (SELECT taskKey, threadId, endLocation FROM ThreadRecord GROUP BY taskKey, threadId, endLocation " + "HAVING COUNT(*) > 1) AND rowid " - + "NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY key, threadId, endLocation " + + "NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY taskKey, threadId, endLocation " + "HAVING COUNT(*)> 1)"; ALog.d(TAG, repeatSql); db.execSQL(repeatSql); } + /** + * 处理366版本以下的升级 + */ + private void handle366Update(SQLiteDatabase db) { + Map> modifyMap = new HashMap<>(); + // 处理ThreadRecord的key字段名修改 + Map threadRecordModify = new HashMap<>(); + threadRecordModify.put("key", "taskKey"); + modifyMap.put("ThreadRecord", threadRecordModify); + + // 执行升级操作 + handleDbUpdate(db, modifyMap, null); + } + /** * 处理365版本以下的升级 */ private void handle365Update(SQLiteDatabase db) { db.execSQL("UPDATE ThreadRecord SET threadId=0 WHERE threadId=-1"); + Map> modifyMap = new HashMap<>(); + // 处理ThreadRecord的key字段名修改 + Map threadRecordModify = new HashMap<>(); + threadRecordModify.put("key", "taskKey"); + modifyMap.put("ThreadRecord", threadRecordModify); + // 执行升级操作 - handleDbUpdate(db, null, null); + handleDbUpdate(db, modifyMap, null); delRepeatThreadRecord(db); } @@ -271,19 +293,25 @@ final class SqlHelper extends SQLiteOpenHelper { } } - Map> columnMap = new HashMap<>(); + Map> modifyMap = new HashMap<>(); // 处理DownloadEntity、DownloadGroupEntity的 groupName字段名的修改 - Map groupNameModify = new HashMap<>(); - groupNameModify.put("groupName", "groupHash"); - columnMap.put("DownloadEntity", groupNameModify); - columnMap.put("DownloadGroupEntity", groupNameModify); + Map entityModify = new HashMap<>(); + entityModify.put("groupName", "groupHash"); + modifyMap.put("DownloadEntity", entityModify); + modifyMap.put("DownloadGroupEntity", entityModify); + // 处理TaskRecord的dGroupName字段名的修改 - Map dGroupNameModify = new HashMap<>(); - dGroupNameModify.put("dGroupName", "dGroupHash"); - columnMap.put("TaskRecord", dGroupNameModify); + Map taskRecordModify = new HashMap<>(); + taskRecordModify.put("dGroupName", "dGroupHash"); + modifyMap.put("TaskRecord", taskRecordModify); + + // 处理ThreadRecord的key字段名修改 + Map threadRecordModify = new HashMap<>(); + threadRecordModify.put("key", "taskKey"); + modifyMap.put("ThreadRecord", threadRecordModify); // 执行升级操作 - handleDbUpdate(db, columnMap, null); + handleDbUpdate(db, modifyMap, null); delRepeatThreadRecord(db); } @@ -324,18 +352,19 @@ final class SqlHelper extends SQLiteOpenHelper { i++; } - Map> modifyColumnMap = new HashMap<>(); - Map dMap = new HashMap<>(); - dMap.put("groupName", "groupHash"); // 处理数据库版本小于3的字段改变 - dMap.put("downloadUrl", "url"); - dMap.put("isDownloadComplete", "isComplete"); - modifyColumnMap.put("DownloadEntity", dMap); - - Map dGMap = new HashMap<>(); - dGMap.put("groupName", "groupHash"); - modifyColumnMap.put("DownloadGroupEntity", dGMap); - + Map> modifyMap = new HashMap<>(); + Map dEntityModifyMap = new HashMap<>(); + dEntityModifyMap.put("groupName", "groupHash"); + dEntityModifyMap.put("downloadUrl", "url"); + dEntityModifyMap.put("isDownloadComplete", "isComplete"); + modifyMap.put("DownloadEntity", dEntityModifyMap); + + Map dGEntityModifyMap = new HashMap<>(); + dGEntityModifyMap.put("groupName", "groupHash"); + modifyMap.put("DownloadGroupEntity", dGEntityModifyMap); + + // 删除字段 Map> delColumnMap = new HashMap<>(); List dEntityDel = new ArrayList<>(); dEntityDel.add("taskKey"); @@ -344,6 +373,6 @@ final class SqlHelper extends SQLiteOpenHelper { dgEntityDel.add("subtask"); delColumnMap.put("DownloadGroupEntity", dgEntityDel); - handleDbUpdate(db, modifyColumnMap, delColumnMap); + handleDbUpdate(db, modifyMap, delColumnMap); } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java b/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java index 313568f8..c5d5b522 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java @@ -83,7 +83,7 @@ public class RecordUtil { } } } - DbEntity.deleteData(ThreadRecord.class, "key=?", record.taskRecord.filePath); + DbEntity.deleteData(ThreadRecord.class, "taskKey=?", record.taskRecord.filePath); record.taskRecord.deleteData(); } } @@ -148,15 +148,14 @@ public class RecordUtil { */ if (!entity.isComplete()) { if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件 - String cacheDir = null; - if (!targetFile.isDirectory()) { - cacheDir = targetFile.getParent() + "/." + targetFile.getName(); - } - removeTsCache(cacheDir); + removeTsCache(targetFile, record.bandWidth); } else if (record.isBlock) { // 删除分块文件 removeBlockFile(record); } } else if (removeFile) { // 处理任务完成情况 + if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { + removeTsCache(targetFile, record.bandWidth); + } removeTargetFile(targetFile); } @@ -209,16 +208,14 @@ public class RecordUtil { */ if (!entity.isComplete()) { if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件 - String cacheDir = null; - if (!targetFile.isDirectory()) { - cacheDir = String.format("%s/.%s_%s", targetFile.getParent(), targetFile.getName(), - record.bandWidth); - } - removeTsCache(cacheDir); + removeTsCache(targetFile, record.bandWidth); } else if (record.isBlock) { // 删除分块文件 removeBlockFile(record); } } else if (removeFile) { // 处理任务完成情况 + if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { + removeTsCache(targetFile, record.bandWidth); + } removeTargetFile(targetFile); } @@ -238,7 +235,7 @@ public class RecordUtil { private static void removeRecord(String filePath) { ALog.i(TAG, "删除任务记录"); - DbEntity.deleteData(ThreadRecord.class, "key=?", filePath); + DbEntity.deleteData(ThreadRecord.class, "taskKey=?", filePath); DbEntity.deleteData(TaskRecord.class, "filePath=?", filePath); } @@ -287,11 +284,17 @@ public class RecordUtil { /** * 删除ts文件 */ - private static void removeTsCache(String cacheDir) { + private static void removeTsCache(File targetFile, long bandWidth) { + + String cacheDir = null; + if (!targetFile.isDirectory()) { + cacheDir = + String.format("%s/.%s_%s", targetFile.getParent(), targetFile.getName(), bandWidth); + } if (!TextUtils.isEmpty(cacheDir)) { File cacheDirF = new File(cacheDir); - if (!cacheDirF.exists()){ + if (!cacheDirF.exists()) { return; } File[] files = cacheDirF.listFiles(); @@ -348,7 +351,7 @@ public class RecordUtil { // 修改线程记录 if (record.threadRecords != null && !record.threadRecords.isEmpty()) { for (ThreadRecord tr : record.threadRecords) { - tr.key = newPath; + tr.taskKey = newPath; File blockFile = new File(String.format(RecordHandler.SUB_PATH, oldPath, tr.threadId)); if (blockFile.exists()) { blockFile.renameTo(new File(String.format(RecordHandler.SUB_PATH, newPath, tr.threadId))); diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index dab01a5e..1fb5c1ec 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -44,7 +44,7 @@ - + diff --git a/app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java b/app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java index 8cec1211..05a66219 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java @@ -1,244 +1,244 @@ -/* - * 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.core.download; - -import android.os.Bundle; -import android.os.Environment; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; -import com.arialyy.annotations.Download; -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; -import com.arialyy.simple.base.BaseActivity; -import com.arialyy.simple.databinding.ActivityHighestPriorityBinding; -import com.arialyy.simple.core.download.multi_download.DownloadAdapter; -import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Created by lyy on 2017/6/2. - * 最高优先级任务Demo - */ -public class HighestPriorityActivity extends BaseActivity { - private HorizontalProgressBarWithNumber mPb; - private Button mStart; - private Button mStop; - private Button mCancel; - private TextView mSize; - private TextView mSpeed; - private RecyclerView mList; - - private String mTaskName = "光明大陆"; - private static final String DOWNLOAD_URL = - "https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk"; - private DownloadAdapter mAdapter; - private List mData = new ArrayList<>(); - private Set mRecord = new HashSet<>(); - - @Override protected int setLayoutId() { - return R.layout.activity_highest_priority; - } - - @Override protected void init(Bundle savedInstanceState) { - super.init(savedInstanceState); - mPb = findViewById(R.id.progressBar); - mStart = findViewById(R.id.start); - mStop = findViewById(R.id.stop); - mCancel = findViewById(R.id.cancel); - mSize = findViewById(R.id.size); - mSpeed = findViewById(R.id.speed); - mList = findViewById(R.id.list); - - setTitle("最高优先级任务"); - getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)"); - initWidget(); - Aria.download(this).register(); - } - - private void initWidget() { - DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); - mPb.setProgress(target.getPercent()); - if (target.getTaskState() == IEntity.STATE_STOP) { - mStart.setText("恢复"); - mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light)); - setBtState(true); - } else if (target.isRunning()) { - setBtState(false); - } - mSize.setText(target.getConvertFileSize()); - List temp = Aria.download(this).getTaskList(); - if (temp != null && !temp.isEmpty()) { - for (DownloadEntity entity : temp) { - if (entity.getUrl().equals(DOWNLOAD_URL)) continue; - mData.add(entity); - mRecord.add(entity.getUrl()); - } - } - mAdapter = new DownloadAdapter(this, mData); - mList.setLayoutManager(new LinearLayoutManager(this)); - mList.setAdapter(mAdapter); - } - - @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_highest_priority, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.add_task: - List temp = getModule(DownloadModule.class).getHighestTestList(); - for (DownloadEntity entity : temp) { - String url = entity.getUrl(); - if (mRecord.contains(url)) { - continue; - } - mAdapter.addDownloadEntity(entity); - mRecord.add(url); - } - mAdapter.notifyDataSetChanged(); - break; - case R.id.help: - String title = "最高优先级任务介绍"; - String msg = " 将任务设置为最高优先级任务,最高优先级任务有以下特点:\n" - + " 1、在下载队列中,有且只有一个最高优先级任务\n" - + " 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成\n" - + " 3、任务调度器不会暂停最高优先级任务\n" - + " 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效\n" - + " 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行\n" - + " 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务"; - showMsgDialog(title, msg); - break; - } - return true; - } - - public void onClick(View view) { - switch (view.getId()) { - case R.id.start: - String text = ((TextView) view).getText().toString(); - if (text.equals("重新开始?") || text.equals("开始")) { - Aria.download(this) - .load(DOWNLOAD_URL) - .setFilePath(Environment.getExternalStorageDirectory().getPath() - + "/Download/" - + mTaskName - + ".apk") - .setHighestPriority(); - } else if (text.equals("恢复")) { - Aria.download(this).load(DOWNLOAD_URL).resume(); - } - break; - case R.id.stop: - Aria.download(this).load(DOWNLOAD_URL).pause(); - break; - case R.id.cancel: - Aria.download(this).load(DOWNLOAD_URL).cancel(); - break; - } - } - - /** - * 设置start 和 stop 按钮状态 - */ - private void setBtState(boolean state) { - mStart.setEnabled(state); - mStop.setEnabled(!state); - } - - @Download.onPre public void onPre(DownloadTask task) { - mAdapter.updateState(task.getDownloadEntity()); - } - - @Download.onTaskPre public void onTaskPre(DownloadTask task) { - if (task.getKey().equals(DOWNLOAD_URL)) { - mSize.setText(task.getConvertFileSize()); - } - mAdapter.updateState(task.getDownloadEntity()); - } - - @Download.onTaskStart public void onTaskStart(DownloadTask task) { - if (task.getKey().equals(DOWNLOAD_URL)) { - setBtState(false); - } - mAdapter.updateState(task.getDownloadEntity()); - } - - @Download.onTaskResume public void onTaskResume(DownloadTask task) { - if (task.getKey().equals(DOWNLOAD_URL)) { - setBtState(false); - } - mAdapter.updateState(task.getDownloadEntity()); - } - - @Download.onTaskStop public void onTaskStop(DownloadTask task) { - if (task.getKey().equals(DOWNLOAD_URL)) { - setBtState(true); - mStart.setText("恢复"); - mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light)); - } - mAdapter.updateState(task.getDownloadEntity()); - } - - @Download.onTaskCancel public void onTaskCancel(DownloadTask task) { - if (task.getKey().equals(DOWNLOAD_URL)) { - setBtState(true); - mStart.setText("开始"); - mPb.setProgress(0); - } - mAdapter.updateState(task.getDownloadEntity()); - } - - @Download.onTaskFail public void onTaskFail(DownloadTask task) { - if (task.getKey().equals(DOWNLOAD_URL)) { - setBtState(true); - } else { - L.d(TAG, "download fail【" + task.getKey() + "】"); - } - } - - @Download.onTaskComplete public void onTaskComplete(DownloadTask task) { - if (task.getKey().equals(DOWNLOAD_URL)) { - setBtState(true); - mStart.setText("重新开始"); - mStart.setTextColor(getResources().getColor(android.R.color.holo_green_light)); - mPb.setProgress(100); - } - mAdapter.updateState(task.getDownloadEntity()); - } - - @Download.onTaskRunning public void onTaskRunning(DownloadTask task) { - if (task.getKey().equals(DOWNLOAD_URL)) { - mPb.setProgress(task.getPercent()); - mSpeed.setText(task.getConvertSpeed()); - } - mAdapter.setProgress(task.getDownloadEntity()); - } -} +/* + * 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.core.download; + +import android.os.Bundle; +import android.os.Environment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import com.arialyy.annotations.Download; +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; +import com.arialyy.simple.base.BaseActivity; +import com.arialyy.simple.databinding.ActivityHighestPriorityBinding; +import com.arialyy.simple.core.download.multi_download.DownloadAdapter; +import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Created by lyy on 2017/6/2. + * 最高优先级任务Demo + */ +public class HighestPriorityActivity extends BaseActivity { + private HorizontalProgressBarWithNumber mPb; + private Button mStart; + private Button mStop; + private Button mCancel; + private TextView mSize; + private TextView mSpeed; + private RecyclerView mList; + + private String mTaskName = "光明大陆"; + private static final String DOWNLOAD_URL = + "https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk"; + private DownloadAdapter mAdapter; + private List mData = new ArrayList<>(); + private Set mRecord = new HashSet<>(); + + @Override protected int setLayoutId() { + return R.layout.activity_highest_priority; + } + + @Override protected void init(Bundle savedInstanceState) { + super.init(savedInstanceState); + mPb = findViewById(R.id.progressBar); + mStart = findViewById(R.id.start); + mStop = findViewById(R.id.stop); + mCancel = findViewById(R.id.cancel); + mSize = findViewById(R.id.size); + mSpeed = findViewById(R.id.speed); + mList = findViewById(R.id.list); + + setTitle("最高优先级任务"); + getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)"); + initWidget(); + Aria.download(this).register(); + } + + private void initWidget() { + DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); + mPb.setProgress(target.getPercent()); + if (target.getTaskState() == IEntity.STATE_STOP) { + mStart.setText("恢复"); + mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light)); + setBtState(true); + } else if (target.isRunning()) { + setBtState(false); + } + mSize.setText(target.getConvertFileSize()); + List temp = Aria.download(this).getTaskList(); + if (temp != null && !temp.isEmpty()) { + for (DownloadEntity entity : temp) { + if (entity.getUrl().equals(DOWNLOAD_URL)) continue; + mData.add(entity); + mRecord.add(entity.getUrl()); + } + } + mAdapter = new DownloadAdapter(this, mData); + mList.setLayoutManager(new LinearLayoutManager(this)); + mList.setAdapter(mAdapter); + } + + @Override public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_highest_priority, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override public boolean onMenuItemClick(MenuItem item) { + switch (item.getItemId()) { + case R.id.add_task: + List temp = getModule(DownloadModule.class).getHighestTestList(); + for (DownloadEntity entity : temp) { + String url = entity.getUrl(); + if (mRecord.contains(url)) { + continue; + } + mAdapter.addDownloadEntity(entity); + mRecord.add(url); + } + mAdapter.notifyDataSetChanged(); + break; + case R.id.help: + String title = "最高优先级任务介绍"; + String msg = " 将任务设置为最高优先级任务,最高优先级任务有以下特点:\n" + + " 1、在下载队列中,有且只有一个最高优先级任务\n" + + " 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成\n" + + " 3、任务调度器不会暂停最高优先级任务\n" + + " 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效\n" + + " 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行\n" + + " 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务"; + showMsgDialog(title, msg); + break; + } + return true; + } + + public void onClick(View view) { + switch (view.getId()) { + case R.id.start: + String text = ((TextView) view).getText().toString(); + if (text.equals("重新开始?") || text.equals("开始")) { + Aria.download(this) + .load(DOWNLOAD_URL) + .setFilePath(Environment.getExternalStorageDirectory().getPath() + + "/Download/" + + mTaskName + + ".apk") + .setHighestPriority(); + } else if (text.equals("恢复")) { + Aria.download(this).load(DOWNLOAD_URL).resume(); + } + break; + case R.id.stop: + Aria.download(this).load(DOWNLOAD_URL).pause(); + break; + case R.id.cancel: + Aria.download(this).load(DOWNLOAD_URL).cancel(); + break; + } + } + + /** + * 设置start 和 stop 按钮状态 + */ + private void setBtState(boolean state) { + mStart.setEnabled(state); + mStop.setEnabled(!state); + } + + @Download.onPre public void onPre(DownloadTask task) { + mAdapter.updateState(task.getDownloadEntity()); + } + + @Download.onTaskPre public void onTaskPre(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mSize.setText(task.getConvertFileSize()); + } + mAdapter.updateState(task.getDownloadEntity()); + } + + @Download.onTaskStart public void onTaskStart(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + setBtState(false); + } + mAdapter.updateState(task.getDownloadEntity()); + } + + @Download.onTaskResume public void onTaskResume(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + setBtState(false); + } + mAdapter.updateState(task.getDownloadEntity()); + } + + @Download.onTaskStop public void onTaskStop(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + setBtState(true); + mStart.setText("恢复"); + mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light)); + } + mAdapter.updateState(task.getDownloadEntity()); + } + + @Download.onTaskCancel public void onTaskCancel(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + setBtState(true); + mStart.setText("开始"); + mPb.setProgress(0); + } + mAdapter.updateState(task.getDownloadEntity()); + } + + @Download.onTaskFail public void onTaskFail(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + setBtState(true); + } else { + L.d(TAG, "download fail【" + task.getKey() + "】"); + } + } + + @Download.onTaskComplete public void onTaskComplete(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + setBtState(true); + mStart.setText("重新开始"); + mStart.setTextColor(getResources().getColor(android.R.color.holo_green_light)); + mPb.setProgress(100); + } + mAdapter.updateState(task.getDownloadEntity()); + } + + @Download.onTaskRunning public void onTaskRunning(DownloadTask task) { + if (task.getKey().equals(DOWNLOAD_URL)) { + mPb.setProgress(task.getPercent()); + mSpeed.setText(task.getConvertSpeed()); + } + mAdapter.setProgress(task.getDownloadEntity()); + } +} diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java index e54380f4..f9892578 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java @@ -309,9 +309,11 @@ public class M3U8VodDLoadActivity extends BaseActivity { }) .setMergeHandler(new ITsMergeHandler() { @Override public boolean merge(@Nullable M3U8KeyInfo keyInfo, List tsPath) { + ALog.d(TAG, "合并TS...."); return false; } }) + .merge(true) //.asVod().setPeerIndex(50) .start(); } diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java index 9b5f6b4f..fd119ef0 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java +++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java @@ -55,7 +55,7 @@ public class VideoPlayerFragment extends BaseFragment { dialog.show(getSupportFragmentManager(), "download_num"); break; case R.id.stop_all: - Aria.download(this).stopAllTask(); - //Aria.download(this).removeAllTask(false); + List entities = Aria.download(this).getTaskList(); + for (DownloadEntity entity: entities){ + Aria.download(this).load(entity.getUrl()).cancel(true); + ALog.d(TAG, "exist ==" + Aria.download(this).load(entity.getUrl()).taskExists()); + } + //Aria.download(this).stopAllTask(); + //Aria.download(this).removeAllTask(true); break; case R.id.turn: startActivity(new Intent(this, MultiDownloadActivity.class)); diff --git a/app/src/main/java/com/arialyy/simple/core/test/TestMutilTaskSysDownload.java b/app/src/main/java/com/arialyy/simple/core/test/TestMutilTaskSysDownload.java index a3dd437b..b5248fa8 100644 --- a/app/src/main/java/com/arialyy/simple/core/test/TestMutilTaskSysDownload.java +++ b/app/src/main/java/com/arialyy/simple/core/test/TestMutilTaskSysDownload.java @@ -1,80 +1,80 @@ -package com.arialyy.simple.core.test; - -import android.os.Environment; -import android.view.View; -import com.arialyy.aria.core.Aria; -import com.arialyy.aria.core.common.QueueMod; -import com.arialyy.simple.R; -import com.arialyy.simple.base.BaseActivity; -import com.arialyy.simple.databinding.TestActivityMultiBinding; - -/** - * Created by AriaL on 2017/6/15. - */ - -public class TestMutilTaskSysDownload extends BaseActivity { - - @Override protected int setLayoutId() { - return R.layout.test_activity_multi; - } - - public void onClick(View view) { - String baseUrl = "http://file.bmob.cn/"; - String[] urlArray = { - "M02/3B/A4/oYYBAFaOeUSAc1QiAAFTbmA7AHs052.jpg", - "M02/3B/A4/oYYBAFaOeUaAfYC-AAFD8zf9NXc879.jpg", - "M02/3B/A4/oYYBAFaOeUuAOxhnAACSdmbqSac702.jpg", - "M02/3B/A4/oYYBAFaOeU2AFAIGAAFICximvXc924.jpg", - "M02/3B/A4/oYYBAFaOeVCAPWMQAAFm2KWCq_E721.jpg", - "M02/3B/A4/oYYBAFaOeVOAbiv9AAFfCTTgr94948.jpg", - "M02/3B/A4/oYYBAFaOeVaAMR3tAAFf3yTuuCM577.jpg", - "M02/3B/A4/oYYBAFaOeVmACEWhAAEt72ecbpg468.jpg", - "M02/3B/A4/oYYBAFaOeVyAHHt4AAFg9e9bRio507.jpg", - "M02/3B/A4/oYYBAFaOeV-AClYXAAESLGY0gag424.jpg", - "M02/3B/A4/oYYBAFaOeWKAA7N0AAF3omYOJUI703.jpg", - "M02/3B/A4/oYYBAFaOeWWAD2lrAAFN7eRFxBs575.jpg", - "M02/3B/A4/oYYBAFaOeWiAdCVEAAFg4273Dus313.jpg", - "M02/3B/A4/oYYBAFaOeWyAJDm5AAF8JVoGVb0705.jpg", - "M02/3B/A4/oYYBAFaOeW-AUoA8AAGjKiHkXUo181.jpg", - "M02/3B/A4/oYYBAFaOeXKABIamAAFU7J7vraE265.jpg", - "M02/3B/A5/oYYBAFaOeXaAW09jAAFf37qdwDA457.jpg", - "M02/3B/A5/oYYBAFaOeXmAWmS7AAFtLNpWjgo967.jpg", - "M02/3B/A5/oYYBAFaOeX2AQf9cAAF2fhwS2UE145.jpg", - "M02/3B/A5/oYYBAFaOeYCAKGnLAAFVAzks-qU937.jpg", - "M02/3B/A5/oYYBAFaOeYOAMODNAAF6HjTTMq4819.jpg", - "M02/3B/A5/oYYBAFaOeYeAbn8uAAFLSQLw48Q042.jpg", - "M02/3B/A5/oYYBAFaOeYqAMJThAAFtrNe4UNM047.jpg", - "M02/3B/A5/oYYBAFaOeY2AbnQvAAFNSXWn0Dc026.jpg", - "M02/3B/A5/oYYBAFaOeZCAIsr0AAFHZFEVhPc682.jpg", - "M02/3B/A5/oYYBAFaOeZOAGvITAAFqPmfcc9c471.jpg", - "M02/3B/A5/oYYBAFaOeZaATvjbAAFHDmALnhE003.jpg", - "M02/3B/A5/oYYBAFaOeZmAJPuVAAFfPJC2wsE319.jpg", - "M02/3B/A5/oYYBAFaOeZyAXtAmAAFfArJNwtM371.jpg", - "M02/3B/A5/oYYBAFaOeZ-AGZN0AAFgqwYYCS8004.jpg", - "M02/3B/A5/oYYBAFaOeaOAbbrGAAFcq59JjUo205.jpg", - "M02/3B/A5/oYYBAFaOeaSAdFyoAACaxVxgUJA092.jpg" - }; - int maxNum = Aria.get(this).getDownloadConfig().getMaxTaskNum(); - Aria.get(this).setDownloadQueueMod(QueueMod.NOW); - for (int i = 0; i < urlArray.length; i++) { - Aria.download(this) - .load(baseUrl + urlArray[i]) - .setFilePath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg") - //.addHeader("Accept-Encoding", "gzip,deflate,sdcn") - .start(); - //if (i < maxNum) { - // Aria.download(this) - // .load(baseUrl + urlArray[i]) - // .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg") - // //.addHeader("Accept-Encoding", "gzip,deflate,sdcn") - // .start(); - //} else { - // Aria.download(this) - // .load(baseUrl + urlArray[i]) - // .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg") - // //.addHeader("Accept-Encoding", "gzip,deflate,sdcn") - // .add(); - //} - } - } -} +package com.arialyy.simple.core.test; + +import android.os.Environment; +import android.view.View; +import com.arialyy.aria.core.Aria; +import com.arialyy.aria.core.common.QueueMod; +import com.arialyy.simple.R; +import com.arialyy.simple.base.BaseActivity; +import com.arialyy.simple.databinding.TestActivityMultiBinding; + +/** + * Created by AriaL on 2017/6/15. + */ + +public class TestMutilTaskSysDownload extends BaseActivity { + + @Override protected int setLayoutId() { + return R.layout.test_activity_multi; + } + + public void onClick(View view) { + String baseUrl = "http://file.bmob.cn/"; + String[] urlArray = { + "M02/3B/A4/oYYBAFaOeUSAc1QiAAFTbmA7AHs052.jpg", + "M02/3B/A4/oYYBAFaOeUaAfYC-AAFD8zf9NXc879.jpg", + "M02/3B/A4/oYYBAFaOeUuAOxhnAACSdmbqSac702.jpg", + "M02/3B/A4/oYYBAFaOeU2AFAIGAAFICximvXc924.jpg", + "M02/3B/A4/oYYBAFaOeVCAPWMQAAFm2KWCq_E721.jpg", + "M02/3B/A4/oYYBAFaOeVOAbiv9AAFfCTTgr94948.jpg", + "M02/3B/A4/oYYBAFaOeVaAMR3tAAFf3yTuuCM577.jpg", + "M02/3B/A4/oYYBAFaOeVmACEWhAAEt72ecbpg468.jpg", + "M02/3B/A4/oYYBAFaOeVyAHHt4AAFg9e9bRio507.jpg", + "M02/3B/A4/oYYBAFaOeV-AClYXAAESLGY0gag424.jpg", + "M02/3B/A4/oYYBAFaOeWKAA7N0AAF3omYOJUI703.jpg", + "M02/3B/A4/oYYBAFaOeWWAD2lrAAFN7eRFxBs575.jpg", + "M02/3B/A4/oYYBAFaOeWiAdCVEAAFg4273Dus313.jpg", + "M02/3B/A4/oYYBAFaOeWyAJDm5AAF8JVoGVb0705.jpg", + "M02/3B/A4/oYYBAFaOeW-AUoA8AAGjKiHkXUo181.jpg", + "M02/3B/A4/oYYBAFaOeXKABIamAAFU7J7vraE265.jpg", + "M02/3B/A5/oYYBAFaOeXaAW09jAAFf37qdwDA457.jpg", + "M02/3B/A5/oYYBAFaOeXmAWmS7AAFtLNpWjgo967.jpg", + "M02/3B/A5/oYYBAFaOeX2AQf9cAAF2fhwS2UE145.jpg", + "M02/3B/A5/oYYBAFaOeYCAKGnLAAFVAzks-qU937.jpg", + "M02/3B/A5/oYYBAFaOeYOAMODNAAF6HjTTMq4819.jpg", + "M02/3B/A5/oYYBAFaOeYeAbn8uAAFLSQLw48Q042.jpg", + "M02/3B/A5/oYYBAFaOeYqAMJThAAFtrNe4UNM047.jpg", + "M02/3B/A5/oYYBAFaOeY2AbnQvAAFNSXWn0Dc026.jpg", + "M02/3B/A5/oYYBAFaOeZCAIsr0AAFHZFEVhPc682.jpg", + "M02/3B/A5/oYYBAFaOeZOAGvITAAFqPmfcc9c471.jpg", + "M02/3B/A5/oYYBAFaOeZaATvjbAAFHDmALnhE003.jpg", + "M02/3B/A5/oYYBAFaOeZmAJPuVAAFfPJC2wsE319.jpg", + "M02/3B/A5/oYYBAFaOeZyAXtAmAAFfArJNwtM371.jpg", + "M02/3B/A5/oYYBAFaOeZ-AGZN0AAFgqwYYCS8004.jpg", + "M02/3B/A5/oYYBAFaOeaOAbbrGAAFcq59JjUo205.jpg", + "M02/3B/A5/oYYBAFaOeaSAdFyoAACaxVxgUJA092.jpg" + }; + int maxNum = Aria.get(this).getDownloadConfig().getMaxTaskNum(); + Aria.get(this).setDownloadQueueMod(QueueMod.NOW); + for (int i = 0; i < urlArray.length; i++) { + Aria.download(this) + .load(baseUrl + urlArray[i]) + .setFilePath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg") + //.addHeader("Accept-Encoding", "gzip,deflate,sdcn") + .start(); + //if (i < maxNum) { + // Aria.download(this) + // .load(baseUrl + urlArray[i]) + // .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg") + // //.addHeader("Accept-Encoding", "gzip,deflate,sdcn") + // .start(); + //} else { + // Aria.download(this) + // .load(baseUrl + urlArray[i]) + // .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg") + // //.addHeader("Accept-Encoding", "gzip,deflate,sdcn") + // .add(); + //} + } + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cfd04d89..2e4adb69 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,26 +64,16 @@ - http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk - http://static.gaoshouyou.com/d/21/e8/61218d78d0e8b79df68dbc18dd484c97.apk - http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk http://static.gaoshouyou.com/d/d4/4f/d6d48db3794fb9ecf47e83c346570881.apk - - - - - - - - 阴阳师 - 奇迹暖暖 - 幻影纹章 - 史上最坑爹的游戏10 - 鲜果消消乐 - 航海奇迹 + 王者荣耀 + 植物大战僵尸 + 部落冲突 + 瘟疫公司 + 水上公园大战 + 死亡之雨 test_1 test_2 @@ -91,13 +81,12 @@ - https://g37.gdl.netease.com/onmyoji_netease_10_1.0.20.apk - http://static.gaoshouyou.com/d/eb/f2/dfeba30541f209ab8a50d847fc1661ce.apk - http://rs.0.gaoshouyou.com/d/51/46/58514d126c46b8a3f27fc8c7db3b09ec.apk - http://rs.0.gaoshouyou.com/d/23/69/07238f952669727878d7a0e180534c8b.apk - http://rs.0.gaoshouyou.com/d/e7/3d/73e716d3353de5b479fcf7da8d36a5ef.apk - http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk - + https://downs.muzhiwan.com/2019/06/28/com.tencent.tmgp.sgame5d15f9df3bb4d.gpk + https://downs.muzhiwan.com/2017/03/15/com.ea.game.pvz2_row58c8bfc00eea8.gpk + https://downs.muzhiwan.com/2019/07/04/com.supercell.clashofclans.ewan.mzw_5d1da09397884.apk + https://downs.muzhiwan.com/2019/02/28/com.miniclip.plagueinc_5c77596c79179.apk + https://downs.muzhiwan.com/2019/06/03/com.aqua.slide_5cf4b69e90e6a.apk + https://downs.muzhiwan.com/2019/05/07/com.tinydevbox.deadrain2_g_5cd14a8aedb2f.apk http://dby-resource-android.duobeiyun.com/jz22a8508b4265466b9fb4bb29082eaa2d.zip http://dby-resource-android.duobeiyun.com/jz05fa8faf068145fcb25c93c8091297ad.zip http://dby-resource-android.duobeiyun.com/jz684e1b4c2f6b4576979e60fd95edebad.zip diff --git a/gradle.properties b/gradle.properties index 3f9aa62f..e720aeae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,27 +1,27 @@ -## Project-wide Gradle settings. -# -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx1024m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -# -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -#Wed Dec 07 20:19:22 CST 2016 -#org.gradle.daemon=true -#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -# gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/ -#systemProp.socksProxyHost=127.0.0.1 -#systemProp.socksProxyPort=1080 -#systemprop.socksProxyVersion=5 - -#Pandroid.debug.obsoleteApi=true - -# androidx https://developer.android.com/studio/preview/features/?hl=zh-cn#androidx_migration -#android.useAndroidX=true +## Project-wide Gradle settings. +# +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx1024m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +#Wed Dec 07 20:19:22 CST 2016 +#org.gradle.daemon=true +#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 +# gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/ +#systemProp.socksProxyHost=127.0.0.1 +#systemProp.socksProxyPort=1080 +#systemprop.socksProxyVersion=5 + +#Pandroid.debug.obsoleteApi=true + +# androidx https://developer.android.com/studio/preview/features/?hl=zh-cn#androidx_migration +#android.useAndroidX=true #android.enableJetifier=true \ No newline at end of file From a5fc5d0bcfacb42139b088f746beb7394c90a8c0 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Tue, 23 Jul 2019 20:52:30 +0800 Subject: [PATCH 2/2] fix bug https://github.com/AriaLyy/Aria/issues/429 --- .../main/java/com/arialyy/aria/core/AriaManager.java | 10 ++++------ .../core/download/downloader/HttpFileInfoThread.java | 9 +++++++-- README.md | 1 - build.gradle | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index 21b80459..d99589ff 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -161,13 +161,11 @@ import org.xml.sax.SAXException; * 初始化数据库 */ private void initDb(Context context) { - // 这个地方错误了,获取数据库路径见:https://www.jianshu.com/p/815c9efc5449 String oldDbName = "AriaLyyDb"; - String oldDbPath = context.getDatabasePath(oldDbName).getPath(); - File db = new File(oldDbPath); - File dbConfig = new File(String.format("%s/%s", db.getParent(), "AriaLyyDb-journal")); - if (db.exists()) { - db.renameTo(new File(String.format("%s/%s", db.getParent(), "AndroidAria.db"))); + File oldDbFile = context.getDatabasePath(oldDbName); + if (oldDbFile != null && oldDbFile.exists()) { + File dbConfig = new File(String.format("%s/%s", oldDbFile.getParent(), "AriaLyyDb-journal")); + oldDbFile.renameTo(new File(String.format("%s/%s", oldDbFile.getParent(), "AndroidAria.db"))); // 如果数据库是在/data/data/{packagename}/databases/下面,journal文件因权限问题将无法删除和重命名 if (dbConfig.exists()) { dbConfig.delete(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 78f7a229..2bee53b4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -16,6 +16,7 @@ package com.arialyy.aria.core.download.downloader; import android.net.TrafficStats; +import android.net.Uri; import android.os.Process; import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; @@ -284,13 +285,17 @@ public class HttpFileInfoThread implements Runnable { */ private void handleUrlReTurn(HttpURLConnection conn, String newUrl) throws IOException { ALog.d(TAG, "30x跳转,新url为【" + newUrl + "】"); - if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null") || !newUrl.startsWith( - "http")) { + if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) { if (onFileInfoCallback != null) { onFileInfoCallback.onFail(mEntity, new TaskException(TAG, "获取重定向链接失败"), false); } return; } + if (newUrl.startsWith("/")) { + Uri uri = Uri.parse(mEntity.getUrl()); + newUrl = uri.getHost() + newUrl; + } + if (!CheckUtil.checkUrlNotThrow(newUrl)) { failDownload(new TaskException(TAG, "下载失败,重定向url错误"), false); return; diff --git a/README.md b/README.md index a695aef5..99598aee 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,6 @@ protected void onCreate(Bundle savedInstanceState) { ## 其他 有任何问题,可以在[issues](https://github.com/AriaLyy/Aria/issues)给我留言反馈。
在提交问题前,希望你已经查看过[wiki](https://aria.laoyuyu.me/aria_doc/)或搜索过[issues](https://github.com/AriaLyy/Aria/issues)。
- 交流群:524329160 *** diff --git a/build.gradle b/build.gradle index 1fac0216..05b0c05b 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.6.5' + publishVersion = '3.6.6_beta_1' // publishVersion = '1.0.4' //FTP插件 repoName='maven' desc = 'android 下载框架'