From 9a27ae8e6937c65b97acabcd3d547397cf6971dc Mon Sep 17 00:00:00 2001 From: jyuesong <425698907@qq.com> Date: Fri, 27 May 2022 09:59:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=88=97=E8=A1=A8=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/module/task/task_viewmodel.dart | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/module/task/task_viewmodel.dart b/lib/module/task/task_viewmodel.dart index 17ad24a..eeeafe1 100644 --- a/lib/module/task/task_viewmodel.dart +++ b/lib/module/task/task_viewmodel.dart @@ -6,6 +6,13 @@ import 'package:qinglong_app/module/task/task_bean.dart'; import 'package:qinglong_app/utils/extension.dart'; var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel()); +Map sort = { + 0: 0, + 5: 1, + 3: 2, + 1: 3, + 4: 4, +}; class TaskViewModel extends BaseViewModel { List list = []; @@ -33,17 +40,17 @@ class TaskViewModel extends BaseViewModel { } void sortList() { - for (int i = 0; i < list.length; i++) { - if (list[i].isPinned == 1) { - final TaskBean item = list.removeAt(i); - list.insert(0, item); - } - } + list.sort((TaskBean a, TaskBean b) { + int? sortA = (a.isPinned == 1 && a.status != 0) ? 5 : ((a.isDisabled == 1 && a.status != 0) ? 4 : a.status); + int? sortB = (b.isPinned == 1 && b.status != 0) ? 5 : ((b.isDisabled == 1 && b.status != 0) ? 4 : b.status); + + return sort[sortA!]! - sort[sortB!]!; + }); running.clear(); running.addAll(list.where((element) => element.status == 0)); neverRunning.clear(); - neverRunning.addAll(list.where((element) => element.lastRunningTime == null )); + neverRunning.addAll(list.where((element) => element.lastRunningTime == null)); notScripts.clear(); notScripts.addAll(list.where((element) => (element.command != null && (element.command!.startsWith("ql repo") || element.command!.startsWith("ql raw"))))); disabled.clear();