From 5558cac263d14dc842d2e23ee462a7955dc0bddc Mon Sep 17 00:00:00 2001 From: liwei Date: Sat, 1 Apr 2023 19:43:47 +0800 Subject: [PATCH] fix: task view ui --- .../app/modules/create/views/create_view.dart | 4 +- .../bindings/downloaded_binding.dart | 12 ---- .../controllers/downloaded_controller.dart | 31 ---------- .../bindings/downloading_binding.dart | 12 ---- .../lib/app/modules/home/views/home_view.dart | 29 ++------- .../modules/task/bindings/task_binding.dart | 20 +++++++ .../task/controllers/task_controller.dart | 5 ++ .../task_downloaded_controller.dart | 9 +++ .../task_downloading_controller.dart | 7 +++ .../controllers/task_list_controller.dart} | 27 +++++++-- .../views/task_downloaded_view.dart} | 6 +- .../views/task_downloading_view.dart} | 6 +- .../lib/app/modules/task/views/task_view.dart | 60 +++++++++++++++++++ ui/flutter/lib/app/routes/app_pages.dart | 25 +++----- ui/flutter/lib/app/routes/app_routes.dart | 14 ++--- .../app/views/views/buid_task_list_view.dart | 26 -------- 16 files changed, 149 insertions(+), 144 deletions(-) delete mode 100644 ui/flutter/lib/app/modules/downloaded/bindings/downloaded_binding.dart delete mode 100644 ui/flutter/lib/app/modules/downloaded/controllers/downloaded_controller.dart delete mode 100644 ui/flutter/lib/app/modules/downloading/bindings/downloading_binding.dart create mode 100644 ui/flutter/lib/app/modules/task/bindings/task_binding.dart create mode 100644 ui/flutter/lib/app/modules/task/controllers/task_controller.dart create mode 100644 ui/flutter/lib/app/modules/task/controllers/task_downloaded_controller.dart create mode 100644 ui/flutter/lib/app/modules/task/controllers/task_downloading_controller.dart rename ui/flutter/lib/app/modules/{downloading/controllers/downloading_controller.dart => task/controllers/task_list_controller.dart} (55%) rename ui/flutter/lib/app/modules/{downloading/views/downloading_view.dart => task/views/task_downloaded_view.dart} (56%) rename ui/flutter/lib/app/modules/{downloaded/views/downloaded_view.dart => task/views/task_downloading_view.dart} (56%) create mode 100644 ui/flutter/lib/app/modules/task/views/task_view.dart diff --git a/ui/flutter/lib/app/modules/create/views/create_view.dart b/ui/flutter/lib/app/modules/create/views/create_view.dart index ef58a412..4ad5d562 100644 --- a/ui/flutter/lib/app/modules/create/views/create_view.dart +++ b/ui/flutter/lib/app/modules/create/views/create_view.dart @@ -31,7 +31,7 @@ class CreateView extends GetView { appBar: AppBar( leading: IconButton( icon: const Icon(Icons.arrow_back), - onPressed: () => Get.rootDelegate.offNamed(Routes.DOWNLOADING)), + onPressed: () => Get.rootDelegate.offNamed(Routes.TASK)), // actions: [], title: Text('create'.tr), ), @@ -188,7 +188,7 @@ class CreateView extends GetView { selectFiles: controller.selectedIndexes .cast()))); Get.back(); - Get.rootDelegate.offNamed(Routes.DOWNLOADING); + Get.rootDelegate.offNamed(Routes.TASK); } } catch (e) { showErrorMessage(e); diff --git a/ui/flutter/lib/app/modules/downloaded/bindings/downloaded_binding.dart b/ui/flutter/lib/app/modules/downloaded/bindings/downloaded_binding.dart deleted file mode 100644 index a935e9ae..00000000 --- a/ui/flutter/lib/app/modules/downloaded/bindings/downloaded_binding.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:get/get.dart'; - -import '../controllers/downloaded_controller.dart'; - -class DownloadedBinding extends Bindings { - @override - void dependencies() { - Get.lazyPut( - () => DownloadedController(), - ); - } -} diff --git a/ui/flutter/lib/app/modules/downloaded/controllers/downloaded_controller.dart b/ui/flutter/lib/app/modules/downloaded/controllers/downloaded_controller.dart deleted file mode 100644 index 390aa510..00000000 --- a/ui/flutter/lib/app/modules/downloaded/controllers/downloaded_controller.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'dart:async'; - -import 'package:get/get.dart'; - -import '../../../../api/api.dart'; -import '../../../../api/model/task.dart'; - -class DownloadedController extends GetxController { - final tasks = [].obs; - late final Timer _timer; - - @override - void onInit() async { - super.onInit(); - await getTasksState(); - _timer = Timer.periodic(const Duration(milliseconds: 1000), (timer) async { - // debugPrint('timer${DateTime.now()}'); - await getTasksState(); - }); - } - - @override - void onClose() { - super.onClose(); - _timer.cancel(); - } - - getTasksState() async { - tasks.value = await getTasks([Status.done]); - } -} diff --git a/ui/flutter/lib/app/modules/downloading/bindings/downloading_binding.dart b/ui/flutter/lib/app/modules/downloading/bindings/downloading_binding.dart deleted file mode 100644 index 1be6275c..00000000 --- a/ui/flutter/lib/app/modules/downloading/bindings/downloading_binding.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:get/get.dart'; - -import '../controllers/downloading_controller.dart'; - -class DownloadingBinding extends Bindings { - @override - void dependencies() { - Get.lazyPut( - () => DownloadingController(), - ); - } -} diff --git a/ui/flutter/lib/app/modules/home/views/home_view.dart b/ui/flutter/lib/app/modules/home/views/home_view.dart index 6e2c73bd..86c13f05 100644 --- a/ui/flutter/lib/app/modules/home/views/home_view.dart +++ b/ui/flutter/lib/app/modules/home/views/home_view.dart @@ -12,7 +12,7 @@ class HomeView extends GetView { Widget build(BuildContext context) { return GetRouterOutlet.builder(builder: (context, delegate, currentRoute) { return Scaffold( - extendBody: true, + // extendBody: true, body: Row( // crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -26,29 +26,20 @@ class HomeView extends GetView { onDestinationSelected: (int index) { switch (index) { case 0: - delegate.toNamed(Routes.DOWNLOADING); controller.currentIndex.value = 0; + delegate.toNamed(Routes.TASK); break; case 1: - delegate.toNamed(Routes.DOWNLOADED); controller.currentIndex.value = 1; - break; - case 2: delegate.toNamed(Routes.SETTING); - controller.currentIndex.value = 2; break; } }, destinations: [ - NavigationRailDestination( - icon: const Icon(Icons.file_download), - selectedIcon: const Icon(Icons.file_download), - label: Text('downloading'.tr), - ), NavigationRailDestination( icon: const Icon(Icons.done), selectedIcon: const Icon(Icons.done), - label: Text('downloaded'.tr), + label: Text('task'.tr), ), NavigationRailDestination( icon: const Icon(Icons.settings), @@ -63,7 +54,7 @@ class HomeView extends GetView { : const SizedBox.shrink(), Expanded( child: GetRouterOutlet( - initialRoute: Routes.DOWNLOADING, + initialRoute: Routes.TASK, // anchorRoute: '/', // filterPages: (afterAnchor) { // logger.w(afterAnchor); @@ -75,13 +66,9 @@ class HomeView extends GetView { bottomNavigationBar: ResponsiveBuilder.isNarrow(context) ? BottomNavigationBar( items: [ - BottomNavigationBarItem( - icon: const Icon(Icons.file_download), - label: 'downloading'.tr, - ), BottomNavigationBarItem( icon: const Icon(Icons.done), - label: 'downloaded'.tr, + label: 'task'.tr, ), BottomNavigationBarItem( icon: const Icon(Icons.settings), @@ -93,16 +80,12 @@ class HomeView extends GetView { onTap: (index) { switch (index) { case 0: - delegate.toNamed(Routes.DOWNLOADING); controller.currentIndex.value = 0; + delegate.toNamed(Routes.TASK); break; case 1: - delegate.toNamed(Routes.DOWNLOADED); controller.currentIndex.value = 1; - break; - case 2: delegate.toNamed(Routes.SETTING); - controller.currentIndex.value = 2; break; } }, diff --git a/ui/flutter/lib/app/modules/task/bindings/task_binding.dart b/ui/flutter/lib/app/modules/task/bindings/task_binding.dart new file mode 100644 index 00000000..aa85cd31 --- /dev/null +++ b/ui/flutter/lib/app/modules/task/bindings/task_binding.dart @@ -0,0 +1,20 @@ +import 'package:get/get.dart'; + +import '../controllers/task_controller.dart'; +import '../controllers/task_downloaded_controller.dart'; +import '../controllers/task_downloading_controller.dart'; + +class TaskBinding extends Bindings { + @override + void dependencies() { + Get.lazyPut( + () => TaskController(), + ); + Get.lazyPut( + () => TaskDownloadingController(), + ); + Get.lazyPut( + () => TaskDownloadedController(), + ); + } +} diff --git a/ui/flutter/lib/app/modules/task/controllers/task_controller.dart b/ui/flutter/lib/app/modules/task/controllers/task_controller.dart new file mode 100644 index 00000000..62b60d5c --- /dev/null +++ b/ui/flutter/lib/app/modules/task/controllers/task_controller.dart @@ -0,0 +1,5 @@ +import 'package:get/get.dart'; + +class TaskController extends GetxController { + final tabIndex = 0.obs; +} diff --git a/ui/flutter/lib/app/modules/task/controllers/task_downloaded_controller.dart b/ui/flutter/lib/app/modules/task/controllers/task_downloaded_controller.dart new file mode 100644 index 00000000..50d32cad --- /dev/null +++ b/ui/flutter/lib/app/modules/task/controllers/task_downloaded_controller.dart @@ -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]); +} diff --git a/ui/flutter/lib/app/modules/task/controllers/task_downloading_controller.dart b/ui/flutter/lib/app/modules/task/controllers/task_downloading_controller.dart new file mode 100644 index 00000000..ce48e58e --- /dev/null +++ b/ui/flutter/lib/app/modules/task/controllers/task_downloading_controller.dart @@ -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]); +} diff --git a/ui/flutter/lib/app/modules/downloading/controllers/downloading_controller.dart b/ui/flutter/lib/app/modules/task/controllers/task_list_controller.dart similarity index 55% rename from ui/flutter/lib/app/modules/downloading/controllers/downloading_controller.dart rename to ui/flutter/lib/app/modules/task/controllers/task_list_controller.dart index a6cf58b9..ac2ca1f1 100644 --- a/ui/flutter/lib/app/modules/downloading/controllers/downloading_controller.dart +++ b/ui/flutter/lib/app/modules/task/controllers/task_list_controller.dart @@ -5,18 +5,25 @@ import 'package:get/get.dart'; import '../../../../api/api.dart'; import '../../../../api/model/task.dart'; -class DownloadingController extends GetxController { +abstract class TaskListController extends GetxController { + List statuses; + + TaskListController(this.statuses); + final tasks = [].obs; + final isRunning = false.obs; late final Timer _timer; @override void onInit() async { super.onInit(); - await getTasksState(); + + start(); _timer = Timer.periodic(const Duration(milliseconds: 1000), (timer) async { - // debugPrint('timer${DateTime.now()}'); - await getTasksState(); + if (isRunning.value) { + await getTasksState(); + } }); } @@ -26,8 +33,16 @@ class DownloadingController extends GetxController { _timer.cancel(); } + void start() async { + await getTasksState(); + isRunning.value = true; + } + + void stop() { + isRunning.value = false; + } + getTasksState() async { - tasks.value = await getTasks( - [Status.ready, Status.running, Status.pause, Status.error]); + tasks.value = await getTasks(statuses); } } diff --git a/ui/flutter/lib/app/modules/downloading/views/downloading_view.dart b/ui/flutter/lib/app/modules/task/views/task_downloaded_view.dart similarity index 56% rename from ui/flutter/lib/app/modules/downloading/views/downloading_view.dart rename to ui/flutter/lib/app/modules/task/views/task_downloaded_view.dart index 6c6f6183..a834aafd 100644 --- a/ui/flutter/lib/app/modules/downloading/views/downloading_view.dart +++ b/ui/flutter/lib/app/modules/task/views/task_downloaded_view.dart @@ -2,10 +2,10 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../../../views/views/buid_task_list_view.dart'; -import '../controllers/downloading_controller.dart'; +import '../controllers/task_downloaded_controller.dart'; -class DownloadingView extends GetView { - const DownloadingView({Key? key}) : super(key: key); +class TaskDownloadedView extends GetView { + const TaskDownloadedView({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/ui/flutter/lib/app/modules/downloaded/views/downloaded_view.dart b/ui/flutter/lib/app/modules/task/views/task_downloading_view.dart similarity index 56% rename from ui/flutter/lib/app/modules/downloaded/views/downloaded_view.dart rename to ui/flutter/lib/app/modules/task/views/task_downloading_view.dart index 0ddf1d0e..609eb333 100644 --- a/ui/flutter/lib/app/modules/downloaded/views/downloaded_view.dart +++ b/ui/flutter/lib/app/modules/task/views/task_downloading_view.dart @@ -2,10 +2,10 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../../../views/views/buid_task_list_view.dart'; -import '../controllers/downloaded_controller.dart'; +import '../controllers/task_downloading_controller.dart'; -class DownloadedView extends GetView { - const DownloadedView({Key? key}) : super(key: key); +class TaskDownloadingView extends GetView { + const TaskDownloadingView({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/ui/flutter/lib/app/modules/task/views/task_view.dart b/ui/flutter/lib/app/modules/task/views/task_view.dart new file mode 100644 index 00000000..18a43999 --- /dev/null +++ b/ui/flutter/lib/app/modules/task/views/task_view.dart @@ -0,0 +1,60 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:gopeed/app/modules/task/controllers/task_downloading_controller.dart'; +import '../controllers/task_downloaded_controller.dart'; +import 'task_downloading_view.dart'; + +import 'task_downloaded_view.dart'; +import '../controllers/task_controller.dart'; + +class TaskView extends GetView { + const TaskView({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return DefaultTabController( + length: 2, + child: Scaffold( + appBar: PreferredSize( + preferredSize: const Size.fromHeight(56), + child: AppBar( + bottom: TabBar( + tabs: const [ + Tab( + icon: Icon(Icons.file_download), + ), + Tab( + icon: Icon(Icons.done), + ), + ], + onTap: (index) { + if (controller.tabIndex.value != index) { + controller.tabIndex.value = index; + final downloadingController = + Get.find(); + final downloadedController = + Get.find(); + switch (index) { + case 0: + downloadingController.start(); + downloadedController.stop(); + break; + case 1: + downloadingController.stop(); + downloadedController.start(); + break; + } + } + }, + ), + )), + body: const TabBarView( + children: [ + TaskDownloadingView(), + TaskDownloadedView(), + ], + ), + ), + ); + } +} diff --git a/ui/flutter/lib/app/routes/app_pages.dart b/ui/flutter/lib/app/routes/app_pages.dart index 7b619cc0..9935592d 100644 --- a/ui/flutter/lib/app/routes/app_pages.dart +++ b/ui/flutter/lib/app/routes/app_pages.dart @@ -1,25 +1,21 @@ import 'package:get/get.dart'; +import 'package:gopeed/app/modules/task/views/task_view.dart'; import '../modules/create/bindings/create_binding.dart'; import '../modules/create/views/create_view.dart'; -import '../modules/downloaded/bindings/downloaded_binding.dart'; -import '../modules/downloaded/views/downloaded_view.dart'; -import '../modules/downloading/bindings/downloading_binding.dart'; -import '../modules/downloading/views/downloading_view.dart'; import '../modules/home/bindings/home_binding.dart'; import '../modules/home/views/home_view.dart'; import '../modules/root/bindings/root_binding.dart'; import '../modules/root/views/root_view.dart'; import '../modules/setting/bindings/setting_binding.dart'; import '../modules/setting/views/setting_view.dart'; +import '../modules/task/bindings/task_binding.dart'; part 'app_routes.dart'; class AppPages { AppPages._(); - static const INITIAL = Routes.ROOT; - static final routes = [ GetPage( name: _Paths.ROOT, @@ -38,21 +34,14 @@ class AppPages { binding: HomeBinding(), children: [ GetPage( - name: _Paths.DOWNLOADED, - transition: Transition.noTransition, - page: () => const DownloadedView(), - binding: DownloadedBinding(), - ), - GetPage( - name: _Paths.DOWNLOADING, - transition: Transition.noTransition, - page: () => const DownloadingView(), - binding: DownloadingBinding(), - ), + name: _Paths.TASK, + page: () => const TaskView(), + transition: Transition.noTransition, + binding: TaskBinding()), GetPage( name: _Paths.SETTING, - transition: Transition.noTransition, page: () => const SettingView(), + transition: Transition.noTransition, binding: SettingBinding(), ), ]), diff --git a/ui/flutter/lib/app/routes/app_routes.dart b/ui/flutter/lib/app/routes/app_routes.dart index ab00a934..49e66033 100644 --- a/ui/flutter/lib/app/routes/app_routes.dart +++ b/ui/flutter/lib/app/routes/app_routes.dart @@ -3,20 +3,18 @@ part of 'app_pages.dart'; abstract class Routes { Routes._(); - static const DOWNLOADED = _Paths.HOME + _Paths.DOWNLOADED; - static const DOWNLOADING = _Paths.HOME + _Paths.DOWNLOADING; - static const CREATE = _Paths.CREATE; static const ROOT = _Paths.ROOT; - static const SETTING = _Paths.HOME + _Paths.SETTING; static const HOME = _Paths.HOME; + static const CREATE = _Paths.CREATE; + static const TASK = _Paths.HOME + _Paths.TASK; + static const SETTING = _Paths.HOME + _Paths.SETTING; } abstract class _Paths { _Paths._(); - static const DOWNLOADED = '/downloaded'; - static const DOWNLOADING = '/downloading'; - static const CREATE = '/create'; static const ROOT = '/'; - static const SETTING = '/setting'; static const HOME = '/home'; + static const CREATE = '/create'; + static const TASK = '/task'; + static const SETTING = '/setting'; } diff --git a/ui/flutter/lib/app/views/views/buid_task_list_view.dart b/ui/flutter/lib/app/views/views/buid_task_list_view.dart index 385aacbf..1ef2d468 100644 --- a/ui/flutter/lib/app/views/views/buid_task_list_view.dart +++ b/ui/flutter/lib/app/views/views/buid_task_list_view.dart @@ -23,32 +23,6 @@ class BuildTaskListView extends GetView { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - // actions: [ - // // IconButton( - // // icon: const Icon(Icons.add), - // // tooltip: 'create'.tr, - // // onPressed: () { - // // Get.rootDelegate.toNamed(Routes.CREATE); - // // }, - // // ), - // //TODO appBar toggleALl/start selected/delete selected/ - // // IconButton( - // // icon: const Icon(Icons.pause), - // // tooltip: 'title'.tr, - // // onPressed: () { - // // // pause all - // // }, - // // ), - // // IconButton( - // // icon: const Icon(Icons.delete), - // // tooltip: 'title'.tr, - // // onPressed: () { - // // // delete all - // // }, - // // ) - // ], - ), floatingActionButton: FloatingActionButton( onPressed: () { Get.rootDelegate.toNamed(Routes.CREATE);