pull/330/head
AriaLyy 7 years ago
parent f5babb38f1
commit 063a0e95c2
  1. 1
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  2. 5
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java
  3. 10
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  4. 8
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  6. 5
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  7. 4
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  8. 30
      app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java

@ -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 (task == null) {
task = createTask();
}
if (task != null) {
if (!TextUtils.isEmpty(mTargetName)) {
task.setTargetName(mTargetName);
}
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,36 +166,32 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mStop.setEnabled(!state);
}
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
@Override public void onPre(DownloadTask task) {
super.onPre(task);
@Download.onPre public void onPre(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mSize.setText(task.getConvertFileSize());
}
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskStart(DownloadTask task) {
@Download.onTaskStart public void onTaskStart(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskResume(DownloadTask task) {
@Download.onTaskResume public void onTaskResume(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskStop(DownloadTask task) {
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("恢复");
@ -207,7 +200,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskCancel(DownloadTask task) {
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("开始");
@ -216,7 +209,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskFail(DownloadTask task) {
@Download.onTaskFail public void onTaskFail(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
} else {
@ -224,7 +217,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
}
}
@Override public void onTaskComplete(DownloadTask task) {
@Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("重新开始");
@ -234,12 +227,11 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskRunning(DownloadTask task) {
@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());
}
}
}

Loading…
Cancel
Save