mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 17:40:28 +00:00
fix: task view ui
This commit is contained in:
1 parent
4128e718e9
commit
5558cac263
16 files changed
+149
-144
No files matched your search
@@ -0,0 +1,5 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class TaskController extends GetxController {
|
||||
final tabIndex = 0.obs;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:gopeed/app/modules/task/controllers/task_list_controller.dart';
|
||||
|
||||
import '../../../../api/model/task.dart';
|
||||
|
||||
class TaskDownloadedController extends TaskListController {
|
||||
TaskDownloadedController() : super([Status.done]);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import '../../../../api/model/task.dart';
|
||||
import 'task_list_controller.dart';
|
||||
|
||||
class TaskDownloadingController extends TaskListController {
|
||||
TaskDownloadingController()
|
||||
: super([Status.ready, Status.running, Status.pause, Status.error]);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../../api/api.dart';
|
||||
import '../../../../api/model/task.dart';
|
||||
|
||||
abstract class TaskListController extends GetxController {
|
||||
List<Status> statuses;
|
||||
|
||||
TaskListController(this.statuses);
|
||||
|
||||
final tasks = <Task>[].obs;
|
||||
final isRunning = false.obs;
|
||||
|
||||
late final Timer _timer;
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
|
||||
start();
|
||||
_timer = Timer.periodic(const Duration(milliseconds: 1000), (timer) async {
|
||||
if (isRunning.value) {
|
||||
await getTasksState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
_timer.cancel();
|
||||
}
|
||||
|
||||
void start() async {
|
||||
await getTasksState();
|
||||
isRunning.value = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
isRunning.value = false;
|
||||
}
|
||||
|
||||
getTasksState() async {
|
||||
tasks.value = await getTasks(statuses);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user