diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java index 56b8e17d..5d24fa67 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java @@ -29,7 +29,7 @@ import com.arialyy.aria.util.CommonUtil; * Created by AriaL on 2017/6/29. * 任务组命令 */ -public abstract class AbsGroupCmd extends AbsCmd { +abstract class AbsGroupCmd extends AbsCmd { /** * @param targetName 创建任务的对象名 diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java index 786dd6b8..a818d688 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java @@ -22,7 +22,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by AriaL on 2017/6/29. */ -public class GroupCmdFactory extends AbsCmdFactory { +class GroupCmdFactory extends AbsCmdFactory { /** * 启动任务 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java index 8ed5de0d..e848813b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java @@ -17,7 +17,6 @@ package com.arialyy.aria.core.command.normal; import android.util.Log; -import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index 7fdcafa2..be7815c1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -25,13 +25,10 @@ import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulerListener; import com.arialyy.aria.core.upload.ProxyHelper; import com.arialyy.aria.orm.DbEntity; -import com.arialyy.aria.orm.DbUtil; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; -import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Set; -import java.lang.reflect.Method; /** * Created by lyy on 2016/12/5. @@ -138,7 +135,8 @@ public class DownloadReceiver extends AbsReceiver { */ public DownloadEntity getDownloadEntity(String downloadUrl) { CheckUtil.checkDownloadUrl(downloadUrl); - return DbEntity.findFirst(DownloadEntity.class, "downloadUrl=?", downloadUrl); + return DbEntity.findFirst(DownloadEntity.class, "downloadUrl=? and isGroupChild='false'", + downloadUrl); } /** @@ -146,13 +144,14 @@ public class DownloadReceiver extends AbsReceiver { */ public DownloadTaskEntity getDownloadTask(String downloadUrl) { CheckUtil.checkDownloadUrl(downloadUrl); - return DbEntity.findFirst(DownloadTaskEntity.class, "key=?", downloadUrl); + return DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'", + downloadUrl); } /** * 通过下载链接获取保存在数据库的下载任务组实体 */ - public DownloadGroupTaskEntity getDownlaodGroupTask(List urls) { + public DownloadGroupTaskEntity getDownloadGroupTask(List urls) { CheckUtil.checkDownloadUrls(urls); String hashCode = CommonUtil.getMd5Code(urls); return DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", hashCode); @@ -165,8 +164,18 @@ public class DownloadReceiver extends AbsReceiver { return DownloadEntity.findFirst(DownloadEntity.class, "downloadUrl=?", downloadUrl) != null; } + /** + * 获取普通下载任务列表 + */ @Override public List getTaskList() { - return DownloadEntity.findAllData(DownloadEntity.class); + return DownloadEntity.findDatas(DownloadEntity.class, "isGroupChild=?", "false"); + } + + /** + * 获取任务组列表 + */ + public List getGroupTaskList() { + return DownloadEntity.findAllData(DownloadGroupTaskEntity.class); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java index ab91b62f..4dec4117 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java @@ -36,12 +36,9 @@ public class DownloadTarget DownloadTarget(String url, String targetName) { mTargetName = targetName; - DownloadEntity entity = DbEntity.findFirst(DownloadEntity.class, "downloadUrl=?", url); - if (entity == null) { - entity = getEntity(url); - } - mEntity = entity; - mTaskEntity = DbEntity.findFirst(DownloadTaskEntity.class, "key=?", entity.getDownloadPath()); + DownloadEntity entity = getEntity(url); + mTaskEntity = DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'", + entity.getDownloadPath()); if (mTaskEntity == null) { mTaskEntity = new DownloadTaskEntity(); mTaskEntity.key = entity.getDownloadPath(); @@ -49,8 +46,9 @@ public class DownloadTarget mTaskEntity.save(); } if (mTaskEntity.entity == null) { - mTaskEntity.entity = mEntity; + mTaskEntity.entity = entity; } + mEntity = entity; } /** 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 af3c693a..f688f8ba 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 @@ -76,24 +76,23 @@ public class DownloadGroupUtil implements IDownloadUtil { * 文件信息回调组 */ private SparseArray mFileInfoCallbacks = new SparseArray<>(); - - //任务总数 - private int mTaskNum = 0; - //已经完成的任务数 - private int mCompleteNum = 0; - //失败的任务数 - private int mFailNum = 0; /** * 该任务组对应的所有任务 */ private Map mTasksMap = new HashMap<>(); + //已经完成的任务数 + private int mCompleteNum = 0; + //失败的任务数 + private int mFailNum = 0; + //实际的下载任务数 + private int mActualTaskNum = 0; public DownloadGroupUtil(IDownloadListener listener, DownloadGroupTaskEntity taskEntity) { mListener = listener; mTaskEntity = taskEntity; mInfoPool = Executors.newCachedThreadPool(); mExePool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - mTaskNum = mTaskEntity.entity.getSubTask().size(); + mActualTaskNum = mTaskEntity.entity.getSubTask().size(); List tasks = DbEntity.findDatas(DownloadTaskEntity.class, "groupName=?", mTaskEntity.key); if (tasks != null && !tasks.isEmpty()) { @@ -224,12 +223,14 @@ public class DownloadGroupUtil implements IDownloadUtil { mFailMap.put(url, te); mFileInfoCallbacks.put(te.hashCode(), this); } - mInitFailNum++; //404链接不重试下载 - if (!errorMsg.contains("错误码:404")) { - if (failNum < 10) { - mInfoPool.execute(createFileInfoThread(te)); - } + if (failNum < 10 && !errorMsg.contains("错误码:404") && !errorMsg.contains( + "UnknownHostException")) { + mInfoPool.execute(createFileInfoThread(te)); + } else { + mInitFailNum++; + mActualTaskNum--; + if (mActualTaskNum < 0) mActualTaskNum = 0; } failNum++; if (mInitNum + mInitFailNum == mTaskEntity.getEntity().getSubTask().size()) { @@ -238,7 +239,6 @@ public class DownloadGroupUtil implements IDownloadUtil { } }; } - return new FileInfoThread(taskEntity, callback); } @@ -349,7 +349,7 @@ public class DownloadGroupUtil implements IDownloadUtil { @Override public void onComplete() { saveData(IEntity.STATE_COMPLETE, entity.getFileSize()); mCompleteNum++; - if (mCompleteNum >= mTaskNum) { + if (mCompleteNum + mFailNum >= mActualTaskNum) { mListener.onComplete(); closeTimer(); } @@ -368,6 +368,8 @@ public class DownloadGroupUtil implements IDownloadUtil { if (entity.getFailNum() < 5) { Downloader dt = mDownloaderMap.get(entity.getDownloadUrl()); dt.startDownload(); + } else { + mFailNum++; } } 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 6d943536..680007ec 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -32,7 +32,7 @@ import java.util.Map; public class DBConfig { static Map mapping = new HashMap<>(); static String DB_NAME; - static int VERSION = 8; + static int VERSION = 9; static { if (TextUtils.isEmpty(DB_NAME)) { 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 4d87cb04..11896bf2 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -375,9 +375,8 @@ final class SqlHelper extends SQLiteOpenHelper { /** * 保存一对一的数据 - * @param field */ - private void saveOneToOneFile(Field field){ + private void saveOneToOneFile(Field field) { } @@ -498,7 +497,8 @@ final class SqlHelper extends SQLiteOpenHelper { continue; } if (isPrimary(field)) { - sb.append(" PRIMARY KEY"); + //sb.append(" PRIMARY KEY"); + sb.append(" NOT NULL"); } sb.append(","); } diff --git a/AriaAnnotations/src/main/java/com/arialyy/annotations/AriaConstance.java b/AriaAnnotations/src/main/java/com/arialyy/annotations/AriaConstance.java index 3fd7e89a..0481539a 100644 --- a/AriaAnnotations/src/main/java/com/arialyy/annotations/AriaConstance.java +++ b/AriaAnnotations/src/main/java/com/arialyy/annotations/AriaConstance.java @@ -21,5 +21,25 @@ package com.arialyy.annotations; public interface AriaConstance { String NO_URL = ""; + + /** + * 注解方法为普通任务下载 + */ + int DOWNLOAD = 0xa1; + + /** + * 注解方法为任务组下载 + */ + int DOWNLOAD_GROUP = 0xa2; + + /** + * 注解方法为普通任务上传 + */ + int UPLOAD = 0xb1; + + /** + * 注解方法为任务组上传 + */ + int UPLOAD_GROUP = 0xb2; } diff --git a/app/src/main/java/com/arialyy/simple/download/DownloadModule.java b/app/src/main/java/com/arialyy/simple/download/DownloadModule.java index 56ad3738..faef1cf3 100644 --- a/app/src/main/java/com/arialyy/simple/download/DownloadModule.java +++ b/app/src/main/java/com/arialyy/simple/download/DownloadModule.java @@ -16,27 +16,16 @@ package com.arialyy.simple.download; -import android.content.BroadcastReceiver; import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; import android.content.res.Resources; import android.os.Environment; -import android.os.Handler; -import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.util.CommonUtil; -import com.arialyy.frame.util.AndroidUtils; -import com.arialyy.frame.util.StringUtil; -import com.arialyy.frame.util.show.L; import com.arialyy.simple.R; import com.arialyy.simple.download.multi_download.FileListEntity; import com.arialyy.simple.base.BaseModule; -import java.io.File; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import java.util.Random; /** * Created by Lyy on 2016/9/27. 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 22c73f3a..2a8ae080 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 @@ -25,7 +25,6 @@ import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; -import com.arialyy.aria.util.CommonUtil; import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.T; import com.arialyy.simple.R; @@ -48,12 +47,16 @@ public class DownloadGroupActivity extends BaseActivity