Single-task logic optimization

v4
laoyuyu 2 years ago
parent 1415de11c6
commit e0c9b0c373
  1. 4
      Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java
  2. 6
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  3. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskListener.java
  4. 8
      Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java
  5. 8
      Http/src/main/java/com/arialyy/aria/http/HttpUtil.kt
  6. 2
      Http/src/main/java/com/arialyy/aria/http/download/HttpBlockThreadInterceptor.kt
  7. 24
      Http/src/main/java/com/arialyy/aria/http/download/HttpDBlockInterceptor.kt
  8. 13
      Http/src/main/java/com/arialyy/aria/http/download/HttpDCheckInterceptor.kt
  9. 4
      Http/src/main/java/com/arialyy/aria/http/download/HttpDEventListener.kt
  10. 2
      Http/src/main/java/com/arialyy/aria/http/download/HttpDHeaderInterceptor.kt
  11. 10
      Http/src/main/java/com/arialyy/aria/http/download/HttpDStartController.kt
  12. 75
      Http/src/main/java/com/arialyy/aria/http/download/HttpDTaskAdapter.kt
  13. 4
      Http/src/main/java/com/arialyy/aria/http/download/HttpDownloadListener.kt
  14. 51
      Http/src/main/java/com/arialyy/aria/http/download/ITaskAdapterDelegate.kt
  15. 100
      Http/src/main/java/com/arialyy/aria/http/download/SingleTaskDelegate.kt
  16. 51
      Http/src/main/java/com/arialyy/aria/http/download/SubTaskDelegate.kt
  17. 14
      Http/src/main/java/com/arialyy/aria/http/download/TimerInterceptor.kt
  18. 2
      Http/src/main/java/com/arialyy/aria/http/upload/HttpUStartController.kt
  19. 8
      Http/src/main/java/com/arialyy/aria/http/upload/HttpUTaskAdapter.kt
  20. 9
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGCheckInterceptor.kt
  21. 3
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGEventListener.kt
  22. 9
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGStartController.kt
  23. 73
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGSubTaskInterceptor.kt
  24. 6
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGTaskManager.kt
  25. 14
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGroupAdapter.kt
  26. 11
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpGroupTask.java
  27. 52
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpSubBlockManager.kt
  28. 58
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpSubListener.kt
  29. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/command/AbsCmd.java
  30. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/command/CmdHelper.java
  31. 6
      PublicComponent/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java
  32. 6
      PublicComponent/src/main/java/com/arialyy/aria/core/common/TaskOption.kt
  33. 8
      PublicComponent/src/main/java/com/arialyy/aria/core/inf/IBlockManager.java
  34. 7
      PublicComponent/src/main/java/com/arialyy/aria/core/inf/ITaskManager.kt
  35. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/listener/ISchedulers.java
  36. 3
      PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt
  37. 14
      PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTaskAdapter.kt
  38. 17
      PublicComponent/src/main/java/com/arialyy/aria/core/task/DBlockManager.kt
  39. 6
      PublicComponent/src/main/java/com/arialyy/aria/core/task/ITask.java
  40. 9
      PublicComponent/src/main/java/com/arialyy/aria/core/task/SingleDownloadTask.java
  41. 4
      PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskCachePool.kt
  42. 4
      PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskChain.kt
  43. 15
      PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskState.kt
  44. 59
      PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTaskManager2.kt
  45. 2
      PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt
  46. 4
      PublicComponent/src/main/java/com/arialyy/aria/orm/entity/DEntity.kt
  47. 2
      PublicComponent/src/main/java/com/arialyy/aria/orm/entity/TaskRecord.kt
  48. 7
      PublicComponent/src/main/java/com/arialyy/aria/util/BlockUtil.kt
  49. 9
      PublicComponent/src/main/java/com/arialyy/aria/util/Ext.kt
  50. 2
      Queue/src/main/java/com/arialyy/aria/queue/AbsTaskQueue.java
  51. 4
      Queue/src/main/java/com/arialyy/aria/queue/DTaskQueue.java
  52. 4
      Schedulers/src/main/java/com/arialyy/aria/schedulers/AptNormalTaskListener.java
  53. 4
      Schedulers/src/main/java/com/arialyy/aria/schedulers/NormalTaskListenerInterface.java
  54. 16
      Schedulers/src/main/java/com/arialyy/aria/schedulers/TaskSchedulers.java
  55. 20
      app/src/main/assets/help_code/KotlinHttpDownload.kt
  56. 10
      app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java
  57. 18
      app/src/main/java/com/arialyy/simple/core/download/DownloadDialogFragment.java
  58. 10
      app/src/main/java/com/arialyy/simple/core/download/DownloadPopupWindow.java
  59. 20
      app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
  60. 20
      app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java
  61. 19
      app/src/main/java/com/arialyy/simple/core/download/KotlinDownloadActivity.kt
  62. 20
      app/src/main/java/com/arialyy/simple/core/download/SFtpDownloadActivity.java
  63. 20
      app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  64. 10
      app/src/main/java/com/arialyy/simple/core/download/fragment/DownloadFragment.java
  65. 10
      app/src/main/java/com/arialyy/simple/core/download/fragment/MultiItemFragment.java
  66. 20
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveDLoadActivity.java
  67. 20
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  68. 20
      app/src/main/java/com/arialyy/simple/core/download/mutil/MultiDownloadActivity.java
  69. 16
      app/src/main/java/com/arialyy/simple/core/download/mutil/MultiTaskListActivity.java
  70. 16
      app/src/main/java/com/arialyy/simple/core/download/service/DownloadService.java
  71. 20
      app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java

@ -132,9 +132,9 @@ public abstract class FeatureController {
int checkTaskType() { int checkTaskType() {
int taskType = 0; int taskType = 0;
if (mTaskWrapper instanceof DTaskWrapper) { if (mTaskWrapper instanceof DTaskWrapper) {
taskType = ITask.DOWNLOAD; taskType = ITask.SINGLE_DOWNLOAD;
} else if (mTaskWrapper instanceof DGTaskWrapper) { } else if (mTaskWrapper instanceof DGTaskWrapper) {
taskType = ITask.DOWNLOAD_GROUP; taskType = ITask.HTTP_GROUP;
} else if (mTaskWrapper instanceof UTaskWrapper) { } else if (mTaskWrapper instanceof UTaskWrapper) {
taskType = ITask.UPLOAD; taskType = ITask.UPLOAD;
} }

@ -484,7 +484,7 @@ public class DownloadReceiver extends AbsReceiver {
public void stopAllTask() { public void stopAllTask() {
EventMsgUtil.getDefault().post(NormalCmdFactory.getInstance() EventMsgUtil.getDefault().post(NormalCmdFactory.getInstance()
.createCmd(new DTaskWrapper(null), NormalCmdFactory.TASK_STOP_ALL, .createCmd(new DTaskWrapper(null), NormalCmdFactory.TASK_STOP_ALL,
ITask.DOWNLOAD)); ITask.SINGLE_DOWNLOAD));
} }
/** /**
@ -495,7 +495,7 @@ public class DownloadReceiver extends AbsReceiver {
public void resumeAllTask() { public void resumeAllTask() {
EventMsgUtil.getDefault().post(NormalCmdFactory.getInstance() EventMsgUtil.getDefault().post(NormalCmdFactory.getInstance()
.createCmd(new DTaskWrapper(null), NormalCmdFactory.TASK_RESUME_ALL, .createCmd(new DTaskWrapper(null), NormalCmdFactory.TASK_RESUME_ALL,
ITask.DOWNLOAD)); ITask.SINGLE_DOWNLOAD));
} }
/** /**
@ -508,7 +508,7 @@ public class DownloadReceiver extends AbsReceiver {
final AriaManager ariaManager = AriaManager.getInstance(); final AriaManager ariaManager = AriaManager.getInstance();
CancelAllCmd cancelCmd = CancelAllCmd cancelCmd =
(CancelAllCmd) CmdHelper.createNormalCmd(new DTaskWrapper(null), (CancelAllCmd) CmdHelper.createNormalCmd(new DTaskWrapper(null),
NormalCmdFactory.TASK_CANCEL_ALL, ITask.DOWNLOAD); NormalCmdFactory.TASK_CANCEL_ALL, ITask.SINGLE_DOWNLOAD);
cancelCmd.removeFile = removeFile; cancelCmd.removeFile = removeFile;
EventMsgUtil.getDefault().post(cancelCmd); EventMsgUtil.getDefault().post(cancelCmd);

@ -16,11 +16,11 @@
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
import com.arialyy.aria.core.scheduler.NormalTaskListenerInterface; import com.arialyy.aria.core.scheduler.NormalTaskListenerInterface;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
/** /**
* @author ChenFei(chenfei0928@gmail.com) * @author ChenFei(chenfei0928@gmail.com)
* Date: 2020-07-07 14:12 * Date: 2020-07-07 14:12
*/ */
public interface DownloadTaskListener extends NormalTaskListenerInterface<DownloadTask> { public interface DownloadTaskListener extends NormalTaskListenerInterface<SingleDownloadTask> {
} }

@ -19,7 +19,7 @@ package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.task.DownloadGroupTask; import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.task.ITask; import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.listener.ISchedulers; import com.arialyy.aria.core.listener.ISchedulers;
@ -54,7 +54,7 @@ class TaskFactory {
* @param schedulers 对应的任务调度器 * @param schedulers 对应的任务调度器
* @param <TASK_ENTITY> {@link DTaskWrapper}{@link UTaskWrapper}{@link * @param <TASK_ENTITY> {@link DTaskWrapper}{@link UTaskWrapper}{@link
* DGTaskWrapper} * DGTaskWrapper}
* @return {@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask} * @return {@link SingleDownloadTask}{@link UploadTask}{@link DownloadGroupTask}
*/ */
<TASK_ENTITY extends AbsTaskWrapper, SCHEDULER extends ISchedulers> ITask createTask( <TASK_ENTITY extends AbsTaskWrapper, SCHEDULER extends ISchedulers> ITask createTask(
TASK_ENTITY entity, SCHEDULER schedulers) { TASK_ENTITY entity, SCHEDULER schedulers) {
@ -96,8 +96,8 @@ class TaskFactory {
* @param entity 下载任务实体{@link DTaskWrapper} * @param entity 下载任务实体{@link DTaskWrapper}
* @param schedulers {@link ISchedulers} * @param schedulers {@link ISchedulers}
*/ */
private DownloadTask createDownloadTask(DTaskWrapper entity, ISchedulers schedulers) { private SingleDownloadTask createDownloadTask(DTaskWrapper entity, ISchedulers schedulers) {
DownloadTask.Builder builder = new DownloadTask.Builder(entity); SingleDownloadTask.Builder builder = new SingleDownloadTask.Builder(entity);
builder.setOutHandler(schedulers); builder.setOutHandler(schedulers);
return builder.build(); return builder.build();
} }

@ -87,15 +87,15 @@ object HttpUtil {
Timber.e("invalid url, ${option.sourUrl}") Timber.e("invalid url, ${option.sourUrl}")
return false return false
} }
if (option.savePathUri == null) { if (option.savePathDir == null) {
Timber.e("save path is null") Timber.e("save path is null")
return false return false
} }
if (!FileUtils.uriEffective(option.savePathUri)) { if (!FileUtils.uriEffective(option.savePathDir)) {
Timber.e("invalid uri, ${option.savePathUri}") Timber.e("invalid uri, ${option.savePathDir}")
return false return false
} }
if (!FileUtils.uriIsDir(option.savePathUri!!)){ if (!FileUtils.uriIsDir(option.savePathDir!!)){
Timber.e("invalid uri, that path not a dir") Timber.e("invalid uri, that path not a dir")
return false return false
} }

@ -57,7 +57,7 @@ class HttpBlockThreadInterceptor : ITaskInterceptor {
) else HttpDBTaskAdapter( ) else HttpDBTaskAdapter(
threadConfig threadConfig
), ),
handler = blockManager.getHandler(), handler = blockManager.handler,
record = it record = it
) )
) )

@ -24,10 +24,11 @@ import com.arialyy.aria.core.task.TaskChain
import com.arialyy.aria.core.task.TaskResp import com.arialyy.aria.core.task.TaskResp
import com.arialyy.aria.http.HttpTaskOption import com.arialyy.aria.http.HttpTaskOption
import com.arialyy.aria.orm.entity.BlockRecord import com.arialyy.aria.orm.entity.BlockRecord
import com.arialyy.aria.orm.entity.DEntity
import com.arialyy.aria.orm.entity.TaskRecord import com.arialyy.aria.orm.entity.TaskRecord
import com.arialyy.aria.util.BlockUtil import com.arialyy.aria.util.BlockUtil
import com.arialyy.aria.util.FileUri
import com.arialyy.aria.util.FileUtils import com.arialyy.aria.util.FileUtils
import com.arialyy.aria.util.uri
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import timber.log.Timber import timber.log.Timber
@ -53,17 +54,11 @@ internal class HttpDBlockInterceptor : ITaskInterceptor {
return TaskResp(TaskResp.CODE_INTERRUPT) return TaskResp(TaskResp.CODE_INTERRUPT)
} }
val savePath = FileUri.getPathByUri(task.getTaskOption(HttpTaskOption::class.java).savePathUri)
if (savePath.isNullOrEmpty()) {
Timber.e("saveUri is null")
return TaskResp(TaskResp.CODE_INTERRUPT)
}
// if task not support resume, don't save record // if task not support resume, don't save record
if (task.taskState.fileSize == 0L) { if (task.taskState.fileSize == 0L) {
blockManager.setBlockNum(1) blockManager.setBlockNum(1)
// if block exist, delete the existed block // if block exist, delete the existed block
removeBlock() removeBlock(0)
return chain.proceed(chain.getTask()) return chain.proceed(chain.getTask())
} }
val blockNum = checkRecord() val blockNum = checkRecord()
@ -77,12 +72,13 @@ internal class HttpDBlockInterceptor : ITaskInterceptor {
return chain.proceed(chain.getTask()) return chain.proceed(chain.getTask())
} }
private fun removeBlock() { private fun removeBlock(blockId: Int) {
val saveUri = task.getTaskOption(HttpTaskOption::class.java).savePathUri val saveUri = task.taskState.getEntity(DEntity::class.java).getFilePath().uri()
if (!FileUtils.uriEffective(saveUri)) { if (!FileUtils.uriEffective(saveUri)) {
Timber.d("invalid uri: ${saveUri}")
return return
} }
val blockF = File(BlockUtil.getBlockPathFormUri(saveUri!!, 0)) val blockF = File(BlockUtil.getBlockPathFormUri(saveUri, blockId))
if (blockF.exists()) { if (blockF.exists()) {
blockF.delete() blockF.delete()
} }
@ -101,8 +97,8 @@ internal class HttpDBlockInterceptor : ITaskInterceptor {
val blockNumInfo = BlockUtil.getBlockNum(task.taskState.fileSize) val blockNumInfo = BlockUtil.getBlockNum(task.taskState.fileSize)
val taskRecord = TaskRecord( val taskRecord = TaskRecord(
taskKey = task.filePath, taskKey = task.filePath,
filePath = option.savePathUri!!, filePath = task.filePath.uri(),
taskType = ITask.DOWNLOAD, taskType = ITask.SINGLE_DOWNLOAD,
fileLen = task.taskState.fileSize, fileLen = task.taskState.fileSize,
blockNum = blockNumInfo.first, blockNum = blockNumInfo.first,
blockSize = task.taskState.blockSize blockSize = task.taskState.blockSize
@ -110,7 +106,7 @@ internal class HttpDBlockInterceptor : ITaskInterceptor {
taskRecord.blockList.addAll( taskRecord.blockList.addAll(
BlockUtil.createBlockRecord( BlockUtil.createBlockRecord(
task.getTaskOption(HttpTaskOption::class.java).savePathUri!!, task.taskState.getEntity(DEntity::class.java).getFilePath(),
task.taskState.fileSize task.taskState.fileSize
) )
) )

@ -15,6 +15,7 @@
*/ */
package com.arialyy.aria.http.download package com.arialyy.aria.http.download
import android.net.Uri
import com.arialyy.aria.core.DuaContext import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.task.ITaskInterceptor import com.arialyy.aria.core.task.ITaskInterceptor
import com.arialyy.aria.core.task.TaskCachePool import com.arialyy.aria.core.task.TaskCachePool
@ -33,16 +34,16 @@ class HttpDCheckInterceptor : ITaskInterceptor {
/** /**
* find DEntity, if that not exist, create and save it * find DEntity, if that not exist, create and save it
*/ */
private suspend fun findDEntityBySavePath(option: HttpTaskOption): DEntity { private suspend fun findDEntityByUrl(option: HttpTaskOption): DEntity {
val savePath = option.savePathUri
val dao = DuaContext.getServiceManager().getDbService().getDuaDb().getDEntityDao() val dao = DuaContext.getServiceManager().getDbService().getDuaDb().getDEntityDao()
val de = dao.queryDEntityBySavePath(savePath.toString()) val de = dao.queryDEntityByUrl(option.sourUrl ?: "")
if (de != null) { if (de != null) {
return de return de
} }
// Set the file save path only after getting the file name
val newDe = DEntity( val newDe = DEntity(
sourceUrl = option.sourUrl!!, sourceUrl = option.sourUrl!!,
savePath = savePath!!, savePath = Uri.EMPTY,
) )
dao.insert(newDe) dao.insert(newDe)
return newDe return newDe
@ -50,8 +51,8 @@ class HttpDCheckInterceptor : ITaskInterceptor {
override suspend fun interceptor(chain: TaskChain): TaskResp { override suspend fun interceptor(chain: TaskChain): TaskResp {
val option = chain.getTask().getTaskOption(HttpTaskOption::class.java) val option = chain.getTask().getTaskOption(HttpTaskOption::class.java)
val dEntity = findDEntityBySavePath(option) val dEntity = findDEntityByUrl(option)
chain.getTask().taskState.entity = dEntity chain.getTask().taskState.setEntity(dEntity)
TaskCachePool.putEntity(chain.getTask().taskId, dEntity) TaskCachePool.putEntity(chain.getTask().taskId, dEntity)
return chain.proceed(chain.getTask()) return chain.proceed(chain.getTask())
} }

@ -19,7 +19,7 @@ import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.inf.IEntity import com.arialyy.aria.core.inf.IEntity
import com.arialyy.aria.core.listener.AbsEventListener import com.arialyy.aria.core.listener.AbsEventListener
import com.arialyy.aria.core.listener.ISchedulers import com.arialyy.aria.core.listener.ISchedulers
import com.arialyy.aria.core.task.DownloadTask import com.arialyy.aria.core.task.SingleDownloadTask
import com.arialyy.aria.core.task.TaskCachePool import com.arialyy.aria.core.task.TaskCachePool
import com.arialyy.aria.exception.AriaException import com.arialyy.aria.exception.AriaException
import com.arialyy.aria.orm.entity.DEntity import com.arialyy.aria.orm.entity.DEntity
@ -31,7 +31,7 @@ import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
import java.io.File import java.io.File
class HttpDEventListener(task: DownloadTask) : AbsEventListener(task) { class HttpDEventListener(task: SingleDownloadTask) : AbsEventListener(task) {
/** /**
* merge block file, if merge fail call [onFail] * merge block file, if merge fail call [onFail]

@ -80,7 +80,7 @@ internal class HttpDHeaderInterceptor : ITaskInterceptor {
getOptionAdapter().isSupportResume && fileSize > BlockRecord.BLOCK_SIZE getOptionAdapter().isSupportResume && fileSize > BlockRecord.BLOCK_SIZE
val fileName = val fileName =
getFileName(if (taskOption.redirectUrl.isNullOrEmpty()) taskOption.sourUrl!! else taskOption.redirectUrl!!) getFileName(if (taskOption.redirectUrl.isNullOrEmpty()) taskOption.sourUrl!! else taskOption.redirectUrl!!)
(task.taskState.entity as DEntity?)?.let { task.taskState.getEntity(DEntity::class.java).let {
it.fileName = fileName it.fileName = fileName
it.update() it.update()
} }

@ -22,7 +22,7 @@ import com.arialyy.aria.core.command.CancelCmd
import com.arialyy.aria.core.command.StartCmd import com.arialyy.aria.core.command.StartCmd
import com.arialyy.aria.core.command.StopCmd import com.arialyy.aria.core.command.StopCmd
import com.arialyy.aria.core.processor.IHttpFileLenAdapter import com.arialyy.aria.core.processor.IHttpFileLenAdapter
import com.arialyy.aria.core.task.DownloadTask import com.arialyy.aria.core.task.SingleDownloadTask
import com.arialyy.aria.core.task.ITaskInterceptor import com.arialyy.aria.core.task.ITaskInterceptor
import com.arialyy.aria.core.task.TaskCachePool import com.arialyy.aria.core.task.TaskCachePool
import com.arialyy.aria.http.HttpBaseStartController import com.arialyy.aria.http.HttpBaseStartController
@ -88,22 +88,22 @@ class HttpDStartController(target: Any, val url: String) : HttpBaseStartControll
* *
*/ */
fun setSavePath(savePath: Uri): HttpDStartController { fun setSavePath(savePath: Uri): HttpDStartController {
httpTaskOption.savePathUri = savePath httpTaskOption.savePathDir = savePath
return this return this
} }
private fun getTask(createNewTask: Boolean = true): DownloadTask? { private fun getTask(createNewTask: Boolean = true): SingleDownloadTask? {
if (HttpUtil.checkHttpDParams(httpTaskOption)) { if (HttpUtil.checkHttpDParams(httpTaskOption)) {
throw IllegalArgumentException("invalid params") throw IllegalArgumentException("invalid params")
} }
val tempTask = TaskCachePool.getTaskByKey(url) val tempTask = TaskCachePool.getTaskByKey(url)
if (tempTask != null) { if (tempTask != null) {
return tempTask as DownloadTask return tempTask as SingleDownloadTask
} }
if (!createNewTask) { if (!createNewTask) {
return null return null
} }
val task = DownloadTask(httpTaskOption) val task = SingleDownloadTask(httpTaskOption)
task.adapter = HttpDTaskAdapter() task.adapter = HttpDTaskAdapter()
TaskCachePool.putTask(task) TaskCachePool.putTask(task)
return task return task

@ -15,88 +15,51 @@
*/ */
package com.arialyy.aria.http.download package com.arialyy.aria.http.download
import android.os.Looper import com.arialyy.aria.core.inf.IBlockManager
import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.task.AbsTaskAdapter import com.arialyy.aria.core.task.AbsTaskAdapter
import com.arialyy.aria.core.task.BlockManager import com.arialyy.aria.core.task.SingleDownloadTask
import com.arialyy.aria.core.task.DownloadTask
import com.arialyy.aria.core.task.TaskResp
import com.arialyy.aria.core.task.ThreadTaskManager2
import com.arialyy.aria.exception.AriaException
import com.arialyy.aria.http.HttpTaskOption import com.arialyy.aria.http.HttpTaskOption
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
/** /**
* @Author laoyuyu * @Author laoyuyu
* @Description * @Description
* @Date 1:47 PM 2023/1/28 * @Date 1:47 PM 2023/1/28
**/ **/
internal class HttpDTaskAdapter : AbsTaskAdapter() { class HttpDTaskAdapter(val isSubTask: Boolean = false) : AbsTaskAdapter() {
private var blockManager: BlockManager? = null private val delegate: ITaskAdapterDelegate
init { init {
getTask().getTaskOption(HttpTaskOption::class.java).eventListener = getTask().getTaskOption(HttpTaskOption::class.java).eventListener =
HttpDEventListener(getTask() as DownloadTask) HttpDEventListener(getTask() as SingleDownloadTask)
delegate = if (isSubTask) {
SubTaskDelegate(this)
} else {
SingleTaskDelegate(this)
}
} }
override fun getTaskManager(): BlockManager { fun setBlockManager(blockManager: IBlockManager) {
if (blockManager == null) { delegate.setBlockManager(blockManager)
blockManager = BlockManager(getTask())
} }
return blockManager!!
override fun getBlockManager(): IBlockManager {
return delegate.getBlockManager()
} }
override fun isRunning(): Boolean { override fun isRunning(): Boolean {
return getTaskManager().isRunning() return delegate.isRunning()
} }
override fun cancel() { override fun cancel() {
if (getTaskManager().isCanceled()) { delegate.cancel()
Timber.w("task already canceled, taskId: ${getTask().taskId}")
return
}
DuaContext.duaScope.launch(Dispatchers.IO) {
ThreadTaskManager2.stopThreadTask(getTask().taskId, true)
}
} }
override fun stop() { override fun stop() {
if (getTaskManager().isStopped()) { delegate.stop()
Timber.w("task already stopped, taskId: ${getTask().taskId}")
return
}
DuaContext.duaScope.launch(Dispatchers.IO) {
ThreadTaskManager2.stopThreadTask(getTask().taskId)
}
} }
override fun start() { override fun start() {
getTask().getTaskOption(HttpTaskOption::class.java).taskInterceptor.let { delegate.start()
if (it.isNotEmpty()) {
addInterceptors(it)
}
}
DuaContext.duaScope.launch(Dispatchers.IO) {
Looper.prepare()
blockManager?.setLooper()
addCoreInterceptor(HttpDCheckInterceptor())
addCoreInterceptor(TimerInterceptor())
addCoreInterceptor(HttpDHeaderInterceptor())
addCoreInterceptor(HttpDBlockInterceptor())
addCoreInterceptor(HttpBlockThreadInterceptor())
val resp = interceptor()
if (resp == null || resp.code != TaskResp.CODE_SUCCESS) {
getTask().getTaskOption(HttpTaskOption::class.java).eventListener.onFail(
false,
AriaException("start task fail, task interrupt, code: ${resp?.code ?: TaskResp.CODE_INTERRUPT}")
)
blockManager?.stop()
return@launch
}
Looper.loop()
}
} }
} }

@ -16,12 +16,12 @@
package com.arialyy.aria.http.download package com.arialyy.aria.http.download
import com.arialyy.aria.core.listener.ITaskStatusListener import com.arialyy.aria.core.listener.ITaskStatusListener
import com.arialyy.aria.core.task.DownloadTask import com.arialyy.aria.core.task.SingleDownloadTask
/** /**
* @Author laoyuyu * @Author laoyuyu
* @Description * @Description
* @Date 12:24 PM 2023/1/22 * @Date 12:24 PM 2023/1/22
**/ **/
class HttpDownloadListener : ITaskStatusListener<DownloadTask> { class HttpDownloadListener : ITaskStatusListener<SingleDownloadTask> {
} }

@ -0,0 +1,51 @@
/*
* 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.http.download
import com.arialyy.aria.core.inf.IBlockManager
/**
* @Author laoyuyu
* @Description
* @Date 11:37 2023/3/12
**/
internal interface ITaskAdapterDelegate {
/**
* 任务是否正在执行
*
* @return `true` 任务正在执行
*/
fun isRunning(): Boolean
/**
* 取消
*/
fun cancel()
/**
* 停止
*/
fun stop()
/**
* 开始
*/
fun start()
fun setBlockManager(blockManager: IBlockManager)
fun getBlockManager(): IBlockManager
}

@ -0,0 +1,100 @@
/*
* 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.http.download
import android.os.Looper
import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.inf.IBlockManager
import com.arialyy.aria.core.task.DBlockManager
import com.arialyy.aria.core.task.TaskResp
import com.arialyy.aria.core.task.ThreadTaskManager2
import com.arialyy.aria.exception.AriaException
import com.arialyy.aria.http.HttpTaskOption
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
/**
* @Author laoyuyu
* @Description
* @Date 11:32 2023/3/12
**/
internal class SingleTaskDelegate(val adapter: HttpDTaskAdapter) : ITaskAdapterDelegate {
private val blockManager = DBlockManager(adapter.getTask())
init {
ThreadTaskManager2.putThreadManager(adapter.getTask().taskId, blockManager)
}
override fun isRunning(): Boolean {
return blockManager.isRunning()
}
override fun cancel() {
if (blockManager.isCanceled()) {
Timber.w("task already canceled, taskId: ${adapter.getTask().taskId}")
return
}
DuaContext.duaScope.launch(Dispatchers.IO) {
ThreadTaskManager2.stopThreadTask(adapter.getTask().taskId, true)
}
}
override fun stop() {
if (blockManager.isStopped()) {
Timber.w("task already stopped, taskId: ${adapter.getTask().taskId}")
return
}
DuaContext.duaScope.launch(Dispatchers.IO) {
ThreadTaskManager2.stopThreadTask(adapter.getTask().taskId)
}
}
override fun start() {
adapter.getTask().getTaskOption(HttpTaskOption::class.java).taskInterceptor.let {
if (it.isNotEmpty()) {
adapter.addInterceptors(it)
}
}
DuaContext.duaScope.launch(Dispatchers.IO) {
Looper.prepare()
blockManager.setLooper()
adapter.addCoreInterceptor(HttpDCheckInterceptor())
adapter.addCoreInterceptor(TimerInterceptor())
adapter.addCoreInterceptor(HttpDHeaderInterceptor())
adapter.addCoreInterceptor(HttpDBlockInterceptor())
adapter.addCoreInterceptor(HttpBlockThreadInterceptor())
val resp = adapter.interceptor()
if (resp == null || resp.code != TaskResp.CODE_SUCCESS) {
adapter.getTask().getTaskOption(HttpTaskOption::class.java).eventListener.onFail(
false,
AriaException("start task fail, task interrupt, code: ${resp?.code ?: TaskResp.CODE_INTERRUPT}")
)
blockManager.stop()
return@launch
}
Looper.loop()
}
}
override fun setBlockManager(blockManager: IBlockManager) {
throw UnsupportedOperationException("Single task does not support setting up a block manager")
}
override fun getBlockManager(): IBlockManager {
return blockManager
}
}

@ -0,0 +1,51 @@
/*
* 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.http.download
import com.arialyy.aria.core.inf.IBlockManager
/**
* @Author laoyuyu
* @Description
* @Date 11:35 2023/3/12
**/
internal class SubTaskDelegate(val adapter: HttpDTaskAdapter) : ITaskAdapterDelegate {
private lateinit var blockManager: IBlockManager
override fun isRunning(): Boolean {
TODO("Not yet implemented")
}
override fun cancel() {
TODO("Not yet implemented")
}
override fun stop() {
TODO("Not yet implemented")
}
override fun start() {
TODO("Not yet implemented")
}
override fun setBlockManager(blockManager: IBlockManager) {
this.blockManager = blockManager
}
override fun getBlockManager(): IBlockManager {
return blockManager
}
}

@ -16,11 +16,11 @@
package com.arialyy.aria.http.download package com.arialyy.aria.http.download
import com.arialyy.aria.core.inf.ITaskOption import com.arialyy.aria.core.inf.ITaskOption
import com.arialyy.aria.core.task.ThreadTaskManager2
import com.arialyy.aria.core.task.ITask import com.arialyy.aria.core.task.ITask
import com.arialyy.aria.core.task.ITaskInterceptor import com.arialyy.aria.core.task.ITaskInterceptor
import com.arialyy.aria.core.task.TaskChain import com.arialyy.aria.core.task.TaskChain
import com.arialyy.aria.core.task.TaskResp import com.arialyy.aria.core.task.TaskResp
import com.arialyy.aria.core.task.ThreadTaskManager2
import timber.log.Timber import timber.log.Timber
import java.util.concurrent.ScheduledThreadPoolExecutor import java.util.concurrent.ScheduledThreadPoolExecutor
import java.util.concurrent.TimeUnit.MILLISECONDS import java.util.concurrent.TimeUnit.MILLISECONDS
@ -51,13 +51,17 @@ open class TimerInterceptor : ITaskInterceptor {
closeTimer() closeTimer()
try { try {
mTimer = ScheduledThreadPoolExecutor(1) mTimer = ScheduledThreadPoolExecutor(1)
val blockManager = chain.blockManager val threadManager = ThreadTaskManager2.getThreadManager(chain.getTask().taskId)
if (threadManager == null) {
Timber.e("thread manager is null, start timer fail")
return false
}
mTimer.scheduleWithFixedDelay(object : Runnable { mTimer.scheduleWithFixedDelay(object : Runnable {
override fun run() { override fun run() {
// 线程池中是不抛异常的,没有日志,很难定位问题,需要手动try-catch // 线程池中是不抛异常的,没有日志,很难定位问题,需要手动try-catch
try { try {
if (blockManager.isCompleted() if (threadManager.isCompleted()
|| blockManager.hasFailedTask() || threadManager.hasFailedTask()
|| !isRunning(chain.getTask()) || !isRunning(chain.getTask())
) { ) {
ThreadTaskManager2.stopThreadTask(chain.getTask().taskId) ThreadTaskManager2.stopThreadTask(chain.getTask().taskId)
@ -66,7 +70,7 @@ open class TimerInterceptor : ITaskInterceptor {
} }
if (chain.getTask().taskState.curProgress >= 0) { if (chain.getTask().taskState.curProgress >= 0) {
chain.getTask().getTaskOption(ITaskOption::class.java).eventListener.onProgress( chain.getTask().getTaskOption(ITaskOption::class.java).eventListener.onProgress(
blockManager.getCurrentProgress() threadManager.getCurrentProgress()
) )
return return
} }

@ -28,7 +28,7 @@ import com.arialyy.aria.http.HttpOption
class HttpUStartController(target: Any, val filePath: Uri) : HttpBaseStartController(target) { class HttpUStartController(target: Any, val filePath: Uri) : HttpBaseStartController(target) {
init { init {
httpTaskOption.savePathUri = filePath httpTaskOption.savePathDir = filePath
} }
override fun setTaskInterceptor(taskInterceptor: ITaskInterceptor): HttpUStartController { override fun setTaskInterceptor(taskInterceptor: ITaskInterceptor): HttpUStartController {

@ -19,7 +19,7 @@ import android.os.Looper
import com.arialyy.aria.core.DuaContext import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.inf.ITaskManager import com.arialyy.aria.core.inf.ITaskManager
import com.arialyy.aria.core.task.AbsTaskAdapter import com.arialyy.aria.core.task.AbsTaskAdapter
import com.arialyy.aria.core.task.BlockManager import com.arialyy.aria.core.task.DBlockManager
import com.arialyy.aria.core.task.TaskResp import com.arialyy.aria.core.task.TaskResp
import com.arialyy.aria.exception.AriaException import com.arialyy.aria.exception.AriaException
import com.arialyy.aria.http.HttpTaskOption import com.arialyy.aria.http.HttpTaskOption
@ -34,11 +34,11 @@ import kotlinx.coroutines.launch
* @Date 9:21 PM 2023/2/21 * @Date 9:21 PM 2023/2/21
**/ **/
class HttpUTaskAdapter : AbsTaskAdapter() { class HttpUTaskAdapter : AbsTaskAdapter() {
private var blockManager: BlockManager? = null private var blockManager: DBlockManager? = null
override fun getTaskManager(): ITaskManager { override fun getBlockManager(): ITaskManager {
if (blockManager == null) { if (blockManager == null) {
blockManager = BlockManager(getTask()) blockManager = DBlockManager(getTask())
} }
return blockManager!! return blockManager!!
} }

@ -51,7 +51,7 @@ internal class HttpDGCheckInterceptor : ITaskInterceptor {
taskOption = task.getTaskOption(HttpTaskOption::class.java) taskOption = task.getTaskOption(HttpTaskOption::class.java)
optionAdapter = taskOption.getOptionAdapter(HttpDGOptionAdapter::class.java) optionAdapter = taskOption.getOptionAdapter(HttpDGOptionAdapter::class.java)
if (checkParams(taskOption.savePathUri)) { if (checkParams(taskOption.savePathDir)) {
return TaskResp(TaskResp.CODE_INTERRUPT) return TaskResp(TaskResp.CODE_INTERRUPT)
} }
@ -65,7 +65,7 @@ internal class HttpDGCheckInterceptor : ITaskInterceptor {
* @return false interrupt task * @return false interrupt task
*/ */
private suspend fun checkRecord(): Boolean { private suspend fun checkRecord(): Boolean {
val savePath = taskOption.savePathUri val savePath = taskOption.savePathDir
val dgE = dgDao.queryDGEntityByPath(savePath.toString()) val dgE = dgDao.queryDGEntityByPath(savePath.toString())
if (dgE == null) { if (dgE == null) {
createNewEntity() createNewEntity()
@ -93,13 +93,13 @@ internal class HttpDGCheckInterceptor : ITaskInterceptor {
Timber.d("create new task") Timber.d("create new task")
// create sub task record // create sub task record
val dgEntity = DGEntity( val dgEntity = DGEntity(
savePath = taskOption.savePathUri!!, savePath = taskOption.savePathDir!!,
urls = optionAdapter.subUrlList.toList(), urls = optionAdapter.subUrlList.toList(),
subNameList = optionAdapter.subNameList subNameList = optionAdapter.subNameList
) )
val subTask = mutableListOf<DEntity>() val subTask = mutableListOf<DEntity>()
val dir = File(FileUri.getPathByUri(taskOption.savePathUri)!!) val dir = File(FileUri.getPathByUri(taskOption.savePathDir)!!)
optionAdapter.subUrlList.forEachIndexed { index, it -> optionAdapter.subUrlList.forEachIndexed { index, it ->
val subName = if (optionAdapter.subNameList.isNotEmpty()) { val subName = if (optionAdapter.subNameList.isNotEmpty()) {
optionAdapter.subNameList[index] optionAdapter.subNameList[index]
@ -119,6 +119,7 @@ internal class HttpDGCheckInterceptor : ITaskInterceptor {
) )
} }
dgEntity.subList.addAll(subTask) dgEntity.subList.addAll(subTask)
task.taskState.setEntity(dgEntity)
dgDao.insert(dgEntity) dgDao.insert(dgEntity)
return true return true

@ -16,14 +16,13 @@
package com.arialyy.dua.group package com.arialyy.dua.group
import com.arialyy.aria.core.listener.AbsEventListener import com.arialyy.aria.core.listener.AbsEventListener
import com.arialyy.aria.core.task.DownloadGroupTask
/** /**
* @Author laoyuyu * @Author laoyuyu
* @Description * @Description
* @Date 9:15 PM 2023/3/6 * @Date 9:15 PM 2023/3/6
**/ **/
internal class HttpDGEventListener(task: DownloadGroupTask) : AbsEventListener(task) { internal class HttpDGEventListener(task: HttpGroupTask) : AbsEventListener(task) {
override fun onComplete() { override fun onComplete() {
TODO("Not yet implemented") TODO("Not yet implemented")
} }

@ -17,7 +17,6 @@ package com.arialyy.dua.group
import android.net.Uri import android.net.Uri
import com.arialyy.aria.core.command.StartCmd import com.arialyy.aria.core.command.StartCmd
import com.arialyy.aria.core.task.DownloadGroupTask
import com.arialyy.aria.core.task.ITaskInterceptor import com.arialyy.aria.core.task.ITaskInterceptor
import com.arialyy.aria.core.task.TaskCachePool import com.arialyy.aria.core.task.TaskCachePool
import com.arialyy.aria.http.HttpBaseStartController import com.arialyy.aria.http.HttpBaseStartController
@ -37,7 +36,7 @@ class HttpDGStartController(target: Any, val savePath: Uri) : HttpBaseStartContr
init { init {
httpTaskOption.taskOptionAdapter = optionAdapter httpTaskOption.taskOptionAdapter = optionAdapter
httpTaskOption.savePathUri = savePath httpTaskOption.savePathDir = savePath
} }
override fun setTaskInterceptor(taskInterceptor: ITaskInterceptor): HttpDGStartController { override fun setTaskInterceptor(taskInterceptor: ITaskInterceptor): HttpDGStartController {
@ -68,15 +67,15 @@ class HttpDGStartController(target: Any, val savePath: Uri) : HttpBaseStartContr
return this return this
} }
private fun getTask(createNewTask: Boolean = true): DownloadGroupTask { private fun getTask(createNewTask: Boolean = true): HttpGroupTask {
if (HttpUtil.checkHttpDParams(httpTaskOption)) { if (HttpUtil.checkHttpDParams(httpTaskOption)) {
throw IllegalArgumentException("invalid params") throw IllegalArgumentException("invalid params")
} }
val temp = TaskCachePool.getTaskByKey(savePath.toString()) val temp = TaskCachePool.getTaskByKey(savePath.toString())
if (temp != null) { if (temp != null) {
return temp as DownloadGroupTask return temp as HttpGroupTask
} }
val task = DownloadGroupTask(httpTaskOption) val task = HttpGroupTask(httpTaskOption)
task.adapter = HttpDGroupAdapter() task.adapter = HttpDGroupAdapter()
TaskCachePool.putTask(task) TaskCachePool.putTask(task)
return task return task

@ -0,0 +1,73 @@
/*
* 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.dua.group
import com.arialyy.aria.core.common.TaskOption
import com.arialyy.aria.core.task.ITask
import com.arialyy.aria.core.task.ITaskInterceptor
import com.arialyy.aria.core.task.SingleDownloadTask
import com.arialyy.aria.core.task.TaskChain
import com.arialyy.aria.core.task.TaskResp
import com.arialyy.aria.http.HttpTaskOption
import com.arialyy.aria.http.download.HttpDTaskAdapter
import com.arialyy.aria.orm.entity.DGEntity
/**
* Subtasks do not support chunking
* @Author laoyuyu
* @Description
* @Date 08:51 2023/3/12
**/
internal class HttpDGSubTaskInterceptor : ITaskInterceptor {
private lateinit var task: ITask
private lateinit var optionAdapter: HttpDGOptionAdapter
private lateinit var taskOption: HttpTaskOption
override suspend fun interceptor(chain: TaskChain): TaskResp {
task = chain.getTask()
taskOption = task.getTaskOption(HttpTaskOption::class.java)
optionAdapter = taskOption.getOptionAdapter(HttpDGOptionAdapter::class.java)
val subList = createSubTask(chain)
return TaskResp(TaskResp.CODE_SUCCESS)
}
private fun startSubTask(subList: List<SingleDownloadTask>) {
subList.forEach {
}
}
private fun createSubTask(chain: TaskChain): List<SingleDownloadTask> {
val subTaskList = mutableListOf<SingleDownloadTask>()
task.taskState.getEntity(DGEntity::class.java).subList.forEach {
val tp = TaskOption()
tp.sourUrl = it.sourceUrl
tp.savePathDir = taskOption.savePathDir
tp.threadNum = 1
tp.eventListener = HttpSubListener()
val subTask = SingleDownloadTask(tp)
val subAdapter = HttpDTaskAdapter(true)
subAdapter.setBlockManager(HttpSubBlockManager(chain.blockManager.handler))
subTask.adapter = subAdapter
subTaskList.add(subTask)
}
return subTaskList
}
}

@ -62,6 +62,10 @@ internal class HttpDGTaskManager : ITaskManager {
override fun stop() { override fun stop() {
} }
override fun cancel() {
}
override fun isCompleted(): Boolean { override fun isCompleted(): Boolean {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
@ -82,7 +86,7 @@ internal class HttpDGTaskManager : ITaskManager {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
override fun getHandler(): Handler { fun getHandler(): Handler {
return handler return handler
} }

@ -17,14 +17,12 @@ package com.arialyy.dua.group
import android.os.Looper import android.os.Looper
import com.arialyy.aria.core.DuaContext import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.inf.IBlockManager
import com.arialyy.aria.core.inf.ITaskManager import com.arialyy.aria.core.inf.ITaskManager
import com.arialyy.aria.core.task.AbsTaskAdapter import com.arialyy.aria.core.task.AbsTaskAdapter
import com.arialyy.aria.core.task.DownloadGroupTask
import com.arialyy.aria.core.task.TaskResp import com.arialyy.aria.core.task.TaskResp
import com.arialyy.aria.exception.AriaException import com.arialyy.aria.exception.AriaException
import com.arialyy.aria.http.HttpTaskOption import com.arialyy.aria.http.HttpTaskOption
import com.arialyy.aria.http.download.HttpBlockThreadInterceptor
import com.arialyy.aria.http.download.HttpDCheckInterceptor
import com.arialyy.aria.http.download.TimerInterceptor import com.arialyy.aria.http.download.TimerInterceptor
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -42,10 +40,10 @@ internal class HttpDGroupAdapter : AbsTaskAdapter() {
init { init {
getTask().getTaskOption(HttpTaskOption::class.java).eventListener = getTask().getTaskOption(HttpTaskOption::class.java).eventListener =
HttpDGEventListener(getTask() as DownloadGroupTask) HttpDGEventListener(getTask() as HttpGroupTask)
} }
override fun getTaskManager(): ITaskManager { override fun getBlockManager(): IBlockManager {
return taskManager return taskManager
} }
@ -54,14 +52,14 @@ internal class HttpDGroupAdapter : AbsTaskAdapter() {
} }
override fun cancel() { override fun cancel() {
if (getTaskManager().isCanceled()) { if (getBlockManager().isCanceled()) {
Timber.w("task already canceled, taskId: ${getTask().taskId}") Timber.w("task already canceled, taskId: ${getTask().taskId}")
return return
} }
} }
override fun stop() { override fun stop() {
if (getTaskManager().isStopped()) { if (getBlockManager().isStopped()) {
Timber.w("task already stopped, taskId: ${getTask().taskId}") Timber.w("task already stopped, taskId: ${getTask().taskId}")
return return
} }
@ -78,7 +76,7 @@ internal class HttpDGroupAdapter : AbsTaskAdapter() {
taskManager.setLooper() taskManager.setLooper()
addCoreInterceptor(HttpDGCheckInterceptor()) addCoreInterceptor(HttpDGCheckInterceptor())
addCoreInterceptor(TimerInterceptor()) addCoreInterceptor(TimerInterceptor())
addCoreInterceptor() addCoreInterceptor(HttpDGSubTaskInterceptor())
val resp = interceptor() val resp = interceptor()
if (resp == null || resp.code != TaskResp.CODE_SUCCESS) { if (resp == null || resp.code != TaskResp.CODE_SUCCESS) {

@ -13,24 +13,25 @@
* 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.task; package com.arialyy.dua.group;
import com.arialyy.aria.core.common.TaskOption; import com.arialyy.aria.core.common.TaskOption;
import com.arialyy.aria.core.inf.ITaskOption; import com.arialyy.aria.core.inf.ITaskOption;
import com.arialyy.aria.core.task.AbsTask;
import java.util.Objects; import java.util.Objects;
/** /**
* Created by AriaL on 2017/6/27. * Created by AriaL on 2017/6/27.
* 任务组任务 * 任务组任务
*/ */
public class DownloadGroupTask extends AbsTask { public class HttpGroupTask extends AbsTask {
public DownloadGroupTask(ITaskOption taskOption) { public HttpGroupTask(ITaskOption taskOption) {
super(taskOption); super(taskOption);
} }
@Override public int getTaskType() { @Override public int getTaskType() {
return DOWNLOAD_GROUP; return HTTP_GROUP;
} }
/** /**
@ -42,6 +43,6 @@ public class DownloadGroupTask extends AbsTask {
} }
@Override public String getFilePath() { @Override public String getFilePath() {
return Objects.requireNonNull(getTaskOption(TaskOption.class).getSavePathUri()).toString(); return Objects.requireNonNull(getTaskOption(TaskOption.class).getSavePathDir()).toString();
} }
} }

@ -0,0 +1,52 @@
/*
* 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.dua.group
import android.os.Handler
import com.arialyy.aria.core.inf.IBlockManager
import com.arialyy.aria.core.task.IThreadTask
import com.arialyy.aria.orm.entity.BlockRecord
/**
* @Author laoyuyu
* @Description
* @Date 10:04 2023/3/12
**/
class HttpSubBlockManager(val handler: Handler) : IBlockManager {
private val unfinishedBlock = mutableListOf<BlockRecord>()
private var blockNum: Int = 1
override fun putUnfinishedBlock(record: BlockRecord) {
unfinishedBlock.add(record)
}
override fun getUnfinishedBlockList(): List<BlockRecord> {
return unfinishedBlock
}
override fun getHandler() = handler
override fun start(threadTaskList: List<IThreadTask>) {
threadTaskList.forEach { tt ->
tt.run()
}
}
override fun setBlockNum(blockNum: Int) {
this.blockNum = blockNum
}
}

@ -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.dua.group
import com.arialyy.aria.core.listener.IEventListener
import com.arialyy.aria.exception.AriaException
/**
* @Author laoyuyu
* @Description
* @Date 10:13 2023/3/12
**/
internal class HttpSubListener : IEventListener {
override fun onPre() {
TODO("Not yet implemented")
}
override fun onStart(startLocation: Long) {
TODO("Not yet implemented")
}
override fun onResume(resumeLocation: Long) {
TODO("Not yet implemented")
}
override fun onProgress(currentLocation: Long) {
TODO("Not yet implemented")
}
override fun onStop(stopLocation: Long) {
TODO("Not yet implemented")
}
override fun onComplete() {
TODO("Not yet implemented")
}
override fun onCancel() {
TODO("Not yet implemented")
}
override fun onFail(needRetry: Boolean, e: AriaException?) {
TODO("Not yet implemented")
}
}

@ -76,7 +76,7 @@ public abstract class AbsCmd implements ICmd {
} }
ITaskQueue<?> itq = null; ITaskQueue<?> itq = null;
switch (mTask.getTaskType()) { switch (mTask.getTaskType()) {
case ITask.DOWNLOAD: { case ITask.SINGLE_DOWNLOAD: {
itq = DuaContext.INSTANCE.getServiceManager().getDownloadQueue(); itq = DuaContext.INSTANCE.getServiceManager().getDownloadQueue();
break; break;
} }

@ -25,7 +25,7 @@ public class CmdHelper {
/** /**
* 创建任务命令 * 创建任务命令
* *
* @param taskType {@link ITask#DOWNLOAD}{@link ITask#DOWNLOAD_GROUP}{@link ITask#UPLOAD} * @param taskType {@link ITask#SINGLE_DOWNLOAD}{@link ITask#HTTP_GROUP}{@link ITask#UPLOAD}
*/ */
public static <T extends AbsTaskWrapper> AbsNormalCmd createNormalCmd(T entity, int cmd, public static <T extends AbsTaskWrapper> AbsNormalCmd createNormalCmd(T entity, int cmd,
int taskType) { int taskType) {

@ -17,7 +17,7 @@ package com.arialyy.aria.core.command;
import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.queue.DTaskQueue; import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
@ -46,9 +46,9 @@ final class HighestPriorityCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T>
ALog.e(TAG, "启动任务失败,网络未连接"); ALog.e(TAG, "启动任务失败,网络未连接");
return; return;
} }
DownloadTask task = (DownloadTask) getTask(); SingleDownloadTask task = (SingleDownloadTask) getTask();
if (task == null) { if (task == null) {
task = (DownloadTask) createTask(); task = (SingleDownloadTask) createTask();
} }
if (task != null) { if (task != null) {
((DTaskQueue) mQueue).setTaskHighestPriority(task); ((DTaskQueue) mQueue).setTaskHighestPriority(task);

@ -25,6 +25,10 @@ import com.arialyy.aria.core.inf.ITaskOption
**/ **/
open class TaskOption : ITaskOption() { open class TaskOption : ITaskOption() {
var sourUrl: String? = null var sourUrl: String? = null
var savePathUri: Uri? = null
/**
* The folder where the file is located
*/
var savePathDir: Uri? = null
var redirectUrl: String? = null var redirectUrl: String? = null
} }

@ -15,6 +15,7 @@
*/ */
package com.arialyy.aria.core.inf; package com.arialyy.aria.core.inf;
import android.os.Handler;
import com.arialyy.aria.core.task.IThreadTask; import com.arialyy.aria.core.task.IThreadTask;
import com.arialyy.aria.orm.entity.BlockRecord; import com.arialyy.aria.orm.entity.BlockRecord;
import java.util.List; import java.util.List;
@ -22,7 +23,7 @@ import java.util.List;
/** /**
* 线程任务状态 * 线程任务状态
*/ */
public interface IBlockManager extends ITaskManager { public interface IBlockManager {
void start(List<IThreadTask> threadTaskList); void start(List<IThreadTask> threadTaskList);
@ -32,5 +33,8 @@ public interface IBlockManager extends ITaskManager {
List<BlockRecord> getUnfinishedBlockList(); List<BlockRecord> getUnfinishedBlockList();
/**
* 创建handler 回调
*/
Handler getHandler();
} }

@ -44,6 +44,8 @@ interface ITaskManager {
fun stop() fun stop()
fun cancel()
/** /**
* 任务是否已经完成 * 任务是否已经完成
* *
@ -64,11 +66,6 @@ interface ITaskManager {
fun isRunning(): Boolean fun isRunning(): Boolean
/**
* 创建handler 回调
*/
fun getHandler(): Handler
/** /**
* 是否有失败的快 * 是否有失败的快
* *

@ -31,7 +31,7 @@ public interface ISchedulers extends Handler.Callback, IService {
String ARIA_TASK_INFO_ACTION = "ARIA_TASK_INFO_ACTION"; String ARIA_TASK_INFO_ACTION = "ARIA_TASK_INFO_ACTION";
/** /**
* 广播接收器中通过TASK_TYPE字段获取任务类型 {@link ITask#DOWNLOAD}{@link ITask#DOWNLOAD_GROUP}{@link * 广播接收器中通过TASK_TYPE字段获取任务类型 {@link ITask#SINGLE_DOWNLOAD}{@link ITask#HTTP_GROUP}{@link
* ITask#UPLOAD}{@link ITask#DOWNLOAD_GROUP_SUB} * ITask#UPLOAD}{@link ITask#DOWNLOAD_GROUP_SUB}
*/ */
String TASK_TYPE = "ARIA_TASK_TYPE"; String TASK_TYPE = "ARIA_TASK_TYPE";

@ -20,10 +20,7 @@ import android.os.Looper
import com.arialyy.aria.core.DuaContext import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.inf.ITaskQueue import com.arialyy.aria.core.inf.ITaskQueue
import com.arialyy.aria.core.listener.ISchedulers import com.arialyy.aria.core.listener.ISchedulers
import com.arialyy.aria.core.task.DownloadGroupTask
import com.arialyy.aria.core.task.DownloadTask
import com.arialyy.aria.core.task.ITask import com.arialyy.aria.core.task.ITask
import com.arialyy.aria.core.task.UploadTask
import com.arialyy.aria.exception.AriaException import com.arialyy.aria.exception.AriaException
import timber.log.Timber import timber.log.Timber

@ -15,7 +15,7 @@
*/ */
package com.arialyy.aria.core.task package com.arialyy.aria.core.task
import com.arialyy.aria.core.inf.ITaskManager import com.arialyy.aria.core.inf.IBlockManager
import com.arialyy.aria.core.inf.ITaskAdapter import com.arialyy.aria.core.inf.ITaskAdapter
import com.arialyy.aria.core.listener.IEventListener import com.arialyy.aria.core.listener.IEventListener
import com.arialyy.aria.core.task.ITaskInterceptor.IChain import com.arialyy.aria.core.task.ITaskInterceptor.IChain
@ -37,32 +37,32 @@ abstract class AbsTaskAdapter : ITaskAdapter {
mEventListener = listener mEventListener = listener
} }
protected fun getTask() = mTask fun getTask() = mTask
abstract fun getTaskManager(): ITaskManager abstract fun getBlockManager(): IBlockManager
/** /**
* add user interceptor * add user interceptor
*/ */
protected fun addInterceptors(userInterceptors: List<ITaskInterceptor>) { fun addInterceptors(userInterceptors: List<ITaskInterceptor>) {
mUserInterceptor.addAll(userInterceptors) mUserInterceptor.addAll(userInterceptors)
} }
protected fun addCoreInterceptor(interceptor: ITaskInterceptor) { fun addCoreInterceptor(interceptor: ITaskInterceptor) {
mCoreInterceptor.add(interceptor) mCoreInterceptor.add(interceptor)
} }
/** /**
* if interruption occurred, stop cmd * if interruption occurred, stop cmd
*/ */
protected open suspend fun interceptor(): TaskResp? { open suspend fun interceptor(): TaskResp? {
if (mUserInterceptor.isEmpty()) { if (mUserInterceptor.isEmpty()) {
return null return null
} }
val interceptors: MutableList<ITaskInterceptor> = ArrayList() val interceptors: MutableList<ITaskInterceptor> = ArrayList()
interceptors.addAll(mUserInterceptor) interceptors.addAll(mUserInterceptor)
interceptors.addAll(mCoreInterceptor) interceptors.addAll(mCoreInterceptor)
val chain: IChain = TaskChain(interceptors, 0, mTask, getTaskManager()) val chain: IChain = TaskChain(interceptors, 0, mTask, getBlockManager())
return chain.proceed(mTask) return chain.proceed(mTask)
} }
} }

@ -35,7 +35,7 @@ import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit.MILLISECONDS import java.util.concurrent.TimeUnit.MILLISECONDS
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
class BlockManager(task: ITask) : IBlockManager { class DBlockManager(val task: ITask) : IBlockManager, ITaskManager {
private val unfinishedBlock = mutableListOf<BlockRecord>() private val unfinishedBlock = mutableListOf<BlockRecord>()
private val canceledNum = AtomicInteger(0) // 已经取消的线程的数 private val canceledNum = AtomicInteger(0) // 已经取消的线程的数
private val stoppedNum = AtomicInteger(0) // 已经停止的线程数 private val stoppedNum = AtomicInteger(0) // 已经停止的线程数
@ -49,6 +49,7 @@ class BlockManager(task: ITask) : IBlockManager {
LinkedBlockingQueue(), LinkedBlockingQueue(),
) )
private val dispatcher = threadPool.asCoroutineDispatcher() private val dispatcher = threadPool.asCoroutineDispatcher()
private val threadTaskList = mutableListOf<IThreadTask>()
private var progress: Long = 0 //当前总进度 private var progress: Long = 0 //当前总进度
private lateinit var looper: Looper private lateinit var looper: Looper
@ -113,6 +114,8 @@ class BlockManager(task: ITask) : IBlockManager {
looper.quit() looper.quit()
handler.removeCallbacksAndMessages(null) handler.removeCallbacksAndMessages(null)
scope.cancel() scope.cancel()
threadTaskList.clear()
unfinishedBlock.clear()
} }
override fun putUnfinishedBlock(record: BlockRecord) { override fun putUnfinishedBlock(record: BlockRecord) {
@ -132,6 +135,8 @@ class BlockManager(task: ITask) : IBlockManager {
} }
override fun start(threadTaskList: List<IThreadTask>) { override fun start(threadTaskList: List<IThreadTask>) {
this.threadTaskList.clear()
this.threadTaskList.addAll(threadTaskList)
threadTaskList.forEach { tt -> threadTaskList.forEach { tt ->
scope.launch(dispatcher) { scope.launch(dispatcher) {
tt.run() tt.run()
@ -140,7 +145,15 @@ class BlockManager(task: ITask) : IBlockManager {
} }
override fun stop() { override fun stop() {
quitLooper() threadTaskList.forEach {
it.stop()
}
}
override fun cancel() {
threadTaskList.forEach {
it.cancel()
}
} }
override fun setBlockNum(blockNum: Int) { override fun setBlockNum(blockNum: Int) {

@ -27,7 +27,7 @@ public interface ITask {
/** /**
* 普通下载任务 * 普通下载任务
*/ */
int DOWNLOAD = 1; int SINGLE_DOWNLOAD = 1;
/** /**
* 上传任务 * 上传任务
*/ */
@ -35,7 +35,7 @@ public interface ITask {
/** /**
* 组合任务 * 组合任务
*/ */
int DOWNLOAD_GROUP = 3; int HTTP_GROUP = 3;
/** /**
* 组合任务的子任务 * 组合任务的子任务
*/ */
@ -58,7 +58,7 @@ public interface ITask {
/** /**
* 获取任务类型 * 获取任务类型
* *
* @return {@link #DOWNLOAD}{@link #UPLOAD}{@link #DOWNLOAD_GROUP} * @return {@link #SINGLE_DOWNLOAD}{@link #UPLOAD}{@link #HTTP_GROUP}
*/ */
int getTaskType(); int getTaskType();

@ -17,15 +17,16 @@
package com.arialyy.aria.core.task; package com.arialyy.aria.core.task;
import com.arialyy.aria.core.common.TaskOption; import com.arialyy.aria.core.common.TaskOption;
import com.arialyy.aria.orm.entity.DEntity;
import java.util.Objects; import java.util.Objects;
/** /**
* Created by lyy on 2016/8/11. * Created by lyy on 2016/8/11.
* 下载任务类 * 下载任务类
*/ */
public class DownloadTask extends AbsTask { public class SingleDownloadTask extends AbsTask {
public DownloadTask(TaskOption taskOption) { public SingleDownloadTask(TaskOption taskOption) {
super(taskOption); super(taskOption);
} }
@ -33,7 +34,7 @@ public class DownloadTask extends AbsTask {
* 获取当前下载任务的下载地址 * 获取当前下载任务的下载地址
*/ */
@Override public int getTaskType() { @Override public int getTaskType() {
return ITask.DOWNLOAD; return ITask.SINGLE_DOWNLOAD;
} }
@Override public String getUrl() { @Override public String getUrl() {
@ -41,6 +42,6 @@ public class DownloadTask extends AbsTask {
} }
@Override public String getFilePath() { @Override public String getFilePath() {
return Objects.requireNonNull(getTaskOption(TaskOption.class).getSavePathUri()).toString(); return Objects.requireNonNull(getTaskState().getEntity(DEntity.class).getFilePath().getPath());
} }
} }

@ -56,10 +56,10 @@ object TaskCachePool {
fun putTask(task: ITask) { fun putTask(task: ITask) {
when (task) { when (task) {
is DownloadTask -> { is SingleDownloadTask -> {
taskMap[task.url] = task taskMap[task.url] = task
} }
is DownloadGroupTask -> { is com.arialyy.dua.group.DownloadGroupTask -> {
taskMap[task.filePath] = task taskMap[task.filePath] = task
} }
} }

@ -15,7 +15,7 @@
*/ */
package com.arialyy.aria.core.task package com.arialyy.aria.core.task
import com.arialyy.aria.core.inf.ITaskManager import com.arialyy.aria.core.inf.IBlockManager
/** /**
* @Author laoyuyu * @Author laoyuyu
@ -26,7 +26,7 @@ class TaskChain(
private val interceptors: List<ITaskInterceptor>, private val interceptors: List<ITaskInterceptor>,
private val index: Int = 0, private val index: Int = 0,
private val task: ITask, private val task: ITask,
val blockManager: ITaskManager val blockManager: IBlockManager
) : ITaskInterceptor.IChain { ) : ITaskInterceptor.IChain {
override fun getTask(): ITask { override fun getTask(): ITask {

@ -31,11 +31,7 @@ class TaskState {
lateinit var taskRecord: TaskRecord lateinit var taskRecord: TaskRecord
var entity: BaseEntity? = null private lateinit var _entity: BaseEntity
set(value) {
fileSize = value?.fileSize ?: 0
field = value
}
/** /**
* need to try again?default: false * need to try again?default: false
@ -84,6 +80,15 @@ class TaskState {
val blockSize = BlockRecord.BLOCK_SIZE val blockSize = BlockRecord.BLOCK_SIZE
fun setEntity(entity: BaseEntity) {
fileSize = entity.fileSize
_entity = entity
}
fun <T : BaseEntity> getEntity(clazz: Class<T>): T {
return _entity as T
}
fun getPercent() = ((curProgress * 100) / fileSize).toInt() fun getPercent() = ((curProgress * 100) / fileSize).toInt()
fun isCompleted() = state == IEntity.STATE_COMPLETE fun isCompleted() = state == IEntity.STATE_COMPLETE

@ -15,13 +15,18 @@
*/ */
package com.arialyy.aria.core.task package com.arialyy.aria.core.task
import com.arialyy.aria.core.inf.ITaskManager
import timber.log.Timber
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit.SECONDS
import java.util.concurrent.locks.ReentrantLock
object ThreadTaskManager2 { object ThreadTaskManager2 {
private val mThreadTasks: ConcurrentHashMap<Int, MutableSet<IThreadTask>> = ConcurrentHashMap() private val taskManagerMap: ConcurrentHashMap<Int, ITaskManager> = ConcurrentHashMap()
private val LOCK = ReentrantLock()
fun getThreadManager(taskId: Int) = taskManagerMap[taskId]
fun putThreadManager(taskId: Int, taskManager: ITaskManager) {
taskManagerMap[taskId] = taskManager
}
/** /**
* 任务是否在执行 * 任务是否在执行
@ -29,7 +34,7 @@ object ThreadTaskManager2 {
* @return `true` 任务正在运行 * @return `true` 任务正在运行
*/ */
fun taskIsRunning(taskId: Int): Boolean { fun taskIsRunning(taskId: Int): Boolean {
return mThreadTasks[taskId] != null return taskManagerMap[taskId]?.isRunning() == true
} }
/** /**
@ -37,46 +42,30 @@ object ThreadTaskManager2 {
* @param isRemoveTask if true, remove task and block * @param isRemoveTask if true, remove task and block
*/ */
fun stopThreadTask(taskId: Int, isRemoveTask: Boolean = false) { fun stopThreadTask(taskId: Int, isRemoveTask: Boolean = false) {
try { val taskManager = taskManagerMap[taskId]
LOCK.tryLock(2, SECONDS) if (taskManager == null) {
val threadTaskList: MutableSet<IThreadTask>? = mThreadTasks[taskId] Timber.d("task already stop, taskId: $taskId")
threadTaskList?.forEach { return
if (isRemoveTask) {
it.cancel()
return@forEach
}
it.stop()
} }
mThreadTasks.remove(taskId) if (isRemoveTask) {
taskManager.cancel()
} catch (e: Exception) { } else {
e.printStackTrace() taskManager.stop()
} finally {
LOCK.unlock()
} }
taskManagerMap.remove(taskId)
} }
/** /**
* 删除所有线程任务 * 删除所有线程任务
*/ */
fun removeAllThreadTask() { fun stopAllThreadTask() {
if (mThreadTasks.isEmpty()) { if (taskManagerMap.isEmpty()) {
return return
} }
try { taskManagerMap.forEach {
LOCK.tryLock(2, SECONDS) it.value.cancel()
for (threads in mThreadTasks.values) {
for (tt in threads) {
tt.stop()
}
threads.clear()
}
mThreadTasks.clear()
} catch (e: InterruptedException) {
e.printStackTrace()
} finally {
LOCK.unlock()
} }
taskManagerMap.clear()
} }
} }

@ -42,7 +42,7 @@ interface DEntityDao {
suspend fun queryDEntityById(did: String): DEntity? suspend fun queryDEntityById(did: String): DEntity?
@Query("SELECT * FROM DEntity WHERE :sourceUrl=sourceUrl") @Query("SELECT * FROM DEntity WHERE :sourceUrl=sourceUrl")
suspend fun queryDEntityBySource(sourceUrl: String): DEntity? suspend fun queryDEntityByUrl(sourceUrl: String): DEntity?
@Insert @Insert
suspend fun insert(dEntity: DEntity) suspend fun insert(dEntity: DEntity)

@ -56,11 +56,11 @@ data class DEntity(
) : BaseEntity() { ) : BaseEntity() {
private var dirFile: File? = null private var dirFile: File? = null
fun getFilePath(): String { fun getFilePath(): File {
if (dirFile == null) { if (dirFile == null) {
dirFile = File(FileUri.getPathByUri(savePath)!!) dirFile = File(FileUri.getPathByUri(savePath)!!)
} }
return File(dirFile, fileName).path return File(dirFile, fileName)
} }
override fun update() { override fun update() {

@ -33,7 +33,7 @@ data class TaskRecord(
*/ */
val filePath: Uri, val filePath: Uri,
/** /**
* [ITask.DOWNLOAD] ... * [ITask.SINGLE_DOWNLOAD] ...
*/ */
val taskType: Int, val taskType: Int,
val fileLen: Long, val fileLen: Long,

@ -36,10 +36,9 @@ object BlockUtil {
/** /**
* create block record * create block record
*/ */
fun createBlockRecord(fileSaveUri: Uri, fileSize: Long): List<BlockRecord> { fun createBlockRecord(filePath: File, fileSize: Long): List<BlockRecord> {
val filePath = FileUri.getPathByUri(fileSaveUri) ?: "/" val fileName = filePath.name
val fileName = FileUtils.getFileNameFromPath(filePath) val dirPath = filePath.parent
val dirPath = FileUtils.getFilePathFromFullPath(filePath)
val blockNumInfo = getBlockNum(fileSize) val blockNumInfo = getBlockNum(fileSize)
val lastIndex = blockNumInfo.first - 1 val lastIndex = blockNumInfo.first - 1

@ -20,10 +20,19 @@ import android.content.pm.PackageManager
import android.net.Uri import android.net.Uri
import com.arialyy.aria.core.DuaContext import com.arialyy.aria.core.DuaContext
import timber.log.Timber import timber.log.Timber
import java.io.File
import java.math.BigInteger import java.math.BigInteger
internal const val AUTHORITY = ".andoFileProvider" internal const val AUTHORITY = ".andoFileProvider"
fun File.uri(): Uri {
return Uri.parse(path)
}
fun String.uri():Uri{
return Uri.parse(this)
}
fun ByteArray.toBigInteger(): BigInteger { fun ByteArray.toBigInteger(): BigInteger {
return BigInteger(1, this) return BigInteger(1, this)
} }

@ -133,7 +133,7 @@ public abstract class AbsTaskQueue<TASK extends ITask> implements ITaskQueue<TAS
task.stop(TaskSchedulerType.TYPE_STOP_NOT_NEXT); task.stop(TaskSchedulerType.TYPE_STOP_NOT_NEXT);
} }
} }
ThreadTaskManager2.INSTANCE.removeAllThreadTask(); ThreadTaskManager2.INSTANCE.stopAllThreadTask();
getCachePool().clear(); getCachePool().clear();
} }

@ -19,13 +19,13 @@ package com.arialyy.aria.queue;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
/** /**
* Created by lyy on 2016/8/17. * Created by lyy on 2016/8/17.
* 下载任务队列 * 下载任务队列
*/ */
public class DTaskQueue extends AbsTaskQueue<DownloadTask> { public class DTaskQueue extends AbsTaskQueue<SingleDownloadTask> {
private static volatile DTaskQueue INSTANCE = null; private static volatile DTaskQueue INSTANCE = null;
public static DTaskQueue getInstance() { public static DTaskQueue getInstance() {

@ -16,13 +16,13 @@
package com.arialyy.aria.schedulers; package com.arialyy.aria.schedulers;
import com.arialyy.aria.core.task.DownloadGroupTask; import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.core.task.ITask; import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.task.UploadTask; import com.arialyy.aria.core.task.UploadTask;
/** /**
* Created by Aria.Lao on 2017/6/7. * Created by Aria.Lao on 2017/6/7.
* 普通任务事件{@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}回调类 * 普通任务事件{@link SingleDownloadTask}{@link UploadTask}{@link DownloadGroupTask}回调类
*/ */
public class AptNormalTaskListener<TASK extends ITask> implements NormalTaskListenerInterface<TASK>, ISchedulerListener { public class AptNormalTaskListener<TASK extends ITask> implements NormalTaskListenerInterface<TASK>, ISchedulerListener {

@ -16,13 +16,13 @@
package com.arialyy.aria.schedulers; package com.arialyy.aria.schedulers;
import com.arialyy.aria.core.task.DownloadGroupTask; import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.core.task.ITask; import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.task.UploadTask; import com.arialyy.aria.core.task.UploadTask;
/** /**
* Created by Aria.Lao on 2017/6/7. * Created by Aria.Lao on 2017/6/7.
* 普通任务事件{@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}回调类 * 普通任务事件{@link SingleDownloadTask}{@link UploadTask}{@link DownloadGroupTask}回调类
*/ */
public interface NormalTaskListenerInterface<TASK extends ITask> extends public interface NormalTaskListenerInterface<TASK extends ITask> extends
TaskInternalListenerInterface { TaskInternalListenerInterface {

@ -29,7 +29,7 @@ import com.arialyy.aria.core.inf.ITaskQueue;
import com.arialyy.aria.core.listener.ISchedulers; import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.task.AbsTask; import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.task.DownloadGroupTask; import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.core.task.ITask; import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.task.TaskCachePool; import com.arialyy.aria.core.task.TaskCachePool;
import com.arialyy.aria.core.task.UploadTask; import com.arialyy.aria.core.task.UploadTask;
@ -76,10 +76,10 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
* @param taskType 任务类型 * @param taskType 任务类型
*/ */
ITaskQueue<ITask> getQueue(int taskType) { ITaskQueue<ITask> getQueue(int taskType) {
if (taskType == ITask.DOWNLOAD) { if (taskType == ITask.SINGLE_DOWNLOAD) {
return DuaContext.INSTANCE.getServiceManager().getDownloadQueue(); return DuaContext.INSTANCE.getServiceManager().getDownloadQueue();
} }
if (taskType == ITask.DOWNLOAD_GROUP) { if (taskType == ITask.HTTP_GROUP) {
return DuaContext.INSTANCE.getServiceManager().getDownloadGroupQueue(); return DuaContext.INSTANCE.getServiceManager().getDownloadGroupQueue();
} }
if (taskType == ITask.UPLOAD) { if (taskType == ITask.UPLOAD) {
@ -366,11 +366,11 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
} }
NormalTaskListenerInterface<TASK> listener = null; NormalTaskListenerInterface<TASK> listener = null;
if (mObservers.get(key) != null) { if (mObservers.get(key) != null) {
if (taskType == ITask.DOWNLOAD) { if (taskType == ITask.SINGLE_DOWNLOAD) {
listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD);
} else if (taskType == ITask.DOWNLOAD_GROUP) { } else if (taskType == ITask.HTTP_GROUP) {
listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP);
} else if (taskType == ITask.DOWNLOAD_GROUP) { } else if (taskType == ITask.HTTP_GROUP) {
listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.UPLOAD); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.UPLOAD);
} }
} }
@ -397,7 +397,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
} }
NormalTaskListenerInterface<TASK> listener = null; NormalTaskListenerInterface<TASK> listener = null;
if (mObservers.get(key) != null) { if (mObservers.get(key) != null) {
if (task instanceof DownloadTask) { if (task instanceof SingleDownloadTask) {
listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD);
} else if (task instanceof DownloadGroupTask) { } else if (task instanceof DownloadGroupTask) {
listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP);
@ -470,7 +470,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
return; return;
} }
int type = task.getTaskType(); int type = task.getTaskType();
if (type == ITask.DOWNLOAD || type == ITask.DOWNLOAD_GROUP) { if (type == ITask.SINGLE_DOWNLOAD || type == ITask.HTTP_GROUP) {
mAriaConfig.getAPP().sendBroadcast(createData(task)); mAriaConfig.getAPP().sendBroadcast(createData(task));
} else if (type == ITask.UPLOAD) { } else if (type == ITask.UPLOAD) {
mAriaConfig.getAPP().sendBroadcast(createData(task)); mAriaConfig.getAPP().sendBroadcast(createData(task));

@ -22,7 +22,7 @@ import android.widget.Toast
import com.arialyy.annotations.Download import com.arialyy.annotations.Download
import com.arialyy.aria.core.Aria import com.arialyy.aria.core.Aria
import com.arialyy.aria.core.download.target.HttpNormalTarget import com.arialyy.aria.core.download.target.HttpNormalTarget
import com.arialyy.aria.core.task.DownloadTask import com.arialyy.aria.core.task.SingleDownloadTask
import com.arialyy.aria.inf.IEntity import com.arialyy.aria.inf.IEntity
import com.arialyy.simple.R import com.arialyy.simple.R
import com.arialyy.simple.base.BaseActivity import com.arialyy.simple.base.BaseActivity
@ -71,7 +71,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleBinding>() {
* 注解方法不能添加internal修饰符否则会出现e: [kapt] An exception occurred: java.lang.IllegalArgumentException: peerIndex 1 for '$a' not in range (received 0 arguments)错误 * 注解方法不能添加internal修饰符否则会出现e: [kapt] An exception occurred: java.lang.IllegalArgumentException: peerIndex 1 for '$a' not in range (received 0 arguments)错误
*/ */
@Download.onTaskRunning @Download.onTaskRunning
fun running(task: com.arialyy.aria.core.task.DownloadTask) { fun running(task: SingleDownloadTask) {
Log.d(TAG, task.percent.toString()) Log.d(TAG, task.percent.toString())
val len = task.fileSize val len = task.fileSize
if (len == 0L) { if (len == 0L) {
@ -83,40 +83,40 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleBinding>() {
} }
@Download.onWait @Download.onWait
fun onWait(task: com.arialyy.aria.core.task.DownloadTask) { fun onWait(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) { if (task.key == DOWNLOAD_URL) {
Log.d(TAG, "wait ==> " + task.downloadEntity.fileName) Log.d(TAG, "wait ==> " + task.downloadEntity.fileName)
} }
} }
@Download.onPre @Download.onPre
fun onPre(task: com.arialyy.aria.core.task.DownloadTask) { fun onPre(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) { if (task.key == DOWNLOAD_URL) {
mStart.text = "停止" mStart.text = "停止"
} }
} }
@Download.onTaskStart @Download.onTaskStart
fun taskStart(task: com.arialyy.aria.core.task.DownloadTask) { fun taskStart(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) { if (task.key == DOWNLOAD_URL) {
binding.fileSize = task.convertFileSize binding.fileSize = task.convertFileSize
} }
} }
@Download.onTaskComplete @Download.onTaskComplete
fun complete(task: com.arialyy.aria.core.task.DownloadTask) { fun complete(task: SingleDownloadTask) {
Log.d(TAG, "完成") Log.d(TAG, "完成")
} }
@Download.onTaskResume @Download.onTaskResume
fun taskResume(task: com.arialyy.aria.core.task.DownloadTask) { fun taskResume(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) { if (task.key == DOWNLOAD_URL) {
mStart.text = "停止" mStart.text = "停止"
} }
} }
@Download.onTaskStop @Download.onTaskStop
fun taskStop(task: com.arialyy.aria.core.task.DownloadTask) { fun taskStop(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) { if (task.key == DOWNLOAD_URL) {
mStart.text = "恢复" mStart.text = "恢复"
binding.speed = "" binding.speed = ""
@ -124,7 +124,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleBinding>() {
} }
@Download.onTaskCancel @Download.onTaskCancel
fun taskCancel(task: com.arialyy.aria.core.task.DownloadTask) { fun taskCancel(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) { if (task.key == DOWNLOAD_URL) {
binding.progress = 0 binding.progress = 0
Toast.makeText(this@KotlinDownloadActivity, "取消下载", Toast.LENGTH_SHORT) Toast.makeText(this@KotlinDownloadActivity, "取消下载", Toast.LENGTH_SHORT)
@ -136,7 +136,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleBinding>() {
} }
@Download.onTaskFail @Download.onTaskFail
fun taskFail(task: com.arialyy.aria.core.task.DownloadTask) { fun taskFail(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) { if (task.key == DOWNLOAD_URL) {
Toast.makeText(this@KotlinDownloadActivity, "下载失败", Toast.LENGTH_SHORT) Toast.makeText(this@KotlinDownloadActivity, "下载失败", Toast.LENGTH_SHORT)
.show() .show()

@ -24,7 +24,7 @@ import android.widget.TextView;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsDialog; import com.arialyy.frame.core.AbsDialog;
import com.arialyy.simple.R; import com.arialyy.simple.R;
@ -101,20 +101,20 @@ public class DownloadDialog extends AbsDialog implements View.OnClickListener {
} }
} }
@Download.onTaskPre public void onTaskPre(DownloadTask task) { @Download.onTaskPre public void onTaskPre(SingleDownloadTask task) {
mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
} }
@Download.onTaskStop public void onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());
} }
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
mPb.setProgress(0); mPb.setProgress(0);
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());
} }
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
mPb.setProgress(task.getPercent()); mPb.setProgress(task.getPercent());
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());

@ -9,7 +9,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseDialog; import com.arialyy.simple.base.BaseDialog;
@ -58,14 +58,14 @@ import com.arialyy.simple.util.AppUtil;
Aria.download(this).unRegister(); Aria.download(this).unRegister();
} }
@Download.onPre(DOWNLOAD_URL) protected void onPre(DownloadTask task) { @Download.onPre(DOWNLOAD_URL) protected void onPre(SingleDownloadTask task) {
} }
@Download.onTaskStart(DOWNLOAD_URL) void taskStart(DownloadTask task) { @Download.onTaskStart(DOWNLOAD_URL) void taskStart(SingleDownloadTask task) {
getBinding().setFileSize(task.getConvertFileSize()); getBinding().setFileSize(task.getConvertFileSize());
} }
@Download.onTaskRunning(DOWNLOAD_URL) protected void running(DownloadTask task) { @Download.onTaskRunning(DOWNLOAD_URL) protected void running(SingleDownloadTask task) {
long len = task.getFileSize(); long len = task.getFileSize();
if (len == 0) { if (len == 0) {
getBinding().setProgress(0); getBinding().setProgress(0);
@ -75,24 +75,24 @@ import com.arialyy.simple.util.AppUtil;
getBinding().setSpeed(task.getConvertSpeed()); getBinding().setSpeed(task.getConvertSpeed());
} }
@Download.onTaskResume(DOWNLOAD_URL) void taskResume(DownloadTask task) { @Download.onTaskResume(DOWNLOAD_URL) void taskResume(SingleDownloadTask task) {
} }
@Download.onTaskStop(DOWNLOAD_URL) void taskStop(DownloadTask task) { @Download.onTaskStop(DOWNLOAD_URL) void taskStop(SingleDownloadTask task) {
getBinding().setSpeed(""); getBinding().setSpeed("");
} }
@Download.onTaskCancel(DOWNLOAD_URL) void taskCancel(DownloadTask task) { @Download.onTaskCancel(DOWNLOAD_URL) void taskCancel(SingleDownloadTask task) {
getBinding().setProgress(0); getBinding().setProgress(0);
Toast.makeText(getContext(), "取消下载", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "取消下载", Toast.LENGTH_SHORT).show();
getBinding().setSpeed(""); getBinding().setSpeed("");
} }
@Download.onTaskFail(DOWNLOAD_URL) void taskFail(DownloadTask task) { @Download.onTaskFail(DOWNLOAD_URL) void taskFail(SingleDownloadTask task) {
Toast.makeText(getContext(), "下载失败", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "下载失败", Toast.LENGTH_SHORT).show();
} }
@Download.onTaskComplete(DOWNLOAD_URL) void taskComplete(DownloadTask task) { @Download.onTaskComplete(DOWNLOAD_URL) void taskComplete(SingleDownloadTask task) {
getBinding().setProgress(100); getBinding().setProgress(100);
Toast.makeText(getContext(), "下载完成", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "下载完成", Toast.LENGTH_SHORT).show();
getBinding().setSpeed(""); getBinding().setSpeed("");

@ -27,7 +27,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsPopupWindow; import com.arialyy.frame.core.AbsPopupWindow;
import com.arialyy.simple.R; import com.arialyy.simple.R;
@ -116,21 +116,21 @@ public class DownloadPopupWindow extends AbsPopupWindow implements View.OnClickL
} }
@Download.onTaskPre public void onTaskPre(DownloadTask task) { @Download.onTaskPre public void onTaskPre(SingleDownloadTask task) {
mSize.setText(CommonUtil.formatFileSize(task.getFileSize())); mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
} }
@Download.onTaskStop public void onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
mSpeed.setText("0.0kb/s"); mSpeed.setText("0.0kb/s");
mStart.setText(getContext().getString(R.string.resume)); mStart.setText(getContext().getString(R.string.resume));
} }
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
mPb.setProgress(0); mPb.setProgress(0);
mSpeed.setText("0.0kb/s"); mSpeed.setText("0.0kb/s");
} }
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
long current = task.getCurrentProgress(); long current = task.getCurrentProgress();
long len = task.getFileSize(); long len = task.getFileSize();
if (len == 0) { if (len == 0) {

@ -27,7 +27,7 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.common.FtpOption; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.simple.R; import com.arialyy.simple.R;
@ -100,7 +100,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onWait @Download.onWait
void onWait(DownloadTask task) { void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -108,14 +108,14 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onPre @Download.onPre
protected void onPre(DownloadTask task) { protected void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }
} }
@Download.onTaskStart @Download.onTaskStart
void taskStart(DownloadTask task) { void taskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState()); ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
@ -123,7 +123,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskRunning @Download.onTaskRunning
protected void running(DownloadTask task) { protected void running(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState()); ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState());
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -131,7 +131,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskResume @Download.onTaskResume
void taskResume(DownloadTask task) { void taskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "resume"); ALog.d(TAG, "resume");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -139,7 +139,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskStop @Download.onTaskStop
void taskStop(DownloadTask task) { void taskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop"); ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -147,7 +147,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskCancel @Download.onTaskCancel
void taskCancel(DownloadTask task) { void taskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
mTaskId = -1; mTaskId = -1;
Log.d(TAG, "cancel"); Log.d(TAG, "cancel");
@ -156,7 +156,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskFail @Download.onTaskFail
void taskFail(DownloadTask task, Exception e) { void taskFail(SingleDownloadTask task, Exception e) {
ALog.d(TAG, "下载失败"); ALog.d(TAG, "下载失败");
Toast.makeText(this, getString(R.string.download_fail), Toast.LENGTH_SHORT) Toast.makeText(this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
.show(); .show();
@ -166,7 +166,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskComplete @Download.onTaskComplete
void taskComplete(DownloadTask task) { void taskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Toast.makeText(this, getString(R.string.download_success), Toast.makeText(this, getString(R.string.download_success),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();

@ -28,7 +28,7 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
@ -178,32 +178,32 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mStop.setEnabled(!state); mStop.setEnabled(!state);
} }
@Download.onPre public void onPre(DownloadTask task) { @Download.onPre public void onPre(SingleDownloadTask task) {
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskPre public void onTaskPre(DownloadTask task) { @Download.onTaskPre public void onTaskPre(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
mSize.setText(task.getConvertFileSize()); mSize.setText(task.getConvertFileSize());
} }
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskStart public void onTaskStart(DownloadTask task) { @Download.onTaskStart public void onTaskStart(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false); setBtState(false);
} }
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskResume public void onTaskResume(DownloadTask task) { @Download.onTaskResume public void onTaskResume(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false); setBtState(false);
} }
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskStop public void onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true); setBtState(true);
mStart.setText("恢复"); mStart.setText("恢复");
@ -212,7 +212,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true); setBtState(true);
mStart.setText("开始"); mStart.setText("开始");
@ -221,7 +221,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskFail public void onTaskFail(DownloadTask task) { @Download.onTaskFail public void onTaskFail(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true); setBtState(true);
} else { } else {
@ -229,7 +229,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
} }
} }
@Download.onTaskComplete public void onTaskComplete(DownloadTask task) { @Download.onTaskComplete public void onTaskComplete(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true); setBtState(true);
mStart.setText("重新开始"); mStart.setText("重新开始");
@ -239,7 +239,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
mPb.setProgress(task.getPercent()); mPb.setProgress(task.getPercent());
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());

@ -32,6 +32,7 @@ import com.arialyy.aria.core.Aria
import com.arialyy.aria.core.download.DownloadEntity import com.arialyy.aria.core.download.DownloadEntity
import com.arialyy.aria.core.inf.IEntity import com.arialyy.aria.core.inf.IEntity
import com.arialyy.aria.core.listener.ISchedulers import com.arialyy.aria.core.listener.ISchedulers
import com.arialyy.aria.core.task.SingleDownloadTask
import com.arialyy.aria.util.ALog import com.arialyy.aria.util.ALog
import com.arialyy.aria.util.CommonUtil import com.arialyy.aria.util.CommonUtil
import com.arialyy.frame.util.show.T import com.arialyy.frame.util.show.T
@ -178,28 +179,28 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
} }
@Download.onWait @Download.onWait
fun onWait(task: com.arialyy.aria.core.task.DownloadTask) { fun onWait(task: SingleDownloadTask) {
if (task.key == mUrl) { if (task.key == mUrl) {
Log.d(TAG, "wait ==> " + task.downloadEntity.fileName) Log.d(TAG, "wait ==> " + task.downloadEntity.fileName)
} }
} }
@Download.onPre @Download.onPre
fun onPre(task: com.arialyy.aria.core.task.DownloadTask) { fun onPre(task: SingleDownloadTask) {
if (task.key == mUrl) { if (task.key == mUrl) {
binding.stateStr = getString(R.string.stop) binding.stateStr = getString(R.string.stop)
} }
} }
@Download.onTaskStart @Download.onTaskStart
fun taskStart(task: com.arialyy.aria.core.task.DownloadTask) { fun taskStart(task: SingleDownloadTask) {
if (task.key == mUrl) { if (task.key == mUrl) {
binding.fileSize = task.convertFileSize binding.fileSize = task.convertFileSize
} }
} }
@Download.onTaskRunning @Download.onTaskRunning
fun running(task: com.arialyy.aria.core.task.DownloadTask) { fun running(task: SingleDownloadTask) {
if (task.key == mUrl) { if (task.key == mUrl) {
//Log.d(TAG, task.getKey()); //Log.d(TAG, task.getKey());
val len = task.fileSize val len = task.fileSize
@ -213,14 +214,14 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
} }
@Download.onTaskResume @Download.onTaskResume
fun taskResume(task: com.arialyy.aria.core.task.DownloadTask) { fun taskResume(task: SingleDownloadTask) {
if (task.key == mUrl) { if (task.key == mUrl) {
binding.stateStr = getString(R.string.stop) binding.stateStr = getString(R.string.stop)
} }
} }
@Download.onTaskStop @Download.onTaskStop
fun taskStop(task: com.arialyy.aria.core.task.DownloadTask) { fun taskStop(task: SingleDownloadTask) {
if (task.key == mUrl) { if (task.key == mUrl) {
binding.stateStr = getString(R.string.resume) binding.stateStr = getString(R.string.resume)
binding.speed = "" binding.speed = ""
@ -228,7 +229,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
} }
@Download.onTaskCancel @Download.onTaskCancel
fun taskCancel(task: com.arialyy.aria.core.task.DownloadTask) { fun taskCancel(task: SingleDownloadTask) {
if (task.key == mUrl) { if (task.key == mUrl) {
binding.progress = 0 binding.progress = 0
binding.stateStr = getString(R.string.start) binding.stateStr = getString(R.string.start)
@ -242,7 +243,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
*/ */
@Download.onTaskFail @Download.onTaskFail
fun taskFail( fun taskFail(
task: com.arialyy.aria.core.task.DownloadTask, task: SingleDownloadTask,
e: Exception e: Exception
) { ) {
if (task.key == mUrl) { if (task.key == mUrl) {
@ -253,7 +254,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
} }
@Download.onTaskComplete @Download.onTaskComplete
fun taskComplete(task: com.arialyy.aria.core.task.DownloadTask) { fun taskComplete(task: SingleDownloadTask) {
if (task.key == mUrl) { if (task.key == mUrl) {
binding.progress = 100 binding.progress = 100

@ -27,7 +27,7 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.common.SFtpOption; import com.arialyy.aria.core.common.SFtpOption;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.FileUtil; import com.arialyy.aria.util.FileUtil;
@ -143,7 +143,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onWait @Download.onWait
void onWait(DownloadTask task) { void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -151,14 +151,14 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onPre @Download.onPre
protected void onPre(DownloadTask task) { protected void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }
} }
@Download.onTaskStart @Download.onTaskStart
void taskStart(DownloadTask task) { void taskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState()); ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
@ -166,7 +166,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskRunning @Download.onTaskRunning
protected void running(DownloadTask task) { protected void running(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState()); ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState());
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -174,7 +174,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskResume @Download.onTaskResume
void taskResume(DownloadTask task) { void taskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "resume"); ALog.d(TAG, "resume");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -182,7 +182,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskStop @Download.onTaskStop
void taskStop(DownloadTask task) { void taskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop"); ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -190,7 +190,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskCancel @Download.onTaskCancel
void taskCancel(DownloadTask task) { void taskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
mTaskId = -1; mTaskId = -1;
Log.d(TAG, "cancel"); Log.d(TAG, "cancel");
@ -199,7 +199,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskFail @Download.onTaskFail
void taskFail(DownloadTask task, Exception e) { void taskFail(SingleDownloadTask task, Exception e) {
ALog.d(TAG, "下载失败"); ALog.d(TAG, "下载失败");
Toast.makeText(this, getString(R.string.download_fail), Toast.LENGTH_SHORT) Toast.makeText(this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
.show(); .show();
@ -209,7 +209,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskComplete @Download.onTaskComplete
void taskComplete(DownloadTask task) { void taskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Toast.makeText(this, getString(R.string.download_success), Toast.makeText(this, getString(R.string.download_success),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();

@ -36,7 +36,7 @@ import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.listener.ISchedulers; import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter; import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
@ -184,7 +184,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onWait @Download.onWait
public void onWait(DownloadTask task) { public void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -192,7 +192,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onPre @Download.onPre
public void onPre(DownloadTask task) { public void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }
@ -203,7 +203,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//} //}
@Download.onTaskStart @Download.onTaskStart
public void onTaskStart(DownloadTask task) { public void onTaskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState()); ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
@ -211,7 +211,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskRunning @Download.onTaskRunning
public void onTaskRunning(DownloadTask task) { public void onTaskRunning(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
//ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState()); //ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState());
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -223,7 +223,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//} //}
@Download.onTaskResume @Download.onTaskResume
public void onTaskResume(DownloadTask task) { public void onTaskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "resume"); ALog.d(TAG, "resume");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -231,7 +231,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskStop @Download.onTaskStop
public void onTaskStop(DownloadTask task) { public void onTaskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop"); ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -239,7 +239,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskCancel @Download.onTaskCancel
public void onTaskCancel(DownloadTask task) { public void onTaskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
mTaskId = -1; mTaskId = -1;
Log.d(TAG, "cancel"); Log.d(TAG, "cancel");
@ -248,7 +248,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskFail @Download.onTaskFail
public void onTaskFail(DownloadTask task, Exception e) { public void onTaskFail(SingleDownloadTask task, Exception e) {
ALog.d(TAG, "下载失败"); ALog.d(TAG, "下载失败");
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_fail), Toast.LENGTH_SHORT) Toast.makeText(SingleTaskActivity.this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
.show(); .show();
@ -258,7 +258,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onTaskComplete @Download.onTaskComplete
public void onTaskComplete(DownloadTask task) { public void onTaskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_success), Toast.makeText(SingleTaskActivity.this, getString(R.string.download_success),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();

@ -23,7 +23,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.frame.core.AbsFragment; import com.arialyy.frame.core.AbsFragment;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.databinding.FragmentDownloadBinding; import com.arialyy.simple.databinding.FragmentDownloadBinding;
@ -77,19 +77,19 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
}); });
} }
@Download.onTaskPre public void onTaskPre(DownloadTask task) { @Download.onTaskPre public void onTaskPre(SingleDownloadTask task) {
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }
@Download.onTaskStop public void onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
long len = task.getFileSize(); long len = task.getFileSize();
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }

@ -23,7 +23,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.frame.core.AbsFragment; import com.arialyy.frame.core.AbsFragment;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.databinding.FragmentDownloadBinding; import com.arialyy.simple.databinding.FragmentDownloadBinding;
@ -81,28 +81,28 @@ public class MultiItemFragment extends AbsFragment<FragmentDownloadBinding> {
}); });
} }
@Download.onTaskPre public void onTaskPre(DownloadTask task) { @Download.onTaskPre public void onTaskPre(SingleDownloadTask task) {
if (!task.getKey().equals(DOWNLOAD_URL)){ if (!task.getKey().equals(DOWNLOAD_URL)){
return; return;
} }
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }
@Download.onTaskStop public void onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
if (!task.getKey().equals(DOWNLOAD_URL)){ if (!task.getKey().equals(DOWNLOAD_URL)){
return; return;
} }
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
if (!task.getKey().equals(DOWNLOAD_URL)){ if (!task.getKey().equals(DOWNLOAD_URL)){
return; return;
} }
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
} }
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
if (!task.getKey().equals(DOWNLOAD_URL)){ if (!task.getKey().equals(DOWNLOAD_URL)){
return; return;
} }

@ -33,7 +33,7 @@ import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.m3u8.M3U8LiveOption; import com.arialyy.aria.core.download.m3u8.M3U8LiveOption;
import com.arialyy.aria.core.processor.IBandWidthUrlConverter; import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.ILiveTsUrlConverter; import com.arialyy.aria.core.processor.ILiveTsUrlConverter;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
@ -149,14 +149,14 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
} }
@Download.onWait @Download.onWait
void onWait(DownloadTask task) { void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
} }
} }
@Download.onPre @Download.onPre
protected void onPre(DownloadTask task) { protected void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "pre"); ALog.d(TAG, "pre");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -164,7 +164,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
} }
@Download.onTaskStart @Download.onTaskStart
void taskStart(DownloadTask task) { void taskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState()); ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -172,7 +172,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
} }
@Download.onTaskRunning @Download.onTaskRunning
protected void running(DownloadTask task) { protected void running(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, ALog.d(TAG,
"m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed()); "m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
@ -181,7 +181,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
} }
@Download.onTaskResume @Download.onTaskResume
void taskResume(DownloadTask task) { void taskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "m3u8 vod resume"); ALog.d(TAG, "m3u8 vod resume");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -189,7 +189,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
} }
@Download.onTaskStop @Download.onTaskStop
void taskStop(DownloadTask task) { void taskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop"); ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -197,7 +197,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
} }
@Download.onTaskCancel @Download.onTaskCancel
void taskCancel(DownloadTask task) { void taskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Log.d(TAG, "cancel"); Log.d(TAG, "cancel");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -205,7 +205,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
} }
@Download.onTaskFail @Download.onTaskFail
void taskFail(DownloadTask task, Exception e) { void taskFail(SingleDownloadTask task, Exception e) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Toast.makeText(this, getString(R.string.download_fail), Toast.makeText(this, getString(R.string.download_fail),
Toast.LENGTH_SHORT) Toast.LENGTH_SHORT)
@ -216,7 +216,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
} }
@Download.onTaskComplete @Download.onTaskComplete
void taskComplete(DownloadTask task) { void taskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Toast.makeText(this, getString(R.string.download_success), Toast.makeText(this, getString(R.string.download_success),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();

@ -38,7 +38,7 @@ import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.IKeyUrlConverter; import com.arialyy.aria.core.processor.IKeyUrlConverter;
import com.arialyy.aria.core.processor.ITsMergeHandler; import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.core.processor.IVodTsUrlConverter; import com.arialyy.aria.core.processor.IVodTsUrlConverter;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
@ -210,14 +210,14 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} }
@Download.onWait @Download.onWait
void onWait(DownloadTask task) { void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
} }
} }
@Download.onPre @Download.onPre
protected void onPre(DownloadTask task) { protected void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "pre"); ALog.d(TAG, "pre");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -225,7 +225,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} }
@Download.onTaskStart @Download.onTaskStart
void taskStart(DownloadTask task) { void taskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState()); ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
getBinding().seekBar.setMax(task.getEntity().getM3U8Entity().getPeerNum()); getBinding().seekBar.setMax(task.getEntity().getM3U8Entity().getPeerNum());
@ -234,7 +234,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} }
@Download.onTaskRunning @Download.onTaskRunning
protected void running(DownloadTask task) { protected void running(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, ALog.d(TAG,
"m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed()); "m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
@ -243,7 +243,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} }
@Download.onTaskResume @Download.onTaskResume
void taskResume(DownloadTask task) { void taskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "m3u8 vod resume"); ALog.d(TAG, "m3u8 vod resume");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -251,7 +251,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} }
@Download.onTaskStop @Download.onTaskStop
void taskStop(DownloadTask task) { void taskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop"); ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -259,7 +259,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} }
@Download.onTaskCancel @Download.onTaskCancel
void taskCancel(DownloadTask task) { void taskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Log.d(TAG, "cancel"); Log.d(TAG, "cancel");
getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setInfo(task.getEntity());
@ -267,7 +267,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} }
@Download.onTaskFail @Download.onTaskFail
void taskFail(DownloadTask task, Exception e) { void taskFail(SingleDownloadTask task, Exception e) {
if (task != null && task.getKey().equals(mUrl)) { if (task != null && task.getKey().equals(mUrl)) {
Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_fail), Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_fail),
Toast.LENGTH_SHORT) Toast.LENGTH_SHORT)
@ -278,7 +278,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} }
@Download.onTaskComplete @Download.onTaskComplete
void taskComplete(DownloadTask task) { void taskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) { if (task.getKey().equals(mUrl)) {
Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_success), Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_success),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();

@ -28,7 +28,7 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadGroupTask; import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
@ -76,30 +76,30 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
return true; return true;
} }
@Download.onPre void onPre(DownloadTask task) { @Download.onPre void onPre(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
Log.d(TAG, task.getTaskName() + ", " + task.getTaskState()); Log.d(TAG, task.getTaskName() + ", " + task.getTaskState());
} }
@Download.onWait void onWait(DownloadTask task) { @Download.onWait void onWait(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(SingleDownloadTask task) {
Log.d(TAG, task.getTaskName() + ", " + task.getTaskState()); Log.d(TAG, task.getTaskName() + ", " + task.getTaskState());
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskResume void taskResume(DownloadTask task) { @Download.onTaskResume void taskResume(SingleDownloadTask task) {
Log.d(TAG, task.getTaskName() + ", " + task.getTaskState()); Log.d(TAG, task.getTaskName() + ", " + task.getTaskState());
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskStop void taskStop(DownloadTask task) { @Download.onTaskStop void taskStop(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskCancel void taskCancel(DownloadTask task) { @Download.onTaskCancel void taskCancel(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
List<DownloadEntity> tasks = Aria.download(this).getAllNotCompleteTask(); List<DownloadEntity> tasks = Aria.download(this).getAllNotCompleteTask();
if (tasks != null){ if (tasks != null){
@ -107,18 +107,18 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
} }
} }
@Download.onTaskFail void taskFail(DownloadTask task) { @Download.onTaskFail void taskFail(SingleDownloadTask task) {
if (task == null || task.getEntity() == null){ if (task == null || task.getEntity() == null){
return; return;
} }
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskComplete void taskComplete(DownloadTask task) { @Download.onTaskComplete void taskComplete(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskRunning void taskRunning(DownloadTask task) { @Download.onTaskRunning void taskRunning(SingleDownloadTask task) {
mAdapter.setProgress(task.getEntity()); mAdapter.setProgress(task.getEntity());
} }

@ -28,7 +28,7 @@ import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.task.DownloadGroupTask; import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.frame.util.FileUtil; import com.arialyy.frame.util.FileUtil;
import com.arialyy.simple.R; import com.arialyy.simple.R;
@ -86,34 +86,34 @@ public class MultiTaskListActivity extends BaseActivity<ActivityMultiBinding> {
} }
} }
@Download.onWait void taskWait(DownloadTask task) { @Download.onWait void taskWait(SingleDownloadTask task) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
} }
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(SingleDownloadTask task) {
mAdapter.updateBtState(task.getKey(), false); mAdapter.updateBtState(task.getKey(), false);
} }
@Download.onTaskResume void taskResume(DownloadTask task) { @Download.onTaskResume void taskResume(SingleDownloadTask task) {
mAdapter.updateBtState(task.getKey(), false); mAdapter.updateBtState(task.getKey(), false);
} }
@Download.onTaskStop void taskStop(DownloadTask task) { @Download.onTaskStop void taskStop(SingleDownloadTask task) {
mAdapter.updateBtState(task.getKey(), true); mAdapter.updateBtState(task.getKey(), true);
} }
@Download.onTaskCancel void taskCancel(DownloadTask task) { @Download.onTaskCancel void taskCancel(SingleDownloadTask task) {
mAdapter.updateBtState(task.getKey(), true); mAdapter.updateBtState(task.getKey(), true);
} }
@Download.onTaskFail void taskFail(DownloadTask task) { @Download.onTaskFail void taskFail(SingleDownloadTask task) {
if (task == null || task.getEntity() == null){ if (task == null || task.getEntity() == null){
return; return;
} }
mAdapter.updateBtState(task.getKey(), true); mAdapter.updateBtState(task.getKey(), true);
} }
@Download.onTaskComplete void taskComplete(DownloadTask task) { @Download.onTaskComplete void taskComplete(SingleDownloadTask task) {
Log.d(TAG, FileUtil.getFileMD5(new File(task.getFilePath()))); Log.d(TAG, FileUtil.getFileMD5(new File(task.getFilePath())));
} }

@ -22,7 +22,7 @@ import android.os.IBinder;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
/** /**
@ -57,32 +57,32 @@ public class DownloadService extends Service {
Aria.download(this).unRegister(); Aria.download(this).unRegister();
} }
@Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) { @Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(SingleDownloadTask task) {
T.showShort(getApplicationContext(), "该下载链接不支持断点"); T.showShort(getApplicationContext(), "该下载链接不支持断点");
} }
@Download.onTaskStart public void onTaskStart(DownloadTask task) { @Download.onTaskStart public void onTaskStart(SingleDownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载");
} }
@Download.onTaskStop public void onTaskStop(DownloadTask task) { @Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载");
} }
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) { @Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载");
} }
@Download.onTaskFail public void onTaskFail(DownloadTask task) { @Download.onTaskFail public void onTaskFail(SingleDownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载失败"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载失败");
} }
@Download.onTaskComplete public void onTaskComplete(DownloadTask task) { @Download.onTaskComplete public void onTaskComplete(SingleDownloadTask task) {
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载完成"); T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载完成");
mNotify.upload(100); mNotify.upload(100);
} }
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) { @Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
long len = task.getFileSize(); long len = task.getFileSize();
int p = (int) (task.getCurrentProgress() * 100 / len); int p = (int) (task.getCurrentProgress() * 100 / len);
mNotify.upload(p); mNotify.upload(p);

@ -22,7 +22,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.FtpOption; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
import com.arialyy.simple.util.AppUtil; import com.arialyy.simple.util.AppUtil;
@ -43,39 +43,39 @@ public class AnyRunnModule {
mContext = context; mContext = context;
} }
@Download.onWait void onWait(DownloadTask task) { @Download.onWait void onWait(SingleDownloadTask task) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
} }
@Download.onPre protected void onPre(DownloadTask task) { @Download.onPre protected void onPre(SingleDownloadTask task) {
Log.d(TAG, "onPre"); Log.d(TAG, "onPre");
} }
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(SingleDownloadTask task) {
Log.d(TAG, "onPreStart"); Log.d(TAG, "onPreStart");
} }
@Download.onTaskRunning protected void running(DownloadTask task) { @Download.onTaskRunning protected void running(SingleDownloadTask task) {
Log.d(TAG, "running;Percent = " + task.getPercent()); Log.d(TAG, "running;Percent = " + task.getPercent());
} }
@Download.onTaskResume void taskResume(DownloadTask task) { @Download.onTaskResume void taskResume(SingleDownloadTask task) {
Log.d(TAG, "resume"); Log.d(TAG, "resume");
} }
@Download.onTaskStop void taskStop(DownloadTask task) { @Download.onTaskStop void taskStop(SingleDownloadTask task) {
Log.d(TAG, "stop"); Log.d(TAG, "stop");
} }
@Download.onTaskCancel void taskCancel(DownloadTask task) { @Download.onTaskCancel void taskCancel(SingleDownloadTask task) {
Log.d(TAG, "cancel"); Log.d(TAG, "cancel");
} }
@Download.onTaskFail void taskFail(DownloadTask task) { @Download.onTaskFail void taskFail(SingleDownloadTask task) {
Log.d(TAG, "fail"); Log.d(TAG, "fail");
} }
@Download.onTaskComplete void taskComplete(DownloadTask task) { @Download.onTaskComplete void taskComplete(SingleDownloadTask task) {
L.d(TAG, "path ==> " + task.getDownloadEntity().getFilePath()); L.d(TAG, "path ==> " + task.getDownloadEntity().getFilePath());
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getFilePath()))); L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getFilePath())));
} }

Loading…
Cancel
Save