Skip to content
Permalink
Browse files

fix bug #414

fix bug #406
  • Loading branch information...
AriaLyy committed Jul 10, 2019
1 parent b081853 commit b1bc4529c099c88450606053be298aed34563c79
Showing with 405 additions and 247 deletions.
  1. +1 −0 AppFrame/src/main/java/com/arialyy/frame/base/BaseFragment.java
  2. +7 −6 Aria/src/main/java/com/arialyy/aria/core/command/AbsNormalCmd.java
  3. +0 −12 Aria/src/main/java/com/arialyy/aria/core/command/ICmd.java
  4. +2 −2 Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java
  5. +1 −1 Aria/src/main/java/com/arialyy/aria/core/common/http/HttpTaskConfig.java
  6. +11 −3 Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java
  7. +4 −4 Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  8. +8 −8 Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java
  9. +3 −3 Aria/src/main/java/com/arialyy/aria/core/download/group/ChildDownloadListener.java
  10. +7 −5 Aria/src/main/java/com/arialyy/aria/core/download/group/SimpleSchedulers.java
  11. +17 −18 Aria/src/main/java/com/arialyy/aria/core/download/group/SimpleSubQueue.java
  12. +4 −5 Aria/src/main/java/com/arialyy/aria/core/download/group/{SubDownloadLoader.java → SubDLoadUtil.java}
  13. +6 −85 Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  14. +1 −1 Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java
  15. +61 −14 Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  16. +4 −0 Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java
  17. +3 −3 Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  18. +5 −2 Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java
  19. +2 −0 DEV_LOG.md
  20. +1 −0 app/build.gradle
  21. +46 −0 app/src/main/java/com/arialyy/simple/common/LoadingDialog.java
  22. +3 −6 app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  23. +1 −1 app/src/main/java/com/arialyy/simple/core/download/group/ChildHandleDialog.java
  24. +42 −29 app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
  25. +19 −2 app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  26. +92 −34 app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java
  27. +20 −0 app/src/main/java/com/arialyy/simple/to/PeerIndex.java
  28. +5 −0 app/src/main/res/drawable/bg_loading.xml
  29. +7 −1 app/src/main/res/layout/activity_download_group.xml
  30. +19 −0 app/src/main/res/layout/dialog_loading.xml
  31. +3 −2 app/src/main/res/layout/fragment_video_player.xml
  32. BIN img/m3u8VodDownload.gif
@@ -9,6 +9,7 @@
public abstract class BaseFragment<VB extends ViewDataBinding> extends AbsFragment<VB> {
public int color;


@Override protected void dataCallback(int result, Object obj) {

}
@@ -21,6 +21,7 @@
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
@@ -41,26 +42,26 @@
int taskType;

/**
* @param taskType 下载任务类型{@link ICmd#TASK_TYPE_DOWNLOAD}、{@link ICmd#TASK_TYPE_DOWNLOAD_GROUP}、{@link
* ICmd#TASK_TYPE_UPLOAD}
* @param taskType 下载任务类型{@link ITask#DOWNLOAD}、{@link ITask#DOWNLOAD_GROUP}、{@link
* ITask#UPLOAD}
*/
AbsNormalCmd(T entity, int taskType) {
this.taskType = taskType;
mTaskWrapper = entity;
TAG = CommonUtil.getClassName(this);
if (taskType == ICmd.TASK_TYPE_DOWNLOAD) {
if (taskType == ITask.DOWNLOAD) {
if (!(entity instanceof DTaskWrapper)) {
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD");
return;
}
mQueue = DownloadTaskQueue.getInstance();
} else if (taskType == ICmd.TASK_TYPE_DOWNLOAD_GROUP) {
} else if (taskType == ITask.DOWNLOAD_GROUP) {
if (!(entity instanceof DGTaskWrapper)) {
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD_GROUP");
return;
}
mQueue = DownloadGroupTaskQueue.getInstance();
} else if (taskType == ICmd.TASK_TYPE_UPLOAD) {
} else if (taskType == ITask.UPLOAD) {
if (!(entity instanceof UTaskWrapper)) {
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_UPLOAD");
return;
@@ -70,7 +71,7 @@
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD、TASK_TYPE_DOWNLOAD_GROUP、TASK_TYPE_UPLOAD");
return;
}
isDownloadCmd = taskType < ICmd.TASK_TYPE_UPLOAD;
isDownloadCmd = taskType == ITask.DOWNLOAD || taskType == ITask.DOWNLOAD_GROUP;
}

/**
@@ -20,18 +20,6 @@
*/

public interface ICmd {
/**
* 单任务下载任务
*/
int TASK_TYPE_DOWNLOAD = 0x01;
/**
* 任务组下载任务
*/
int TASK_TYPE_DOWNLOAD_GROUP = 0x02;
/**
* 上传任务
*/
int TASK_TYPE_UPLOAD = 0x10;

/**
* 执行命令
@@ -38,12 +38,12 @@
TASK extends AbsTask<TASK_WRAPPER>>
implements IEventListener {
protected static String TAG;
private static final int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
protected static final int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
protected WeakReference<Handler> outHandler;
private long mLastLen; //上一次发送长度
private boolean isFirst = true;
private TASK mTask;
private long mLastSaveTime;
protected long mLastSaveTime;
protected ENTITY mEntity;
protected TASK_WRAPPER mTaskWrapper;
private boolean isConvertSpeed;
@@ -86,7 +86,7 @@
private WeakReference<IHttpFileLenAdapter> fileLenAdapter;

public IHttpFileLenAdapter getFileLenAdapter() {
return fileLenAdapter.get();
return fileLenAdapter == null ? null : fileLenAdapter.get();
}

/**
@@ -16,7 +16,6 @@
package com.arialyy.aria.core.download;

import android.os.Handler;

import com.arialyy.aria.core.common.BaseListener;
import com.arialyy.aria.core.common.RecordHandler;
import com.arialyy.aria.core.download.group.IDownloadGroupListener;
@@ -46,6 +45,7 @@

@Override
public void onSubPre(DownloadEntity subEntity) {
saveSubState(IEntity.STATE_PRE, subEntity);
sendInState2Target(ISchedulers.SUB_PRE, subEntity);
}

@@ -56,23 +56,27 @@ public void supportBreakpoint(boolean support, DownloadEntity subEntity) {

@Override
public void onSubStart(DownloadEntity subEntity) {
saveSubState(IEntity.STATE_RUNNING, subEntity);
sendInState2Target(ISchedulers.SUB_START, subEntity);
}

@Override
public void onSubStop(DownloadEntity subEntity) {
saveSubState(IEntity.STATE_STOP, subEntity);
saveCurrentLocation();
sendInState2Target(ISchedulers.SUB_STOP, subEntity);
}

@Override
public void onSubComplete(DownloadEntity subEntity) {
saveSubState(IEntity.STATE_COMPLETE, subEntity);
saveCurrentLocation();
sendInState2Target(ISchedulers.SUB_COMPLETE, subEntity);
}

@Override
public void onSubFail(DownloadEntity subEntity, BaseException e) {
saveSubState(IEntity.STATE_FAIL, subEntity);
saveCurrentLocation();
sendInState2Target(ISchedulers.SUB_FAIL, subEntity);
if (e != null) {
@@ -83,12 +87,17 @@ public void onSubFail(DownloadEntity subEntity, BaseException e) {

@Override
public void onSubCancel(DownloadEntity subEntity) {
saveSubState(IEntity.STATE_CANCEL, subEntity);
saveCurrentLocation();
sendInState2Target(ISchedulers.SUB_CANCEL, subEntity);
}

@Override
public void onSubRunning(DownloadEntity subEntity) {
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL) {
saveSubState(IEntity.STATE_RUNNING, subEntity);
mLastSaveTime = System.currentTimeMillis();
}
sendInState2Target(ISchedulers.SUB_RUNNING, subEntity);
}

@@ -102,7 +111,6 @@ private void sendInState2Target(int state, DownloadEntity subEntity) {
mSeedEntity.entity = subEntity;
outHandler.get().obtainMessage(state, ISchedulers.IS_SUB_TASK, 0, mSeedEntity).sendToTarget();
}
saveSubState(state, subEntity);
}

private void saveSubState(int state, DownloadEntity subEntity) {
@@ -117,7 +125,7 @@ private void saveSubState(int state, DownloadEntity subEntity) {
subEntity.setConvertSpeed("0kb/s");
subEntity.setSpeed(0);
ALog.i(TAG, String.format("任务【%s】完成,将删除线程任务记录", mEntity.getKey()));
RecordUtil.delTaskRecord(subEntity.getKey(), RecordHandler.TYPE_DOWNLOAD, false, false);
RecordUtil.delTaskRecord(subEntity.getFilePath(), RecordHandler.TYPE_DOWNLOAD, false, false);
}
subEntity.update();
}
@@ -21,12 +21,12 @@
import com.arialyy.annotations.TaskEnum;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.CancelAllCmd;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.NormalCmdFactory;
import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.ReceiverType;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
@@ -423,7 +423,7 @@ public boolean taskExists(List<String> urls) {
public void stopAllTask() {
EventMsgUtil.getDefault().post(NormalCmdFactory.getInstance()
.createCmd(new DTaskWrapper(null), NormalCmdFactory.TASK_STOP_ALL,
ICmd.TASK_TYPE_DOWNLOAD));
ITask.DOWNLOAD));
}

/**
@@ -434,7 +434,7 @@ public void stopAllTask() {
public void resumeAllTask() {
EventMsgUtil.getDefault().post(NormalCmdFactory.getInstance()
.createCmd(new DTaskWrapper(null), NormalCmdFactory.TASK_RESUME_ALL,
ICmd.TASK_TYPE_DOWNLOAD));
ITask.DOWNLOAD));
}

/**
@@ -447,7 +447,7 @@ public void removeAllTask(boolean removeFile) {
final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP);
CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createNormalCmd(new DTaskWrapper(null),
NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_DOWNLOAD);
NormalCmdFactory.TASK_CANCEL_ALL, ITask.DOWNLOAD);
cancelCmd.removeFile = removeFile;
EventMsgUtil.getDefault().post(cancelCmd);

@@ -50,7 +50,7 @@
private boolean isStop = false, isCancel = false;
private Handler mScheduler;
private SimpleSubQueue mSubQueue = SimpleSubQueue.newInstance();
private Map<String, SubDownloadLoader> mExeLoader = new WeakHashMap<>();
private Map<String, SubDLoadUtil> mExeLoader = new WeakHashMap<>();
private Map<String, DTaskWrapper> mCache = new WeakHashMap<>();
DGTaskWrapper mGTWrapper;
GroupRunState mState;
@@ -102,7 +102,7 @@ public void startSubTask(String url) {
if (!mState.isRunning) {
startTimer();
}
SubDownloadLoader d = getDownloader(url);
SubDLoadUtil d = getDownloader(url);
if (d != null && !d.isRunning()) {
mSubQueue.startTask(d);
}
@@ -115,7 +115,7 @@ public void startSubTask(String url) {
*/
public void stopSubTask(String url) {
if (!checkSubTask(url, "停止")) return;
SubDownloadLoader d = getDownloader(url);
SubDLoadUtil d = getDownloader(url);
if (d != null && d.isRunning()) {
mSubQueue.stopTask(d);
}
@@ -147,8 +147,8 @@ private boolean checkSubTask(String url, String type) {
*
* @param url 子任务下载地址
*/
private SubDownloadLoader getDownloader(String url) {
SubDownloadLoader d = mExeLoader.get(url);
private SubDLoadUtil getDownloader(String url) {
SubDLoadUtil d = mExeLoader.get(url);
if (d == null) {
return createAndStartSubLoader(mCache.get(url));
}
@@ -266,7 +266,7 @@ private synchronized void startTimer() {
/**
* 创建并启动子任务下载器
*/
SubDownloadLoader createAndStartSubLoader(DTaskWrapper taskWrapper) {
SubDLoadUtil createAndStartSubLoader(DTaskWrapper taskWrapper) {
return createAndStartSubLoader(taskWrapper, true);
}

@@ -275,8 +275,8 @@ SubDownloadLoader createAndStartSubLoader(DTaskWrapper taskWrapper) {
*
* @param needGetFileInfo {@code true} 需要获取文件信息。{@code false} 不需要获取文件信息
*/
SubDownloadLoader createAndStartSubLoader(DTaskWrapper taskWrapper, boolean needGetFileInfo) {
SubDownloadLoader loader = new SubDownloadLoader(mScheduler, taskWrapper, needGetFileInfo);
SubDLoadUtil createAndStartSubLoader(DTaskWrapper taskWrapper, boolean needGetFileInfo) {
SubDLoadUtil loader = new SubDLoadUtil(mScheduler, taskWrapper, needGetFileInfo);
mExeLoader.put(loader.getKey(), loader);
mSubQueue.startTask(loader);
return loader;
@@ -32,9 +32,9 @@
private long lastSaveTime;
private long lastLen;
private Handler schedulers;
private SubDownloadLoader loader;
private SubDLoadUtil loader;

ChildDownloadListener(Handler schedulers, SubDownloadLoader loader) {
ChildDownloadListener(Handler schedulers, SubDLoadUtil loader) {
this.loader = loader;
this.schedulers = schedulers;
subEntity = loader.getEntity();
@@ -140,7 +140,7 @@ private void saveData(int state, long location) {
*
* @param state {@link ISchedulers}
*/
private void sendToTarget(int state, SubDownloadLoader util) {
private void sendToTarget(int state, SubDLoadUtil util) {
schedulers.obtainMessage(state, util).sendToTarget();
}
}
@@ -20,6 +20,7 @@
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.config.Configuration;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog;
@@ -47,7 +48,7 @@ static SimpleSchedulers newInstance(GroupRunState state) {
}

@Override public boolean handleMessage(Message msg) {
SubDownloadLoader loader = (SubDownloadLoader) msg.obj;
SubDLoadUtil loader = (SubDLoadUtil) msg.obj;
switch (msg.what) {
case RUNNING:
mGState.listener.onSubRunning(loader.getEntity());
@@ -78,7 +79,7 @@ static SimpleSchedulers newInstance(GroupRunState state) {
* 2、stopNum + failNum + completeNum + cacheNum == subSize,则认为组合任务停止
* 3、failNum == subSize,只有全部的子任务都失败了,才能任务组合任务失败
*/
private synchronized void handleFail(final SubDownloadLoader loader) {
private synchronized void handleFail(final SubDLoadUtil loader) {
Configuration config = Configuration.getInstance();

long interval = config.dGroupCfg.getSubReTryInterval();
@@ -125,7 +126,7 @@ private synchronized void handleFail(final SubDownloadLoader loader) {
* 1、所有的子任务已经停止,则认为组合任务停止
* 2、completeNum + failNum + stopNum = subSize,则认为组合任务停止
*/
private synchronized void handleStop(SubDownloadLoader loader) {
private synchronized void handleStop(SubDLoadUtil loader) {
mGState.listener.onSubStop(loader.getEntity());
mGState.countStopNum(loader.getKey());
if (mGState.getStopNum() == mGState.getSubSize()
@@ -150,8 +151,9 @@ private synchronized void handleStop(SubDownloadLoader loader) {
* GroupRunState#getFailNum()}不为0,则认为组合任务被停止
* 3、只有有缓存的子任务,则任务组合任务没有完成
*/
private synchronized void handleComplete(SubDownloadLoader loader) {
private synchronized void handleComplete(SubDLoadUtil loader) {
ALog.d(TAG, String.format("子任务【%s】完成", loader.getEntity().getFileName()));
ThreadTaskManager.getInstance().removeTaskThread(loader.getKey());
mGState.listener.onSubComplete(loader.getEntity());
mQueue.removeTaskFromExecQ(loader);
mGState.updateCompleteNum();
@@ -177,7 +179,7 @@ private void startNext() {
if (mQueue.isStopAll()) {
return;
}
SubDownloadLoader next = mQueue.getNextTask();
SubDLoadUtil next = mQueue.getNextTask();
if (next != null) {
ALog.d(TAG, String.format("启动任务:%s", next.getEntity().getFileName()));
mQueue.startTask(next);

0 comments on commit b1bc452

Please sign in to comment.
You can’t perform that action at this time.