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