mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
任务列表排序
This commit is contained in:
@@ -6,6 +6,13 @@ import 'package:qinglong_app/module/task/task_bean.dart';
|
|||||||
import 'package:qinglong_app/utils/extension.dart';
|
import 'package:qinglong_app/utils/extension.dart';
|
||||||
|
|
||||||
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
||||||
|
Map<int, int> sort = {
|
||||||
|
0: 0,
|
||||||
|
5: 1,
|
||||||
|
3: 2,
|
||||||
|
1: 3,
|
||||||
|
4: 4,
|
||||||
|
};
|
||||||
|
|
||||||
class TaskViewModel extends BaseViewModel {
|
class TaskViewModel extends BaseViewModel {
|
||||||
List<TaskBean> list = [];
|
List<TaskBean> list = [];
|
||||||
@@ -33,17 +40,17 @@ class TaskViewModel extends BaseViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sortList() {
|
void sortList() {
|
||||||
for (int i = 0; i < list.length; i++) {
|
list.sort((TaskBean a, TaskBean b) {
|
||||||
if (list[i].isPinned == 1) {
|
int? sortA = (a.isPinned == 1 && a.status != 0) ? 5 : ((a.isDisabled == 1 && a.status != 0) ? 4 : a.status);
|
||||||
final TaskBean item = list.removeAt(i);
|
int? sortB = (b.isPinned == 1 && b.status != 0) ? 5 : ((b.isDisabled == 1 && b.status != 0) ? 4 : b.status);
|
||||||
list.insert(0, item);
|
|
||||||
}
|
return sort[sortA!]! - sort[sortB!]!;
|
||||||
}
|
});
|
||||||
|
|
||||||
running.clear();
|
running.clear();
|
||||||
running.addAll(list.where((element) => element.status == 0));
|
running.addAll(list.where((element) => element.status == 0));
|
||||||
neverRunning.clear();
|
neverRunning.clear();
|
||||||
neverRunning.addAll(list.where((element) => element.lastRunningTime == null ));
|
neverRunning.addAll(list.where((element) => element.lastRunningTime == null));
|
||||||
notScripts.clear();
|
notScripts.clear();
|
||||||
notScripts.addAll(list.where((element) => (element.command != null && (element.command!.startsWith("ql repo") || element.command!.startsWith("ql raw")))));
|
notScripts.addAll(list.where((element) => (element.command != null && (element.command!.startsWith("ql repo") || element.command!.startsWith("ql raw")))));
|
||||||
disabled.clear();
|
disabled.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user