diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java index c21012a0..81eb2128 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java @@ -100,7 +100,7 @@ class ConfigHelper extends DefaultHandler { } } else if (isAppConfig) { String value = attributes.getValue("value"); - switch (value) { + switch (qName) { case "useAriaCrashHandler": loadUseAriaCrashHandler(value); break; 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 6cf11bfa..fd79a6a0 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 @@ -60,7 +60,7 @@ final class ResumeAllCmd extends AbsNormalCmd { List tempList = new ArrayList<>(); if (type == 1) { List wrappers = DbEntity.findRelationData(DTEWrapper.class, - "DownloadTaskEntity.isGroupTask=false and DownloadTaskEntity.state!=?", "1"); + "DownloadTaskEntity.isGroupTask=? and DownloadTaskEntity.state!=?", "false", "1"); if (wrappers != null && !wrappers.isEmpty()) { for (DTEWrapper w : wrappers) { tempList.add(w.taskEntity); @@ -75,8 +75,8 @@ final class ResumeAllCmd extends AbsNormalCmd { } } } else if (type == 3) { - List wrappers = DbEntity.findRelationData(UTEWrapper.class, - "UploadTaskEntity.state!=?", "1"); + List wrappers = + DbEntity.findRelationData(UTEWrapper.class, "UploadTaskEntity.state!=?", "1"); if (wrappers != null && !wrappers.isEmpty()) { for (UTEWrapper w : wrappers) { tempList.add(w.taskEntity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java index 80ff11d8..1d3749c0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java @@ -119,7 +119,7 @@ class StartCmd extends AbsNormalCmd { List waitList = new ArrayList<>(); if (type == 1) { List wrappers = DbEntity.findRelationData(DTEWrapper.class, - "DownloadTaskEntity.isGroupTask=false and DownloadTaskEntity.state=?", "3"); + "DownloadTaskEntity.isGroupTask=? and DownloadTaskEntity.state=?", "false", "3"); if (wrappers != null && !wrappers.isEmpty()) { for (DTEWrapper w : wrappers) { waitList.add(w.taskEntity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java index 79c322c7..cff59599 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java @@ -16,6 +16,7 @@ package com.arialyy.aria.core.download; import android.text.TextUtils; +import android.util.Log; import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.util.ALog; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java index 5a938021..4b5fba95 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java @@ -155,9 +155,9 @@ public class DownloadGroupTarget extends BaseGroupTarget { * 更新所有改动的子任务文件名 */ private void updateSingleSubFileName() { - List entities = mEntity.getSubEntities(); + List entities = mTaskEntity.getSubTaskEntities(); int i = 0; - for (DownloadEntity entity : entities) { + for (DownloadTaskEntity entity : entities) { if (i < mSubNameTemp.size()) { String newName = mSubNameTemp.get(i); updateSingleSubFileName(entity, newName); @@ -215,7 +215,8 @@ public class DownloadGroupTarget extends BaseGroupTarget { /** * 更新单个子任务文件名 */ - private void updateSingleSubFileName(DownloadEntity entity, String newName) { + private void updateSingleSubFileName(DownloadTaskEntity taskEntity, String newName) { + DownloadEntity entity = taskEntity.getEntity(); if (!newName.equals(entity.getFileName())) { String oldPath = mEntity.getDirPath() + "/" + entity.getFileName(); String newPath = mEntity.getDirPath() + "/" + newName; @@ -224,8 +225,8 @@ public class DownloadGroupTarget extends BaseGroupTarget { oldFile.renameTo(new File(newPath)); } CommonUtil.renameDownloadConfig(oldFile.getName(), newName); - // TODO: 2018/4/11 需要校验数据库级联操作是否生效 entity.setDownloadPath(newPath); + taskEntity.key = newPath; entity.setFileName(newName); entity.update(); } 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 633343ec..742bec2e 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 @@ -308,10 +308,8 @@ public abstract class AbsGroupUtil implements IUtil { } private void clearState(){ - mExeMap.clear(); mDownloaderMap.clear(); mFailMap.clear(); - mTasksMap.clear(); } private void closeTimer(boolean isRunning) { 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 89352252..32949d9f 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 @@ -78,20 +78,17 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { return; } Set keys = mExeMap.keySet(); - int i = 0; for (String key : keys) { DownloadTaskEntity taskEntity = mExeMap.get(key); if (taskEntity != null) { if (taskEntity.getState() != IEntity.STATE_FAIL && taskEntity.getState() != IEntity.STATE_WAIT) { createChildDownload(taskEntity); - i++; } else { mInfoPool.execute(createFileInfoThread(taskEntity)); } } } - if (i != 0 && i == mExeMap.size()) startRunningFlow(); if (mCurrentLocation == mTotalLen) { mListener.onComplete(); } @@ -115,6 +112,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { } createChildDownload(te); } + mInitCompleteNum ++; if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) { startRunningFlow(); diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java index 41e94823..5eafd31a 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java @@ -18,6 +18,7 @@ package com.arialyy.aria.orm; import android.content.ContentValues; import android.database.sqlite.SQLiteDatabase; import android.text.TextUtils; +import android.util.Log; import com.arialyy.aria.orm.annotation.Primary; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; @@ -90,7 +91,6 @@ class DelegateUpdate extends AbsDelegate { } catch (IllegalAccessException e) { e.printStackTrace(); } - //print(MODIFY_DATA, sql.toString()); if (values.size() > 0) { db.update(CommonUtil.getClassName(dbEntity), values, "rowid=?", new String[] { String.valueOf(dbEntity.rowID) }); diff --git a/Aria/src/main/java/com/arialyy/aria/util/AriaCrashHandler.java b/Aria/src/main/java/com/arialyy/aria/util/AriaCrashHandler.java index 20a17483..f6b30f82 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/AriaCrashHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/util/AriaCrashHandler.java @@ -35,7 +35,8 @@ public class AriaCrashHandler implements Thread.UncaughtExceptionHandler { @Override public void uncaughtException(Thread thread, Throwable ex) { - ALog.d(thread.getName(), ex.getLocalizedMessage()); + ex.printStackTrace(); + //ALog.d(thread.getName(), ex.getLocalizedMessage()); handleException(thread.getName(), ex); try { Thread.sleep(1000); diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ffe769e9..bf4f2dc0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,11 +14,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 7b163305..ce5f8a8f 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -46,7 +46,7 @@ public class SingleTaskActivity extends BaseActivity { //"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://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载 + "http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载 //"https://static.donguo.me//video/ip/course/pfys_1.mp4"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @@ -107,67 +107,87 @@ public class SingleTaskActivity extends BaseActivity { } @Download.onWait void onWait(DownloadTask task) { - Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); + if (task.getKey().equals(DOWNLOAD_URL)) { + Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); + } } @Download.onPre protected void onPre(DownloadTask task) { - setBtState(false); + if (task.getKey().equals(DOWNLOAD_URL)) { + setBtState(false); + } } @Download.onTaskStart void taskStart(DownloadTask task) { - getBinding().setFileSize(task.getConvertFileSize()); + if (task.getKey().equals(DOWNLOAD_URL)) { + getBinding().setFileSize(task.getConvertFileSize()); + } } @Download.onTaskRunning protected void running(DownloadTask task) { - - long len = task.getFileSize(); - if (len == 0) { - getBinding().setProgress(0); - } else { - getBinding().setProgress(task.getPercent()); + if (task.getKey().equals(DOWNLOAD_URL)) { + Log.d(TAG, task.getKey()); + long len = task.getFileSize(); + if (len == 0) { + getBinding().setProgress(0); + } else { + getBinding().setProgress(task.getPercent()); + } + getBinding().setSpeed(task.getConvertSpeed()); } - getBinding().setSpeed(task.getConvertSpeed()); } @Download.onTaskResume void taskResume(DownloadTask task) { - mStart.setText("暂停"); - setBtState(false); + if (task.getKey().equals(DOWNLOAD_URL)) { + mStart.setText("暂停"); + setBtState(false); + } } @Download.onTaskStop void taskStop(DownloadTask task) { - mStart.setText("恢复"); - setBtState(true); - getBinding().setSpeed(""); + if (task.getKey().equals(DOWNLOAD_URL)) { + mStart.setText("恢复"); + setBtState(true); + getBinding().setSpeed(""); + } } @Download.onTaskCancel void taskCancel(DownloadTask task) { - getBinding().setProgress(0); - Toast.makeText(SingleTaskActivity.this, "取消下载", Toast.LENGTH_SHORT).show(); - mStart.setText("开始"); - setBtState(true); - getBinding().setSpeed(""); - Log.d(TAG, "cancel"); + if (task.getKey().equals(DOWNLOAD_URL)) { + getBinding().setProgress(0); + Toast.makeText(SingleTaskActivity.this, "取消下载", Toast.LENGTH_SHORT).show(); + mStart.setText("开始"); + setBtState(true); + getBinding().setSpeed(""); + Log.d(TAG, "cancel"); + } } @Download.onTaskFail void taskFail(DownloadTask task) { - Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show(); - setBtState(true); + if (task.getKey().equals(DOWNLOAD_URL)) { + Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show(); + setBtState(true); + } } @Download.onTaskComplete void taskComplete(DownloadTask task) { - getBinding().setProgress(100); - Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show(); - mStart.setText("重新开始?"); - mCancel.setEnabled(false); - setBtState(true); - getBinding().setSpeed(""); - 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)); + if (task.getKey().equals(DOWNLOAD_URL)) { + getBinding().setProgress(100); + Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show(); + mStart.setText("重新开始?"); + mCancel.setEnabled(false); + setBtState(true); + getBinding().setSpeed(""); + 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)); + } } @Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) { - T.showShort(SingleTaskActivity.this, "该下载链接不支持断点"); + if (task.getKey().equals(DOWNLOAD_URL)) { + T.showShort(SingleTaskActivity.this, "该下载链接不支持断点"); + } } @Override protected int setLayoutId() { diff --git a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java index b0527c6f..fab70aaf 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java @@ -17,6 +17,7 @@ package com.arialyy.simple.download.group; import android.os.Bundle; import android.os.Environment; +import android.util.Log; import android.view.View; import butterknife.Bind; import com.arialyy.annotations.DownloadGroup; @@ -84,7 +85,7 @@ public class DownloadGroupActivity extends BaseActivity - 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 diff --git a/aria/src/main/java/com/arialyy/aria/core/Configuration.java b/aria/src/main/java/com/arialyy/aria/core/Configuration.java index aa527b1e..f8f46bff 100644 --- a/aria/src/main/java/com/arialyy/aria/core/Configuration.java +++ b/aria/src/main/java/com/arialyy/aria/core/Configuration.java @@ -154,11 +154,8 @@ class Configuration { Properties properties = CommonUtil.loadConfig(file); for (Field field : fields) { int m = field.getModifiers(); - if (field.isSynthetic() - || Modifier.isFinal(m) - || Modifier.isStatic(m) - || field.getName().equals("shadow$_klass_") - || field.getName().equals("shadow$_monitor_")) { + if (field.isSynthetic() || Modifier.isFinal(m) || Modifier.isStatic(m) || field.getName() + .equals("shadow$_klass_") || field.getName().equals("shadow$_monitor_")) { continue; } field.setAccessible(true); @@ -447,7 +444,7 @@ class Configuration { * 是否使用{@link AriaCrashHandler}来捕获异常 * {@code true} 使用;{@code false} 不使用 */ - Boolean useAriaCrashHandler; + boolean useAriaCrashHandler; /** * 设置Aria的日志级别 @@ -480,11 +477,11 @@ class Configuration { return logLevel; } - public Boolean getUseAriaCrashHandler() { + public boolean getUseAriaCrashHandler() { return useAriaCrashHandler; } - public AppConfig setUseAriaCrashHandler(Boolean useAriaCrashHandler) { + public AppConfig setUseAriaCrashHandler(boolean useAriaCrashHandler) { this.useAriaCrashHandler = useAriaCrashHandler; saveKey("useAriaCrashHandler", String.valueOf(useAriaCrashHandler)); if (useAriaCrashHandler) {