laoyuyu 5 years ago
parent fdb607e10f
commit 062f124cae
  1. 308
      Aria/src/main/java/com/arialyy/aria/core/Aria.java
  2. 25
      Aria/src/main/java/com/arialyy/aria/core/command/CommandManager.java
  3. 14
      Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java
  4. 8
      Aria/src/main/java/com/arialyy/aria/core/common/RecordHandler.java
  5. 2
      Aria/src/main/java/com/arialyy/aria/core/common/RecordWrapper.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java
  7. 10
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  8. 2
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java
  10. 10
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java
  11. 54
      Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java
  12. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java
  13. 48
      Aria/src/main/java/com/arialyy/aria/exception/ParamException.java
  14. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  15. 79
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  16. 35
      Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java
  17. 2
      app/src/main/assets/aria_config.xml
  18. 488
      app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java
  19. 2
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  20. 2
      app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java
  21. 6
      app/src/main/java/com/arialyy/simple/core/download/multi_download/DownloadAdapter.java
  22. 10
      app/src/main/java/com/arialyy/simple/core/download/multi_download/MultiTaskActivity.java
  23. 160
      app/src/main/java/com/arialyy/simple/core/test/TestMutilTaskSysDownload.java
  24. 35
      app/src/main/res/values/strings.xml
  25. 52
      gradle.properties

@ -1,154 +1,154 @@
/*
* 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.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.app.Dialog;
import android.app.Service;
import android.content.Context;
import android.os.Build;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.widget.PopupWindow;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.upload.UploadReceiver;
import com.arialyy.aria.util.ALog;
/**
* Created by lyy on 2016/12/1.
*
* @see <a href="https://github.com/AriaLyy/Aria">Aria</a>
* @see <a href="https://aria.laoyuyu.me/aria_doc/">Aria doc</a>
* Aria启动管理全局任务
* <pre>
* <code>
* //下载
* Aria.download(this)
* .load(URL) //下载地址,必填
* //文件保存路径,必填
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
* .start();
* </code>
* <code>
* //上传
* Aria.upload(this)
* .load(filePath) //文件路径,必填
* .setTempUrl(uploadUrl) //上传路径,必填
* .setAttachment(fileKey) //服务器读取文件的key,必填
* .start();
* </code>
* </pre>
*
* 如果你需要在ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog
* 之外的java中使用Aria那么你应该在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化
* 然后才能使用{@link #download(Object)}{@link #upload(Object)}
*
* <pre>
* <code>
* Aria.init(this);
*
* Aria.download(this)
* .load(URL) //下载地址,必填
* //文件保存路径,必填
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
* .start();
*
* </code>
*
* </pre>
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {
private Aria() {
}
/**
* 下载在当前类中调用Aria方法参数需要使用this否则将
* 如果不是ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog对象那么你
* 需要在对象中初始化下载前在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化
*
* @param obj 观察者对象为本类对象使用{@code this}
*/
public static DownloadReceiver download(Object obj) {
if (AriaManager.getInstance() != null){
return AriaManager.getInstance().download(obj);
}
return get(convertContext(obj)).download(obj);
}
/**
* 上传
* 如果不是ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog对象那么你
* 需要在对象中初始化下载前在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化
*
* @param obj 观察者对象为本类对象使用{@code this}
*/
public static UploadReceiver upload(Object obj) {
if (AriaManager.getInstance() != null){
return AriaManager.getInstance().upload(obj);
}
return get(convertContext(obj)).upload(obj);
}
/**
* 处理通用事件
*/
public static AriaManager get(Context context) {
if (context == null) {
throw new NullPointerException("context 无效,在非【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】,"
+ "请参考【https://aria.laoyuyu.me/aria_doc/start/any_java.html】,参数请使用 download(this) 或 upload(this);"
+ "不要使用 download(getContext()) 或 upload(getContext())");
}
return AriaManager.getInstance(context);
}
/**
* 初始化Aria如果你需要在ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog
* 之外的java中使用Aria那么你应该在Application或Activity初始化的时候调用本方法对Aria进行初始化
* 只需要初始化一次就可以
* {@link #download(Object)}{@link #upload(Object)}
*/
public static AriaManager init(Context context) {
return AriaManager.getInstance(context);
}
private static Context convertContext(Object obj) {
if (obj instanceof Application) {
return (Application) obj;
} else if (obj instanceof Service) {
return (Service) obj;
} else if (obj instanceof Activity) {
return (Activity) obj;
} else if (obj instanceof DialogFragment) {
return ((DialogFragment) obj).getContext();
} else if (obj instanceof android.app.DialogFragment) {
return ((android.app.DialogFragment) obj).getActivity();
} else if (obj instanceof android.support.v4.app.Fragment) {
return ((Fragment) obj).getContext();
} else if (obj instanceof android.app.Fragment) {
return ((android.app.Fragment) obj).getActivity();
} else if (obj instanceof Dialog) {
return ((Dialog) obj).getContext();
} else if (obj instanceof PopupWindow) {
return ((PopupWindow) obj).getContentView().getContext();
}
ALog.e("Aria", "请使用download(this)或upload(this)");
return null;
}
}
/*
* 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.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.app.Dialog;
import android.app.Service;
import android.content.Context;
import android.os.Build;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.widget.PopupWindow;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.upload.UploadReceiver;
import com.arialyy.aria.util.ALog;
/**
* Created by lyy on 2016/12/1.
*
* @see <a href="https://github.com/AriaLyy/Aria">Aria</a>
* @see <a href="https://aria.laoyuyu.me/aria_doc/">Aria doc</a>
* Aria启动管理全局任务
* <pre>
* <code>
* //下载
* Aria.download(this)
* .load(URL) //下载地址,必填
* //文件保存路径,必填
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
* .start();
* </code>
* <code>
* //上传
* Aria.upload(this)
* .load(filePath) //文件路径,必填
* .setTempUrl(uploadUrl) //上传路径,必填
* .setAttachment(fileKey) //服务器读取文件的key,必填
* .start();
* </code>
* </pre>
*
* 如果你需要在ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog
* 之外的java中使用Aria那么你应该在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化
* 然后才能使用{@link #download(Object)}{@link #upload(Object)}
*
* <pre>
* <code>
* Aria.init(this);
*
* Aria.download(this)
* .load(URL) //下载地址,必填
* //文件保存路径,必填
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
* .start();
*
* </code>
*
* </pre>
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {
private Aria() {
}
/**
* 下载在当前类中调用Aria方法参数需要使用this否则将
* 如果不是ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog对象那么你
* 需要在对象中初始化下载前在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化
*
* @param obj 观察者对象为本类对象使用{@code this}
*/
public static DownloadReceiver download(Object obj) {
if (AriaManager.getInstance() != null){
return AriaManager.getInstance().download(obj);
}
return get(convertContext(obj)).download(obj);
}
/**
* 上传
* 如果不是ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog对象那么你
* 需要在对象中初始化下载前在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化
*
* @param obj 观察者对象为本类对象使用{@code this}
*/
public static UploadReceiver upload(Object obj) {
if (AriaManager.getInstance() != null){
return AriaManager.getInstance().upload(obj);
}
return get(convertContext(obj)).upload(obj);
}
/**
* 处理通用事件
*/
public static AriaManager get(Context context) {
if (context == null) {
throw new NullPointerException("context 无效,在非【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】,"
+ "请参考【https://aria.laoyuyu.me/aria_doc/start/any_java.html】,参数请使用 download(this) 或 upload(this);"
+ "不要使用 download(getContext()) 或 upload(getContext())");
}
return AriaManager.getInstance(context);
}
/**
* 初始化Aria如果你需要在ActivityServiceApplicationDialogFragmentFragmentPopupWindowDialog
* 之外的java中使用Aria那么你应该在Application或Activity初始化的时候调用本方法对Aria进行初始化
* 只需要初始化一次就可以
* {@link #download(Object)}{@link #upload(Object)}
*/
public static AriaManager init(Context context) {
return AriaManager.getInstance(context);
}
private static Context convertContext(Object obj) {
if (obj instanceof Application) {
return (Application) obj;
} else if (obj instanceof Service) {
return (Service) obj;
} else if (obj instanceof Activity) {
return (Activity) obj;
} else if (obj instanceof DialogFragment) {
return ((DialogFragment) obj).getContext();
} else if (obj instanceof android.app.DialogFragment) {
return ((android.app.DialogFragment) obj).getActivity();
} else if (obj instanceof android.support.v4.app.Fragment) {
return ((Fragment) obj).getContext();
} else if (obj instanceof android.app.Fragment) {
return ((android.app.Fragment) obj).getActivity();
} else if (obj instanceof Dialog) {
return ((Dialog) obj).getContext();
} else if (obj instanceof PopupWindow) {
return ((PopupWindow) obj).getContentView().getContext();
}
ALog.e("Aria", "请使用download(this)或upload(this)");
return null;
}
}

@ -43,7 +43,7 @@ public class CommandManager {
@Event
public void add(AddCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
if (CommonUtil.isFastDoubleClick()) {
return;
}
cmd.executeCmd();
@ -51,7 +51,7 @@ public class CommandManager {
@Event
public void start(StartCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
if (CommonUtil.isFastDoubleClick()) {
return;
}
cmd.executeCmd();
@ -59,23 +59,17 @@ public class CommandManager {
@Event
public void stop(StopCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
return;
}
cmd.executeCmd();
}
@Event
public void cancel(CancelCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
return;
}
cmd.executeCmd();
}
@Event
public void stopAll(StopAllCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
if (CommonUtil.isFastDoubleClick()) {
return;
}
cmd.executeCmd();
@ -83,7 +77,7 @@ public class CommandManager {
@Event
public void cancelAll(CancelAllCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
if (CommonUtil.isFastDoubleClick()) {
return;
}
cmd.executeCmd();
@ -91,7 +85,7 @@ public class CommandManager {
@Event
public void reStart(ReStartCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
if (CommonUtil.isFastDoubleClick()) {
return;
}
cmd.executeCmd();
@ -99,7 +93,7 @@ public class CommandManager {
@Event
public void highestPriority(HighestPriorityCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
if (CommonUtil.isFastDoubleClick()) {
return;
}
cmd.executeCmd();
@ -107,7 +101,7 @@ public class CommandManager {
@Event
public void resumeAll(ResumeAllCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
if (CommonUtil.isFastDoubleClick()) {
return;
}
cmd.executeCmd();
@ -115,7 +109,7 @@ public class CommandManager {
@Event
public void subStart(DGSubStartCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
if (CommonUtil.isFastDoubleClick()) {
return;
}
cmd.executeCmd();
@ -123,9 +117,6 @@ public class CommandManager {
@Event
public void subStop(DGSubStopCmd cmd) {
if (CommonUtil.isFastDoubleClick()){
return;
}
cmd.executeCmd();
}
}

@ -16,8 +16,6 @@
package com.arialyy.aria.core.common;
import android.os.Handler;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
@ -26,12 +24,10 @@ import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
import com.arialyy.aria.util.RecordUtil;
import java.lang.ref.WeakReference;
public abstract class BaseListener<ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>,
@ -156,16 +152,6 @@ public abstract class BaseListener<ENTITY extends AbsEntity, TASK_WRAPPER extend
mEntity.setCurrentProgress(mEntity.getFileSize());
mEntity.setPercent(100);
handleSpeed(0);
ALog.i(TAG, String.format("任务【%s】完成,将删除任务任务记录", mEntity.getKey()));
if (mEntity instanceof DownloadGroupEntity) {
RecordUtil.delGroupTaskRecord((DownloadGroupEntity) mEntity, false, false);
} else if (mEntity instanceof DownloadEntity) {
RecordUtil.delTaskRecord(((DownloadEntity) mEntity).getFilePath(),
RecordHandler.TYPE_DOWNLOAD, false, false);
} else if (mEntity instanceof UploadEntity) {
RecordUtil.delTaskRecord(((UploadEntity) mEntity).getFilePath(), RecordHandler.TYPE_UPLOAD,
false, false);
}
}
/**

@ -152,7 +152,7 @@ public class RecordHandler {
ThreadRecord tr = mTaskRecord.threadRecords.get(0);
tr.startLocation = 0;
tr.endLocation = mEntity.getFileSize();
tr.key = mTaskRecord.filePath;
tr.taskKey = mTaskRecord.filePath;
tr.blockLen = tr.endLocation;
tr.isComplete = false;
}
@ -164,7 +164,7 @@ public class RecordHandler {
File file = new File(mTaskRecord.filePath);
if (!file.exists()) {
ALog.w(TAG, String.format("文件【%s】不存在,重新分配线程区间", mTaskRecord.filePath));
DbEntity.deleteData(ThreadRecord.class, "key=?", mTaskRecord.filePath);
DbEntity.deleteData(ThreadRecord.class, "taskKey=?", mTaskRecord.filePath);
initRecord(false);
}
}
@ -290,7 +290,7 @@ public class RecordHandler {
File tempFile = new File(getFilePath());
for (int i = 0; i < threadNum; i++) {
ThreadRecord tRecord = new ThreadRecord();
tRecord.key = mTaskRecord.filePath;
tRecord.taskKey = mTaskRecord.filePath;
Object state = pro.getProperty(tempFile.getName() + STATE + i);
Object record = pro.getProperty(tempFile.getName() + RECORD + i);
if (state != null && Integer.parseInt(String.valueOf(state)) == 1) {
@ -329,7 +329,7 @@ public class RecordHandler {
long startL = i * blockSize, endL = (i + 1) * blockSize;
ThreadRecord tr;
tr = new ThreadRecord();
tr.key = mTaskRecord.filePath;
tr.taskKey = mTaskRecord.filePath;
tr.threadId = i;
tr.startLocation = startL;
tr.isComplete = false;

@ -32,7 +32,7 @@ public class RecordWrapper extends AbsDbWrapper {
@One
public TaskRecord taskRecord;
@Many(parentColumn = "filePath", entityColumn = "key")
@Many(parentColumn = "filePath", entityColumn = "taskKey")
public List<ThreadRecord> threadRecords;
@Override protected void handleConvert() {

@ -26,7 +26,7 @@ public class ThreadRecord extends DbEntity {
/**
* 任务的文件路径不是当前线程记录的的分块文件路径
*/
public String key;
public String taskKey;
/**
* 开始位置

@ -22,9 +22,9 @@ import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.common.http.HttpTaskConfig;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.common.http.HttpTaskConfig;
import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.BaseException;
@ -54,7 +54,7 @@ import java.util.UUID;
* 下载文件信息获取
*/
public class HttpFileInfoThread implements Runnable {
private final String TAG = "HttpFileInfoThread";
private static final String TAG = "HttpFileInfoThread";
private DownloadEntity mEntity;
private DTaskWrapper mTaskWrapper;
private int mConnectTimeOut;
@ -119,7 +119,7 @@ public class HttpFileInfoThread implements Runnable {
}
long len = lenAdapter.handleFileLen(conn.getHeaderFields());
if (!CommonUtil.checkSDMemorySpace(mEntity.getDownloadPath(), len)) {
if (!CommonUtil.checkSDMemorySpace(mEntity.getFilePath(), len)) {
failDownload(new TaskException(TAG,
String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getDownloadPath(),
mEntity.getUrl())), false);
@ -334,6 +334,10 @@ public class HttpFileInfoThread implements Runnable {
private static class FileLenAdapter implements IHttpFileLenAdapter {
@Override public long handleFileLen(Map<String, List<String>> headers) {
if (headers == null || headers.isEmpty()) {
ALog.e(TAG, "header为空,获取文件长度失败");
return -1;
}
List<String> sLength = headers.get("Content-Length");
if (sLength == null || sLength.isEmpty()) {
return -1;

@ -53,7 +53,7 @@ import java.util.regex.Pattern;
* https://blog.csdn.net/Guofengpu/article/details/54922865
*/
final class M3U8InfoThread implements Runnable {
private final String TAG = "M3U8FileInfoThread";
private final String TAG = "M3U8InfoThread";
private DownloadEntity mEntity;
private DTaskWrapper mTaskWrapper;
private int mConnectTimeOut;

@ -127,7 +127,7 @@ public class M3U8LiveLoader extends BaseM3U8Loader {
*/
private M3U8ThreadTask createThreadTask(String cacheDir, int indexId, String tsUrl) {
ThreadRecord record = new ThreadRecord();
record.key = mRecord.filePath;
record.taskKey = mRecord.filePath;
record.isComplete = false;
record.tsUrl = tsUrl;
record.threadType = TaskRecord.TYPE_M3U8_LIVE;

@ -95,10 +95,14 @@ public class M3U8LiveUtil implements IUtil {
if (mInfoThread != null) {
mInfoThread.setStop(true);
closeTimer();
if (mLoader.mergeFile()) {
mListener.onComplete();
if (mWrapper.asM3U8().isMergeFile()) {
if (mLoader.mergeFile()) {
mListener.onComplete();
} else {
mListener.onFail(false, new M3U8Exception(TAG, "合并文件失败"));
}
} else {
mListener.onFail(false, new M3U8Exception(TAG, "合并文件失败"));
mListener.onComplete();
}
}
}

@ -1,27 +1,27 @@
/*
* 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.upload;
import com.arialyy.aria.core.inf.AbsTarget;
/**
* Created by AriaL on 2017/6/29.
* 普通上传任务接收器
*/
abstract class AbsUploadTarget<TARGET extends AbsUploadTarget> extends AbsTarget<TARGET> {
}
/*
* 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.upload;
import com.arialyy.aria.core.inf.AbsTarget;
/**
* Created by AriaL on 2017/6/29.
* 普通上传任务接收器
*/
abstract class AbsUploadTarget<TARGET extends AbsUploadTarget> extends AbsTarget<TARGET> {
}

@ -144,7 +144,7 @@ class FtpFileInfoThread extends AbsFtpInfoThread<UploadEntity, UTaskWrapper> {
ThreadRecord threadRecord;
if (record.threadRecords == null || record.threadRecords.isEmpty()) {
threadRecord = new ThreadRecord();
threadRecord.key = record.filePath;
threadRecord.taskKey = record.filePath;
} else {
threadRecord = record.threadRecords.get(0);
}

@ -1,24 +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.exception;
public class ParamException extends RuntimeException {
private static final String ARIA_NET_EXCEPTION = "Aria Params Exception:";
public ParamException(String message) {
super(String.format("%s%s", ARIA_NET_EXCEPTION, message));
}
}
/*
* 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.exception;
public class ParamException extends RuntimeException {
private static final String ARIA_NET_EXCEPTION = "Aria Params Exception:";
public ParamException(String message) {
super(String.format("%s%s", ARIA_NET_EXCEPTION, message));
}
}

@ -38,7 +38,7 @@ class DBConfig {
static boolean DEBUG = false;
static Map<String, Class> mapping = new LinkedHashMap<>();
static String DB_NAME;
static int VERSION = 51;
static int VERSION = 52;
/**
* 是否将数据库保存在Sd卡{@code true}

@ -100,6 +100,8 @@ final class SqlHelper extends SQLiteOpenHelper {
handle360AriaUpdate(db);
} else if (oldVersion < 51) {
handle365Update(db);
} else if (oldVersion < 52) {
handle366Update(db);
} else {
handleDbUpdate(db, null, null);
}
@ -239,23 +241,43 @@ final class SqlHelper extends SQLiteOpenHelper {
*/
private void delRepeatThreadRecord(SQLiteDatabase db) {
String repeatSql =
"DELETE FROM ThreadRecord WHERE (key, threadId, endLocation) "
+ "IN (SELECT key, threadId, endLocation FROM ThreadRecord GROUP BY key, threadId, endLocation "
"DELETE FROM ThreadRecord WHERE (taskKey, threadId, endLocation) "
+ "IN (SELECT taskKey, threadId, endLocation FROM ThreadRecord GROUP BY taskKey, threadId, endLocation "
+ "HAVING COUNT(*) > 1) AND rowid "
+ "NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY key, threadId, endLocation "
+ "NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY taskKey, threadId, endLocation "
+ "HAVING COUNT(*)> 1)";
ALog.d(TAG, repeatSql);
db.execSQL(repeatSql);
}
/**
* 处理366版本以下的升级
*/
private void handle366Update(SQLiteDatabase db) {
Map<String, Map<String, String>> modifyMap = new HashMap<>();
// 处理ThreadRecord的key字段名修改
Map<String, String> threadRecordModify = new HashMap<>();
threadRecordModify.put("key", "taskKey");
modifyMap.put("ThreadRecord", threadRecordModify);
// 执行升级操作
handleDbUpdate(db, modifyMap, null);
}
/**
* 处理365版本以下的升级
*/
private void handle365Update(SQLiteDatabase db) {
db.execSQL("UPDATE ThreadRecord SET threadId=0 WHERE threadId=-1");
Map<String, Map<String, String>> modifyMap = new HashMap<>();
// 处理ThreadRecord的key字段名修改
Map<String, String> threadRecordModify = new HashMap<>();
threadRecordModify.put("key", "taskKey");
modifyMap.put("ThreadRecord", threadRecordModify);
// 执行升级操作
handleDbUpdate(db, null, null);
handleDbUpdate(db, modifyMap, null);
delRepeatThreadRecord(db);
}
@ -271,19 +293,25 @@ final class SqlHelper extends SQLiteOpenHelper {
}
}
Map<String, Map<String, String>> columnMap = new HashMap<>();
Map<String, Map<String, String>> modifyMap = new HashMap<>();
// 处理DownloadEntity、DownloadGroupEntity的 groupName字段名的修改
Map<String, String> groupNameModify = new HashMap<>();
groupNameModify.put("groupName", "groupHash");
columnMap.put("DownloadEntity", groupNameModify);
columnMap.put("DownloadGroupEntity", groupNameModify);
Map<String, String> entityModify = new HashMap<>();
entityModify.put("groupName", "groupHash");
modifyMap.put("DownloadEntity", entityModify);
modifyMap.put("DownloadGroupEntity", entityModify);
// 处理TaskRecord的dGroupName字段名的修改
Map<String, String> dGroupNameModify = new HashMap<>();
dGroupNameModify.put("dGroupName", "dGroupHash");
columnMap.put("TaskRecord", dGroupNameModify);
Map<String, String> taskRecordModify = new HashMap<>();
taskRecordModify.put("dGroupName", "dGroupHash");
modifyMap.put("TaskRecord", taskRecordModify);
// 处理ThreadRecord的key字段名修改
Map<String, String> threadRecordModify = new HashMap<>();
threadRecordModify.put("key", "taskKey");
modifyMap.put("ThreadRecord", threadRecordModify);
// 执行升级操作
handleDbUpdate(db, columnMap, null);
handleDbUpdate(db, modifyMap, null);
delRepeatThreadRecord(db);
}
@ -324,18 +352,19 @@ final class SqlHelper extends SQLiteOpenHelper {
i++;
}
Map<String, Map<String, String>> modifyColumnMap = new HashMap<>();
Map<String, String> dMap = new HashMap<>();
dMap.put("groupName", "groupHash");
// 处理数据库版本小于3的字段改变
dMap.put("downloadUrl", "url");
dMap.put("isDownloadComplete", "isComplete");
modifyColumnMap.put("DownloadEntity", dMap);
Map<String, String> dGMap = new HashMap<>();
dGMap.put("groupName", "groupHash");
modifyColumnMap.put("DownloadGroupEntity", dGMap);
Map<String, Map<String, String>> modifyMap = new HashMap<>();
Map<String, String> dEntityModifyMap = new HashMap<>();
dEntityModifyMap.put("groupName", "groupHash");
dEntityModifyMap.put("downloadUrl", "url");
dEntityModifyMap.put("isDownloadComplete", "isComplete");
modifyMap.put("DownloadEntity", dEntityModifyMap);
Map<String, String> dGEntityModifyMap = new HashMap<>();
dGEntityModifyMap.put("groupName", "groupHash");
modifyMap.put("DownloadGroupEntity", dGEntityModifyMap);
// 删除字段
Map<String, List<String>> delColumnMap = new HashMap<>();
List<String> dEntityDel = new ArrayList<>();
dEntityDel.add("taskKey");
@ -344,6 +373,6 @@ final class SqlHelper extends SQLiteOpenHelper {
dgEntityDel.add("subtask");
delColumnMap.put("DownloadGroupEntity", dgEntityDel);
handleDbUpdate(db, modifyColumnMap, delColumnMap);
handleDbUpdate(db, modifyMap, delColumnMap);
}
}

@ -83,7 +83,7 @@ public class RecordUtil {
}
}
}
DbEntity.deleteData(ThreadRecord.class, "key=?", record.taskRecord.filePath);
DbEntity.deleteData(ThreadRecord.class, "taskKey=?", record.taskRecord.filePath);
record.taskRecord.deleteData();
}
}
@ -148,15 +148,14 @@ public class RecordUtil {
*/
if (!entity.isComplete()) {
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件
String cacheDir = null;
if (!targetFile.isDirectory()) {
cacheDir = targetFile.getParent() + "/." + targetFile.getName();
}
removeTsCache(cacheDir);
removeTsCache(targetFile, record.bandWidth);
} else if (record.isBlock) { // 删除分块文件
removeBlockFile(record);
}
} else if (removeFile) { // 处理任务完成情况
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) {
removeTsCache(targetFile, record.bandWidth);
}
removeTargetFile(targetFile);
}
@ -209,16 +208,14 @@ public class RecordUtil {
*/
if (!entity.isComplete()) {
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件
String cacheDir = null;
if (!targetFile.isDirectory()) {
cacheDir = String.format("%s/.%s_%s", targetFile.getParent(), targetFile.getName(),
record.bandWidth);
}
removeTsCache(cacheDir);
removeTsCache(targetFile, record.bandWidth);
} else if (record.isBlock) { // 删除分块文件
removeBlockFile(record);
}
} else if (removeFile) { // 处理任务完成情况
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) {
removeTsCache(targetFile, record.bandWidth);
}
removeTargetFile(targetFile);
}
@ -238,7 +235,7 @@ public class RecordUtil {
private static void removeRecord(String filePath) {
ALog.i(TAG, "删除任务记录");
DbEntity.deleteData(ThreadRecord.class, "key=?", filePath);
DbEntity.deleteData(ThreadRecord.class, "taskKey=?", filePath);
DbEntity.deleteData(TaskRecord.class, "filePath=?", filePath);
}
@ -287,11 +284,17 @@ public class RecordUtil {
/**
* 删除ts文件
*/
private static void removeTsCache(String cacheDir) {
private static void removeTsCache(File targetFile, long bandWidth) {
String cacheDir = null;
if (!targetFile.isDirectory()) {
cacheDir =
String.format("%s/.%s_%s", targetFile.getParent(), targetFile.getName(), bandWidth);
}
if (!TextUtils.isEmpty(cacheDir)) {
File cacheDirF = new File(cacheDir);
if (!cacheDirF.exists()){
if (!cacheDirF.exists()) {
return;
}
File[] files = cacheDirF.listFiles();
@ -348,7 +351,7 @@ public class RecordUtil {
// 修改线程记录
if (record.threadRecords != null && !record.threadRecords.isEmpty()) {
for (ThreadRecord tr : record.threadRecords) {
tr.key = newPath;
tr.taskKey = newPath;
File blockFile = new File(String.format(RecordHandler.SUB_PATH, oldPath, tr.threadId));
if (blockFile.exists()) {
blockFile.renameTo(new File(String.format(RecordHandler.SUB_PATH, newPath, tr.threadId)));

@ -44,7 +44,7 @@
<threadNum value="3"/>
<!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="1"/>
<maxTaskNum value="3"/>
<!--设置下载失败,重试次数,默认为10-->
<reTryNum value="1"/>

@ -1,244 +1,244 @@
/*
* 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.simple.core.download;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityHighestPriorityBinding;
import com.arialyy.simple.core.download.multi_download.DownloadAdapter;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by lyy on 2017/6/2.
* 最高优先级任务Demo
*/
public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorityBinding> {
private HorizontalProgressBarWithNumber mPb;
private Button mStart;
private Button mStop;
private Button mCancel;
private TextView mSize;
private TextView mSpeed;
private RecyclerView mList;
private String mTaskName = "光明大陆";
private static final String DOWNLOAD_URL =
"https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk";
private DownloadAdapter mAdapter;
private List<AbsEntity> mData = new ArrayList<>();
private Set<String> mRecord = new HashSet<>();
@Override protected int setLayoutId() {
return R.layout.activity_highest_priority;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
mPb = findViewById(R.id.progressBar);
mStart = findViewById(R.id.start);
mStop = findViewById(R.id.stop);
mCancel = findViewById(R.id.cancel);
mSize = findViewById(R.id.size);
mSpeed = findViewById(R.id.speed);
mList = findViewById(R.id.list);
setTitle("最高优先级任务");
getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)");
initWidget();
Aria.download(this).register();
}
private void initWidget() {
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
mPb.setProgress(target.getPercent());
if (target.getTaskState() == IEntity.STATE_STOP) {
mStart.setText("恢复");
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
setBtState(true);
} else if (target.isRunning()) {
setBtState(false);
}
mSize.setText(target.getConvertFileSize());
List<DownloadEntity> temp = Aria.download(this).getTaskList();
if (temp != null && !temp.isEmpty()) {
for (DownloadEntity entity : temp) {
if (entity.getUrl().equals(DOWNLOAD_URL)) continue;
mData.add(entity);
mRecord.add(entity.getUrl());
}
}
mAdapter = new DownloadAdapter(this, mData);
mList.setLayoutManager(new LinearLayoutManager(this));
mList.setAdapter(mAdapter);
}
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_highest_priority, menu);
return super.onCreateOptionsMenu(menu);
}
@Override public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.add_task:
List<DownloadEntity> temp = getModule(DownloadModule.class).getHighestTestList();
for (DownloadEntity entity : temp) {
String url = entity.getUrl();
if (mRecord.contains(url)) {
continue;
}
mAdapter.addDownloadEntity(entity);
mRecord.add(url);
}
mAdapter.notifyDataSetChanged();
break;
case R.id.help:
String title = "最高优先级任务介绍";
String msg = " 将任务设置为最高优先级任务,最高优先级任务有以下特点:\n"
+ " 1、在下载队列中,有且只有一个最高优先级任务\n"
+ " 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成\n"
+ " 3、任务调度器不会暂停最高优先级任务\n"
+ " 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效\n"
+ " 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行\n"
+ " 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务";
showMsgDialog(title, msg);
break;
}
return true;
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
String text = ((TextView) view).getText().toString();
if (text.equals("重新开始?") || text.equals("开始")) {
Aria.download(this)
.load(DOWNLOAD_URL)
.setFilePath(Environment.getExternalStorageDirectory().getPath()
+ "/Download/"
+ mTaskName
+ ".apk")
.setHighestPriority();
} else if (text.equals("恢复")) {
Aria.download(this).load(DOWNLOAD_URL).resume();
}
break;
case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).pause();
break;
case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel();
break;
}
}
/**
* 设置start stop 按钮状态
*/
private void setBtState(boolean state) {
mStart.setEnabled(state);
mStop.setEnabled(!state);
}
@Download.onPre public void onPre(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mSize.setText(task.getConvertFileSize());
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskStart public void onTaskStart(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskResume public void onTaskResume(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("恢复");
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("开始");
mPb.setProgress(0);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskFail public void onTaskFail(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
} else {
L.d(TAG, "download fail【" + task.getKey() + "】");
}
}
@Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("重新开始");
mStart.setTextColor(getResources().getColor(android.R.color.holo_green_light));
mPb.setProgress(100);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mPb.setProgress(task.getPercent());
mSpeed.setText(task.getConvertSpeed());
}
mAdapter.setProgress(task.getDownloadEntity());
}
}
/*
* 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.simple.core.download;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityHighestPriorityBinding;
import com.arialyy.simple.core.download.multi_download.DownloadAdapter;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by lyy on 2017/6/2.
* 最高优先级任务Demo
*/
public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorityBinding> {
private HorizontalProgressBarWithNumber mPb;
private Button mStart;
private Button mStop;
private Button mCancel;
private TextView mSize;
private TextView mSpeed;
private RecyclerView mList;
private String mTaskName = "光明大陆";
private static final String DOWNLOAD_URL =
"https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk";
private DownloadAdapter mAdapter;
private List<AbsEntity> mData = new ArrayList<>();
private Set<String> mRecord = new HashSet<>();
@Override protected int setLayoutId() {
return R.layout.activity_highest_priority;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
mPb = findViewById(R.id.progressBar);
mStart = findViewById(R.id.start);
mStop = findViewById(R.id.stop);
mCancel = findViewById(R.id.cancel);
mSize = findViewById(R.id.size);
mSpeed = findViewById(R.id.speed);
mList = findViewById(R.id.list);
setTitle("最高优先级任务");
getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)");
initWidget();
Aria.download(this).register();
}
private void initWidget() {
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
mPb.setProgress(target.getPercent());
if (target.getTaskState() == IEntity.STATE_STOP) {
mStart.setText("恢复");
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
setBtState(true);
} else if (target.isRunning()) {
setBtState(false);
}
mSize.setText(target.getConvertFileSize());
List<DownloadEntity> temp = Aria.download(this).getTaskList();
if (temp != null && !temp.isEmpty()) {
for (DownloadEntity entity : temp) {
if (entity.getUrl().equals(DOWNLOAD_URL)) continue;
mData.add(entity);
mRecord.add(entity.getUrl());
}
}
mAdapter = new DownloadAdapter(this, mData);
mList.setLayoutManager(new LinearLayoutManager(this));
mList.setAdapter(mAdapter);
}
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_highest_priority, menu);
return super.onCreateOptionsMenu(menu);
}
@Override public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.add_task:
List<DownloadEntity> temp = getModule(DownloadModule.class).getHighestTestList();
for (DownloadEntity entity : temp) {
String url = entity.getUrl();
if (mRecord.contains(url)) {
continue;
}
mAdapter.addDownloadEntity(entity);
mRecord.add(url);
}
mAdapter.notifyDataSetChanged();
break;
case R.id.help:
String title = "最高优先级任务介绍";
String msg = " 将任务设置为最高优先级任务,最高优先级任务有以下特点:\n"
+ " 1、在下载队列中,有且只有一个最高优先级任务\n"
+ " 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成\n"
+ " 3、任务调度器不会暂停最高优先级任务\n"
+ " 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效\n"
+ " 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行\n"
+ " 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务";
showMsgDialog(title, msg);
break;
}
return true;
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
String text = ((TextView) view).getText().toString();
if (text.equals("重新开始?") || text.equals("开始")) {
Aria.download(this)
.load(DOWNLOAD_URL)
.setFilePath(Environment.getExternalStorageDirectory().getPath()
+ "/Download/"
+ mTaskName
+ ".apk")
.setHighestPriority();
} else if (text.equals("恢复")) {
Aria.download(this).load(DOWNLOAD_URL).resume();
}
break;
case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).pause();
break;
case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel();
break;
}
}
/**
* 设置start stop 按钮状态
*/
private void setBtState(boolean state) {
mStart.setEnabled(state);
mStop.setEnabled(!state);
}
@Download.onPre public void onPre(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mSize.setText(task.getConvertFileSize());
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskStart public void onTaskStart(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskResume public void onTaskResume(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("恢复");
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("开始");
mPb.setProgress(0);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskFail public void onTaskFail(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
} else {
L.d(TAG, "download fail【" + task.getKey() + "】");
}
}
@Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("重新开始");
mStart.setTextColor(getResources().getColor(android.R.color.holo_green_light));
mPb.setProgress(100);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mPb.setProgress(task.getPercent());
mSpeed.setText(task.getConvertSpeed());
}
mAdapter.setProgress(task.getDownloadEntity());
}
}

@ -309,9 +309,11 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
})
.setMergeHandler(new ITsMergeHandler() {
@Override public boolean merge(@Nullable M3U8KeyInfo keyInfo, List<String> tsPath) {
ALog.d(TAG, "合并TS....");
return false;
}
})
.merge(true)
//.asVod().setPeerIndex(50)
.start();
}

@ -55,7 +55,7 @@ public class VideoPlayerFragment extends BaseFragment<FragmentVideoPlayerBinding
getBinding().surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override public void surfaceCreated(SurfaceHolder holder) {
mSurfaceHolder = holder;
startNewPlayer(mPlayers.valueAt(0));
//startNewPlayer(mPlayers.valueAt(0));
}
@Override

@ -206,10 +206,10 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
//删除按钮事件
holder.cancel.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
// mData.remove(entity);
mData.remove(entity);
notifyDataSetChanged();
// cancel(entity);
stop(entity);
cancel(entity);
//stop(entity);
}
});
//if (holder instanceof GroupHolder){

@ -26,6 +26,7 @@ import android.view.View;
import com.arialyy.annotations.Download;
import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.util.ALog;
@ -71,8 +72,13 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
dialog.show(getSupportFragmentManager(), "download_num");
break;
case R.id.stop_all:
Aria.download(this).stopAllTask();
//Aria.download(this).removeAllTask(false);
List<DownloadEntity> entities = Aria.download(this).getTaskList();
for (DownloadEntity entity: entities){
Aria.download(this).load(entity.getUrl()).cancel(true);
ALog.d(TAG, "exist ==" + Aria.download(this).load(entity.getUrl()).taskExists());
}
//Aria.download(this).stopAllTask();
//Aria.download(this).removeAllTask(true);
break;
case R.id.turn:
startActivity(new Intent(this, MultiDownloadActivity.class));

@ -1,80 +1,80 @@
package com.arialyy.simple.core.test;
import android.os.Environment;
import android.view.View;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.TestActivityMultiBinding;
/**
* Created by AriaL on 2017/6/15.
*/
public class TestMutilTaskSysDownload extends BaseActivity<TestActivityMultiBinding> {
@Override protected int setLayoutId() {
return R.layout.test_activity_multi;
}
public void onClick(View view) {
String baseUrl = "http://file.bmob.cn/";
String[] urlArray = {
"M02/3B/A4/oYYBAFaOeUSAc1QiAAFTbmA7AHs052.jpg",
"M02/3B/A4/oYYBAFaOeUaAfYC-AAFD8zf9NXc879.jpg",
"M02/3B/A4/oYYBAFaOeUuAOxhnAACSdmbqSac702.jpg",
"M02/3B/A4/oYYBAFaOeU2AFAIGAAFICximvXc924.jpg",
"M02/3B/A4/oYYBAFaOeVCAPWMQAAFm2KWCq_E721.jpg",
"M02/3B/A4/oYYBAFaOeVOAbiv9AAFfCTTgr94948.jpg",
"M02/3B/A4/oYYBAFaOeVaAMR3tAAFf3yTuuCM577.jpg",
"M02/3B/A4/oYYBAFaOeVmACEWhAAEt72ecbpg468.jpg",
"M02/3B/A4/oYYBAFaOeVyAHHt4AAFg9e9bRio507.jpg",
"M02/3B/A4/oYYBAFaOeV-AClYXAAESLGY0gag424.jpg",
"M02/3B/A4/oYYBAFaOeWKAA7N0AAF3omYOJUI703.jpg",
"M02/3B/A4/oYYBAFaOeWWAD2lrAAFN7eRFxBs575.jpg",
"M02/3B/A4/oYYBAFaOeWiAdCVEAAFg4273Dus313.jpg",
"M02/3B/A4/oYYBAFaOeWyAJDm5AAF8JVoGVb0705.jpg",
"M02/3B/A4/oYYBAFaOeW-AUoA8AAGjKiHkXUo181.jpg",
"M02/3B/A4/oYYBAFaOeXKABIamAAFU7J7vraE265.jpg",
"M02/3B/A5/oYYBAFaOeXaAW09jAAFf37qdwDA457.jpg",
"M02/3B/A5/oYYBAFaOeXmAWmS7AAFtLNpWjgo967.jpg",
"M02/3B/A5/oYYBAFaOeX2AQf9cAAF2fhwS2UE145.jpg",
"M02/3B/A5/oYYBAFaOeYCAKGnLAAFVAzks-qU937.jpg",
"M02/3B/A5/oYYBAFaOeYOAMODNAAF6HjTTMq4819.jpg",
"M02/3B/A5/oYYBAFaOeYeAbn8uAAFLSQLw48Q042.jpg",
"M02/3B/A5/oYYBAFaOeYqAMJThAAFtrNe4UNM047.jpg",
"M02/3B/A5/oYYBAFaOeY2AbnQvAAFNSXWn0Dc026.jpg",
"M02/3B/A5/oYYBAFaOeZCAIsr0AAFHZFEVhPc682.jpg",
"M02/3B/A5/oYYBAFaOeZOAGvITAAFqPmfcc9c471.jpg",
"M02/3B/A5/oYYBAFaOeZaATvjbAAFHDmALnhE003.jpg",
"M02/3B/A5/oYYBAFaOeZmAJPuVAAFfPJC2wsE319.jpg",
"M02/3B/A5/oYYBAFaOeZyAXtAmAAFfArJNwtM371.jpg",
"M02/3B/A5/oYYBAFaOeZ-AGZN0AAFgqwYYCS8004.jpg",
"M02/3B/A5/oYYBAFaOeaOAbbrGAAFcq59JjUo205.jpg",
"M02/3B/A5/oYYBAFaOeaSAdFyoAACaxVxgUJA092.jpg"
};
int maxNum = Aria.get(this).getDownloadConfig().getMaxTaskNum();
Aria.get(this).setDownloadQueueMod(QueueMod.NOW);
for (int i = 0; i < urlArray.length; i++) {
Aria.download(this)
.load(baseUrl + urlArray[i])
.setFilePath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
//.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
.start();
//if (i < maxNum) {
// Aria.download(this)
// .load(baseUrl + urlArray[i])
// .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
// //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
// .start();
//} else {
// Aria.download(this)
// .load(baseUrl + urlArray[i])
// .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
// //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
// .add();
//}
}
}
}
package com.arialyy.simple.core.test;
import android.os.Environment;
import android.view.View;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.TestActivityMultiBinding;
/**
* Created by AriaL on 2017/6/15.
*/
public class TestMutilTaskSysDownload extends BaseActivity<TestActivityMultiBinding> {
@Override protected int setLayoutId() {
return R.layout.test_activity_multi;
}
public void onClick(View view) {
String baseUrl = "http://file.bmob.cn/";
String[] urlArray = {
"M02/3B/A4/oYYBAFaOeUSAc1QiAAFTbmA7AHs052.jpg",
"M02/3B/A4/oYYBAFaOeUaAfYC-AAFD8zf9NXc879.jpg",
"M02/3B/A4/oYYBAFaOeUuAOxhnAACSdmbqSac702.jpg",
"M02/3B/A4/oYYBAFaOeU2AFAIGAAFICximvXc924.jpg",
"M02/3B/A4/oYYBAFaOeVCAPWMQAAFm2KWCq_E721.jpg",
"M02/3B/A4/oYYBAFaOeVOAbiv9AAFfCTTgr94948.jpg",
"M02/3B/A4/oYYBAFaOeVaAMR3tAAFf3yTuuCM577.jpg",
"M02/3B/A4/oYYBAFaOeVmACEWhAAEt72ecbpg468.jpg",
"M02/3B/A4/oYYBAFaOeVyAHHt4AAFg9e9bRio507.jpg",
"M02/3B/A4/oYYBAFaOeV-AClYXAAESLGY0gag424.jpg",
"M02/3B/A4/oYYBAFaOeWKAA7N0AAF3omYOJUI703.jpg",
"M02/3B/A4/oYYBAFaOeWWAD2lrAAFN7eRFxBs575.jpg",
"M02/3B/A4/oYYBAFaOeWiAdCVEAAFg4273Dus313.jpg",
"M02/3B/A4/oYYBAFaOeWyAJDm5AAF8JVoGVb0705.jpg",
"M02/3B/A4/oYYBAFaOeW-AUoA8AAGjKiHkXUo181.jpg",
"M02/3B/A4/oYYBAFaOeXKABIamAAFU7J7vraE265.jpg",
"M02/3B/A5/oYYBAFaOeXaAW09jAAFf37qdwDA457.jpg",
"M02/3B/A5/oYYBAFaOeXmAWmS7AAFtLNpWjgo967.jpg",
"M02/3B/A5/oYYBAFaOeX2AQf9cAAF2fhwS2UE145.jpg",
"M02/3B/A5/oYYBAFaOeYCAKGnLAAFVAzks-qU937.jpg",
"M02/3B/A5/oYYBAFaOeYOAMODNAAF6HjTTMq4819.jpg",
"M02/3B/A5/oYYBAFaOeYeAbn8uAAFLSQLw48Q042.jpg",
"M02/3B/A5/oYYBAFaOeYqAMJThAAFtrNe4UNM047.jpg",
"M02/3B/A5/oYYBAFaOeY2AbnQvAAFNSXWn0Dc026.jpg",
"M02/3B/A5/oYYBAFaOeZCAIsr0AAFHZFEVhPc682.jpg",
"M02/3B/A5/oYYBAFaOeZOAGvITAAFqPmfcc9c471.jpg",
"M02/3B/A5/oYYBAFaOeZaATvjbAAFHDmALnhE003.jpg",
"M02/3B/A5/oYYBAFaOeZmAJPuVAAFfPJC2wsE319.jpg",
"M02/3B/A5/oYYBAFaOeZyAXtAmAAFfArJNwtM371.jpg",
"M02/3B/A5/oYYBAFaOeZ-AGZN0AAFgqwYYCS8004.jpg",
"M02/3B/A5/oYYBAFaOeaOAbbrGAAFcq59JjUo205.jpg",
"M02/3B/A5/oYYBAFaOeaSAdFyoAACaxVxgUJA092.jpg"
};
int maxNum = Aria.get(this).getDownloadConfig().getMaxTaskNum();
Aria.get(this).setDownloadQueueMod(QueueMod.NOW);
for (int i = 0; i < urlArray.length; i++) {
Aria.download(this)
.load(baseUrl + urlArray[i])
.setFilePath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
//.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
.start();
//if (i < maxNum) {
// Aria.download(this)
// .load(baseUrl + urlArray[i])
// .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
// //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
// .start();
//} else {
// Aria.download(this)
// .load(baseUrl + urlArray[i])
// .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
// //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
// .add();
//}
}
}
}

@ -64,26 +64,16 @@
<string-array name="test_apk_download_url">
<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item> <!--300M的文件-->
<item>http://static.gaoshouyou.com/d/21/e8/61218d78d0e8b79df68dbc18dd484c97.apk</item>
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
<item>http://static.gaoshouyou.com/d/d4/4f/d6d48db3794fb9ecf47e83c346570881.apk</item>
<!--<item>http://static.gaoshouyou.com/d/18/cf/ba18113bc6cf56c1c5863e761e717003.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/60/17/2460921367173ea7145f11194a6f2587.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/32/e0/1a32123ecbe0ee010d35479df248f90f.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk</item>-->
<!--<item>http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk</item>-->
</string-array>
<string-array name="file_nams">
<item>阴阳师</item>
<item>奇迹暖暖</item>
<item>幻影纹章</item>
<item>史上最坑爹的游戏10</item>
<item>鲜果消消乐</item>
<item>航海奇迹</item>
<item>王者荣耀</item>
<item>植物大战僵尸</item>
<item>部落冲突</item>
<item>瘟疫公司</item>
<item>水上公园大战</item>
<item>死亡之雨</item>
<item>test_1</item>
<item>test_2</item>
@ -91,13 +81,12 @@
</string-array>
<string-array name="download_url">
<item>https://g37.gdl.netease.com/onmyoji_netease_10_1.0.20.apk</item>
<item>http://static.gaoshouyou.com/d/eb/f2/dfeba30541f209ab8a50d847fc1661ce.apk</item>
<item>http://rs.0.gaoshouyou.com/d/51/46/58514d126c46b8a3f27fc8c7db3b09ec.apk</item>
<item>http://rs.0.gaoshouyou.com/d/23/69/07238f952669727878d7a0e180534c8b.apk</item>
<item>http://rs.0.gaoshouyou.com/d/e7/3d/73e716d3353de5b479fcf7da8d36a5ef.apk</item>
<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item>
<item>https://downs.muzhiwan.com/2019/06/28/com.tencent.tmgp.sgame5d15f9df3bb4d.gpk</item>
<item>https://downs.muzhiwan.com/2017/03/15/com.ea.game.pvz2_row58c8bfc00eea8.gpk</item>
<item>https://downs.muzhiwan.com/2019/07/04/com.supercell.clashofclans.ewan.mzw_5d1da09397884.apk</item>
<item>https://downs.muzhiwan.com/2019/02/28/com.miniclip.plagueinc_5c77596c79179.apk</item>
<item>https://downs.muzhiwan.com/2019/06/03/com.aqua.slide_5cf4b69e90e6a.apk</item>
<item>https://downs.muzhiwan.com/2019/05/07/com.tinydevbox.deadrain2_g_5cd14a8aedb2f.apk</item>
<item>http://dby-resource-android.duobeiyun.com/jz22a8508b4265466b9fb4bb29082eaa2d.zip</item>
<item>http://dby-resource-android.duobeiyun.com/jz05fa8faf068145fcb25c93c8091297ad.zip</item>
<item>http://dby-resource-android.duobeiyun.com/jz684e1b4c2f6b4576979e60fd95edebad.zip</item>

@ -1,27 +1,27 @@
## Project-wide Gradle settings.
#
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Wed Dec 07 20:19:22 CST 2016
#org.gradle.daemon=true
#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
# gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/
#systemProp.socksProxyHost=127.0.0.1
#systemProp.socksProxyPort=1080
#systemprop.socksProxyVersion=5
#Pandroid.debug.obsoleteApi=true
# androidx https://developer.android.com/studio/preview/features/?hl=zh-cn#androidx_migration
#android.useAndroidX=true
## Project-wide Gradle settings.
#
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Wed Dec 07 20:19:22 CST 2016
#org.gradle.daemon=true
#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
# gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/
#systemProp.socksProxyHost=127.0.0.1
#systemProp.socksProxyPort=1080
#systemprop.socksProxyVersion=5
#Pandroid.debug.obsoleteApi=true
# androidx https://developer.android.com/studio/preview/features/?hl=zh-cn#androidx_migration
#android.useAndroidX=true
#android.enableJetifier=true
Loading…
Cancel
Save