From a903180491bccb5d6a5ea76cc91f6b4f05f95381 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Sat, 30 Dec 2017 11:54:16 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8A3.3.9=E4=BE=9D?= =?UTF-8?q?=E7=84=B6=E5=AD=98=E5=9C=A8=E7=9A=84=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AE=B0=E5=BD=95=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20https://github.com/AriaLyy/Aria/issues/181?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/arialyy/aria/core/inf/AbsTarget.java | 2 ++ .../arialyy/aria/core/manager/TEManager.java | 23 +++++++++---------- .../java/com/arialyy/aria/orm/DBConfig.java | 2 +- .../java/com/arialyy/aria/orm/SqlHelper.java | 10 +++++++- .../java/com/arialyy/aria/orm/SqlUtil.java | 23 ++++++++++++++++--- .../simple/download/SingleTaskActivity.java | 3 ++- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java index ab174537..76e66441 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java @@ -24,6 +24,7 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -50,6 +51,7 @@ public abstract class AbsTarget map = new ConcurrentHashMap<>(); + private LruCache cache = new LruCache<>(1024); private Lock lock; public static TEManager getInstance() { @@ -61,7 +60,7 @@ public class TEManager { final Lock lock = this.lock; lock.lock(); try { - AbsTaskEntity tEntity = map.get(convertKey(key)); + AbsTaskEntity tEntity = cache.get(convertKey(key)); if (tEntity == null || tEntity.getClass() != clazz) { ITEntityFactory factory = chooseFactory(clazz); if (factory == null) { @@ -69,7 +68,7 @@ public class TEManager { return null; } tEntity = factory.create(key); - map.put(convertKey(key), tEntity); + cache.put(convertKey(key), tEntity); } return (TE) tEntity; } finally { @@ -87,7 +86,7 @@ public class TEManager { lock.lock(); try { String groupName = CommonUtil.getMd5Code(urls); - AbsTaskEntity tEntity = map.get(convertKey(groupName)); + AbsTaskEntity tEntity = cache.get(convertKey(groupName)); if (tEntity == null || tEntity.getClass() != clazz) { IGTEntityFactory factory = chooseGroupFactory(clazz); if (factory == null) { @@ -95,7 +94,7 @@ public class TEManager { return null; } tEntity = factory.create(groupName, urls); - map.put(convertKey(groupName), tEntity); + cache.put(convertKey(groupName), tEntity); } return (TE) tEntity; } finally { @@ -112,7 +111,7 @@ public class TEManager { final Lock lock = this.lock; lock.lock(); try { - AbsTaskEntity tEntity = map.get(convertKey(absEntity.getKey())); + AbsTaskEntity tEntity = cache.get(convertKey(absEntity.getKey())); if (tEntity == null || tEntity.getClass() != clazz) { ITEntityFactory factory = chooseFactory(clazz); if (factory == null) { @@ -120,7 +119,7 @@ public class TEManager { return null; } tEntity = factory.create(absEntity); - map.put(convertKey(absEntity.getKey()), tEntity); + cache.put(convertKey(absEntity.getKey()), tEntity); } return (TE) tEntity; } finally { @@ -153,7 +152,7 @@ public class TEManager { final Lock lock = this.lock; lock.lock(); try { - AbsTaskEntity tEntity = map.get(convertKey(key)); + AbsTaskEntity tEntity = cache.get(convertKey(key)); if (tEntity == null) { return null; } else { @@ -177,7 +176,7 @@ public class TEManager { final Lock lock = this.lock; lock.lock(); try { - return map.put(convertKey(te.key), te) != null; + return cache.put(convertKey(te.key), te) != null; } finally { lock.unlock(); } @@ -190,7 +189,7 @@ public class TEManager { final Lock lock = this.lock; lock.lock(); try { - return map.remove(convertKey(key)); + return cache.remove(convertKey(key)); } finally { lock.unlock(); } 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 d691dec1..5f7870a6 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -34,7 +34,7 @@ import java.util.Map; class DBConfig { static Map mapping = new HashMap<>(); static String DB_NAME; - static int VERSION = 20; + static int VERSION = 21; 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 bc4671c3..53cf61ef 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -21,6 +21,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; +import android.support.v4.util.LruCache; import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.util.ALog; @@ -49,6 +50,7 @@ final class SqlHelper extends SQLiteOpenHelper { private static final int DEL_DATA = 6; private static volatile SqlHelper INSTANCE = null; + private static LruCache mDataCache = new LruCache<>(1024); static SqlHelper init(Context context) { if (INSTANCE == null) { @@ -328,6 +330,7 @@ final class SqlHelper extends SQLiteOpenHelper { db = checkDb(db); Class clazz = dbEntity.getClass(); List fields = CommonUtil.getAllFields(clazz); + DbEntity cacheEntity = mDataCache.get(dbEntity.hashCode()); if (fields != null && fields.size() > 0) { StringBuilder sb = new StringBuilder(); sb.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET "); @@ -337,8 +340,12 @@ final class SqlHelper extends SQLiteOpenHelper { if (SqlUtil.ignoreField(field)) { continue; } - sb.append(i > 0 ? ", " : ""); try { + if (cacheEntity != null && field.get(dbEntity) == field.get(cacheEntity)) { + continue; + } + + sb.append(i > 0 ? ", " : ""); String value; sb.append(field.getName()).append("='"); Type type = field.getType(); @@ -656,6 +663,7 @@ final class SqlHelper extends SQLiteOpenHelper { } } entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid")); + mDataCache.put(entity.hashCode(), entity); entitys.add(entity); } closeCursor(cursor); diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlUtil.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlUtil.java index dd736b81..877f10dd 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlUtil.java @@ -110,10 +110,19 @@ final class SqlUtil { if (TextUtils.isEmpty(str)) { return map; } + boolean isDecode = false; + if (str.endsWith("_&_decode_&_")) { + isDecode = true; + str = str.substring(0, str.length() - 12); + } String[] element = str.split(","); for (String data : element) { String[] s = data.split("\\$"); - map.put(s[0], s[1]); + if (isDecode) { + map.put(CommonUtil.decryptBASE64(s[0]), CommonUtil.decryptBASE64(s[1])); + } else { + map.put(s[0], s[1]); + } } return map; } @@ -128,10 +137,18 @@ final class SqlUtil { StringBuilder sb = new StringBuilder(); Set keys = map.keySet(); for (String key : keys) { - sb.append(key).append("$").append(map.get(key)).append(","); + sb.append(CommonUtil.encryptBASE64(key)) + .append("$") + .append(CommonUtil.encryptBASE64(map.get(key))) + .append(","); } String str = sb.toString(); - return TextUtils.isEmpty(str) ? str : str.substring(0, str.length() - 1); + str = TextUtils.isEmpty(str) ? str : str.substring(0, str.length() - 1); + //3.3.10版本之前没有decode,需要加标志 + if (map.size() != 0) { + str += "_&_decode_&_"; + } + return str; } /** 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 fd14a025..d89f85fa 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -209,7 +209,8 @@ public class SingleTaskActivity extends BaseActivity { //Aria.download(this).load(DOWNLOAD_URL).removeRecord(); break; case R.id.cancel: - Aria.download(this).load(DOWNLOAD_URL).cancel(); + //Aria.download(this).load(DOWNLOAD_URL).cancel(); + Aria.download(this).load(DOWNLOAD_URL).removeRecord(); break; } } From 31f0acf059f82cf4f0d67b1b1e2177e4ef63b1e5 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 2 Jan 2018 21:47:41 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84api=EF=BC=8C=E5=BD=93=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E4=BF=A1=E6=81=AF=E4=B8=8D=E6=94=B9=E5=8F=98=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E6=98=AF=E6=9B=BF=E6=8D=A2=E4=BA=86=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E7=9A=84=E5=AF=B9=E5=BA=94=E7=9A=84=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E7=94=A8`Aria.download(this).load(url).reset?= =?UTF-8?q?State()`=E9=87=8D=E7=BD=AE=E4=B8=8B=E8=BD=BD=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/download/DownloadGroupTarget.java | 4 +-- .../aria/core/download/DownloadReceiver.java | 4 +-- .../downloader/DownloadGroupUtil.java | 6 +++++ .../arialyy/aria/core/inf/AbsGroupTask.java | 2 +- .../com/arialyy/aria/core/inf/AbsTarget.java | 9 +++++++ .../arialyy/aria/core/manager/TEManager.java | 1 + .../java/com/arialyy/aria/orm/SqlHelper.java | 26 ++++++++++++------- DEV_LOG.md | 3 +++ .../simple/download/SingleTaskActivity.java | 6 ++--- .../download/group/DownloadGroupActivity.java | 13 +++++++++- .../simple/download/group/GroupModule.java | 7 +++++ app/src/main/res/values/strings.xml | 4 +-- build.gradle | 2 +- 13 files changed, 66 insertions(+), 21 deletions(-) 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 9d288cdc..9bd63dd7 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 @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.download; +import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.util.ALog; @@ -36,8 +37,7 @@ public class DownloadGroupTarget this.mUrls.addAll(groupEntity.getUrls()); } mGroupName = CommonUtil.getMd5Code(groupEntity.getUrls()); - mTaskEntity = TEManager.getInstance() - .getTEntity(DownloadGroupTaskEntity.class, mGroupName); + mTaskEntity = TEManager.getInstance().getTEntity(DownloadGroupTaskEntity.class, mGroupName); if (mTaskEntity == null) { mTaskEntity = TEManager.getInstance().createTEntity(DownloadGroupTaskEntity.class, groupEntity); 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 d849369f..61ea9f29 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 @@ -84,7 +84,7 @@ public class DownloadReceiver extends AbsReceiver { * 加载Http、https单任务下载地址 * * @param url 下载地址 - * @param refreshInfo 是否刷新下载信息 + * @param refreshInfo 是否刷新下载信息,当下载地址改变而保存路径不变,则需要设置该参数为{@code true} */ public DownloadTarget load(@NonNull String url, boolean refreshInfo) { CheckUtil.checkUrl(url); @@ -111,7 +111,7 @@ public class DownloadReceiver extends AbsReceiver { /** * 使用下载实体执行下载操作 * - * @param refreshInfo 是否刷新下载信息 + * @param refreshInfo 是否刷新下载信息,当下载地址改变而保存路径不变,则需要设置该参数为{@code true} */ public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) { CheckUtil.checkDownloadEntity(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 82513e9a..937f535f 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 @@ -21,6 +21,7 @@ import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.util.ALog; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -63,6 +64,11 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { @Override protected void onStart() { super.onStart(); + if (mExeMap.size() == 0){ + ALog.e(TAG, "任务组无可执行任务"); + mListener.onFail(false); + return; + } Set keys = mExeMap.keySet(); int i = 0; for (String key : keys) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java index 41883028..e395b1f9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java @@ -27,7 +27,7 @@ public abstract class AbsGroupTask protected AbsGroupUtil mUtil; @Override public String getKey() { - return mTaskEntity.getEntity().getGroupName(); + return mTaskEntity.getEntity().getKey(); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java index 76e66441..985196c8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java @@ -42,6 +42,15 @@ public abstract class AbsTarget fields = CommonUtil.getAllFields(clazz); DbEntity cacheEntity = mDataCache.get(dbEntity.hashCode()); if (fields != null && fields.size() > 0) { - StringBuilder sb = new StringBuilder(); - sb.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET "); + StringBuilder sql = new StringBuilder(); + StringBuilder prams = new StringBuilder(); + sql.append("UPDATE ").append(CommonUtil.getClassName(dbEntity)).append(" SET "); int i = 0; for (Field field : fields) { field.setAccessible(true); @@ -345,9 +346,11 @@ final class SqlHelper extends SQLiteOpenHelper { continue; } - sb.append(i > 0 ? ", " : ""); + //sb.append(i > 0 ? ", " : ""); + //sb.append(field.getName()).append("='"); String value; - sb.append(field.getName()).append("='"); + prams.append(i > 0 ? ", " : ""); + prams.append(field.getName()).append("='"); Type type = field.getType(); if (type == Map.class) { value = SqlUtil.map2Str((Map) field.get(dbEntity)); @@ -364,16 +367,21 @@ final class SqlHelper extends SQLiteOpenHelper { value = obj == null ? "" : obj.toString(); } - sb.append(value == null ? "" : value); - sb.append("'"); + //sb.append(value == null ? "" : value); + //sb.append("'"); + prams.append(TextUtils.isEmpty(value) ? "" : value); + prams.append("'"); } catch (IllegalAccessException e) { e.printStackTrace(); } i++; } - sb.append(" where rowid=").append(dbEntity.rowID); - print(MODIFY_DATA, sb.toString()); - db.execSQL(sb.toString()); + if (!TextUtils.isEmpty(prams.toString())) { + sql.append(prams.toString()); + sql.append(" where rowid=").append(dbEntity.rowID); + print(MODIFY_DATA, sql.toString()); + db.execSQL(sql.toString()); + } } close(db); } diff --git a/DEV_LOG.md b/DEV_LOG.md index 923c075a..69d361d2 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,7 @@ ## 开发日志 + + v_3.3.10 + - 修复地址切换导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/181 + - 添加重置状态的api,当下载信息不改变,只是替换了服务器的对应的文件,可用`Aria.download(this).load(url).resetState()`重置下载状态 https://github.com/AriaLyy/Aria/issues/182 + v_3.3.9 - 添加POST支持 - 任务执行的过程中,如果调用removeRecord()方法,将会取消任务 https://github.com/AriaLyy/Aria/issues/174 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 d89f85fa..fe30b087 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -61,8 +61,8 @@ public class SingleTaskActivity extends BaseActivity { //"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1"; //不支持断点的链接 //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; - //"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; - "http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; + "http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; + //"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; @@ -226,7 +226,7 @@ public class SingleTaskActivity extends BaseActivity { //.addHeader("groupName", "value") .addHeaders(map) //.setRequestMode(RequestEnum.POST) - .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg.apk") + .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") .start(); } 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 66b9034b..e53219a9 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 @@ -26,6 +26,7 @@ import com.arialyy.aria.core.download.DownloadEntity; 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.core.manager.TEManager; import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.T; import com.arialyy.simple.R; @@ -66,6 +67,7 @@ public class DownloadGroupActivity extends BaseActivity getUrls() { + List urls = new ArrayList<>(); + String[] str = getContext().getResources().getStringArray(R.array.group_urls_1); + Collections.addAll(urls, str); + return urls; + } + + List getUrls1() { List urls = new ArrayList<>(); String[] str = getContext().getResources().getStringArray(R.array.group_urls); Collections.addAll(urls, str); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e14beb6d..2aabf57f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,7 +58,7 @@ - https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk + http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk @@ -79,7 +79,7 @@ - 王者荣耀.apk + 战斗吧剑灵.apk 天魔幻想.apk diff --git a/build.gradle b/build.gradle index 77153ac4..f7cca8f1 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.3.9' + publishVersion = '3.3.10' // publishVersion = '1.0.3' //FTP插件 repoName='maven' desc = 'android 下载框架' From a73d867445daa9b0fa6ca18d56d4fd1b66d00216 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Wed, 10 Jan 2018 21:59:52 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=99=9A=E8=A1=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20https://github.com/AriaLyy/Aria/issues/185?= =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0resetState()=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E4=B8=8B=E8=BD=BD=E4=BF=A1=E6=81=AF=E3=80=82?= =?UTF-8?q?=20https://github.com/AriaLyy/Aria/issues/182?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aria/core/common/AbsThreadTask.java | 35 +++++++++----- .../aria/core/download/DownloadReceiver.java | 37 ++++++++++++-- .../com/arialyy/aria/core/inf/AbsTarget.java | 1 + .../java/com/arialyy/aria/orm/DBConfig.java | 2 +- .../java/com/arialyy/aria/orm/DbEntity.java | 18 +++---- .../java/com/arialyy/aria/orm/DbUtil.java | 20 ++++---- .../java/com/arialyy/aria/orm/SqlHelper.java | 48 ++++++++++--------- .../simple/download/SingleTaskActivity.java | 5 +- .../download/group/DownloadGroupActivity.java | 21 ++++---- .../multi_download/MultiTaskActivity.java | 4 +- app/src/main/res/values/strings.xml | 1 + build.gradle | 2 +- 12 files changed, 122 insertions(+), 72 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java index 05b48059..c490372e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java @@ -32,6 +32,8 @@ import java.math.BigDecimal; import java.util.Properties; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * Created by lyy on 2017/1/18. @@ -60,6 +62,17 @@ public abstract class AbsThreadTask info) { @@ -76,6 +89,7 @@ public abstract class AbsThreadTask= Build.VERSION_CODES.LOLLIPOP; } + @Override protected void finalize() throws Throwable { + super.finalize(); + if (mConfigThreadPool != null) { + mConfigThreadPool.shutdown(); + } + } + /** * 停止任务 */ @@ -134,20 +155,12 @@ public abstract class AbsThreadTask 5000 && mChildCurrentLocation < mConfig.END_LOCATION) { mLastSaveTime = System.currentTimeMillis(); - new Thread(new Runnable() { - @Override public void run() { - final long currentTemp = mChildCurrentLocation; - try { - writeConfig(false, currentTemp); - } catch (IOException e) { - e.printStackTrace(); - } - } - }).start(); + if (!mConfigThreadPool.isShutdown()) { + mConfigThreadPool.execute(mConfigThread); + } } } } 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 61ea9f29..bcf00f21 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 @@ -24,6 +24,7 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.common.ProxyHelper; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsReceiver; +import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulerListener; @@ -65,8 +66,18 @@ public class DownloadReceiver extends AbsReceiver { * 使用下载实体执行下载操作 * * @param refreshInfo 是否刷新下载信息 + * @deprecated 请使用 {@link AbsTarget#resetState()} + *
+   *   
+   *   Aria.download(this)
+   *       .load(URL)
+   *       .setDownloadPath(PATH)
+   *       .resetState()
+   *       .start();
+   *   
+   * 
*/ - public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) { + @Deprecated public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) { CheckUtil.checkDownloadEntity(entity); return new DownloadTarget(entity, targetName, refreshInfo); } @@ -85,8 +96,18 @@ public class DownloadReceiver extends AbsReceiver { * * @param url 下载地址 * @param refreshInfo 是否刷新下载信息,当下载地址改变而保存路径不变,则需要设置该参数为{@code true} + * @deprecated 请使用 {@link AbsTarget#resetState()} + *
+   *   
+   *   Aria.download(this)
+   *       .load(URL)
+   *       .setDownloadPath(PATH)
+   *       .resetState()
+   *       .start();
+   *   
+   * 
*/ - public DownloadTarget load(@NonNull String url, boolean refreshInfo) { + @Deprecated public DownloadTarget load(@NonNull String url, boolean refreshInfo) { CheckUtil.checkUrl(url); return new DownloadTarget(url, targetName, refreshInfo); } @@ -112,8 +133,18 @@ public class DownloadReceiver extends AbsReceiver { * 使用下载实体执行下载操作 * * @param refreshInfo 是否刷新下载信息,当下载地址改变而保存路径不变,则需要设置该参数为{@code true} + * @deprecated 请使用 {@link AbsTarget#resetState()} + *
+   *   
+   *   Aria.download(this)
+   *       .load(URL)
+   *       .setDownloadPath(PATH)
+   *       .resetState()
+   *       .start();
+   *   
+   * 
*/ - public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) { + @Deprecated public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) { CheckUtil.checkDownloadEntity(entity); if (!entity.getUrl().startsWith("ftp")) { throw new IllegalArgumentException("非FTP请求不能使用该方法"); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java index 985196c8..6e2d69c4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java @@ -47,6 +47,7 @@ public abstract class AbsTarget mapping = new HashMap<>(); static String DB_NAME; - static int VERSION = 21; + static int VERSION = 22; 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 787d319a..8b6ced31 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java @@ -36,15 +36,15 @@ public class DbEntity { } - /** - * 关键字模糊检索全文 - * - * @param column 需要查找的列 - * @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green” - */ - public static List searchData(Class clazz, String column, String mathSql) { - return DbUtil.getInstance().searchData(clazz, column, mathSql); - } + ///** + // * 关键字模糊检索全文 + // * + // * @param column 需要查找的列 + // * @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green” + // */ + //public static List searchData(Class clazz, String column, String mathSql) { + // return DbUtil.getInstance().searchData(clazz, column, mathSql); + //} /** * 检查某个字段的值是否存在 diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java b/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java index 3cc12950..7e1bf8d9 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java @@ -64,16 +64,16 @@ public class DbUtil { return INSTANCE; } - /** - * 关键字模糊检索全文 - * - * @param column 需要查找的列 - * @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green” - */ - public List searchData(Class clazz, String column, String mathSql) { - checkDb(); - return SqlHelper.searchData(mDb, clazz, column, mathSql); - } + ///** + // * 关键字模糊检索全文 + // * + // * @param column 需要查找的列 + // * @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green” + // */ + //public List searchData(Class clazz, String column, String mathSql) { + // checkDb(); + // return SqlHelper.searchData(mDb, clazz, column, mathSql); + //} /** * 检查某个字段的值是否存在 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 8bf84746..e0884fb1 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -164,27 +164,27 @@ final class SqlHelper extends SQLiteOpenHelper { return count; } - /** - * 关键字模糊检索全文 - * - * @param column 需要查找的列 - * @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green” - */ - public static List searchData(SQLiteDatabase db, Class clazz, - String column, String mathSql) { - String sql = "SELECT * FROM " - + CommonUtil.getClassName(clazz) - + " WHERE " - + column - + " MATCH '" - + mathSql - + "'"; - - Cursor cursor = db.rawQuery(sql, null); - List data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null; - closeCursor(cursor); - return data; - } + ///** + // * 关键字模糊检索全文 + // * + // * @param column 需要查找的列 + // * @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green” + // */ + //public static List searchData(SQLiteDatabase db, Class clazz, + // String column, String mathSql) { + // String sql = "SELECT * FROM " + // + CommonUtil.getClassName(clazz) + // + " WHERE " + // + column + // + " MATCH '" + // + mathSql + // + "'"; + // + // Cursor cursor = db.rawQuery(sql, null); + // List data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null; + // closeCursor(cursor); + // return data; + //} /** * 检查某个字段的值是否存在 @@ -492,9 +492,11 @@ final class SqlHelper extends SQLiteOpenHelper { //外键Map,在Sqlite3中foreign修饰的字段必须放在最后 final List foreignArray = new ArrayList<>(); StringBuilder sb = new StringBuilder(); - sb.append("create VIRTUAL table ") + //sb.append("create VIRTUAL table ") + sb.append("create table ") .append(TextUtils.isEmpty(tableName) ? CommonUtil.getClassName(clazz) : tableName) - .append(" USING fts4("); + //.append(" USING fts4("); + .append(" ("); for (Field field : fields) { field.setAccessible(true); if (SqlUtil.ignoreField(field)) { 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 fe30b087..afa60d39 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -61,8 +61,8 @@ public class SingleTaskActivity extends BaseActivity { //"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1"; //不支持断点的链接 //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; - "http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; - //"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; + //"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; + "http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; @@ -227,6 +227,7 @@ public class SingleTaskActivity extends BaseActivity { .addHeaders(map) //.setRequestMode(RequestEnum.POST) .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") + .resetState() .start(); } 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 e53219a9..b682d4c7 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 @@ -96,16 +96,17 @@ public class DownloadGroupActivity extends BaseActivity { dialog.show(getSupportFragmentManager(), "download_num"); break; case R.id.stop_all: - //Aria.download(this).stopAllTask(); - Aria.download(this).removeAllTask(false); + Aria.download(this).stopAllTask(); + //Aria.download(this).removeAllTask(false); break; case R.id.turn: startActivity(new Intent(this, MultiDownloadActivity.class)); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2aabf57f..911363ca 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -65,6 +65,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 diff --git a/build.gradle b/build.gradle index f7cca8f1..c1e4c196 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.3.10' + publishVersion = '3.3.10_dev' // publishVersion = '1.0.3' //FTP插件 repoName='maven' desc = 'android 下载框架' From f6d7a7c820c0707af6cacf01b665ee835a203db1 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Wed, 10 Jan 2018 22:33:22 +0800 Subject: [PATCH 4/4] 3.3.10 --- README.md | 12 ++++++------ build.gradle | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1b592c21..43816bf4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Aria -![图标](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/app/src/main/res/mipmap-hdpi/ic_launcher.png)
+![图标](https://github.com/AriaLyy/DownloadUtil/blob/v_3.0/app/src/main/res/mipmap-hdpi/ic_launcher.png)
## [ENGLISH DOC](https://github.com/AriaLyy/Aria/blob/master/ENGLISH_README.md)
Aria项目源于工作中遇到的一个文件下载管理的需求,当时被下载折磨的痛不欲生,从那时起便萌生了编写一个简单易用,稳当高效的下载框架,aria经历了1.0到3.0的开发,算是越来越接近当初所制定的目标了。 @@ -28,8 +28,8 @@ Aria有以下特点: [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) ```java -compile 'com.arialyy.aria:aria-core:3.3.7' -annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.7' +compile 'com.arialyy.aria:aria-core:3.3.10' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.10' ``` 如果你使用的是kotlin,请使用kotlin官方提供的方法配置apt,[kotlin kapt官方配置传送门](https://www.kotlincn.net/docs/reference/kapt.html) @@ -97,9 +97,9 @@ protected void onCreate(Bundle savedInstanceState) { ### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki) ### 升级日志 -+ v_3.3.7 - - 修复一个线程重启的问题 https://github.com/AriaLyy/Aria/issues/160 - - 修复配置文件异常问题、格式化速度为0问题 https://github.com/AriaLyy/Aria/issues/161 ++ v_3.3.10 + - 修复地址切换导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/181 + - 添加重置状态的api,当下载信息不改变,只是替换了服务器的对应的文件,可用`Aria.download(this).load(url).resetState()`重置下载状态 https://github.com/AriaLyy/Aria/issues/182 [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/build.gradle b/build.gradle index c1e4c196..f7cca8f1 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.3.10_dev' + publishVersion = '3.3.10' // publishVersion = '1.0.3' //FTP插件 repoName='maven' desc = 'android 下载框架'