diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/NormalController.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/NormalController.java index 3a5a6cd8..eea22cd0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/NormalController.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/NormalController.java @@ -15,7 +15,7 @@ */ package com.arialyy.aria.core.common.controller; -import com.arialyy.aria.core.command.CancelCmd; +import com.arialyy.aria.core.command.DeleteCmd; import com.arialyy.aria.core.command.CmdHelper; import com.arialyy.aria.core.command.NormalCmdFactory; import com.arialyy.aria.core.command.StartCmd; @@ -106,11 +106,11 @@ public final class NormalController extends FeatureController implements INormal public void cancel(boolean removeFile) { setAction(ACTION_CANCEL); if (checkConfig()) { - CancelCmd cancelCmd = - (CancelCmd) CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_CANCEL, + DeleteCmd deleteCmd = + (DeleteCmd) CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_CANCEL, checkTaskType()); - cancelCmd.removeFile = removeFile; - EventMsgUtil.getDefault().post(cancelCmd); + deleteCmd.removeFile = removeFile; + EventMsgUtil.getDefault().post(deleteCmd); } } 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 0db65c89..646f7db3 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 @@ -18,7 +18,7 @@ package com.arialyy.aria.core.download; import com.arialyy.annotations.TaskEnum; import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.command.CancelAllCmd; +import com.arialyy.aria.core.command.DeleteAllCmd; import com.arialyy.aria.core.command.CmdHelper; import com.arialyy.aria.core.command.NormalCmdFactory; import com.arialyy.aria.core.common.AbsBuilderTarget; @@ -506,8 +506,8 @@ public class DownloadReceiver extends AbsReceiver { */ public void removeAllTask(boolean removeFile) { final AriaManager ariaManager = AriaManager.getInstance(); - CancelAllCmd cancelCmd = - (CancelAllCmd) CmdHelper.createNormalCmd(new DTaskWrapper(null), + DeleteAllCmd cancelCmd = + (DeleteAllCmd) CmdHelper.createNormalCmd(new DTaskWrapper(null), 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/target/AbsGroupConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/AbsGroupConfigHandler.java deleted file mode 100644 index 3eec7170..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/AbsGroupConfigHandler.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.arialyy.aria.core.download.target; - -import android.text.TextUtils; -import com.arialyy.aria.core.common.AbsNormalTarget; -import com.arialyy.aria.core.download.DGTaskWrapper; -import com.arialyy.aria.core.download.DownloadGroupEntity; -import com.arialyy.aria.core.event.ErrorEvent; -import com.arialyy.aria.core.inf.AbsTarget; -import com.arialyy.aria.core.inf.IConfigHandler; -import com.arialyy.aria.core.manager.SubTaskManager; -import com.arialyy.aria.core.manager.TaskWrapperManager; -import com.arialyy.aria.core.queue.DGroupTaskQueue; -import com.arialyy.aria.core.task.DownloadGroupTask; -import com.arialyy.aria.orm.DbEntity; -import com.arialyy.aria.util.CommonUtil; - -/** - * Created by lyy on 2019/4/9. - * 下载组合任务功能 - */ -abstract class AbsGroupConfigHandler implements IConfigHandler { - protected String TAG; - private TARGET mTarget; - private DGTaskWrapper mWrapper; - - private SubTaskManager mSubTaskManager; - - AbsGroupConfigHandler(TARGET target, long taskId) { - TAG = CommonUtil.getClassName(getClass()); - mTarget = target; - mWrapper = TaskWrapperManager.getInstance().getGroupWrapper(DGTaskWrapper.class, taskId); - // 判断已存在的任务 - if (mTarget instanceof AbsNormalTarget) { - if (taskId < 0) { - mWrapper.setErrorEvent(new ErrorEvent(taskId, "任务id为空")); - } else if (mWrapper.getEntity().getId() < 0) { - mWrapper.setErrorEvent(new ErrorEvent(taskId, "任务信息不存在")); - } - } - - mTarget.setTaskWrapper(mWrapper); - if (getEntity() != null) { - getTaskWrapper().setDirPathTemp(getEntity().getDirPath()); - } - } - - /** - * 获取子任务管理器 - * - * @return 子任务管理器 - */ - SubTaskManager getSubTaskManager() { - if (mSubTaskManager == null) { - mSubTaskManager = new SubTaskManager(getTaskWrapper()); - } - return mSubTaskManager; - } - - /** - * 设置任务组别名 - */ - void setGroupAlias(String alias) { - if (TextUtils.isEmpty(alias)) { - return; - } - getEntity().setAlias(alias); - } - - @Override public boolean isRunning() { - DownloadGroupTask task = DGroupTaskQueue.getInstance().getTask(getEntity().getKey()); - return task != null && task.isRunning(); - } - - TARGET setDirPath(String dirPath) { - mWrapper.setDirPathTemp(dirPath); - return mTarget; - } - - @Override public DownloadGroupEntity getEntity() { - return mWrapper.getEntity(); - } - - @Override public boolean taskExists() { - return getEntity().getId() != -1 && DbEntity.checkDataExist(DownloadGroupEntity.class, - "rowid=?", String.valueOf(getEntity().getId())); - } - - DGTaskWrapper getTaskWrapper() { - return mWrapper; - } - - TARGET getTarget() { - return mTarget; - } -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java index 10ddf065..8e2f7670 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java @@ -19,7 +19,7 @@ import android.text.TextUtils; import com.arialyy.annotations.TaskEnum; import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.command.CancelAllCmd; +import com.arialyy.aria.core.command.DeleteAllCmd; import com.arialyy.aria.core.command.CmdHelper; import com.arialyy.aria.core.command.NormalCmdFactory; import com.arialyy.aria.core.common.AbsBuilderTarget; @@ -251,8 +251,8 @@ public class UploadReceiver extends AbsReceiver { */ public void removeAllTask(boolean removeFile) { final AriaManager am = AriaManager.getInstance(); - CancelAllCmd cancelCmd = - (CancelAllCmd) CmdHelper.createNormalCmd(new UTaskWrapper(null), + DeleteAllCmd cancelCmd = + (DeleteAllCmd) CmdHelper.createNormalCmd(new UTaskWrapper(null), NormalCmdFactory.TASK_CANCEL_ALL, ITask.UPLOAD); cancelCmd.removeFile = removeFile; diff --git a/Http/src/main/java/com/arialyy/aria/http/HttpCmdHandler.kt b/Http/src/main/java/com/arialyy/aria/http/HttpCmdHandler.kt new file mode 100644 index 00000000..a7345249 --- /dev/null +++ b/Http/src/main/java/com/arialyy/aria/http/HttpCmdHandler.kt @@ -0,0 +1,113 @@ +/* + * 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 + +import androidx.annotation.Keep +import com.arialyy.aria.core.DuaContext +import com.arialyy.aria.core.command.ICmdHandler +import com.arialyy.aria.core.command.StartCmd +import com.arialyy.aria.core.event.DeleteAllEvent +import com.arialyy.aria.core.event.Event +import com.arialyy.aria.core.event.EventMsgUtil +import com.arialyy.aria.core.event.ResumeAllEvent +import com.arialyy.aria.core.event.StopAllEvent +import com.arialyy.aria.http.download.HttpDTaskAdapter +import com.arialyy.aria.util.FileUtils +import com.arialyy.aria.util.isNotComplete +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import timber.log.Timber + +/** + * @Author laoyuyu + * @Description + * @Date 12:40 PM 2023/4/2 + **/ +@Keep +internal object HttpCmdHandler : ICmdHandler { + override fun initHandler() { + EventMsgUtil.getDefault().register(this) + } + + @Event + fun resumeAll(event: ResumeAllEvent) { + DuaContext.duaScope.launch(Dispatchers.IO) { + resumeDTask() + } + } + + @Event + fun stopAll(event: StopAllEvent) { + DuaContext.duaScope.launch(Dispatchers.IO) { + DuaContext.getServiceManager().getDownloadQueue().stopAllTask() + } + } + + @Event + fun removeAll(event: DeleteAllEvent) { + DuaContext.duaScope.launch(Dispatchers.IO) { + removeAllDTask(event) + } + } + + private suspend fun removeAllDTask(event: DeleteAllEvent) { + val dao = DuaContext.getServiceManager().getDbService().getDuaDb().getDEntityDao() + val entityList = dao.queryDEntityList() + DuaContext.getServiceManager().getDownloadQueue().deleteAllTask() + dao.deleteAll() + if (event.onlyRemoveRecord) { + Timber.d("Only remove record") + return + } + // Delete the downloaded file + entityList.forEach { + if (it.fileIsComplete()) { + val path = it.getFilePath() + Timber.d("Delete file: $path") + FileUtils.deleteFile(path) + } + } + } + + /** + * Recovery status is an unfinished task + */ + private suspend fun resumeDTask() { + val entityList = DuaContext.getServiceManager().getDbService().getDuaDb().getDEntityDao() + .queryAllNotCompleteEntityList() + if (entityList.isNullOrEmpty()) { + Timber.w("No tasks to recover") + return + } + entityList.forEach { + if (!it.isNotComplete()) { + Timber.d("Ignore the task, task status: ${it.state}") + return@forEach + } + val taskOption = HttpTaskOption() + taskOption.sourUrl = it.sourceUrl + val tempTask = HttpUtil.getSingDTask(taskOption) + if (tempTask == null) { + Timber.e("Resume task fail, url: ${it.sourceUrl}") + return@forEach + } + val taskAdapter = HttpDTaskAdapter() + tempTask.adapter = taskAdapter + StartCmd(tempTask).executeCmd() + } + } + +} \ No newline at end of file diff --git a/Http/src/main/java/com/arialyy/aria/http/HttpComponent.kt b/Http/src/main/java/com/arialyy/aria/http/HttpComponent.kt index 9d393204..2146c705 100644 --- a/Http/src/main/java/com/arialyy/aria/http/HttpComponent.kt +++ b/Http/src/main/java/com/arialyy/aria/http/HttpComponent.kt @@ -1,9 +1,6 @@ package com.arialyy.aria.http import android.content.Context -import com.arialyy.aria.core.event.Event -import com.arialyy.aria.core.event.EventMsgUtil -import com.arialyy.aria.core.event.ResumeAllEvent import com.arialyy.aria.core.inf.IComponentInit /** @@ -13,12 +10,7 @@ import com.arialyy.aria.core.inf.IComponentInit **/ class HttpComponent : IComponentInit { override fun init(context: Context) { - EventMsgUtil.getDefault().register(this) - } - - @Event - fun resumeAll(resumeAllEvent: ResumeAllEvent) { - + HttpCmdHandler.initHandler() } } \ No newline at end of file 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 2a575043..cc5b2f80 100644 --- a/Http/src/main/java/com/arialyy/aria/http/HttpUtil.kt +++ b/Http/src/main/java/com/arialyy/aria/http/HttpUtil.kt @@ -16,6 +16,9 @@ package com.arialyy.aria.http import android.text.TextUtils +import com.arialyy.aria.core.task.SingleDownloadTask +import com.arialyy.aria.core.task.TaskCachePool +import com.arialyy.aria.http.download.HttpDTaskAdapter import com.arialyy.aria.util.FileUtils import com.arialyy.aria.util.Regular import timber.log.Timber @@ -33,6 +36,33 @@ import java.util.zip.InflaterInputStream **/ object HttpUtil { + /** + * get or create single task + * @param createNewTask if not found task in [TaskCachePool], create new task + */ + fun getSingDTask( + httpTaskOption: HttpTaskOption, + createNewTask: Boolean = true + ): SingleDownloadTask? { + if (checkHttpDParams(httpTaskOption)) { + throw IllegalArgumentException("invalid params") + } + if (httpTaskOption.sourUrl.isNullOrEmpty()) { + return null + } + val tempTask = TaskCachePool.getTaskByKey(httpTaskOption.sourUrl!!) + if (tempTask != null) { + return tempTask as SingleDownloadTask + } + if (!createNewTask) { + return null + } + val task = SingleDownloadTask(httpTaskOption) + task.adapter = HttpDTaskAdapter() + TaskCachePool.putTask(task) + return task + } + /** * 拦截window.location.replace数据 * @@ -95,7 +125,7 @@ object HttpUtil { Timber.e("invalid uri, ${option.savePathDir}") return false } - if (!FileUtils.uriIsDir(option.savePathDir!!)){ + 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/HttpDBlockManager.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpDBlockManager.kt index 6172bce8..df89850d 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpDBlockManager.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpDBlockManager.kt @@ -43,7 +43,7 @@ class HttpDBlockManager(task: ITask) : DBlockManager(task) { } } - override fun cancel() { + override fun delete() { optionAdapter.threadList.forEach { it.cancel() } 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 79b3d7cc..8242eab3 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 @@ -18,16 +18,14 @@ package com.arialyy.aria.http.download import android.net.Uri import com.arialyy.aria.core.DuaContext import com.arialyy.aria.core.command.AddCmd -import com.arialyy.aria.core.command.CancelCmd +import com.arialyy.aria.core.command.DeleteCmd import com.arialyy.aria.core.command.StartCmd import com.arialyy.aria.core.command.StopCmd -import com.arialyy.aria.http.IHttpFileLenAdapter -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 import com.arialyy.aria.http.HttpOption import com.arialyy.aria.http.HttpUtil +import com.arialyy.aria.http.IHttpFileLenAdapter import timber.log.Timber import java.net.HttpURLConnection @@ -92,28 +90,11 @@ class HttpDStartController(target: Any, val url: String) : HttpBaseStartControll return this } - 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 SingleDownloadTask - } - if (!createNewTask) { - return null - } - val task = SingleDownloadTask(httpTaskOption) - task.adapter = HttpDTaskAdapter() - TaskCachePool.putTask(task) - return task - } - fun add(): Int { if (!HttpUtil.checkHttpDParams(httpTaskOption)) { return -1 } - val task = getTask() + val task = HttpUtil.getSingDTask(httpTaskOption) val resp = AddCmd(task).executeCmd() return if (resp.isInterrupt()) -1 else task?.taskId ?: -1 } @@ -122,7 +103,7 @@ class HttpDStartController(target: Any, val url: String) : HttpBaseStartControll if (!HttpUtil.checkHttpDParams(httpTaskOption)) { return -1 } - val task = getTask() + val task = HttpUtil.getSingDTask(httpTaskOption) val resp = StartCmd(task).executeCmd() return if (resp.isInterrupt()) -1 else task?.taskId ?: -1 } @@ -131,17 +112,17 @@ class HttpDStartController(target: Any, val url: String) : HttpBaseStartControll return start() } - fun cancel() { - val task = getTask(true) + fun delete() { + val task = HttpUtil.getSingDTask(httpTaskOption, true) if (task == null) { Timber.e("not found task, url: $url") return } - CancelCmd(task).executeCmd() + DeleteCmd(task).executeCmd() } fun stop() { - val task = getTask(false) + val task = HttpUtil.getSingDTask(httpTaskOption, false) if (task == null) { Timber.e("task not running, url: $url") return diff --git a/Http/src/main/java/com/arialyy/aria/http/download/HttpDStopController.kt b/Http/src/main/java/com/arialyy/aria/http/download/HttpDStopController.kt index 22b10565..0fdcdfa7 100644 --- a/Http/src/main/java/com/arialyy/aria/http/download/HttpDStopController.kt +++ b/Http/src/main/java/com/arialyy/aria/http/download/HttpDStopController.kt @@ -15,7 +15,7 @@ */ package com.arialyy.aria.http.download -import com.arialyy.aria.core.command.CancelCmd +import com.arialyy.aria.core.command.DeleteCmd import com.arialyy.aria.core.command.StopCmd import com.arialyy.aria.core.task.TaskCachePool import timber.log.Timber @@ -27,13 +27,13 @@ import timber.log.Timber **/ class HttpDStopController(val taskId: Int) { - fun cancel() { + fun delete() { val task = TaskCachePool.getTaskById(taskId) if (task == null) { Timber.e("task not found, taskId: $taskId") return } - CancelCmd(task).executeCmd() + DeleteCmd(task).executeCmd() } fun stop() { diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGAdapter.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGAdapter.kt index b69915a2..72443c2a 100644 --- a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGAdapter.kt +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGAdapter.kt @@ -59,7 +59,7 @@ internal class HttpDGAdapter : AbsTaskAdapter() { Timber.w("task already canceled, taskId: ${getTask().taskId}") return } - it.cancel() + it.delete() } } diff --git a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGLoader.kt b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGLoader.kt index 12665862..748fe156 100644 --- a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGLoader.kt +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGLoader.kt @@ -32,6 +32,19 @@ class HttpDGLoader(private val target: Any) : IDownloader { /** * start, create a task + * + *``` + * + mnt + * + sdcard + * + download + * + group_test + * - task1.apk + * - task2.apk + * - task3.apk + * .... + * + *``` + * * @param savePath download url */ fun load(savePath: Uri): HttpDGStartController { 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 0c341255..62504163 100644 --- a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGStartController.kt +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGStartController.kt @@ -18,7 +18,7 @@ package com.arialyy.dua.group import android.net.Uri import com.arialyy.aria.core.DuaContext import com.arialyy.aria.core.command.AddCmd -import com.arialyy.aria.core.command.CancelCmd +import com.arialyy.aria.core.command.DeleteCmd import com.arialyy.aria.core.command.StartCmd import com.arialyy.aria.core.command.StopCmd import com.arialyy.aria.core.task.ITaskInterceptor @@ -149,7 +149,7 @@ class HttpDGStartController(target: Any, private val savePath: Uri) : Timber.e("not found task, savePath: $savePath") return } - CancelCmd(task).executeCmd() + DeleteCmd(task).executeCmd() } fun stop() { 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 26cf46d8..f163d3db 100644 --- a/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGTaskManager.kt +++ b/HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGTaskManager.kt @@ -132,10 +132,10 @@ internal class HttpDGTaskManager(private val task: HttpDGTask) : ITaskManager, I } } - override fun cancel() { + override fun delete() { scope.launch(Dispatchers.IO) { task.subTaskList.forEach { - it.cancel(TaskSchedulerType.TYPE_DEFAULT) + it.delete(TaskSchedulerType.TYPE_DEFAULT) } task.subTaskList.clear() } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/command/CancelAllCmd.java b/PublicComponent/src/main/java/com/arialyy/aria/core/command/CancelAllCmd.java deleted file mode 100644 index f589d984..00000000 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/command/CancelAllCmd.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arialyy.aria.core.command; - -import com.arialyy.aria.core.download.DGTaskWrapper; -import com.arialyy.aria.core.download.DTaskWrapper; -import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadGroupEntity; -import com.arialyy.aria.core.wrapper.AbsTaskWrapper; -import com.arialyy.aria.core.manager.TaskWrapperManager; -import com.arialyy.aria.core.queue.DGroupTaskQueue; -import com.arialyy.aria.core.queue.DTaskQueue; -import com.arialyy.aria.core.queue.UTaskQueue; -import com.arialyy.aria.core.upload.UTaskWrapper; -import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.orm.DbEntity; -import com.arialyy.aria.util.ALog; -import java.util.List; - -/** - * Created by AriaL on 2017/6/27. - * 删除所有任务,并且删除所有回掉 - */ -final public class CancelAllCmd extends AbsNormalCmd { - /** - * removeFile {@code true} 删除已经下载完成的任务,不仅删除下载记录,还会删除已经下载完成的文件,{@code false} - * 如果文件已经下载完成,只删除下载记录 - */ - public boolean removeFile = false; - - CancelAllCmd(T entity, int taskType) { - super(entity, taskType); - } - - @Override public void executeCmd() { - if (!canExeCmd) return; - if (isDownloadCmd) { - removeAllDTask(); - removeAllDGTask(); - } else { - removeUTask(); - } - } - - /** - * 删除所有普通下载任务 - */ - private void removeAllDTask() { - List entities = - DbEntity.findDatas(DownloadEntity.class, "isGroupChild=?", "false"); - if (entities != null && !entities.isEmpty()) { - for (DownloadEntity entity : entities) { - remove(TaskWrapperManager.getInstance() - .getNormalTaskWrapper(DTaskWrapper.class, entity.getId())); - } - } - } - - /** - * 删除所有下载任务组任务 - */ - private void removeAllDGTask() { - List entities = - DbEntity.findDatas(DownloadGroupEntity.class, "state!=?", "-1"); - if (entities != null && !entities.isEmpty()) { - for (DownloadGroupEntity entity : entities) { - remove(TaskWrapperManager.getInstance() - .getGroupWrapper(DGTaskWrapper.class, entity.getId())); - } - } - } - - /** - * 删除所有普通上传任务 - */ - private void removeUTask() { - List entities = - DbEntity.findDatas(UploadEntity.class, "isGroupChild=?", "false"); - if (entities != null && !entities.isEmpty()) { - for (UploadEntity entity : entities) { - remove(TaskWrapperManager.getInstance() - .getNormalTaskWrapper(UTaskWrapper.class, entity.getId())); - } - } - } - - private void remove(AbsTaskWrapper te) { - if (te == null) { - ALog.w(TAG, "取消任务失败,任务为空"); - return; - } - if (te instanceof DTaskWrapper) { - mQueue = DTaskQueue.getInstance(); - } else if (te instanceof UTaskWrapper) { - mQueue = UTaskQueue.getInstance(); - } else if (te instanceof DGTaskWrapper) { - mQueue = DGroupTaskQueue.getInstance(); - } - te.setRemoveFile(removeFile); - removeTask(te); - } -} diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/command/CommandManager.java b/PublicComponent/src/main/java/com/arialyy/aria/core/command/DeleteAllCmd.java similarity index 52% rename from PublicComponent/src/main/java/com/arialyy/aria/core/command/CommandManager.java rename to PublicComponent/src/main/java/com/arialyy/aria/core/command/DeleteAllCmd.java index 9227b7fc..142c2b06 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/command/CommandManager.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/command/DeleteAllCmd.java @@ -13,32 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.arialyy.aria.core.command; +import com.arialyy.aria.core.event.EventMsgUtil; +import com.arialyy.aria.core.event.DeleteAllEvent; + /** - * 命令处理器 + * Created by AriaL on 2017/6/27. + * 删除所有任务,并且删除所有回掉 */ -public class CommandManager { +final public class DeleteAllCmd implements ICmd { - private static CommandManager instance; - - private CommandManager() { - } + private boolean onlyDeleteRecord; - public static void init() { - if (instance == null) { - synchronized (CommandManager.class) { - if (instance == null) { - instance = new CommandManager(); - } - } - } + /** + * @param onlyDeleteRecord true: Delete records only; + * false: Delete file and records + */ + public DeleteAllCmd(boolean onlyDeleteRecord) { + this.onlyDeleteRecord = onlyDeleteRecord; } - public void exeCmd(ICmd cmd) { - //if (CommonUtil.isFastDoubleClick()) { - // return; - //} - cmd.executeCmd(); + @Override public CmdResp executeCmd() { + EventMsgUtil.getDefault().post(new DeleteAllEvent(onlyDeleteRecord)); + return new CmdResp(CmdResp.CODE_COMPLETE); } } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/command/CancelCmd.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/command/DeleteCmd.kt similarity index 87% rename from PublicComponent/src/main/java/com/arialyy/aria/core/command/CancelCmd.kt rename to PublicComponent/src/main/java/com/arialyy/aria/core/command/DeleteCmd.kt index ab0b00b5..9eded138 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/command/CancelCmd.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/command/DeleteCmd.kt @@ -27,7 +27,7 @@ import timber.log.Timber * Created by lyy on 2016/9/20. * 取消命令 */ -class CancelCmd(task: ITask) : AbsCmd(task) { +class DeleteCmd(task: ITask) : AbsCmd(task) { override fun executeCmd(): CmdResp { val resp = interceptor() @@ -35,12 +35,6 @@ class CancelCmd(task: ITask) : AbsCmd(task) { Timber.w("interruption occurred, cancel cmd") return resp } - - if (!taskQueue.taskIsRunning(mTask?.taskId ?: -1)) { - // remove already file - - return CmdResp(CmdResp.CODE_COMPLETE) - } DuaContext.duaScope.launch(Dispatchers.IO) { ThreadTaskManager2.stopThreadTask(mTask!!.taskId, true) } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/event/USpeedEvent.java b/PublicComponent/src/main/java/com/arialyy/aria/core/command/ICmdHandler.kt similarity index 80% rename from PublicComponent/src/main/java/com/arialyy/aria/core/event/USpeedEvent.java rename to PublicComponent/src/main/java/com/arialyy/aria/core/command/ICmdHandler.kt index c3693709..b6520c27 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/event/USpeedEvent.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/command/ICmdHandler.kt @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.event; +package com.arialyy.aria.core.command -public class USpeedEvent { - - public int speed; - - public USpeedEvent(int speed) { - this.speed = speed; - } -} +/** + * @Author laoyuyu + * @Description + * @Date 21:51 2023/4/2 + **/ +interface ICmdHandler { + fun initHandler() +} \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.kt index cd560898..13a7dc7a 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.kt @@ -15,9 +15,8 @@ */ package com.arialyy.aria.core.command -import com.arialyy.aria.core.DuaContext -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch +import com.arialyy.aria.core.event.EventMsgUtil +import com.arialyy.aria.core.event.ResumeAllEvent /** * Created by AriaL on 2017/6/13. @@ -30,9 +29,7 @@ import kotlinx.coroutines.launch class ResumeAllCmd() : ICmd { override fun executeCmd(): CmdResp { - DuaContext.duaScope.launch(Dispatchers.IO) { - - } + EventMsgUtil.getDefault().post(ResumeAllEvent()) return CmdResp(CmdResp.CODE_COMPLETE) } } \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/command/StopAllCmd.java b/PublicComponent/src/main/java/com/arialyy/aria/core/command/StopAllCmd.java index 7b1210b4..8c1ee9fa 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/command/StopAllCmd.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/command/StopAllCmd.java @@ -1,16 +1,30 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.arialyy.aria.core.command; +import com.arialyy.aria.core.event.EventMsgUtil; +import com.arialyy.aria.core.event.StopAllEvent; /** * Created by AriaL on 2017/6/13. * 停止所有任务的命令,并清空所有等待队列 */ -final class StopAllCmd extends AbsCmd { - StopAllCmd(T entity, int taskType) { - super(entity, taskType); - } - - @Override public void executeCmd() { - stopAll(); +final class StopAllCmd implements ICmd { + @Override public CmdResp executeCmd() { + EventMsgUtil.getDefault().post(new StopAllEvent()); + return new CmdResp(CmdResp.CODE_COMPLETE); } } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/event/DGMaxNumEvent.java b/PublicComponent/src/main/java/com/arialyy/aria/core/event/DGMaxNumEvent.java deleted file mode 100644 index ac5f9286..00000000 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/event/DGMaxNumEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.arialyy.aria.core.event; - -/** - * 组合任务最大下载任务数事件 - */ -public class DGMaxNumEvent { - - public int maxNum; - - public DGMaxNumEvent(int maxNum) { - this.maxNum = maxNum; - } -} diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/event/DMaxNumEvent.java b/PublicComponent/src/main/java/com/arialyy/aria/core/event/DeleteAllEvent.kt similarity index 75% rename from PublicComponent/src/main/java/com/arialyy/aria/core/event/DMaxNumEvent.java rename to PublicComponent/src/main/java/com/arialyy/aria/core/event/DeleteAllEvent.kt index ef1adb02..a179386c 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/event/DMaxNumEvent.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/event/DeleteAllEvent.kt @@ -13,16 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.event; +package com.arialyy.aria.core.event -/** - * 最大下载任务数事件 - */ -public class DMaxNumEvent { +import androidx.annotation.Keep - public int maxNum; - - public DMaxNumEvent(int maxNum) { - this.maxNum = maxNum; - } -} +/** + * @Author laoyuyu + * @Description + * @Date 22:12 2023/4/2 + **/ +@Keep +data class DeleteAllEvent(val onlyRemoveRecord: Boolean = true) \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/event/ErrorEvent.java b/PublicComponent/src/main/java/com/arialyy/aria/core/event/ErrorEvent.java deleted file mode 100644 index 82124c9d..00000000 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/event/ErrorEvent.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.arialyy.aria.core.event; - -public class ErrorEvent { - public long taskId; - public String errorMsg; - - public ErrorEvent(long taskId, String errorMsg) { - this.taskId = taskId; - this.errorMsg = errorMsg; - } -} diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/event/EventMsgUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/core/event/EventMsgUtil.java index f4a27dd1..0dbc0ba2 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/event/EventMsgUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/event/EventMsgUtil.java @@ -15,7 +15,6 @@ */ package com.arialyy.aria.core.event; -import com.arialyy.aria.util.ALog; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -28,17 +27,17 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import timber.log.Timber; /** * 消息发送工具 */ public class EventMsgUtil { - private static final String TAG = "EventUtil"; private static EventMsgUtil defaultInstance; - private Map> mEventMethods = + private final Map> mEventMethods = new ConcurrentHashMap<>(); - private ArrayBlockingQueue mEventQueue = new ArrayBlockingQueue<>(10); - private ExecutorService mPool = Executors.newFixedThreadPool(5); + private final ArrayBlockingQueue mEventQueue = new ArrayBlockingQueue<>(10); + private final ExecutorService mPool = Executors.newFixedThreadPool(5); private EventMsgUtil() { ExecutorService pool = Executors.newSingleThreadExecutor(); @@ -102,15 +101,14 @@ public class EventMsgUtil { continue; } Class[] clazz = method.getParameterTypes(); - if (clazz.length == 0 || clazz.length > 1) { - ALog.e(TAG, - String.format("%s.%s参数数量为0或参数数量大于1", obj.getClass().getName(), method.getName())); + if (clazz.length != 1) { + Timber.e("%s.%s参数数量为0或参数数量大于1", obj.getClass().getName(), method.getName()); continue; } int modifier = method.getModifiers(); if (Modifier.isStatic(modifier) || Modifier.isAbstract(modifier) || Modifier.isFinal( modifier)) { - ALog.e(TAG, "注册的方法不能使用final、static、abstract修饰"); + Timber.e("注册的方法不能使用final、static、abstract修饰"); continue; } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/event/ResumeAllEvent.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/event/ResumeAllEvent.kt index 8c7c50c7..bb46cddb 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/event/ResumeAllEvent.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/event/ResumeAllEvent.kt @@ -15,9 +15,12 @@ */ package com.arialyy.aria.core.event +import androidx.annotation.Keep + /** * @Author laoyuyu * @Description * @Date 8:26 PM 2023/3/21 **/ +@Keep class ResumeAllEvent \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/event/DSpeedEvent.java b/PublicComponent/src/main/java/com/arialyy/aria/core/event/StopAllEvent.kt similarity index 79% rename from PublicComponent/src/main/java/com/arialyy/aria/core/event/DSpeedEvent.java rename to PublicComponent/src/main/java/com/arialyy/aria/core/event/StopAllEvent.kt index 4b2e30cb..ad69b714 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/event/DSpeedEvent.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/event/StopAllEvent.kt @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.event; +package com.arialyy.aria.core.event -public class DSpeedEvent { +import androidx.annotation.Keep - public int speed; - - public DSpeedEvent(int speed) { - this.speed = speed; - } -} +/** + * @Author laoyuyu + * @Description + * @Date 21:57 2023/4/2 + **/ +@Keep +class StopAllEvent \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/event/UMaxNumEvent.java b/PublicComponent/src/main/java/com/arialyy/aria/core/event/UMaxNumEvent.java deleted file mode 100644 index 6c59f59e..00000000 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/event/UMaxNumEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.arialyy.aria.core.event; - -/** - * 最大上传任务数事件 - */ -public class UMaxNumEvent { - - public int maxNum; - - public UMaxNumEvent(int maxNum) { - this.maxNum = maxNum; - } -} diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IPool.java b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IPool.java index 7149eaa3..751f52e8 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IPool.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IPool.java @@ -59,7 +59,7 @@ public interface IPool { /** * @return true:移除成功 */ - boolean removeTask(int taskId); + boolean deleteTask(int taskId); /** * 池子大小 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 e9103699..b8e11bb7 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 @@ -47,7 +47,7 @@ interface ITaskManager { fun stop() - fun cancel() + fun delete() /** * 任务是否已经完成 diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/ITaskQueue.java b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/ITaskQueue.java index d057c24d..f439208e 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/ITaskQueue.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/ITaskQueue.java @@ -59,7 +59,12 @@ public interface ITaskQueue extends IService { /** * remove task */ - void removeTask(TASK task); + void deleteTask(TASK task); + + /** + * Delete all active tasks + */ + void deleteAllTask(); /** * 重试 diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTask.java b/PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTask.java index 5b2c9962..625a5197 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTask.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTask.java @@ -183,7 +183,7 @@ public abstract class AbsTask implements ITask { mAdapter.stop(); } - @Override public void cancel(int type) { + @Override public void delete(int type) { if (mAdapter == null) { Timber.e("util is null"); return; 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 5836f729..a734f060 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 @@ -91,11 +91,11 @@ public interface ITask { void stop(int type); /** - * 停止任务 + * 删除任务 * * @param type {@link TaskSchedulerType} */ - void cancel(int type); + void delete(int type); /** * 任务是否停止了 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 3f55c958..5d5c0e81 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 @@ -48,7 +48,7 @@ object ThreadTaskManager2 { return } if (isRemoveTask) { - taskManager.cancel() + taskManager.delete() } else { taskManager.stop() } @@ -63,7 +63,7 @@ object ThreadTaskManager2 { return } taskManagerMap.forEach { - it.value.cancel() + it.value.delete() } taskManagerMap.clear() } 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 dbada223..0407b713 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 @@ -21,6 +21,7 @@ import androidx.room.Insert import androidx.room.Query import androidx.room.Transaction import androidx.room.Update +import com.arialyy.aria.core.inf.IEntity import com.arialyy.aria.orm.entity.DEntity /** @@ -38,6 +39,10 @@ interface DEntityDao { @Query("SELECT * FROM DEntity WHERE :savePath=savePath") suspend fun queryDEntityBySavePath(savePath: String): DEntity? + @Transaction + @Query("SELECT * FROM DEntity WHERE state!=${IEntity.STATE_COMPLETE}") + suspend fun queryAllNotCompleteEntityList(): List? + @Query("SELECT * FROM DEntity WHERE :dId=dId") suspend fun queryDEntityById(did: String): DEntity? @@ -52,4 +57,9 @@ interface DEntityDao { @Delete suspend fun delete(dEntity: DEntity) + + @Transaction + @Query("DELETE FROM DEntity") + suspend fun deleteAll() + } \ No newline at end of file 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 ff1cfa7d..486ab514 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/Ext.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/Ext.kt @@ -19,6 +19,8 @@ import android.content.Intent import android.content.pm.PackageManager import android.net.Uri import com.arialyy.aria.core.DuaContext +import com.arialyy.aria.core.inf.IEntity +import com.arialyy.aria.orm.entity.DEntity import timber.log.Timber import java.io.File import java.math.BigInteger @@ -29,7 +31,7 @@ fun File.uri(): Uri { return Uri.parse(path) } -fun String.uri():Uri{ +fun String.uri(): Uri { return Uri.parse(this) } @@ -81,4 +83,8 @@ inline fun Uri.use(block: Uri.() -> R): R { } } return block() +} + +fun DEntity.isNotComplete(): Boolean { + return state != IEntity.STATE_COMPLETE && state != IEntity.STATE_CANCEL } \ No newline at end of file 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 388ae042..0504372b 100644 --- a/Queue/src/main/java/com/arialyy/aria/queue/AbsTaskQueue.java +++ b/Queue/src/main/java/com/arialyy/aria/queue/AbsTaskQueue.java @@ -99,18 +99,18 @@ public abstract class AbsTaskQueue implements ITaskQueue implements ITaskQueue implements ITaskQueue implements ITaskQueue implements IPool { return getTask(taskId) != null; } - @Override public boolean removeTask(int taskId) { + @Override public boolean deleteTask(int taskId) { if (taskId <= 0) { Timber.e("invalid taskId: %s", taskId); return false; diff --git a/Queue/src/main/java/com/arialyy/aria/queue/BaseExecutePool.java b/Queue/src/main/java/com/arialyy/aria/queue/BaseExecutePool.java index 7b4b85e5..740eb3a0 100644 --- a/Queue/src/main/java/com/arialyy/aria/queue/BaseExecutePool.java +++ b/Queue/src/main/java/com/arialyy/aria/queue/BaseExecutePool.java @@ -146,7 +146,7 @@ public class BaseExecutePool implements IPool { return getTask(taskId) != null; } - @Override public boolean removeTask(int taskId) { + @Override public boolean deleteTask(int taskId) { if (taskId < 0) { Timber.e("invalid taskId"); return false; 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 c44f0d00..085c1ae4 100644 --- a/Schedulers/src/main/java/com/arialyy/aria/schedulers/TaskSchedulers.java +++ b/Schedulers/src/main/java/com/arialyy/aria/schedulers/TaskSchedulers.java @@ -312,7 +312,7 @@ public class TaskSchedulers implements ISchedulers { } break; case CANCEL: - queue.removeTask(task); + queue.deleteTask(task); if (!queue.isFull()) { Timber.d("remove task success, if there is a task, start the next task, taskId: %s", @@ -323,7 +323,7 @@ public class TaskSchedulers implements ISchedulers { } break; case COMPLETE: - queue.removeTask(task); + queue.deleteTask(task); Timber.d("task complete, taskId: %s", task.getTaskId()); queue.startNextTask(); break; @@ -502,7 +502,7 @@ public class TaskSchedulers implements ISchedulers { */ private void handleFailTask(final ITaskQueue queue, final TASK task) { if (!task.getTaskState().getNeedRetry() || task.isStopped() || task.isCanceled()) { - queue.removeTask(task); + queue.deleteTask(task); queue.startNextTask(); normalTaskCallback(FAIL, task); return; @@ -511,7 +511,7 @@ public class TaskSchedulers implements ISchedulers { boolean isNotNetRetry = mAriaConfig.getAConfig().isNotNetRetry(); if ((!NetUtils.isConnected(mAriaConfig.getAPP()) && !isNotNetRetry)) { - queue.removeTask(task); + queue.deleteTask(task); queue.startNextTask(); normalTaskCallback(FAIL, task); return;