diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java index 991d50bd..8bc5bd04 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java @@ -284,7 +284,6 @@ public abstract class AbsGroupUtil implements IUtil { } mTasksMap.put(te.getUrl(), te); } - updateFileSize(); } @Override public void start() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java index 32949d9f..ac9b1cea 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java @@ -35,6 +35,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { private final String TAG = "DownloadGroupUtil"; private ExecutorService mInfoPool; private int mInitCompleteNum, mInitFailNum; + private boolean isStop = false; /** * 文件信息回调组 @@ -53,6 +54,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { @Override public void onCancel() { super.onCancel(); + isStop = true; if (!mInfoPool.isShutdown()) { mInfoPool.shutdown(); } @@ -60,6 +62,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { @Override protected void onStop() { super.onStop(); + isStop = true; if (!mInfoPool.isShutdown()) { mInfoPool.shutdown(); } @@ -67,6 +70,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { @Override protected void onStart() { super.onStart(); + isStop = false; if (mCompleteNum == mGroupSize) { mListener.onComplete(); return; @@ -83,7 +87,9 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { if (taskEntity != null) { if (taskEntity.getState() != IEntity.STATE_FAIL && taskEntity.getState() != IEntity.STATE_WAIT) { + mInitCompleteNum++; createChildDownload(taskEntity); + checkStartFlow(); } else { mInfoPool.execute(createFileInfoThread(taskEntity)); } @@ -105,6 +111,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { int failNum = 0; @Override public void onComplete(String url, CompleteInfo info) { + if (isStop) return; DownloadTaskEntity te = mExeMap.get(url); if (te != null) { if (isNeedLoadFileSize) { @@ -112,15 +119,13 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { } createChildDownload(te); } - mInitCompleteNum ++; + mInitCompleteNum++; - if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) { - startRunningFlow(); - updateFileSize(); - } + checkStartFlow(); } @Override public void onFail(String url, String errorMsg, boolean needRetry) { + if (isStop) return; ALog.e(TAG, "任务【" + url + "】初始化失败。"); DownloadTaskEntity te = mExeMap.get(url); if (te != null) { @@ -136,14 +141,23 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { // mInitFailNum++; //} //failNum++; - mInitFailNum ++; - if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) { - startRunningFlow(); - updateFileSize(); - } + mInitFailNum++; + checkStartFlow(); } }; } return new HttpFileInfoThread(taskEntity, callback); } + + /** + * 检查能否启动下载流程 + */ + private void checkStartFlow() { + synchronized (DownloadGroupUtil.class) { + if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) { + startRunningFlow(); + updateFileSize(); + } + } + } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java index c2946ce1..ee7f2a4d 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java @@ -30,6 +30,7 @@ import java.lang.reflect.Field; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Date; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -217,8 +218,8 @@ class DelegateFind extends AbsDelegate { } List wrappers = new ArrayList<>(); - Map tempParent = new WeakHashMap<>(); // 所有父表元素,key为父表主键的值 - Map> tempChild = new WeakHashMap<>(); // 所有的字表元素,key为父表主键的值 + Map tempParent = new LinkedHashMap<>(); // 所有父表元素,key为父表主键的值 + Map> tempChild = new LinkedHashMap<>(); // 所有的字表元素,key为父表主键的值 Object old = null; while (cursor.moveToNext()) { diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index 629b64ce..122d115f 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -888,11 +888,6 @@ public class CommonUtil { ALog.w(TAG, "修改任务记录失败,新文件路径和旧文件路径一致"); return; } - File oldFile = new File(oldPath); - if (!oldFile.exists()) { - ALog.w(TAG, "修改任务记录失败,文件【" + oldPath + "】不存在"); - return; - } TaskRecord record = DbHelper.getTaskRecord(oldPath); if (record == null) { ALog.w(TAG, "修改任务记录失败,文件【" + oldPath + "】对应的任务记录不存在"); diff --git a/DEV_LOG.md b/DEV_LOG.md index b5ab1e9b..43af1526 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -2,6 +2,7 @@ + v_3.4.2 - fix bug https://github.com/AriaLyy/Aria/issues/248 - fix bug https://github.com/AriaLyy/Aria/issues/247 + - fix bug https://github.com/AriaLyy/Aria/issues/250 + v_3.4.1 - 移除记录配置文件,改用数据库记录任务记录 - 上传配置添加io超时时间、缓存大小配置 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c3a993d0..c65e5e79 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,9 +16,9 @@ android:theme="@style/AppTheme.NoActionBar"> - + diff --git a/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java b/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java index bbbdb32c..bf4ab92f 100644 --- a/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java +++ b/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java @@ -19,7 +19,8 @@ public class AnyRunActivity extends BaseActivity { String[] urls; int index = 0; //String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk"; - String URL = "http://d1.showself.com/download/showself_android-s236279_release.apk"; + String URL = "http://58.213.157.242:8081/sims_file/rest/v1/file/mshd_touchscreen_ms/guideFile/41c33556-dc4a-4d78-bb76-b9f627f94448.mp4/%E5%85%AB%E5%8D%A6%E6%B4%B2%E5%8D%97%E4%BA%AC%E5%86%9C%E4%B8%9A%E5%98%89%E5%B9%B4%E5%8D%8E0511.mp4"; + //String URL = "http://d1.showself.com/download/showself_android-s236279_release.apk"; //String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //private final String URL = "ftp://192.168.29.140:21/download/AriaPrj.rar"; //String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; diff --git a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java index fd4fb8fe..998acc63 100644 --- a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java +++ b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java @@ -38,7 +38,7 @@ public class AnyRunnModule { } @Download.onTaskRunning protected void running(DownloadTask task) { - Log.d(TAG, "running"); + Log.d(TAG, "running;Percent = " + task.getPercent()); } @Download.onTaskResume void taskResume(DownloadTask task) { @@ -68,7 +68,7 @@ public class AnyRunnModule { .load(url) //.addHeader("Accept-Encoding", "gzip") .setRequestMode(RequestEnum.GET) - .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg12345678.apk") + .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/abcd.mp4") //.resetState() .start(); //String[] urls = new String[] { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0706bd39..911363ca 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,7 +64,7 @@ - + http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk http://hzdown.muzhiwan.com/2017/09/05/com.mir.iphone.empire83jie.mzw_59ae6d5a3638d.apk @@ -81,7 +81,7 @@ - + 战斗吧剑灵.apk 天魔幻想.apk