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 b8afcd17..0d18ce41 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 @@ -74,6 +74,13 @@ public class DownloadTarget extends AbsTarget return -1; } + /** + * 下载任务是否存在 + */ + public boolean taskExists(String downloadUrl) { + return false; + } + /** * 获取当前任务进度,如果任务存在,则返回当前进度 * diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java index 7288fde6..a40d92b5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java @@ -160,9 +160,13 @@ public class DownloadTaskQueue } @Override public DownloadTask getTask(DownloadEntity entity) { - DownloadTask task = mExecutePool.getTask(entity.getDownloadUrl()); + return getTask(entity.getDownloadUrl()); + } + + @Override public DownloadTask getTask(String url) { + DownloadTask task = mExecutePool.getTask(url); if (task == null) { - task = mCachePool.getTask(entity.getDownloadUrl()); + task = mCachePool.getTask(url); } return task; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java index 0b9b18af..7f05cbff 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java @@ -89,6 +89,14 @@ public interface ITaskQueue { return this; } + /** + * 下载任务是否存在 + */ + @Override public boolean taskExists(String downloadUrl) { + return UploadTaskQueue.getInstance().getTask(downloadUrl) != null; + } + /** * 设置请求类型 * 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 0e14dea1..79a94c20 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java @@ -21,13 +21,9 @@ import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.support.annotation.NonNull; -import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Date; import java.util.List; /** @@ -73,7 +69,7 @@ public class DbUtil { */ synchronized void delData(Class clazz, String... expression) { CheckUtil.checkSqlExpression(expression); - mDb = mHelper.getWritableDatabase(); + checkDb(); SqlHelper.delData(mDb, clazz, expression); } @@ -81,7 +77,7 @@ public class DbUtil { * 修改某行数据 */ synchronized void modifyData(DbEntity dbEntity) { - mDb = mHelper.getWritableDatabase(); + checkDb(); SqlHelper.modifyData(mDb, dbEntity); } @@ -89,9 +85,7 @@ public class DbUtil { * 遍历所有数据 */ synchronized List findAllData(Class clazz) { - if (mDb == null || !mDb.isOpen()) { - mDb = mHelper.getReadableDatabase(); - } + checkDb(); return SqlHelper.findAllData(mDb, clazz); } @@ -99,7 +93,7 @@ public class DbUtil { * 条件查寻数据 */ synchronized List findData(Class clazz, String... expression) { - mDb = mHelper.getReadableDatabase(); + checkDb(); return SqlHelper.findData(mDb, clazz, expression); } @@ -108,7 +102,7 @@ public class DbUtil { */ @Deprecated synchronized List findData(Class clazz, @NonNull String[] wheres, @NonNull String[] values) { - mDb = mHelper.getReadableDatabase(); + checkDb(); return SqlHelper.findData(mDb, clazz, wheres, values); } @@ -116,9 +110,7 @@ public class DbUtil { * 插入数据 */ synchronized void insertData(DbEntity dbEntity) { - if (mDb == null || !mDb.isOpen()) { - mDb = mHelper.getReadableDatabase(); - } + checkDb(); SqlHelper.insertData(mDb, dbEntity); } @@ -126,17 +118,19 @@ public class DbUtil { * 查找某张表是否存在 */ synchronized boolean tableExists(Class clazz) { - if (mDb == null || !mDb.isOpen()) { - mDb = mHelper.getReadableDatabase(); - } + checkDb(); return SqlHelper.tableExists(mDb, clazz); } synchronized void createTable(Class clazz, String tableName) { + checkDb(); + SqlHelper.createTable(mDb, clazz, tableName); + } + + private void checkDb(){ if (mDb == null || !mDb.isOpen()) { - mDb = mHelper.getWritableDatabase(); + mDb = mHelper.getReadableDatabase(); } - SqlHelper.createTable(mDb, clazz, tableName); } /** @@ -159,7 +153,7 @@ public class DbUtil { * 获取所在行Id */ synchronized int[] getRowId(Class clazz) { - mDb = mHelper.getReadableDatabase(); + checkDb(); Cursor cursor = mDb.rawQuery("SELECT rowid, * FROM " + CommonUtil.getClassName(clazz), null); int[] ids = new int[cursor.getCount()]; int i = 0; @@ -176,7 +170,7 @@ public class DbUtil { * 获取行Id */ synchronized int getRowId(Class clazz, Object[] wheres, Object[] values) { - mDb = mHelper.getReadableDatabase(); + checkDb(); if (wheres.length <= 0 || values.length <= 0) { Log.e(TAG, "请输入删除条件"); return -1;