Merge branch 'v_3.0'

pull/330/head
AriaLyy 7 years ago
commit 05cee573de
  1. 92
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java
  4. 7
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java
  6. 78
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  7. 10
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  8. 2
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java
  9. 7
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java
  10. 8
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  11. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  12. 5
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  13. 119
      Aria/src/main/java/com/arialyy/aria/core/queue/QueueControl.java
  14. 4
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  15. 4
      app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java
  16. 30
      app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java
  17. 6
      app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java

@ -19,12 +19,13 @@ package com.arialyy.aria.core.command.normal;
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;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue; 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.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
/** /**
@ -32,12 +33,13 @@ import com.arialyy.aria.util.CommonUtil;
* 下载命令 * 下载命令
*/ */
public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> { public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
/** /**
* 能否执行命令 * 能否执行命令
*/ */
boolean canExeCmd = true; boolean canExeCmd = true;
private AbsTask tempTask = null;
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */
@ -58,4 +60,90 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
isDownloadCmd = true; isDownloadCmd = true;
} }
} }
/**
* 删除所有任务
*/
void removeAll() {
mQueue.removeAllTask();
}
/**
* 停止所有任务
*/
void stopAll() {
mQueue.stopAllTask();
}
/**
* 停止任务
*/
void stopTask() {
if (tempTask == null) createTask();
mQueue.stopTask(tempTask);
}
/**
* 删除任务
*/
void removeTask() {
if (tempTask == null) createTask();
mQueue.removeTask(tempTask);
}
/**
* 启动任务
*/
void startTask() {
mQueue.startTask(tempTask);
}
/**
* 启动指定任务
*
* @param task 指定任务
*/
void startTask(AbsTask task) {
mQueue.startTask(task);
}
/**
* 从队列中获取任务
*
* @return 执行任务
*/
AbsTask getTask() {
tempTask = mQueue.getTask(mTaskEntity.getEntity());
return tempTask;
}
/**
* 从队列中获取任务
*
* @return 执行任务
*/
AbsTask getTask(AbsEntity entity) {
tempTask = mQueue.getTask(entity);
return tempTask;
}
/**
* 创建任务
*
* @return 创建的任务
*/
AbsTask createTask() {
tempTask = mQueue.createTask(mTargetName, mTaskEntity);
return tempTask;
}
/**
* 创建指定实体的任务
*
* @param taskEntity 特定的任务实体
* @return 创建的任务
*/
AbsTask createTask(AbsTaskEntity taskEntity) {
return mQueue.createTask(mTargetName, taskEntity);
}
} }

@ -33,10 +33,10 @@ class AddCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
@Override public void executeCmd() { @Override public void executeCmd() {
if (!canExeCmd) return; if (!canExeCmd) return;
AbsTask task = mQueue.getTask(mTaskEntity.getEntity()); AbsTask task = getTask();
if (task == null) { if (task == null) {
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT); mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
mQueue.createTask(mTargetName, mTaskEntity); createTask();
} else { } else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】"); Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
} }

@ -36,7 +36,7 @@ final class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
} }
@Override public void executeCmd() { @Override public void executeCmd() {
mQueue.removeAllTask(); removeAll();
if (mTaskEntity instanceof DownloadTaskEntity) { if (mTaskEntity instanceof DownloadTaskEntity) {
handleDownloadRemove(); handleDownloadRemove();
} else if (mTaskEntity instanceof UploadTaskEntity){ } else if (mTaskEntity instanceof UploadTaskEntity){

@ -17,7 +17,6 @@
package com.arialyy.aria.core.command.normal; package com.arialyy.aria.core.command.normal;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.inf.AbsNormalTask;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
@ -32,15 +31,15 @@ class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
@Override public void executeCmd() { @Override public void executeCmd() {
if (!canExeCmd) return; if (!canExeCmd) return;
AbsTask task = mQueue.getTask(mTaskEntity.getEntity()); AbsTask task = getTask();
if (task == null) { if (task == null) {
task = mQueue.createTask(mTargetName, mTaskEntity); task = createTask();
} }
if (task != null) { if (task != null) {
if (!TextUtils.isEmpty(mTargetName)) { if (!TextUtils.isEmpty(mTargetName)) {
task.setTargetName(mTargetName); task.setTargetName(mTargetName);
} }
mQueue.removeTask(task); removeTask();
} }
} }
} }

@ -43,9 +43,9 @@ final class HighestPriorityCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T>
@Override public void executeCmd() { @Override public void executeCmd() {
if (!canExeCmd) return; if (!canExeCmd) return;
DownloadTask task = (DownloadTask) mQueue.getTask(mTaskEntity.getEntity()); DownloadTask task = (DownloadTask) getTask();
if (task == null) { if (task == null) {
task = (DownloadTask) mQueue.createTask(mTargetName, mTaskEntity); task = (DownloadTask) createTask();
} }
if (task != null) { if (task != null) {
if (!TextUtils.isEmpty(mTargetName)) { if (!TextUtils.isEmpty(mTargetName)) {

@ -1,11 +1,13 @@
package com.arialyy.aria.core.command.normal; package com.arialyy.aria.core.command.normal;
import android.util.Log; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTask;
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.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import java.util.List; import java.util.List;
@ -24,29 +26,65 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
} }
@Override public void executeCmd() { @Override public void executeCmd() {
List<DownloadEntity> allEntity = if (isDownloadCmd) {
DbEntity.findDatas(DownloadEntity.class, "state=?", IEntity.STATE_STOP + ""); resumeDownload();
for (DownloadEntity entity : allEntity) {
int exeNum = mQueue.getCurrentExePoolNum();
if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) {
AbsTask task = createTask(entity);
mQueue.startTask(task);
} else { } else {
entity.setState(IEntity.STATE_WAIT); resumeUpload();
createTask(entity); }
}
/**
* 恢复下载包括普通任务和任务组
*/
private void resumeDownload() {
List<DownloadTaskEntity> dTaskEntity =
DbEntity.findDatas(DownloadTaskEntity.class, "isGroupTask=?", "false");
for (DownloadTaskEntity te : dTaskEntity) {
int state = te.getState();
if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue;
resumeEntity(te);
}
List<DownloadGroupTaskEntity> groupTask = DbEntity.findAllData(DownloadGroupTaskEntity.class);
for (DownloadGroupTaskEntity te : groupTask) {
int state = te.getState();
if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue;
resumeEntity(te);
} }
} }
/**
* 恢复上传包括普通任务和任务组
*/
private void resumeUpload() {
List<UploadTaskEntity> dTaskEntity =
DbEntity.findDatas(UploadTaskEntity.class, "isGroupTask=?", "false");
for (UploadTaskEntity te : dTaskEntity) {
int state = te.getState();
if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue;
resumeEntity(te);
}
} }
private AbsTask createTask(DownloadEntity entity) { /**
AbsTask task = mQueue.getTask(entity); * 恢复实体任务
if (task == null) { *
DownloadTaskEntity taskEntity = new DownloadTaskEntity(); * @param te 任务实体
taskEntity.entity = entity; */
task = mQueue.createTask(mTargetName, taskEntity); 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));
} else { } else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】"); te.getEntity().setState(IEntity.STATE_WAIT);
createTask(te);
} }
return task;
} }
} }

@ -47,26 +47,26 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
maxTaskNum = manager.getUploadConfig().getMaxTaskNum(); maxTaskNum = manager.getUploadConfig().getMaxTaskNum();
} }
AbsTask task = mQueue.getTask(mTaskEntity.getEntity()); AbsTask task = getTask();
if (task == null) { if (task == null) {
task = mQueue.createTask(mTargetName, mTaskEntity); task = createTask();
if (!TextUtils.isEmpty(mTargetName)) { if (!TextUtils.isEmpty(mTargetName)) {
task.setTargetName(mTargetName); task.setTargetName(mTargetName);
} }
// 任务不存在时,根据配置不同,对任务执行操作 // 任务不存在时,根据配置不同,对任务执行操作
if (mod.equals(QueueMod.NOW.getTag())) { if (mod.equals(QueueMod.NOW.getTag())) {
mQueue.startTask(task); startTask();
} else if (mod.equals(QueueMod.WAIT.getTag())) { } else if (mod.equals(QueueMod.WAIT.getTag())) {
if (mQueue.getCurrentExePoolNum() < maxTaskNum if (mQueue.getCurrentExePoolNum() < maxTaskNum
|| task.getState() == IEntity.STATE_STOP || task.getState() == IEntity.STATE_STOP
|| task.getState() == IEntity.STATE_COMPLETE) { || task.getState() == IEntity.STATE_COMPLETE) {
mQueue.startTask(task); startTask();
} }
} }
} else { } else {
// 任务不存在时,根据配置不同,对任务执行操作 // 任务不存在时,根据配置不同,对任务执行操作
if (!task.isRunning()) { if (!task.isRunning()) {
mQueue.startTask(task); startTask();
} }
} }
} }

@ -15,6 +15,6 @@ final class StopAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
} }
@Override public void executeCmd() { @Override public void executeCmd() {
mQueue.stopAllTask(); stopAll();
} }
} }

@ -34,11 +34,10 @@ class StopCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
@Override public void executeCmd() { @Override public void executeCmd() {
if (!canExeCmd) return; if (!canExeCmd) return;
AbsTask task = mQueue.getTask(mTaskEntity.getEntity()); AbsTask task = getTask();
if (task == null) { if (task == null) {
if (mTaskEntity.getEntity().getState() == IEntity.STATE_RUNNING) { if (mTaskEntity.getEntity().getState() == IEntity.STATE_RUNNING) {
task = mQueue.createTask(mTargetName, mTaskEntity); stopTask();
mQueue.stopTask(task);
} else { } else {
Log.w(TAG, "停止命令执行失败,【调度器中没有该任务】"); Log.w(TAG, "停止命令执行失败,【调度器中没有该任务】");
} }
@ -46,7 +45,7 @@ class StopCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
if (!TextUtils.isEmpty(mTargetName)) { if (!TextUtils.isEmpty(mTargetName)) {
task.setTargetName(mTargetName); task.setTargetName(mTargetName);
} }
mQueue.stopTask(task); stopTask();
} }
} }
} }

@ -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();
}
} }
/** /**

@ -0,0 +1,119 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.queue;
import android.os.Handler;
import android.os.Message;
import android.util.SparseArray;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity;
/**
* Created by Aria.Lao on 2017/8/3.
* 队列控制器用于处理各种命令
*/
public class QueueControl implements Handler.Callback {
/**
* 获取任务命令
*/
public static final int CMD_GET_TASK = 0xa1;
/**
* 创建任务命令
*/
public static final int CMD_CREATE_TASK = 0xa2;
/**
* 启动任务命令
*/
public static final int CMD_START_TASK = 0xa3;
/**
* 停止任务命令
*/
public static final int CMD_STOP_TASK = 0xa4;
/**
* 删除任务命令
*/
public static final int CMD_CANCEL_TASK = 0xa5;
/**
* 停止所有任务命令
*/
public static final int CMD_STOP_ALL_TASK = 0xa6;
/**
* 删除所有任务命令
*/
public static final int CMD_CANCEL_ALL_TASK = 0xa7;
/**
* 队列类型为单文件下载队列
*/
public static final int TYPE_SIMPLE_DOWNLOAD_QUEUE = 0xc1;
/**
* 队列类型为任务组下载队列
*/
public static final int TYPE_SIMPLE_DOWNLOAD_GROUP_QUEUE = 0xc2;
/**
* 队列类型为单文件上传队列
*/
public static final int TYPE_SIMPLE_UPLOAD_QUEUE = 0xc3;
private Handler outHandler;
private AbsTaskQueue queue;
public QueueControl(Handler.Callback callback, int type) {
outHandler = new Handler(callback);
switch (type) {
case TYPE_SIMPLE_DOWNLOAD_QUEUE:
queue = DownloadTaskQueue.getInstance();
break;
case TYPE_SIMPLE_DOWNLOAD_GROUP_QUEUE:
queue = DownloadGroupTaskQueue.getInstance();
break;
case TYPE_SIMPLE_UPLOAD_QUEUE:
queue = UploadTaskQueue.getInstance();
break;
}
}
@Override public boolean handleMessage(Message msg) {
switch (msg.what) {
case CMD_GET_TASK:
outHandler.obtainMessage(CMD_GET_TASK, queue.getTask((AbsEntity) msg.obj)).sendToTarget();
break;
case CMD_CREATE_TASK:
SparseArray params = (SparseArray) msg.obj;
outHandler.obtainMessage(CMD_CREATE_TASK,
queue.createTask(String.valueOf(params.get(1)), (AbsTaskEntity) params.get(2)))
.sendToTarget();
break;
case CMD_START_TASK:
queue.startTask((AbsTask) msg.obj);
break;
case CMD_STOP_TASK:
queue.stopTask((AbsTask) msg.obj);
break;
case CMD_CANCEL_TASK:
queue.removeTask((AbsTask) msg.obj);
break;
case CMD_STOP_ALL_TASK:
queue.stopAllTask();
break;
case CMD_CANCEL_ALL_TASK:
queue.removeAllTask();
break;
}
return true;
}
}

@ -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, "目标文件所在路径不存在,准备创建……");

@ -37,7 +37,7 @@ import java.io.File;
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> { public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
//private final String URL = "ftp://172.18.104.129:21/haha/large.rar"; //private final String URL = "ftp://172.18.104.129:21/haha/large.rar";
//private final String URL = "ftp://172.18.104.129:21/haha/large.rar"; //private final String URL = "ftp://172.18.104.129:21/haha/large.rar";
private final String URL = "ftp://172.18.104.129:21/haha/很大的文件_v100.rar"; private final String URL = "ftp://172.18.104.66:21/haha/成都.mp3";
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState); super.init(savedInstanceState);
@ -113,7 +113,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
getBinding().setSpeed(""); getBinding().setSpeed("");
getBinding().setProgress(100); getBinding().setProgress(100);
Log.d(TAG, "md5 ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); Log.d(TAG, "md5 ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
T.showShort(this, "FTP下载完成"); T.showShort(this, "文件:" + task.getEntity().getFileName() + ",下载完成");
} }
@Override protected int setLayoutId() { @Override protected int setLayoutId() {

@ -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,36 +166,32 @@ 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) {
@Override public void onPre(DownloadTask task) {
super.onPre(task);
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Override public void onTaskPre(DownloadTask task) { @Download.onTaskPre public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
mSize.setText(task.getConvertFileSize()); mSize.setText(task.getConvertFileSize());
} }
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Override public void onTaskStart(DownloadTask task) { @Download.onTaskStart public void onTaskStart(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.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 onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true); setBtState(true);
mStart.setText("恢复"); mStart.setText("恢复");
@ -207,7 +200,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Override public void onTaskCancel(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("开始");
@ -216,7 +209,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Override public void onTaskFail(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);
} else { } 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)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true); setBtState(true);
mStart.setText("重新开始"); mStart.setText("重新开始");
@ -234,12 +227,11 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Override public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
mPb.setProgress(task.getPercent()); mPb.setProgress(task.getPercent());
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());
} }
mAdapter.setProgress(task.getDownloadEntity()); mAdapter.setProgress(task.getDownloadEntity());
} }
}
} }

@ -34,8 +34,8 @@ import com.arialyy.simple.databinding.ActivityFtpUploadBinding;
* Ftp 文件上传demo * Ftp 文件上传demo
*/ */
public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> { public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
private final String FILE_PATH = "/mnt/sdcard/gggg.apk"; private final String FILE_PATH = "/mnt/sdcard/Download/group_test_3/战斗吧剑灵.apk";
private final String URL = "ftp://172.18.104.79:21/upload/"; private final String URL = "ftp://172.18.104.66:21/upload/";
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
setTile("FTP 文件上传"); setTile("FTP 文件上传");
@ -99,6 +99,6 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
@Upload.onTaskComplete public void taskComplete(UploadTask task) { @Upload.onTaskComplete public void taskComplete(UploadTask task) {
getBinding().setProgress(100); getBinding().setProgress(100);
getBinding().setSpeed(""); getBinding().setSpeed("");
T.showShort(this, "上传完成"); T.showShort(this, "文件:" + task.getEntity().getFileName() + ",上传完成");
} }
} }

Loading…
Cancel
Save