mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-17 07:36:14 +08:00
opt: reply message
This commit is contained in:
@@ -246,18 +246,32 @@ class ReplyItem extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
// title
|
// title
|
||||||
Container(
|
Padding(
|
||||||
margin: const EdgeInsets.only(top: 10, left: 45, right: 6, bottom: 4),
|
padding:
|
||||||
child: Semantics(
|
const EdgeInsets.only(top: 10, left: 45, right: 6, bottom: 4),
|
||||||
label: replyItem?.content?.message ?? "",
|
child: LayoutBuilder(
|
||||||
// excludeSemantics: true,
|
builder: (BuildContext context, BoxConstraints constraints) {
|
||||||
|
String text = replyItem?.content?.message ?? '';
|
||||||
|
var textPainter = TextPainter(
|
||||||
|
text: TextSpan(text: text),
|
||||||
|
maxLines:
|
||||||
|
replyItem!.content!.isText! && replyLevel == '1' ? 6 : 999,
|
||||||
|
textDirection: Directionality.of(context),
|
||||||
|
)..layout(maxWidth: constraints.maxWidth);
|
||||||
|
bool didExceedMaxLines = textPainter.didExceedMaxLines;
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Semantics(
|
||||||
|
label: text,
|
||||||
child: Text.rich(
|
child: Text.rich(
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
height: 1.75,
|
height: 1.75,
|
||||||
fontSize: Theme.of(context).textTheme.bodyMedium!.fontSize),
|
fontSize: Theme.of(context)
|
||||||
maxLines:
|
.textTheme
|
||||||
replyItem!.content!.isText! && replyLevel == '1' ? 6 : 999,
|
.bodyMedium!
|
||||||
overflow: TextOverflow.ellipsis,
|
.fontSize),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
children: [
|
children: [
|
||||||
if (replyItem!.isTop!) ...[
|
if (replyItem!.isTop!) ...[
|
||||||
@@ -274,10 +288,28 @@ class ReplyItem extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const TextSpan(text: ' '),
|
const TextSpan(text: ' '),
|
||||||
],
|
],
|
||||||
buildContent(context, replyItem!, replyReply, null),
|
buildContent(
|
||||||
|
context,
|
||||||
|
replyItem!,
|
||||||
|
replyReply,
|
||||||
|
null,
|
||||||
|
textPainter,
|
||||||
|
didExceedMaxLines,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
|
if (didExceedMaxLines)
|
||||||
|
Text(
|
||||||
|
'查看更多',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
// 操作区域
|
// 操作区域
|
||||||
buttonAction(context, replyItem!.replyControl),
|
buttonAction(context, replyItem!.replyControl),
|
||||||
@@ -488,10 +520,13 @@ class ReplyItemRow extends StatelessWidget {
|
|||||||
replies![i],
|
replies![i],
|
||||||
replyReply,
|
replyReply,
|
||||||
replyItem,
|
replyItem,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@@ -539,7 +574,13 @@ class ReplyItemRow extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InlineSpan buildContent(
|
InlineSpan buildContent(
|
||||||
BuildContext context, replyItem, replyReply, fReplyItem) {
|
BuildContext context,
|
||||||
|
replyItem,
|
||||||
|
replyReply,
|
||||||
|
fReplyItem,
|
||||||
|
textPainter,
|
||||||
|
didExceedMaxLines,
|
||||||
|
) {
|
||||||
final String routePath = Get.currentRoute;
|
final String routePath = Get.currentRoute;
|
||||||
bool isVideoPage = routePath.startsWith('/video');
|
bool isVideoPage = routePath.startsWith('/video');
|
||||||
|
|
||||||
@@ -547,12 +588,24 @@ InlineSpan buildContent(
|
|||||||
// replyReply 查看二楼回复(回复详情)回调
|
// replyReply 查看二楼回复(回复详情)回调
|
||||||
// fReplyItem 父级回复内容,用作二楼回复(回复详情)展示
|
// fReplyItem 父级回复内容,用作二楼回复(回复详情)展示
|
||||||
final content = replyItem.content;
|
final content = replyItem.content;
|
||||||
|
String message = content.message ?? '';
|
||||||
final List<InlineSpan> spanChildren = <InlineSpan>[];
|
final List<InlineSpan> spanChildren = <InlineSpan>[];
|
||||||
|
|
||||||
|
if (didExceedMaxLines == true) {
|
||||||
|
final textSize = textPainter.size;
|
||||||
|
var position = textPainter.getPositionForOffset(
|
||||||
|
Offset(
|
||||||
|
textSize.width,
|
||||||
|
textSize.height,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final endOffset = textPainter.getOffsetBefore(position.offset);
|
||||||
|
message = message.substring(0, endOffset);
|
||||||
|
}
|
||||||
|
|
||||||
// 投票
|
// 投票
|
||||||
if (content.vote.isNotEmpty) {
|
if (content.vote.isNotEmpty) {
|
||||||
content.message.splitMapJoin(RegExp(r"\{vote:\d+?\}"),
|
message.splitMapJoin(RegExp(r"\{vote:\d+?\}"), onMatch: (Match match) {
|
||||||
onMatch: (Match match) {
|
|
||||||
// String matchStr = match[0]!;
|
// String matchStr = match[0]!;
|
||||||
spanChildren.add(
|
spanChildren.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
@@ -575,9 +628,9 @@ InlineSpan buildContent(
|
|||||||
}, onNonMatch: (String str) {
|
}, onNonMatch: (String str) {
|
||||||
return str;
|
return str;
|
||||||
});
|
});
|
||||||
content.message = content.message.replaceAll(RegExp(r"\{vote:\d+?\}"), "");
|
message = message.replaceAll(RegExp(r"\{vote:\d+?\}"), "");
|
||||||
}
|
}
|
||||||
content.message = content.message
|
message = message
|
||||||
.replaceAll('&', '&')
|
.replaceAll('&', '&')
|
||||||
.replaceAll('<', '<')
|
.replaceAll('<', '<')
|
||||||
.replaceAll('>', '>')
|
.replaceAll('>', '>')
|
||||||
@@ -618,7 +671,7 @@ InlineSpan buildContent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分割文本并处理每个部分
|
// 分割文本并处理每个部分
|
||||||
content.message.splitMapJoin(
|
message.splitMapJoin(
|
||||||
pattern,
|
pattern,
|
||||||
onMatch: (Match match) {
|
onMatch: (Match match) {
|
||||||
String matchStr = match[0]!;
|
String matchStr = match[0]!;
|
||||||
@@ -835,7 +888,7 @@ InlineSpan buildContent(
|
|||||||
if (content.jumpUrl.keys.isNotEmpty) {
|
if (content.jumpUrl.keys.isNotEmpty) {
|
||||||
List<String> unmatchedItems = content.jumpUrl.keys
|
List<String> unmatchedItems = content.jumpUrl.keys
|
||||||
.toList()
|
.toList()
|
||||||
.where((item) => !content.message.contains(item))
|
.where((item) => !message.contains(item))
|
||||||
.toList();
|
.toList();
|
||||||
if (unmatchedItems.isNotEmpty) {
|
if (unmatchedItems.isNotEmpty) {
|
||||||
for (int i = 0; i < unmatchedItems.length; i++) {
|
for (int i = 0; i < unmatchedItems.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user