pull/330/head
AriaLyy 8 years ago
parent 1c8f808c1c
commit 577b3d2546
  1. 2
      .idea/misc.xml
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/Aria.java
  3. 5
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  4. 37
      Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java
  5. 46
      Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java
  6. 73
      Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java
  7. 23
      Aria/src/main/java/com/arialyy/aria/core/command/IDownloadCmd.java
  8. 41
      Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java
  9. 64
      Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java
  10. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  11. 22
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  12. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  13. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java
  14. 48
      Aria/src/main/java/com/arialyy/aria/core/download/command/SingleCmd.java
  15. 55
      Aria/src/main/java/com/arialyy/aria/core/download/command/StopCmd.java
  16. 8
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  17. 8
      Aria/src/main/java/com/arialyy/aria/core/inf/ItaskEntity.java
  18. 12
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  19. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/IDownloader.java
  20. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/IPool.java
  21. 9
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  22. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java
  23. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java
  24. 6
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  25. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/IDownloadSchedulers.java
  26. 4
      Aria/src/main/java/com/arialyy/aria/core/scheduler/OnSchedulerListener.java
  27. 2
      Aria/src/main/java/com/arialyy/aria/core/task/ConnectionHelp.java
  28. 2
      Aria/src/main/java/com/arialyy/aria/core/task/DownloadListener.java
  29. 2
      Aria/src/main/java/com/arialyy/aria/core/task/DownloadStateConstance.java
  30. 6
      Aria/src/main/java/com/arialyy/aria/core/task/DownloadTask.java
  31. 4
      Aria/src/main/java/com/arialyy/aria/core/task/DownloadTaskFactory.java
  32. 2
      Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java
  33. 2
      Aria/src/main/java/com/arialyy/aria/core/task/IDownloadListener.java
  34. 2
      Aria/src/main/java/com/arialyy/aria/core/task/IDownloadUtil.java
  35. 2
      Aria/src/main/java/com/arialyy/aria/core/task/SingleThreadTask.java
  36. 3
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java
  37. 3
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadUtil.java
  38. 14
      Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
  39. 11
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  40. 2
      app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java
  41. 2
      app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java
  42. 2
      app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java
  43. 2
      app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java
  44. 2
      app/src/main/java/com/arialyy/simple/notification/SimpleNotification.java
  45. 2
      app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java
  46. 2
      app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

@ -27,8 +27,8 @@ import android.content.Context;
import android.os.Build;
import android.widget.PopupWindow;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.download.scheduler.OnSchedulerListener;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.scheduler.OnSchedulerListener;
import com.arialyy.aria.core.task.DownloadTask;
/**
* Created by lyy on 2016/12/1.

@ -27,13 +27,12 @@ import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.widget.PopupWindow;
import com.arialyy.aria.core.download.command.IDownloadCmd;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.inf.ICmd;
import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.download.queue.DownloadTaskQueue;
import com.arialyy.aria.core.download.queue.ITaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.core.upload.UploadReceiver;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.DbUtil;

@ -14,32 +14,41 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.command;
package com.arialyy.aria.core.command;
import android.util.Log;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.inf.ITaskEntity;
import com.arialyy.aria.core.task.DownloadTask;
/**
* Created by lyy on 2016/8/22.
* 添加任务的命令
*/
class AddCmd extends IDownloadCmd {
class AddCmd<T extends ITaskEntity> extends IDownloadCmd<T> {
AddCmd(DownloadTaskEntity entity) {
super(entity);
}
AddCmd(String targetName, DownloadTaskEntity entity) {
AddCmd(String targetName, T entity) {
super(targetName, entity);
}
@Override public void executeCmd() {
DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) {
mQueue.createTask(mTargetName, mEntity);
} else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
}
}
//AddCmd(DownloadTaskEntity entity) {
// super(entity);
//}
//
//AddCmd(String targetName, DownloadTaskEntity entity) {
// super(targetName, entity);
//}
//
//@Override public void executeCmd() {
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
// if (task == null) {
// mQueue.createTask(mTargetName, mEntity);
// } else {
// Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
// }
//}
}

@ -14,35 +14,43 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.command;
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.inf.ITaskEntity;
import com.arialyy.aria.core.task.DownloadTask;
/**
* Created by lyy on 2016/9/20.
* 取消命令
*/
class CancelCmd extends IDownloadCmd {
CancelCmd(DownloadTaskEntity entity) {
super(entity);
}
CancelCmd(String targetName, DownloadTaskEntity entity) {
class CancelCmd<T extends ITaskEntity> extends IDownloadCmd<T> {
CancelCmd(String targetName, T entity) {
super(targetName, entity);
}
@Override public void executeCmd() {
DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) {
task = mQueue.createTask(mTargetName, mEntity);
}
if (task != null) {
if (mTargetName != null) {
task.setTargetName(mTargetName);
}
mQueue.cancelTask(task);
}
}
//CancelCmd(DownloadTaskEntity entity) {
// super(entity);
//}
//
//CancelCmd(String targetName, DownloadTaskEntity entity) {
// super(targetName, entity);
//}
//
//@Override public void executeCmd() {
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
// if (task == null) {
// task = mQueue.createTask(mTargetName, mEntity);
// }
// if (task != null) {
// if (mTargetName != null) {
// task.setTargetName(mTargetName);
// }
// mQueue.cancelTask(task);
// }
//}
}

@ -14,9 +14,9 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.command;
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.ITaskEntity;
/**
* Created by Lyy on 2016/9/23.
@ -61,36 +61,13 @@ public class CmdFactory {
return INSTANCE;
}
/**
* @param entity 下载实体
* @param type 命令类型{@link #TASK_CREATE}{@link #TASK_START}{@link #TASK_CANCEL}{@link
* #TASK_STOP}
*/
public IDownloadCmd createCmd(DownloadTaskEntity entity, int type) {
switch (type) {
case TASK_CREATE:
return createAddCmd(entity);
case TASK_RESUME:
case TASK_START:
return createStartCmd(entity);
case TASK_CANCEL:
return createCancelCmd(entity);
case TASK_STOP:
return createStopCmd(entity);
case TASK_SINGLE:
//return new SingleCmd(entity);
default:
return null;
}
}
/**
* @param target 创建任务的对象
* @param entity 下载实体
* @param type 命令类型{@link #TASK_CREATE}{@link #TASK_START}{@link #TASK_CANCEL}{@link
* #TASK_STOP}
*/
public IDownloadCmd createCmd(String target, DownloadTaskEntity entity, int type) {
public <T extends ITaskEntity> IDownloadCmd createCmd(String target, T entity, int type) {
switch (type) {
case TASK_CREATE:
return createAddCmd(target, entity);
@ -113,43 +90,25 @@ public class CmdFactory {
*
* @return {@link StopCmd}
*/
private StopCmd createStopCmd(String target, DownloadTaskEntity entity) {
private <T extends ITaskEntity> StopCmd createStopCmd(String target, T entity) {
return new StopCmd(target, entity);
}
/**
* 创建停止命令
*
* @return {@link StopCmd}
*/
private StopCmd createStopCmd(DownloadTaskEntity entity) {
return new StopCmd(entity);
}
/**
* 创建下载任务命令
*
* @return {@link AddCmd}
*/
private AddCmd createAddCmd(String target, DownloadTaskEntity entity) {
private <T extends ITaskEntity> AddCmd createAddCmd(String target, T entity) {
return new AddCmd(target, entity);
}
/**
* 创建下载任务命令
*
* @return {@link AddCmd}
*/
private AddCmd createAddCmd(DownloadTaskEntity entity) {
return new AddCmd(entity);
}
/**
* 创建启动下载命令
*
* @return {@link StartCmd}
*/
private StartCmd createStartCmd(String target, DownloadTaskEntity entity) {
private <T extends ITaskEntity> StartCmd createStartCmd(String target, T entity) {
return new StartCmd(target, entity);
}
@ -158,25 +117,7 @@ public class CmdFactory {
*
* @return {@link StartCmd}
*/
private StartCmd createStartCmd(DownloadTaskEntity entity) {
return new StartCmd(entity);
}
/**
* 创建 取消下载的命令
*
* @return {@link CancelCmd}
*/
private CancelCmd createCancelCmd(String target, DownloadTaskEntity entity) {
private <T extends ITaskEntity> CancelCmd createCancelCmd(String target, T entity) {
return new CancelCmd(target, entity);
}
/**
* 创建 取消下载的命令
*
* @return {@link CancelCmd}
*/
private CancelCmd createCancelCmd(DownloadTaskEntity entity) {
return new CancelCmd(entity);
}
}

@ -14,12 +14,15 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.command;
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.queue.ITaskQueue;
import com.arialyy.aria.core.inf.ITaskEntity;
import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.core.inf.ICmd;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
@ -27,28 +30,20 @@ import com.arialyy.aria.util.CommonUtil;
* Created by lyy on 2016/8/22.
* 下载命令
*/
public abstract class IDownloadCmd implements ICmd{
public abstract class IDownloadCmd<T extends ITaskEntity> implements ICmd {
ITaskQueue mQueue;
DownloadTaskEntity mEntity;
T mEntity;
String TAG;
String mTargetName;
/**
* @param entity 下载实体
*/
IDownloadCmd(DownloadTaskEntity entity) {
this(null, entity);
}
/**
* @param targetName 产生任务的对象名
*/
IDownloadCmd(String targetName, DownloadTaskEntity entity) {
CheckUtil.checkDownloadEntity(entity.downloadEntity);
IDownloadCmd(String targetName, T entity) {
CheckUtil.checkTaskEntity(entity);
mTargetName = targetName;
mEntity = entity;
TAG = CommonUtil.getClassName(this);
mQueue = AriaManager.getInstance(AriaManager.APP).getTaskQueue();
}
}

@ -14,33 +14,42 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.command;
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.inf.ITaskEntity;
import com.arialyy.aria.core.task.DownloadTask;
/**
* Created by lyy on 2016/8/22.
* 开始命令
*/
class StartCmd extends IDownloadCmd {
class StartCmd<T extends ITaskEntity> extends IDownloadCmd<T> {
StartCmd(DownloadTaskEntity entity) {
super(entity);
}
StartCmd(String targetName, DownloadTaskEntity entity) {
StartCmd(String targetName, T entity) {
super(targetName, entity);
}
@Override public void executeCmd() {
DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) {
task = mQueue.createTask(mTargetName, mEntity);
}
if (task != null) {
task.setTargetName(mTargetName);
mQueue.startTask(task);
}
}
//StartCmd(DownloadTaskEntity entity) {
// super(entity);
//}
//
//StartCmd(String targetName, DownloadTaskEntity entity) {
// super(targetName, entity);
//}
//
//@Override public void executeCmd() {
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
// if (task == null) {
// task = mQueue.createTask(mTargetName, mEntity);
// }
// if (task != null) {
// task.setTargetName(mTargetName);
// mQueue.startTask(task);
// }
//}
}

@ -0,0 +1,64 @@
/*
* 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.command;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.ITaskEntity;
import com.arialyy.aria.core.task.DownloadTask;
/**
* Created by lyy on 2016/9/20.
* 停止命令
*/
class StopCmd<T extends ITaskEntity> extends IDownloadCmd<T> {
StopCmd(String targetName, T entity) {
super(targetName, entity);
}
@Override public void executeCmd() {
}
//StopCmd(DownloadTaskEntity entity) {
// super(entity);
//}
//
//StopCmd(String targetName, DownloadTaskEntity entity) {
// super(targetName, entity);
//}
//
//@Override public void executeCmd() {
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
// if (task == null) {
// if (mEntity.downloadEntity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
// task = mQueue.createTask(mTargetName, mEntity);
// mQueue.stopTask(task);
// } else {
// Log.w(TAG, "停止命令执行失败,【调度器中没有该任务】");
// }
// } else {
// if (!TextUtils.isEmpty(mTargetName)) {
// task.setTargetName(mTargetName);
// }
// mQueue.stopTask(task);
// }
//}
}

@ -19,6 +19,7 @@ package com.arialyy.aria.core.download;
import android.os.Parcel;
import android.os.Parcelable;
import com.arialyy.aria.core.inf.ITaskEntity;
import com.arialyy.aria.orm.Ignore;
import com.arialyy.aria.orm.DbEntity;
@ -28,7 +29,7 @@ import com.arialyy.aria.orm.DbEntity;
* 注意CREATOR要进行@Ignore注解
* 并且需要Parcelable时需要手动填写rowID;
*/
public class DownloadEntity extends DbEntity implements Parcelable {
public class DownloadEntity extends DbEntity implements Parcelable{
/**
* 其它状态
*/

@ -18,10 +18,10 @@ package com.arialyy.aria.core.download;
import android.support.annotation.NonNull;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.download.command.CmdFactory;
import com.arialyy.aria.core.download.command.IDownloadCmd;
import com.arialyy.aria.core.download.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.download.scheduler.OnSchedulerListener;
import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.command.IDownloadCmd;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.OnSchedulerListener;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
@ -70,15 +70,13 @@ public class DownloadReceiver implements IReceiver {
/**
* 移除回调
*/
@Override
public void removeSchedulerListener() {
@Override public void removeSchedulerListener() {
if (listener != null) {
DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener);
}
}
@Override
public void destroy() {
@Override public void destroy() {
targetName = null;
listener = null;
}
@ -114,8 +112,8 @@ public class DownloadReceiver implements IReceiver {
List<IDownloadCmd> stopCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) {
if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
stopCmds.add(
CommonUtil.createDownloadCmd(new DownloadTaskEntity(entity), CmdFactory.TASK_STOP));
stopCmds.add(CommonUtil.createDownloadCmd(targetName, new DownloadTaskEntity(entity),
CmdFactory.TASK_STOP));
}
}
ariaManager.setCmds(stopCmds).exe();
@ -129,8 +127,8 @@ public class DownloadReceiver implements IReceiver {
List<DownloadEntity> allEntity = ariaManager.getAllDownloadEntity();
List<IDownloadCmd> cancelCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) {
cancelCmds.add(
CommonUtil.createDownloadCmd(new DownloadTaskEntity(entity), CmdFactory.TASK_CANCEL));
cancelCmds.add(CommonUtil.createDownloadCmd(targetName, new DownloadTaskEntity(entity),
CmdFactory.TASK_CANCEL));
}
ariaManager.setCmds(cancelCmds).exe();
Set<String> keys = ariaManager.getReceiver().keySet();

@ -19,8 +19,8 @@ import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.core.download.command.CmdFactory;
import com.arialyy.aria.core.download.command.IDownloadCmd;
import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.command.IDownloadCmd;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;

@ -16,6 +16,7 @@
package com.arialyy.aria.core.download;
import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.core.inf.ITaskEntity;
import java.util.HashMap;
import java.util.Map;
@ -23,7 +24,7 @@ import java.util.Map;
* Created by Aria.Lao on 2017/1/23.
* 下载任务实体
*/
public class DownloadTaskEntity {
public class DownloadTaskEntity implements ITaskEntity {
public DownloadEntity downloadEntity;
public RequestEnum requestEnum = RequestEnum.GET;

@ -1,48 +0,0 @@
///*
// * 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.command.download;
//
//import android.util.Log;
//import com.arialyy.aria.core.download.DownloadEntity;
//import com.arialyy.aria.core.task.DownloadTask;
//
///**
// * Created by lyy on 2016/11/30.
// * 获取任务状态命令
// */
//class SingleCmd extends IDownloadCmd {
// /**
// * @param entity 下载实体
// */
// SingleCmd(String target, DownloadEntity entity) {
// super(target, entity);
// }
//
// SingleCmd(DownloadEntity entity) {
// super(entity);
// }
//
// @Override public void executeCmd() {
// DownloadTask task = mQueue.getTask(mEntity);
// if (task == null) {
// task = mQueue.createTask(mTargetName, mEntity);
// } else {
// Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
// }
// task.setTargetName(mTargetName);
// mQueue.startTask(task);
// }
//}

@ -1,55 +0,0 @@
/*
* 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.download.command;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
/**
* Created by lyy on 2016/9/20.
* 停止命令
*/
class StopCmd extends IDownloadCmd {
StopCmd(DownloadTaskEntity entity) {
super(entity);
}
StopCmd(String targetName, DownloadTaskEntity entity) {
super(targetName, entity);
}
@Override public void executeCmd() {
DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) {
if (mEntity.downloadEntity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
task = mQueue.createTask(mTargetName, mEntity);
mQueue.stopTask(task);
} else {
Log.w(TAG, "停止命令执行失败,【调度器中没有该任务】");
}
} else {
if (!TextUtils.isEmpty(mTargetName)) {
task.setTargetName(mTargetName);
}
mQueue.stopTask(task);
}
}
}

@ -0,0 +1,8 @@
package com.arialyy.aria.core.inf;
/**
* Created by Aria.Lao on 2017/2/13.
*/
public interface ITask {
}

@ -0,0 +1,8 @@
package com.arialyy.aria.core.inf;
/**
* Created by Aria.Lao on 2017/2/13.
*/
public interface ITaskEntity {
}

@ -14,18 +14,18 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.queue;
package com.arialyy.aria.core.queue;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.queue.pool.CachePool;
import com.arialyy.aria.core.download.queue.pool.ExecutePool;
import com.arialyy.aria.core.download.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.download.task.DownloadTaskFactory;
import com.arialyy.aria.core.queue.pool.CachePool;
import com.arialyy.aria.core.queue.pool.ExecutePool;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTaskFactory;
import com.arialyy.aria.util.Configuration;
/**

@ -15,9 +15,9 @@
*/
package com.arialyy.aria.core.download.queue;
package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
/**
* Created by lyy on 2016/8/16.

@ -15,9 +15,9 @@
*/
package com.arialyy.aria.core.download.queue;
package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
/**
* Created by lyy on 2016/8/14.

@ -14,11 +14,11 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.queue;
package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
/**
* Created by lyy on 2016/8/16.
@ -26,11 +26,6 @@ import com.arialyy.aria.core.download.task.DownloadTask;
*/
public interface ITaskQueue extends IDownloader {
///**
// * 获取调度器
// */
//public IDownloadSchedulers getDownloadSchedulers();
/**
* 任务池队列大小
*/

@ -14,12 +14,12 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.queue.pool;
package com.arialyy.aria.core.queue.pool;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.download.queue.IPool;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.queue.IPool;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import java.util.HashMap;
import java.util.Map;

@ -14,13 +14,13 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.queue.pool;
package com.arialyy.aria.core.queue.pool;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.core.download.queue.IPool;
import com.arialyy.aria.core.queue.IPool;
import com.arialyy.aria.util.Configuration;
import java.util.HashMap;
import java.util.Map;

@ -14,15 +14,15 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.scheduler;
package com.arialyy.aria.core.scheduler;
import android.os.CountDownTimer;
import android.os.Message;
import android.util.Log;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.queue.ITaskQueue;
import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.Configuration;
import java.util.Iterator;
import java.util.Map;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.scheduler;
package com.arialyy.aria.core.scheduler;
import android.os.Handler;
import com.arialyy.aria.core.download.DownloadEntity;

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.scheduler;
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
/**
* Target处理任务监听

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.task;
package com.arialyy.aria.core.task;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.util.CAConfiguration;

@ -15,7 +15,7 @@
*/
package com.arialyy.aria.core.download.task;
package com.arialyy.aria.core.task;
class DownloadListener implements IDownloadListener {

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.task;
package com.arialyy.aria.core.task;
/**
* Created by lyy on 2017/1/18.

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.task;
package com.arialyy.aria.core.task;
import android.content.Context;
import android.content.Intent;
@ -22,8 +22,8 @@ import android.os.Handler;
import android.util.Log;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.download.scheduler.IDownloadSchedulers;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;

@ -14,11 +14,11 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.task;
package com.arialyy.aria.core.task;
import android.content.Context;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.scheduler.IDownloadSchedulers;
import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
/**
* Created by lyy on 2016/8/18.

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.task;
package com.arialyy.aria.core.task;
import android.content.Context;
import android.util.Log;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.aria.core.download.task;
package com.arialyy.aria.core.task;
/**
* 下载监听

@ -15,7 +15,7 @@
*/
package com.arialyy.aria.core.download.task;
package com.arialyy.aria.core.task;
/**
* Created by AriaLyy@outlook.com on 2016/10/31.

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.task;
package com.arialyy.aria.core.task;
import android.util.Log;
import com.arialyy.aria.util.CommonUtil;

@ -1,6 +1,7 @@
package com.arialyy.aria.core.upload;
import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.core.inf.ITaskEntity;
import java.util.HashMap;
import java.util.Map;
@ -8,7 +9,7 @@ import java.util.Map;
* Created by Aria.Lao on 2017/2/9.
*/
public class UploadTaskEntity {
public class UploadTaskEntity implements ITaskEntity {
public UploadEntity uploadEntity;
public RequestEnum requestEnum = RequestEnum.GET;
public String uploadUrl; //上传路径

@ -3,7 +3,6 @@ package com.arialyy.aria.core.upload;
import android.util.Log;
import com.arialyy.aria.util.CheckUtil;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -67,8 +66,8 @@ public class UploadUtil implements Runnable {
mHttpConn.setDoInput(true);
mHttpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
mHttpConn.setRequestProperty("User-Agent", "CodeJava Agent");
mHttpConn.setRequestProperty("Range", "bytes=" + 0 + "-" + "100");
//内部缓冲区---分段上传防止oom
//System.setProperty("http.keepAlive", "false");
mHttpConn.setChunkedStreamingMode(1024);
//添加Http请求头部

@ -19,7 +19,10 @@ package com.arialyy.aria.util;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.ITaskEntity;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.exception.FileException;
import java.io.File;
import java.util.regex.Matcher;
@ -74,6 +77,17 @@ public class CheckUtil {
if (TextUtils.isEmpty(downloadUrl)) throw new IllegalArgumentException("下载链接不能为null");
}
/**
* 检查任务实体
*/
public static void checkTaskEntity(ITaskEntity entity) {
if (entity instanceof DownloadTaskEntity) {
checkDownloadEntity(((DownloadTaskEntity) entity).downloadEntity);
} else if (entity instanceof UploadTaskEntity) {
checkUploadEntity(((UploadTaskEntity) entity).uploadEntity);
}
}
/**
* 检查上传实体是否合法
*/

@ -22,8 +22,9 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Log;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.command.CmdFactory;
import com.arialyy.aria.core.download.command.IDownloadCmd;
import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.command.IDownloadCmd;
import com.arialyy.aria.core.inf.ITaskEntity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -40,14 +41,10 @@ import java.util.Properties;
public class CommonUtil {
private static final String TAG = "util";
public static IDownloadCmd createDownloadCmd(String target, DownloadTaskEntity entity, int cmd) {
public static <T extends ITaskEntity> IDownloadCmd createDownloadCmd(String target, T entity, int cmd) {
return CmdFactory.getInstance().createCmd(target, entity, cmd);
}
public static IDownloadCmd createDownloadCmd(DownloadTaskEntity entity, int cmd) {
return CmdFactory.getInstance().createCmd(entity, cmd);
}
/**
* 创建隐性的Intent
*/

@ -10,7 +10,7 @@ import butterknife.OnClick;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsDialog;
import com.arialyy.simple.R;

@ -10,7 +10,7 @@ import butterknife.OnClick;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsFragment;
import com.arialyy.simple.R;

@ -5,7 +5,7 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import butterknife.Bind;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;

@ -24,7 +24,7 @@ import android.support.v7.widget.Toolbar;
import android.view.View;
import butterknife.Bind;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiBinding;

@ -5,7 +5,7 @@ import android.content.Context;
import android.os.Environment;
import android.support.v4.app.NotificationCompat;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.simple.R;
/**

@ -12,7 +12,7 @@ import butterknife.OnClick;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsPopupWindow;
import com.arialyy.simple.R;

@ -33,7 +33,7 @@ import butterknife.Bind;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.task.DownloadTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;

Loading…
Cancel
Save