From 90c7cd78ff5d1ee4f5980cca92afdba282797c48 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 7 Feb 2017 17:33:03 +0800 Subject: [PATCH] =?UTF-8?q?AriaManager=20=E9=80=BB=E8=BE=91=E9=87=8D?= =?UTF-8?q?=E5=86=99=EF=BC=8Capi=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/arialyy/aria/core/Aria.java | 1 - .../com/arialyy/aria/core/AriaManager.java | 272 +++++++----------- .../arialyy/aria/core/DownloadManager.java | 107 ------- .../arialyy/aria/core/DownloadReceiver.java | 141 +++++++++ .../{AMTarget.java => DownloadTarget.java} | 36 ++- .../arialyy/aria/core/DownloadTaskEntity.java | 15 + .../aria/core/{receiver => }/IReceiver.java | 13 +- .../com/arialyy/aria/core/RequestEnum.java | 17 +- .../core/{receiver => }/UploadReceiver.java | 11 +- .../arialyy/aria/core/WidgetLiftManager.java | 111 +++++++ .../core/command/download/IDownloadCmd.java | 5 +- .../aria/core/receiver/DownloadReceiver.java | 77 ----- .../core/scheduler/DownloadSchedulers.java | 6 +- .../com/arialyy/aria/util/Configuration.java | 4 +- .../com/arialyy/aria/util/SSLContextUtil.java | 9 +- .../arialyy/simple/base/BaseApplication.java | 2 - .../simple/dialog_task/DownloadDialog.java | 8 +- .../fragment_task/DownloadFragment.java | 8 +- .../arialyy/simple/module/DownloadModule.java | 2 +- .../simple/multi_task/DownloadActivity.java | 2 +- .../simple/multi_task/MultiTaskActivity.java | 2 +- .../simple/pop_task/DownloadPopupWindow.java | 8 +- .../single_task/SingleTaskActivity.java | 6 +- 23 files changed, 450 insertions(+), 413 deletions(-) delete mode 100644 Aria/src/main/java/com/arialyy/aria/core/DownloadManager.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/DownloadReceiver.java rename Aria/src/main/java/com/arialyy/aria/core/{AMTarget.java => DownloadTarget.java} (81%) rename Aria/src/main/java/com/arialyy/aria/core/{receiver => }/IReceiver.java (78%) rename Aria/src/main/java/com/arialyy/aria/core/{receiver => }/UploadReceiver.java (82%) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java delete mode 100644 Aria/src/main/java/com/arialyy/aria/core/receiver/DownloadReceiver.java diff --git a/Aria/src/main/java/com/arialyy/aria/core/Aria.java b/Aria/src/main/java/com/arialyy/aria/core/Aria.java index 9183b797..8bd04957 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java +++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java @@ -26,7 +26,6 @@ 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; diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index eeff3689..95a9711b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -15,33 +15,30 @@ */ package com.arialyy.aria.core; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; import android.app.Application; import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; import android.os.Build; import android.os.Bundle; -import android.os.Message; import android.support.v4.app.Fragment; import android.text.TextUtils; import android.util.Log; import android.widget.PopupWindow; -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.download.IDownloadCmd; +import com.arialyy.aria.core.queue.DownloadTaskQueue; +import com.arialyy.aria.core.queue.ITaskQueue; +import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.orm.DbUtil; +import com.arialyy.aria.util.CAConfiguration; import com.arialyy.aria.util.Configuration; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; /** * Created by lyy on 2016/12/1. @@ -50,18 +47,26 @@ import java.util.Set; */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager { private static final String TAG = "AriaManager"; + private static final String DOWNLOAD = "_download"; + private static final String UPLOAD = "_upload"; private static final Object LOCK = new Object(); - private static volatile AriaManager INSTANCE = null; - private Map mDownloadTargets = new HashMap<>(); - private DownloadManager mManager; + @SuppressLint("StaticFieldLeak") private static volatile AriaManager INSTANCE = null; + Map mReceivers = new HashMap<>(); private LifeCallback mLifeCallback; + public static Context APP; + private ITaskQueue mTaskQueue; + private List mCommands = new ArrayList<>(); + private AriaManager(Context context) { + DbUtil.init(context.getApplicationContext()); + APP = context; + DownloadTaskQueue.Builder builder = new DownloadTaskQueue.Builder(context); + mTaskQueue = builder.build(); regAppLifeCallback(context); - mManager = DownloadManager.init(context); } - static AriaManager getInstance(Context context) { + public static AriaManager getInstance(Context context) { if (INSTANCE == null) { synchronized (LOCK) { INSTANCE = new AriaManager(context); @@ -70,63 +75,72 @@ import java.util.Set; return INSTANCE; } - DownloadReceiver download(Object obj) { - return getDownloadTarget(obj); + List getAllDownloadEntity() { + return DbEntity.findAllData(DownloadEntity.class); } /** - * 设置CA证书信息 - * - * @param caAlias ca证书别名 - * @param caPath assets 文件夹下的ca证书完整路径 + * 获取任务队列 */ - public void setCAInfo(String caAlias, String caPath) { - if (TextUtils.isEmpty(caAlias)) { - Log.e(TAG, "ca证书别名不能为null"); - return; - } else if (TextUtils.isEmpty(caPath)) { - Log.e(TAG, "ca证书路径不能为null"); - return; - } - CAConfiguration.CA_ALIAS = caAlias; - CAConfiguration.CA_PATH = caPath; + public ITaskQueue getTaskQueue() { + return mTaskQueue; + } + + /** + * 设置命令 + */ + AriaManager setCmd(IDownloadCmd command) { + mCommands.add(command); + return this; } /** - * 获取下载列表 + * 设置一组命令 */ - public List getDownloadList() { - return DownloadEntity.findAllData(DownloadEntity.class); + AriaManager setCmds(List commands) { + if (commands != null && commands.size() > 0) { + mCommands.addAll(commands); + } + return this; } /** - * 通过下载链接获取下载实体 + * 执行所有设置的命令 */ - public DownloadEntity getDownloadEntity(String downloadUrl) { - CheckUtil.checkDownloadUrl(downloadUrl); - return DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl); + synchronized void exe() { + for (IDownloadCmd command : mCommands) { + command.executeCmd(); + } + mCommands.clear(); } /** - * 下载任务是否存在 + * 处理下载操作 */ - public boolean taskExists(String downloadUrl) { - return DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl) != null; + DownloadReceiver download(Object obj) { + IReceiver receiver = mReceivers.get(getKey(true, obj)); + if (receiver == null) { + receiver = putReceiver(true, obj); + } + return (receiver instanceof DownloadReceiver) ? (DownloadReceiver) receiver : null; } /** - * 停止所有正在下载的任务 + * 设置CA证书信息 + * + * @param caAlias ca证书别名 + * @param caPath assets 文件夹下的ca证书完整路径 */ - public void stopAllTask() { - List allEntity = mManager.getAllDownloadEntity(); - List stopCmds = new ArrayList<>(); - for (DownloadEntity entity : allEntity) { - if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) { - stopCmds.add( - CommonUtil.createDownloadCmd(new DownloadTaskEntity(entity), CmdFactory.TASK_STOP)); - } + public void setCAInfo(String caAlias, String caPath) { + if (TextUtils.isEmpty(caAlias)) { + Log.e(TAG, "ca证书别名不能为null"); + return; + } else if (TextUtils.isEmpty(caPath)) { + Log.e(TAG, "ca证书路径不能为null"); + return; } - mManager.setCmds(stopCmds).exe(); + CAConfiguration.CA_ALIAS = caAlias; + CAConfiguration.CA_PATH = caPath; } /** @@ -138,7 +152,7 @@ import java.util.Set; } /** - * 设置下载失败重试次数 + * 设置失败重试次数 */ public AriaManager setReTryNum(int reTryNum) { Configuration.getInstance().setReTryNum(reTryNum); @@ -146,7 +160,7 @@ import java.util.Set; } /** - * 设置下载失败重试间隔 + * 设置失败重试间隔 */ public AriaManager setReTryInterval(int interval) { Configuration.getInstance().setReTryInterval(interval); @@ -171,32 +185,40 @@ import java.util.Set; Log.w(TAG, "最大任务数不能小于 1"); return this; } - mManager.getTaskQueue().setDownloadNum(maxDownloadNum); + mTaskQueue.setDownloadNum(maxDownloadNum); return this; } - /** - * 删除所有任务 - */ - public void cancelAllTask() { - List allEntity = mManager.getAllDownloadEntity(); - List cancelCmds = new ArrayList<>(); - for (DownloadEntity entity : allEntity) { - cancelCmds.add( - CommonUtil.createDownloadCmd(new DownloadTaskEntity(entity), CmdFactory.TASK_CANCEL)); + private IReceiver putReceiver(boolean isDownload, Object obj) { + final String key = getKey(isDownload, obj); + IReceiver receiver = mReceivers.get(key); + final WidgetLiftManager widgetLiftManager = new WidgetLiftManager(); + if (obj instanceof Dialog) { + widgetLiftManager.handleDialogLift((Dialog) obj); + } else if (obj instanceof PopupWindow) { + widgetLiftManager.handlePopupWindowLift((PopupWindow) obj); } - mManager.setCmds(cancelCmds).exe(); - Set keys = mDownloadTargets.keySet(); - for (String key : keys) { - DownloadReceiver target = mDownloadTargets.get(key); - target.removeSchedulerListener(); - mDownloadTargets.remove(key); + + if (receiver == null) { + if (isDownload) { + DownloadReceiver dReceiver = new DownloadReceiver(); + dReceiver.targetName = obj.getClass().getName(); + mReceivers.put(key, dReceiver); + receiver = dReceiver; + } else { + UploadReceiver uReceiver = new UploadReceiver(); + + receiver = uReceiver; + } } + return receiver; } - private DownloadReceiver putTarget(Object obj) { + /** + * 根据功能类型和控件类型获取对应的key + */ + private String getKey(boolean isDownload, Object obj) { String clsName = obj.getClass().getName(); - DownloadReceiver target = null; String key = ""; if (!(obj instanceof Activity)) { if (obj instanceof android.support.v4.app.Fragment) { @@ -210,7 +232,6 @@ import java.util.Set; } else { key = clsName; } - handleDialogLift((Dialog) obj); } else if (obj instanceof PopupWindow) { Context context = ((PopupWindow) obj).getContentView().getContext(); if (context instanceof Activity) { @@ -218,7 +239,6 @@ import java.util.Set; } else { key = clsName; } - handlePopupWindowLift((PopupWindow) obj); } } else { key = clsName; @@ -226,76 +246,8 @@ import java.util.Set; if (TextUtils.isEmpty(key)) { throw new IllegalArgumentException("未知类型"); } - target = mDownloadTargets.get(key); - if (target == null) { - target = new DownloadReceiver(); - target.targetName = obj.getClass().getName(); - mDownloadTargets.put(key, target); - } - return target; - } - - /** - * 出来悬浮框取消或dismiss - */ - private void handlePopupWindowLift(PopupWindow popupWindow) { - try { - Field dismissField = CommonUtil.getField(popupWindow.getClass(), "mOnDismissListener"); - PopupWindow.OnDismissListener listener = - (PopupWindow.OnDismissListener) dismissField.get(popupWindow); - if (listener != null) { - Log.e(TAG, "你已经对PopupWindow设置了Dismiss事件。为了防止内存泄露," - + "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件"); - } else { - popupWindow.setOnDismissListener(createPopupWindowListener(popupWindow)); - } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - /** - * 创建popupWindow dismiss事件 - */ - private PopupWindow.OnDismissListener createPopupWindowListener(final PopupWindow popupWindow) { - return new PopupWindow.OnDismissListener() { - @Override public void onDismiss() { - destroySchedulerListener(popupWindow); - } - }; - } - - /** - * 处理对话框取消或dismiss - */ - private void handleDialogLift(Dialog dialog) { - try { - Field dismissField = CommonUtil.getField(dialog.getClass(), "mDismissMessage"); - Message dismissMsg = (Message) dismissField.get(dialog); - //如果Dialog已经设置Dismiss事件,则查找cancel事件 - if (dismissMsg != null) { - Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage"); - Message cancelMsg = (Message) cancelField.get(dialog); - if (cancelMsg != null) { - Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露," - + "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件"); - } else { - dialog.setOnCancelListener(createCancelListener()); - } - } else { - dialog.setOnDismissListener(createDismissListener()); - } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - private DownloadReceiver getDownloadTarget(Object obj) { - DownloadReceiver target = mDownloadTargets.get(obj.getClass().getName()); - if (target == null) { - target = putTarget(obj); - } - return target; + key += isDownload ? DOWNLOAD : UPLOAD; + return key; } /** @@ -309,43 +261,17 @@ import java.util.Set; } } - /** - * 创建Dialog取消事件 - */ - private Dialog.OnCancelListener createCancelListener() { - return new Dialog.OnCancelListener() { - - @Override public void onCancel(DialogInterface dialog) { - destroySchedulerListener(dialog); - } - }; - } - - /** - * 创建Dialog dismiss取消事件 - */ - private Dialog.OnDismissListener createDismissListener() { - return new Dialog.OnDismissListener() { - - @Override public void onDismiss(DialogInterface dialog) { - destroySchedulerListener(dialog); - } - }; - } - /** * onDestroy */ - private void destroySchedulerListener(Object obj) { - Set keys = mDownloadTargets.keySet(); + void destroySchedulerListener(Object obj) { String clsName = obj.getClass().getName(); - for ( - Iterator> iter = mDownloadTargets.entrySet().iterator(); + for (Iterator> iter = mReceivers.entrySet().iterator(); iter.hasNext(); ) { - Map.Entry entry = iter.next(); + Map.Entry entry = iter.next(); String key = entry.getKey(); - if (key.equals(clsName) || key.contains(clsName)) { - DownloadReceiver receiver = mDownloadTargets.get(key); + if (key.contains(clsName)) { + IReceiver receiver = mReceivers.get(key); receiver.removeSchedulerListener(); receiver.destroy(); iter.remove(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/DownloadManager.java b/Aria/src/main/java/com/arialyy/aria/core/DownloadManager.java deleted file mode 100644 index d8119bb8..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/DownloadManager.java +++ /dev/null @@ -1,107 +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; - -import android.content.Context; -import com.arialyy.aria.core.queue.ITaskQueue; -import com.arialyy.aria.orm.DbUtil; -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; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by lyy on 2016/8/11. - * 下载管理器,通过命令的方式控制下载 - */ -public class DownloadManager { - private static final String TAG = "DownloadManager"; - private static final Object LOCK = new Object(); - private static volatile DownloadManager INSTANCE = null; - private List mCommands = new ArrayList<>(); - public static Context APP; - private ITaskQueue mTaskQueue; - private static Configuration mConfig; - - private DownloadManager() { - - } - - private DownloadManager(Context context) { - APP = context; - DownloadTaskQueue.Builder builder = new DownloadTaskQueue.Builder(context); - mTaskQueue = builder.build(); - DbUtil.init(context); - } - - static DownloadManager init(Context context) { - if (INSTANCE == null) { - synchronized (LOCK) { - INSTANCE = new DownloadManager(context.getApplicationContext()); - } - } - return INSTANCE; - } - - public static DownloadManager getInstance() { - if (INSTANCE == null) { - throw new NullPointerException("请在Application中调用init进行下载器注册"); - } - return INSTANCE; - } - - List getAllDownloadEntity() { - return DbEntity.findAllData(DownloadEntity.class); - } - - /** - * 获取任务队列 - */ - public ITaskQueue getTaskQueue() { - return mTaskQueue; - } - - /** - * 设置命令 - */ - DownloadManager setCmd(IDownloadCmd command) { - mCommands.add(command); - return this; - } - - /** - * 设置一组命令 - */ - DownloadManager setCmds(List commands) { - if (commands != null && commands.size() > 0) { - mCommands.addAll(commands); - } - return this; - } - - /** - * 执行所有设置的命令 - */ - synchronized void exe() { - for (IDownloadCmd command : mCommands) { - command.executeCmd(); - } - mCommands.clear(); - } -} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/DownloadReceiver.java new file mode 100644 index 00000000..8a2237a8 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/DownloadReceiver.java @@ -0,0 +1,141 @@ +/* + * 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; + +import android.support.annotation.NonNull; +import com.arialyy.aria.core.command.download.CmdFactory; +import com.arialyy.aria.core.command.download.IDownloadCmd; +import com.arialyy.aria.core.scheduler.DownloadSchedulers; +import com.arialyy.aria.core.scheduler.OnSchedulerListener; +import com.arialyy.aria.util.CheckUtil; +import com.arialyy.aria.util.CommonUtil; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * Created by lyy on 2016/12/5. + * 下载功能接收器 + */ +public class DownloadReceiver implements IReceiver{ + private static final String TAG = "DownloadReceiver"; + public String targetName; + public OnSchedulerListener listener; + + /** + * {@link #load(String)},请使用该方法 + */ + @Deprecated public DownloadTarget load(DownloadEntity entity) { + return new DownloadTarget(entity, targetName); + } + + /** + * 读取下载链接 + */ + public DownloadTarget load(@NonNull String downloadUrl) { + CheckUtil.checkDownloadUrl(downloadUrl); + DownloadEntity entity = + DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl); + if (entity == null) { + entity = new DownloadEntity(); + } + entity.setDownloadUrl(downloadUrl); + return new DownloadTarget(entity, targetName); + } + + /** + * 添加调度器回调 + */ + public DownloadReceiver addSchedulerListener(OnSchedulerListener listener) { + this.listener = listener; + DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener); + return this; + } + + /** + * 移除回调 + */ + @Override + public void removeSchedulerListener() { + if (listener != null) { + DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener); + } + } + + @Override + public void destroy() { + targetName = null; + listener = null; + } + + /** + * 获取下载列表 + */ + public List getDownloadList() { + return DownloadEntity.findAllData(DownloadEntity.class); + } + + /** + * 通过下载链接获取下载实体 + */ + public DownloadEntity getDownloadEntity(String downloadUrl) { + CheckUtil.checkDownloadUrl(downloadUrl); + return DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl); + } + + /** + * 下载任务是否存在 + */ + public boolean taskExists(String downloadUrl) { + return DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl) != null; + } + + /** + * 停止所有正在下载的任务 + */ + public void stopAllTask() { + final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP); + List allEntity = ariaManager.getAllDownloadEntity(); + List stopCmds = new ArrayList<>(); + for (DownloadEntity entity : allEntity) { + if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) { + stopCmds.add( + CommonUtil.createDownloadCmd(new DownloadTaskEntity(entity), CmdFactory.TASK_STOP)); + } + } + ariaManager.setCmds(stopCmds).exe(); + } + + /** + * 删除所有任务 + */ + public void cancelAllTask() { + final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP); + List allEntity = ariaManager.getAllDownloadEntity(); + List cancelCmds = new ArrayList<>(); + for (DownloadEntity entity : allEntity) { + cancelCmds.add( + CommonUtil.createDownloadCmd(new DownloadTaskEntity(entity), CmdFactory.TASK_CANCEL)); + } + ariaManager.setCmds(cancelCmds).exe(); + Set keys = ariaManager.mReceivers.keySet(); + for (String key : keys) { + IReceiver receiver = ariaManager.mReceivers.get(key); + receiver.removeSchedulerListener(); + ariaManager.mReceivers.remove(key); + } + } +} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/AMTarget.java b/Aria/src/main/java/com/arialyy/aria/core/DownloadTarget.java similarity index 81% rename from Aria/src/main/java/com/arialyy/aria/core/AMTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/DownloadTarget.java index d5b1a5ad..6eae0275 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AMTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/DownloadTarget.java @@ -22,22 +22,20 @@ 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 { +public class DownloadTarget { DownloadEntity entity; String targetName; DownloadTaskEntity taskEntity; - public AMTarget(DownloadEntity entity, String targetName) { + public DownloadTarget(DownloadEntity entity, String targetName) { this.entity = entity; this.targetName = targetName; taskEntity = new DownloadTaskEntity(entity); @@ -49,7 +47,7 @@ public class AMTarget { * @param key 头部key * @param header 头部value */ - public AMTarget addHeader(@NonNull String key, @NonNull String header) { + public DownloadTarget addHeader(@NonNull String key, @NonNull String header) { taskEntity.headers.put(key, header); return this; } @@ -59,7 +57,7 @@ public class AMTarget { * * @param headers Map */ - public AMTarget addHeaders(Map headers) { + public DownloadTarget addHeaders(Map headers) { if (headers != null && headers.size() > 0) { Set keys = headers.keySet(); for (String key : keys) { @@ -72,7 +70,7 @@ public class AMTarget { /** * 设置文件存储路径 */ - public AMTarget setDownloadPath(@NonNull String downloadPath) { + public DownloadTarget setDownloadPath(@NonNull String downloadPath) { if (TextUtils.isEmpty(downloadPath)) { throw new IllegalArgumentException("文件保持路径不能为null"); } @@ -80,10 +78,20 @@ public class AMTarget { return this; } + /** + * 设置请求类型 + * + * @param requestEnum {@link RequestEnum} + */ + public DownloadTarget setRequestMode(RequestEnum requestEnum) { + taskEntity.requestEnum = requestEnum; + return this; + } + /** * 设置文件名 */ - public AMTarget setDownloadName(@NonNull String downloadName) { + public DownloadTarget setDownloadName(@NonNull String downloadName) { if (TextUtils.isEmpty(downloadName)) { throw new IllegalArgumentException("文件名不能为null"); } @@ -122,7 +130,7 @@ public class AMTarget { * 添加任务 */ public void add() { - DownloadManager.getInstance() + AriaManager.getInstance(AriaManager.APP) .setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_CREATE)) .exe(); } @@ -134,7 +142,7 @@ public class AMTarget { List cmds = new ArrayList<>(); cmds.add(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_CREATE)); cmds.add(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_START)); - DownloadManager.getInstance().setCmds(cmds).exe(); + AriaManager.getInstance(AriaManager.APP).setCmds(cmds).exe(); cmds.clear(); } @@ -142,7 +150,7 @@ public class AMTarget { * 停止下载 */ public void stop() { - DownloadManager.getInstance() + AriaManager.getInstance(AriaManager.APP) .setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_STOP)) .exe(); } @@ -151,7 +159,7 @@ public class AMTarget { * 恢复下载 */ public void resume() { - DownloadManager.getInstance() + AriaManager.getInstance(AriaManager.APP) .setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_START)) .exe(); } @@ -160,7 +168,7 @@ public class AMTarget { * 取消下载 */ public void cancel() { - DownloadManager.getInstance() + AriaManager.getInstance(AriaManager.APP) .setCmd(CommonUtil.createDownloadCmd(targetName, taskEntity, CmdFactory.TASK_CANCEL)) .exe(); } @@ -169,7 +177,7 @@ public class AMTarget { * 是否在下载 */ public boolean isDownloading() { - return DownloadManager.getInstance().getTaskQueue().getTask(entity).isDownloading(); + return AriaManager.getInstance(AriaManager.APP).getTaskQueue().getTask(entity).isDownloading(); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/DownloadTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/DownloadTaskEntity.java index 02517f71..9d15475e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/DownloadTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/DownloadTaskEntity.java @@ -1,3 +1,18 @@ +/* + * 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; import java.util.HashMap; diff --git a/Aria/src/main/java/com/arialyy/aria/core/receiver/IReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/IReceiver.java similarity index 78% rename from Aria/src/main/java/com/arialyy/aria/core/receiver/IReceiver.java rename to Aria/src/main/java/com/arialyy/aria/core/IReceiver.java index bf25c280..6aebd8c4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/receiver/IReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/IReceiver.java @@ -13,12 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.receiver; +package com.arialyy.aria.core; /** * Created by Aria.Lao on 2017/2/6. */ +interface IReceiver { + /** + * Receiver 销毁 + */ + public void destroy(); -public interface IReceiver { - + /** + * 移除事件回调 + */ + public void removeSchedulerListener(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/RequestEnum.java b/Aria/src/main/java/com/arialyy/aria/core/RequestEnum.java index 1919a949..4d3766d5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/RequestEnum.java +++ b/Aria/src/main/java/com/arialyy/aria/core/RequestEnum.java @@ -1,9 +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; /** * Created by Aria.Lao on 2017/1/23. + * url请求方式,目前支持GET、POST */ - public enum RequestEnum { GET("GET"), POST("POST"); diff --git a/Aria/src/main/java/com/arialyy/aria/core/receiver/UploadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/UploadReceiver.java similarity index 82% rename from Aria/src/main/java/com/arialyy/aria/core/receiver/UploadReceiver.java rename to Aria/src/main/java/com/arialyy/aria/core/UploadReceiver.java index cc3329a7..51eff28d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/receiver/UploadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/UploadReceiver.java @@ -13,12 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.receiver; +package com.arialyy.aria.core; /** * Created by Aria.Lao on 2017/2/6. + * 上传功能接收器 */ - public class UploadReceiver implements IReceiver { + @Override public void destroy() { + + } + + @Override public void removeSchedulerListener() { + + } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java b/Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java new file mode 100644 index 00000000..f604c93f --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java @@ -0,0 +1,111 @@ +/* + * 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; + +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Message; +import android.util.Log; +import android.widget.PopupWindow; +import com.arialyy.aria.util.CommonUtil; +import java.lang.reflect.Field; + +/** + * Created by Aria.Lao on 2017/2/7. + * 为组件添加生命周期 + */ +final class WidgetLiftManager { + private final String TAG = "WidgetLiftManager"; + + /** + * 处理悬浮框取消或dismiss事件 + */ + void handlePopupWindowLift(PopupWindow popupWindow) { + try { + Field dismissField = CommonUtil.getField(popupWindow.getClass(), "mOnDismissListener"); + PopupWindow.OnDismissListener listener = + (PopupWindow.OnDismissListener) dismissField.get(popupWindow); + if (listener != null) { + Log.e(TAG, "你已经对PopupWindow设置了Dismiss事件。为了防止内存泄露," + + "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件"); + } else { + popupWindow.setOnDismissListener(createPopupWindowListener(popupWindow)); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + /** + * 创建popupWindow dismiss事件 + */ + private PopupWindow.OnDismissListener createPopupWindowListener(final PopupWindow popupWindow) { + return new PopupWindow.OnDismissListener() { + @Override public void onDismiss() { + AriaManager.getInstance(AriaManager.APP).destroySchedulerListener(popupWindow); + } + }; + } + + /** + * 处理对话框取消或dismiss + */ + void handleDialogLift(Dialog dialog) { + try { + Field dismissField = CommonUtil.getField(dialog.getClass(), "mDismissMessage"); + Message dismissMsg = (Message) dismissField.get(dialog); + //如果Dialog已经设置Dismiss事件,则查找cancel事件 + if (dismissMsg != null) { + Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage"); + Message cancelMsg = (Message) cancelField.get(dialog); + if (cancelMsg != null) { + Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露," + + "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件"); + } else { + dialog.setOnCancelListener(createCancelListener()); + } + } else { + dialog.setOnDismissListener(createDismissListener()); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + /** + * 创建Dialog取消事件 + */ + private Dialog.OnCancelListener createCancelListener() { + return new Dialog.OnCancelListener() { + + @Override public void onCancel(DialogInterface dialog) { + AriaManager.getInstance(AriaManager.APP).destroySchedulerListener(dialog); + } + }; + } + + /** + * 创建Dialog dismiss取消事件 + */ + private Dialog.OnDismissListener createDismissListener() { + return new Dialog.OnDismissListener() { + + @Override public void onDismiss(DialogInterface dialog) { + AriaManager.getInstance(AriaManager.APP).destroySchedulerListener(dialog); + } + }; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/download/IDownloadCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/download/IDownloadCmd.java index f9bb1bd7..ea1909a6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/download/IDownloadCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/download/IDownloadCmd.java @@ -16,12 +16,11 @@ package com.arialyy.aria.core.command.download; -import com.arialyy.aria.core.DownloadManager; +import com.arialyy.aria.core.AriaManager; 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; -import com.arialyy.aria.core.DownloadEntity; /** * Created by lyy on 2016/8/22. @@ -50,7 +49,7 @@ public abstract class IDownloadCmd { mTargetName = targetName; mEntity = entity; TAG = CommonUtil.getClassName(this); - mQueue = DownloadManager.getInstance().getTaskQueue(); + mQueue = AriaManager.getInstance(AriaManager.APP).getTaskQueue(); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/receiver/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/receiver/DownloadReceiver.java deleted file mode 100644 index 5ba5e251..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/receiver/DownloadReceiver.java +++ /dev/null @@ -1,77 +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.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; - -/** - * Created by lyy on 2016/12/5. - * AM 接收器 - */ -public class DownloadReceiver { - public String targetName; - public OnSchedulerListener listener; - - /** - * {@link #load(String)},请使用该方法 - */ - @Deprecated public AMTarget load(DownloadEntity entity) { - return new AMTarget(entity, targetName); - } - - /** - * 读取下载链接 - */ - public AMTarget load(@NonNull String downloadUrl) { - CheckUtil.checkDownloadUrl(downloadUrl); - DownloadEntity entity = - DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl); - if (entity == null) { - entity = new DownloadEntity(); - } - entity.setDownloadUrl(downloadUrl); - return new AMTarget(entity, targetName); - } - - /** - * 添加调度器回调 - */ - public DownloadReceiver addSchedulerListener(OnSchedulerListener listener) { - this.listener = listener; - DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener); - return this; - } - - /** - * 移除回调 - */ - public DownloadReceiver removeSchedulerListener() { - if (listener != null) { - DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener); - } - return this; - } - - public void destroy() { - targetName = null; - listener = null; - } -} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java index 25e9385c..3a11b779 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java @@ -18,9 +18,8 @@ package com.arialyy.aria.core.scheduler; import android.os.CountDownTimer; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.arialyy.aria.core.DownloadManager; +import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.queue.ITaskQueue; import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.task.Task; @@ -75,11 +74,10 @@ public class DownloadSchedulers implements IDownloadSchedulers { * 下载器任务监听 */ Map mSchedulerListeners = new ConcurrentHashMap<>(); - DownloadManager mManager = DownloadManager.getInstance(); ITaskQueue mQueue; private DownloadSchedulers() { - mQueue = mManager.getTaskQueue(); + mQueue = AriaManager.getInstance(AriaManager.APP).getTaskQueue(); } public static DownloadSchedulers getInstance() { diff --git a/Aria/src/main/java/com/arialyy/aria/util/Configuration.java b/Aria/src/main/java/com/arialyy/aria/util/Configuration.java index de3703d7..3c2ae6f4 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/Configuration.java +++ b/Aria/src/main/java/com/arialyy/aria/util/Configuration.java @@ -16,7 +16,7 @@ package com.arialyy.aria.util; import android.util.Log; -import com.arialyy.aria.core.DownloadManager; +import com.arialyy.aria.core.AriaManager; import java.io.File; import java.io.IOException; import java.util.Map; @@ -67,7 +67,7 @@ public class Configuration { } private Configuration() { - mConfigFile = new File(DownloadManager.APP.getFilesDir().getPath() + CONFIG_FILE); + mConfigFile = new File(AriaManager.APP.getFilesDir().getPath() + CONFIG_FILE); try { if (!mConfigFile.exists()) { mConfigFile.getParentFile().mkdirs(); diff --git a/Aria/src/main/java/com/arialyy/aria/util/SSLContextUtil.java b/Aria/src/main/java/com/arialyy/aria/util/SSLContextUtil.java index af40e0de..b93328f8 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/SSLContextUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/SSLContextUtil.java @@ -16,10 +16,7 @@ package com.arialyy.aria.util; import android.text.TextUtils; -import com.arialyy.aria.core.DownloadManager; -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; +import com.arialyy.aria.core.AriaManager; import java.io.IOException; import java.io.InputStream; import java.security.KeyManagementException; @@ -42,8 +39,8 @@ import javax.net.ssl.X509TrustManager; /** * Created by Aria.Lao on 2017/1/11. + * SSL证书工具 */ - public class SSLContextUtil { /** @@ -61,7 +58,7 @@ public class SSLContextUtil { CertificateFactory cf = null; try { cf = CertificateFactory.getInstance("X.509"); - InputStream caInput = DownloadManager.APP.getAssets().open(caPath); + InputStream caInput = AriaManager.APP.getAssets().open(caPath); Certificate ca; ca = cf.generateCertificate(caInput); System.out.println("ca=" + ((X509Certificate) ca).getSubjectDN()); diff --git a/app/src/main/java/com/arialyy/simple/base/BaseApplication.java b/app/src/main/java/com/arialyy/simple/base/BaseApplication.java index 39f4aea0..187716cf 100644 --- a/app/src/main/java/com/arialyy/simple/base/BaseApplication.java +++ b/app/src/main/java/com/arialyy/simple/base/BaseApplication.java @@ -18,7 +18,6 @@ package com.arialyy.simple.base; import android.app.Application; -import com.arialyy.aria.core.DownloadManager; import com.arialyy.frame.core.AbsFrame; /** @@ -28,6 +27,5 @@ public class BaseApplication extends Application { @Override public void onCreate() { super.onCreate(); AbsFrame.init(this); - //DownloadManager.init(this); } } \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java b/app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java index be9d1e87..6f3ac0d5 100644 --- a/app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java +++ b/app/src/main/java/com/arialyy/simple/dialog_task/DownloadDialog.java @@ -7,7 +7,7 @@ import android.widget.Button; import android.widget.TextView; import butterknife.Bind; import butterknife.OnClick; -import com.arialyy.aria.core.AMTarget; +import com.arialyy.aria.core.DownloadTarget; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.task.Task; @@ -40,13 +40,13 @@ public class DownloadDialog extends AbsDialog { } private void init() { - if (Aria.get(this).taskExists(DOWNLOAD_URL)) { - AMTarget target = Aria.download(this).load(DOWNLOAD_URL); + if (Aria.download(this).taskExists(DOWNLOAD_URL)) { + DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); mPb.setProgress(p); } Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback()); - DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL); + DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL); if (entity != null) { mSize.setText(CommonUtil.formatFileSize(entity.getFileSize())); int state = entity.getState(); diff --git a/app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java b/app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java index 44bf2faa..a97e03a0 100644 --- a/app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java +++ b/app/src/main/java/com/arialyy/simple/fragment_task/DownloadFragment.java @@ -7,7 +7,7 @@ import android.widget.Button; import android.widget.TextView; import butterknife.Bind; import butterknife.OnClick; -import com.arialyy.aria.core.AMTarget; +import com.arialyy.aria.core.DownloadTarget; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.task.Task; @@ -32,12 +32,12 @@ public class DownloadFragment extends AbsFragment { "http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk"; @Override protected void init(Bundle savedInstanceState) { - if (Aria.get(this).taskExists(DOWNLOAD_URL)) { - AMTarget target = Aria.download(this).load(DOWNLOAD_URL); + if (Aria.download(this).taskExists(DOWNLOAD_URL)) { + DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); mPb.setProgress(p); } - DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL); + DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL); if (entity != null) { mSize.setText(CommonUtil.formatFileSize(entity.getFileSize())); int state = entity.getState(); diff --git a/app/src/main/java/com/arialyy/simple/module/DownloadModule.java b/app/src/main/java/com/arialyy/simple/module/DownloadModule.java index b9ac5582..fad25862 100644 --- a/app/src/main/java/com/arialyy/simple/module/DownloadModule.java +++ b/app/src/main/java/com/arialyy/simple/module/DownloadModule.java @@ -86,7 +86,7 @@ public class DownloadModule extends BaseModule { String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url); List list = new ArrayList<>(); for (String url : urls) { - DownloadEntity entity = Aria.get(getContext()).getDownloadEntity(url); + DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(url); if (entity == null) { entity = createDownloadEntity(url); } diff --git a/app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java b/app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java index 74402096..30b98b98 100644 --- a/app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/multi_task/DownloadActivity.java @@ -25,7 +25,7 @@ public class DownloadActivity extends BaseActivity { @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); - mAdapter = new DownloadAdapter(this, Aria.get(this).getDownloadList()); + mAdapter = new DownloadAdapter(this, Aria.download(this).getDownloadList()); mList.setLayoutManager(new LinearLayoutManager(this)); mList.setAdapter(mAdapter); } diff --git a/app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java b/app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java index d838e31c..4b7f6aae 100644 --- a/app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/multi_task/MultiTaskActivity.java @@ -62,7 +62,7 @@ public class MultiTaskActivity extends BaseActivity { dialog.show(getSupportFragmentManager(), "download_num"); break; case R.id.stop_all: - Aria.get(this).stopAllTask(); + Aria.download(this).stopAllTask(); break; case R.id.turn: startActivity(new Intent(this, DownloadActivity.class)); diff --git a/app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java b/app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java index 926a8dfe..171c52ab 100644 --- a/app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java +++ b/app/src/main/java/com/arialyy/simple/pop_task/DownloadPopupWindow.java @@ -9,7 +9,7 @@ import android.widget.Button; import android.widget.TextView; import butterknife.Bind; import butterknife.OnClick; -import com.arialyy.aria.core.AMTarget; +import com.arialyy.aria.core.DownloadTarget; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.task.Task; @@ -42,13 +42,13 @@ public class DownloadPopupWindow extends AbsPopupWindow { } private void initWidget() { - if (Aria.get(this).taskExists(DOWNLOAD_URL)) { - AMTarget target = Aria.download(this).load(DOWNLOAD_URL); + if (Aria.download(this).taskExists(DOWNLOAD_URL)) { + DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); mPb.setProgress(p); } Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback()); - DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL); + DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL); if (entity != null) { mSize.setText(CommonUtil.formatFileSize(entity.getFileSize())); int state = entity.getState(); diff --git a/app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java index 8915bb54..b039d3a3 100644 --- a/app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/single_task/SingleTaskActivity.java @@ -30,7 +30,7 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import butterknife.Bind; -import com.arialyy.aria.core.AMTarget; +import com.arialyy.aria.core.DownloadTarget; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.DownloadEntity; import com.arialyy.aria.core.task.Task; @@ -161,8 +161,8 @@ public class SingleTaskActivity extends BaseActivity { } private void init() { - if (Aria.get(this).taskExists(DOWNLOAD_URL)) { - AMTarget target = Aria.download(this).load(DOWNLOAD_URL); + if (Aria.download(this).taskExists(DOWNLOAD_URL)) { + DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL); int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize()); mPb.setProgress(p); }