e 7 years ago
parent 755e333d8b
commit 754e23a2f2
  1. 39
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 2
      Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java

@ -63,7 +63,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
*/
private static final long SUB_LEN = 1024 * 1024;
private Timer mTimer;
private long mUpdateInterval = 1000;
protected AbsFileer(IEventListener listener, TASK_ENTITY taskEntity) {
mListener = listener;
@ -98,7 +97,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
/**
* 开始流程
* 开始下载流程
*/
private void startFlow() {
mConstance.resetState();
@ -112,7 +111,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
mConstance.THREAD_NUM = mTotalThreadNum;
handleNoSupportBP();
} else {
mTotalThreadNum = isNewTask ? (getNewTaskThreadNum()) : mStartThreadNum + mCompleteThreadNum;
mTotalThreadNum = isNewTask ? (getNewTaskThreadNum()) : mStartThreadNum;
mConstance.THREAD_NUM = mTotalThreadNum;
handleBreakpoint();
}
@ -146,7 +145,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
mListener.onProgress(mConstance.CURRENT_LOCATION);
}
}
}, 0, mUpdateInterval);
}, 0, 1000);
}
protected void closeTimer() {
@ -226,25 +225,11 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
return mListener;
}
/**
* 设置定时器更新间隔
*
* @param interval 单位毫秒不能小于0
*/
protected long setUpdateInterval(long interval) {
if (interval < 0) {
ALog.w(TAG, "更新间隔不能小于0,默认为1000毫秒");
return 1000;
}
mUpdateInterval = interval;
return interval;
}
/**
* 检查任务是否是新任务新任务条件
* 1文件不存在
* 2记录文件不存在
* 3记录文件缺失或不匹配
* 2下载记录文件不存在
* 3下载记录文件缺失或不匹配
* 4数据库记录不存在
* 5不支持断点则是新任务
*/
@ -264,9 +249,10 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
int num = 0;
for (Object key : keys) {
String str = String.valueOf(key);
Object state = pro.getProperty(str);
if (str.contains("_record_")) {
num++;
} else if (str.contains("_state_")) {
} else if (state != null && str.contains("_state_") && Integer.parseInt(state + "") == 1) {
mCompleteThreadNum++;
}
}
@ -289,7 +275,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
/**
* 恢复记录地址
*
* @return true 表示完成
* @return true 表示下载完成
*/
private boolean resumeRecordLocation(int i, long startL, long endL) {
mConstance.CURRENT_LOCATION += endL - startL;
@ -357,11 +343,12 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
//如果有记录,则恢复下载
if (!isNewTask && record != null && Long.parseLong(record + "") >= 0) {
Long r = Long.parseLong(record + "");
if (r > startL) {
//记录的位置需要在线程区间中
if (startL < r && r < (i == (mTotalThreadNum - 1) ? fileLength : endL)) {
mConstance.CURRENT_LOCATION += r - startL;
startL = r;
}
ALog.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复");
ALog.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复下载");
recordL[rl] = i;
rl++;
} else {
@ -380,7 +367,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
/**
* 启动单线程处理任务
* 启动单线程下载任务
*/
private void startSingleTask(int[] recordL) {
if (mConstance.CURRENT_LOCATION > 0) {
@ -405,7 +392,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
protected abstract void handleNewTask();
/**
* 处理不支持断点的任务
* 处理不支持断点的下载
*/
private void handleNoSupportBP() {
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();

@ -63,7 +63,7 @@ public class StateConstance {
* 所有子线程是否都已经完成下载
*/
public boolean isComplete() {
return COMPLETE_THREAD_NUM == THREAD_NUM;
return COMPLETE_THREAD_NUM >= THREAD_NUM;
}
/**

Loading…
Cancel
Save