Merge branch 'v_3.0'

pull/330/head
AriaLyy 7 years ago
commit fe9789deb8
  1. 7
      Aria/build.gradle
  2. 3
      Aria/src/main/java/com/arialyy/aria/core/ProxyHelper.java
  3. 6
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  4. 59
      Aria/src/main/java/com/arialyy/aria/core/download/BaseListener.java
  5. 66
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java
  6. 7
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  7. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  8. 35
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  10. 49
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  11. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  12. 82
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  13. 72
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadListener.java
  14. 3
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java
  15. 58
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadGroupListener.java
  16. 12
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadListener.java
  17. 1
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/SingleThreadTask.java
  18. 9
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java
  19. 3
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  20. 3
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  21. 3
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java
  22. 3
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java
  23. 89
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DQueueMapping.java
  24. 21
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadGroupSchedulers.java
  25. 23
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  26. 1
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  27. 8
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  28. 63
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  29. 6
      README.md
  30. 6
      app/src/main/assets/aria_config.xml
  31. 1
      app/src/main/java/com/arialyy/simple/download/SimpleNotification.java
  32. 28
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  33. 8
      app/src/main/java/com/arialyy/simple/download/group/GroupModule.java
  34. 1
      app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java
  35. 3
      build.gradle

@ -7,8 +7,8 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 9 minSdkVersion 9
targetSdkVersion 23 targetSdkVersion 23
versionCode 317 versionCode 327
versionName "3.1.7" versionName "3.2.7"
} }
buildTypes { buildTypes {
release { release {
@ -22,7 +22,6 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1'
// compile project(':AriaCompiler') compile project(':AriaAnnotations')
compile project(':AriaAnnotations') //gradle
} }
apply from: 'bintray-release.gradle' apply from: 'bintray-release.gradle'

@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.upload; package com.arialyy.aria.core;
import com.arialyy.aria.core.AriaManager;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Set; import java.util.Set;

@ -19,15 +19,9 @@ package com.arialyy.aria.core.command.normal;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.QueueMod; import com.arialyy.aria.core.QueueMod;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.scheduler.DQueueMapping;
import com.arialyy.aria.orm.Primary;
/** /**
* Created by lyy on 2016/8/22. * Created by lyy on 2016/8/22.

@ -17,10 +17,10 @@ package com.arialyy.aria.core.download;
import android.os.Handler; import android.os.Handler;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.downloader.DownloadListener;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -28,22 +28,23 @@ import java.lang.ref.WeakReference;
/** /**
* 下载监听类 * 下载监听类
*/ */
class DListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>> class BaseListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
extends DownloadListener { implements IEventListener {
private WeakReference<Handler> outHandler; private WeakReference<Handler> outHandler;
private long lastLen = 0; //上一次发送长度 private long mLastLen = 0; //上一次发送长度
private boolean isFirst = true; private boolean isFirst = true;
private ENTITY entity; protected ENTITY mEntity;
private TASK task; protected TASK mTask;
private boolean isConvertSpeed = false; private boolean isConvertSpeed = false;
boolean isWait = false; boolean isWait = false;
DListener(TASK task, Handler outHandler) { BaseListener(TASK task, Handler outHandler) {
this.outHandler = new WeakReference<>(outHandler); this.outHandler = new WeakReference<>(outHandler);
this.task = new WeakReference<>(task).get(); this.mTask = new WeakReference<>(task).get();
this.entity = this.task.getEntity(); this.mEntity = this.mTask.getEntity();
final AriaManager manager = AriaManager.getInstance(AriaManager.APP); final AriaManager manager = AriaManager.getInstance(AriaManager.APP);
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed(); isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
mLastLen = mEntity.getCurrentProgress();
} }
@Override public void onPre() { @Override public void onPre() {
@ -52,8 +53,8 @@ class DListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
} }
@Override public void onPostPre(long fileSize) { @Override public void onPostPre(long fileSize) {
entity.setFileSize(fileSize); mEntity.setFileSize(fileSize);
entity.setConvertFileSize(CommonUtil.formatFileSize(fileSize)); mEntity.setConvertFileSize(CommonUtil.formatFileSize(fileSize));
saveData(IEntity.STATE_POST_PRE, -1); saveData(IEntity.STATE_POST_PRE, -1);
sendInState2Target(ISchedulers.POST_PRE); sendInState2Target(ISchedulers.POST_PRE);
} }
@ -69,15 +70,15 @@ class DListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
} }
@Override public void onProgress(long currentLocation) { @Override public void onProgress(long currentLocation) {
entity.setCurrentProgress(currentLocation); mEntity.setCurrentProgress(currentLocation);
long speed = currentLocation - lastLen; long speed = currentLocation - mLastLen;
if (isFirst) { if (isFirst) {
speed = 0; speed = 0;
isFirst = false; isFirst = false;
} }
handleSpeed(speed); handleSpeed(speed);
sendInState2Target(ISchedulers.RUNNING); sendInState2Target(ISchedulers.RUNNING);
lastLen = currentLocation; mLastLen = currentLocation;
} }
@Override public void onStop(long stopLocation) { @Override public void onStop(long stopLocation) {
@ -93,23 +94,23 @@ class DListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
} }
@Override public void onComplete() { @Override public void onComplete() {
saveData(IEntity.STATE_COMPLETE, entity.getFileSize()); saveData(IEntity.STATE_COMPLETE, mEntity.getFileSize());
handleSpeed(0); handleSpeed(0);
sendInState2Target(ISchedulers.COMPLETE); sendInState2Target(ISchedulers.COMPLETE);
} }
@Override public void onFail() { @Override public void onFail() {
entity.setFailNum(entity.getFailNum() + 1); mEntity.setFailNum(mEntity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, -1); saveData(IEntity.STATE_FAIL, mEntity.getCurrentProgress());
handleSpeed(0); handleSpeed(0);
sendInState2Target(ISchedulers.FAIL); sendInState2Target(ISchedulers.FAIL);
} }
private void handleSpeed(long speed) { private void handleSpeed(long speed) {
if (isConvertSpeed) { if (isConvertSpeed) {
entity.setConvertSpeed(CommonUtil.formatFileSize(speed) + "/s"); mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
} else { } else {
entity.setSpeed(speed); mEntity.setSpeed(speed < 0 ? 0 : speed);
} }
} }
@ -120,25 +121,25 @@ class DListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
*/ */
private void sendInState2Target(int state) { private void sendInState2Target(int state) {
if (outHandler.get() != null) { if (outHandler.get() != null) {
outHandler.get().obtainMessage(state, task).sendToTarget(); outHandler.get().obtainMessage(state, mTask).sendToTarget();
} }
} }
private void saveData(int state, long location) { private void saveData(int state, long location) {
mEntity.setComplete(state == IEntity.STATE_COMPLETE);
if (state == IEntity.STATE_CANCEL) { if (state == IEntity.STATE_CANCEL) {
entity.deleteData(); mEntity.deleteData();
} else if (state == IEntity.STATE_COMPLETE) { } else if (state == IEntity.STATE_COMPLETE) {
entity.setState(state); mEntity.setState(state);
entity.setComplete(true); mEntity.setCompleteTime(System.currentTimeMillis());
entity.setCompleteTime(System.currentTimeMillis()); mEntity.setCurrentProgress(mEntity.getFileSize());
entity.setCurrentProgress(entity.getFileSize()); mEntity.update();
entity.update();
} else { } else {
entity.setState(state); mEntity.setState(state);
if (location != -1) { if (location != -1) {
entity.setCurrentProgress(location); mEntity.setCurrentProgress(location);
} }
entity.update(); mEntity.update();
} }
} }
} }

@ -0,0 +1,66 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download;
import android.os.Handler;
import android.util.Log;
import com.arialyy.aria.core.download.downloader.IDownloadGroupListener;
/**
* Created by Aria.Lao on 2017/7/20.
* 任务组下载事件
*/
class DownloadGroupListener extends BaseListener<DownloadGroupEntity, DownloadGroupTask>
implements IDownloadGroupListener {
private final String TAG = "DownloadGroupListener";
DownloadGroupListener(DownloadGroupTask task, Handler outHandler) {
super(task, outHandler);
}
@Override public void supportBreakpoint(boolean support, DownloadEntity subEntity) {
}
@Override public void onSubStart(DownloadEntity subEntity) {
}
@Override public void onSubStop(DownloadEntity subEntity) {
saveCurrentLocation();
}
@Override public void onSubComplete(DownloadEntity subEntity) {
saveCurrentLocation();
}
@Override public void onSubFail(DownloadEntity subEntity) {
saveCurrentLocation();
}
@Override public void onSubCancel(DownloadEntity entity) {
saveCurrentLocation();
}
private void saveCurrentLocation() {
long location = 0;
for (DownloadEntity e : mEntity.getSubTask()) {
location += e.getCurrentProgress();
}
mEntity.setCurrentProgress(location);
mEntity.update();
}
}

@ -207,10 +207,11 @@ public class DownloadGroupTarget
if (!newName.equals(entity.getFileName())) { if (!newName.equals(entity.getFileName())) {
String oldPath = mEntity.getDirPath() + "/" + entity.getFileName(); String oldPath = mEntity.getDirPath() + "/" + entity.getFileName();
String newPath = mEntity.getDirPath() + "/" + newName; String newPath = mEntity.getDirPath() + "/" + newName;
File file = new File(oldPath); File oldFile = new File(oldPath);
if (file.exists()) { if (oldFile.exists()) {
file.renameTo(new File(newPath)); oldFile.renameTo(new File(newPath));
} }
CommonUtil.renameDownloadConfig(oldFile.getName(), newName);
DbEntity.exeSql( DbEntity.exeSql(
"UPDATE DownloadTaskEntity SET key='" + newPath + "' WHERE key='" + oldPath + "'"); "UPDATE DownloadTaskEntity SET key='" + newPath + "' WHERE key='" + oldPath + "'");
entity.setDownloadPath(newPath); entity.setDownloadPath(newPath);

@ -29,7 +29,7 @@ import com.arialyy.aria.util.CheckUtil;
*/ */
public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, DownloadGroupEntity> { public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, DownloadGroupEntity> {
private final String TAG = "DownloadGroupTask"; private final String TAG = "DownloadGroupTask";
private DListener<DownloadGroupEntity, DownloadGroupTask> mListener; private DownloadGroupListener mListener;
private IDownloadUtil mUtil; private IDownloadUtil mUtil;
private DownloadGroupTask(DownloadGroupTaskEntity taskEntity, Handler outHandler) { private DownloadGroupTask(DownloadGroupTaskEntity taskEntity, Handler outHandler) {
@ -37,7 +37,7 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, Dow
mEntity = taskEntity.getEntity(); mEntity = taskEntity.getEntity();
mOutHandler = outHandler; mOutHandler = outHandler;
mContext = AriaManager.APP; mContext = AriaManager.APP;
mListener = new DListener<>(this, mOutHandler); mListener = new DownloadGroupListener(this, mOutHandler);
mUtil = new DownloadGroupUtil(mListener, mTaskEntity); mUtil = new DownloadGroupUtil(mListener, mTaskEntity);
} }

@ -0,0 +1,35 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download;
import android.os.Handler;
import com.arialyy.aria.core.download.downloader.IDownloadListener;
/**
* Created by Aria.Lao on 2017/7/20.
* 普通任务下载的事件监听器
*/
class DownloadListener extends BaseListener<DownloadEntity, DownloadTask>
implements IDownloadListener {
DownloadListener(DownloadTask task, Handler outHandler) {
super(task, outHandler);
}
@Override public void supportBreakpoint(boolean support) {
}
}

@ -24,7 +24,7 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers; import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulerListener; import com.arialyy.aria.core.scheduler.ISchedulerListener;
import com.arialyy.aria.core.upload.ProxyHelper; import com.arialyy.aria.core.ProxyHelper;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;

@ -21,6 +21,7 @@ import com.arialyy.aria.core.inf.AbsNormalTarget;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil;
import java.io.File; import java.io.File;
/** /**
@ -48,7 +49,7 @@ public class DownloadTarget
if (mTaskEntity.entity == null) { if (mTaskEntity.entity == null) {
mTaskEntity.entity = entity; mTaskEntity.entity = entity;
} }
mEntity = entity; mEntity = mTaskEntity.entity;
} }
/** /**
@ -102,42 +103,32 @@ public class DownloadTarget
} }
/** /**
* 设置文件存储路径 * 设置文件存储路径如果需要修改新的文件名修改路径便可
* 原文件路径 /mnt/sdcard/test.zip
* 如果需要将test.zip改为game.zip只需要重新设置文件路径为/mnt/sdcard/game.zip
*
* @param downloadPath 路径必须为文件路径不能为文件夹路径
*/ */
public DownloadTarget setDownloadPath(@NonNull String downloadPath) { public DownloadTarget setDownloadPath(@NonNull String downloadPath) {
if (TextUtils.isEmpty(downloadPath)) { if (TextUtils.isEmpty(downloadPath)) {
throw new IllegalArgumentException("文件保持路径不能为null"); throw new IllegalArgumentException("文件保持路径不能为null");
} }
File file = new File(downloadPath); File file = new File(downloadPath);
mEntity.setDownloadPath(downloadPath); if (file.isDirectory()) {
mEntity.setFileName(file.getName()); throw new IllegalArgumentException("文件不能为文件夹");
mTaskEntity.key = downloadPath;
mEntity.update();
mTaskEntity.update();
return this;
}
/**
* 设置文件名
*
* @deprecated {@link #setFileName(String)}
*/
@Deprecated public DownloadTarget setDownloadName(@NonNull String downloadName) {
if (TextUtils.isEmpty(downloadName)) {
throw new IllegalArgumentException("文件名不能为null");
} }
mEntity.setFileName(downloadName); if (!downloadPath.equals(mEntity.getDownloadPath())) {
return this; File oldFile = new File(mEntity.getDownloadPath());
} File newFile = new File(downloadPath);
if (TextUtils.isEmpty(mEntity.getDownloadPath()) || oldFile.renameTo(newFile)) {
/** mEntity.setDownloadPath(downloadPath);
* 设置文件名 mEntity.setFileName(newFile.getName());
*/ mTaskEntity.key = downloadPath;
public DownloadTarget setFileName(@NonNull String fileName) { mEntity.update();
if (TextUtils.isEmpty(fileName)) { mTaskEntity.update();
throw new IllegalArgumentException("文件名不能为null"); CommonUtil.renameDownloadConfig(oldFile.getName(), newFile.getName());
}
} }
mEntity.setFileName(fileName);
return this; return this;
} }

@ -32,14 +32,14 @@ import java.io.File;
public class DownloadTask extends AbsNormalTask<DownloadEntity> { public class DownloadTask extends AbsNormalTask<DownloadEntity> {
public static final String TAG = "DownloadTask"; public static final String TAG = "DownloadTask";
private DListener<DownloadEntity, DownloadTask> mListener; private DownloadListener mListener;
private SimpleDownloadUtil mUtil; private SimpleDownloadUtil mUtil;
private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) { private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) {
mEntity = taskEntity.getEntity(); mEntity = taskEntity.getEntity();
mOutHandler = outHandler; mOutHandler = outHandler;
mContext = AriaManager.APP; mContext = AriaManager.APP;
mListener = new DListener<>(this, mOutHandler); mListener = new DownloadListener(this, mOutHandler);
mUtil = new SimpleDownloadUtil(taskEntity, mListener); mUtil = new SimpleDownloadUtil(taskEntity, mListener);
} }

@ -45,7 +45,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
private long mCurrentLocation = 0; private long mCurrentLocation = 0;
private ExecutorService mInfoPool; private ExecutorService mInfoPool;
private ExecutorService mExePool; private ExecutorService mExePool;
private IDownloadListener mListener; private IDownloadGroupListener mListener;
private DownloadGroupTaskEntity mTaskEntity; private DownloadGroupTaskEntity mTaskEntity;
private boolean isRunning = true; private boolean isRunning = true;
private Timer mTimer; private Timer mTimer;
@ -87,7 +87,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
//实际的下载任务数 //实际的下载任务数
private int mActualTaskNum = 0; private int mActualTaskNum = 0;
public DownloadGroupUtil(IDownloadListener listener, DownloadGroupTaskEntity taskEntity) { public DownloadGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) {
mListener = listener; mListener = listener;
mTaskEntity = taskEntity; mTaskEntity = taskEntity;
mInfoPool = Executors.newCachedThreadPool(); mInfoPool = Executors.newCachedThreadPool();
@ -102,8 +102,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
} }
for (DownloadEntity entity : mTaskEntity.entity.getSubTask()) { for (DownloadEntity entity : mTaskEntity.entity.getSubTask()) {
File file = new File(entity.getDownloadPath()); File file = new File(entity.getDownloadPath());
if (entity.isComplete() && file.exists()) { if (entity.getState() == IEntity.STATE_COMPLETE && file.exists()) {
mTotalSize += entity.getFileSize();
mCompleteNum++; mCompleteNum++;
mInitNum++; mInitNum++;
mCurrentLocation += entity.getFileSize(); mCurrentLocation += entity.getFileSize();
@ -111,6 +110,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
mExeMap.put(entity.getDownloadUrl(), createChildDownloadTask(entity)); mExeMap.put(entity.getDownloadUrl(), createChildDownloadTask(entity));
mCurrentLocation += entity.getCurrentProgress(); mCurrentLocation += entity.getCurrentProgress();
} }
mTotalSize += entity.getFileSize();
} }
} }
@ -127,8 +127,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
} }
@Override public void cancelDownload() { @Override public void cancelDownload() {
isRunning = false; closeTimer(false);
closeTimer();
mListener.onCancel(); mListener.onCancel();
if (!mInfoPool.isShutdown()) { if (!mInfoPool.isShutdown()) {
mInfoPool.shutdown(); mInfoPool.shutdown();
@ -161,8 +160,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
} }
@Override public void stopDownload() { @Override public void stopDownload() {
isRunning = false; closeTimer(false);
closeTimer();
mListener.onStop(mCurrentLocation); mListener.onStop(mCurrentLocation);
if (!mInfoPool.isShutdown()) { if (!mInfoPool.isShutdown()) {
mInfoPool.shutdown(); mInfoPool.shutdown();
@ -182,14 +180,23 @@ public class DownloadGroupUtil implements IDownloadUtil {
@Override public void startDownload() { @Override public void startDownload() {
isRunning = true; isRunning = true;
mFailNum = 0;
Set<String> keys = mExeMap.keySet(); Set<String> keys = mExeMap.keySet();
mListener.onPre(); mListener.onPre();
int i = 0;
for (String key : keys) { for (String key : keys) {
DownloadTaskEntity taskEntity = mExeMap.get(key); DownloadTaskEntity taskEntity = mExeMap.get(key);
if (taskEntity != null) { if (taskEntity != null) {
mInfoPool.execute(createFileInfoThread(taskEntity)); if (taskEntity.getState() != IEntity.STATE_FAIL
&& taskEntity.getState() != IEntity.STATE_WAIT) {
startChildDownload(taskEntity);
i++;
} else {
mInfoPool.execute(createFileInfoThread(taskEntity));
}
} }
} }
if (i == mExeMap.size()) startRunningFlow();
} }
@Override public void resumeDownload() { @Override public void resumeDownload() {
@ -214,7 +221,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
startChildDownload(te); startChildDownload(te);
} }
mInitNum++; mInitNum++;
if (mInitNum + mInitFailNum == mTaskEntity.getEntity().getSubTask().size()) { if (mInitNum + mInitFailNum >= mTaskEntity.getEntity().getSubTask().size()) {
startRunningFlow(); startRunningFlow();
} }
} }
@ -235,7 +242,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
if (mActualTaskNum < 0) mActualTaskNum = 0; if (mActualTaskNum < 0) mActualTaskNum = 0;
} }
failNum++; failNum++;
if (mInitNum + mInitFailNum == mTaskEntity.getEntity().getSubTask().size()) { if (mInitNum + mInitFailNum >= mTaskEntity.getEntity().getSubTask().size()) {
startRunningFlow(); startRunningFlow();
} }
} }
@ -244,7 +251,8 @@ public class DownloadGroupUtil implements IDownloadUtil {
return new FileInfoThread(taskEntity, callback); return new FileInfoThread(taskEntity, callback);
} }
private void closeTimer() { private void closeTimer(boolean isRunning) {
this.isRunning = isRunning;
if (mTimer != null) { if (mTimer != null) {
mTimer.purge(); mTimer.purge();
mTimer.cancel(); mTimer.cancel();
@ -255,13 +263,15 @@ public class DownloadGroupUtil implements IDownloadUtil {
* 开始进度流程 * 开始进度流程
*/ */
private void startRunningFlow() { private void startRunningFlow() {
closeTimer(); closeTimer(true);
mListener.onPostPre(mTotalSize); mListener.onPostPre(mTotalSize);
mListener.onStart(mCurrentLocation); mListener.onStart(mCurrentLocation);
mTimer = new Timer(true); mTimer = new Timer(true);
mTimer.schedule(new TimerTask() { mTimer.schedule(new TimerTask() {
@Override public void run() { @Override public void run() {
if (mCurrentLocation >= 0) { if (!isRunning) {
closeTimer(false);
} else if (mCurrentLocation >= 0) {
mListener.onProgress(mCurrentLocation); mListener.onProgress(mCurrentLocation);
} }
} }
@ -304,7 +314,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
/** /**
* 子任务事件监听 * 子任务事件监听
*/ */
private class ChildDownloadListener extends DownloadListener { private class ChildDownloadListener implements IDownloadListener {
DownloadTaskEntity taskEntity; DownloadTaskEntity taskEntity;
DownloadEntity entity; DownloadEntity entity;
@ -314,6 +324,8 @@ public class DownloadGroupUtil implements IDownloadUtil {
ChildDownloadListener(DownloadTaskEntity entity) { ChildDownloadListener(DownloadTaskEntity entity) {
this.taskEntity = entity; this.taskEntity = entity;
this.entity = taskEntity.getEntity(); this.entity = taskEntity.getEntity();
lastLen = this.entity.getCurrentProgress();
this.entity.setFailNum(0);
} }
@Override public void onPre() { @Override public void onPre() {
@ -347,26 +359,35 @@ public class DownloadGroupUtil implements IDownloadUtil {
@Override public void onStop(long stopLocation) { @Override public void onStop(long stopLocation) {
saveData(IEntity.STATE_STOP, stopLocation); saveData(IEntity.STATE_STOP, stopLocation);
handleSpeed(0); handleSpeed(0);
mListener.onSubStop(entity);
} }
@Override public void onCancel() { @Override public void onCancel() {
saveData(IEntity.STATE_CANCEL, -1); saveData(IEntity.STATE_CANCEL, -1);
handleSpeed(0); handleSpeed(0);
mListener.onSubCancel(entity);
} }
@Override public void onComplete() { @Override public void onComplete() {
saveData(IEntity.STATE_COMPLETE, entity.getFileSize()); saveData(IEntity.STATE_COMPLETE, entity.getFileSize());
mCompleteNum++; mCompleteNum++;
handleSpeed(0);
mListener.onSubComplete(entity);
//如果子任务完成的数量和总任务数一致,表示任务组任务已经完成
if (mCompleteNum >= mTaskEntity.getEntity().getSubTask().size()){
closeTimer(false);
mListener.onComplete();
}
//如果子任务完成数量加上失败的数量和总任务数一致,则任务组停止下载
if (mCompleteNum + mFailNum >= mActualTaskNum) { if (mCompleteNum + mFailNum >= mActualTaskNum) {
closeTimer(); closeTimer(false);
mListener.onComplete(); mListener.onComplete();
} }
handleSpeed(0);
} }
@Override public void onFail() { @Override public void onFail() {
entity.setFailNum(entity.getFailNum() + 1); entity.setFailNum(entity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, -1); saveData(IEntity.STATE_FAIL, lastLen);
handleSpeed(0); handleSpeed(0);
reTry(); reTry();
} }
@ -376,13 +397,28 @@ public class DownloadGroupUtil implements IDownloadUtil {
*/ */
private void reTry() { private void reTry() {
if (entity.getFailNum() < 5) { if (entity.getFailNum() < 5) {
Downloader dt = mDownloaderMap.get(entity.getDownloadUrl()); reStartTask();
dt.startDownload();
} else { } else {
mFailNum++; mFailNum++;
mListener.onSubFail(entity);
//如果失败的任务数大于实际的下载任务数,任务组停止下载
if (mFailNum >= mActualTaskNum) {
closeTimer(false);
mListener.onStop(mCurrentLocation);
}
} }
} }
private void reStartTask() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override public void run() {
Downloader dt = mDownloaderMap.get(entity.getDownloadUrl());
dt.startDownload();
}
}, 3000);
}
private void handleSpeed(long speed) { private void handleSpeed(long speed) {
entity.setSpeed(speed); entity.setSpeed(speed);
entity.setConvertSpeed(speed <= 0 ? "" : CommonUtil.formatFileSize(speed) + "/s"); entity.setConvertSpeed(speed <= 0 ? "" : CommonUtil.formatFileSize(speed) + "/s");
@ -394,10 +430,14 @@ public class DownloadGroupUtil implements IDownloadUtil {
if (entity.isComplete()) { if (entity.isComplete()) {
entity.setCompleteTime(System.currentTimeMillis()); entity.setCompleteTime(System.currentTimeMillis());
entity.setCurrentProgress(entity.getFileSize()); entity.setCurrentProgress(entity.getFileSize());
} else { } else if (location > 0) {
entity.setCurrentProgress(location); entity.setCurrentProgress(location);
} }
entity.update(); entity.update();
} }
@Override public void supportBreakpoint(boolean support) {
}
} }
} }

@ -1,72 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.downloader;
/**
* @author lyy
*/
public class DownloadListener implements IDownloadListener {
@Override public void onResume(long resumeLocation) {
}
@Override public void supportBreakpoint(boolean support) {
}
@Override public void onCancel() {
}
@Override public void onFail() {
}
@Override public void onPre() {
}
@Override public void onPostPre(long fileSize) {
}
@Override public void onProgress(long currentLocation) {
}
@Override public void onChildComplete(long finishLocation) {
}
@Override public void onStart(long startLocation) {
}
@Override public void onChildResume(long resumeLocation) {
}
@Override public void onStop(long stopLocation) {
}
@Override public void onComplete() {
}
}

@ -111,7 +111,7 @@ class Downloader implements Runnable, IDownloadUtil {
mTimer = new Timer(true); mTimer = new Timer(true);
mTimer.schedule(new TimerTask() { mTimer.schedule(new TimerTask() {
@Override public void run() { @Override public void run() {
if (mConstance.isComplete()) { if (mConstance.isComplete() || !mConstance.isDownloading) {
closeTimer(); closeTimer();
} else if (mConstance.CURRENT_LOCATION >= 0) { } else if (mConstance.CURRENT_LOCATION >= 0) {
mListener.onProgress(mConstance.CURRENT_LOCATION); mListener.onProgress(mConstance.CURRENT_LOCATION);
@ -343,7 +343,6 @@ class Downloader implements Runnable, IDownloadUtil {
Long r = Long.parseLong(record + ""); Long r = Long.parseLong(record + "");
mConstance.CURRENT_LOCATION += r - startL; mConstance.CURRENT_LOCATION += r - startL;
Log.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复下载"); Log.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复下载");
mListener.onChildResume(r);
startL = r; startL = r;
recordL[rl] = i; recordL[rl] = i;
rl++; rl++;

@ -0,0 +1,58 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.downloader;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEventListener;
/**
* Created by Aria.Lao on 2017/7/20.
* 下载任务组事件
*/
public interface IDownloadGroupListener extends IEventListener {
/**
* 子任务支持断点回调
*
* @param support true,支持false 不支持
*/
void supportBreakpoint(boolean support, DownloadEntity subEntity);
/**
* 子任务开始下载\恢复下载
*/
void onSubStart(DownloadEntity subEntity);
/**
* 子任务停止下载
*/
void onSubStop(DownloadEntity subEntity);
/**
* 子任务下载完成
*/
void onSubComplete(DownloadEntity subEntity);
/**
* 子任务下载失败
*/
void onSubFail(DownloadEntity subEntity);
/**
* 子任务取消下载
*/
void onSubCancel(DownloadEntity subEntity);
}

@ -21,7 +21,7 @@ import com.arialyy.aria.core.inf.IEventListener;
/** /**
* 下载监听 * 下载监听
*/ */
interface IDownloadListener extends IEventListener { public interface IDownloadListener extends IEventListener {
/** /**
* 支持断点回调 * 支持断点回调
@ -29,14 +29,4 @@ interface IDownloadListener extends IEventListener {
* @param support true,支持false 不支持 * @param support true,支持false 不支持
*/ */
void supportBreakpoint(boolean support); void supportBreakpoint(boolean support);
/**
* 单一线程的结束位置
*/
void onChildComplete(long finishLocation);
/**
* 子程恢复下载的位置
*/
void onChildResume(long resumeLocation);
} }

@ -134,7 +134,6 @@ final class SingleThreadTask implements Runnable {
+ mConfigEntity.THREAD_ID + mConfigEntity.THREAD_ID
+ "__下载完毕"); + "__下载完毕");
writeConfig(true, 1); writeConfig(true, 1);
mListener.onChildComplete(mConfigEntity.END_LOCATION);
CONSTANCE.COMPLETE_THREAD_NUM++; CONSTANCE.COMPLETE_THREAD_NUM++;
if (CONSTANCE.isComplete()) { if (CONSTANCE.isComplete()) {
File configFile = new File(mConfigFPath); File configFile = new File(mConfigFPath);

@ -84,4 +84,13 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
public int code; public int code;
public abstract ENTITY getEntity(); public abstract ENTITY getEntity();
/**
* 获取任务下载状态
*
* @return {@link IEntity}
*/
public int getState() {
return getEntity().getState();
}
} }

@ -25,7 +25,6 @@ import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.queue.pool.BaseCachePool; import com.arialyy.aria.core.queue.pool.BaseCachePool;
import com.arialyy.aria.core.queue.pool.BaseExecutePool; import com.arialyy.aria.core.queue.pool.BaseExecutePool;
import com.arialyy.aria.core.queue.pool.DownloadSharePool; import com.arialyy.aria.core.queue.pool.DownloadSharePool;
import com.arialyy.aria.core.scheduler.DQueueMapping;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers; import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
/** /**
@ -65,8 +64,6 @@ public class DownloadGroupTaskQueue
.createTask(targetName, entity, DownloadGroupSchedulers.getInstance()); .createTask(targetName, entity, DownloadGroupSchedulers.getInstance());
entity.key = entity.getEntity().getGroupName(); entity.key = entity.getEntity().getGroupName();
mCachePool.putTask(task); mCachePool.putTask(task);
DQueueMapping.getInstance().addType(task.getKey(), DQueueMapping.QUEUE_TYPE_DOWNLOAD_GROUP);
} else { } else {
Log.e(TAG, "target name 为 null!!"); Log.e(TAG, "target name 为 null!!");
} }

@ -25,7 +25,6 @@ import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.queue.pool.BaseCachePool; import com.arialyy.aria.core.queue.pool.BaseCachePool;
import com.arialyy.aria.core.queue.pool.BaseExecutePool; import com.arialyy.aria.core.queue.pool.BaseExecutePool;
import com.arialyy.aria.core.queue.pool.DownloadSharePool; import com.arialyy.aria.core.queue.pool.DownloadSharePool;
import com.arialyy.aria.core.scheduler.DQueueMapping;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
@ -130,8 +129,6 @@ public class DownloadTaskQueue
.createTask(target, entity, DownloadSchedulers.getInstance()); .createTask(target, entity, DownloadSchedulers.getInstance());
entity.key = entity.getEntity().getDownloadPath(); entity.key = entity.getEntity().getDownloadPath();
mCachePool.putTask(task); mCachePool.putTask(task);
DQueueMapping.getInstance().addType(task.getKey(), DQueueMapping.QUEUE_TYPE_DOWNLOAD);
} else { } else {
Log.e(TAG, "target name 为 null!!"); Log.e(TAG, "target name 为 null!!");
} }

@ -21,7 +21,6 @@ import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.scheduler.DQueueMapping;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -186,8 +185,6 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
String convertKey = CommonUtil.keyToHashKey(key); String convertKey = CommonUtil.keyToHashKey(key);
TASK task = mExecuteMap.get(convertKey); TASK task = mExecuteMap.get(convertKey);
mExecuteMap.remove(convertKey); mExecuteMap.remove(convertKey);
DQueueMapping.getInstance().removeType(key);
return mExecuteQueue.remove(task); return mExecuteQueue.remove(task);
} }
} }

@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
* 单个下载任务的执行池 * 单个下载任务的执行池
*/ */
public class DownloadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> { class DownloadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
private final String TAG = "DownloadExecutePool"; private final String TAG = "DownloadExecutePool";
@Override protected int getMaxSize() { @Override protected int getMaxSize() {
@ -41,6 +41,7 @@ public class DownloadExecutePool<TASK extends AbsTask> extends BaseExecutePool<T
} }
String url = task.getKey(); String url = task.getKey();
if (mExecuteQueue.contains(task)) { if (mExecuteQueue.contains(task)) {
if (!task.isRunning()) return true;
Log.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】"); Log.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】");
return false; return false;
} else { } else {

@ -1,89 +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.scheduler;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Created by Aria.Lao on 2017/7/13.
* 下载任务和队列的映射表
*/
public class DQueueMapping {
public static final int QUEUE_TYPE_DOWNLOAD = 0xa1;
public static final int QUEUE_TYPE_DOWNLOAD_GROUP = 0xa2;
public static final int QUEUE_NONE = 0xab2;
private LinkedHashMap<String, Integer> types = new LinkedHashMap<>();
private static volatile DQueueMapping instance = null;
private DQueueMapping() {
}
public static DQueueMapping getInstance() {
if (instance == null) {
synchronized (AriaManager.LOCK) {
instance = new DQueueMapping();
}
}
return instance;
}
/**
* map中增加类型
*
* @param key 任务的key
* @param type {@link #QUEUE_TYPE_DOWNLOAD}{@link #QUEUE_TYPE_DOWNLOAD}
*/
public void addType(String key, int type) {
types.put(key, type);
}
/**
* @param key 任务的key
*/
public void removeType(String key) {
types.remove(key);
}
/**
* 获取下一个任务类型
*
* @return {@link #QUEUE_TYPE_DOWNLOAD}{@link #QUEUE_TYPE_DOWNLOAD}
*/
public int nextType() {
Iterator<Map.Entry<String, Integer>> iter = types.entrySet().iterator();
if (iter.hasNext()) {
Map.Entry<String, Integer> next = iter.next();
int type = next.getValue();
iter.remove();
return type;
}
return QUEUE_NONE;
}
public boolean canStart() {
return DownloadTaskQueue.getInstance().getCurrentExePoolNum()
+ DownloadGroupTaskQueue.getInstance().getCurrentExePoolNum() >= AriaManager.getInstance(
AriaManager.APP).getDownloadConfig().getMaxTaskNum();
}
}

@ -50,25 +50,4 @@ public class DownloadGroupSchedulers extends
@Override String getProxySuffix() { @Override String getProxySuffix() {
return "$$DownloadGroupListenerProxy"; return "$$DownloadGroupListenerProxy";
} }
@Override protected void startNextTask() {
if (getExeTaskNum() + DownloadSchedulers.getInstance().getExeTaskNum()
>= AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum()) {
return;
}
if (!DownloadSchedulers.getInstance().hasNextTask()) {
nextSelf();
} else {
Integer nextType = DQueueMapping.getInstance().nextType();
if (nextType == DQueueMapping.QUEUE_TYPE_DOWNLOAD) {
DownloadSchedulers.getInstance().nextSelf();
} else {
nextSelf();
}
}
}
void nextSelf() {
super.startNextTask();
}
} }

@ -16,13 +16,11 @@
package com.arialyy.aria.core.scheduler; package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import java.nio.MappedByteBuffer;
/** /**
* Created by lyy on 2016/8/16. * Created by lyy on 2016/8/16.
@ -54,25 +52,4 @@ public class DownloadSchedulers
@Override String getProxySuffix() { @Override String getProxySuffix() {
return "$$DownloadListenerProxy"; return "$$DownloadListenerProxy";
} }
@Override protected void startNextTask() {
if (getExeTaskNum() + DownloadGroupSchedulers.getInstance().getExeTaskNum()
>= AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum()) {
return;
}
if (!DownloadGroupSchedulers.getInstance().hasNextTask()) {
nextSelf();
} else {
Integer nextType = DQueueMapping.getInstance().nextType();
if (nextType == DQueueMapping.QUEUE_TYPE_DOWNLOAD_GROUP) {
DownloadGroupSchedulers.getInstance().nextSelf();
} else {
nextSelf();
}
}
}
void nextSelf() {
super.startNextTask();
}
} }

@ -17,6 +17,7 @@ package com.arialyy.aria.core.upload;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.ProxyHelper;
import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.AbsReceiver;

@ -82,14 +82,6 @@ public class UploadTarget extends AbsNormalTarget<UploadTarget, UploadEntity, Up
return this; return this;
} }
/**
* 设置文件名
*/
public UploadTarget setFileName(String fileName) {
mEntity.setFileName(fileName);
return this;
}
/** /**
* 设置上传文件类型 * 设置上传文件类型
* *

@ -44,8 +44,12 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.lang.reflect.GenericArrayType; import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
@ -595,6 +599,65 @@ public class CommonUtil {
return err.toString(); return err.toString();
} }
/**
* 重命名下载配置文件
* 如果旧的配置文件名不存在则使用新的配置文件名新创建一个文件否则将旧的配置文件重命名为新的位置文件名
* 除了重命名配置文件名外还会将文件中的记录重命名为新的记录如果没有记录则不做处理
*
* @param oldName 旧的下载文件名
* @param newName 新的下载文件名
*/
public static void renameDownloadConfig(String oldName, String newName) {
renameConfig(AriaManager.APP.getFilesDir().getPath() + AriaManager.DOWNLOAD_TEMP_DIR, oldName,
newName);
}
/**
* 重命名上传配置文件
* 如果旧的配置文件名不存在则使用新的配置文件名新创建一个文件否则将旧的配置文件重命名为新的位置文件名
* 除了重命名配置文件名外还会将文件中的记录重命名为新的记录如果没有记录则不做处理
*
* @param oldName 旧的上传文件名
* @param newName 新的上传文件名
*/
public static void renameUploadConfig(String oldName, String newName) {
renameConfig(AriaManager.APP.getFilesDir().getPath() + AriaManager.UPLOAD_TEMP_DIR, oldName,
newName);
}
private static void renameConfig(String basePath, String oldName, String newName) {
if (oldName.equals(newName)) return;
File oldFile = new File(basePath + oldName + ".properties");
File newFile = new File(basePath + newName + ".properties");
if (!oldFile.exists()) {
createFile(newFile.getPath());
} else {
Properties pro = CommonUtil.loadConfig(oldFile);
if (!pro.isEmpty()) {
Set<Object> keys = pro.keySet();
Set<String> newKeys = new LinkedHashSet<>();
Set<String> values = new LinkedHashSet<>();
for (Object key : keys) {
String oldKey = String.valueOf(key);
if (oldKey.contains(oldName)) {
values.add(pro.getProperty(oldKey));
newKeys.add(oldKey.replace(oldName, newName));
}
}
pro.clear();
Iterator<String> next = values.iterator();
for (String key : newKeys) {
pro.setProperty(key, next.next());
}
CommonUtil.saveConfig(oldFile, pro);
}
oldFile.renameTo(newFile);
}
}
/** /**
* 读取下载配置文件 * 读取下载配置文件
*/ */

@ -30,8 +30,8 @@ Aria怎样使用?
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion)
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java ```java
compile 'com.arialyy.aria:aria-core:3.2.6' compile 'com.arialyy.aria:aria-core:3.2.7'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.2.6' annotationProcessor 'com.arialyy.aria:aria-compiler:3.2.7'
``` ```
## 示例 ## 示例
@ -345,11 +345,13 @@ Aria.download(this).load(DOWNLOAD_URL).setExtendField(str)
*** ***
## 后续版本开发规划 ## 后续版本开发规划
* ~~ftp断点下载~~
* ~~http、scoket断点上传~~ * ~~http、scoket断点上传~~
* ~~实现上传队列调度功能~~ * ~~实现上传队列调度功能~~
## 开发日志 ## 开发日志
+ v_3.2.7 移除设置文件名的api接口,修复断开网络时出现的进度条错误的问题
+ v_3.2.6 移除广播事件,增加任务组下载功能 + v_3.2.6 移除广播事件,增加任务组下载功能
+ v_3.1.9 修复stopAll队列没有任务时崩溃的问题,增加针对单个任务监听的功能 + v_3.1.9 修复stopAll队列没有任务时崩溃的问题,增加针对单个任务监听的功能
+ v_3.1.7 修复某些文件下载不了的bug,增加apt注解方法,事件获取更加简单了 + v_3.1.7 修复某些文件下载不了的bug,增加apt注解方法,事件获取更加简单了

@ -8,7 +8,7 @@
<threadNum value="4"/> <threadNum value="4"/>
<!--设置下载队列最大任务数, 默认为2--> <!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="2"/> <maxTaskNum value="4"/>
<!--设置下载失败,重试次数,默认为10--> <!--设置下载失败,重试次数,默认为10-->
<reTryNum value="10"/> <reTryNum value="10"/>
@ -17,10 +17,10 @@
<reTryInterval value="5000"/> <reTryInterval value="5000"/>
<!--设置url连接超时时间,单位为毫秒,默认5000毫秒--> <!--设置url连接超时时间,单位为毫秒,默认5000毫秒-->
<connectTimeOut value="10000"/> <connectTimeOut value="1000"/>
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒--> <!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
<iOTimeOut value="20000"/> <iOTimeOut value="10000"/>
<!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢--> <!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢-->
<buffSize value="8192"/> <buffSize value="8192"/>

@ -56,7 +56,6 @@ public class SimpleNotification {
public void start() { public void start() {
Aria.download(mContext) Aria.download(mContext)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
.setDownloadName("notification_test.apk")
.setDownloadPath( .setDownloadPath(
Environment.getExternalStorageDirectory() + "/Download/消灭星星.apk") Environment.getExternalStorageDirectory() + "/Download/消灭星星.apk")
.start(); .start();

@ -186,19 +186,25 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
String text = ((TextView) view).getText().toString(); //String text = ((TextView) view).getText().toString();
if (text.equals("重新开始?") || text.equals("开始")) { //if (text.equals("重新开始?") || text.equals("开始")) {
Aria.download(this) // Aria.download(this)
.load(DOWNLOAD_URL) // .load(DOWNLOAD_URL)
.addHeader("groupName", "value") // .addHeader("groupName", "value")
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") // .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
.start(); // .setFileName("hehe.apk")
} else if (text.equals("恢复")) { // .start();
Aria.download(this).load(DOWNLOAD_URL).resume(); //} else if (text.equals("恢复")) {
} // Aria.download(this).load(DOWNLOAD_URL).resume();
//}
Aria.download(this)
.load(DOWNLOAD_URL)
.addHeader("groupName", "value")
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/gggg.apk")
.start();
break; break;
case R.id.stop: case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).pause(); Aria.download(this).load(DOWNLOAD_URL).stop();
break; break;
case R.id.cancel: case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel(); Aria.download(this).load(DOWNLOAD_URL).cancel();

@ -43,12 +43,4 @@ public class GroupModule extends BaseModule {
Collections.addAll(names, str); Collections.addAll(names, str);
return names; return names;
} }
//NormalList<String> convertPath(NormalList<String> urls){
// NormalList<String> paths = new ArrayList<>();
//
// for (String url : urls){
//
// }
//}
} }

@ -68,7 +68,6 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show();
Aria.download(getContext()) Aria.download(getContext())
.load(item.downloadUrl) .load(item.downloadUrl)
.setFileName(item.name)
.setDownloadPath(item.downloadPath) .setDownloadPath(item.downloadPath)
.start(); .start();
} }

@ -37,8 +37,7 @@ task clean(type: Delete) {
ext { ext {
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
// publishVersion = '0.0.8' publishVersion = '3.2.7'
publishVersion = '3.2.6'
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'
website = 'https://github.com/AriaLyy/Aria' website = 'https://github.com/AriaLyy/Aria'

Loading…
Cancel
Save