bug fix
This commit is contained in:
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.arialyy.aria.core.command.normal;
|
package com.arialyy.aria.core.command.normal;
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
import com.arialyy.aria.core.command.AbsCmd;
|
import com.arialyy.aria.core.command.AbsCmd;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||||
|
@ -32,9 +32,14 @@ class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
|||||||
@Override public void executeCmd() {
|
@Override public void executeCmd() {
|
||||||
if (!canExeCmd) return;
|
if (!canExeCmd) return;
|
||||||
AbsTask task = getTask();
|
AbsTask task = getTask();
|
||||||
if (!TextUtils.isEmpty(mTargetName)) {
|
if (task == null) {
|
||||||
task.setTargetName(mTargetName);
|
task = createTask();
|
||||||
|
}
|
||||||
|
if (task != null) {
|
||||||
|
if (!TextUtils.isEmpty(mTargetName)) {
|
||||||
|
task.setTargetName(mTargetName);
|
||||||
|
}
|
||||||
|
removeTask();
|
||||||
}
|
}
|
||||||
removeTask();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,9 @@ import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
|||||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||||
import com.arialyy.aria.core.inf.IEntity;
|
import com.arialyy.aria.core.inf.IEntity;
|
||||||
|
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||||
|
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||||
|
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -69,6 +72,13 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
|||||||
* @param te 任务实体
|
* @param te 任务实体
|
||||||
*/
|
*/
|
||||||
private void resumeEntity(AbsTaskEntity te) {
|
private void resumeEntity(AbsTaskEntity te) {
|
||||||
|
if (te instanceof DownloadTaskEntity) {
|
||||||
|
mQueue = DownloadTaskQueue.getInstance();
|
||||||
|
} else if (te instanceof UploadTaskEntity) {
|
||||||
|
mQueue = UploadTaskQueue.getInstance();
|
||||||
|
} else if (te instanceof DownloadGroupTaskEntity) {
|
||||||
|
mQueue = DownloadGroupTaskQueue.getInstance();
|
||||||
|
}
|
||||||
int exeNum = mQueue.getCurrentExePoolNum();
|
int exeNum = mQueue.getCurrentExePoolNum();
|
||||||
if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) {
|
if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) {
|
||||||
startTask(createTask(te));
|
startTask(createTask(te));
|
||||||
|
@ -33,13 +33,19 @@ public class DownloadTarget
|
|||||||
protected String url;
|
protected String url;
|
||||||
|
|
||||||
DownloadTarget(DownloadEntity entity, String targetName) {
|
DownloadTarget(DownloadEntity entity, String targetName) {
|
||||||
this(entity.getUrl(), targetName);
|
this.url = entity.getUrl();
|
||||||
|
mTargetName = targetName;
|
||||||
|
initTask(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadTarget(String url, String targetName) {
|
DownloadTarget(String url, String targetName) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
mTargetName = targetName;
|
mTargetName = targetName;
|
||||||
DownloadEntity entity = getEntity(url);
|
DownloadEntity entity = getEntity(url);
|
||||||
|
initTask(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initTask(DownloadEntity entity) {
|
||||||
mTaskEntity = DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'",
|
mTaskEntity = DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'",
|
||||||
entity.getDownloadPath());
|
entity.getDownloadPath());
|
||||||
if (mTaskEntity == null) {
|
if (mTaskEntity == null) {
|
||||||
|
@ -44,10 +44,10 @@ abstract class AbsGroupUtil implements IUtil {
|
|||||||
* 任务组所有任务总大小
|
* 任务组所有任务总大小
|
||||||
*/
|
*/
|
||||||
long mTotalSize = 0;
|
long mTotalSize = 0;
|
||||||
private long mCurrentLocation = 0;
|
protected long mCurrentLocation = 0;
|
||||||
private ExecutorService mExePool;
|
private ExecutorService mExePool;
|
||||||
protected IDownloadGroupListener mListener;
|
protected IDownloadGroupListener mListener;
|
||||||
DownloadGroupTaskEntity mTaskEntity;
|
protected DownloadGroupTaskEntity mTaskEntity;
|
||||||
private boolean isRunning = true;
|
private boolean isRunning = true;
|
||||||
private Timer mTimer;
|
private Timer mTimer;
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +72,10 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == mExeMap.size()) startRunningFlow();
|
if (i != 0 && i == mExeMap.size()) startRunningFlow();
|
||||||
|
if (mCurrentLocation == mTotalSize) {
|
||||||
|
mListener.onComplete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -575,6 +575,10 @@ public class CommonUtil {
|
|||||||
* 如果文件存在,先删除原文件,然后重新创建一个新文件
|
* 如果文件存在,先删除原文件,然后重新创建一个新文件
|
||||||
*/
|
*/
|
||||||
public static void createFile(String path) {
|
public static void createFile(String path) {
|
||||||
|
if (TextUtils.isEmpty(path)) {
|
||||||
|
Log.e(TAG, "文件路径不能为null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (!file.getParentFile().exists()) {
|
if (!file.getParentFile().exists()) {
|
||||||
Log.d(TAG, "目标文件所在路径不存在,准备创建……");
|
Log.d(TAG, "目标文件所在路径不存在,准备创建……");
|
||||||
|
@ -25,6 +25,7 @@ import android.view.View;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
|
import com.arialyy.annotations.Download;
|
||||||
import com.arialyy.aria.core.Aria;
|
import com.arialyy.aria.core.Aria;
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadTarget;
|
import com.arialyy.aria.core.download.DownloadTarget;
|
||||||
@ -71,6 +72,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
|||||||
setTitle("最高优先级任务");
|
setTitle("最高优先级任务");
|
||||||
getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)");
|
getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)");
|
||||||
initWidget();
|
initWidget();
|
||||||
|
Aria.download(this).register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initWidget() {
|
private void initWidget() {
|
||||||
@ -97,11 +99,6 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
|||||||
mList.setAdapter(mAdapter);
|
mList.setAdapter(mAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean onCreateOptionsMenu(Menu menu) {
|
@Override public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.menu_highest_priority, menu);
|
getMenuInflater().inflate(R.menu.menu_highest_priority, menu);
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
@ -169,77 +166,72 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
|
|||||||
mStop.setEnabled(!state);
|
mStop.setEnabled(!state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
|
@Download.onPre public void onPre(DownloadTask task) {
|
||||||
|
mAdapter.updateState(task.getDownloadEntity());
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onPre(DownloadTask task) {
|
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
|
||||||
super.onPre(task);
|
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||||
mAdapter.updateState(task.getDownloadEntity());
|
mSize.setText(task.getConvertFileSize());
|
||||||
}
|
}
|
||||||
|
mAdapter.updateState(task.getDownloadEntity());
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onTaskPre(DownloadTask task) {
|
@Download.onTaskStart public void onTaskStart(DownloadTask task) {
|
||||||
super.onTaskPre(task);
|
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
setBtState(false);
|
||||||
mSize.setText(task.getConvertFileSize());
|
|
||||||
}
|
|
||||||
mAdapter.updateState(task.getDownloadEntity());
|
|
||||||
}
|
}
|
||||||
|
mAdapter.updateState(task.getDownloadEntity());
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onTaskStart(DownloadTask task) {
|
@Download.onTaskResume public void onTaskResume(DownloadTask task) {
|
||||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||||
setBtState(false);
|
setBtState(false);
|
||||||
}
|
|
||||||
mAdapter.updateState(task.getDownloadEntity());
|
|
||||||
}
|
}
|
||||||
|
mAdapter.updateState(task.getDownloadEntity());
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onTaskResume(DownloadTask task) {
|
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
|
||||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||||
setBtState(false);
|
setBtState(true);
|
||||||
}
|
mStart.setText("恢复");
|
||||||
mAdapter.updateState(task.getDownloadEntity());
|
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
|
||||||
}
|
}
|
||||||
|
mAdapter.updateState(task.getDownloadEntity());
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onTaskStop(DownloadTask task) {
|
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
|
||||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||||
setBtState(true);
|
setBtState(true);
|
||||||
mStart.setText("恢复");
|
mStart.setText("开始");
|
||||||
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
|
mPb.setProgress(0);
|
||||||
}
|
|
||||||
mAdapter.updateState(task.getDownloadEntity());
|
|
||||||
}
|
}
|
||||||
|
mAdapter.updateState(task.getDownloadEntity());
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onTaskCancel(DownloadTask task) {
|
@Download.onTaskFail public void onTaskFail(DownloadTask task) {
|
||||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||||
setBtState(true);
|
setBtState(true);
|
||||||
mStart.setText("开始");
|
} else {
|
||||||
mPb.setProgress(0);
|
L.d(TAG, "download fail【" + task.getKey() + "】");
|
||||||
}
|
|
||||||
mAdapter.updateState(task.getDownloadEntity());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onTaskFail(DownloadTask task) {
|
|
||||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
|
||||||
setBtState(true);
|
|
||||||
} else {
|
|
||||||
L.d(TAG, "download fail【" + task.getKey() + "】");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onTaskComplete(DownloadTask task) {
|
|
||||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
|
||||||
setBtState(true);
|
|
||||||
mStart.setText("重新开始");
|
|
||||||
mStart.setTextColor(getResources().getColor(android.R.color.holo_green_light));
|
|
||||||
mPb.setProgress(100);
|
|
||||||
}
|
|
||||||
mAdapter.updateState(task.getDownloadEntity());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onTaskRunning(DownloadTask task) {
|
|
||||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
|
||||||
mPb.setProgress(task.getPercent());
|
|
||||||
mSpeed.setText(task.getConvertSpeed());
|
|
||||||
}
|
|
||||||
mAdapter.setProgress(task.getDownloadEntity());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
|
||||||
|
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||||
|
setBtState(true);
|
||||||
|
mStart.setText("重新开始");
|
||||||
|
mStart.setTextColor(getResources().getColor(android.R.color.holo_green_light));
|
||||||
|
mPb.setProgress(100);
|
||||||
|
}
|
||||||
|
mAdapter.updateState(task.getDownloadEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
|
||||||
|
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||||
|
mPb.setProgress(task.getPercent());
|
||||||
|
mSpeed.setText(task.getConvertSpeed());
|
||||||
|
}
|
||||||
|
mAdapter.setProgress(task.getDownloadEntity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user