From 0c4bad406ea2b8620b131a45a059dec57e84969b Mon Sep 17 00:00:00 2001 From: orz12 Date: Sat, 27 Jan 2024 14:28:15 +0800 Subject: [PATCH 01/16] =?UTF-8?q?fix:=20=E8=AF=84=E8=AE=BA=E5=8C=BA?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E9=80=BB=E8=BE=91=E9=87=8D=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=AB=E6=9C=89=E5=85=B3=E9=94=AE=E8=AF=8D?= =?UTF-8?q?=E7=9A=84=E8=AF=84=E8=AE=BA=E9=87=8D=E5=A4=8D=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/reply/widgets/reply_item.dart | 363 +++++++----------- 1 file changed, 131 insertions(+), 232 deletions(-) diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 48518bee..6ecf3983 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -1,5 +1,6 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; @@ -585,255 +586,153 @@ InlineSpan buildContent( if (content.message.contains('&')) { content.message = content.message.replaceAll('&', '&'); } - // 匹配表情 + print("content.jumpUrl.keys:" + content.jumpUrl.keys.toString()); + // 构建正则表达式 + final List specialTokens = [ + ...content.emote.keys, + ...content.atNameToMid.keys.map((e) => '@$e'), + ...content.jumpUrl.keys.map((e) => + e.replaceAll('?', '\\?').replaceAll('+', '\\+').replaceAll('*', '\\*')), + r'\b\d{2}:\d{2}\b' + ]; + + final String patternStr = specialTokens.map(RegExp.escape).join('|'); + final RegExp pattern = RegExp(patternStr); + List matchedStrs = []; + // 分割文本并处理每个部分 content.message.splitMapJoin( - RegExp(r"\[.*?\]"), + pattern, onMatch: (Match match) { - final String matchStr = match[0]!; - if (content.emote.isNotEmpty && - matchStr.indexOf('[') == matchStr.lastIndexOf('[') && - matchStr.indexOf(']') == matchStr.lastIndexOf(']')) { + String matchStr = match[0]!; + if (content.emote.containsKey(matchStr)) { + // 处理表情 final int size = content.emote[matchStr]['meta']['size']; - if (content.emote.keys.contains(matchStr)) { + spanChilds.add(WidgetSpan( + child: NetworkImgLayer( + src: content.emote[matchStr]['url'], + type: 'emote', + width: size * 20, + height: size * 20, + ), + )); + } else if (matchStr.startsWith("@") && + content.atNameToMid.containsKey(matchStr.substring(1))) { + // 处理@用户 + final String userName = matchStr.substring(1); + final int userId = content.atNameToMid[userName]; + spanChilds.add( + TextSpan( + text: matchStr, + style: TextStyle( + color: Theme.of(context).colorScheme.primary, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + final String heroTag = Utils.makeHeroTag(userId); + Get.toNamed( + '/member?mid=$userId', + arguments: {'face': '', 'heroTag': heroTag}, + ); + }, + ), + ); + } else if (matchStr.contains(':')) { + spanChilds.add( + TextSpan( + text: ' $matchStr ', + style: TextStyle( + color: Theme.of(context).colorScheme.primary, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + // 跳转到指定位置 + try { + Get.find(tag: Get.arguments['heroTag']) + .plPlayerController + .seekTo( + Duration(seconds: Utils.duration(matchStr)), + ); + } catch (_) {} + }, + ), + ); + } else { + print("matchStr=$matchStr"); + String appUrlSchema = ''; + final bool enableWordRe = setting.get(SettingBoxKey.enableWordRe, + defaultValue: false) as bool; + if (enableWordRe && content.jumpUrl[matchStr] != null && !matchedStrs.contains(matchStr)) { + appUrlSchema = content.jumpUrl[matchStr]['app_url_schema']; spanChilds.add( - WidgetSpan( - child: NetworkImgLayer( - src: content.emote[matchStr]['url'], - type: 'emote', - width: size * 20, - height: size * 20, + TextSpan( + text: content.jumpUrl[matchStr]['title'], + style: TextStyle( + color: Theme.of(context).colorScheme.primary, ), + recognizer: TapGestureRecognizer() + ..onTap = () { + if (appUrlSchema == '') { + final String str = Uri.parse(matchStr).pathSegments[0]; + final Map matchRes = IdUtils.matchAvorBv(input: str); + final List matchKeys = matchRes.keys.toList(); + if (matchKeys.isNotEmpty) { + if (matchKeys.first == 'BV') { + Get.toNamed( + '/searchResult', + parameters: {'keyword': matchRes['BV']}, + ); + } + } else { + Get.toNamed( + '/webview', + parameters: { + 'url': matchStr, + 'type': 'url', + 'pageTitle': '' + }, + ); + } + } else { + if (appUrlSchema.startsWith('bilibili://search')) { + Get.toNamed('/searchResult', parameters: { + 'keyword': content.jumpUrl[matchStr]['title'] + }); + } + } + }, ), ); + if (appUrlSchema.startsWith('bilibili://search') && enableWordRe) { + spanChilds.add( + WidgetSpan( + child: Icon( + FontAwesomeIcons.magnifyingGlass, + size: 9, + color: Theme.of(context).colorScheme.primary, + ), + alignment: PlaceholderAlignment.top, + ), + ); + } + // 只显示一次 + matchedStrs.add(matchStr); } else { spanChilds.add(TextSpan( text: matchStr, recognizer: TapGestureRecognizer() ..onTap = () => replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); - return matchStr; } - } else { - spanChilds.add(TextSpan( - text: matchStr, - recognizer: TapGestureRecognizer() - ..onTap = () => - replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); - return matchStr; } return ''; }, - onNonMatch: (String str) { - // 匹配@用户 - String matchMember = str; - if (content.atNameToMid.isNotEmpty) { - final List atNameToMidKeys = content.atNameToMid.keys.toList(); - RegExp reg = RegExp(atNameToMidKeys.map((key) => key).join('|')); - // if (!content.message.contains(':')) { - // reg = RegExp(r"@.*( |:)"); - // } - - // 只@用户没有内容 - if (!content.message.contains(':') || - (content.atNameToMid.length == 1 && - content.message == '@${content.members.first.uname}')) { - reg = RegExp(r"@.*( |:|$)"); - } - matchMember = str.splitMapJoin( - reg, - onMatch: (Match match) { - if (match[0] != null) { - hasMatchMember = true; - content.atNameToMid.forEach((key, value) { - if (str.contains('回复')) { - spanChilds.add( - TextSpan( - text: '回复 ', - style: TextStyle( - fontSize: - Theme.of(context).textTheme.titleSmall!.fontSize, - ), - ), - ); - } - spanChilds.add( - TextSpan( - text: '@$key', - style: TextStyle( - fontSize: - Theme.of(context).textTheme.titleSmall!.fontSize, - color: Theme.of(context).colorScheme.primary, - ), - recognizer: TapGestureRecognizer() - ..onTap = () { - final String heroTag = Utils.makeHeroTag(value); - Get.toNamed( - '/member?mid=$value', - arguments: {'face': '', 'heroTag': heroTag}, - ); - }, - ), - ); - }); - } - return ''; - }, - onNonMatch: (String str) { - if (!str.contains('@')) { - spanChilds.add(TextSpan(text: str)); - } - print(str); - return str; - }, - ); - } else { - matchMember = str; - } - - // 匹配 jumpUrl - String matchUrl = matchMember; - if (content.jumpUrl.isNotEmpty) { - final List urlKeys = content.jumpUrl.keys.toList().reversed.toList(); - for (int index = 0; index < urlKeys.length; index++) { - var i = urlKeys[index]; - if (i.contains('?')) { - urlKeys[index] = i.replaceAll('?', '\\?'); - } - if (i.contains('+')) { - urlKeys[index] = i.replaceAll('+', '\\+'); - } - if (i.contains('*')) { - urlKeys[index] = i.replaceAll('*', '\\*'); - } - } - if (hasMatchMember) { - matchMember = matchMember.split('回复 @ :').length > 1 - ? matchMember.split('回复 @ :')[1] - : matchMember; - } - matchUrl = matchMember.splitMapJoin( - /// RegExp.escape() 转义特殊字符 - RegExp(urlKeys.map((key) => key).join("|")), - // RegExp('What does the fox say\\?'), - onMatch: (Match match) { - final String matchStr = match[0]!; - String appUrlSchema = ''; - if (content.jumpUrl[matchStr] != null) { - appUrlSchema = content.jumpUrl[matchStr]['app_url_schema']; - } - // 默认不显示关键词 - final bool enableWordRe = setting.get(SettingBoxKey.enableWordRe, - defaultValue: false) as bool; - if (content.jumpUrl[matchStr] != null) { - spanChilds.add( - TextSpan( - text: content.jumpUrl[matchStr]['title'], - style: TextStyle( - color: enableWordRe - ? Theme.of(context).colorScheme.primary - : null, - ), - recognizer: TapGestureRecognizer() - ..onTap = () { - if (appUrlSchema == '') { - final String str = Uri.parse(matchStr).pathSegments[0]; - final Map matchRes = IdUtils.matchAvorBv(input: str); - final List matchKeys = matchRes.keys.toList(); - if (matchKeys.isNotEmpty) { - if (matchKeys.first == 'BV') { - Get.toNamed( - '/searchResult', - parameters: {'keyword': matchRes['BV']}, - ); - } - } else { - Get.toNamed( - '/webview', - parameters: { - 'url': matchStr, - 'type': 'url', - 'pageTitle': '' - }, - ); - } - } else { - if (appUrlSchema.startsWith('bilibili://search') && - enableWordRe) { - Get.toNamed('/searchResult', parameters: { - 'keyword': content.jumpUrl[matchStr]['title'] - }); - } - } - }, - ), - ); - } - - if (appUrlSchema.startsWith('bilibili://search') && enableWordRe) { - spanChilds.add( - WidgetSpan( - child: Icon( - FontAwesomeIcons.magnifyingGlass, - size: 9, - color: Theme.of(context).colorScheme.primary, - ), - alignment: PlaceholderAlignment.top, - ), - ); - } - return ''; - }, - onNonMatch: (String str) { - spanChilds.add(TextSpan( - text: str, - recognizer: TapGestureRecognizer() - ..onTap = () => replyReply( - replyItem.root == 0 ? replyItem : fReplyItem))); - return str; - }, - ); - } - str = matchUrl.splitMapJoin( - RegExp(r'\b\d{2}:\d{2}\b'), - onMatch: (Match match) { - String matchStr = match[0]!; - spanChilds.add( - TextSpan( - text: ' $matchStr ', - style: TextStyle( - color: Theme.of(context).colorScheme.primary, - ), - recognizer: TapGestureRecognizer() - ..onTap = () { - // 跳转到指定位置 - try { - Get.find( - tag: Get.arguments['heroTag']) - .plPlayerController - .seekTo( - Duration(seconds: Utils.duration(matchStr)), - ); - } catch (_) {} - }, - ), - ); - return ''; - }, - onNonMatch: (str) { - return str; - }, - ); - - if (content.atNameToMid.isEmpty && content.jumpUrl.isEmpty) { - if (str != '') { - spanChilds.add(TextSpan( - text: str, - recognizer: TapGestureRecognizer() - ..onTap = () => - replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); - } - } - return str; + onNonMatch: (String nonMatchStr) { + spanChilds.add(TextSpan( + text: nonMatchStr, + recognizer: TapGestureRecognizer() + ..onTap = () => + replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); + return nonMatchStr; }, ); From e603942b5fae5813ace24c4df50ca728f7c6c46c Mon Sep 17 00:00:00 2001 From: orz12 Date: Sat, 27 Jan 2024 15:49:34 +0800 Subject: [PATCH 02/16] =?UTF-8?q?fix:=20=E8=AF=84=E8=AE=BA=E5=8C=BA?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=AD=A3=E5=88=99=E6=8B=BC=E6=8E=A5=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../video/detail/reply/widgets/reply_item.dart | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 6ecf3983..98d8ba6a 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -593,10 +593,10 @@ InlineSpan buildContent( ...content.atNameToMid.keys.map((e) => '@$e'), ...content.jumpUrl.keys.map((e) => e.replaceAll('?', '\\?').replaceAll('+', '\\+').replaceAll('*', '\\*')), - r'\b\d{2}:\d{2}\b' ]; - final String patternStr = specialTokens.map(RegExp.escape).join('|'); + final String patternStr = + specialTokens.map(RegExp.escape).join('|') + r'|\b[0-9]{1,2}:[0-9]{2}\b'; final RegExp pattern = RegExp(patternStr); List matchedStrs = []; // 分割文本并处理每个部分 @@ -647,12 +647,15 @@ InlineSpan buildContent( ..onTap = () { // 跳转到指定位置 try { + SmartDialog.showToast('跳转至:$matchStr'); Get.find(tag: Get.arguments['heroTag']) .plPlayerController .seekTo( Duration(seconds: Utils.duration(matchStr)), ); - } catch (_) {} + } catch (e) { + SmartDialog.showToast('跳转失败: $e'); + } }, ), ); @@ -661,7 +664,9 @@ InlineSpan buildContent( String appUrlSchema = ''; final bool enableWordRe = setting.get(SettingBoxKey.enableWordRe, defaultValue: false) as bool; - if (enableWordRe && content.jumpUrl[matchStr] != null && !matchedStrs.contains(matchStr)) { + if (enableWordRe && + content.jumpUrl[matchStr] != null && + !matchedStrs.contains(matchStr)) { appUrlSchema = content.jumpUrl[matchStr]['app_url_schema']; spanChilds.add( TextSpan( From 85a59e11b961de26d781308619b3386619439507 Mon Sep 17 00:00:00 2001 From: orz12 Date: Thu, 1 Feb 2024 22:56:29 +0800 Subject: [PATCH 03/16] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=85=B3=E9=94=AE=E8=AF=8D=E6=97=B6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E6=97=B6=E9=97=B4=E3=80=81=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=E5=85=B3=E9=94=AE=E8=AF=8D=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E6=9B=BF=E6=8D=A2=E8=B6=85=E9=93=BE=E6=8E=A5=E3=80=81?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=B7=BB=E5=8A=A0=E4=B8=AD=E6=96=87=E5=86=92?= =?UTF-8?q?=E5=8F=B7=E5=8C=B9=E9=85=8D=E5=B9=B6=E6=8F=90=E5=8D=87=E5=88=86?= =?UTF-8?q?=E6=94=AF=E5=88=A4=E5=AE=9A=E4=B8=A5=E6=A0=BC=E7=A8=8B=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/reply/widgets/reply_item.dart | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 98d8ba6a..cab9d420 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -595,10 +595,21 @@ InlineSpan buildContent( e.replaceAll('?', '\\?').replaceAll('+', '\\+').replaceAll('*', '\\*')), ]; - final String patternStr = - specialTokens.map(RegExp.escape).join('|') + r'|\b[0-9]{1,2}:[0-9]{2}\b'; + String patternStr = + specialTokens.map(RegExp.escape).join('|'); + if (patternStr.isNotEmpty) { + patternStr += "|"; + } + patternStr += r'(\b\d{1,2}[::]\d{2}\b)'; final RegExp pattern = RegExp(patternStr); List matchedStrs = []; + void addPlainTextSpan(str){ + spanChilds.add(TextSpan( + text: str, + recognizer: TapGestureRecognizer() + ..onTap = () => + replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); + } // 分割文本并处理每个部分 content.message.splitMapJoin( pattern, @@ -636,7 +647,7 @@ InlineSpan buildContent( }, ), ); - } else if (matchStr.contains(':')) { + } else if (RegExp(r'^\b[0-9]{1,2}[::][0-9]{2}\b$').hasMatch(matchStr)) { spanChilds.add( TextSpan( text: ' $matchStr ', @@ -647,6 +658,7 @@ InlineSpan buildContent( ..onTap = () { // 跳转到指定位置 try { + matchStr = matchStr.replaceAll(':', ':'); SmartDialog.showToast('跳转至:$matchStr'); Get.find(tag: Get.arguments['heroTag']) .plPlayerController @@ -664,10 +676,13 @@ InlineSpan buildContent( String appUrlSchema = ''; final bool enableWordRe = setting.get(SettingBoxKey.enableWordRe, defaultValue: false) as bool; - if (enableWordRe && - content.jumpUrl[matchStr] != null && + if (content.jumpUrl[matchStr] != null && !matchedStrs.contains(matchStr)) { appUrlSchema = content.jumpUrl[matchStr]['app_url_schema']; + if (appUrlSchema.startsWith('bilibili://search') && !enableWordRe) { + addPlainTextSpan(matchStr); + return ""; + } spanChilds.add( TextSpan( text: content.jumpUrl[matchStr]['title'], @@ -707,7 +722,7 @@ InlineSpan buildContent( }, ), ); - if (appUrlSchema.startsWith('bilibili://search') && enableWordRe) { + if (appUrlSchema.startsWith('bilibili://search')) { spanChilds.add( WidgetSpan( child: Icon( @@ -722,21 +737,13 @@ InlineSpan buildContent( // 只显示一次 matchedStrs.add(matchStr); } else { - spanChilds.add(TextSpan( - text: matchStr, - recognizer: TapGestureRecognizer() - ..onTap = () => - replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); + addPlainTextSpan(matchStr); } } return ''; }, onNonMatch: (String nonMatchStr) { - spanChilds.add(TextSpan( - text: nonMatchStr, - recognizer: TapGestureRecognizer() - ..onTap = () => - replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); + addPlainTextSpan(nonMatchStr); return nonMatchStr; }, ); From 81371c5a31538425af93c020943cc0782b92da4d Mon Sep 17 00:00:00 2001 From: orz12 Date: Fri, 2 Feb 2024 00:06:46 +0800 Subject: [PATCH 04/16] =?UTF-8?q?fix:=20=E5=8F=AA=E6=9C=89=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E7=9A=84=E8=AF=84=E8=AE=BA=E5=8C=BA=E4=B8=8D=E9=AB=98?= =?UTF-8?q?=E4=BA=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/video/detail/reply/widgets/reply_item.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index cab9d420..48503d30 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -544,7 +544,9 @@ InlineSpan buildContent( content.atNameToMid.isEmpty && content.jumpUrl.isEmpty && content.vote.isEmpty && - content.pictures.isEmpty) { + content.pictures.isEmpty && + content.message.isNotEmpty && + !RegExp(r'\b[0-9]{1,2}[::][0-9]{2}\b').hasMatch(content.message)) { return TextSpan( text: content.message, recognizer: TapGestureRecognizer() From 0b349e102ebf77467205d4f298b9cef6b81f250e Mon Sep 17 00:00:00 2001 From: orz12 Date: Fri, 2 Feb 2024 00:34:52 +0800 Subject: [PATCH 05/16] =?UTF-8?q?fix=EF=BC=9A=E8=AF=84=E8=AE=BA=E5=8C=BAHT?= =?UTF-8?q?ML=E5=AE=9E=E4=BD=93=E8=BD=AC=E4=B9=89=EF=BC=9B=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E9=94=99=E8=AF=AF=E7=9F=AD=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/reply/widgets/reply_item.dart | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 48503d30..2867474e 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -540,20 +540,6 @@ InlineSpan buildContent( // replyReply 查看二楼回复(回复详情)回调 // fReplyItem 父级回复内容,用作二楼回复(回复详情)展示 final content = replyItem.content; - if (content.emote.isEmpty && - content.atNameToMid.isEmpty && - content.jumpUrl.isEmpty && - content.vote.isEmpty && - content.pictures.isEmpty && - content.message.isNotEmpty && - !RegExp(r'\b[0-9]{1,2}[::][0-9]{2}\b').hasMatch(content.message)) { - return TextSpan( - text: content.message, - recognizer: TapGestureRecognizer() - ..onTap = - () => replyReply(replyItem.root == 0 ? replyItem : fReplyItem), - ); - } final List spanChilds = []; bool hasMatchMember = false; @@ -585,10 +571,13 @@ InlineSpan buildContent( }); } // content.message = content.message.replaceAll(RegExp(r"\{vote:.*?\}"), ' '); - if (content.message.contains('&')) { - content.message = content.message.replaceAll('&', '&'); - } - print("content.jumpUrl.keys:" + content.jumpUrl.keys.toString()); + content.message = content.message.replaceAll('&', '&') + .replaceAll('<', '<') + .replaceAll('>', '>') + .replaceAll('"', '"') + .replaceAll(''', "'") + .replaceAll(' ', ' '); + // print("content.jumpUrl.keys:" + content.jumpUrl.keys.toString()); // 构建正则表达式 final List specialTokens = [ ...content.emote.keys, @@ -674,7 +663,7 @@ InlineSpan buildContent( ), ); } else { - print("matchStr=$matchStr"); + // print("matchStr=$matchStr"); String appUrlSchema = ''; final bool enableWordRe = setting.get(SettingBoxKey.enableWordRe, defaultValue: false) as bool; From 33f61ac0faca92f4932c9dda30a62660c5d96f8f Mon Sep 17 00:00:00 2001 From: orz12 Date: Fri, 2 Feb 2024 01:16:02 +0800 Subject: [PATCH 06/16] =?UTF-8?q?fix:=20=E6=9F=A5=E8=AF=A2=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E4=BA=BA=E6=95=B0=E9=94=99=E8=AF=AF=E6=97=B6=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=BF=94=E5=9B=9Estatus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/video.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/http/video.dart b/lib/http/video.dart index e7b09801..0e869512 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -433,6 +433,8 @@ class VideoHttp { }); if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; + } else { + return {'status': false, 'data': null, 'msg': res.data['message']}; } } From 5b1022628cd0d2c208da1c1db10e2bdfe9c6a053 Mon Sep 17 00:00:00 2001 From: orz12 Date: Fri, 2 Feb 2024 02:34:14 +0800 Subject: [PATCH 07/16] =?UTF-8?q?fix:=20=E4=B9=9D=E5=9B=BE=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BD=8D=E7=BD=AE=E6=97=A0=E6=B3=95=E7=82=B9=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/video/detail/reply/widgets/reply_item.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 2867474e..5e5a5828 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -743,10 +743,10 @@ InlineSpan buildContent( if (content.pictures.isNotEmpty) { final List picList = []; final int len = content.pictures.length; + spanChilds.add(const TextSpan(text: '\n')); if (len == 1) { Map pictureItem = content.pictures.first; picList.add(pictureItem['img_src']); - spanChilds.add(const TextSpan(text: '\n')); spanChilds.add( WidgetSpan( child: LayoutBuilder( From eb1e2ca5f4920c025f9b39976659a9c327a52f27 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Fri, 2 Feb 2024 23:24:36 +0800 Subject: [PATCH 08/16] =?UTF-8?q?fix:=20=E4=B8=AA=E4=BA=BA=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E6=97=A0=E6=B3=95=E8=B7=B3=E8=BD=AC=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/mine/view.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pages/mine/view.dart b/lib/pages/mine/view.dart index 06c375da..091b2149 100644 --- a/lib/pages/mine/view.dart +++ b/lib/pages/mine/view.dart @@ -64,7 +64,7 @@ class _MinePageState extends State { ), ), IconButton( - onPressed: () => Get.toNamed('/setting'), + onPressed: () => Get.toNamed('/setting', preventDuplicates: false), icon: const Icon( CupertinoIcons.slider_horizontal_3, ), From 1da84508d8f6b6fb7e5060e9972e97c6915f0464 Mon Sep 17 00:00:00 2001 From: orz12 Date: Sat, 3 Feb 2024 00:22:58 +0800 Subject: [PATCH 09/16] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E5=9B=9E=E5=A4=8D=E7=A7=81=E4=BF=A1=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../whisper_detail/widget/chat_item.dart | 164 +++++++++++++++++- 1 file changed, 162 insertions(+), 2 deletions(-) diff --git a/lib/pages/whisper_detail/widget/chat_item.dart b/lib/pages/whisper_detail/widget/chat_item.dart index 41df23ab..0925d569 100644 --- a/lib/pages/whisper_detail/widget/chat_item.dart +++ b/lib/pages/whisper_detail/widget/chat_item.dart @@ -27,6 +27,7 @@ enum MsgType { article_card(value: 12, label: "专栏卡片"), pic_card(value: 13, label: "图片卡片"), common_share(value: 14, label: "异形卡片"), + auto_reply_push(value: 16, label: "自动回复推送"), notify_text(value: 18, label: "文本提示"); final int value; @@ -59,8 +60,10 @@ class ChatItem extends StatelessWidget { // bool isArticle = item.msgType == 12; // 专栏 bool isRevoke = item.msgType == MsgType.revoke.value; // 撤回消息 bool isShareV2 = item.msgType == MsgType.share_v2.value; - bool isSystem = - item.msgType == 18 || item.msgType == 10 || item.msgType == 13; + bool isSystem = item.msgType == MsgType.notify_text.value || + item.msgType == MsgType.notify_msg.value || + item.msgType == MsgType.pic_card.value || + item.msgType == MsgType.auto_reply_push.value; dynamic content = item.content ?? ''; Color textColor(BuildContext context) { return isOwner @@ -190,6 +193,163 @@ class ChatItem extends StatelessWidget { ), ], ); + case MsgType.archive_card: + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + GestureDetector( + onTap: () async { + SmartDialog.showLoading(); + var bvid = content["bvid"]; + final int cid = await SearchHttp.ab2c(bvid: bvid); + final String heroTag = Utils.makeHeroTag(bvid); + SmartDialog.dismiss().then( + (e) => Get.toNamed('/video?bvid=$bvid&cid=$cid', + arguments: { + 'pic': content['thumb'], + 'heroTag': heroTag, + }), + ); + }, + child: NetworkImgLayer( + width: 220, + height: 220 * 9 / 16, + src: content['cover'], + ), + ), + const SizedBox(height: 6), + Text( + content['title'], + style: TextStyle( + letterSpacing: 0.6, + height: 1.5, + color: textColor(context), + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 1), + Text( + Utils.timeFormat(content['times']), + style: TextStyle( + letterSpacing: 0.6, + height: 1.5, + color: textColor(context).withOpacity(0.6), + fontSize: 12, + ), + ), + ], + ); + case MsgType.auto_reply_push: + return Container( + constraints: const BoxConstraints( + maxWidth: 300.0, // 设置最大宽度为200.0 + ), + decoration: BoxDecoration( + color: Theme.of(context) + .colorScheme + .secondaryContainer + .withOpacity(0.4), + borderRadius: const BorderRadius.only( + topLeft: Radius.circular(16), + topRight: Radius.circular(16), + bottomLeft: Radius.circular(6), + bottomRight: Radius.circular(16), + ), + ), + margin: const EdgeInsets.all(12), + padding: const EdgeInsets.all(12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + content['main_title'], + style: TextStyle( + letterSpacing: 0.6, + height: 1.5, + color: textColor(context), + fontWeight: FontWeight.bold, + ), + ), + for (var i in content['sub_cards']) ...[ + const SizedBox(height: 6), + GestureDetector( + onTap: () async { + RegExp bvRegex = RegExp(r'BV[0-9A-Za-z]{10}', + caseSensitive: false); + Iterable matches = + bvRegex.allMatches(i['jump_url']); + if (matches.isNotEmpty) { + Match match = matches.first; + String bvid = match.group(0)!; + try { + SmartDialog.showLoading(); + final int cid = await SearchHttp.ab2c(bvid: bvid); + final String heroTag = Utils.makeHeroTag(bvid); + SmartDialog.dismiss().then( + (e) => Get.toNamed( + '/video?bvid=$bvid&cid=$cid', + arguments: { + 'pic': i['cover_url'], + 'heroTag': heroTag, + }), + ); + } catch (err) { + SmartDialog.dismiss(); + SmartDialog.showToast(err.toString()); + } + } else { + SmartDialog.showToast('未匹配到 BV 号'); + Get.toNamed('/webview', + arguments: {'url': i['jump_url']}); + } + }, + child: Row( + children: [ + NetworkImgLayer( + width: 130, + height: 130 * 9 / 16, + src: i['cover_url'], + ), + const SizedBox(width: 6), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + i['field1'], + maxLines: 2, + style: TextStyle( + letterSpacing: 0.6, + height: 1.5, + color: textColor(context), + fontWeight: FontWeight.bold, + ), + ), + Text( + i['field2'], + style: TextStyle( + letterSpacing: 0.6, + height: 1.5, + color: textColor(context).withOpacity(0.6), + fontSize: 12, + ), + ), + Text( + Utils.timeFormat(int.parse(i['field3'])), + style: TextStyle( + letterSpacing: 0.6, + height: 1.5, + color: textColor(context).withOpacity(0.6), + fontSize: 12, + ), + ), + ], + )), + ], + )), + ], + ], + )); default: return Text( content['content'] ?? content.toString(), From b5315998938faf3047849c44dde3b9e8cb97e79a Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 3 Feb 2024 00:29:47 +0800 Subject: [PATCH 10/16] =?UTF-8?q?mod:=20floating=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pubspec.lock | 9 +++++---- pubspec.yaml | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index d9b6a01d..f5d63ca9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -500,10 +500,11 @@ packages: floating: dependency: "direct main" description: - name: floating - sha256: d9d563089e34fbd714ffdcdd2df447ec41b40c9226dacae6b4f78847aef8b991 - url: "https://pub.flutter-io.cn" - source: hosted + path: "." + ref: main + resolved-ref: d2d8421c4d80f6113f832404109853684721e11a + url: "https://github.com/guozhigq/floating.git" + source: git version: "2.0.1" flutter: dependency: "direct main" diff --git a/pubspec.yaml b/pubspec.yaml index f4b8fe61..16df4ad7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -124,7 +124,10 @@ dependencies: # 代理 system_proxy: ^0.1.0 # pip - floating: ^2.0.1 + floating: + git: + url: https://github.com/guozhigq/floating.git + ref: main # html解析 html: ^0.15.4 # html渲染 From 045186b3c8370e1f4da0280959834b44023762e8 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 3 Feb 2024 00:33:29 +0800 Subject: [PATCH 11/16] =?UTF-8?q?mod:=20=E8=A7=86=E9=A2=91=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E5=93=8D=E5=BA=94status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/video.dart | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/http/video.dart b/lib/http/video.dart index 0e869512..6ffbde21 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -361,7 +361,7 @@ class VideoHttp { if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; } else { - return {'status': true, 'data': []}; + return {'status': false, 'data': []}; } } @@ -377,7 +377,7 @@ class VideoHttp { if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; } else { - return {'status': true, 'data': []}; + return {'status': false, 'data': []}; } } @@ -455,10 +455,7 @@ class VideoHttp { 'data': AiConclusionModel.fromJson(res.data['data']), }; } else { - return { - 'status': false, - 'data': [] - }; + return {'status': false, 'data': []}; } } } From 18bb58d293ed48bf84f5590d540ec92328b35142 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 3 Feb 2024 00:43:38 +0800 Subject: [PATCH 12/16] =?UTF-8?q?mod:=20=E6=8A=95=E5=B8=81=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=93=8D=E5=BA=94status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/video.dart | 3 ++- lib/pages/video/detail/introduction/controller.dart | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/http/video.dart b/lib/http/video.dart index 6ffbde21..eaa131f3 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -224,10 +224,11 @@ class VideoHttp { // 获取投币状态 static Future hasCoinVideo({required String bvid}) async { var res = await Request().get(Api.hasCoinVideo, data: {'bvid': bvid}); + print('res: $res'); if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; } else { - return {'status': true, 'data': []}; + return {'status': false, 'data': []}; } } diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index 1deadb07..b1b02420 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -148,7 +148,9 @@ class VideoIntroController extends GetxController { // 获取投币状态 Future queryHasCoinVideo() async { var result = await VideoHttp.hasCoinVideo(bvid: bvid); - hasCoin.value = result["data"]['multiply'] == 0 ? false : true; + if (result['status']) { + hasCoin.value = result["data"]['multiply'] == 0 ? false : true; + } } // 获取收藏状态 From 6a844da259cb707696282fe398f80289891da4fc Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 3 Feb 2024 00:53:18 +0800 Subject: [PATCH 13/16] =?UTF-8?q?mod:=20=E7=82=B9=E8=B5=9E=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=99=BB=E5=BD=95=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/video/detail/introduction/controller.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index b1b02420..d1298fcc 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -210,6 +210,10 @@ class VideoIntroController extends GetxController { // (取消)点赞 Future actionLikeVideo() async { + if (userInfo == null) { + SmartDialog.showToast('账号未登录'); + return; + } var result = await VideoHttp.likeVideo(bvid: bvid, type: !hasLike.value); if (result['status']) { // hasLike.value = result["data"] == 1 ? true : false; From 47bdfec8c2c3446f178861002bb10e2da6493067 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 3 Feb 2024 01:07:12 +0800 Subject: [PATCH 14/16] fix: github assets null error --- lib/models/github/latest.dart | 5 +++-- lib/utils/utils.dart | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/models/github/latest.dart b/lib/models/github/latest.dart index 8730a4ba..c4b88b63 100644 --- a/lib/models/github/latest.dart +++ b/lib/models/github/latest.dart @@ -17,8 +17,9 @@ class LatestDataModel { url = json['url']; tagName = json['tag_name']; createdAt = json['created_at']; - assets = - json['assets'].map((e) => AssetItem.fromJson(e)).toList(); + assets = json['assets'] != null + ? json['assets'].map((e) => AssetItem.fromJson(e)).toList() + : []; body = json['body']; } } diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 08693d24..e17ed5ef 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -276,16 +276,18 @@ class Utils { // [arm64-v8a] String abi = androidInfo.supportedAbis.first; late String downloadUrl; - for (var i in data.assets) { - if (i.downloadUrl.contains(abi)) { - downloadUrl = i.downloadUrl; + if (data.assets.isNotEmpty) { + for (var i in data.assets) { + if (i.downloadUrl.contains(abi)) { + downloadUrl = i.downloadUrl; + } } + // 应用外下载 + launchUrl( + Uri.parse(downloadUrl), + mode: LaunchMode.externalApplication, + ); } - // 应用外下载 - launchUrl( - Uri.parse(downloadUrl), - mode: LaunchMode.externalApplication, - ); } } From 230dd813427e692151cdf9bb8dc8b719dcc6d9d8 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 3 Feb 2024 01:13:36 +0800 Subject: [PATCH 15/16] =?UTF-8?q?fix:=20List=20=E8=B6=8A=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/services/audio_handler.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/audio_handler.dart b/lib/services/audio_handler.dart index 61b32b96..ad510e7d 100644 --- a/lib/services/audio_handler.dart +++ b/lib/services/audio_handler.dart @@ -147,8 +147,8 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { processingState: AudioProcessingState.idle, playing: false, )); - _item.removeLast(); if (_item.isNotEmpty) { + _item.removeLast(); setMediaItem(_item.last); } if (_item.isEmpty) { From 387c799de1d86a580d750bf67beb256e87c72134 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 3 Feb 2024 16:59:54 +0800 Subject: [PATCH 16/16] =?UTF-8?q?feat:=20=E5=8A=A8=E6=80=81=E6=9C=AA?= =?UTF-8?q?=E8=AF=BB=E6=A0=87=E8=AE=B0=20issues=20#459?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/common/dynamic_badge_mode.dart | 9 +++++ lib/pages/main/controller.dart | 9 ++++- lib/pages/main/view.dart | 41 +++++++++++++++++------ lib/pages/setting/controller.dart | 34 +++++++++++++++++++ lib/pages/setting/style_setting.dart | 9 +++++ lib/utils/storage.dart | 3 +- 6 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 lib/models/common/dynamic_badge_mode.dart diff --git a/lib/models/common/dynamic_badge_mode.dart b/lib/models/common/dynamic_badge_mode.dart new file mode 100644 index 00000000..2609c5e2 --- /dev/null +++ b/lib/models/common/dynamic_badge_mode.dart @@ -0,0 +1,9 @@ +enum DynamicBadgeMode { hidden, point, number } + +extension DynamicBadgeModeDesc on DynamicBadgeMode { + String get description => ['隐藏', '红点', '数字'][index]; +} + +extension DynamicBadgeModeCode on DynamicBadgeMode { + int get code => [0, 1, 2][index]; +} diff --git a/lib/pages/main/controller.dart b/lib/pages/main/controller.dart index a55c143e..6f33d9cd 100644 --- a/lib/pages/main/controller.dart +++ b/lib/pages/main/controller.dart @@ -11,6 +11,7 @@ import 'package:pilipala/pages/home/view.dart'; import 'package:pilipala/pages/media/index.dart'; import 'package:pilipala/utils/storage.dart'; import 'package:pilipala/utils/utils.dart'; +import '../../models/common/dynamic_badge_mode.dart'; class MainController extends GetxController { List pages = [ @@ -65,6 +66,7 @@ class MainController extends GetxController { int selectedIndex = 0; Box userInfoCache = GStrorage.userInfo; RxBool userLogin = false.obs; + late Rx dynamicBadgeType = DynamicBadgeMode.number.obs; @override void onInit() { @@ -75,7 +77,12 @@ class MainController extends GetxController { hideTabBar = setting.get(SettingBoxKey.hideTabBar, defaultValue: true); var userInfo = userInfoCache.get('userInfoCache'); userLogin.value = userInfo != null; - getUnreadDynamic(); + dynamicBadgeType.value = DynamicBadgeMode.values[setting.get( + SettingBoxKey.dynamicBadgeMode, + defaultValue: DynamicBadgeMode.number.code)]; + if (dynamicBadgeType.value != DynamicBadgeMode.hidden) { + getUnreadDynamic(); + } } void onBackPressed(BuildContext context) { diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 5a570a8f..04e0f087 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; +import 'package:pilipala/models/common/dynamic_badge_mode.dart'; import 'package:pilipala/pages/dynamics/index.dart'; import 'package:pilipala/pages/home/index.dart'; import 'package:pilipala/pages/media/index.dart'; @@ -127,11 +128,21 @@ class _MainAppState extends State with SingleTickerProviderStateMixin { destinations: [ ..._mainController.navigationBars.map((e) { return NavigationDestination( - icon: Badge( - label: Text(e['count'].toString()), - padding: const EdgeInsets.fromLTRB(6, 0, 6, 0), - isLabelVisible: e['count'] > 0, - child: e['icon'], + icon: Obx( + () => Badge( + label: + _mainController.dynamicBadgeType.value == + DynamicBadgeMode.number + ? Text(e['count'].toString()) + : null, + padding: + const EdgeInsets.fromLTRB(6, 0, 6, 0), + isLabelVisible: + _mainController.dynamicBadgeType.value != + DynamicBadgeMode.hidden && + e['count'] > 0, + child: e['icon'], + ), ), selectedIcon: e['selectIcon'], label: e['label'], @@ -148,11 +159,21 @@ class _MainAppState extends State with SingleTickerProviderStateMixin { items: [ ..._mainController.navigationBars.map((e) { return BottomNavigationBarItem( - icon: Badge( - label: Text(e['count'].toString()), - padding: const EdgeInsets.fromLTRB(6, 0, 6, 0), - isLabelVisible: e['count'] > 0, - child: e['icon'], + icon: Obx( + () => Badge( + label: + _mainController.dynamicBadgeType.value == + DynamicBadgeMode.number + ? Text(e['count'].toString()) + : null, + padding: + const EdgeInsets.fromLTRB(6, 0, 6, 0), + isLabelVisible: + _mainController.dynamicBadgeType.value != + DynamicBadgeMode.hidden && + e['count'] > 0, + child: e['icon'], + ), ), activeIcon: e['selectIcon'], label: e['label'], diff --git a/lib/pages/setting/controller.dart b/lib/pages/setting/controller.dart index afd14156..2e6680e5 100644 --- a/lib/pages/setting/controller.dart +++ b/lib/pages/setting/controller.dart @@ -7,6 +7,9 @@ import 'package:pilipala/models/common/theme_type.dart'; import 'package:pilipala/utils/feed_back.dart'; import 'package:pilipala/utils/login.dart'; import 'package:pilipala/utils/storage.dart'; +import '../../models/common/dynamic_badge_mode.dart'; +import '../main/index.dart'; +import 'widgets/select_dialog.dart'; class SettingController extends GetxController { Box userInfoCache = GStrorage.userInfo; @@ -19,6 +22,7 @@ class SettingController extends GetxController { RxInt picQuality = 10.obs; Rx themeType = ThemeType.system.obs; var userInfo; + Rx dynamicBadgeType = DynamicBadgeMode.number.obs; @override void onInit() { @@ -33,6 +37,9 @@ class SettingController extends GetxController { setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); themeType.value = ThemeType.values[setting.get(SettingBoxKey.themeMode, defaultValue: ThemeType.system.code)]; + dynamicBadgeType.value = DynamicBadgeMode.values[setting.get( + SettingBoxKey.dynamicBadgeMode, + defaultValue: DynamicBadgeMode.number.code)]; } loginOut() async { @@ -76,4 +83,31 @@ class SettingController extends GetxController { feedBackEnable.value = !feedBackEnable.value; setting.put(SettingBoxKey.feedBackEnable, feedBackEnable.value); } + + // 设置动态未读标记 + setDynamicBadgeMode(BuildContext context) async { + DynamicBadgeMode? result = await showDialog( + context: context, + builder: (context) { + return SelectDialog( + title: '动态未读标记', + value: dynamicBadgeType.value, + values: DynamicBadgeMode.values.map((e) { + return {'title': e.description, 'value': e}; + }).toList(), + ); + }, + ); + if (result != null) { + dynamicBadgeType.value = result; + setting.put(SettingBoxKey.dynamicBadgeMode, result.code); + MainController mainController = Get.put(MainController()); + mainController.dynamicBadgeType.value = + DynamicBadgeMode.values[result.code]; + if (mainController.dynamicBadgeType.value != DynamicBadgeMode.hidden) { + mainController.getUnreadDynamic(); + } + SmartDialog.showToast('设置成功'); + } + } } diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index 57ec110a..fb3c780a 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -10,6 +10,7 @@ import 'package:pilipala/pages/setting/widgets/select_dialog.dart'; import 'package:pilipala/pages/setting/widgets/slide_dialog.dart'; import 'package:pilipala/utils/storage.dart'; +import '../../models/common/dynamic_badge_mode.dart'; import 'controller.dart'; import 'widgets/switch_item.dart'; @@ -241,6 +242,14 @@ class _StyleSettingState extends State { '当前模式:${settingController.themeType.value.description}', style: subTitleStyle)), ), + ListTile( + dense: false, + onTap: () => settingController.setDynamicBadgeMode(context), + title: Text('动态未读标记', style: titleStyle), + subtitle: Obx(() => Text( + '当前标记样式:${settingController.dynamicBadgeType.value.description}', + style: subTitleStyle)), + ), ListTile( dense: false, onTap: () => Get.toNamed('/colorSetting'), diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index d408cc1c..89dae3e7 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -130,7 +130,8 @@ class SettingBoxKey { enableMYBar = 'enableMYBar', hideSearchBar = 'hideSearchBar', // 收起顶栏 hideTabBar = 'hideTabBar', // 收起底栏 - tabbarSort = 'tabbarSort'; // 首页tabbar + tabbarSort = 'tabbarSort', // 首页tabbar + dynamicBadgeMode = 'dynamicBadgeMode'; } class LocalCacheKey {