This commit is contained in:
@@ -25,7 +25,6 @@ import com.arialyy.aria.core.loader.IRecordHandler;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.wrapper.ITaskWrapper;
|
||||
import com.arialyy.aria.util.RecordUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -97,13 +96,13 @@ public class SubRecordHandler extends RecordHandler {
|
||||
@Override public int initTaskThreadNum() {
|
||||
int requestTpe = getWrapper().getRequestType();
|
||||
if (requestTpe == ITaskWrapper.U_HTTP
|
||||
|| (requestTpe == ITaskWrapper.D_HTTP && (!getWrapper().isSupportBP())
|
||||
|| (requestTpe == ITaskWrapper.D_HTTP && (!getWrapper().isSupportBP())
|
||||
)) {
|
||||
return 1;
|
||||
}
|
||||
int threadNum = Configuration.getInstance().downloadCfg.getThreadNum();
|
||||
return getFileSize() <= IRecordHandler.SUB_LEN
|
||||
? 1
|
||||
: threadNum;
|
||||
? 1
|
||||
: threadNum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +132,6 @@ public class NormalLoader<T extends AbsTaskWrapper> extends AbsNormalLoader<T> {
|
||||
ThreadTaskManager.getInstance().startThread(mTaskWrapper.getKey(), threadTask);
|
||||
}
|
||||
|
||||
List<IThreadTask> list = getTaskList();
|
||||
|
||||
// 启动定时器
|
||||
startTimer();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.TaskRecord;
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
import com.arialyy.aria.core.common.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.inf.IThreadStateManager;
|
||||
import com.arialyy.aria.core.manager.ThreadTaskManager;
|
||||
@@ -97,26 +96,27 @@ public final class SubLoader implements ILoader, ILoaderVisitor {
|
||||
}
|
||||
|
||||
private void handlerTask() {
|
||||
if (isBreak()){
|
||||
if (isBreak()) {
|
||||
return;
|
||||
}
|
||||
Looper looper=Looper.myLooper();
|
||||
if(looper==null) {
|
||||
Looper looper = Looper.myLooper();
|
||||
if (looper == null) {
|
||||
Looper.prepare();
|
||||
looper=Looper.myLooper();
|
||||
looper = Looper.myLooper();
|
||||
}
|
||||
|
||||
record = recordHandler.getRecord(wrapper.getEntity().getFileSize());
|
||||
if (record.threadRecords != null
|
||||
&& !TextUtils.isEmpty(record.filePath)
|
||||
&& new File(record.filePath).exists()
|
||||
&& !record.threadRecords.isEmpty()
|
||||
&& record.threadRecords.get(0).isComplete) {
|
||||
&& !TextUtils.isEmpty(record.filePath)
|
||||
&& new File(record.filePath).exists()
|
||||
&& !record.threadRecords.isEmpty()
|
||||
&& record.threadRecords.get(0).isComplete) {
|
||||
ALog.d(TAG, "子任务已完成,key:" + wrapper.getKey());
|
||||
sendNormalState(IThreadStateManager.STATE_COMPLETE);
|
||||
return;
|
||||
}
|
||||
List<IThreadTask> task = ttBuild.buildThreadTask(record, new Handler(looper, mStateManager.getHandlerCallback()));
|
||||
List<IThreadTask> task =
|
||||
ttBuild.buildThreadTask(record, new Handler(looper, mStateManager.getHandlerCallback()));
|
||||
mStateManager.setLooper(record, looper);
|
||||
if (task == null || task.isEmpty()) {
|
||||
ALog.e(TAG, "创建子任务的线程任务失败,key:" + wrapper.getKey());
|
||||
@@ -129,9 +129,8 @@ public final class SubLoader implements ILoader, ILoaderVisitor {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sendNormalState(IThreadStateManager.STATE_PRE);
|
||||
mTask .addAll( task);
|
||||
mTask.addAll(task);
|
||||
try {
|
||||
for (IThreadTask iThreadTask : mTask) {
|
||||
ThreadTaskManager.getInstance().startThread(parentKey, iThreadTask);
|
||||
@@ -146,7 +145,7 @@ public final class SubLoader implements ILoader, ILoaderVisitor {
|
||||
Looper.loop();
|
||||
}
|
||||
|
||||
public TaskRecord getRecord(){
|
||||
public TaskRecord getRecord() {
|
||||
return record;
|
||||
}
|
||||
|
||||
@@ -160,7 +159,7 @@ public final class SubLoader implements ILoader, ILoaderVisitor {
|
||||
|
||||
public void retryTask() {
|
||||
try {
|
||||
if (!mTask.isEmpty() ) {
|
||||
if (!mTask.isEmpty()) {
|
||||
for (IThreadTask iThreadTask : mTask) {
|
||||
iThreadTask.call();
|
||||
}
|
||||
@@ -181,14 +180,14 @@ public final class SubLoader implements ILoader, ILoaderVisitor {
|
||||
for (IThreadTask iThreadTask : mTask) {
|
||||
iThreadTask.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override public boolean isRunning() {
|
||||
if(mTask.isEmpty())
|
||||
if (mTask.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (IThreadTask iThreadTask : mTask) {
|
||||
if(!iThreadTask.isBreak()) return true;
|
||||
if (!iThreadTask.isBreak()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -223,7 +222,8 @@ public final class SubLoader implements ILoader, ILoaderVisitor {
|
||||
}
|
||||
|
||||
@Override public long getCurrentProgress() {
|
||||
return isRunning() ? mStateManager.getCurrentProgress() : getWrapper().getEntity().getCurrentProgress();
|
||||
return isRunning() ? mStateManager.getCurrentProgress()
|
||||
: getWrapper().getEntity().getCurrentProgress();
|
||||
}
|
||||
|
||||
@Override public void addComponent(IRecordHandler recordHandler) {
|
||||
|
||||
@@ -139,8 +139,8 @@ class DelegateFind extends AbsDelegate {
|
||||
Class parentClazz = Class.forName(one.getType().getName());
|
||||
Class childClazz = Class.forName(CommonUtil.getListParamType(many).getName());
|
||||
// 检查表
|
||||
SqlUtil.checkTable(db, parentClazz);
|
||||
SqlUtil.checkTable(db, childClazz);
|
||||
SqlUtil.checkOrCreateTable(db, parentClazz);
|
||||
SqlUtil.checkOrCreateTable(db, childClazz);
|
||||
final String pTableName = parentClazz.getSimpleName();
|
||||
final String cTableName = childClazz.getSimpleName();
|
||||
List<Field> pColumn = SqlUtil.getAllNotIgnoreField(parentClazz);
|
||||
@@ -460,7 +460,7 @@ class DelegateFind extends AbsDelegate {
|
||||
*/
|
||||
private <T extends DbEntity> List<T> exeNormalDataSql(SQLiteDatabase db, Class<T> clazz,
|
||||
String sql, String[] selectionArgs) {
|
||||
SqlUtil.checkTable(db, clazz);
|
||||
SqlUtil.checkOrCreateTable(db, clazz);
|
||||
Cursor cursor;
|
||||
if (selectionArgs != null) {
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class DelegateUpdate extends AbsDelegate {
|
||||
*/
|
||||
synchronized <T extends DbEntity> void delData(SQLiteDatabase db, Class<T> clazz,
|
||||
String... expression) {
|
||||
SqlUtil.checkTable(db, clazz);
|
||||
SqlUtil.checkOrCreateTable(db, clazz);
|
||||
db = checkDb(db);
|
||||
if (!CommonUtil.checkSqlExpression(expression)) {
|
||||
return;
|
||||
@@ -58,7 +58,7 @@ class DelegateUpdate extends AbsDelegate {
|
||||
* 修改某行数据
|
||||
*/
|
||||
synchronized void updateData(SQLiteDatabase db, DbEntity dbEntity) {
|
||||
SqlUtil.checkTable(db, dbEntity.getClass());
|
||||
SqlUtil.checkOrCreateTable(db, dbEntity.getClass());
|
||||
db = checkDb(db);
|
||||
ContentValues values = createValues(dbEntity);
|
||||
if (values != null) {
|
||||
@@ -111,7 +111,7 @@ class DelegateUpdate extends AbsDelegate {
|
||||
if (oldClazz == null || oldClazz != entity.getClass() || table == null) {
|
||||
oldClazz = entity.getClass();
|
||||
table = CommonUtil.getClassName(oldClazz);
|
||||
SqlUtil.checkTable(db, oldClazz);
|
||||
SqlUtil.checkOrCreateTable(db, oldClazz);
|
||||
}
|
||||
|
||||
ContentValues value = createValues(entity);
|
||||
@@ -133,7 +133,7 @@ class DelegateUpdate extends AbsDelegate {
|
||||
* 插入数据
|
||||
*/
|
||||
synchronized void insertData(SQLiteDatabase db, DbEntity dbEntity) {
|
||||
SqlUtil.checkTable(db, dbEntity.getClass());
|
||||
SqlUtil.checkOrCreateTable(db, dbEntity.getClass());
|
||||
db = checkDb(db);
|
||||
ContentValues values = createValues(dbEntity);
|
||||
if (values != null) {
|
||||
|
||||
@@ -22,7 +22,11 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.TaskRecord;
|
||||
import com.arialyy.aria.core.ThreadRecord;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.M3U8Entity;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.wrapper.ITaskWrapper;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import java.io.File;
|
||||
@@ -308,6 +312,11 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
*/
|
||||
private void addTaskRecordType(SQLiteDatabase db) {
|
||||
try {
|
||||
SqlUtil.checkOrCreateTable(db, ThreadRecord.class);
|
||||
SqlUtil.checkOrCreateTable(db, TaskRecord.class);
|
||||
SqlUtil.checkOrCreateTable(db, UploadEntity.class);
|
||||
SqlUtil.checkOrCreateTable(db, DownloadEntity.class);
|
||||
|
||||
db.beginTransaction();
|
||||
/*
|
||||
* 增加下载实体的类型
|
||||
@@ -380,6 +389,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
* 删除重复的repeat数据
|
||||
*/
|
||||
private void delRepeatThreadRecord(SQLiteDatabase db) {
|
||||
SqlUtil.checkOrCreateTable(db, ThreadRecord.class);
|
||||
String repeatSql = "DELETE FROM ThreadRecord WHERE (rowid) "
|
||||
+ "IN (SELECT rowid FROM ThreadRecord GROUP BY taskKey, threadId, endLocation HAVING COUNT(*) > 1) "
|
||||
+ "AND rowid NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY taskKey, threadId, endLocation HAVING COUNT(*)> 1)";
|
||||
@@ -406,6 +416,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
* 处理365版本以下的升级
|
||||
*/
|
||||
private void handle365Update(SQLiteDatabase db) {
|
||||
SqlUtil.checkOrCreateTable(db, ThreadRecord.class);
|
||||
db.execSQL("UPDATE ThreadRecord SET threadId=0 WHERE threadId=-1");
|
||||
|
||||
Map<String, Map<String, String>> modifyMap = new HashMap<>();
|
||||
|
||||
@@ -49,7 +49,7 @@ final class SqlUtil {
|
||||
/**
|
||||
* 检查表是否存在,不存在则创建表
|
||||
*/
|
||||
static void checkTable(SQLiteDatabase db, Class<? extends DbEntity> clazz) {
|
||||
static void checkOrCreateTable(SQLiteDatabase db, Class<? extends DbEntity> clazz) {
|
||||
if (!tableExists(db, clazz)) {
|
||||
createTable(db, clazz);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user