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