From 21a2373a5c6af43954b9759a3c28208dc91f2c51 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Fri, 28 Nov 2025 11:23:29 +0800 Subject: [PATCH] update dm Signed-off-by: bggRGjQaUbCoE --- lib/common/widgets/appbar/appbar.dart | 6 +- .../common/search/common_search_page.dart | 4 +- lib/pages/download/detail/view.dart | 28 ++++ lib/pages/download/detail/widgets/item.dart | 5 +- lib/pages/download/search/view.dart | 29 ++++ lib/pages/download/view.dart | 155 +++++++++++------- lib/pages/later/view.dart | 2 +- 7 files changed, 163 insertions(+), 66 deletions(-) diff --git a/lib/common/widgets/appbar/appbar.dart b/lib/common/widgets/appbar/appbar.dart index 368a96b3f..fd0355936 100644 --- a/lib/common/widgets/appbar/appbar.dart +++ b/lib/common/widgets/appbar/appbar.dart @@ -7,13 +7,13 @@ class MultiSelectAppBarWidget extends StatelessWidget final MultiSelectBase ctr; final bool? visible; final AppBar child; - final List? children; + final List? actions; const MultiSelectAppBarWidget({ super.key, required this.ctr, this.visible, - this.children, + this.actions, required this.child, }); @@ -36,7 +36,7 @@ class MultiSelectAppBarWidget extends StatelessWidget onPressed: () => ctr.handleSelect(checked: true), child: const Text('全选'), ), - ...?children, + ...?actions, TextButton( style: TextButton.styleFrom( visualDensity: VisualDensity.compact, diff --git a/lib/pages/common/search/common_search_page.dart b/lib/pages/common/search/common_search_page.dart index 47bfd0278..a1cd3e1c1 100644 --- a/lib/pages/common/search/common_search_page.dart +++ b/lib/pages/common/search/common_search_page.dart @@ -13,7 +13,7 @@ abstract class CommonSearchPageState List? get extraActions => null; - List? get multiSelectChildren => null; + List? get multiSelectActions => null; @override Widget build(BuildContext context) { @@ -84,7 +84,7 @@ abstract class CommonSearchPageState if (multiSelect) { return MultiSelectAppBarWidget( ctr: controller as MultiSelectBase, - children: multiSelectChildren, + actions: multiSelectActions, child: bar, ); } diff --git a/lib/pages/download/detail/view.dart b/lib/pages/download/detail/view.dart index 7fd5fa501..bb487fa4c 100644 --- a/lib/pages/download/detail/view.dart +++ b/lib/pages/download/detail/view.dart @@ -94,6 +94,34 @@ class _DownloadDetailPageState extends State resizeToAvoidBottomInset: false, appBar: MultiSelectAppBarWidget( ctr: this, + actions: [ + TextButton( + style: TextButton.styleFrom( + visualDensity: VisualDensity.compact, + ), + onPressed: () async { + final allChecked = this.allChecked.toSet(); + handleSelect(); + final res = await Future.wait( + allChecked.map( + (e) => _downloadService.downloadDanmaku( + entry: e, + isUpdate: true, + ), + ), + ); + if (res.every((e) => e)) { + SmartDialog.showToast('更新成功'); + } else { + SmartDialog.showToast('更新失败'); + } + }, + child: Text( + '更新', + style: TextStyle(color: Get.theme.colorScheme.onSurface), + ), + ), + ], child: AppBar( title: Text(widget.title), actions: [ diff --git a/lib/pages/download/detail/widgets/item.dart b/lib/pages/download/detail/widgets/item.dart index eb53287d9..eefb973db 100644 --- a/lib/pages/download/detail/widgets/item.dart +++ b/lib/pages/download/detail/widgets/item.dart @@ -57,7 +57,8 @@ class DetailItem extends StatelessWidget { final outline = theme.colorScheme.outline; final cid = entry.source?.cid ?? entry.pageData?.cid; final canDel = onDelete != null; - void onLongPress() => canDel + final enableMultiSelect = controller.enableMultiSelect.value; + void onLongPress() => canDel && !enableMultiSelect ? showDialog( context: context, builder: (context) { @@ -116,7 +117,7 @@ class DetailItem extends StatelessWidget { Get.to(const DownloadingPage()); return; } - if (controller.enableMultiSelect.value) { + if (enableMultiSelect) { (onSelect ?? controller.onSelect).call(entry); return; } diff --git a/lib/pages/download/search/view.dart b/lib/pages/download/search/view.dart index 18bb64daf..bf894eb38 100644 --- a/lib/pages/download/search/view.dart +++ b/lib/pages/download/search/view.dart @@ -7,6 +7,7 @@ import 'package:PiliPlus/services/download/download_service.dart'; import 'package:PiliPlus/utils/grid.dart'; import 'package:flutter/material.dart' hide SliverGridDelegateWithMaxCrossAxisExtent; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; class DownloadSearchPage extends StatefulWidget { @@ -47,6 +48,34 @@ class _DownloadSearchPageState ), ]; + @override + List? get multiSelectActions => [ + TextButton( + style: TextButton.styleFrom(visualDensity: VisualDensity.compact), + onPressed: () async { + final allChecked = controller.allChecked.toSet(); + controller.handleSelect(); + final res = await Future.wait( + allChecked.map( + (e) => _downloadService.downloadDanmaku( + entry: e, + isUpdate: true, + ), + ), + ); + if (res.every((e) => e)) { + SmartDialog.showToast('更新成功'); + } else { + SmartDialog.showToast('更新失败'); + } + }, + child: Text( + '更新', + style: TextStyle(color: Get.theme.colorScheme.onSurface), + ), + ), + ]; + @override Widget buildList(List list) { if (list.isNotEmpty) { diff --git a/lib/pages/download/view.dart b/lib/pages/download/view.dart index 0e0377b4d..0aeb176f5 100644 --- a/lib/pages/download/view.dart +++ b/lib/pages/download/view.dart @@ -8,6 +8,7 @@ import 'package:PiliPlus/common/widgets/image/network_img_layer.dart'; import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart'; import 'package:PiliPlus/common/widgets/select_mask.dart'; import 'package:PiliPlus/models/common/badge_type.dart'; +import 'package:PiliPlus/models_new/download/bili_download_entry_info.dart'; import 'package:PiliPlus/models_new/download/download_info.dart'; import 'package:PiliPlus/pages/download/controller.dart'; import 'package:PiliPlus/pages/download/detail/view.dart'; @@ -57,6 +58,38 @@ class _DownloadPageState extends State { resizeToAvoidBottomInset: false, appBar: MultiSelectAppBarWidget( ctr: _controller, + actions: [ + TextButton( + style: TextButton.styleFrom( + visualDensity: VisualDensity.compact, + ), + onPressed: () async { + final allChecked = _controller.allChecked.toSet(); + _controller.handleSelect(); + final list = []; + for (var page in allChecked) { + list.addAll(page.entrys); + } + final res = await Future.wait( + list.map( + (e) => _downloadService.downloadDanmaku( + entry: e, + isUpdate: true, + ), + ), + ); + if (res.every((e) => e)) { + SmartDialog.showToast('更新成功'); + } else { + SmartDialog.showToast('更新失败'); + } + }, + child: Text( + '更新', + style: TextStyle(color: theme.colorScheme.onSurface), + ), + ), + ], child: AppBar( title: const Text('离线缓存'), actions: [ @@ -169,7 +202,7 @@ class _DownloadPageState extends State { controller: _controller, ); } - return _buildItem(theme, item); + return _buildItem(theme, item, enableMultiSelect); }, itemCount: _controller.pages.length, ), @@ -192,66 +225,72 @@ class _DownloadPageState extends State { }); } - Widget _buildItem(ThemeData theme, DownloadPageInfo pageInfo) { - void onLongPress() => showDialog( - context: context, - builder: (context) { - return AlertDialog( - clipBehavior: Clip.hardEdge, - contentPadding: const EdgeInsets.symmetric(vertical: 12), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - ListTile( - onTap: () { - Get.back(); - showConfirmDialog( - context: context, - title: '确定删除?', - onConfirm: () async { - await GStorage.watchProgress.deleteAll( - pageInfo.entrys.map((e) => e.cid.toString()), - ); - _downloadService.deletePage( - pageDirPath: pageInfo.dirPath, - ); - }, - ); - }, - dense: true, - title: const Text( - '删除', - style: TextStyle(fontSize: 14), - ), - ), - ListTile( - onTap: () async { - Get.back(); - final res = await Future.wait( - pageInfo.entrys.map( - (e) => _downloadService.downloadDanmaku( - entry: e, - isUpdate: true, + Widget _buildItem( + ThemeData theme, + DownloadPageInfo pageInfo, + bool enableMultiSelect, + ) { + void onLongPress() => enableMultiSelect + ? null + : showDialog( + context: context, + builder: (context) { + return AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: const EdgeInsets.symmetric(vertical: 12), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + onTap: () { + Get.back(); + showConfirmDialog( + context: context, + title: '确定删除?', + onConfirm: () async { + await GStorage.watchProgress.deleteAll( + pageInfo.entrys.map((e) => e.cid.toString()), + ); + _downloadService.deletePage( + pageDirPath: pageInfo.dirPath, + ); + }, + ); + }, + dense: true, + title: const Text( + '删除', + style: TextStyle(fontSize: 14), ), ), - ); - if (res.every((e) => e)) { - SmartDialog.showToast('更新成功'); - } else { - SmartDialog.showToast('更新失败'); - } - }, - dense: true, - title: const Text( - '更新弹幕', - style: TextStyle(fontSize: 14), + ListTile( + onTap: () async { + Get.back(); + final res = await Future.wait( + pageInfo.entrys.map( + (e) => _downloadService.downloadDanmaku( + entry: e, + isUpdate: true, + ), + ), + ); + if (res.every((e) => e)) { + SmartDialog.showToast('更新成功'); + } else { + SmartDialog.showToast('更新失败'); + } + }, + dense: true, + title: const Text( + '更新弹幕', + style: TextStyle(fontSize: 14), + ), + ), + ], ), - ), - ], - ), - ); - }, - ); + ); + }, + ); final first = pageInfo.entrys.first; return Material( type: MaterialType.transparency, diff --git a/lib/pages/later/view.dart b/lib/pages/later/view.dart index 05881adbd..0f4ce8e9d 100644 --- a/lib/pages/later/view.dart +++ b/lib/pages/later/view.dart @@ -157,7 +157,7 @@ class _LaterPageState extends State return MultiSelectAppBarWidget( visible: enableMultiSelect, ctr: currCtr(), - children: [ + actions: [ TextButton( style: TextButton.styleFrom( visualDensity: VisualDensity.compact,