如删除正在运行的任务的记录,将回执行取消任务的记录, https://github.com/AriaLyy/Aria/issues/174, fix bug https://github.com/AriaLyy/Aria/issues/173
This commit is contained in:
@@ -100,7 +100,7 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
|
||||
client.setDataTimeout(10 * 1000);
|
||||
client.enterLocalPassiveMode();
|
||||
client.setFileType(FTP.BINARY_FILE_TYPE);
|
||||
client.setControlKeepAliveTimeout(5);
|
||||
client.setControlKeepAliveTimeout(5000);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@@ -125,9 +125,8 @@ class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
||||
private void handleSpeed(long speed) {
|
||||
if (isConvertSpeed) {
|
||||
mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
|
||||
} else {
|
||||
mEntity.setSpeed(speed < 0 ? 0 : speed);
|
||||
}
|
||||
mEntity.setSpeed(speed < 0 ? 0 : speed);
|
||||
|
||||
mEntity.setPercent((int) (mEntity.getFileSize() <= 0 ? 0
|
||||
: mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()));
|
||||
|
@@ -16,6 +16,7 @@
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -86,4 +87,9 @@ public class DownloadGroupTarget
|
||||
mEntity.update();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override public boolean isRunning() {
|
||||
DownloadGroupTask task = DownloadGroupTaskQueue.getInstance().getTask(mEntity.getKey());
|
||||
return task != null && task.isRunning();
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,6 @@ import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulerListener;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.ArrayList;
|
||||
@@ -250,13 +249,31 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取普通下载任务列表
|
||||
* 获取所有普通下载任务
|
||||
* 获取未完成的普通任务列表{@link #getAllNotCompletTask()}
|
||||
* 获取已经完成的普通任务列表{@link #getAllCompleteTask()}
|
||||
*/
|
||||
@Override public List<DownloadEntity> getSimpleTaskList() {
|
||||
@Override public List<DownloadEntity> getTaskList() {
|
||||
return DownloadEntity.findDatas(DownloadEntity.class, "isGroupChild=? and downloadPath!=''",
|
||||
"false");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有未完成的普通下载任务
|
||||
*/
|
||||
public List<DownloadEntity> getAllNotCompletTask() {
|
||||
return DownloadEntity.findDatas(DownloadEntity.class,
|
||||
"isGroupChild=? and downloadPath!='' and isComplete=?", "false", "false");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已经完成的普通任务
|
||||
*/
|
||||
public List<DownloadEntity> getAllCompleteTask() {
|
||||
return DownloadEntity.findDatas(DownloadEntity.class,
|
||||
"isGroupChild=? and downloadPath!='' and isComplete=?", "false", "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务组列表
|
||||
*/
|
||||
@@ -269,7 +286,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
*/
|
||||
public List<AbsEntity> getTotleTaskList() {
|
||||
List<AbsEntity> list = new ArrayList<>();
|
||||
List<DownloadEntity> simpleTask = getSimpleTaskList();
|
||||
List<DownloadEntity> simpleTask = getTaskList();
|
||||
List<DownloadGroupEntity> groupTask = getGroupTaskList();
|
||||
if (simpleTask != null && !simpleTask.isEmpty()) {
|
||||
list.addAll(simpleTask);
|
||||
|
@@ -17,7 +17,6 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.inf.AbsDownloadTarget;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
@@ -131,8 +130,14 @@ public class DownloadTarget
|
||||
|
||||
/**
|
||||
* 是否在下载
|
||||
*
|
||||
* @deprecated {@link #isRunning()}
|
||||
*/
|
||||
public boolean isDownloading() {
|
||||
return isRunning();
|
||||
}
|
||||
|
||||
@Override public boolean isRunning() {
|
||||
DownloadTask task = DownloadTaskQueue.getInstance().getTask(mEntity.getKey());
|
||||
return task != null && task.isRunning();
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package com.arialyy.aria.core.download;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
|
||||
/**
|
||||
@@ -83,4 +84,9 @@ public class FtpDirDownloadTarget
|
||||
mTaskEntity.urlEntity.account = account;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override public boolean isRunning() {
|
||||
DownloadGroupTask task = DownloadGroupTaskQueue.getInstance().getTask(mEntity.getKey());
|
||||
return task != null && task.isRunning();
|
||||
}
|
||||
}
|
||||
|
@@ -42,11 +42,25 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
protected String mTargetName;
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* 删除记录,如果任务正在执行,则会删除正在下载的任务
|
||||
*/
|
||||
public void removeRecord() {
|
||||
if (isRunning()) {
|
||||
ALog.d("AbsTarget", "任务正在下载,即将删除任务");
|
||||
cancel();
|
||||
} else {
|
||||
mTaskEntity.deleteData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务是否在执行
|
||||
*
|
||||
* @return {@code true} 任务正在执行
|
||||
*/
|
||||
public boolean isRunning() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务是否存在
|
||||
|
@@ -51,8 +51,14 @@ public abstract class AbsUploadTarget<TARGET extends AbsUploadTarget, ENTITY ext
|
||||
|
||||
/**
|
||||
* 是否在下载
|
||||
*
|
||||
* @deprecated {@link #isRunning()}
|
||||
*/
|
||||
public boolean isUploading() {
|
||||
return isRunning();
|
||||
}
|
||||
|
||||
@Override public boolean isRunning() {
|
||||
UploadTask task = UploadTaskQueue.getInstance().getTask(mEntity.getKey());
|
||||
return task != null && task.isRunning();
|
||||
}
|
||||
|
@@ -52,5 +52,5 @@ public interface IReceiver<ENTITY extends IEntity> {
|
||||
/**
|
||||
* 获取任务列表
|
||||
*/
|
||||
List<ENTITY> getSimpleTaskList();
|
||||
List<ENTITY> getTaskList();
|
||||
}
|
||||
|
@@ -113,9 +113,8 @@ class BaseUListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
||||
private void handleSpeed(long speed) {
|
||||
if (isConvertSpeed) {
|
||||
mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
|
||||
} else {
|
||||
mEntity.setSpeed(speed < 0 ? 0 : speed);
|
||||
}
|
||||
mEntity.setSpeed(speed < 0 ? 0 : speed);
|
||||
mEntity.setPercent((int) (mEntity.getFileSize() <= 0 ? 0
|
||||
: mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()));
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
|
||||
return DbEntity.findFirst(UploadEntity.class, "filePath=?", filePath) != null;
|
||||
}
|
||||
|
||||
@Override public List<UploadEntity> getSimpleTaskList() {
|
||||
@Override public List<UploadEntity> getTaskList() {
|
||||
return DbEntity.findAllData(UploadEntity.class);
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,7 @@ class DBConfig {
|
||||
static Map<String, Class> mapping = new HashMap<>();
|
||||
static String DB_NAME;
|
||||
//static int VERSION = 16;
|
||||
static int VERSION = 17;
|
||||
static int VERSION = 18;
|
||||
|
||||
static {
|
||||
if (TextUtils.isEmpty(DB_NAME)) {
|
||||
|
@@ -36,6 +36,16 @@ public class DbEntity {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字模糊检索全文
|
||||
*
|
||||
* @param column 需要查找的列
|
||||
* @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green”
|
||||
*/
|
||||
public static <T extends DbEntity> List<T> searchData(Class<T> clazz, String column, String mathSql) {
|
||||
return DbUtil.getInstance().searchData(clazz, column, mathSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查某个字段的值是否存在
|
||||
*
|
||||
|
@@ -64,6 +64,17 @@ public class DbUtil {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字模糊检索全文
|
||||
*
|
||||
* @param column 需要查找的列
|
||||
* @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green”
|
||||
*/
|
||||
public <T extends DbEntity> List<T> searchData(Class<T> clazz, String column, String mathSql) {
|
||||
checkDb();
|
||||
return SqlHelper.searchData(mDb, clazz, column, mathSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查某个字段的值是否存在
|
||||
*
|
||||
|
@@ -162,14 +162,34 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字模糊检索全文
|
||||
*
|
||||
* @param column 需要查找的列
|
||||
* @param mathSql 关键字语法,exsimple “white OR green”、“blue AND red”、“white NOT green”
|
||||
*/
|
||||
public static <T extends DbEntity> List<T> searchData(SQLiteDatabase db, Class<T> clazz,
|
||||
String column, String mathSql) {
|
||||
String sql = "SELECT * FROM "
|
||||
+ CommonUtil.getClassName(clazz)
|
||||
+ " WHERE "
|
||||
+ column
|
||||
+ " MATCH '"
|
||||
+ mathSql + "'";
|
||||
|
||||
Cursor cursor = db.rawQuery(sql, null);
|
||||
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(db, clazz, cursor) : null;
|
||||
closeCursor(cursor);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查某个字段的值是否存在
|
||||
*
|
||||
* @param expression 字段和值"url=xxx"
|
||||
* @return {@code true}该字段的对应的value已存在
|
||||
*/
|
||||
static synchronized boolean checkDataExist(SQLiteDatabase db, Class clazz,
|
||||
String... expression) {
|
||||
static synchronized boolean checkDataExist(SQLiteDatabase db, Class clazz, String... expression) {
|
||||
db = checkDb(db);
|
||||
CheckUtil.checkSqlExpression(expression);
|
||||
String sql =
|
||||
@@ -414,12 +434,16 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
* @return true,该数据库实体对应的表存在;false,不存在
|
||||
*/
|
||||
static synchronized boolean tableExists(SQLiteDatabase db, Class clazz) {
|
||||
return tableExists(db, CommonUtil.getClassName(clazz));
|
||||
}
|
||||
|
||||
static synchronized boolean tableExists(SQLiteDatabase db, String tableName) {
|
||||
db = checkDb(db);
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SELECT COUNT(*) AS c FROM sqlite_master WHERE type='table' AND name='");
|
||||
sb.append(CommonUtil.getClassName(clazz));
|
||||
sb.append(tableName);
|
||||
sb.append("'");
|
||||
print(TABLE_EXISTS, sb.toString());
|
||||
cursor = db.rawQuery(sb.toString(), null);
|
||||
@@ -446,14 +470,15 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
*/
|
||||
static synchronized void createTable(SQLiteDatabase db, Class clazz, String tableName) {
|
||||
db = checkDb(db);
|
||||
createFTSTable(db);
|
||||
List<Field> fields = CommonUtil.getAllFields(clazz);
|
||||
if (fields != null && fields.size() > 0) {
|
||||
//外键Map,在Sqlite3中foreign修饰的字段必须放在最后
|
||||
final List<Field> foreignArray = new ArrayList<>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("create table ")
|
||||
sb.append("create VIRTUAL table ")
|
||||
.append(TextUtils.isEmpty(tableName) ? CommonUtil.getClassName(clazz) : tableName)
|
||||
.append("(");
|
||||
.append(" USING fts4(");
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
if (SqlUtil.ignoreField(field)) {
|
||||
@@ -486,7 +511,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
|
||||
}
|
||||
if (SqlUtil.isForeign(field)) {
|
||||
foreignArray.add(field);
|
||||
//foreignArray.add(field);
|
||||
}
|
||||
|
||||
if (SqlUtil.isNoNull(field)) {
|
||||
@@ -514,6 +539,17 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
close(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建分词表
|
||||
*/
|
||||
private static void createFTSTable(SQLiteDatabase db) {
|
||||
String tableName = "ariaFts";
|
||||
String sql = "CREATE VIRTUAL TABLE " + tableName + " USING fts4(tokenize= porter)";
|
||||
if (!tableExists(db, tableName)) {
|
||||
db.execSQL(sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印数据库日志
|
||||
*
|
||||
|
@@ -13,6 +13,7 @@ android {
|
||||
targetSdkVersion 23
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
multiDexEnabled true
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@@ -5,10 +5,10 @@
|
||||
<download>
|
||||
|
||||
<!--设置下载线程,线程下载数改变后,新的下载任务才会生效,如果任务大小小于1m,该设置也不会生效-->
|
||||
<threadNum value="3"/>
|
||||
<threadNum value="1"/>
|
||||
|
||||
<!--设置下载队列最大任务数, 默认为2-->
|
||||
<maxTaskNum value="1"/>
|
||||
<maxTaskNum value="2"/>
|
||||
|
||||
<!--设置下载失败,重试次数,默认为10-->
|
||||
<reTryNum value="2"/>
|
||||
|
@@ -86,7 +86,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
||||
setBtState(false);
|
||||
}
|
||||
mSize.setText(target.getConvertFileSize());
|
||||
List<DownloadEntity> temp = Aria.download(this).getSimpleTaskList();
|
||||
List<DownloadEntity> temp = Aria.download(this).getTaskList();
|
||||
if (temp != null && !temp.isEmpty()) {
|
||||
for (DownloadEntity entity : temp) {
|
||||
if (entity.getUrl().equals(DOWNLOAD_URL)) continue;
|
||||
|
@@ -58,9 +58,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
//"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://172.18.104.50:8080/download/_302turn";
|
||||
"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk";
|
||||
//"http://172.21.1.99:8080/download/test+ 中文123.zip";
|
||||
@Bind(R.id.start) Button mStart;
|
||||
@Bind(R.id.stop) Button mStop;
|
||||
@Bind(R.id.cancel) Button mCancel;
|
||||
@@ -170,6 +168,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
setBtState(true);
|
||||
getBinding().setSpeed("");
|
||||
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
|
||||
L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL));
|
||||
}
|
||||
|
||||
@Download.onNoSupportBreakPoint
|
||||
@@ -200,20 +199,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
startD();
|
||||
//new Thread(new Runnable() {
|
||||
// @Override public void run() {
|
||||
// startD();
|
||||
// }
|
||||
//}).start();
|
||||
//
|
||||
//new Thread(new Runnable() {
|
||||
// @Override public void run() {
|
||||
// startD();
|
||||
// }
|
||||
//}).start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
|
@@ -157,8 +157,13 @@ class Configuration {
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
int m = field.getModifiers();
|
||||
if (field.getName().equals("oldMaxTaskNum") || Modifier.isFinal(m) || Modifier.isStatic(
|
||||
m)) {
|
||||
String fileName = field.getName();
|
||||
if (fileName.equals("oldMaxTaskNum")
|
||||
|| field.isSynthetic()
|
||||
|| Modifier.isFinal(m)
|
||||
|| Modifier.isStatic(m)
|
||||
|| fileName.equals("shadow$_klass_")
|
||||
|| fileName.equals("shadow$_monitor_")) {
|
||||
continue;
|
||||
}
|
||||
field.setAccessible(true);
|
||||
@@ -267,6 +272,11 @@ class Configuration {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setThreadNum(int threadNum){
|
||||
this.threadNum = threadNum;
|
||||
saveKey("threadNum", String.valueOf(threadNum));
|
||||
}
|
||||
|
||||
public DownloadConfig setIOTimeOut(int iOTimeOut) {
|
||||
this.iOTimeOut = iOTimeOut;
|
||||
saveKey("iOTimeOut", iOTimeOut + "");
|
||||
|
Reference in New Issue
Block a user