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. 77
      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. 61
      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 taskType = 0;
if (mTaskWrapper instanceof DTaskWrapper) {
taskType = ITask.DOWNLOAD;
taskType = ITask.SINGLE_DOWNLOAD;
} else if (mTaskWrapper instanceof DGTaskWrapper) {
taskType = ITask.DOWNLOAD_GROUP;
taskType = ITask.HTTP_GROUP;
} else if (mTaskWrapper instanceof UTaskWrapper) {
taskType = ITask.UPLOAD;
}

@ -484,7 +484,7 @@ public class DownloadReceiver extends AbsReceiver {
public void stopAllTask() {
EventMsgUtil.getDefault().post(NormalCmdFactory.getInstance()
.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() {
EventMsgUtil.getDefault().post(NormalCmdFactory.getInstance()
.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();
CancelAllCmd cancelCmd =
(CancelAllCmd) CmdHelper.createNormalCmd(new DTaskWrapper(null),
NormalCmdFactory.TASK_CANCEL_ALL, ITask.DOWNLOAD);
NormalCmdFactory.TASK_CANCEL_ALL, ITask.SINGLE_DOWNLOAD);
cancelCmd.removeFile = removeFile;
EventMsgUtil.getDefault().post(cancelCmd);

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

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

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

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

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.http.download
import android.net.Uri
import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.task.ITaskInterceptor
import com.arialyy.aria.core.task.TaskCachePool
@ -33,16 +34,16 @@ class HttpDCheckInterceptor : ITaskInterceptor {
/**
* find DEntity, if that not exist, create and save it
*/
private suspend fun findDEntityBySavePath(option: HttpTaskOption): DEntity {
val savePath = option.savePathUri
private suspend fun findDEntityByUrl(option: HttpTaskOption): DEntity {
val dao = DuaContext.getServiceManager().getDbService().getDuaDb().getDEntityDao()
val de = dao.queryDEntityBySavePath(savePath.toString())
val de = dao.queryDEntityByUrl(option.sourUrl ?: "")
if (de != null) {
return de
}
// Set the file save path only after getting the file name
val newDe = DEntity(
sourceUrl = option.sourUrl!!,
savePath = savePath!!,
savePath = Uri.EMPTY,
)
dao.insert(newDe)
return newDe
@ -50,8 +51,8 @@ class HttpDCheckInterceptor : ITaskInterceptor {
override suspend fun interceptor(chain: TaskChain): TaskResp {
val option = chain.getTask().getTaskOption(HttpTaskOption::class.java)
val dEntity = findDEntityBySavePath(option)
chain.getTask().taskState.entity = dEntity
val dEntity = findDEntityByUrl(option)
chain.getTask().taskState.setEntity(dEntity)
TaskCachePool.putEntity(chain.getTask().taskId, dEntity)
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.listener.AbsEventListener
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.exception.AriaException
import com.arialyy.aria.orm.entity.DEntity
@ -31,7 +31,7 @@ import kotlinx.coroutines.launch
import timber.log.Timber
import java.io.File
class HttpDEventListener(task: DownloadTask) : AbsEventListener(task) {
class HttpDEventListener(task: SingleDownloadTask) : AbsEventListener(task) {
/**
* merge block file, if merge fail call [onFail]

@ -80,7 +80,7 @@ internal class HttpDHeaderInterceptor : ITaskInterceptor {
getOptionAdapter().isSupportResume && fileSize > BlockRecord.BLOCK_SIZE
val fileName =
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.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.StopCmd
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.TaskCachePool
import com.arialyy.aria.http.HttpBaseStartController
@ -88,22 +88,22 @@ class HttpDStartController(target: Any, val url: String) : HttpBaseStartControll
*
*/
fun setSavePath(savePath: Uri): HttpDStartController {
httpTaskOption.savePathUri = savePath
httpTaskOption.savePathDir = savePath
return this
}
private fun getTask(createNewTask: Boolean = true): DownloadTask? {
private fun getTask(createNewTask: Boolean = true): SingleDownloadTask? {
if (HttpUtil.checkHttpDParams(httpTaskOption)) {
throw IllegalArgumentException("invalid params")
}
val tempTask = TaskCachePool.getTaskByKey(url)
if (tempTask != null) {
return tempTask as DownloadTask
return tempTask as SingleDownloadTask
}
if (!createNewTask) {
return null
}
val task = DownloadTask(httpTaskOption)
val task = SingleDownloadTask(httpTaskOption)
task.adapter = HttpDTaskAdapter()
TaskCachePool.putTask(task)
return task

@ -15,88 +15,51 @@
*/
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.AbsTaskAdapter
import com.arialyy.aria.core.task.BlockManager
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.core.task.SingleDownloadTask
import com.arialyy.aria.http.HttpTaskOption
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
/**
* @Author laoyuyu
* @Description
* @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 {
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 {
if (blockManager == null) {
blockManager = BlockManager(getTask())
}
return blockManager!!
fun setBlockManager(blockManager: IBlockManager) {
delegate.setBlockManager(blockManager)
}
override fun getBlockManager(): IBlockManager {
return delegate.getBlockManager()
}
override fun isRunning(): Boolean {
return getTaskManager().isRunning()
return delegate.isRunning()
}
override fun cancel() {
if (getTaskManager().isCanceled()) {
Timber.w("task already canceled, taskId: ${getTask().taskId}")
return
}
DuaContext.duaScope.launch(Dispatchers.IO) {
ThreadTaskManager2.stopThreadTask(getTask().taskId, true)
}
delegate.cancel()
}
override fun stop() {
if (getTaskManager().isStopped()) {
Timber.w("task already stopped, taskId: ${getTask().taskId}")
return
}
DuaContext.duaScope.launch(Dispatchers.IO) {
ThreadTaskManager2.stopThreadTask(getTask().taskId)
}
delegate.stop()
}
override fun start() {
getTask().getTaskOption(HttpTaskOption::class.java).taskInterceptor.let {
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()
}
delegate.start()
}
}

@ -16,12 +16,12 @@
package com.arialyy.aria.http.download
import com.arialyy.aria.core.listener.ITaskStatusListener
import com.arialyy.aria.core.task.DownloadTask
import com.arialyy.aria.core.task.SingleDownloadTask
/**
* @Author laoyuyu
* @Description
* @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
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.ITaskInterceptor
import com.arialyy.aria.core.task.TaskChain
import com.arialyy.aria.core.task.TaskResp
import com.arialyy.aria.core.task.ThreadTaskManager2
import timber.log.Timber
import java.util.concurrent.ScheduledThreadPoolExecutor
import java.util.concurrent.TimeUnit.MILLISECONDS
@ -51,13 +51,17 @@ open class TimerInterceptor : ITaskInterceptor {
closeTimer()
try {
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 {
override fun run() {
// 线程池中是不抛异常的,没有日志,很难定位问题,需要手动try-catch
try {
if (blockManager.isCompleted()
|| blockManager.hasFailedTask()
if (threadManager.isCompleted()
|| threadManager.hasFailedTask()
|| !isRunning(chain.getTask())
) {
ThreadTaskManager2.stopThreadTask(chain.getTask().taskId)
@ -66,7 +70,7 @@ open class TimerInterceptor : ITaskInterceptor {
}
if (chain.getTask().taskState.curProgress >= 0) {
chain.getTask().getTaskOption(ITaskOption::class.java).eventListener.onProgress(
blockManager.getCurrentProgress()
threadManager.getCurrentProgress()
)
return
}

@ -28,7 +28,7 @@ import com.arialyy.aria.http.HttpOption
class HttpUStartController(target: Any, val filePath: Uri) : HttpBaseStartController(target) {
init {
httpTaskOption.savePathUri = filePath
httpTaskOption.savePathDir = filePath
}
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.inf.ITaskManager
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.exception.AriaException
import com.arialyy.aria.http.HttpTaskOption
@ -34,11 +34,11 @@ import kotlinx.coroutines.launch
* @Date 9:21 PM 2023/2/21
**/
class HttpUTaskAdapter : AbsTaskAdapter() {
private var blockManager: BlockManager? = null
private var blockManager: DBlockManager? = null
override fun getTaskManager(): ITaskManager {
override fun getBlockManager(): ITaskManager {
if (blockManager == null) {
blockManager = BlockManager(getTask())
blockManager = DBlockManager(getTask())
}
return blockManager!!
}

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

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

@ -17,7 +17,6 @@ package com.arialyy.dua.group
import android.net.Uri
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.TaskCachePool
import com.arialyy.aria.http.HttpBaseStartController
@ -37,7 +36,7 @@ class HttpDGStartController(target: Any, val savePath: Uri) : HttpBaseStartContr
init {
httpTaskOption.taskOptionAdapter = optionAdapter
httpTaskOption.savePathUri = savePath
httpTaskOption.savePathDir = savePath
}
override fun setTaskInterceptor(taskInterceptor: ITaskInterceptor): HttpDGStartController {
@ -68,15 +67,15 @@ class HttpDGStartController(target: Any, val savePath: Uri) : HttpBaseStartContr
return this
}
private fun getTask(createNewTask: Boolean = true): DownloadGroupTask {
private fun getTask(createNewTask: Boolean = true): HttpGroupTask {
if (HttpUtil.checkHttpDParams(httpTaskOption)) {
throw IllegalArgumentException("invalid params")
}
val temp = TaskCachePool.getTaskByKey(savePath.toString())
if (temp != null) {
return temp as DownloadGroupTask
return temp as HttpGroupTask
}
val task = DownloadGroupTask(httpTaskOption)
val task = HttpGroupTask(httpTaskOption)
task.adapter = HttpDGroupAdapter()
TaskCachePool.putTask(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 cancel() {
}
override fun isCompleted(): Boolean {
TODO("Not yet implemented")
}
@ -82,7 +86,7 @@ internal class HttpDGTaskManager : ITaskManager {
TODO("Not yet implemented")
}
override fun getHandler(): Handler {
fun getHandler(): Handler {
return handler
}

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

@ -13,24 +13,25 @@
* See the License for the specific language governing permissions and
* 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.inf.ITaskOption;
import com.arialyy.aria.core.task.AbsTask;
import java.util.Objects;
/**
* 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);
}
@Override public int getTaskType() {
return DOWNLOAD_GROUP;
return HTTP_GROUP;
}
/**
@ -42,6 +43,6 @@ public class DownloadGroupTask extends AbsTask {
}
@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;
switch (mTask.getTaskType()) {
case ITask.DOWNLOAD: {
case ITask.SINGLE_DOWNLOAD: {
itq = DuaContext.INSTANCE.getServiceManager().getDownloadQueue();
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,
int taskType) {

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

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

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.inf;
import android.os.Handler;
import com.arialyy.aria.core.task.IThreadTask;
import com.arialyy.aria.orm.entity.BlockRecord;
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);
@ -32,5 +33,8 @@ public interface IBlockManager extends ITaskManager {
List<BlockRecord> getUnfinishedBlockList();
/**
* 创建handler 回调
*/
Handler getHandler();
}

@ -44,6 +44,8 @@ interface ITaskManager {
fun stop()
fun cancel()
/**
* 任务是否已经完成
*
@ -64,11 +66,6 @@ interface ITaskManager {
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";
/**
* 广播接收器中通过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}
*/
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.inf.ITaskQueue
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.UploadTask
import com.arialyy.aria.exception.AriaException
import timber.log.Timber

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

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

@ -17,15 +17,16 @@
package com.arialyy.aria.core.task;
import com.arialyy.aria.core.common.TaskOption;
import com.arialyy.aria.orm.entity.DEntity;
import java.util.Objects;
/**
* 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);
}
@ -33,7 +34,7 @@ public class DownloadTask extends AbsTask {
* 获取当前下载任务的下载地址
*/
@Override public int getTaskType() {
return ITask.DOWNLOAD;
return ITask.SINGLE_DOWNLOAD;
}
@Override public String getUrl() {
@ -41,6 +42,6 @@ public class DownloadTask extends AbsTask {
}
@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) {
when (task) {
is DownloadTask -> {
is SingleDownloadTask -> {
taskMap[task.url] = task
}
is DownloadGroupTask -> {
is com.arialyy.dua.group.DownloadGroupTask -> {
taskMap[task.filePath] = task
}
}

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

@ -31,11 +31,7 @@ class TaskState {
lateinit var taskRecord: TaskRecord
var entity: BaseEntity? = null
set(value) {
fileSize = value?.fileSize ?: 0
field = value
}
private lateinit var _entity: BaseEntity
/**
* need to try again?default: false
@ -84,6 +80,15 @@ class TaskState {
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 isCompleted() = state == IEntity.STATE_COMPLETE

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

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

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

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

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

@ -20,10 +20,19 @@ import android.content.pm.PackageManager
import android.net.Uri
import com.arialyy.aria.core.DuaContext
import timber.log.Timber
import java.io.File
import java.math.BigInteger
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 {
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);
}
}
ThreadTaskManager2.INSTANCE.removeAllThreadTask();
ThreadTaskManager2.INSTANCE.stopAllThreadTask();
getCachePool().clear();
}

@ -19,13 +19,13 @@ package com.arialyy.aria.queue;
import android.content.Context;
import androidx.annotation.NonNull;
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.
* 下载任务队列
*/
public class DTaskQueue extends AbsTaskQueue<DownloadTask> {
public class DTaskQueue extends AbsTaskQueue<SingleDownloadTask> {
private static volatile DTaskQueue INSTANCE = null;
public static DTaskQueue getInstance() {

@ -16,13 +16,13 @@
package com.arialyy.aria.schedulers;
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.UploadTask;
/**
* 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 {

@ -16,13 +16,13 @@
package com.arialyy.aria.schedulers;
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.UploadTask;
/**
* 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
TaskInternalListenerInterface {

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

@ -22,7 +22,7 @@ import android.widget.Toast
import com.arialyy.annotations.Download
import com.arialyy.aria.core.Aria
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.simple.R
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)错误
*/
@Download.onTaskRunning
fun running(task: com.arialyy.aria.core.task.DownloadTask) {
fun running(task: SingleDownloadTask) {
Log.d(TAG, task.percent.toString())
val len = task.fileSize
if (len == 0L) {
@ -83,40 +83,40 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleBinding>() {
}
@Download.onWait
fun onWait(task: com.arialyy.aria.core.task.DownloadTask) {
fun onWait(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) {
Log.d(TAG, "wait ==> " + task.downloadEntity.fileName)
}
}
@Download.onPre
fun onPre(task: com.arialyy.aria.core.task.DownloadTask) {
fun onPre(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) {
mStart.text = "停止"
}
}
@Download.onTaskStart
fun taskStart(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskStart(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) {
binding.fileSize = task.convertFileSize
}
}
@Download.onTaskComplete
fun complete(task: com.arialyy.aria.core.task.DownloadTask) {
fun complete(task: SingleDownloadTask) {
Log.d(TAG, "完成")
}
@Download.onTaskResume
fun taskResume(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskResume(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) {
mStart.text = "停止"
}
}
@Download.onTaskStop
fun taskStop(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskStop(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) {
mStart.text = "恢复"
binding.speed = ""
@ -124,7 +124,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleBinding>() {
}
@Download.onTaskCancel
fun taskCancel(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskCancel(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) {
binding.progress = 0
Toast.makeText(this@KotlinDownloadActivity, "取消下载", Toast.LENGTH_SHORT)
@ -136,7 +136,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleBinding>() {
}
@Download.onTaskFail
fun taskFail(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskFail(task: SingleDownloadTask) {
if (task.key == DOWNLOAD_URL) {
Toast.makeText(this@KotlinDownloadActivity, "下载失败", Toast.LENGTH_SHORT)
.show()

@ -24,7 +24,7 @@ import android.widget.TextView;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.task.SingleDownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsDialog;
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()));
}
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
@Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
mSpeed.setText(task.getConvertSpeed());
}
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
@Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
mPb.setProgress(0);
mSpeed.setText(task.getConvertSpeed());
}
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
@Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mPb.setProgress(task.getPercent());
mSpeed.setText(task.getConvertSpeed());

@ -9,7 +9,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
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.simple.R;
import com.arialyy.simple.base.BaseDialog;
@ -58,14 +58,14 @@ import com.arialyy.simple.util.AppUtil;
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());
}
@Download.onTaskRunning(DOWNLOAD_URL) protected void running(DownloadTask task) {
@Download.onTaskRunning(DOWNLOAD_URL) protected void running(SingleDownloadTask task) {
long len = task.getFileSize();
if (len == 0) {
getBinding().setProgress(0);
@ -75,24 +75,24 @@ import com.arialyy.simple.util.AppUtil;
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("");
}
@Download.onTaskCancel(DOWNLOAD_URL) void taskCancel(DownloadTask task) {
@Download.onTaskCancel(DOWNLOAD_URL) void taskCancel(SingleDownloadTask task) {
getBinding().setProgress(0);
Toast.makeText(getContext(), "取消下载", Toast.LENGTH_SHORT).show();
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();
}
@Download.onTaskComplete(DOWNLOAD_URL) void taskComplete(DownloadTask task) {
@Download.onTaskComplete(DOWNLOAD_URL) void taskComplete(SingleDownloadTask task) {
getBinding().setProgress(100);
Toast.makeText(getContext(), "下载完成", Toast.LENGTH_SHORT).show();
getBinding().setSpeed("");

@ -27,7 +27,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
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.frame.core.AbsPopupWindow;
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()));
}
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
@Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
mSpeed.setText("0.0kb/s");
mStart.setText(getContext().getString(R.string.resume));
}
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
@Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
mPb.setProgress(0);
mSpeed.setText("0.0kb/s");
}
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
@Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
long current = task.getCurrentProgress();
long len = task.getFileSize();
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.FtpOption;
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.CommonUtil;
import com.arialyy.simple.R;
@ -100,7 +100,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onWait
void onWait(DownloadTask task) {
void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
getBinding().pl.setInfo(task.getEntity());
@ -108,14 +108,14 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onPre
protected void onPre(DownloadTask task) {
protected void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity());
}
}
@Download.onTaskStart
void taskStart(DownloadTask task) {
void taskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity());
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
@ -123,7 +123,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskRunning
protected void running(DownloadTask task) {
protected void running(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState());
getBinding().pl.setInfo(task.getEntity());
@ -131,7 +131,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskResume
void taskResume(DownloadTask task) {
void taskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "resume");
getBinding().pl.setInfo(task.getEntity());
@ -139,7 +139,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskStop
void taskStop(DownloadTask task) {
void taskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity());
@ -147,7 +147,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskCancel
void taskCancel(DownloadTask task) {
void taskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
mTaskId = -1;
Log.d(TAG, "cancel");
@ -156,7 +156,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskFail
void taskFail(DownloadTask task, Exception e) {
void taskFail(SingleDownloadTask task, Exception e) {
ALog.d(TAG, "下载失败");
Toast.makeText(this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
.show();
@ -166,7 +166,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskComplete
void taskComplete(DownloadTask task) {
void taskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Toast.makeText(this, getString(R.string.download_success),
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.download.DownloadEntity;
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.simple.R;
import com.arialyy.simple.base.BaseActivity;
@ -178,32 +178,32 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mStop.setEnabled(!state);
}
@Download.onPre public void onPre(DownloadTask task) {
@Download.onPre public void onPre(SingleDownloadTask task) {
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
@Download.onTaskPre public void onTaskPre(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mSize.setText(task.getConvertFileSize());
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskStart public void onTaskStart(DownloadTask task) {
@Download.onTaskStart public void onTaskStart(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskResume public void onTaskResume(DownloadTask task) {
@Download.onTaskResume public void onTaskResume(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
@Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("恢复");
@ -212,7 +212,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
@Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mStart.setText("开始");
@ -221,7 +221,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskFail public void onTaskFail(DownloadTask task) {
@Download.onTaskFail public void onTaskFail(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
} 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)) {
setBtState(true);
mStart.setText("重新开始");
@ -239,7 +239,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mAdapter.updateState(task.getDownloadEntity());
}
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
@Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mPb.setProgress(task.getPercent());
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.inf.IEntity
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.CommonUtil
import com.arialyy.frame.util.show.T
@ -178,28 +179,28 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
}
@Download.onWait
fun onWait(task: com.arialyy.aria.core.task.DownloadTask) {
fun onWait(task: SingleDownloadTask) {
if (task.key == mUrl) {
Log.d(TAG, "wait ==> " + task.downloadEntity.fileName)
}
}
@Download.onPre
fun onPre(task: com.arialyy.aria.core.task.DownloadTask) {
fun onPre(task: SingleDownloadTask) {
if (task.key == mUrl) {
binding.stateStr = getString(R.string.stop)
}
}
@Download.onTaskStart
fun taskStart(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskStart(task: SingleDownloadTask) {
if (task.key == mUrl) {
binding.fileSize = task.convertFileSize
}
}
@Download.onTaskRunning
fun running(task: com.arialyy.aria.core.task.DownloadTask) {
fun running(task: SingleDownloadTask) {
if (task.key == mUrl) {
//Log.d(TAG, task.getKey());
val len = task.fileSize
@ -213,14 +214,14 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
}
@Download.onTaskResume
fun taskResume(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskResume(task: SingleDownloadTask) {
if (task.key == mUrl) {
binding.stateStr = getString(R.string.stop)
}
}
@Download.onTaskStop
fun taskStop(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskStop(task: SingleDownloadTask) {
if (task.key == mUrl) {
binding.stateStr = getString(R.string.resume)
binding.speed = ""
@ -228,7 +229,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
}
@Download.onTaskCancel
fun taskCancel(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskCancel(task: SingleDownloadTask) {
if (task.key == mUrl) {
binding.progress = 0
binding.stateStr = getString(R.string.start)
@ -242,7 +243,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
*/
@Download.onTaskFail
fun taskFail(
task: com.arialyy.aria.core.task.DownloadTask,
task: SingleDownloadTask,
e: Exception
) {
if (task.key == mUrl) {
@ -253,7 +254,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
}
@Download.onTaskComplete
fun taskComplete(task: com.arialyy.aria.core.task.DownloadTask) {
fun taskComplete(task: SingleDownloadTask) {
if (task.key == mUrl) {
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.SFtpOption;
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.CommonUtil;
import com.arialyy.aria.util.FileUtil;
@ -143,7 +143,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onWait
void onWait(DownloadTask task) {
void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
getBinding().pl.setInfo(task.getEntity());
@ -151,14 +151,14 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onPre
protected void onPre(DownloadTask task) {
protected void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity());
}
}
@Download.onTaskStart
void taskStart(DownloadTask task) {
void taskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity());
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
@ -166,7 +166,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskRunning
protected void running(DownloadTask task) {
protected void running(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState());
getBinding().pl.setInfo(task.getEntity());
@ -174,7 +174,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskResume
void taskResume(DownloadTask task) {
void taskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "resume");
getBinding().pl.setInfo(task.getEntity());
@ -182,7 +182,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskStop
void taskStop(DownloadTask task) {
void taskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity());
@ -190,7 +190,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskCancel
void taskCancel(DownloadTask task) {
void taskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
mTaskId = -1;
Log.d(TAG, "cancel");
@ -199,7 +199,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskFail
void taskFail(DownloadTask task, Exception e) {
void taskFail(SingleDownloadTask task, Exception e) {
ALog.d(TAG, "下载失败");
Toast.makeText(this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
.show();
@ -209,7 +209,7 @@ public class SFtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskComplete
void taskComplete(DownloadTask task) {
void taskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Toast.makeText(this, getString(R.string.download_success),
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.listener.ISchedulers;
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.CommonUtil;
import com.arialyy.frame.util.show.T;
@ -184,7 +184,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onWait
public void onWait(DownloadTask task) {
public void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
getBinding().pl.setInfo(task.getEntity());
@ -192,7 +192,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onPre
public void onPre(DownloadTask task) {
public void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity());
}
@ -203,7 +203,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//}
@Download.onTaskStart
public void onTaskStart(DownloadTask task) {
public void onTaskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity());
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
@ -211,7 +211,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskRunning
public void onTaskRunning(DownloadTask task) {
public void onTaskRunning(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
//ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState());
getBinding().pl.setInfo(task.getEntity());
@ -223,7 +223,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//}
@Download.onTaskResume
public void onTaskResume(DownloadTask task) {
public void onTaskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "resume");
getBinding().pl.setInfo(task.getEntity());
@ -231,7 +231,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskStop
public void onTaskStop(DownloadTask task) {
public void onTaskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity());
@ -239,7 +239,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskCancel
public void onTaskCancel(DownloadTask task) {
public void onTaskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
mTaskId = -1;
Log.d(TAG, "cancel");
@ -248,7 +248,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskFail
public void onTaskFail(DownloadTask task, Exception e) {
public void onTaskFail(SingleDownloadTask task, Exception e) {
ALog.d(TAG, "下载失败");
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
.show();
@ -258,7 +258,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
@Download.onTaskComplete
public void onTaskComplete(DownloadTask task) {
public void onTaskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_success),
Toast.LENGTH_SHORT).show();

@ -23,7 +23,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.AbsEntity;
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.simple.R;
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());
}
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
@Download.onTaskStop public void onTaskStop(SingleDownloadTask task) {
getBinding().pl.setInfo(task.getEntity());
}
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
@Download.onTaskCancel public void onTaskCancel(SingleDownloadTask task) {
getBinding().pl.setInfo(task.getEntity());
}
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
@Download.onTaskRunning public void onTaskRunning(SingleDownloadTask task) {
long len = task.getFileSize();
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.common.AbsEntity;
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.simple.R;
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)){
return;
}
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)){
return;
}
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)){
return;
}
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)){
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.processor.IBandWidthUrlConverter;
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.CommonUtil;
import com.arialyy.frame.util.show.T;
@ -149,14 +149,14 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
}
@Download.onWait
void onWait(DownloadTask task) {
void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
}
}
@Download.onPre
protected void onPre(DownloadTask task) {
protected void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "pre");
getBinding().pl.setInfo(task.getEntity());
@ -164,7 +164,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
}
@Download.onTaskStart
void taskStart(DownloadTask task) {
void taskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
getBinding().pl.setInfo(task.getEntity());
@ -172,7 +172,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
}
@Download.onTaskRunning
protected void running(DownloadTask task) {
protected void running(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG,
"m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
@ -181,7 +181,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
}
@Download.onTaskResume
void taskResume(DownloadTask task) {
void taskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "m3u8 vod resume");
getBinding().pl.setInfo(task.getEntity());
@ -189,7 +189,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
}
@Download.onTaskStop
void taskStop(DownloadTask task) {
void taskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity());
@ -197,7 +197,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
}
@Download.onTaskCancel
void taskCancel(DownloadTask task) {
void taskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Log.d(TAG, "cancel");
getBinding().pl.setInfo(task.getEntity());
@ -205,7 +205,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
}
@Download.onTaskFail
void taskFail(DownloadTask task, Exception e) {
void taskFail(SingleDownloadTask task, Exception e) {
if (task.getKey().equals(mUrl)) {
Toast.makeText(this, getString(R.string.download_fail),
Toast.LENGTH_SHORT)
@ -216,7 +216,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
}
@Download.onTaskComplete
void taskComplete(DownloadTask task) {
void taskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Toast.makeText(this, getString(R.string.download_success),
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.ITsMergeHandler;
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.CommonUtil;
import com.arialyy.frame.util.show.T;
@ -210,14 +210,14 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
}
@Download.onWait
void onWait(DownloadTask task) {
void onWait(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
}
}
@Download.onPre
protected void onPre(DownloadTask task) {
protected void onPre(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "pre");
getBinding().pl.setInfo(task.getEntity());
@ -225,7 +225,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
}
@Download.onTaskStart
void taskStart(DownloadTask task) {
void taskStart(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getTaskState());
getBinding().seekBar.setMax(task.getEntity().getM3U8Entity().getPeerNum());
@ -234,7 +234,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
}
@Download.onTaskRunning
protected void running(DownloadTask task) {
protected void running(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG,
"m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
@ -243,7 +243,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
}
@Download.onTaskResume
void taskResume(DownloadTask task) {
void taskResume(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "m3u8 vod resume");
getBinding().pl.setInfo(task.getEntity());
@ -251,7 +251,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
}
@Download.onTaskStop
void taskStop(DownloadTask task) {
void taskStop(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity());
@ -259,7 +259,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
}
@Download.onTaskCancel
void taskCancel(DownloadTask task) {
void taskCancel(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Log.d(TAG, "cancel");
getBinding().pl.setInfo(task.getEntity());
@ -267,7 +267,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
}
@Download.onTaskFail
void taskFail(DownloadTask task, Exception e) {
void taskFail(SingleDownloadTask task, Exception e) {
if (task != null && task.getKey().equals(mUrl)) {
Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_fail),
Toast.LENGTH_SHORT)
@ -278,7 +278,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
}
@Download.onTaskComplete
void taskComplete(DownloadTask task) {
void taskComplete(SingleDownloadTask task) {
if (task.getKey().equals(mUrl)) {
Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_success),
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.download.DownloadEntity;
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.simple.R;
import com.arialyy.simple.base.BaseActivity;
@ -76,30 +76,30 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
return true;
}
@Download.onPre void onPre(DownloadTask task) {
@Download.onPre void onPre(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity());
Log.d(TAG, task.getTaskName() + ", " + task.getTaskState());
}
@Download.onWait void onWait(DownloadTask task) {
@Download.onWait void onWait(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity());
}
@Download.onTaskStart void taskStart(DownloadTask task) {
@Download.onTaskStart void taskStart(SingleDownloadTask task) {
Log.d(TAG, task.getTaskName() + ", " + task.getTaskState());
mAdapter.updateState(task.getEntity());
}
@Download.onTaskResume void taskResume(DownloadTask task) {
@Download.onTaskResume void taskResume(SingleDownloadTask task) {
Log.d(TAG, task.getTaskName() + ", " + task.getTaskState());
mAdapter.updateState(task.getEntity());
}
@Download.onTaskStop void taskStop(DownloadTask task) {
@Download.onTaskStop void taskStop(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity());
}
@Download.onTaskCancel void taskCancel(DownloadTask task) {
@Download.onTaskCancel void taskCancel(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity());
List<DownloadEntity> tasks = Aria.download(this).getAllNotCompleteTask();
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){
return;
}
mAdapter.updateState(task.getEntity());
}
@Download.onTaskComplete void taskComplete(DownloadTask task) {
@Download.onTaskComplete void taskComplete(SingleDownloadTask task) {
mAdapter.updateState(task.getEntity());
}
@Download.onTaskRunning void taskRunning(DownloadTask task) {
@Download.onTaskRunning void taskRunning(SingleDownloadTask task) {
mAdapter.setProgress(task.getEntity());
}

@ -28,7 +28,7 @@ import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.AbsEntity;
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.frame.util.FileUtil;
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());
}
@Download.onTaskStart void taskStart(DownloadTask task) {
@Download.onTaskStart void taskStart(SingleDownloadTask task) {
mAdapter.updateBtState(task.getKey(), false);
}
@Download.onTaskResume void taskResume(DownloadTask task) {
@Download.onTaskResume void taskResume(SingleDownloadTask task) {
mAdapter.updateBtState(task.getKey(), false);
}
@Download.onTaskStop void taskStop(DownloadTask task) {
@Download.onTaskStop void taskStop(SingleDownloadTask task) {
mAdapter.updateBtState(task.getKey(), true);
}
@Download.onTaskCancel void taskCancel(DownloadTask task) {
@Download.onTaskCancel void taskCancel(SingleDownloadTask task) {
mAdapter.updateBtState(task.getKey(), true);
}
@Download.onTaskFail void taskFail(DownloadTask task) {
@Download.onTaskFail void taskFail(SingleDownloadTask task) {
if (task == null || task.getEntity() == null){
return;
}
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())));
}

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

@ -22,7 +22,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.FtpOption;
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.frame.util.show.L;
import com.arialyy.simple.util.AppUtil;
@ -43,39 +43,39 @@ public class AnyRunnModule {
mContext = context;
}
@Download.onWait void onWait(DownloadTask task) {
@Download.onWait void onWait(SingleDownloadTask task) {
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");
}
@Download.onTaskStart void taskStart(DownloadTask task) {
@Download.onTaskStart void taskStart(SingleDownloadTask task) {
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());
}
@Download.onTaskResume void taskResume(DownloadTask task) {
@Download.onTaskResume void taskResume(SingleDownloadTask task) {
Log.d(TAG, "resume");
}
@Download.onTaskStop void taskStop(DownloadTask task) {
@Download.onTaskStop void taskStop(SingleDownloadTask task) {
Log.d(TAG, "stop");
}
@Download.onTaskCancel void taskCancel(DownloadTask task) {
@Download.onTaskCancel void taskCancel(SingleDownloadTask task) {
Log.d(TAG, "cancel");
}
@Download.onTaskFail void taskFail(DownloadTask task) {
@Download.onTaskFail void taskFail(SingleDownloadTask task) {
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, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getFilePath())));
}

Loading…
Cancel
Save