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 1c527810..c8423d3e 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 @@ -56,16 +56,22 @@ public class DownloadTarget } private void initTask(DownloadEntity entity) { - mTaskEntity = DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'", - entity.getDownloadPath()); + mTaskEntity = + DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false' and url=?", + entity.getDownloadPath(), entity.getUrl()); if (mTaskEntity == null) { mTaskEntity = new DownloadTaskEntity(); + mTaskEntity.url = entity.getUrl(); mTaskEntity.key = entity.getDownloadPath(); mTaskEntity.entity = entity; mTaskEntity.save(); - } - if (mTaskEntity.entity == null || TextUtils.isEmpty(mTaskEntity.entity.getUrl())) { + } else if (mTaskEntity.entity == null || TextUtils.isEmpty(mTaskEntity.entity.getUrl())) { + mTaskEntity.entity = entity; + mTaskEntity.save(); + } else if (!mTaskEntity.entity.getUrl().equals(entity.getUrl())) { //处理地址切换而保存路径不变 + mTaskEntity.entity.deleteData(); mTaskEntity.entity = entity; + entity.save(); mTaskEntity.save(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java index d947d2e4..51f5f9ad 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java @@ -27,6 +27,11 @@ public class DownloadTaskEntity extends AbsTaskEntity { @OneToOne(table = DownloadEntity.class, key = "downloadPath") public DownloadEntity entity; + /** + * 任务的url + */ + public String url = ""; + /** * 所属的任务组组名,如果不属于任务组,则为null */ 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 1734cccf..9e1dabfc 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -33,7 +33,7 @@ import java.util.Map; class DBConfig { static Map mapping = new HashMap<>(); static String DB_NAME; - static int VERSION = 13; + static int VERSION = 14; static { if (TextUtils.isEmpty(DB_NAME)) { 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 c8e2efc9..eaf9285d 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -45,7 +45,6 @@ public class SingleTaskActivity extends BaseActivity { private static final String DOWNLOAD_URL = //"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://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //"http://120.25.196.56:8000/filereq?id=15692406294&ipncid=105635&client=android&filename=20170819185541.avi"; //"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt"; @@ -56,6 +55,7 @@ public class SingleTaskActivity extends BaseActivity { //不支持断点的链接 //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; //"http://172.18.104.50:8080/download/_302turn"; + //"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; @@ -196,7 +196,7 @@ public class SingleTaskActivity extends BaseActivity { Aria.download(SingleTaskActivity.this) .load(DOWNLOAD_URL, true) .addHeader("groupName", "value") - .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/gggg.apk") + .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/hhhhhhhh.apk") .start(); break;