From b485399517aa948074028618ead9f59cd73b3e34 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Wed, 30 Aug 2023 11:04:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BF=AB=E9=80=9F=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/setting/extra_setting.dart | 6 +++ .../video/detail/introduction/controller.dart | 28 +++++++++- lib/pages/video/detail/introduction/view.dart | 51 +++++++++++++++---- .../introduction/widgets/action_row_item.dart | 8 +++ lib/utils/storage.dart | 1 + 5 files changed, 83 insertions(+), 11 deletions(-) diff --git a/lib/pages/setting/extra_setting.dart b/lib/pages/setting/extra_setting.dart index 4ed55f96..bb262b57 100644 --- a/lib/pages/setting/extra_setting.dart +++ b/lib/pages/setting/extra_setting.dart @@ -55,6 +55,12 @@ class _ExtraSettingState extends State { defaultVal: true, callFn: (val) => {SmartDialog.showToast('下次启动时生效')}, ), + const SetSwitchItem( + title: '快速收藏', + subTitle: '点按收藏至默认,长按选择文件夹', + setKey: SettingBoxKey.enableQuickFav, + defaultVal: false, + ), ListTile( dense: false, title: Text('评论展示', style: titleStyle), diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index ea63c14d..5a548607 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -144,6 +144,8 @@ class VideoIntroController extends GetxController { // 获取收藏状态 Future queryHasFavVideo() async { + /// fix 延迟查询 + await Future.delayed(const Duration(milliseconds: 200)); var result = await VideoHttp.hasFavVideo(aid: IdUtils.bv2av(bvid)); if (result['status']) { hasFav.value = result["data"]['favoured']; @@ -275,7 +277,27 @@ class VideoIntroController extends GetxController { } // (取消)收藏 - Future actionFavVideo() async { + Future actionFavVideo({type = 'choose'}) async { + // 收藏至默认文件夹 + if (type == 'default') { + await queryVideoInFolder(); + int defaultFolderId = favFolderData.value.list!.first.id!; + int favStatus = favFolderData.value.list!.first.favState!; + print('favStatus: $favStatus'); + var result = await VideoHttp.favVideo( + aid: IdUtils.bv2av(bvid), + addIds: favStatus == 0 ? '$defaultFolderId' : '', + delIds: favStatus == 1 ? '$defaultFolderId' : '', + ); + if (result['status']) { + if (result['data']['prompt']) { + // 重新获取收藏状态 + await queryHasFavVideo(); + SmartDialog.showToast('✅ 操作成功'); + } + } + return; + } try { for (var i in favFolderData.value.list!.toList()) { if (i.favState == 1) { @@ -288,17 +310,19 @@ class VideoIntroController extends GetxController { // ignore: avoid_print print(e); } + SmartDialog.showLoading(msg: '请求中'); var result = await VideoHttp.favVideo( aid: IdUtils.bv2av(bvid), addIds: addMediaIdsNew.join(','), delIds: delMediaIdsNew.join(',')); + SmartDialog.dismiss(); if (result['status']) { if (result['data']['prompt']) { addMediaIdsNew = []; delMediaIdsNew = []; Get.back(); // 重新获取收藏状态 - queryHasFavVideo(); + await queryHasFavVideo(); SmartDialog.showToast('✅ 操作成功'); } } diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index 75eef280..a0fa0b9e 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -122,6 +122,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { late final Map videoItem; Box localCache = GStrorage.localCache; + Box setting = GStrorage.setting; late double sheetHeight; late final bool loadingStatus; // 加载状态 @@ -150,19 +151,50 @@ class _VideoInfoState extends State with TickerProviderStateMixin { } // 收藏 - showFavBottomSheet() { + showFavBottomSheet({type = 'tap'}) { if (videoIntroController.userInfo == null) { SmartDialog.showToast('账号未登录'); return; } - showModalBottomSheet( - context: context, - useRootNavigator: true, - isScrollControlled: true, - builder: (context) { - return FavPanel(ctr: videoIntroController); - }, - ); + bool enableDragQuickFav = + setting.get(SettingBoxKey.enableQuickFav, defaultValue: false); + // 快速收藏 & + // 点按 收藏至默认文件夹 + // 长按选择文件夹 + if (enableDragQuickFav) { + if (type == 'tap') { + if (!videoIntroController.hasFav.value) { + videoIntroController.actionFavVideo(type: 'default'); + } else { + showModalBottomSheet( + context: context, + useRootNavigator: true, + isScrollControlled: true, + builder: (context) { + return FavPanel(ctr: videoIntroController); + }, + ); + } + } else { + showModalBottomSheet( + context: context, + useRootNavigator: true, + isScrollControlled: true, + builder: (context) { + return FavPanel(ctr: videoIntroController); + }, + ); + } + } else if (type != 'longPress') { + showModalBottomSheet( + context: context, + useRootNavigator: true, + isScrollControlled: true, + builder: (context) { + return FavPanel(ctr: videoIntroController); + }, + ); + } } // 视频介绍 @@ -510,6 +542,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { () => ActionRowItem( icon: const Icon(FontAwesomeIcons.heart), onTap: () => showFavBottomSheet(), + onLongPress: () => showFavBottomSheet(type: 'longPress'), selectStatus: videoIntroController.hasFav.value, loadingStatus: loadingStatus, text: !loadingStatus diff --git a/lib/pages/video/detail/introduction/widgets/action_row_item.dart b/lib/pages/video/detail/introduction/widgets/action_row_item.dart index 3aabe337..890a3a97 100644 --- a/lib/pages/video/detail/introduction/widgets/action_row_item.dart +++ b/lib/pages/video/detail/introduction/widgets/action_row_item.dart @@ -8,6 +8,7 @@ class ActionRowItem extends StatelessWidget { final bool? loadingStatus; final String? text; final bool selectStatus; + final Function? onLongPress; const ActionRowItem({ Key? key, @@ -17,6 +18,7 @@ class ActionRowItem extends StatelessWidget { this.loadingStatus, this.text, this.selectStatus = false, + this.onLongPress, }) : super(key: key); @override @@ -32,6 +34,12 @@ class ActionRowItem extends StatelessWidget { feedBack(), onTap!(), }, + onLongPress: () { + feedBack(); + if (onLongPress != null) { + onLongPress!(); + } + }, child: Padding( padding: const EdgeInsets.fromLTRB(15, 7, 15, 7), child: Row( diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 91094a39..8c3b981c 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -108,6 +108,7 @@ class SettingBoxKey { static const String replySortType = 'replySortType'; static const String defaultDynamicType = 'defaultDynamicType'; static const String enableHotKey = 'enableHotKey'; + static const String enableQuickFav = 'enableQuickFav'; /// 外观 static const String themeMode = 'themeMode';