diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java index 92322853..4f0f3571 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.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; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index 2ea352ae..0db65c89 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -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); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskListener.java index 84418149..0de8e266 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskListener.java @@ -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 { +public interface DownloadTaskListener extends NormalTaskListenerInterface { } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java b/Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java index eebde726..c3808f67 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java @@ -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 {@link DTaskWrapper}、{@link UTaskWrapper}、{@link * DGTaskWrapper} - * @return {@link DownloadTask}、{@link UploadTask}、{@link DownloadGroupTask} + * @return {@link SingleDownloadTask}、{@link UploadTask}、{@link DownloadGroupTask} */ 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(); } diff --git a/Http/src/main/java/com/arialyy/aria/http/HttpUtil.kt b/Http/src/main/java/com/arialyy/aria/http/HttpUtil.kt index bcaef28d..2a575043 100644 --- a/Http/src/main/java/com/arialyy/aria/http/HttpUtil.kt +++ b/Http/src/main/java/com/arialyy/aria/http/HttpUtil.kt @@ -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 } diff --git a/Http/src/main/java/com/arialyy/aria/http/download/HttpBlockThreadInterceptor.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpBlockThreadInterceptor.kt index c5c7a4c4..8438e6a3 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpBlockThreadInterceptor.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpBlockThreadInterceptor.kt @@ -57,7 +57,7 @@ class HttpBlockThreadInterceptor : ITaskInterceptor { ) else HttpDBTaskAdapter( threadConfig ), - handler = blockManager.getHandler(), + handler = blockManager.handler, record = it ) ) diff --git a/Http/src/main/java/com/arialyy/aria/http/download/HttpDBlockInterceptor.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpDBlockInterceptor.kt index cf53dc09..cccc38c3 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpDBlockInterceptor.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpDBlockInterceptor.kt @@ -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 ) ) diff --git a/Http/src/main/java/com/arialyy/aria/http/download/HttpDCheckInterceptor.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpDCheckInterceptor.kt index 52fb165e..e846eb51 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpDCheckInterceptor.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpDCheckInterceptor.kt @@ -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()) } diff --git a/Http/src/main/java/com/arialyy/aria/http/download/HttpDEventListener.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpDEventListener.kt index e44cb4bc..d80b9223 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpDEventListener.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpDEventListener.kt @@ -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] diff --git a/Http/src/main/java/com/arialyy/aria/http/download/HttpDHeaderInterceptor.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpDHeaderInterceptor.kt index cf64da86..9435a2dd 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpDHeaderInterceptor.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpDHeaderInterceptor.kt @@ -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() } diff --git a/Http/src/main/java/com/arialyy/aria/http/download/HttpDStartController.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpDStartController.kt index f9dd4c75..4125588b 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpDStartController.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpDStartController.kt @@ -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 diff --git a/Http/src/main/java/com/arialyy/aria/http/download/HttpDTaskAdapter.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpDTaskAdapter.kt index 0097745b..486a888f 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpDTaskAdapter.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpDTaskAdapter.kt @@ -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() } } \ No newline at end of file diff --git a/Http/src/main/java/com/arialyy/aria/http/download/HttpDownloadListener.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpDownloadListener.kt index 8b990d72..96949566 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpDownloadListener.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpDownloadListener.kt @@ -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 { +class HttpDownloadListener : ITaskStatusListener { } \ No newline at end of file diff --git a/Http/src/main/java/com/arialyy/aria/http/download/ITaskAdapterDelegate.kt b/Http/src/main/java/com/arialyy/aria/http/download/ITaskAdapterDelegate.kt new file mode 100644 index 00000000..a9f3f3dd --- /dev/null +++ b/Http/src/main/java/com/arialyy/aria/http/download/ITaskAdapterDelegate.kt @@ -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 +} \ No newline at end of file diff --git a/Http/src/main/java/com/arialyy/aria/http/download/SingleTaskDelegate.kt b/Http/src/main/java/com/arialyy/aria/http/download/SingleTaskDelegate.kt new file mode 100644 index 00000000..2cc2104c --- /dev/null +++ b/Http/src/main/java/com/arialyy/aria/http/download/SingleTaskDelegate.kt @@ -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 + } +} \ No newline at end of file diff --git a/Http/src/main/java/com/arialyy/aria/http/download/SubTaskDelegate.kt b/Http/src/main/java/com/arialyy/aria/http/download/SubTaskDelegate.kt new file mode 100644 index 00000000..452cceef --- /dev/null +++ b/Http/src/main/java/com/arialyy/aria/http/download/SubTaskDelegate.kt @@ -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 + } +} \ No newline at end of file diff --git a/Http/src/main/java/com/arialyy/aria/http/download/TimerInterceptor.kt b/Http/src/main/java/com/arialyy/aria/http/download/TimerInterceptor.kt index 2af4899a..c7099d92 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/TimerInterceptor.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/TimerInterceptor.kt @@ -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 } diff --git a/Http/src/main/java/com/arialyy/aria/http/upload/HttpUStartController.kt b/Http/src/main/java/com/arialyy/aria/http/upload/HttpUStartController.kt index bf25e9c2..71c01681 100644 --- a/Http/src/main/java/com/arialyy/aria/http/upload/HttpUStartController.kt +++ b/Http/src/main/java/com/arialyy/aria/http/upload/HttpUStartController.kt @@ -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 { diff --git a/Http/src/main/java/com/arialyy/aria/http/upload/HttpUTaskAdapter.kt b/Http/src/main/java/com/arialyy/aria/http/upload/HttpUTaskAdapter.kt index 055684f8..ca1f0ce8 100644 --- a/Http/src/main/java/com/arialyy/aria/http/upload/HttpUTaskAdapter.kt +++ b/Http/src/main/java/com/arialyy/aria/http/upload/HttpUTaskAdapter.kt @@ -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!! } diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGCheckInterceptor.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGCheckInterceptor.kt index ea2111dc..f14ef5fb 100644 --- a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGCheckInterceptor.kt +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGCheckInterceptor.kt @@ -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() - 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 diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGEventListener.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGEventListener.kt index 33fc6cbf..0ee66879 100644 --- a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGEventListener.kt +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGEventListener.kt @@ -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") } diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGStartController.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGStartController.kt index 1083234e..ad6d50f6 100644 --- a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGStartController.kt +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGStartController.kt @@ -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 diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGSubTaskInterceptor.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGSubTaskInterceptor.kt new file mode 100644 index 00000000..1f700995 --- /dev/null +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGSubTaskInterceptor.kt @@ -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) { + subList.forEach { + + } + } + + private fun createSubTask(chain: TaskChain): List { + val subTaskList = mutableListOf() + 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 + } + +} \ No newline at end of file diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGTaskManager.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGTaskManager.kt index e0b66266..c05f6655 100644 --- a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGTaskManager.kt +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGTaskManager.kt @@ -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 } diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGroupAdapter.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGroupAdapter.kt index 8e1d7bca..815d1c12 100644 --- a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGroupAdapter.kt +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGroupAdapter.kt @@ -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) { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/DownloadGroupTask.java b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpGroupTask.java similarity index 83% rename from PublicComponent/src/main/java/com/arialyy/aria/core/task/DownloadGroupTask.java rename to HttpGroup/src/main/java/com/arialyy/dua/group/HttpGroupTask.java index 127e880e..c77af7e3 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/DownloadGroupTask.java +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpGroupTask.java @@ -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(); } } diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpSubBlockManager.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpSubBlockManager.kt new file mode 100644 index 00000000..bfe6158d --- /dev/null +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpSubBlockManager.kt @@ -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() + private var blockNum: Int = 1 + + override fun putUnfinishedBlock(record: BlockRecord) { + unfinishedBlock.add(record) + } + + override fun getUnfinishedBlockList(): List { + return unfinishedBlock + } + + override fun getHandler() = handler + + override fun start(threadTaskList: List) { + threadTaskList.forEach { tt -> + tt.run() + } + } + + override fun setBlockNum(blockNum: Int) { + this.blockNum = blockNum + } + +} \ No newline at end of file diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpSubListener.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpSubListener.kt new file mode 100644 index 00000000..8ff1c543 --- /dev/null +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpSubListener.kt @@ -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") + } +} \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/command/AbsCmd.java b/PublicComponent/src/main/java/com/arialyy/aria/core/command/AbsCmd.java index 73f97751..df5a7e16 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/command/AbsCmd.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/command/AbsCmd.java @@ -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; } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/command/CmdHelper.java b/PublicComponent/src/main/java/com/arialyy/aria/core/command/CmdHelper.java index 030d00da..d1ca8740 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/command/CmdHelper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/command/CmdHelper.java @@ -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 AbsNormalCmd createNormalCmd(T entity, int cmd, int taskType) { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java b/PublicComponent/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java index d2d8b228..fa914bff 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java @@ -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 extends AbsNormalCmd 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); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/common/TaskOption.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/common/TaskOption.kt index 29f6b627..7b143aac 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/common/TaskOption.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/common/TaskOption.kt @@ -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 } \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IBlockManager.java b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IBlockManager.java index 285e9fa1..b03c3092 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IBlockManager.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IBlockManager.java @@ -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 threadTaskList); @@ -32,5 +33,8 @@ public interface IBlockManager extends ITaskManager { List getUnfinishedBlockList(); - + /** + * 创建handler 回调 + */ + Handler getHandler(); } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/ITaskManager.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/ITaskManager.kt index 0a27461e..e86a5e92 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/ITaskManager.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/ITaskManager.kt @@ -44,6 +44,8 @@ interface ITaskManager { fun stop() + fun cancel() + /** * 任务是否已经完成 * @@ -64,11 +66,6 @@ interface ITaskManager { fun isRunning(): Boolean - /** - * 创建handler 回调 - */ - fun getHandler(): Handler - /** * 是否有失败的快 * diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/listener/ISchedulers.java b/PublicComponent/src/main/java/com/arialyy/aria/core/listener/ISchedulers.java index b1128cce..beb6e70c 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/listener/ISchedulers.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/listener/ISchedulers.java @@ -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"; diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt index 5146ade2..6e1e0733 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/service/ServiceManager.kt @@ -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 diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTaskAdapter.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTaskAdapter.kt index 841300ba..f8700d34 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTaskAdapter.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTaskAdapter.kt @@ -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) { + fun addInterceptors(userInterceptors: List) { 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 = 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) } } \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/DBlockManager.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/task/DBlockManager.kt index 49d4cd2c..3a994df1 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/DBlockManager.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/DBlockManager.kt @@ -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() 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() 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) { + 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) { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ITask.java b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ITask.java index 9d7587ed..5836f729 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ITask.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ITask.java @@ -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(); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/DownloadTask.java b/PublicComponent/src/main/java/com/arialyy/aria/core/task/SingleDownloadTask.java similarity index 79% rename from PublicComponent/src/main/java/com/arialyy/aria/core/task/DownloadTask.java rename to PublicComponent/src/main/java/com/arialyy/aria/core/task/SingleDownloadTask.java index c0ebf5c1..fd6111bb 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/DownloadTask.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/SingleDownloadTask.java @@ -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()); } } \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskCachePool.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskCachePool.kt index 97a7a613..a6961cc8 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskCachePool.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskCachePool.kt @@ -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 } } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskChain.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskChain.kt index 31cdc814..4aa8ec3f 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskChain.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskChain.kt @@ -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, private val index: Int = 0, private val task: ITask, - val blockManager: ITaskManager + val blockManager: IBlockManager ) : ITaskInterceptor.IChain { override fun getTask(): ITask { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskState.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskState.kt index ca314fb9..f69a5c9f 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskState.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/TaskState.kt @@ -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 getEntity(clazz: Class): T { + return _entity as T + } + fun getPercent() = ((curProgress * 100) / fileSize).toInt() fun isCompleted() = state == IEntity.STATE_COMPLETE diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTaskManager2.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTaskManager2.kt index 297f6c83..c48bfdc7 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTaskManager2.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTaskManager2.kt @@ -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> = ConcurrentHashMap() - private val LOCK = ReentrantLock() + private val taskManagerMap: ConcurrentHashMap = 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? = 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() } } \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt b/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt index b2691f24..dbada223 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/dao/DEntityDao.kt @@ -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) diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/DEntity.kt b/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/DEntity.kt index 27f081b8..fc75cd48 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/DEntity.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/DEntity.kt @@ -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() { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/TaskRecord.kt b/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/TaskRecord.kt index f88cd5f5..905e2910 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/TaskRecord.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/entity/TaskRecord.kt @@ -33,7 +33,7 @@ data class TaskRecord( */ val filePath: Uri, /** - * [ITask.DOWNLOAD] ... + * [ITask.SINGLE_DOWNLOAD] ... */ val taskType: Int, val fileLen: Long, diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/BlockUtil.kt b/PublicComponent/src/main/java/com/arialyy/aria/util/BlockUtil.kt index 5ddd6332..44bab4e2 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/BlockUtil.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/BlockUtil.kt @@ -36,10 +36,9 @@ object BlockUtil { /** * create block record */ - fun createBlockRecord(fileSaveUri: Uri, fileSize: Long): List { - val filePath = FileUri.getPathByUri(fileSaveUri) ?: "/" - val fileName = FileUtils.getFileNameFromPath(filePath) - val dirPath = FileUtils.getFilePathFromFullPath(filePath) + fun createBlockRecord(filePath: File, fileSize: Long): List { + val fileName = filePath.name + val dirPath = filePath.parent val blockNumInfo = getBlockNum(fileSize) val lastIndex = blockNumInfo.first - 1 diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/Ext.kt b/PublicComponent/src/main/java/com/arialyy/aria/util/Ext.kt index 8e8f0925..ff1cfa7d 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/Ext.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/Ext.kt @@ -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) } diff --git a/Queue/src/main/java/com/arialyy/aria/queue/AbsTaskQueue.java b/Queue/src/main/java/com/arialyy/aria/queue/AbsTaskQueue.java index 382a8ad4..388ae042 100644 --- a/Queue/src/main/java/com/arialyy/aria/queue/AbsTaskQueue.java +++ b/Queue/src/main/java/com/arialyy/aria/queue/AbsTaskQueue.java @@ -133,7 +133,7 @@ public abstract class AbsTaskQueue implements ITaskQueue { +public class DTaskQueue extends AbsTaskQueue { private static volatile DTaskQueue INSTANCE = null; public static DTaskQueue getInstance() { diff --git a/Schedulers/src/main/java/com/arialyy/aria/schedulers/AptNormalTaskListener.java b/Schedulers/src/main/java/com/arialyy/aria/schedulers/AptNormalTaskListener.java index 440d30ec..e5cd75cb 100644 --- a/Schedulers/src/main/java/com/arialyy/aria/schedulers/AptNormalTaskListener.java +++ b/Schedulers/src/main/java/com/arialyy/aria/schedulers/AptNormalTaskListener.java @@ -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 implements NormalTaskListenerInterface, ISchedulerListener { diff --git a/Schedulers/src/main/java/com/arialyy/aria/schedulers/NormalTaskListenerInterface.java b/Schedulers/src/main/java/com/arialyy/aria/schedulers/NormalTaskListenerInterface.java index af7c97ab..0111cd83 100644 --- a/Schedulers/src/main/java/com/arialyy/aria/schedulers/NormalTaskListenerInterface.java +++ b/Schedulers/src/main/java/com/arialyy/aria/schedulers/NormalTaskListenerInterface.java @@ -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 extends TaskInternalListenerInterface { diff --git a/Schedulers/src/main/java/com/arialyy/aria/schedulers/TaskSchedulers.java b/Schedulers/src/main/java/com/arialyy/aria/schedulers/TaskSchedulers.java index 409440ca..c44f0d00 100644 --- a/Schedulers/src/main/java/com/arialyy/aria/schedulers/TaskSchedulers.java +++ b/Schedulers/src/main/java/com/arialyy/aria/schedulers/TaskSchedulers.java @@ -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 implements ISchedulers { * @param taskType 任务类型 */ ITaskQueue 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 implements ISchedulers { } NormalTaskListenerInterface listener = null; if (mObservers.get(key) != null) { - if (taskType == ITask.DOWNLOAD) { + if (taskType == ITask.SINGLE_DOWNLOAD) { listener = (NormalTaskListenerInterface) listeners.get(TaskEnum.DOWNLOAD); - } else if (taskType == ITask.DOWNLOAD_GROUP) { + } else if (taskType == ITask.HTTP_GROUP) { listener = (NormalTaskListenerInterface) listeners.get(TaskEnum.DOWNLOAD_GROUP); - } else if (taskType == ITask.DOWNLOAD_GROUP) { + } else if (taskType == ITask.HTTP_GROUP) { listener = (NormalTaskListenerInterface) listeners.get(TaskEnum.UPLOAD); } } @@ -397,7 +397,7 @@ public class TaskSchedulers implements ISchedulers { } NormalTaskListenerInterface listener = null; if (mObservers.get(key) != null) { - if (task instanceof DownloadTask) { + if (task instanceof SingleDownloadTask) { listener = (NormalTaskListenerInterface) listeners.get(TaskEnum.DOWNLOAD); } else if (task instanceof DownloadGroupTask) { listener = (NormalTaskListenerInterface) listeners.get(TaskEnum.DOWNLOAD_GROUP); @@ -470,7 +470,7 @@ public class TaskSchedulers 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)); diff --git a/app/src/main/assets/help_code/KotlinHttpDownload.kt b/app/src/main/assets/help_code/KotlinHttpDownload.kt index a1dfe1cb..ea5b34ce 100644 --- a/app/src/main/assets/help_code/KotlinHttpDownload.kt +++ b/app/src/main/assets/help_code/KotlinHttpDownload.kt @@ -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() { * 注解方法不能添加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() { } @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() { } @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() { } @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() diff --git a/app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java b/app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java index de3c5d70..00814b7c 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java +++ b/app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java @@ -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()); diff --git a/app/src/main/java/com/arialyy/simple/core/download/DownloadDialogFragment.java b/app/src/main/java/com/arialyy/simple/core/download/DownloadDialogFragment.java index 2929a91f..98277214 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/DownloadDialogFragment.java +++ b/app/src/main/java/com/arialyy/simple/core/download/DownloadDialogFragment.java @@ -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(""); diff --git a/app/src/main/java/com/arialyy/simple/core/download/DownloadPopupWindow.java b/app/src/main/java/com/arialyy/simple/core/download/DownloadPopupWindow.java index 4c7e2bd6..ba8b13d1 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/DownloadPopupWindow.java +++ b/app/src/main/java/com/arialyy/simple/core/download/DownloadPopupWindow.java @@ -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) { diff --git a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java index c57f2933..e8117d44 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java @@ -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 { } @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 { } @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 { } @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 { } @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 { } @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 { } @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 { } @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 { } @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(); diff --git a/app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java b/app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java index a20803b2..9dfebdba 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java @@ -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() { } @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() { } @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() { } @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() { */ @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() { } @Download.onTaskComplete - fun taskComplete(task: com.arialyy.aria.core.task.DownloadTask) { + fun taskComplete(task: SingleDownloadTask) { if (task.key == mUrl) { binding.progress = 100 diff --git a/app/src/main/java/com/arialyy/simple/core/download/SFtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/SFtpDownloadActivity.java index fc68b25d..d3be38d4 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/SFtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/SFtpDownloadActivity.java @@ -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 { } @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 { } @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 { } @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 { } @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 { } @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 { } @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 { } @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 { } @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(); diff --git a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java index b9af0778..09dccc4d 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java @@ -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 { } @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 { } @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 { //} @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 { } @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 { //} @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 { } @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 { } @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 { } @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 { } @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(); diff --git a/app/src/main/java/com/arialyy/simple/core/download/fragment/DownloadFragment.java b/app/src/main/java/com/arialyy/simple/core/download/fragment/DownloadFragment.java index c821a197..2aedf84d 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/fragment/DownloadFragment.java +++ b/app/src/main/java/com/arialyy/simple/core/download/fragment/DownloadFragment.java @@ -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 { }); } - @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()); } diff --git a/app/src/main/java/com/arialyy/simple/core/download/fragment/MultiItemFragment.java b/app/src/main/java/com/arialyy/simple/core/download/fragment/MultiItemFragment.java index ff5f544e..97741df6 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/fragment/MultiItemFragment.java +++ b/app/src/main/java/com/arialyy/simple/core/download/fragment/MultiItemFragment.java @@ -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 { }); } - @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; } diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveDLoadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveDLoadActivity.java index 59c45700..bfbce644 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveDLoadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveDLoadActivity.java @@ -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 } @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 } @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 } @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 } @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 } @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 } @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 } @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 } @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(); diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java index b335a092..8adce718 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java @@ -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 { } @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 { } @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 { } @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 { } @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 { } @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 { } @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 { } @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 { } @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(); diff --git a/app/src/main/java/com/arialyy/simple/core/download/mutil/MultiDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/mutil/MultiDownloadActivity.java index c8e56484..75034fee 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/mutil/MultiDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/mutil/MultiDownloadActivity.java @@ -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 tasks = Aria.download(this).getAllNotCompleteTask(); if (tasks != null){ @@ -107,18 +107,18 @@ public class MultiDownloadActivity extends BaseActivity { } } - @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()))); } diff --git a/app/src/main/java/com/arialyy/simple/core/download/service/DownloadService.java b/app/src/main/java/com/arialyy/simple/core/download/service/DownloadService.java index 8d7745a4..6ac85ffd 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/service/DownloadService.java +++ b/app/src/main/java/com/arialyy/simple/core/download/service/DownloadService.java @@ -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); diff --git a/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java b/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java index 8bc2331f..9082da48 100644 --- a/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java +++ b/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java @@ -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()))); }