From dda0fc15c731dd438db351ade27cd3b9666db213 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 1 Jan 2025 11:35:01 +0800 Subject: [PATCH] mod: remove disliked rcmd Closes #80 Signed-off-by: bggRGjQaUbCoE --- lib/common/widgets/video_card_v.dart | 4 +- lib/common/widgets/video_popup_menu.dart | 121 ++++++++++-------- .../introduction/widgets/intro_detail.dart | 6 +- lib/pages/rcmd/view.dart | 4 + lib/pages/search/view.dart | 6 +- lib/pages/search/widgets/search_text.dart | 19 +-- .../search_panel/widgets/article_panel.dart | 12 +- .../search_panel/widgets/user_panel.dart | 12 +- .../search_panel/widgets/video_panel.dart | 24 ++-- lib/pages/video/detail/introduction/view.dart | 6 +- .../introduction/widgets/intro_detail.dart | 6 +- 11 files changed, 124 insertions(+), 96 deletions(-) diff --git a/lib/common/widgets/video_card_v.dart b/lib/common/widgets/video_card_v.dart index 47b59733..327ed42e 100644 --- a/lib/common/widgets/video_card_v.dart +++ b/lib/common/widgets/video_card_v.dart @@ -1,7 +1,6 @@ import 'package:PiliPalaX/common/widgets/image_save.dart'; import 'package:PiliPalaX/http/search.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import '../../models/home/rcmd/result.dart'; @@ -19,10 +18,12 @@ import 'video_popup_menu.dart'; // 视频卡片 - 垂直布局 class VideoCardV extends StatelessWidget { final dynamic videoItem; + final VoidCallback? onRemove; const VideoCardV({ super.key, required this.videoItem, + this.onRemove, }); bool isStringNumeric(String str) { @@ -208,6 +209,7 @@ class VideoCardV extends StatelessWidget { size: 29, iconSize: 17, videoItem: videoItem, + onRemove: onRemove, ), ), ]); diff --git a/lib/common/widgets/video_popup_menu.dart b/lib/common/widgets/video_popup_menu.dart index 607d4ad0..5eb4e35f 100644 --- a/lib/common/widgets/video_popup_menu.dart +++ b/lib/common/widgets/video_popup_menu.dart @@ -1,3 +1,4 @@ +import 'package:PiliPalaX/pages/search/widgets/search_text.dart'; import 'package:PiliPalaX/utils/utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; @@ -23,7 +24,9 @@ class VideoCustomActions { dynamic videoItem; BuildContext context; late List actions; - VideoCustomActions(this.videoItem, this.context) { + VoidCallback? onRemove; + + VideoCustomActions(this.videoItem, this.context, [this.onRemove]) { actions = [ if ((videoItem.bvid as String?)?.isNotEmpty == true) VideoCustomAction( @@ -82,12 +85,10 @@ class VideoCustomActions { return; } Widget actionButton(DislikeReason? r, FeedbackReason? f) { - return ElevatedButton( - style: ElevatedButton.styleFrom( - padding: const EdgeInsets.symmetric( - horizontal: 12.0, vertical: 0.0), - ), - onPressed: () async { + return SearchText( + text: r?.name ?? f?.name ?? '未知', + onTap: (_) async { + Get.back(); SmartDialog.showLoading(msg: '正在提交'); var res = await VideoHttp.feedDislike( reasonId: r?.id, @@ -97,10 +98,12 @@ class VideoCustomActions { ); SmartDialog.dismiss(); SmartDialog.showToast( - res['status'] ? (r?.toast ?? f?.toast) : res['msg']); - Get.back(); + res['status'] ? (r?.toast ?? f?.toast) : res['msg'], + ); + if (res['status']) { + onRemove?.call(); + } }, - child: Text(r?.name ?? f?.name ?? '未知'), ); } @@ -108,53 +111,57 @@ class VideoCustomActions { context: context, builder: (context) { return AlertDialog( - title: const Text('请选择'), content: SingleChildScrollView( child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (tp.dislikeReasons != null) - const Padding( - padding: EdgeInsets.symmetric(vertical: 8.0), - child: Text('我不想看'), - ), - if (tp.dislikeReasons != null) + if (tp.dislikeReasons != null) ...[ + Text('我不想看'), + const SizedBox(height: 5), Wrap( - spacing: 5.0, - runSpacing: 2.0, + spacing: 8.0, + runSpacing: 8.0, children: tp.dislikeReasons!.map((item) { return actionButton(item, null); }).toList(), ), - if (tp.feedbacks != null) - const Padding( - padding: EdgeInsets.symmetric(vertical: 8.0), - child: Text('反馈'), - ), - if (tp.feedbacks != null) + ], + if (tp.feedbacks != null) ...[ + const SizedBox(height: 5), + Text('反馈'), + const SizedBox(height: 5), Wrap( - spacing: 5.0, - runSpacing: 2.0, + spacing: 8.0, + runSpacing: 8.0, children: tp.feedbacks!.map((item) { return actionButton(null, item); }).toList(), ), - //分割线 + ], const Divider(), - ElevatedButton( - onPressed: () async { - SmartDialog.showLoading(msg: '正在提交'); - var res = await VideoHttp.feedDislikeCancel( - // reasonId: r?.id, - // feedbackId: f?.id, - id: v.param!, - goto: v.goto!, - ); - SmartDialog.dismiss(); - SmartDialog.showToast( - res['status'] ? "成功" : res['msg']); - Get.back(); - }, - child: const Text("撤销"), + Center( + child: FilledButton.tonal( + onPressed: () async { + SmartDialog.showLoading(msg: '正在提交'); + var res = await VideoHttp.feedDislikeCancel( + // reasonId: r?.id, + // feedbackId: f?.id, + id: v.param!, + goto: v.goto!, + ); + SmartDialog.dismiss(); + SmartDialog.showToast( + res['status'] ? "成功" : res['msg']); + Get.back(); + }, + style: FilledButton.styleFrom( + visualDensity: VisualDensity( + horizontal: -2, + vertical: -2, + ), + ), + child: const Text("撤销"), + ), ), ], ), @@ -167,7 +174,6 @@ class VideoCustomActions { context: context, builder: (context) { return AlertDialog( - title: const Text('点踩该视频?'), content: SingleChildScrollView( child: Column( children: [ @@ -178,20 +184,28 @@ class VideoCustomActions { spacing: 5.0, runSpacing: 2.0, children: [ - ElevatedButton( + FilledButton.tonal( onPressed: () async { + Get.back(); SmartDialog.showLoading(msg: '正在提交'); var res = await VideoHttp.dislikeVideo( bvid: videoItem.bvid as String, type: true); SmartDialog.dismiss(); SmartDialog.showToast( - res['status'] ? "点踩成功" : res['msg']); - Get.back(); + res['status'] ? "点踩成功" : res['msg'], + ); }, + style: FilledButton.styleFrom( + visualDensity: VisualDensity( + horizontal: -2, + vertical: -2, + ), + ), child: const Text("点踩"), ), - ElevatedButton( + FilledButton.tonal( onPressed: () async { + Get.back(); SmartDialog.showLoading(msg: '正在提交'); var res = await VideoHttp.dislikeVideo( bvid: videoItem.bvid as String, @@ -199,8 +213,13 @@ class VideoCustomActions { SmartDialog.dismiss(); SmartDialog.showToast( res['status'] ? "取消踩" : res['msg']); - Get.back(); }, + style: FilledButton.styleFrom( + visualDensity: VisualDensity( + horizontal: -2, + vertical: -2, + ), + ), child: const Text("撤销"), ), ], @@ -272,12 +291,14 @@ class VideoPopupMenu extends StatelessWidget { final double? iconSize; final double menuItemHeight = 45; final dynamic videoItem; + final VoidCallback? onRemove; const VideoPopupMenu({ super.key, required this.size, required this.iconSize, required this.videoItem, + this.onRemove, }); @override @@ -296,7 +317,7 @@ class VideoPopupMenu extends StatelessWidget { position: PopupMenuPosition.under, onSelected: (String type) {}, itemBuilder: (BuildContext context) => - VideoCustomActions(videoItem, context).actions.map((e) { + VideoCustomActions(videoItem, context, onRemove).actions.map((e) { return PopupMenuItem( value: e.value, height: menuItemHeight, diff --git a/lib/pages/bangumi/introduction/widgets/intro_detail.dart b/lib/pages/bangumi/introduction/widgets/intro_detail.dart index b8e9b49f..63071fcd 100644 --- a/lib/pages/bangumi/introduction/widgets/intro_detail.dart +++ b/lib/pages/bangumi/introduction/widgets/intro_detail.dart @@ -121,10 +121,10 @@ class IntroDetail extends StatelessWidget { .map( (item) => SearchText( fontSize: 13, - searchText: item['tag_name'], - onSelect: (_) => Get.toNamed('/searchResult', + text: item['tag_name'], + onTap: (_) => Get.toNamed('/searchResult', parameters: {'keyword': item['tag_name']}), - onLongSelect: (_) => + onLongPress: (_) => Utils.copyText(item['tag_name']), ), ) diff --git a/lib/pages/rcmd/view.dart b/lib/pages/rcmd/view.dart index df8aeb4f..b40f8ed9 100644 --- a/lib/pages/rcmd/view.dart +++ b/lib/pages/rcmd/view.dart @@ -128,6 +128,10 @@ class _RcmdPageState extends State ? widget.tabType == TabType.rcmd ? VideoCardV( videoItem: loadingState.response[index], + onRemove: () { + _controller.loadingState.value = LoadingState.success( + (loadingState.response as List)..removeAt(index)); + }, ) : LiveCardV( liveItem: loadingState.response[index], diff --git a/lib/pages/search/view.dart b/lib/pages/search/view.dart index 39d83b2e..8f8d4e15 100644 --- a/lib/pages/search/view.dart +++ b/lib/pages/search/view.dart @@ -217,9 +217,9 @@ class _SearchPageState extends State with RouteAware { children: _searchController.historyList .map( (item) => SearchText( - searchText: item, - onSelect: _searchController.onClickKeyword, - onLongSelect: _searchController.onLongSelect, + text: item, + onTap: _searchController.onClickKeyword, + onLongPress: _searchController.onLongSelect, ), ) .toList(), diff --git a/lib/pages/search/widgets/search_text.dart b/lib/pages/search/widgets/search_text.dart index 5e0af051..5eb04b1a 100644 --- a/lib/pages/search/widgets/search_text.dart +++ b/lib/pages/search/widgets/search_text.dart @@ -1,18 +1,19 @@ import 'package:flutter/material.dart'; class SearchText extends StatelessWidget { - final String? searchText; - final Function? onSelect; - final Function? onLongSelect; + final String text; + final ValueChanged? onTap; + final ValueChanged? onLongPress; final double? fontSize; final Color? bgColor; final Color? textColor; final TextAlign? textAlign; + const SearchText({ super.key, - this.searchText, - this.onSelect, - this.onLongSelect, + required this.text, + this.onTap, + this.onLongPress, this.fontSize, this.bgColor, this.textColor, @@ -28,17 +29,17 @@ class SearchText extends StatelessWidget { padding: EdgeInsets.zero, child: InkWell( onTap: () { - onSelect?.call(searchText); + onTap?.call(text); }, onLongPress: () { - onLongSelect?.call(searchText); + onLongPress?.call(text); }, borderRadius: BorderRadius.circular(6), child: Padding( padding: const EdgeInsets.only(top: 5, bottom: 5, left: 11, right: 11), child: Text( - searchText!, + text, textAlign: textAlign, style: TextStyle( fontSize: fontSize, diff --git a/lib/pages/search_panel/widgets/article_panel.dart b/lib/pages/search_panel/widgets/article_panel.dart index b70e39cb..a7687ce4 100644 --- a/lib/pages/search_panel/widgets/article_panel.dart +++ b/lib/pages/search_panel/widgets/article_panel.dart @@ -283,8 +283,8 @@ class ArticlePanelController extends GetxController { children: orderFiltersList .map( (item) => SearchText( - searchText: item['label'], - onSelect: (_) async { + text: item['label'], + onTap: (_) async { Get.back(); currentOrderFilterval.value = item['value']; SmartDialog.dismiss(); @@ -297,7 +297,7 @@ class ArticlePanelController extends GetxController { await ctr.onRefresh(); SmartDialog.dismiss(); }, - onLongSelect: (_) {}, + onLongPress: (_) {}, bgColor: item['value'] == currentOrderFilterval.value ? Theme.of(context).colorScheme.secondaryContainer : null, @@ -317,8 +317,8 @@ class ArticlePanelController extends GetxController { children: zoneFiltersList .map( (item) => SearchText( - searchText: item['label'], - onSelect: (_) async { + text: item['label'], + onTap: (_) async { Get.back(); currentZoneFilterval.value = item['value']; SmartDialog.dismiss(); @@ -331,7 +331,7 @@ class ArticlePanelController extends GetxController { await ctr.onRefresh(); SmartDialog.dismiss(); }, - onLongSelect: (_) {}, + onLongPress: (_) {}, bgColor: item['value'] == currentZoneFilterval.value ? Theme.of(context).colorScheme.secondaryContainer : null, diff --git a/lib/pages/search_panel/widgets/user_panel.dart b/lib/pages/search_panel/widgets/user_panel.dart index 1f3c0c82..843a2b8e 100644 --- a/lib/pages/search_panel/widgets/user_panel.dart +++ b/lib/pages/search_panel/widgets/user_panel.dart @@ -206,8 +206,8 @@ class UserPanelController extends GetxController { children: orderFiltersList .map( (item) => SearchText( - searchText: item['label'], - onSelect: (_) async { + text: item['label'], + onTap: (_) async { Get.back(); currentOrderFilterval.value = item['value']; SmartDialog.dismiss(); @@ -221,7 +221,7 @@ class UserPanelController extends GetxController { await ctr.onRefresh(); SmartDialog.dismiss(); }, - onLongSelect: (_) {}, + onLongPress: (_) {}, bgColor: item['value'] == currentOrderFilterval.value ? Theme.of(context).colorScheme.secondaryContainer : null, @@ -241,8 +241,8 @@ class UserPanelController extends GetxController { children: userTypeFiltersList .map( (item) => SearchText( - searchText: item['label'], - onSelect: (_) async { + text: item['label'], + onTap: (_) async { Get.back(); currentUserTypeFilterval.value = item['value']; SmartDialog.dismiss(); @@ -255,7 +255,7 @@ class UserPanelController extends GetxController { await ctr.onRefresh(); SmartDialog.dismiss(); }, - onLongSelect: (_) {}, + onLongPress: (_) {}, bgColor: item['value'] == currentUserTypeFilterval.value ? Theme.of(context).colorScheme.secondaryContainer : null, diff --git a/lib/pages/search_panel/widgets/video_panel.dart b/lib/pages/search_panel/widgets/video_panel.dart index 31711fb8..e97268f2 100644 --- a/lib/pages/search_panel/widgets/video_panel.dart +++ b/lib/pages/search_panel/widgets/video_panel.dart @@ -255,10 +255,10 @@ class VideoPanelController extends GetxController { builder: (context, setState) { Widget dateWidget([bool isFirst = true]) { return SearchText( - searchText: + text: DateFormat('yyyy-MM-dd').format(isFirst ? pubBegin : pubEnd), textAlign: TextAlign.center, - onSelect: (text) { + onTap: (text) { showDatePicker( context: context, initialDate: isFirst ? pubBegin : pubEnd, @@ -303,7 +303,7 @@ class VideoPanelController extends GetxController { } }); }, - onLongSelect: (_) {}, + onLongPress: (_) {}, bgColor: currentPubTimeFilterval == -1 && (isFirst ? customPubBegin : customPubEnd) ? Theme.of(context).colorScheme.secondaryContainer @@ -337,8 +337,8 @@ class VideoPanelController extends GetxController { children: pubTimeFiltersList .map( (item) => SearchText( - searchText: item['label'], - onSelect: (text) async { + text: item['label'], + onTap: (text) async { Get.back(); currentPubTimeFilterval = item['value']; SmartDialog.dismiss(); @@ -379,7 +379,7 @@ class VideoPanelController extends GetxController { await ctr.onRefresh(); SmartDialog.dismiss(); }, - onLongSelect: (_) {}, + onLongPress: (_) {}, bgColor: item['value'] == currentPubTimeFilterval ? Theme.of(context) .colorScheme @@ -416,8 +416,8 @@ class VideoPanelController extends GetxController { children: timeFiltersList .map( (item) => SearchText( - searchText: item['label'], - onSelect: (text) async { + text: item['label'], + onTap: (text) async { Get.back(); currentTimeFilterval = item['value']; SmartDialog.dismiss(); @@ -430,7 +430,7 @@ class VideoPanelController extends GetxController { await ctr.onRefresh(); SmartDialog.dismiss(); }, - onLongSelect: (_) {}, + onLongPress: (_) {}, bgColor: item['value'] == currentTimeFilterval ? Theme.of(context) .colorScheme @@ -454,8 +454,8 @@ class VideoPanelController extends GetxController { children: zoneFiltersList .map( (item) => SearchText( - searchText: item['label'], - onSelect: (text) async { + text: item['label'], + onTap: (text) async { Get.back(); currentZoneFilterval = item['value']; SmartDialog.dismiss(); @@ -468,7 +468,7 @@ class VideoPanelController extends GetxController { await ctr.onRefresh(); SmartDialog.dismiss(); }, - onLongSelect: (_) {}, + onLongPress: (_) {}, bgColor: item['value'] == currentZoneFilterval ? Theme.of(context) .colorScheme diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index 15740d75..464d0231 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -620,12 +620,12 @@ class _VideoInfoState extends State with TickerProviderStateMixin { .map( (item) => SearchText( fontSize: 13, - searchText: item['tag_name'], - onSelect: (_) => Get.toNamed('/searchResult', + text: item['tag_name'], + onTap: (_) => Get.toNamed('/searchResult', parameters: { 'keyword': item['tag_name'] }), - onLongSelect: (_) => + onLongPress: (_) => Utils.copyText(item['tag_name']), ), ) diff --git a/lib/pages/video/detail/introduction/widgets/intro_detail.dart b/lib/pages/video/detail/introduction/widgets/intro_detail.dart index b472792d..0b38ec62 100644 --- a/lib/pages/video/detail/introduction/widgets/intro_detail.dart +++ b/lib/pages/video/detail/introduction/widgets/intro_detail.dart @@ -86,10 +86,10 @@ class IntroDetail extends StatelessWidget { .map( (item) => SearchText( fontSize: 13, - searchText: item['tag_name'], - onSelect: (_) => Get.toNamed('/searchResult', + text: item['tag_name'], + onTap: (_) => Get.toNamed('/searchResult', parameters: {'keyword': item['tag_name']}), - onLongSelect: (_) => + onLongPress: (_) => Utils.copyText(item['tag_name']), ), )