3.0 版本编写、添加header支持、代码逻辑修改
This commit is contained in:
@ -17,25 +17,56 @@ package com.arialyy.aria.core;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.command.CmdFactory;
|
||||
import com.arialyy.aria.core.command.IDownloadCmd;
|
||||
import com.arialyy.aria.core.command.download.CmdFactory;
|
||||
import com.arialyy.aria.core.command.download.IDownloadCmd;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/12/5.
|
||||
* https://github.com/AriaLyy/Aria
|
||||
*/
|
||||
public class AMTarget {
|
||||
//private AMReceiver mReceiver;
|
||||
DownloadEntity entity;
|
||||
String targetName;
|
||||
DownloadTaskEntity taskEntity;
|
||||
|
||||
AMTarget(DownloadEntity entity, String targetName) {
|
||||
public AMTarget(DownloadEntity entity, String targetName) {
|
||||
this.entity = entity;
|
||||
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() {
|
||||
DownloadManager.getInstance()
|
||||
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_CREATE))
|
||||
.setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_CREATE))
|
||||
.exe();
|
||||
}
|
||||
|
||||
@ -101,8 +132,8 @@ public class AMTarget {
|
||||
*/
|
||||
public void start() {
|
||||
List<IDownloadCmd> cmds = new ArrayList<>();
|
||||
cmds.add(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_CREATE));
|
||||
cmds.add(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_START));
|
||||
cmds.add(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_CREATE));
|
||||
cmds.add(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_START));
|
||||
DownloadManager.getInstance().setCmds(cmds).exe();
|
||||
cmds.clear();
|
||||
}
|
||||
@ -112,7 +143,7 @@ public class AMTarget {
|
||||
*/
|
||||
public void stop() {
|
||||
DownloadManager.getInstance()
|
||||
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_STOP))
|
||||
.setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_STOP))
|
||||
.exe();
|
||||
}
|
||||
|
||||
@ -121,7 +152,7 @@ public class AMTarget {
|
||||
*/
|
||||
public void resume() {
|
||||
DownloadManager.getInstance()
|
||||
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_START))
|
||||
.setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_START))
|
||||
.exe();
|
||||
}
|
||||
|
||||
@ -130,7 +161,7 @@ public class AMTarget {
|
||||
*/
|
||||
public void cancel() {
|
||||
DownloadManager.getInstance()
|
||||
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_CANCEL))
|
||||
.setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_CANCEL))
|
||||
.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.os.Build;
|
||||
import android.widget.PopupWindow;
|
||||
import com.arialyy.aria.core.receiver.DownloadReceiver;
|
||||
import com.arialyy.aria.core.scheduler.OnSchedulerListener;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
|
||||
@ -36,7 +37,7 @@ import com.arialyy.aria.core.task.Task;
|
||||
* <pre>
|
||||
* <code>
|
||||
* //启动下载
|
||||
* Aria.whit(this)
|
||||
* Aria.download(this)
|
||||
* .load(DOWNLOAD_URL) //下载地址,必填
|
||||
* //文件保存路径,必填
|
||||
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
@ -99,120 +100,48 @@ import com.arialyy.aria.core.task.Task;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接受Activity、Service、Application
|
||||
* 初始化下载
|
||||
*
|
||||
* @param obj 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
|
||||
*/
|
||||
public static AMReceiver whit(Context context) {
|
||||
//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) {
|
||||
checkNull(dialog);
|
||||
return AriaManager.getInstance(dialog.getContext()).get(dialog);
|
||||
public static DownloadReceiver download(Object obj) {
|
||||
return get(obj).download(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理通用事件
|
||||
*
|
||||
* @param obj 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
|
||||
*/
|
||||
public static AriaManager get(Context context) {
|
||||
if (context == null) throw new IllegalArgumentException("context 不能为 null");
|
||||
if (context instanceof Activity
|
||||
|| context instanceof Service
|
||||
|| context instanceof Application) {
|
||||
return AriaManager.getInstance(context);
|
||||
public static AriaManager get(Object obj) {
|
||||
if (obj instanceof Activity || obj instanceof Service || obj instanceof Application) {
|
||||
return AriaManager.getInstance((Context) obj);
|
||||
} else if (obj instanceof DialogFragment) {
|
||||
DialogFragment dialog = (DialogFragment) obj;
|
||||
return AriaManager.getInstance(
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? dialog.getContext()
|
||||
: dialog.getActivity());
|
||||
} else if (obj instanceof android.support.v4.app.Fragment) {
|
||||
android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj;
|
||||
return AriaManager.getInstance(
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
||||
: fragment.getActivity());
|
||||
} else if (obj instanceof Fragment) {
|
||||
Fragment fragment = (Fragment) obj;
|
||||
return AriaManager.getInstance(
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
||||
: 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("这是不支持的context");
|
||||
throw new IllegalArgumentException("不支持的类型");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理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(
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
||||
: fragment.getActivity());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理Fragment的通用任务
|
||||
*/
|
||||
public static AriaManager get(android.support.v4.app.Fragment fragment) {
|
||||
checkNull(fragment);
|
||||
return AriaManager.getInstance(
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
||||
: fragment.getActivity());
|
||||
}
|
||||
|
||||
private static void checkNull(Object obj) {
|
||||
if (obj == null) throw new IllegalArgumentException("不能传入空对象");
|
||||
}
|
||||
|
||||
public static class SimpleSchedulerListener implements OnSchedulerListener {
|
||||
|
||||
@Override public void onTaskPre(Task task) {
|
||||
|
@ -19,7 +19,6 @@ import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.app.Dialog;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Build;
|
||||
@ -29,11 +28,12 @@ import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
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.CheckUtil;
|
||||
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 java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@ -52,7 +52,7 @@ import java.util.Set;
|
||||
private static final String TAG = "AriaManager";
|
||||
private static final Object LOCK = new Object();
|
||||
private static volatile AriaManager INSTANCE = null;
|
||||
private Map<String, AMReceiver> mTargets = new HashMap<>();
|
||||
private Map<String, DownloadReceiver> mDownloadTargets = new HashMap<>();
|
||||
private DownloadManager mManager;
|
||||
private LifeCallback mLifeCallback;
|
||||
|
||||
@ -70,8 +70,8 @@ import java.util.Set;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
AMReceiver get(Object obj) {
|
||||
return getTarget(obj);
|
||||
DownloadReceiver download(Object obj) {
|
||||
return getDownloadTarget(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,14 +115,15 @@ import java.util.Set;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止所有正在执行的任务
|
||||
* 停止所有正在下载的任务
|
||||
*/
|
||||
public void stopAllTask() {
|
||||
List<DownloadEntity> allEntity = mManager.getAllDownloadEntity();
|
||||
List<IDownloadCmd> stopCmds = new ArrayList<>();
|
||||
for (DownloadEntity entity : allEntity) {
|
||||
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();
|
||||
@ -181,20 +182,21 @@ import java.util.Set;
|
||||
List<DownloadEntity> allEntity = mManager.getAllDownloadEntity();
|
||||
List<IDownloadCmd> cancelCmds = new ArrayList<>();
|
||||
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();
|
||||
Set<String> keys = mTargets.keySet();
|
||||
Set<String> keys = mDownloadTargets.keySet();
|
||||
for (String key : keys) {
|
||||
AMReceiver target = mTargets.get(key);
|
||||
DownloadReceiver target = mDownloadTargets.get(key);
|
||||
target.removeSchedulerListener();
|
||||
mTargets.remove(key);
|
||||
mDownloadTargets.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
private AMReceiver putTarget(Object obj) {
|
||||
private DownloadReceiver putTarget(Object obj) {
|
||||
String clsName = obj.getClass().getName();
|
||||
AMReceiver target = null;
|
||||
DownloadReceiver target = null;
|
||||
String key = "";
|
||||
if (!(obj instanceof Activity)) {
|
||||
if (obj instanceof android.support.v4.app.Fragment) {
|
||||
@ -224,11 +226,11 @@ import java.util.Set;
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
throw new IllegalArgumentException("未知类型");
|
||||
}
|
||||
target = mTargets.get(key);
|
||||
target = mDownloadTargets.get(key);
|
||||
if (target == null) {
|
||||
target = new AMReceiver();
|
||||
target = new DownloadReceiver();
|
||||
target.targetName = obj.getClass().getName();
|
||||
mTargets.put(key, target);
|
||||
mDownloadTargets.put(key, target);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
@ -243,7 +245,7 @@ import java.util.Set;
|
||||
(PopupWindow.OnDismissListener) dismissField.get(popupWindow);
|
||||
if (listener != null) {
|
||||
Log.e(TAG, "你已经对PopupWindow设置了Dismiss事件。为了防止内存泄露,"
|
||||
+ "请在dismiss方法中调用Aria.whit(this).removeSchedulerListener();来注销事件");
|
||||
+ "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件");
|
||||
} else {
|
||||
popupWindow.setOnDismissListener(createPopupWindowListener(popupWindow));
|
||||
}
|
||||
@ -276,7 +278,7 @@ import java.util.Set;
|
||||
Message cancelMsg = (Message) cancelField.get(dialog);
|
||||
if (cancelMsg != null) {
|
||||
Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露,"
|
||||
+ "请在dismiss方法中调用Aria.whit(this).removeSchedulerListener();来注销事件");
|
||||
+ "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件");
|
||||
} else {
|
||||
dialog.setOnCancelListener(createCancelListener());
|
||||
}
|
||||
@ -288,8 +290,8 @@ import java.util.Set;
|
||||
}
|
||||
}
|
||||
|
||||
private AMReceiver getTarget(Object obj) {
|
||||
AMReceiver target = mTargets.get(obj.getClass().getName());
|
||||
private DownloadReceiver getDownloadTarget(Object obj) {
|
||||
DownloadReceiver target = mDownloadTargets.get(obj.getClass().getName());
|
||||
if (target == null) {
|
||||
target = putTarget(obj);
|
||||
}
|
||||
@ -335,17 +337,15 @@ import java.util.Set;
|
||||
* onDestroy
|
||||
*/
|
||||
private void destroySchedulerListener(Object obj) {
|
||||
Set<String> keys = mTargets.keySet();
|
||||
Set<String> keys = mDownloadTargets.keySet();
|
||||
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(); ) {
|
||||
Map.Entry<String, AMReceiver> entry = iter.next();
|
||||
Map.Entry<String, DownloadReceiver> entry = iter.next();
|
||||
String key = entry.getKey();
|
||||
if (key.equals(clsName) || key.contains(clsName)) {
|
||||
AMReceiver receiver = mTargets.get(key);
|
||||
if (receiver.obj != null) {
|
||||
if (receiver.obj instanceof Application || receiver.obj instanceof Service) break;
|
||||
}
|
||||
DownloadReceiver receiver = mDownloadTargets.get(key);
|
||||
receiver.removeSchedulerListener();
|
||||
receiver.destroy();
|
||||
iter.remove();
|
||||
|
@ -19,7 +19,7 @@ package com.arialyy.aria.core;
|
||||
import android.content.Context;
|
||||
import com.arialyy.aria.core.queue.ITaskQueue;
|
||||
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.orm.DbEntity;
|
||||
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 {
|
||||
GET("GET"), POST("POST");
|
||||
|
||||
String name;
|
||||
public String name;
|
||||
|
||||
RequestEnum(String 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.
|
||||
*/
|
||||
|
||||
package com.arialyy.aria.core.command;
|
||||
package com.arialyy.aria.core.command.download;
|
||||
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
|
||||
/**
|
||||
@ -26,16 +27,16 @@ import com.arialyy.aria.core.task.Task;
|
||||
*/
|
||||
class AddCmd extends IDownloadCmd {
|
||||
|
||||
AddCmd(DownloadEntity entity) {
|
||||
AddCmd(DownloadTaskEntity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
AddCmd(String target, DownloadEntity entity) {
|
||||
super(target, entity);
|
||||
AddCmd(String targetName, DownloadTaskEntity entity) {
|
||||
super(targetName, entity);
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
Task task = mQueue.getTask(mEntity);
|
||||
Task task = mQueue.getTask(mEntity.downloadEntity);
|
||||
if (task == null) {
|
||||
mQueue.createTask(mTargetName, mEntity);
|
||||
} else {
|
@ -14,9 +14,10 @@
|
||||
* 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.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
|
||||
/**
|
||||
@ -25,16 +26,16 @@ import com.arialyy.aria.core.task.Task;
|
||||
*/
|
||||
class CancelCmd extends IDownloadCmd {
|
||||
|
||||
CancelCmd(String target, DownloadEntity entity) {
|
||||
super(target, entity);
|
||||
}
|
||||
|
||||
CancelCmd(DownloadEntity entity) {
|
||||
CancelCmd(DownloadTaskEntity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
CancelCmd(String targetName, DownloadTaskEntity entity) {
|
||||
super(targetName, entity);
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
Task task = mQueue.getTask(mEntity);
|
||||
Task task = mQueue.getTask(mEntity.downloadEntity);
|
||||
if (task == null) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
}
|
@ -14,9 +14,10 @@
|
||||
* 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.DownloadTaskEntity;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* #TASK_STOP}
|
||||
*/
|
||||
public IDownloadCmd createCmd(DownloadEntity entity, int type) {
|
||||
public IDownloadCmd createCmd(DownloadTaskEntity entity, int type) {
|
||||
switch (type) {
|
||||
case TASK_CREATE:
|
||||
return createAddCmd(entity);
|
||||
@ -78,7 +79,7 @@ public class CmdFactory {
|
||||
case TASK_STOP:
|
||||
return createStopCmd(entity);
|
||||
case TASK_SINGLE:
|
||||
return new SingleCmd(entity);
|
||||
//return new SingleCmd(entity);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@ -90,7 +91,7 @@ public class CmdFactory {
|
||||
* @param type 命令类型{@link #TASK_CREATE}、{@link #TASK_START}、{@link #TASK_CANCEL}、{@link
|
||||
* #TASK_STOP}
|
||||
*/
|
||||
public IDownloadCmd createCmd(String target, DownloadEntity entity, int type) {
|
||||
public IDownloadCmd createCmd(String target, DownloadTaskEntity entity, int type) {
|
||||
switch (type) {
|
||||
case TASK_CREATE:
|
||||
return createAddCmd(target, entity);
|
||||
@ -102,7 +103,7 @@ public class CmdFactory {
|
||||
case TASK_STOP:
|
||||
return createStopCmd(target, entity);
|
||||
case TASK_SINGLE:
|
||||
return new SingleCmd(target, entity);
|
||||
//return new SingleCmd(target, entity);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@ -113,7 +114,7 @@ public class CmdFactory {
|
||||
*
|
||||
* @return {@link StopCmd}
|
||||
*/
|
||||
private StopCmd createStopCmd(String target, DownloadEntity entity) {
|
||||
private StopCmd createStopCmd(String target, DownloadTaskEntity entity) {
|
||||
return new StopCmd(target, entity);
|
||||
}
|
||||
|
||||
@ -122,7 +123,7 @@ public class CmdFactory {
|
||||
*
|
||||
* @return {@link StopCmd}
|
||||
*/
|
||||
private StopCmd createStopCmd(DownloadEntity entity) {
|
||||
private StopCmd createStopCmd(DownloadTaskEntity entity) {
|
||||
return new StopCmd(entity);
|
||||
}
|
||||
|
||||
@ -131,7 +132,7 @@ public class CmdFactory {
|
||||
*
|
||||
* @return {@link AddCmd}
|
||||
*/
|
||||
private AddCmd createAddCmd(String target, DownloadEntity entity) {
|
||||
private AddCmd createAddCmd(String target, DownloadTaskEntity entity) {
|
||||
return new AddCmd(target, entity);
|
||||
}
|
||||
|
||||
@ -140,7 +141,7 @@ public class CmdFactory {
|
||||
*
|
||||
* @return {@link AddCmd}
|
||||
*/
|
||||
private AddCmd createAddCmd(DownloadEntity entity) {
|
||||
private AddCmd createAddCmd(DownloadTaskEntity entity) {
|
||||
return new AddCmd(entity);
|
||||
}
|
||||
|
||||
@ -149,7 +150,7 @@ public class CmdFactory {
|
||||
*
|
||||
* @return {@link StartCmd}
|
||||
*/
|
||||
private StartCmd createStartCmd(String target, DownloadEntity entity) {
|
||||
private StartCmd createStartCmd(String target, DownloadTaskEntity entity) {
|
||||
return new StartCmd(target, entity);
|
||||
}
|
||||
|
||||
@ -158,7 +159,7 @@ public class CmdFactory {
|
||||
*
|
||||
* @return {@link StartCmd}
|
||||
*/
|
||||
private StartCmd createStartCmd(DownloadEntity entity) {
|
||||
private StartCmd createStartCmd(DownloadTaskEntity entity) {
|
||||
return new StartCmd(entity);
|
||||
}
|
||||
|
||||
@ -167,7 +168,7 @@ public class CmdFactory {
|
||||
*
|
||||
* @return {@link CancelCmd}
|
||||
*/
|
||||
private CancelCmd createCancelCmd(String target, DownloadEntity entity) {
|
||||
private CancelCmd createCancelCmd(String target, DownloadTaskEntity entity) {
|
||||
return new CancelCmd(target, entity);
|
||||
}
|
||||
|
||||
@ -176,7 +177,7 @@ public class CmdFactory {
|
||||
*
|
||||
* @return {@link CancelCmd}
|
||||
*/
|
||||
private CancelCmd createCancelCmd(DownloadEntity entity) {
|
||||
private CancelCmd createCancelCmd(DownloadTaskEntity entity) {
|
||||
return new CancelCmd(entity);
|
||||
}
|
||||
}
|
@ -14,9 +14,10 @@
|
||||
* 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.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.queue.ITaskQueue;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@ -28,22 +29,22 @@ import com.arialyy.aria.core.DownloadEntity;
|
||||
*/
|
||||
public abstract class IDownloadCmd {
|
||||
ITaskQueue mQueue;
|
||||
DownloadEntity mEntity;
|
||||
DownloadTaskEntity mEntity;
|
||||
String TAG;
|
||||
String mTargetName;
|
||||
|
||||
/**
|
||||
* @param entity 下载实体
|
||||
*/
|
||||
IDownloadCmd(DownloadEntity entity) {
|
||||
IDownloadCmd(DownloadTaskEntity entity) {
|
||||
this(null, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param targetName 产生任务的对象名
|
||||
*/
|
||||
IDownloadCmd(String targetName, DownloadEntity entity) {
|
||||
if (!CheckUtil.checkDownloadEntity(entity)) {
|
||||
IDownloadCmd(String targetName, DownloadTaskEntity entity) {
|
||||
if (!CheckUtil.checkDownloadEntity(entity.downloadEntity)) {
|
||||
return;
|
||||
}
|
||||
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.
|
||||
*/
|
||||
|
||||
package com.arialyy.aria.core.command;
|
||||
package com.arialyy.aria.core.command.download;
|
||||
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
|
||||
/**
|
||||
@ -25,16 +26,16 @@ import com.arialyy.aria.core.task.Task;
|
||||
*/
|
||||
class StartCmd extends IDownloadCmd {
|
||||
|
||||
StartCmd(String target, DownloadEntity entity) {
|
||||
super(target, entity);
|
||||
}
|
||||
|
||||
StartCmd(DownloadEntity entity) {
|
||||
StartCmd(DownloadTaskEntity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
StartCmd(String targetName, DownloadTaskEntity entity) {
|
||||
super(targetName, entity);
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
Task task = mQueue.getTask(mEntity);
|
||||
Task task = mQueue.getTask(mEntity.downloadEntity);
|
||||
if (task == null) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
}
|
@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.arialyy.aria.core.command;
|
||||
package com.arialyy.aria.core.command.download;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
|
||||
/**
|
||||
@ -27,21 +28,18 @@ import com.arialyy.aria.core.task.Task;
|
||||
*/
|
||||
class StopCmd extends IDownloadCmd {
|
||||
|
||||
/**
|
||||
* @param entity 下载实体
|
||||
*/
|
||||
StopCmd(String target, DownloadEntity entity) {
|
||||
super(target, entity);
|
||||
}
|
||||
|
||||
StopCmd(DownloadEntity entity) {
|
||||
StopCmd(DownloadTaskEntity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
StopCmd(String targetName, DownloadTaskEntity entity) {
|
||||
super(targetName, entity);
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
Task task = mQueue.getTask(mEntity);
|
||||
Task task = mQueue.getTask(mEntity.downloadEntity);
|
||||
if (task == null) {
|
||||
if (mEntity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
|
||||
if (mEntity.downloadEntity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
mQueue.stopTask(task);
|
||||
} else {
|
@ -20,10 +20,10 @@ import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
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.ExecutePool;
|
||||
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.TaskFactory;
|
||||
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;
|
||||
if (TextUtils.isEmpty(target)) {
|
||||
task =
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.arialyy.aria.core.queue;
|
||||
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
|
||||
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 生成该任务的对象
|
||||
* @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
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core;
|
||||
package com.arialyy.aria.core.receiver;
|
||||
|
||||
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.OnSchedulerListener;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
@ -24,10 +26,9 @@ import com.arialyy.aria.util.CheckUtil;
|
||||
* Created by lyy on 2016/12/5.
|
||||
* AM 接收器
|
||||
*/
|
||||
public class AMReceiver {
|
||||
String targetName;
|
||||
OnSchedulerListener listener;
|
||||
Object obj;
|
||||
public class DownloadReceiver {
|
||||
public String targetName;
|
||||
public OnSchedulerListener listener;
|
||||
|
||||
/**
|
||||
* {@link #load(String)},请使用该方法
|
||||
@ -53,7 +54,7 @@ public class AMReceiver {
|
||||
/**
|
||||
* 添加调度器回调
|
||||
*/
|
||||
public AMReceiver addSchedulerListener(OnSchedulerListener listener) {
|
||||
public DownloadReceiver addSchedulerListener(OnSchedulerListener listener) {
|
||||
this.listener = listener;
|
||||
DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener);
|
||||
return this;
|
||||
@ -62,14 +63,14 @@ public class AMReceiver {
|
||||
/**
|
||||
* 移除回调
|
||||
*/
|
||||
public AMReceiver removeSchedulerListener() {
|
||||
public DownloadReceiver removeSchedulerListener() {
|
||||
if (listener != null) {
|
||||
DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
public void destroy() {
|
||||
targetName = 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;
|
||||
|
||||
import com.arialyy.aria.core.DownloadTaskEntity;
|
||||
import com.arialyy.aria.util.CAConfiguration;
|
||||
import com.arialyy.aria.util.SSLContextUtil;
|
||||
import java.io.IOException;
|
||||
@ -22,6 +23,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Set;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
@ -60,8 +62,15 @@ class ConnectionHelp {
|
||||
*
|
||||
* @throws ProtocolException
|
||||
*/
|
||||
static HttpURLConnection setConnectParam(HttpURLConnection conn) throws ProtocolException {
|
||||
conn.setRequestMethod("GET");
|
||||
static HttpURLConnection setConnectParam(DownloadTaskEntity entity, HttpURLConnection conn)
|
||||
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("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)");
|
||||
|
@ -20,6 +20,8 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -48,20 +50,23 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
private boolean isSupportBreakpoint = true;
|
||||
private Context mContext;
|
||||
private DownloadEntity mDownloadEntity;
|
||||
private DownloadTaskEntity mDownloadTaskEntity;
|
||||
private ExecutorService mFixedThreadPool;
|
||||
private File mDownloadFile; //下载的文件
|
||||
private File mConfigFile;//下载信息配置文件
|
||||
private SparseArray<Runnable> mTask = new SparseArray<>();
|
||||
private DownloadStateConstance mConstance;
|
||||
|
||||
DownloadUtil(Context context, DownloadEntity entity, IDownloadListener downloadListener) {
|
||||
DownloadUtil(Context context, DownloadTaskEntity entity, IDownloadListener downloadListener) {
|
||||
this(context, entity, downloadListener, 3);
|
||||
}
|
||||
|
||||
DownloadUtil(Context context, DownloadEntity entity, IDownloadListener downloadListener,
|
||||
DownloadUtil(Context context, DownloadTaskEntity entity, IDownloadListener downloadListener,
|
||||
int threadNum) {
|
||||
CheckUtil.checkDownloadEntity(entity.downloadEntity);
|
||||
mDownloadEntity = entity.downloadEntity;
|
||||
mContext = context.getApplicationContext();
|
||||
mDownloadEntity = entity;
|
||||
mDownloadTaskEntity = entity;
|
||||
mListener = downloadListener;
|
||||
THREAD_NUM = threadNum;
|
||||
mFixedThreadPool = Executors.newFixedThreadPool(Integer.MAX_VALUE);
|
||||
@ -70,7 +75,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mDownloadFile = new File(mDownloadEntity.getDownloadPath());
|
||||
mDownloadFile = new File(mDownloadTaskEntity.downloadEntity.getDownloadPath());
|
||||
//读取已完成的线程数
|
||||
mConfigFile = new File(
|
||||
mContext.getFilesDir().getPath() + "/temp/" + mDownloadFile.getName() + ".properties");
|
||||
@ -196,7 +201,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
try {
|
||||
URL url = new URL(mDownloadEntity.getDownloadUrl());
|
||||
HttpURLConnection conn = ConnectionHelp.handleConnection(url);
|
||||
conn = ConnectionHelp.setConnectParam(conn);
|
||||
conn = ConnectionHelp.setConnectParam(mDownloadTaskEntity, conn);
|
||||
conn.setRequestProperty("Range", "bytes=" + 0 + "-");
|
||||
conn.setConnectTimeout(mConnectTimeOut * 4);
|
||||
conn.connect();
|
||||
@ -251,6 +256,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
entity.END_LOCATION = entity.FILE_SIZE;
|
||||
entity.CONFIG_FILE_PATH = mConfigFile.getPath();
|
||||
entity.isSupportBreakpoint = isSupportBreakpoint;
|
||||
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
|
||||
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
|
||||
mFixedThreadPool.execute(task);
|
||||
mListener.onStart(0);
|
||||
@ -336,6 +342,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
entity.END_LOCATION = endL;
|
||||
entity.CONFIG_FILE_PATH = mConfigFile.getPath();
|
||||
entity.isSupportBreakpoint = isSupportBreakpoint;
|
||||
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
|
||||
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
|
||||
mTask.put(i, task);
|
||||
}
|
||||
@ -366,5 +373,6 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
File TEMP_FILE;
|
||||
boolean isSupportBreakpoint = true;
|
||||
String CONFIG_FILE_PATH;
|
||||
DownloadTaskEntity DOWNLOAD_TASK_ENTITY;
|
||||
}
|
||||
}
|
@ -70,7 +70,7 @@ final class SingleThreadTask implements Runnable {
|
||||
} else {
|
||||
Log.w(TAG, "该下载不支持断点,即将重新下载");
|
||||
}
|
||||
conn = ConnectionHelp.setConnectParam(conn);
|
||||
conn = ConnectionHelp.setConnectParam(mConfigEntity.DOWNLOAD_TASK_ENTITY, conn);
|
||||
conn.setConnectTimeout(mConstance.CONNECT_TIME_OUT);
|
||||
conn.setReadTimeout(mConstance.READ_TIME_OUT); //设置读取流的等待时间,必须设置该参数
|
||||
is = conn.getInputStream();
|
||||
@ -87,7 +87,6 @@ final class SingleThreadTask implements Runnable {
|
||||
break;
|
||||
}
|
||||
if (mConstance.isStop) {
|
||||
Log.i(TAG, "stop");
|
||||
break;
|
||||
}
|
||||
//把下载数据数据写入文件
|
||||
|
@ -21,11 +21,11 @@ import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadManager;
|
||||
import com.arialyy.aria.core.TaskEntity;
|
||||
import com.arialyy.aria.core.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import java.lang.ref.WeakReference;
|
||||
@ -39,23 +39,25 @@ public class Task {
|
||||
/**
|
||||
* 产生该任务对象的hash码
|
||||
*/
|
||||
private String mTargetName;
|
||||
private DownloadEntity mEntity;
|
||||
private String mTargetName;
|
||||
private DownloadEntity mEntity;
|
||||
private DownloadTaskEntity mTaskEntity;
|
||||
private IDownloadListener mListener;
|
||||
private Handler mOutHandler;
|
||||
private Context mContext;
|
||||
private IDownloadUtil mUtil;
|
||||
private Handler mOutHandler;
|
||||
private Context mContext;
|
||||
private IDownloadUtil mUtil;
|
||||
|
||||
private Task(Context context, DownloadEntity entity, Handler outHandler) {
|
||||
private Task(Context context, DownloadTaskEntity taskEntity, Handler outHandler) {
|
||||
mContext = context.getApplicationContext();
|
||||
mEntity = entity;
|
||||
mTaskEntity = taskEntity;
|
||||
mEntity = taskEntity.downloadEntity;
|
||||
mOutHandler = outHandler;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
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 {
|
||||
DownloadEntity downloadEntity;
|
||||
Handler outHandler;
|
||||
Context context;
|
||||
DownloadTaskEntity taskEntity;
|
||||
Handler outHandler;
|
||||
Context context;
|
||||
int threadNum = 3;
|
||||
String targetName;
|
||||
IDownloadUtil downloadUtil;
|
||||
String targetName;
|
||||
|
||||
public Builder(Context context, DownloadEntity downloadEntity) {
|
||||
public Builder(Context context, DownloadTaskEntity 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.context = context;
|
||||
this.downloadEntity = downloadEntity;
|
||||
this.taskEntity = taskEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,9 +200,9 @@ public class Task {
|
||||
}
|
||||
|
||||
public Task build() {
|
||||
Task task = new Task(context, downloadEntity, outHandler);
|
||||
Task task = new Task(context, taskEntity, outHandler);
|
||||
task.setTargetName(targetName);
|
||||
downloadEntity.save();
|
||||
taskEntity.downloadEntity.save();
|
||||
return task;
|
||||
}
|
||||
}
|
||||
@ -210,16 +212,16 @@ public class Task {
|
||||
*/
|
||||
private static class DListener extends DownloadListener {
|
||||
WeakReference<Handler> outHandler;
|
||||
WeakReference<Task> wTask;
|
||||
Context context;
|
||||
Intent sendIntent;
|
||||
long INTERVAL = 1024 * 10; //10k大小的间隔
|
||||
long lastLen = 0; //上一次发送长度
|
||||
long lastTime = 0;
|
||||
long INTERVAL_TIME = 1000; //1m更新周期
|
||||
boolean isFirst = true;
|
||||
WeakReference<Task> wTask;
|
||||
Context context;
|
||||
Intent sendIntent;
|
||||
long INTERVAL = 1024 * 10; //10k大小的间隔
|
||||
long lastLen = 0; //上一次发送长度
|
||||
long lastTime = 0;
|
||||
long INTERVAL_TIME = 1000; //1m更新周期
|
||||
boolean isFirst = true;
|
||||
DownloadEntity downloadEntity;
|
||||
Task task;
|
||||
Task task;
|
||||
|
||||
DListener(Context context, Task task, Handler outHandler) {
|
||||
this.context = context;
|
||||
|
@ -17,7 +17,7 @@
|
||||
package com.arialyy.aria.core.task;
|
||||
|
||||
import android.content.Context;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
|
||||
|
||||
/**
|
||||
@ -27,7 +27,7 @@ import com.arialyy.aria.core.scheduler.IDownloadSchedulers;
|
||||
public class TaskFactory {
|
||||
private static final String TAG = "TaskFactory";
|
||||
|
||||
private static final Object LOCK = new Object();
|
||||
private static final Object LOCK = new Object();
|
||||
private static volatile TaskFactory INSTANCE = null;
|
||||
|
||||
private TaskFactory() {
|
||||
@ -46,14 +46,19 @@ public class TaskFactory {
|
||||
/**
|
||||
* 创建普通下载任务
|
||||
*
|
||||
* @param entity 下载实体
|
||||
* @param entity 下载任务实体{@link DownloadTaskEntity}
|
||||
* @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);
|
||||
}
|
||||
|
||||
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) {
|
||||
Task.Builder builder = new Task.Builder(targetName, context, entity);
|
||||
builder.setOutHandler(schedulers);
|
||||
|
@ -31,6 +31,13 @@ import java.util.regex.Pattern;
|
||||
public class CheckUtil {
|
||||
private static final String TAG = "CheckUtil";
|
||||
|
||||
/**
|
||||
* 判空
|
||||
*/
|
||||
public static void checkNull(Object obj) {
|
||||
if (obj == null) throw new IllegalArgumentException("不能传入空对象");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查sql的expression是否合法
|
||||
*/
|
||||
@ -47,14 +54,14 @@ public class CheckUtil {
|
||||
}
|
||||
Pattern pattern = Pattern.compile("\\?");
|
||||
Matcher matcher = pattern.matcher(where);
|
||||
int count = 0;
|
||||
int count = 0;
|
||||
while (matcher.find()) {
|
||||
count++;
|
||||
}
|
||||
if (count < expression.length - 1){
|
||||
if (count < expression.length - 1) {
|
||||
throw new IllegalArgumentException("条件语句的?个数不能小于参数个数");
|
||||
}
|
||||
if (count > expression.length - 1){
|
||||
if (count > expression.length - 1) {
|
||||
throw new IllegalArgumentException("条件语句的?个数不能大于参数个数");
|
||||
}
|
||||
}
|
||||
@ -90,7 +97,7 @@ public class CheckUtil {
|
||||
fileName = fileName.replace(" ", "_");
|
||||
}
|
||||
String dPath = entity.getDownloadPath();
|
||||
File file = new File(dPath);
|
||||
File file = new File(dPath);
|
||||
if (file.isDirectory()) {
|
||||
dPath += fileName;
|
||||
entity.setDownloadPath(dPath);
|
||||
|
@ -21,9 +21,10 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
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.command.IDownloadCmd;
|
||||
import com.arialyy.aria.core.command.download.IDownloadCmd;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@ -40,11 +41,11 @@ import java.util.Properties;
|
||||
public class CommonUtil {
|
||||
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);
|
||||
}
|
||||
|
||||
public static IDownloadCmd createCmd(DownloadEntity entity, int cmd) {
|
||||
public static IDownloadCmd createDownloadCmd(DownloadTaskEntity entity, int cmd) {
|
||||
return CmdFactory.getInstance().createCmd(entity, cmd);
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,11 @@ public class DownloadDialog extends AbsDialog {
|
||||
|
||||
private void init() {
|
||||
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());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
Aria.whit(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
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) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.whit(this)
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
|
||||
.setDownloadName("daialog.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
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());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
@ -49,23 +49,23 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
|
||||
@Override public void 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) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.whit(this)
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
|
||||
.setDownloadName("daialog.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadBinding> {
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends Aria.SimpleSchedulerListener {
|
||||
|
@ -142,7 +142,7 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
|
||||
@Override public void onClick(View v) {
|
||||
mData.remove(item);
|
||||
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) {
|
||||
Aria.whit(getContext()).load(entity).start();
|
||||
Aria.download(getContext()).load(entity).start();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
@ -51,7 +50,7 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
|
||||
holder.bt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show();
|
||||
Aria.whit(getContext())
|
||||
Aria.download(getContext())
|
||||
.load(item.downloadUrl)
|
||||
.setDownloadName(item.name)
|
||||
.setDownloadPath(item.downloadPath)
|
||||
|
@ -24,9 +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.DownloadEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityMultiBinding;
|
||||
@ -74,7 +72,7 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new DownloadListener());
|
||||
Aria.download(this).addSchedulerListener(new DownloadListener());
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
|
@ -6,8 +6,6 @@ import android.os.Environment;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -36,11 +34,11 @@ public class SimpleNotification {
|
||||
.setProgress(100, 0, false)
|
||||
.setSmallIcon(R.mipmap.ic_launcher);
|
||||
mManager.notify(mNotifiyId, mBuilder.build());
|
||||
Aria.whit(mContext).addSchedulerListener(new DownloadCallback(mBuilder, mManager));
|
||||
Aria.download(mContext).addSchedulerListener(new DownloadCallback(mBuilder, mManager));
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Aria.whit(mContext)
|
||||
Aria.download(mContext)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadName("notification_test.apk")
|
||||
.setDownloadPath(
|
||||
@ -49,7 +47,7 @@ public class SimpleNotification {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Aria.whit(mContext).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(mContext).load(DOWNLOAD_URL).stop();
|
||||
}
|
||||
|
||||
private static class DownloadCallback extends Aria.SimpleSchedulerListener {
|
||||
|
@ -43,11 +43,11 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
|
||||
private void initWidget() {
|
||||
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());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
Aria.whit(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
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) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.whit(this)
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
|
||||
.setDownloadName("daialog.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
//registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
private void init() {
|
||||
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());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
@ -188,11 +188,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
|
||||
private void resume() {
|
||||
Aria.whit(this).load(DOWNLOAD_URL).resume();
|
||||
Aria.download(this).load(DOWNLOAD_URL).resume();
|
||||
}
|
||||
|
||||
private void start() {
|
||||
Aria.whit(this)
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
.setDownloadName("test.apk")
|
||||
@ -200,11 +200,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
Aria.whit(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
Aria.whit(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends Aria.SimpleSchedulerListener {
|
||||
|
Reference in New Issue
Block a user