3.0 版本编写、添加header支持、代码逻辑修改

pull/330/head
AriaLyy 8 years ago
parent 41154d47fb
commit 62d6434914
  1. 51
      Aria/src/main/java/com/arialyy/aria/core/AMTarget.java
  2. 8
      Aria/src/main/java/com/arialyy/aria/core/AMUplodReceiver.java
  3. 129
      Aria/src/main/java/com/arialyy/aria/core/Aria.java
  4. 56
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  5. 2
      Aria/src/main/java/com/arialyy/aria/core/DownloadManager.java
  6. 19
      Aria/src/main/java/com/arialyy/aria/core/DownloadTaskEntity.java
  7. 2
      Aria/src/main/java/com/arialyy/aria/core/RequestEnum.java
  8. 10
      Aria/src/main/java/com/arialyy/aria/core/TaskEntity.java
  9. 48
      Aria/src/main/java/com/arialyy/aria/core/command/SingleCmd.java
  10. 11
      Aria/src/main/java/com/arialyy/aria/core/command/download/AddCmd.java
  11. 13
      Aria/src/main/java/com/arialyy/aria/core/command/download/CancelCmd.java
  12. 27
      Aria/src/main/java/com/arialyy/aria/core/command/download/CmdFactory.java
  13. 11
      Aria/src/main/java/com/arialyy/aria/core/command/download/IDownloadCmd.java
  14. 48
      Aria/src/main/java/com/arialyy/aria/core/command/download/SingleCmd.java
  15. 13
      Aria/src/main/java/com/arialyy/aria/core/command/download/StartCmd.java
  16. 18
      Aria/src/main/java/com/arialyy/aria/core/command/download/StopCmd.java
  17. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  18. 5
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  19. 17
      Aria/src/main/java/com/arialyy/aria/core/receiver/DownloadReceiver.java
  20. 24
      Aria/src/main/java/com/arialyy/aria/core/receiver/IReceiver.java
  21. 24
      Aria/src/main/java/com/arialyy/aria/core/receiver/UploadReceiver.java
  22. 13
      Aria/src/main/java/com/arialyy/aria/core/task/ConnectionHelp.java
  23. 18
      Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java
  24. 3
      Aria/src/main/java/com/arialyy/aria/core/task/SingleThreadTask.java
  25. 26
      Aria/src/main/java/com/arialyy/aria/core/task/Task.java
  26. 13
      Aria/src/main/java/com/arialyy/aria/core/task/TaskFactory.java
  27. 7
      Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
  28. 9
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  29. 10
      app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java
  30. 10
      app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java
  31. 2
      app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java
  32. 6
      app/src/main/java/com/arialyy/simple/multi_task/DownloadAdapter.java
  33. 3
      app/src/main/java/com/arialyy/simple/multi_task/FileListAdapter.java
  34. 4
      app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java
  35. 8
      app/src/main/java/com/arialyy/simple/notification/SimpleNotification.java
  36. 10
      app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java
  37. 12
      app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java

@ -17,25 +17,56 @@ package com.arialyy.aria.core;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.download.CmdFactory;
import com.arialyy.aria.core.command.IDownloadCmd; import com.arialyy.aria.core.command.download.IDownloadCmd;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
/** /**
* Created by lyy on 2016/12/5. * Created by lyy on 2016/12/5.
* https://github.com/AriaLyy/Aria * https://github.com/AriaLyy/Aria
*/ */
public class AMTarget { public class AMTarget {
//private AMReceiver mReceiver;
DownloadEntity entity; DownloadEntity entity;
String targetName; String targetName;
DownloadTaskEntity taskEntity;
AMTarget(DownloadEntity entity, String targetName) { public AMTarget(DownloadEntity entity, String targetName) {
this.entity = entity; this.entity = entity;
this.targetName = targetName; this.targetName = targetName;
taskEntity = new DownloadTaskEntity(entity);
}
/**
* 给url请求添加头部
*
* @param key 头部key
* @param header 头部value
*/
public AMTarget addHeader(@NonNull String key, @NonNull String header) {
taskEntity.headers.put(key, header);
return this;
}
/**
* 给url请求添加头部
*
* @param headers Map<Key, Value>
*/
public AMTarget addHeaders(Map<String, String> headers) {
if (headers != null && headers.size() > 0) {
Set<String> keys = headers.keySet();
for (String key : keys) {
taskEntity.headers.put(key, headers.get(key));
}
}
return this;
} }
/** /**
@ -92,7 +123,7 @@ public class AMTarget {
*/ */
public void add() { public void add() {
DownloadManager.getInstance() DownloadManager.getInstance()
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_CREATE)) .setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_CREATE))
.exe(); .exe();
} }
@ -101,8 +132,8 @@ public class AMTarget {
*/ */
public void start() { public void start() {
List<IDownloadCmd> cmds = new ArrayList<>(); List<IDownloadCmd> cmds = new ArrayList<>();
cmds.add(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_CREATE)); cmds.add(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_CREATE));
cmds.add(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_START)); cmds.add(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_START));
DownloadManager.getInstance().setCmds(cmds).exe(); DownloadManager.getInstance().setCmds(cmds).exe();
cmds.clear(); cmds.clear();
} }
@ -112,7 +143,7 @@ public class AMTarget {
*/ */
public void stop() { public void stop() {
DownloadManager.getInstance() DownloadManager.getInstance()
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_STOP)) .setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_STOP))
.exe(); .exe();
} }
@ -121,7 +152,7 @@ public class AMTarget {
*/ */
public void resume() { public void resume() {
DownloadManager.getInstance() DownloadManager.getInstance()
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_START)) .setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_START))
.exe(); .exe();
} }
@ -130,7 +161,7 @@ public class AMTarget {
*/ */
public void cancel() { public void cancel() {
DownloadManager.getInstance() DownloadManager.getInstance()
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_CANCEL)) .setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_CANCEL))
.exe(); .exe();
} }

@ -1,8 +0,0 @@
package com.arialyy.aria.core;
/**
* Created by Aria.Lao on 2017/1/18.
* AM 上传文件接收器
*/
public class AMUplodReceiver {
}

@ -26,6 +26,7 @@ import android.app.Service;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import com.arialyy.aria.core.receiver.DownloadReceiver;
import com.arialyy.aria.core.scheduler.OnSchedulerListener; import com.arialyy.aria.core.scheduler.OnSchedulerListener;
import com.arialyy.aria.core.task.Task; import com.arialyy.aria.core.task.Task;
@ -36,7 +37,7 @@ import com.arialyy.aria.core.task.Task;
* <pre> * <pre>
* <code> * <code>
* //启动下载 * //启动下载
* Aria.whit(this) * Aria.download(this)
* .load(DOWNLOAD_URL) //下载地址,必填 * .load(DOWNLOAD_URL) //下载地址,必填
* //文件保存路径,必填 * //文件保存路径,必填
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") * .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
@ -99,118 +100,46 @@ import com.arialyy.aria.core.task.Task;
} }
/** /**
* 接受ActivityServiceApplication * 初始化下载
*/ *
public static AMReceiver whit(Context context) { * @param obj 支持类型有ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog
//if (context == null) throw new IllegalArgumentException("context 不能为 null");
checkNull(context);
if (context instanceof Activity
|| context instanceof Service
|| context instanceof Application) {
return AriaManager.getInstance(context).get(context);
} else {
throw new IllegalArgumentException("这是不支持的context");
}
}
/**
* 处理Fragment
*/
public static AMReceiver whit(Fragment fragment) {
checkNull(fragment);
return AriaManager.getInstance(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
: fragment.getActivity()).get(fragment);
}
/**
* 处理Fragment
*/
public static AMReceiver whit(android.support.v4.app.Fragment fragment) {
checkNull(fragment);
return AriaManager.getInstance(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
: fragment.getActivity()).get(fragment);
}
/**
* 处理Fragment或者DialogFragment
*/
public static AMReceiver whit(DialogFragment dialog) {
checkNull(dialog);
return AriaManager.getInstance(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? dialog.getContext() : dialog.getActivity())
.get(dialog);
}
/**
* 处理popupwindow
*/
public static AMReceiver whit(PopupWindow popupWindow) {
checkNull(popupWindow);
return AriaManager.getInstance(popupWindow.getContentView().getContext()).get(popupWindow);
}
/**
* 处理Dialog
*/ */
public static AMReceiver whit(Dialog dialog) { public static DownloadReceiver download(Object obj) {
checkNull(dialog); return get(obj).download(obj);
return AriaManager.getInstance(dialog.getContext()).get(dialog);
} }
/** /**
* 处理通用事件 * 处理通用事件
*
* @param obj 支持类型有ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog
*/ */
public static AriaManager get(Context context) { public static AriaManager get(Object obj) {
if (context == null) throw new IllegalArgumentException("context 不能为 null"); if (obj instanceof Activity || obj instanceof Service || obj instanceof Application) {
if (context instanceof Activity return AriaManager.getInstance((Context) obj);
|| context instanceof Service } else if (obj instanceof DialogFragment) {
|| context instanceof Application) { DialogFragment dialog = (DialogFragment) obj;
return AriaManager.getInstance(context); return AriaManager.getInstance(
} else { Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? dialog.getContext()
throw new IllegalArgumentException("这是不支持的context"); : dialog.getActivity());
} } else if (obj instanceof android.support.v4.app.Fragment) {
} android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj;
/**
* 处理Dialog的通用任务
*/
public static AriaManager get(Dialog dialog) {
checkNull(dialog);
return AriaManager.getInstance(dialog.getContext());
}
/**
* 处理Dialog的通用任务
*/
public static AriaManager get(PopupWindow popupWindow) {
checkNull(popupWindow);
return AriaManager.getInstance(popupWindow.getContentView().getContext());
}
/**
* 处理Fragment的通用任务
*/
public static AriaManager get(Fragment fragment) {
checkNull(fragment);
return AriaManager.getInstance( return AriaManager.getInstance(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext() Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
: fragment.getActivity()); : fragment.getActivity());
} } else if (obj instanceof Fragment) {
Fragment fragment = (Fragment) obj;
/**
* 处理Fragment的通用任务
*/
public static AriaManager get(android.support.v4.app.Fragment fragment) {
checkNull(fragment);
return AriaManager.getInstance( return AriaManager.getInstance(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext() Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
: fragment.getActivity()); : fragment.getActivity());
} else if (obj instanceof PopupWindow) {
PopupWindow popupWindow = (PopupWindow) obj;
return AriaManager.getInstance(popupWindow.getContentView().getContext());
} else if (obj instanceof Dialog) {
Dialog dialog = (Dialog) obj;
return AriaManager.getInstance(dialog.getContext());
} else {
throw new IllegalArgumentException("不支持的类型");
} }
private static void checkNull(Object obj) {
if (obj == null) throw new IllegalArgumentException("不能传入空对象");
} }
public static class SimpleSchedulerListener implements OnSchedulerListener { public static class SimpleSchedulerListener implements OnSchedulerListener {

@ -19,7 +19,6 @@ import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.app.Dialog; import android.app.Dialog;
import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Build; import android.os.Build;
@ -29,11 +28,12 @@ import android.support.v4.app.Fragment;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.download.CmdFactory;
import com.arialyy.aria.core.receiver.DownloadReceiver;
import com.arialyy.aria.util.CAConfiguration; import com.arialyy.aria.util.CAConfiguration;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.core.command.IDownloadCmd; import com.arialyy.aria.core.command.download.IDownloadCmd;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
@ -52,7 +52,7 @@ import java.util.Set;
private static final String TAG = "AriaManager"; private static final String TAG = "AriaManager";
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private static volatile AriaManager INSTANCE = null; private static volatile AriaManager INSTANCE = null;
private Map<String, AMReceiver> mTargets = new HashMap<>(); private Map<String, DownloadReceiver> mDownloadTargets = new HashMap<>();
private DownloadManager mManager; private DownloadManager mManager;
private LifeCallback mLifeCallback; private LifeCallback mLifeCallback;
@ -70,8 +70,8 @@ import java.util.Set;
return INSTANCE; return INSTANCE;
} }
AMReceiver get(Object obj) { DownloadReceiver download(Object obj) {
return getTarget(obj); return getDownloadTarget(obj);
} }
/** /**
@ -115,14 +115,15 @@ import java.util.Set;
} }
/** /**
* 停止所有正在执行的任务 * 停止所有正在下载的任务
*/ */
public void stopAllTask() { public void stopAllTask() {
List<DownloadEntity> allEntity = mManager.getAllDownloadEntity(); List<DownloadEntity> allEntity = mManager.getAllDownloadEntity();
List<IDownloadCmd> stopCmds = new ArrayList<>(); List<IDownloadCmd> stopCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) { for (DownloadEntity entity : allEntity) {
if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) { if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
stopCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_STOP)); stopCmds.add(
CommonUtil.createDownloadCmd(new DownloadTaskEntity(entity), CmdFactory.TASK_STOP));
} }
} }
mManager.setCmds(stopCmds).exe(); mManager.setCmds(stopCmds).exe();
@ -181,20 +182,21 @@ import java.util.Set;
List<DownloadEntity> allEntity = mManager.getAllDownloadEntity(); List<DownloadEntity> allEntity = mManager.getAllDownloadEntity();
List<IDownloadCmd> cancelCmds = new ArrayList<>(); List<IDownloadCmd> cancelCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) { for (DownloadEntity entity : allEntity) {
cancelCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_CANCEL)); cancelCmds.add(
CommonUtil.createDownloadCmd(new DownloadTaskEntity(entity), CmdFactory.TASK_CANCEL));
} }
mManager.setCmds(cancelCmds).exe(); mManager.setCmds(cancelCmds).exe();
Set<String> keys = mTargets.keySet(); Set<String> keys = mDownloadTargets.keySet();
for (String key : keys) { for (String key : keys) {
AMReceiver target = mTargets.get(key); DownloadReceiver target = mDownloadTargets.get(key);
target.removeSchedulerListener(); target.removeSchedulerListener();
mTargets.remove(key); mDownloadTargets.remove(key);
} }
} }
private AMReceiver putTarget(Object obj) { private DownloadReceiver putTarget(Object obj) {
String clsName = obj.getClass().getName(); String clsName = obj.getClass().getName();
AMReceiver target = null; DownloadReceiver target = null;
String key = ""; String key = "";
if (!(obj instanceof Activity)) { if (!(obj instanceof Activity)) {
if (obj instanceof android.support.v4.app.Fragment) { if (obj instanceof android.support.v4.app.Fragment) {
@ -224,11 +226,11 @@ import java.util.Set;
if (TextUtils.isEmpty(key)) { if (TextUtils.isEmpty(key)) {
throw new IllegalArgumentException("未知类型"); throw new IllegalArgumentException("未知类型");
} }
target = mTargets.get(key); target = mDownloadTargets.get(key);
if (target == null) { if (target == null) {
target = new AMReceiver(); target = new DownloadReceiver();
target.targetName = obj.getClass().getName(); target.targetName = obj.getClass().getName();
mTargets.put(key, target); mDownloadTargets.put(key, target);
} }
return target; return target;
} }
@ -243,7 +245,7 @@ import java.util.Set;
(PopupWindow.OnDismissListener) dismissField.get(popupWindow); (PopupWindow.OnDismissListener) dismissField.get(popupWindow);
if (listener != null) { if (listener != null) {
Log.e(TAG, "你已经对PopupWindow设置了Dismiss事件。为了防止内存泄露," Log.e(TAG, "你已经对PopupWindow设置了Dismiss事件。为了防止内存泄露,"
+ "请在dismiss方法中调用Aria.whit(this).removeSchedulerListener();来注销事件"); + "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件");
} else { } else {
popupWindow.setOnDismissListener(createPopupWindowListener(popupWindow)); popupWindow.setOnDismissListener(createPopupWindowListener(popupWindow));
} }
@ -276,7 +278,7 @@ import java.util.Set;
Message cancelMsg = (Message) cancelField.get(dialog); Message cancelMsg = (Message) cancelField.get(dialog);
if (cancelMsg != null) { if (cancelMsg != null) {
Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露," Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露,"
+ "请在dismiss方法中调用Aria.whit(this).removeSchedulerListener();来注销事件"); + "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件");
} else { } else {
dialog.setOnCancelListener(createCancelListener()); dialog.setOnCancelListener(createCancelListener());
} }
@ -288,8 +290,8 @@ import java.util.Set;
} }
} }
private AMReceiver getTarget(Object obj) { private DownloadReceiver getDownloadTarget(Object obj) {
AMReceiver target = mTargets.get(obj.getClass().getName()); DownloadReceiver target = mDownloadTargets.get(obj.getClass().getName());
if (target == null) { if (target == null) {
target = putTarget(obj); target = putTarget(obj);
} }
@ -335,17 +337,15 @@ import java.util.Set;
* onDestroy * onDestroy
*/ */
private void destroySchedulerListener(Object obj) { private void destroySchedulerListener(Object obj) {
Set<String> keys = mTargets.keySet(); Set<String> keys = mDownloadTargets.keySet();
String clsName = obj.getClass().getName(); String clsName = obj.getClass().getName();
for (Iterator<Map.Entry<String, AMReceiver>> iter = mTargets.entrySet().iterator(); for (
Iterator<Map.Entry<String, DownloadReceiver>> iter = mDownloadTargets.entrySet().iterator();
iter.hasNext(); ) { iter.hasNext(); ) {
Map.Entry<String, AMReceiver> entry = iter.next(); Map.Entry<String, DownloadReceiver> entry = iter.next();
String key = entry.getKey(); String key = entry.getKey();
if (key.equals(clsName) || key.contains(clsName)) { if (key.equals(clsName) || key.contains(clsName)) {
AMReceiver receiver = mTargets.get(key); DownloadReceiver receiver = mDownloadTargets.get(key);
if (receiver.obj != null) {
if (receiver.obj instanceof Application || receiver.obj instanceof Service) break;
}
receiver.removeSchedulerListener(); receiver.removeSchedulerListener();
receiver.destroy(); receiver.destroy();
iter.remove(); iter.remove();

@ -19,7 +19,7 @@ package com.arialyy.aria.core;
import android.content.Context; import android.content.Context;
import com.arialyy.aria.core.queue.ITaskQueue; import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.orm.DbUtil; import com.arialyy.aria.orm.DbUtil;
import com.arialyy.aria.core.command.IDownloadCmd; import com.arialyy.aria.core.command.download.IDownloadCmd;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration;

@ -0,0 +1,19 @@
package com.arialyy.aria.core;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Aria.Lao on 2017/1/23.
* 下载任务实体
*/
public class DownloadTaskEntity {
public DownloadEntity downloadEntity;
public RequestEnum requestEnum = RequestEnum.GET;
public Map<String, String> headers = new HashMap<>();
public DownloadTaskEntity(DownloadEntity downloadEntity) {
this.downloadEntity = downloadEntity;
}
}

@ -7,7 +7,7 @@ package com.arialyy.aria.core;
public enum RequestEnum { public enum RequestEnum {
GET("GET"), POST("POST"); GET("GET"), POST("POST");
String name; public String name;
RequestEnum(String name) { RequestEnum(String name) {
this.name = name; this.name = name;

@ -1,10 +0,0 @@
package com.arialyy.aria.core;
/**
* Created by Aria.Lao on 2017/1/23.
* 任务实体
*/
public class TaskEntity {
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;
import android.util.Log;
import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.task.Task;
/**
* 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() {
Task task = mQueue.getTask(mEntity);
if (task == null) {
task = mQueue.createTask(mTargetName, mEntity);
} else {
Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
}
task.setTargetName(mTargetName);
mQueue.startTask(task);
}
}

@ -14,10 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.download;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.task.Task; import com.arialyy.aria.core.task.Task;
/** /**
@ -26,16 +27,16 @@ import com.arialyy.aria.core.task.Task;
*/ */
class AddCmd extends IDownloadCmd { class AddCmd extends IDownloadCmd {
AddCmd(DownloadEntity entity) { AddCmd(DownloadTaskEntity entity) {
super(entity); super(entity);
} }
AddCmd(String target, DownloadEntity entity) { AddCmd(String targetName, DownloadTaskEntity entity) {
super(target, entity); super(targetName, entity);
} }
@Override public void executeCmd() { @Override public void executeCmd() {
Task task = mQueue.getTask(mEntity); Task task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) { if (task == null) {
mQueue.createTask(mTargetName, mEntity); mQueue.createTask(mTargetName, mEntity);
} else { } else {

@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.download;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.task.Task; import com.arialyy.aria.core.task.Task;
/** /**
@ -25,16 +26,16 @@ import com.arialyy.aria.core.task.Task;
*/ */
class CancelCmd extends IDownloadCmd { class CancelCmd extends IDownloadCmd {
CancelCmd(String target, DownloadEntity entity) { CancelCmd(DownloadTaskEntity entity) {
super(target, entity); super(entity);
} }
CancelCmd(DownloadEntity entity) { CancelCmd(String targetName, DownloadTaskEntity entity) {
super(entity); super(targetName, entity);
} }
@Override public void executeCmd() { @Override public void executeCmd() {
Task task = mQueue.getTask(mEntity); Task task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) { if (task == null) {
task = mQueue.createTask(mTargetName, mEntity); task = mQueue.createTask(mTargetName, mEntity);
} }

@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.download;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadTaskEntity;
/** /**
* Created by Lyy on 2016/9/23. * Created by Lyy on 2016/9/23.
@ -66,7 +67,7 @@ public class CmdFactory {
* @param type 命令类型{@link #TASK_CREATE}{@link #TASK_START}{@link #TASK_CANCEL}{@link * @param type 命令类型{@link #TASK_CREATE}{@link #TASK_START}{@link #TASK_CANCEL}{@link
* #TASK_STOP} * #TASK_STOP}
*/ */
public IDownloadCmd createCmd(DownloadEntity entity, int type) { public IDownloadCmd createCmd(DownloadTaskEntity entity, int type) {
switch (type) { switch (type) {
case TASK_CREATE: case TASK_CREATE:
return createAddCmd(entity); return createAddCmd(entity);
@ -78,7 +79,7 @@ public class CmdFactory {
case TASK_STOP: case TASK_STOP:
return createStopCmd(entity); return createStopCmd(entity);
case TASK_SINGLE: case TASK_SINGLE:
return new SingleCmd(entity); //return new SingleCmd(entity);
default: default:
return null; return null;
} }
@ -90,7 +91,7 @@ public class CmdFactory {
* @param type 命令类型{@link #TASK_CREATE}{@link #TASK_START}{@link #TASK_CANCEL}{@link * @param type 命令类型{@link #TASK_CREATE}{@link #TASK_START}{@link #TASK_CANCEL}{@link
* #TASK_STOP} * #TASK_STOP}
*/ */
public IDownloadCmd createCmd(String target, DownloadEntity entity, int type) { public IDownloadCmd createCmd(String target, DownloadTaskEntity entity, int type) {
switch (type) { switch (type) {
case TASK_CREATE: case TASK_CREATE:
return createAddCmd(target, entity); return createAddCmd(target, entity);
@ -102,7 +103,7 @@ public class CmdFactory {
case TASK_STOP: case TASK_STOP:
return createStopCmd(target, entity); return createStopCmd(target, entity);
case TASK_SINGLE: case TASK_SINGLE:
return new SingleCmd(target, entity); //return new SingleCmd(target, entity);
default: default:
return null; return null;
} }
@ -113,7 +114,7 @@ public class CmdFactory {
* *
* @return {@link StopCmd} * @return {@link StopCmd}
*/ */
private StopCmd createStopCmd(String target, DownloadEntity entity) { private StopCmd createStopCmd(String target, DownloadTaskEntity entity) {
return new StopCmd(target, entity); return new StopCmd(target, entity);
} }
@ -122,7 +123,7 @@ public class CmdFactory {
* *
* @return {@link StopCmd} * @return {@link StopCmd}
*/ */
private StopCmd createStopCmd(DownloadEntity entity) { private StopCmd createStopCmd(DownloadTaskEntity entity) {
return new StopCmd(entity); return new StopCmd(entity);
} }
@ -131,7 +132,7 @@ public class CmdFactory {
* *
* @return {@link AddCmd} * @return {@link AddCmd}
*/ */
private AddCmd createAddCmd(String target, DownloadEntity entity) { private AddCmd createAddCmd(String target, DownloadTaskEntity entity) {
return new AddCmd(target, entity); return new AddCmd(target, entity);
} }
@ -140,7 +141,7 @@ public class CmdFactory {
* *
* @return {@link AddCmd} * @return {@link AddCmd}
*/ */
private AddCmd createAddCmd(DownloadEntity entity) { private AddCmd createAddCmd(DownloadTaskEntity entity) {
return new AddCmd(entity); return new AddCmd(entity);
} }
@ -149,7 +150,7 @@ public class CmdFactory {
* *
* @return {@link StartCmd} * @return {@link StartCmd}
*/ */
private StartCmd createStartCmd(String target, DownloadEntity entity) { private StartCmd createStartCmd(String target, DownloadTaskEntity entity) {
return new StartCmd(target, entity); return new StartCmd(target, entity);
} }
@ -158,7 +159,7 @@ public class CmdFactory {
* *
* @return {@link StartCmd} * @return {@link StartCmd}
*/ */
private StartCmd createStartCmd(DownloadEntity entity) { private StartCmd createStartCmd(DownloadTaskEntity entity) {
return new StartCmd(entity); return new StartCmd(entity);
} }
@ -167,7 +168,7 @@ public class CmdFactory {
* *
* @return {@link CancelCmd} * @return {@link CancelCmd}
*/ */
private CancelCmd createCancelCmd(String target, DownloadEntity entity) { private CancelCmd createCancelCmd(String target, DownloadTaskEntity entity) {
return new CancelCmd(target, entity); return new CancelCmd(target, entity);
} }
@ -176,7 +177,7 @@ public class CmdFactory {
* *
* @return {@link CancelCmd} * @return {@link CancelCmd}
*/ */
private CancelCmd createCancelCmd(DownloadEntity entity) { private CancelCmd createCancelCmd(DownloadTaskEntity entity) {
return new CancelCmd(entity); return new CancelCmd(entity);
} }
} }

@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.download;
import com.arialyy.aria.core.DownloadManager; import com.arialyy.aria.core.DownloadManager;
import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.queue.ITaskQueue; import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -28,22 +29,22 @@ import com.arialyy.aria.core.DownloadEntity;
*/ */
public abstract class IDownloadCmd { public abstract class IDownloadCmd {
ITaskQueue mQueue; ITaskQueue mQueue;
DownloadEntity mEntity; DownloadTaskEntity mEntity;
String TAG; String TAG;
String mTargetName; String mTargetName;
/** /**
* @param entity 下载实体 * @param entity 下载实体
*/ */
IDownloadCmd(DownloadEntity entity) { IDownloadCmd(DownloadTaskEntity entity) {
this(null, entity); this(null, entity);
} }
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */
IDownloadCmd(String targetName, DownloadEntity entity) { IDownloadCmd(String targetName, DownloadTaskEntity entity) {
if (!CheckUtil.checkDownloadEntity(entity)) { if (!CheckUtil.checkDownloadEntity(entity.downloadEntity)) {
return; return;
} }
mTargetName = targetName; mTargetName = targetName;

@ -0,0 +1,48 @@
///*
// * 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.DownloadEntity;
//import com.arialyy.aria.core.task.Task;
//
///**
// * 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() {
// Task task = mQueue.getTask(mEntity);
// if (task == null) {
// task = mQueue.createTask(mTargetName, mEntity);
// } else {
// Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
// }
// task.setTargetName(mTargetName);
// mQueue.startTask(task);
// }
//}

@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.download;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.task.Task; import com.arialyy.aria.core.task.Task;
/** /**
@ -25,16 +26,16 @@ import com.arialyy.aria.core.task.Task;
*/ */
class StartCmd extends IDownloadCmd { class StartCmd extends IDownloadCmd {
StartCmd(String target, DownloadEntity entity) { StartCmd(DownloadTaskEntity entity) {
super(target, entity); super(entity);
} }
StartCmd(DownloadEntity entity) { StartCmd(String targetName, DownloadTaskEntity entity) {
super(entity); super(targetName, entity);
} }
@Override public void executeCmd() { @Override public void executeCmd() {
Task task = mQueue.getTask(mEntity); Task task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) { if (task == null) {
task = mQueue.createTask(mTargetName, mEntity); task = mQueue.createTask(mTargetName, mEntity);
} }

@ -14,11 +14,12 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.download;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.task.Task; import com.arialyy.aria.core.task.Task;
/** /**
@ -27,21 +28,18 @@ import com.arialyy.aria.core.task.Task;
*/ */
class StopCmd extends IDownloadCmd { class StopCmd extends IDownloadCmd {
/** StopCmd(DownloadTaskEntity entity) {
* @param entity 下载实体 super(entity);
*/
StopCmd(String target, DownloadEntity entity) {
super(target, entity);
} }
StopCmd(DownloadEntity entity) { StopCmd(String targetName, DownloadTaskEntity entity) {
super(entity); super(targetName, entity);
} }
@Override public void executeCmd() { @Override public void executeCmd() {
Task task = mQueue.getTask(mEntity); Task task = mQueue.getTask(mEntity.downloadEntity);
if (task == null) { if (task == null) {
if (mEntity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) { if (mEntity.downloadEntity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
task = mQueue.createTask(mTargetName, mEntity); task = mQueue.createTask(mTargetName, mEntity);
mQueue.stopTask(task); mQueue.stopTask(task);
} else { } else {

@ -20,10 +20,10 @@ import android.content.Context;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.queue.pool.CachePool; import com.arialyy.aria.core.queue.pool.CachePool;
import com.arialyy.aria.core.queue.pool.ExecutePool; import com.arialyy.aria.core.queue.pool.ExecutePool;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
import com.arialyy.aria.core.task.Task; import com.arialyy.aria.core.task.Task;
import com.arialyy.aria.core.task.TaskFactory; import com.arialyy.aria.core.task.TaskFactory;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration;
@ -146,7 +146,7 @@ public class DownloadTaskQueue implements ITaskQueue {
} }
} }
@Override public Task createTask(String target, DownloadEntity entity) { @Override public Task createTask(String target, DownloadTaskEntity entity) {
Task task; Task task;
if (TextUtils.isEmpty(target)) { if (TextUtils.isEmpty(target)) {
task = task =

@ -17,6 +17,7 @@
package com.arialyy.aria.core.queue; package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.scheduler.IDownloadSchedulers; import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
import com.arialyy.aria.core.task.Task; import com.arialyy.aria.core.task.Task;
@ -46,11 +47,11 @@ public interface ITaskQueue extends IDownloader {
/** /**
* 创建一个新的下载任务创建时只是将新任务存储到缓存池 * 创建一个新的下载任务创建时只是将新任务存储到缓存池
* *
* @param entity 下载实体{@link DownloadEntity} * @param entity 下载实体{@link DownloadTaskEntity}
* @param targetName 生成该任务的对象 * @param targetName 生成该任务的对象
* @return {@link Task} * @return {@link Task}
*/ */
public Task createTask(String targetName, DownloadEntity entity); public Task createTask(String targetName, DownloadTaskEntity entity);
/** /**
* 通过下载链接从缓存池或任务池搜索下载任务如果缓存池或任务池都没有任务则创建新任务 * 通过下载链接从缓存池或任务池搜索下载任务如果缓存池或任务池都没有任务则创建新任务

@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core; package com.arialyy.aria.core.receiver;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.arialyy.aria.core.AMTarget;
import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.OnSchedulerListener; import com.arialyy.aria.core.scheduler.OnSchedulerListener;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
@ -24,10 +26,9 @@ import com.arialyy.aria.util.CheckUtil;
* Created by lyy on 2016/12/5. * Created by lyy on 2016/12/5.
* AM 接收器 * AM 接收器
*/ */
public class AMReceiver { public class DownloadReceiver {
String targetName; public String targetName;
OnSchedulerListener listener; public OnSchedulerListener listener;
Object obj;
/** /**
* {@link #load(String)}请使用该方法 * {@link #load(String)}请使用该方法
@ -53,7 +54,7 @@ public class AMReceiver {
/** /**
* 添加调度器回调 * 添加调度器回调
*/ */
public AMReceiver addSchedulerListener(OnSchedulerListener listener) { public DownloadReceiver addSchedulerListener(OnSchedulerListener listener) {
this.listener = listener; this.listener = listener;
DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener); DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener);
return this; return this;
@ -62,14 +63,14 @@ public class AMReceiver {
/** /**
* 移除回调 * 移除回调
*/ */
public AMReceiver removeSchedulerListener() { public DownloadReceiver removeSchedulerListener() {
if (listener != null) { if (listener != null) {
DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener); DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener);
} }
return this; return this;
} }
void destroy() { public void destroy() {
targetName = null; targetName = null;
listener = null; listener = null;
} }

@ -0,0 +1,24 @@
/*
* 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.receiver;
/**
* Created by Aria.Lao on 2017/2/6.
*/
public interface IReceiver {
}

@ -0,0 +1,24 @@
/*
* 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.receiver;
/**
* Created by Aria.Lao on 2017/2/6.
*/
public class UploadReceiver implements IReceiver {
}

@ -15,6 +15,7 @@
*/ */
package com.arialyy.aria.core.task; package com.arialyy.aria.core.task;
import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.util.CAConfiguration; import com.arialyy.aria.util.CAConfiguration;
import com.arialyy.aria.util.SSLContextUtil; import com.arialyy.aria.util.SSLContextUtil;
import java.io.IOException; import java.io.IOException;
@ -22,6 +23,7 @@ import java.net.HttpURLConnection;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.Set;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
@ -60,8 +62,15 @@ class ConnectionHelp {
* *
* @throws ProtocolException * @throws ProtocolException
*/ */
static HttpURLConnection setConnectParam(HttpURLConnection conn) throws ProtocolException { static HttpURLConnection setConnectParam(DownloadTaskEntity entity, HttpURLConnection conn)
conn.setRequestMethod("GET"); throws ProtocolException {
conn.setRequestMethod(entity.requestEnum.name);
if (entity.headers != null && entity.headers.size() > 0) {
Set<String> keys = entity.headers.keySet();
for (String key : keys) {
conn.setRequestProperty(key, entity.headers.get(key));
}
}
conn.setRequestProperty("Charset", "UTF-8"); conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("User-Agent", conn.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"); "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");

@ -20,6 +20,8 @@ import android.content.Context;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -48,20 +50,23 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
private boolean isSupportBreakpoint = true; private boolean isSupportBreakpoint = true;
private Context mContext; private Context mContext;
private DownloadEntity mDownloadEntity; private DownloadEntity mDownloadEntity;
private DownloadTaskEntity mDownloadTaskEntity;
private ExecutorService mFixedThreadPool; private ExecutorService mFixedThreadPool;
private File mDownloadFile; //下载的文件 private File mDownloadFile; //下载的文件
private File mConfigFile;//下载信息配置文件 private File mConfigFile;//下载信息配置文件
private SparseArray<Runnable> mTask = new SparseArray<>(); private SparseArray<Runnable> mTask = new SparseArray<>();
private DownloadStateConstance mConstance; private DownloadStateConstance mConstance;
DownloadUtil(Context context, DownloadEntity entity, IDownloadListener downloadListener) { DownloadUtil(Context context, DownloadTaskEntity entity, IDownloadListener downloadListener) {
this(context, entity, downloadListener, 3); this(context, entity, downloadListener, 3);
} }
DownloadUtil(Context context, DownloadEntity entity, IDownloadListener downloadListener, DownloadUtil(Context context, DownloadTaskEntity entity, IDownloadListener downloadListener,
int threadNum) { int threadNum) {
CheckUtil.checkDownloadEntity(entity.downloadEntity);
mDownloadEntity = entity.downloadEntity;
mContext = context.getApplicationContext(); mContext = context.getApplicationContext();
mDownloadEntity = entity; mDownloadTaskEntity = entity;
mListener = downloadListener; mListener = downloadListener;
THREAD_NUM = threadNum; THREAD_NUM = threadNum;
mFixedThreadPool = Executors.newFixedThreadPool(Integer.MAX_VALUE); mFixedThreadPool = Executors.newFixedThreadPool(Integer.MAX_VALUE);
@ -70,7 +75,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
} }
private void init() { private void init() {
mDownloadFile = new File(mDownloadEntity.getDownloadPath()); mDownloadFile = new File(mDownloadTaskEntity.downloadEntity.getDownloadPath());
//读取已完成的线程数 //读取已完成的线程数
mConfigFile = new File( mConfigFile = new File(
mContext.getFilesDir().getPath() + "/temp/" + mDownloadFile.getName() + ".properties"); mContext.getFilesDir().getPath() + "/temp/" + mDownloadFile.getName() + ".properties");
@ -196,7 +201,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
try { try {
URL url = new URL(mDownloadEntity.getDownloadUrl()); URL url = new URL(mDownloadEntity.getDownloadUrl());
HttpURLConnection conn = ConnectionHelp.handleConnection(url); HttpURLConnection conn = ConnectionHelp.handleConnection(url);
conn = ConnectionHelp.setConnectParam(conn); conn = ConnectionHelp.setConnectParam(mDownloadTaskEntity, conn);
conn.setRequestProperty("Range", "bytes=" + 0 + "-"); conn.setRequestProperty("Range", "bytes=" + 0 + "-");
conn.setConnectTimeout(mConnectTimeOut * 4); conn.setConnectTimeout(mConnectTimeOut * 4);
conn.connect(); conn.connect();
@ -251,6 +256,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
entity.END_LOCATION = entity.FILE_SIZE; entity.END_LOCATION = entity.FILE_SIZE;
entity.CONFIG_FILE_PATH = mConfigFile.getPath(); entity.CONFIG_FILE_PATH = mConfigFile.getPath();
entity.isSupportBreakpoint = isSupportBreakpoint; entity.isSupportBreakpoint = isSupportBreakpoint;
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity); SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
mFixedThreadPool.execute(task); mFixedThreadPool.execute(task);
mListener.onStart(0); mListener.onStart(0);
@ -336,6 +342,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
entity.END_LOCATION = endL; entity.END_LOCATION = endL;
entity.CONFIG_FILE_PATH = mConfigFile.getPath(); entity.CONFIG_FILE_PATH = mConfigFile.getPath();
entity.isSupportBreakpoint = isSupportBreakpoint; entity.isSupportBreakpoint = isSupportBreakpoint;
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity); SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
mTask.put(i, task); mTask.put(i, task);
} }
@ -366,5 +373,6 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
File TEMP_FILE; File TEMP_FILE;
boolean isSupportBreakpoint = true; boolean isSupportBreakpoint = true;
String CONFIG_FILE_PATH; String CONFIG_FILE_PATH;
DownloadTaskEntity DOWNLOAD_TASK_ENTITY;
} }
} }

@ -70,7 +70,7 @@ final class SingleThreadTask implements Runnable {
} else { } else {
Log.w(TAG, "该下载不支持断点,即将重新下载"); Log.w(TAG, "该下载不支持断点,即将重新下载");
} }
conn = ConnectionHelp.setConnectParam(conn); conn = ConnectionHelp.setConnectParam(mConfigEntity.DOWNLOAD_TASK_ENTITY, conn);
conn.setConnectTimeout(mConstance.CONNECT_TIME_OUT); conn.setConnectTimeout(mConstance.CONNECT_TIME_OUT);
conn.setReadTimeout(mConstance.READ_TIME_OUT); //设置读取流的等待时间,必须设置该参数 conn.setReadTimeout(mConstance.READ_TIME_OUT); //设置读取流的等待时间,必须设置该参数
is = conn.getInputStream(); is = conn.getInputStream();
@ -87,7 +87,6 @@ final class SingleThreadTask implements Runnable {
break; break;
} }
if (mConstance.isStop) { if (mConstance.isStop) {
Log.i(TAG, "stop");
break; break;
} }
//把下载数据数据写入文件 //把下载数据数据写入文件

@ -21,11 +21,11 @@ import android.content.Intent;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.DownloadManager; import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.TaskEntity;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.IDownloadSchedulers; import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -41,21 +41,23 @@ public class Task {
*/ */
private String mTargetName; private String mTargetName;
private DownloadEntity mEntity; private DownloadEntity mEntity;
private DownloadTaskEntity mTaskEntity;
private IDownloadListener mListener; private IDownloadListener mListener;
private Handler mOutHandler; private Handler mOutHandler;
private Context mContext; private Context mContext;
private IDownloadUtil mUtil; private IDownloadUtil mUtil;
private Task(Context context, DownloadEntity entity, Handler outHandler) { private Task(Context context, DownloadTaskEntity taskEntity, Handler outHandler) {
mContext = context.getApplicationContext(); mContext = context.getApplicationContext();
mEntity = entity; mTaskEntity = taskEntity;
mEntity = taskEntity.downloadEntity;
mOutHandler = outHandler; mOutHandler = outHandler;
init(); init();
} }
private void init() { private void init() {
mListener = new DListener(mContext, this, mOutHandler); mListener = new DListener(mContext, this, mOutHandler);
mUtil = new DownloadUtil(mContext, mEntity, mListener); mUtil = new DownloadUtil(mContext, mTaskEntity, mListener);
} }
/** /**
@ -162,21 +164,21 @@ public class Task {
} }
static class Builder { static class Builder {
DownloadEntity downloadEntity; DownloadTaskEntity taskEntity;
Handler outHandler; Handler outHandler;
Context context; Context context;
int threadNum = 3; int threadNum = 3;
String targetName; String targetName;
IDownloadUtil downloadUtil;
public Builder(Context context, DownloadEntity downloadEntity) { public Builder(Context context, DownloadTaskEntity downloadEntity) {
this("", context, downloadEntity); this("", context, downloadEntity);
} }
Builder(String targetName, Context context, DownloadEntity downloadEntity) { Builder(String targetName, Context context, DownloadTaskEntity taskEntity) {
CheckUtil.checkDownloadEntity(taskEntity.downloadEntity);
this.targetName = targetName; this.targetName = targetName;
this.context = context; this.context = context;
this.downloadEntity = downloadEntity; this.taskEntity = taskEntity;
} }
/** /**
@ -198,9 +200,9 @@ public class Task {
} }
public Task build() { public Task build() {
Task task = new Task(context, downloadEntity, outHandler); Task task = new Task(context, taskEntity, outHandler);
task.setTargetName(targetName); task.setTargetName(targetName);
downloadEntity.save(); taskEntity.downloadEntity.save();
return task; return task;
} }
} }

@ -17,7 +17,7 @@
package com.arialyy.aria.core.task; package com.arialyy.aria.core.task;
import android.content.Context; import android.content.Context;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.scheduler.IDownloadSchedulers; import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
/** /**
@ -46,14 +46,19 @@ public class TaskFactory {
/** /**
* 创建普通下载任务 * 创建普通下载任务
* *
* @param entity 下载实体 * @param entity 下载任务实体{@link DownloadTaskEntity}
* @param schedulers {@link IDownloadSchedulers} * @param schedulers {@link IDownloadSchedulers}
*/ */
public Task createTask(Context context, DownloadEntity entity, IDownloadSchedulers schedulers) { public Task createTask(Context context, DownloadTaskEntity entity,
IDownloadSchedulers schedulers) {
return createTask("", context, entity, schedulers); return createTask("", context, entity, schedulers);
} }
public Task createTask(String targetName, Context context, DownloadEntity entity, /**
* @param entity 下载任务实体{@link DownloadTaskEntity}
* @param schedulers {@link IDownloadSchedulers}
*/
public Task createTask(String targetName, Context context, DownloadTaskEntity entity,
IDownloadSchedulers schedulers) { IDownloadSchedulers schedulers) {
Task.Builder builder = new Task.Builder(targetName, context, entity); Task.Builder builder = new Task.Builder(targetName, context, entity);
builder.setOutHandler(schedulers); builder.setOutHandler(schedulers);

@ -31,6 +31,13 @@ import java.util.regex.Pattern;
public class CheckUtil { public class CheckUtil {
private static final String TAG = "CheckUtil"; private static final String TAG = "CheckUtil";
/**
* 判空
*/
public static void checkNull(Object obj) {
if (obj == null) throw new IllegalArgumentException("不能传入空对象");
}
/** /**
* 检查sql的expression是否合法 * 检查sql的expression是否合法
*/ */

@ -21,9 +21,10 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.DownloadTaskEntity;
import com.arialyy.aria.core.command.download.CmdFactory;
import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.command.IDownloadCmd; import com.arialyy.aria.core.command.download.IDownloadCmd;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -40,11 +41,11 @@ import java.util.Properties;
public class CommonUtil { public class CommonUtil {
private static final String TAG = "util"; private static final String TAG = "util";
public static IDownloadCmd createCmd(String target, DownloadEntity entity, int cmd) { public static IDownloadCmd createDownloadCmd(String target, DownloadTaskEntity entity, int cmd) {
return CmdFactory.getInstance().createCmd(target, entity, cmd); return CmdFactory.getInstance().createCmd(target, entity, cmd);
} }
public static IDownloadCmd createCmd(DownloadEntity entity, int cmd) { public static IDownloadCmd createDownloadCmd(DownloadTaskEntity entity, int cmd) {
return CmdFactory.getInstance().createCmd(entity, cmd); return CmdFactory.getInstance().createCmd(entity, cmd);
} }

@ -41,11 +41,11 @@ public class DownloadDialog extends AbsDialog {
private void init() { private void init() {
if (Aria.get(this).taskExists(DOWNLOAD_URL)) { if (Aria.get(this).taskExists(DOWNLOAD_URL)) {
AMTarget target = Aria.whit(this).load(DOWNLOAD_URL); AMTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p); mPb.setProgress(p);
} }
Aria.whit(this).addSchedulerListener(new MyDialogDownloadCallback()); Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL); DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL);
if (entity != null) { if (entity != null) {
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize())); mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
@ -59,17 +59,17 @@ public class DownloadDialog extends AbsDialog {
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) { @OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
Aria.whit(this) Aria.download(this)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
.setDownloadName("daialog.apk") .setDownloadName("daialog.apk")
.start(); .start();
break; break;
case R.id.stop: case R.id.stop:
Aria.whit(this).load(DOWNLOAD_URL).stop(); Aria.download(this).load(DOWNLOAD_URL).stop();
break; break;
case R.id.cancel: case R.id.cancel:
Aria.whit(this).load(DOWNLOAD_URL).cancel(); Aria.download(this).load(DOWNLOAD_URL).cancel();
break; break;
} }
} }

@ -33,7 +33,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
if (Aria.get(this).taskExists(DOWNLOAD_URL)) { if (Aria.get(this).taskExists(DOWNLOAD_URL)) {
AMTarget target = Aria.whit(this).load(DOWNLOAD_URL); AMTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p); mPb.setProgress(p);
} }
@ -49,23 +49,23 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
@Override public void onResume() { @Override public void onResume() {
super.onResume(); super.onResume();
Aria.whit(this).addSchedulerListener(new DownloadFragment.MyDialogDownloadCallback()); Aria.download(this).addSchedulerListener(new DownloadFragment.MyDialogDownloadCallback());
} }
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) { @OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
Aria.whit(this) Aria.download(this)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
.setDownloadName("daialog.apk") .setDownloadName("daialog.apk")
.start(); .start();
break; break;
case R.id.stop: case R.id.stop:
Aria.whit(this).load(DOWNLOAD_URL).stop(); Aria.download(this).load(DOWNLOAD_URL).stop();
break; break;
case R.id.cancel: case R.id.cancel:
Aria.whit(this).load(DOWNLOAD_URL).cancel(); Aria.download(this).load(DOWNLOAD_URL).cancel();
break; break;
} }
} }

@ -36,7 +36,7 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadBinding> {
@Override protected void onResume() { @Override protected void onResume() {
super.onResume(); super.onResume();
Aria.whit(this).addSchedulerListener(new MySchedulerListener()); Aria.download(this).addSchedulerListener(new MySchedulerListener());
} }
private class MySchedulerListener extends Aria.SimpleSchedulerListener { private class MySchedulerListener extends Aria.SimpleSchedulerListener {

@ -142,7 +142,7 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
@Override public void onClick(View v) { @Override public void onClick(View v) {
mData.remove(item); mData.remove(item);
notifyDataSetChanged(); notifyDataSetChanged();
Aria.whit(getContext()).load(item).cancel(); Aria.download(getContext()).load(item).cancel();
} }
}); });
} }
@ -183,11 +183,11 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
} }
private void start(DownloadEntity entity) { private void start(DownloadEntity entity) {
Aria.whit(getContext()).load(entity).start(); Aria.download(getContext()).load(entity).start();
} }
private void stop(DownloadEntity entity) { private void stop(DownloadEntity entity) {
Aria.whit(getContext()).load(entity).stop(); Aria.download(getContext()).load(entity).stop();
} }
} }

@ -1,7 +1,6 @@
package com.arialyy.simple.multi_task; package com.arialyy.simple.multi_task;
import android.content.Context; import android.content.Context;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
@ -51,7 +50,7 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
holder.bt.setOnClickListener(new View.OnClickListener() { holder.bt.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) { @Override public void onClick(View v) {
Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show();
Aria.whit(getContext()) Aria.download(getContext())
.load(item.downloadUrl) .load(item.downloadUrl)
.setDownloadName(item.name) .setDownloadName(item.name)
.setDownloadPath(item.downloadPath) .setDownloadPath(item.downloadPath)

@ -24,9 +24,7 @@ import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.DownloadEntity;
import com.arialyy.aria.core.task.Task; import com.arialyy.aria.core.task.Task;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiBinding; import com.arialyy.simple.databinding.ActivityMultiBinding;
@ -74,7 +72,7 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
@Override protected void onResume() { @Override protected void onResume() {
super.onResume(); super.onResume();
Aria.whit(this).addSchedulerListener(new DownloadListener()); Aria.download(this).addSchedulerListener(new DownloadListener());
} }
@Override protected void onDestroy() { @Override protected void onDestroy() {

@ -6,8 +6,6 @@ import android.os.Environment;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.task.Task; import com.arialyy.aria.core.task.Task;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R; import com.arialyy.simple.R;
/** /**
@ -36,11 +34,11 @@ public class SimpleNotification {
.setProgress(100, 0, false) .setProgress(100, 0, false)
.setSmallIcon(R.mipmap.ic_launcher); .setSmallIcon(R.mipmap.ic_launcher);
mManager.notify(mNotifiyId, mBuilder.build()); mManager.notify(mNotifiyId, mBuilder.build());
Aria.whit(mContext).addSchedulerListener(new DownloadCallback(mBuilder, mManager)); Aria.download(mContext).addSchedulerListener(new DownloadCallback(mBuilder, mManager));
} }
public void start() { public void start() {
Aria.whit(mContext) Aria.download(mContext)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
.setDownloadName("notification_test.apk") .setDownloadName("notification_test.apk")
.setDownloadPath( .setDownloadPath(
@ -49,7 +47,7 @@ public class SimpleNotification {
} }
public void stop() { public void stop() {
Aria.whit(mContext).load(DOWNLOAD_URL).stop(); Aria.download(mContext).load(DOWNLOAD_URL).stop();
} }
private static class DownloadCallback extends Aria.SimpleSchedulerListener { private static class DownloadCallback extends Aria.SimpleSchedulerListener {

@ -43,11 +43,11 @@ public class DownloadPopupWindow extends AbsPopupWindow {
private void initWidget() { private void initWidget() {
if (Aria.get(this).taskExists(DOWNLOAD_URL)) { if (Aria.get(this).taskExists(DOWNLOAD_URL)) {
AMTarget target = Aria.whit(this).load(DOWNLOAD_URL); AMTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p); mPb.setProgress(p);
} }
Aria.whit(this).addSchedulerListener(new MyDialogDownloadCallback()); Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL); DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL);
if (entity != null) { if (entity != null) {
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize())); mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
@ -61,17 +61,17 @@ public class DownloadPopupWindow extends AbsPopupWindow {
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) { @OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
Aria.whit(this) Aria.download(this)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
.setDownloadName("daialog.apk") .setDownloadName("daialog.apk")
.start(); .start();
break; break;
case R.id.stop: case R.id.stop:
Aria.whit(this).load(DOWNLOAD_URL).stop(); Aria.download(this).load(DOWNLOAD_URL).stop();
break; break;
case R.id.cancel: case R.id.cancel:
Aria.whit(this).load(DOWNLOAD_URL).cancel(); Aria.download(this).load(DOWNLOAD_URL).cancel();
break; break;
} }
} }

@ -139,7 +139,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Override protected void onResume() { @Override protected void onResume() {
super.onResume(); super.onResume();
Aria.whit(this).addSchedulerListener(new MySchedulerListener()); Aria.download(this).addSchedulerListener(new MySchedulerListener());
//registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter()); //registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
} }
@ -162,7 +162,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private void init() { private void init() {
if (Aria.get(this).taskExists(DOWNLOAD_URL)) { if (Aria.get(this).taskExists(DOWNLOAD_URL)) {
AMTarget target = Aria.whit(this).load(DOWNLOAD_URL); AMTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p); mPb.setProgress(p);
} }
@ -188,11 +188,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
private void resume() { private void resume() {
Aria.whit(this).load(DOWNLOAD_URL).resume(); Aria.download(this).load(DOWNLOAD_URL).resume();
} }
private void start() { private void start() {
Aria.whit(this) Aria.download(this)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
.setDownloadName("test.apk") .setDownloadName("test.apk")
@ -200,11 +200,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
private void stop() { private void stop() {
Aria.whit(this).load(DOWNLOAD_URL).stop(); Aria.download(this).load(DOWNLOAD_URL).stop();
} }
private void cancel() { private void cancel() {
Aria.whit(this).load(DOWNLOAD_URL).cancel(); Aria.download(this).load(DOWNLOAD_URL).cancel();
} }
private class MySchedulerListener extends Aria.SimpleSchedulerListener { private class MySchedulerListener extends Aria.SimpleSchedulerListener {

Loading…
Cancel
Save