子任务控制选择bug修复
This commit is contained in:
@@ -67,6 +67,10 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
mConstance = new StateConstance();
|
||||
}
|
||||
|
||||
public void setNewTask(boolean newTask) {
|
||||
mTaskEntity.isNewTask = newTask;
|
||||
}
|
||||
|
||||
@Override public void setMaxSpeed(double maxSpeed) {
|
||||
for (int i = 0; i < mThreadNum; i++) {
|
||||
AbsThreadTask task = mTask.get(i);
|
||||
@@ -134,6 +138,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
if (mTimer != null) {
|
||||
mTimer.purge();
|
||||
mTimer.cancel();
|
||||
mTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download.downloader;
|
||||
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.IUtil;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@@ -48,7 +49,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
private ExecutorService mExePool;
|
||||
protected IDownloadGroupListener mListener;
|
||||
protected DownloadGroupTaskEntity mTaskEntity;
|
||||
private boolean isRunning = true;
|
||||
private boolean isRunning = false;
|
||||
private Timer mTimer;
|
||||
/**
|
||||
* 初始化完成的任务书数
|
||||
@@ -137,12 +138,14 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
* @param url 子任务下载地址
|
||||
*/
|
||||
public void startSubTask(String url) {
|
||||
if (!checkSubTask(url, "开始")) return;
|
||||
if (!isRunning) {
|
||||
isRunning = true;
|
||||
if (mTimer == null) {
|
||||
startTimer();
|
||||
}
|
||||
Downloader d = getDownloader(url);
|
||||
Downloader d = getDownloader(url, false);
|
||||
if (d != null && !d.isRunning()) {
|
||||
d.setNewTask(false);
|
||||
d.start();
|
||||
}
|
||||
}
|
||||
@@ -153,7 +156,8 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
* @param url 子任务下载地址
|
||||
*/
|
||||
public void stopSubTask(String url) {
|
||||
Downloader d = getDownloader(url);
|
||||
if (!checkSubTask(url, "停止")) return;
|
||||
Downloader d = getDownloader(url, false);
|
||||
if (d != null && d.isRunning()) {
|
||||
d.stop();
|
||||
}
|
||||
@@ -165,21 +169,43 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
* @param url 子任务下载地址
|
||||
*/
|
||||
public void cancelSunTask(String url) {
|
||||
Downloader d = getDownloader(url);
|
||||
Downloader d = getDownloader(url, false);
|
||||
if (d != null) {
|
||||
d.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查子任务
|
||||
*
|
||||
* @param url 子任务url
|
||||
* @param type 任务类型
|
||||
* @return {@code true} 任务可以下载
|
||||
*/
|
||||
private boolean checkSubTask(String url, String type) {
|
||||
DownloadTaskEntity entity = mTasksMap.get(url);
|
||||
if (entity != null) {
|
||||
if (entity.getState() == IEntity.STATE_COMPLETE) {
|
||||
Log.w(TAG, "任务【" + url + "】已完成," + type + "失败");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "任务组中没有该任务【" + url + "】," + type + "失败");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过地址获取下载器
|
||||
*
|
||||
* @param url 子任务下载地址
|
||||
* @param start 是否启动任务
|
||||
*/
|
||||
private Downloader getDownloader(String url) {
|
||||
private Downloader getDownloader(String url, boolean start) {
|
||||
Downloader d = mDownloaderMap.get(url);
|
||||
if (d == null) {
|
||||
return startChildDownload(mExeMap.get(url));
|
||||
return createChildDownload(mTasksMap.get(url), start);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -317,14 +343,25 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动子任务下载器
|
||||
* 创建子任务下载器,默认创建完成自动启动
|
||||
*/
|
||||
Downloader startChildDownload(DownloadTaskEntity taskEntity) {
|
||||
Downloader createChildDownload(DownloadTaskEntity taskEntity) {
|
||||
return createChildDownload(taskEntity, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建子任务下载器,启动子任务下载器
|
||||
*
|
||||
* @param start 是否启动下载
|
||||
*/
|
||||
Downloader createChildDownload(DownloadTaskEntity taskEntity, boolean start) {
|
||||
ChildDownloadListener listener = new ChildDownloadListener(taskEntity);
|
||||
Downloader dt = new Downloader(listener, taskEntity);
|
||||
mDownloaderMap.put(taskEntity.getEntity().getUrl(), dt);
|
||||
if (mExePool.isShutdown()) return dt;
|
||||
if (start) {
|
||||
mExePool.execute(dt);
|
||||
}
|
||||
return dt;
|
||||
}
|
||||
|
||||
@@ -339,6 +376,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
taskEntity.userName = mTaskEntity.userName;
|
||||
taskEntity.userPw = mTaskEntity.userPw;
|
||||
taskEntity.account = mTaskEntity.account;
|
||||
mTasksMap.put(entity.getUrl(), taskEntity);
|
||||
return taskEntity;
|
||||
}
|
||||
taskEntity = new DownloadTaskEntity();
|
||||
@@ -356,6 +394,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
taskEntity.account = mTaskEntity.account;
|
||||
taskEntity.key = entity.getDownloadPath();
|
||||
taskEntity.save();
|
||||
mTasksMap.put(entity.getUrl(), taskEntity);
|
||||
return taskEntity;
|
||||
}
|
||||
|
||||
@@ -402,10 +441,10 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
@Override public void onProgress(long currentLocation) {
|
||||
long speed = currentLocation - lastLen;
|
||||
mCurrentLocation += speed;
|
||||
lastLen = currentLocation;
|
||||
entity.setCurrentProgress(currentLocation);
|
||||
handleSpeed(speed);
|
||||
mListener.onSubRunning(entity);
|
||||
lastLen = currentLocation;
|
||||
}
|
||||
|
||||
@Override public void onStop(long stopLocation) {
|
||||
@@ -413,7 +452,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
handleSpeed(0);
|
||||
mListener.onSubStop(entity);
|
||||
mStopNum++;
|
||||
if (mStopNum >= mInitNum) {
|
||||
if (mStopNum + mCompleteNum >= mInitNum) {
|
||||
closeTimer(false);
|
||||
mListener.onStop(mCurrentLocation);
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
if (taskEntity != null) {
|
||||
if (taskEntity.getState() != IEntity.STATE_FAIL
|
||||
&& taskEntity.getState() != IEntity.STATE_WAIT) {
|
||||
startChildDownload(taskEntity);
|
||||
createChildDownload(taskEntity);
|
||||
i++;
|
||||
} else {
|
||||
mInfoPool.execute(createFileInfoThread(taskEntity));
|
||||
@@ -94,7 +94,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
if (isNeedLoadFileSize) {
|
||||
mTotalSize += te.getEntity().getFileSize();
|
||||
}
|
||||
startChildDownload(te);
|
||||
createChildDownload(te);
|
||||
}
|
||||
mInitNum++;
|
||||
if (mInitNum + mInitFailNum >= mTaskEntity.getEntity().getSubTask().size()
|
||||
|
@@ -60,7 +60,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
|
||||
for (String key : keys) {
|
||||
DownloadTaskEntity taskEntity = mExeMap.get(key);
|
||||
if (taskEntity != null) {
|
||||
startChildDownload(taskEntity);
|
||||
createChildDownload(taskEntity);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@@ -86,7 +86,6 @@ import java.util.List;
|
||||
@DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
L.d(TAG, "p ==> " + subEntity.getPercent());
|
||||
mPb.setProgress(subEntity.getPercent());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user