mod: jumpUrl增加icon显示 issues #471

This commit is contained in:
guozhigq
2024-02-04 22:06:45 +08:00
parent 3de009ac43
commit 80b39daaff

View File

@ -571,7 +571,8 @@ InlineSpan buildContent(
}); });
} }
// content.message = content.message.replaceAll(RegExp(r"\{vote:.*?\}"), ' '); // content.message = content.message.replaceAll(RegExp(r"\{vote:.*?\}"), ' ');
content.message = content.message.replaceAll('&', '&') content.message = content.message
.replaceAll('&', '&')
.replaceAll('&lt;', '<') .replaceAll('&lt;', '<')
.replaceAll('&gt;', '>') .replaceAll('&gt;', '>')
.replaceAll('&quot;', '"') .replaceAll('&quot;', '"')
@ -586,21 +587,21 @@ InlineSpan buildContent(
e.replaceAll('?', '\\?').replaceAll('+', '\\+').replaceAll('*', '\\*')), e.replaceAll('?', '\\?').replaceAll('+', '\\+').replaceAll('*', '\\*')),
]; ];
String patternStr = String patternStr = specialTokens.map(RegExp.escape).join('|');
specialTokens.map(RegExp.escape).join('|');
if (patternStr.isNotEmpty) { if (patternStr.isNotEmpty) {
patternStr += "|"; patternStr += "|";
} }
patternStr += r'(\b\d{1,2}[:]\d{2}\b)'; patternStr += r'(\b\d{1,2}[:]\d{2}\b)';
final RegExp pattern = RegExp(patternStr); final RegExp pattern = RegExp(patternStr);
List<String> matchedStrs = []; List<String> matchedStrs = [];
void addPlainTextSpan(str){ void addPlainTextSpan(str) {
spanChilds.add(TextSpan( spanChilds.add(TextSpan(
text: str, text: str,
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () => ..onTap =
replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); () => replyReply(replyItem.root == 0 ? replyItem : fReplyItem)));
} }
// 分割文本并处理每个部分 // 分割文本并处理每个部分
content.message.splitMapJoin( content.message.splitMapJoin(
pattern, pattern,
@ -674,57 +675,56 @@ InlineSpan buildContent(
addPlainTextSpan(matchStr); addPlainTextSpan(matchStr);
return ""; return "";
} }
spanChilds.add( spanChilds.addAll(
TextSpan( [
text: content.jumpUrl[matchStr]['title'], if (content.jumpUrl[matchStr]?['prefix_icon'] != null) ...[
style: TextStyle( WidgetSpan(
color: Theme.of(context).colorScheme.primary, child: Image.network(
), content.jumpUrl[matchStr]['prefix_icon'],
recognizer: TapGestureRecognizer() height: 19,
..onTap = () { color: Theme.of(context).colorScheme.primary,
if (appUrlSchema == '') { ),
final String str = Uri.parse(matchStr).pathSegments[0]; )
final Map matchRes = IdUtils.matchAvorBv(input: str); ],
final List matchKeys = matchRes.keys.toList(); TextSpan(
if (matchKeys.isNotEmpty) { text: content.jumpUrl[matchStr]['title'],
if (matchKeys.first == 'BV') { 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( Get.toNamed(
'/searchResult', '/webview',
parameters: {'keyword': matchRes['BV']}, parameters: {
'url': matchStr,
'type': 'url',
'pageTitle': ''
},
); );
} }
} else { } else {
Get.toNamed( if (appUrlSchema.startsWith('bilibili://search')) {
'/webview', Get.toNamed('/searchResult', parameters: {
parameters: { 'keyword': content.jumpUrl[matchStr]['title']
'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')) {
spanChilds.add(
WidgetSpan(
child: Icon(
FontAwesomeIcons.magnifyingGlass,
size: 9,
color: Theme.of(context).colorScheme.primary,
),
alignment: PlaceholderAlignment.top,
),
);
}
// 只显示一次 // 只显示一次
matchedStrs.add(matchStr); matchedStrs.add(matchStr);
} else { } else {