diff --git a/lib/http/video.dart b/lib/http/video.dart index 68f3508bf..191864e96 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -171,7 +171,8 @@ class VideoHttp { List list = []; List blackMidsList = GStorage.blackMidsList; for (var i in res.data['data']['list']) { - if (!blackMidsList.contains(i['owner']['mid'])) { + if (!blackMidsList.contains(i['owner']['mid']) && + !RecommendFilter.filterTitle(i['title'])) { list.add(HotVideoItemModel.fromJson(i)); } } @@ -978,7 +979,8 @@ class VideoHttp { List list = []; List blackMidsList = GStorage.blackMidsList; for (var i in res.data['data']['list']) { - if (!blackMidsList.contains(i['owner']['mid'])) { + if (!blackMidsList.contains(i['owner']['mid']) && + !RecommendFilter.filterTitle(i['title'])) { list.add(HotVideoItemModel.fromJson(i)); } } diff --git a/lib/pages/setting/recommend_setting.dart b/lib/pages/setting/recommend_setting.dart index 7b012ebd8..b3c6f255d 100644 --- a/lib/pages/setting/recommend_setting.dart +++ b/lib/pages/setting/recommend_setting.dart @@ -155,43 +155,42 @@ class _RecommendSettingState extends State { context: context, builder: (context) { return AlertDialog( - title: const Text('标题关键词过滤'), - content: Column(mainAxisSize: MainAxisSize.min, children: [ - const Text('使用空格隔开,如:尝试 测试'), - TextField( - controller: textController, - //decoration: InputDecoration(hintText: hintText), - ) - ]), + title: const Text( + '标题关键词过滤', + style: TextStyle(fontSize: 18), + ), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('使用|隔开,如:尝试|测试'), + TextField( + controller: textController, + textInputAction: TextInputAction.newline, + minLines: 1, + maxLines: 4, + ) + ], + ), actions: [ TextButton( - child: const Text('清空'), - onPressed: () { - textController.text = ''; - }, - ), - TextButton( - child: const Text('取消'), - onPressed: () { - Navigator.of(context).pop(); - SmartDialog.showToast('关键词未被修改'); - }, + onPressed: Get.back, + child: Text( + '取消', + style: TextStyle( + color: Theme.of(context).colorScheme.outline), + ), ), TextButton( child: const Text('保存'), onPressed: () async { - Navigator.of(context).pop(); - String filter = textController.text.trim(); - banWordForRecommend = filter; + Get.back(); + banWordForRecommend = textController.text; setting.put(SettingBoxKey.banWordForRecommend, banWordForRecommend); setState(() {}); RecommendFilter.update(); - if (filter.isNotEmpty) { - SmartDialog.showToast('已保存:$banWordForRecommend'); - } else { - SmartDialog.showToast('已清除全部关键词'); - } + SmartDialog.showToast('已保存'); }, ), ], @@ -285,7 +284,7 @@ class _RecommendSettingState extends State { }, ), SetSwitchItem( - title: '已关注Up豁免推荐过滤', + title: '已关注UP豁免推荐过滤', subTitle: '推荐中已关注用户发布的内容不会被过滤', leading: const Icon(Icons.favorite_border_outlined), setKey: SettingBoxKey.exemptFilterForFollowed, diff --git a/lib/utils/recommend_filter.dart b/lib/utils/recommend_filter.dart index 1e2ee4161..1d9f04838 100644 --- a/lib/utils/recommend_filter.dart +++ b/lib/utils/recommend_filter.dart @@ -8,7 +8,7 @@ class RecommendFilter { static late int minLikeRatioForRecommend; static late bool exemptFilterForFollowed; static late bool applyFilterToRelatedVideos; - static late List banWordList; + static late String banWords; RecommendFilter() { update(); } @@ -21,9 +21,7 @@ class RecommendFilter { setting.get(SettingBoxKey.minDurationForRcmd, defaultValue: 0); minLikeRatioForRecommend = setting.get(SettingBoxKey.minLikeRatioForRecommend, defaultValue: 0); - banWordList = (setting.get(SettingBoxKey.banWordForRecommend, - defaultValue: '') as String) - .split(' '); + banWords = setting.get(SettingBoxKey.banWordForRecommend, defaultValue: ''); exemptFilterForFollowed = setting.get(SettingBoxKey.exemptFilterForFollowed, defaultValue: true); applyFilterToRelatedVideos = setting @@ -51,8 +49,18 @@ class RecommendFilter { minLikeRatioForRecommend * videoItem.stat.view) { return true; } - for (var word in banWordList) { - if (word.isNotEmpty && videoItem.title.contains(word)) return true; + if (filterTitle(videoItem.title)) { + return true; + } + return false; + } + + static bool filterTitle(String title, {bool? isFollowed}) { + if (exemptFilterForFollowed && isFollowed == true) { + return false; + } + if (banWords.isNotEmpty && RegExp(banWords).hasMatch(title)) { + return true; } return false; }