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] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=99=9A=E8=A1=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20https://github.com/AriaLyy/Aria/issues/185=20?= =?UTF-8?q?=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 下载框架'