diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java index e690524d..675a918a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java @@ -17,8 +17,10 @@ package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.command.AbsCmd; +import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.upload.UploadTaskEntity; @@ -40,8 +42,8 @@ public abstract class AbsNormalCmd extends AbsCmd { * @param targetName 产生任务的对象名 */ AbsNormalCmd(String targetName, T entity) { - canExeCmd = CheckUtil.checkCmdEntity(entity, - !(this instanceof CancelCmd) || !(this instanceof StopCmd)); + //canExeCmd = CheckUtil.checkCmdEntity(entity, + // !(this instanceof CancelCmd) || !(this instanceof StopCmd)); mTargetName = targetName; mTaskEntity = entity; TAG = CommonUtil.getClassName(this); @@ -51,6 +53,9 @@ public abstract class AbsNormalCmd extends AbsCmd { } else if (entity instanceof UploadTaskEntity) { mQueue = UploadTaskQueue.getInstance(); isDownloadCmd = false; + } else if (entity instanceof DownloadGroupTaskEntity) { + mQueue = DownloadGroupTaskQueue.getInstance(); + isDownloadCmd = true; } } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java index 42c9040c..ff0b683a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java @@ -19,7 +19,6 @@ import android.os.Parcel; import com.arialyy.aria.core.inf.AbsGroupEntity; import com.arialyy.aria.orm.OneToMany; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; /** @@ -28,26 +27,25 @@ import java.util.List; */ public class DownloadGroupEntity extends AbsGroupEntity { - @OneToMany(table = DownloadEntity.class, key = "groupName") private List - mSubtask = new ArrayList<>(); + @OneToMany(table = DownloadEntity.class, key = "groupName") private List subtask = new ArrayList<>(); //任务组下载文件的文件夹地址 - private String mDirPath = ""; + private String dirPath = ""; public List getSubTask() { - return mSubtask; + return subtask; } public void setSubTasks(List subTasks) { - this.mSubtask = subTasks; + this.subtask = subTasks; } public String getDirPath() { - return mDirPath; + return dirPath; } public void setDirPath(String dirPath) { - this.mDirPath = dirPath; + this.dirPath = dirPath; } public DownloadGroupEntity() { @@ -59,14 +57,14 @@ public class DownloadGroupEntity extends AbsGroupEntity { @Override public void writeToParcel(Parcel dest, int flags) { super.writeToParcel(dest, flags); - dest.writeTypedList(this.mSubtask); - dest.writeString(this.mDirPath); + dest.writeTypedList(this.subtask); + dest.writeString(this.dirPath); } protected DownloadGroupEntity(Parcel in) { super(in); - this.mSubtask = in.createTypedArrayList(DownloadEntity.CREATOR); - this.mDirPath = in.readString(); + this.subtask = in.createTypedArrayList(DownloadEntity.CREATOR); + this.dirPath = in.readString(); } public static final Creator CREATOR = new Creator() { 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 11a03da7..01068408 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 @@ -50,7 +50,8 @@ public class DownloadGroupTarget if (mTaskEntity == null) { mTaskEntity = new DownloadGroupTaskEntity(); mTaskEntity.key = mGroupName; - mTaskEntity.entity = new DownloadGroupEntity(); + mTaskEntity.entity = getDownloadGroupEntity(); + mTaskEntity.insert(); } if (mTaskEntity.entity == null) { mTaskEntity.entity = getDownloadGroupEntity(); @@ -63,6 +64,9 @@ public class DownloadGroupTarget DbEntity.findFirst(DownloadGroupEntity.class, "groupName=?", mGroupName); if (entity == null) { entity = new DownloadGroupEntity(); + entity.setGroupName(mGroupName); + entity.setUrlmd5(mGroupName); + entity.insert(); } return entity; } @@ -101,12 +105,12 @@ public class DownloadGroupTarget file.mkdirs(); } + mEntity.setDirPath(groupDirPath); if (!TextUtils.isEmpty(mEntity.getDirPath())) { reChangeDirPath(groupDirPath); } else { mEntity.setSubTasks(createSubTask()); } - mEntity.setDirPath(groupDirPath); mEntity.update(); isSetDirPathed = true; return this; @@ -157,15 +161,26 @@ public class DownloadGroupTarget for (int i = 0, len = mUrls.size(); i < len; i++) { DownloadEntity entity = new DownloadEntity(); entity.setDownloadUrl(mUrls.get(i)); - String fileName = mSubtaskFileName.get(i); - if (TextUtils.isEmpty(fileName)) { - fileName = CommonUtil.keyToHashKey(mUrls.get(i)); - } + String fileName = mSubtaskFileName.isEmpty() ? CommonUtil.keyToHashKey(mUrls.get(i)) + : mSubtaskFileName.get(i); entity.setDownloadPath(mEntity.getDirPath() + "/" + fileName); entity.setGroupName(mGroupName); - entity.save(); + entity.setGroupChild(true); + entity.setFileName(fileName); + entity.insert(); list.add(entity); } return list; } + + ///** + // * 创建文件名,如果url链接有后缀名,则使用url中的后缀名 + // * @return url 的 hashKey + // */ + //private String createFileName(String url){ + // if (url.contains(".")){ + // int s = url.lastIndexOf("."); + // String fileName = url.substring() + // } + //} } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java index 9c3d778e..0307a31a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java @@ -51,7 +51,7 @@ public class DownloadGroupTask extends AbsGroupTask mapping = new HashMap<>(); static String DB_NAME; - static int VERSION = 6; + static int VERSION = 7; static { if (TextUtils.isEmpty(DB_NAME)) { diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java b/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java index a909b218..c8636c8c 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java @@ -125,7 +125,7 @@ public class DbEntity { */ public void save() { synchronized (LOCK) { - if (DbUtil.getInstance().tableExists(getClass()) && thisIsExist()) { + if (thisIsExist()) { update(); } else { insert(); 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 65c4a961..988359c8 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -373,6 +373,14 @@ final class SqlHelper extends SQLiteOpenHelper { close(db); } + /** + * 保存一对一的数据 + * @param field + */ + private void saveOneToOneFile(Field field){ + + } + /** * 获取一对一参数 */ @@ -602,7 +610,7 @@ final class SqlHelper extends SQLiteOpenHelper { if (TextUtils.isEmpty(primaryData)) continue; List list = findForeignData(db, primaryData, params); if (list == null) continue; - field.set(entity, findForeignData(db, primaryKey, params)); + field.set(entity, findForeignData(db, primaryData, params)); } else if (isOneToOne(field)) { String primaryKey = getPrimaryName(clazz); if (TextUtils.isEmpty(primaryKey)) { diff --git a/app/src/main/java/com/arialyy/simple/MainActivity.java b/app/src/main/java/com/arialyy/simple/MainActivity.java index 92a733e0..5867a402 100644 --- a/app/src/main/java/com/arialyy/simple/MainActivity.java +++ b/app/src/main/java/com/arialyy/simple/MainActivity.java @@ -23,6 +23,7 @@ import butterknife.OnClick; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivityMainBinding; import com.arialyy.simple.download.DownloadActivity; +import com.arialyy.simple.download.group.DownloadGroupActivity; import com.arialyy.simple.test.TestMutilTaskSysDownload; import com.arialyy.simple.upload.UploadActivity; @@ -53,7 +54,7 @@ public class MainActivity extends BaseActivity { startActivity(new Intent(this, UploadActivity.class)); break; case R.id.download_task_group: - + startActivity(new Intent(this, DownloadGroupActivity.class)); break; } 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 b5968f45..e7666bc2 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 @@ -61,26 +61,25 @@ public class DownloadGroupActivity extends BaseActivity