feat: at user

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-06-24 21:01:30 +08:00
parent fcf758e290
commit 7be3774675
35 changed files with 14468 additions and 207 deletions

View File

@@ -945,7 +945,7 @@ class VideoDetailController extends GetxController
bvid: bvid,
progress: plPlayerController.position.value.inMilliseconds,
initialValue: savedDanmaku,
onSave: (danmaku) => savedDanmaku = danmaku,
onSave: (danmaku) => savedDanmaku = danmaku.text,
callback: (danmakuModel) {
savedDanmaku = null;
plPlayerController.danmakuController?.addDanmaku(danmakuModel);

View File

@@ -229,7 +229,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
onDismissed: widget.onDismissed,
callback: widget.callback,
onCheckReply: (item) => _videoReplyController
.onCheckReply(context, item, isManual: true),
.onCheckReply(item, isManual: true),
onToggleTop: (item) => _videoReplyController.onToggleTop(
item,
index,

View File

@@ -1,15 +1,17 @@
import 'dart:async';
import 'package:PiliPlus/common/widgets/button/toolbar_icon_button.dart';
import 'package:PiliPlus/common/widgets/text_field/text_field.dart';
import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
show ReplyInfo;
import 'package:PiliPlus/http/video.dart';
import 'package:PiliPlus/main.dart';
import 'package:PiliPlus/models/common/publish_panel_type.dart';
import 'package:PiliPlus/pages/common/common_publish_page.dart';
import 'package:PiliPlus/pages/dynamics_mention/controller.dart';
import 'package:PiliPlus/pages/emote/view.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' hide TextField;
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
@@ -24,6 +26,7 @@ class ReplyPage extends CommonPublishPage {
const ReplyPage({
super.key,
super.initialValue,
super.mentions,
super.imageLengthLimit,
super.onSave,
required this.oid,
@@ -66,6 +69,12 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
),
);
@override
void dispose() {
Get.delete<DynMentionController>();
super.dispose();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
@@ -141,7 +150,7 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
} else if (isEmpty && enablePublish.value) {
enablePublish.value = false;
}
widget.onSave?.call(value);
widget.onSave?.call((text: value, mentions: mentions));
},
focusNode: focusNode,
decoration: InputDecoration(
@@ -150,6 +159,7 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
hintStyle: const TextStyle(fontSize: 14),
),
style: themeData.textTheme.bodyLarge,
onMention: onMention,
),
),
),
@@ -163,7 +173,6 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
height: 52,
padding: const EdgeInsets.only(left: 12, right: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Obx(
() => ToolbarIconButton(
@@ -177,7 +186,7 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
selected: panelType.value == PanelType.keyboard,
),
),
const SizedBox(width: 10),
const SizedBox(width: 8),
Obx(
() => ToolbarIconButton(
tooltip: '表情',
@@ -191,7 +200,7 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
),
),
if (widget.root == 0) ...[
const SizedBox(width: 10),
const SizedBox(width: 8),
ToolbarIconButton(
tooltip: '图片',
selected: false,
@@ -199,32 +208,56 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
onPressed: onPickImage,
),
],
const Spacer(),
Obx(
() => TextButton.icon(
style: TextButton.styleFrom(
padding:
const EdgeInsets.symmetric(horizontal: 15, vertical: 13),
visualDensity: VisualDensity.compact,
foregroundColor: _syncToDynamic.value
? themeData.colorScheme.secondary
: themeData.colorScheme.outline,
const SizedBox(width: 8),
ToolbarIconButton(
onPressed: () => onMention(true),
icon: const Icon(Icons.alternate_email, size: 22),
tooltip: '@',
selected: false,
),
Expanded(
child: Center(
child: Obx(
() => TextButton(
style: TextButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: const EdgeInsets.all(13),
visualDensity: VisualDensity.compact,
foregroundColor: _syncToDynamic.value
? themeData.colorScheme.secondary
: themeData.colorScheme.outline,
),
onPressed: () =>
_syncToDynamic.value = !_syncToDynamic.value,
child: Row(
spacing: 4,
mainAxisSize: MainAxisSize.min,
children: [
Icon(
_syncToDynamic.value
? Icons.check_box
: Icons.check_box_outline_blank,
size: 22,
),
const Flexible(
child: Text(
'转到动态',
maxLines: 1,
style: TextStyle(height: 1),
strutStyle: StrutStyle(leading: 0, height: 1),
),
),
],
),
),
),
onPressed: () => _syncToDynamic.value = !_syncToDynamic.value,
icon: Icon(
_syncToDynamic.value
? Icons.check_box
: Icons.check_box_outline_blank,
size: 22,
),
label: const Text('转发至动态'),
),
),
const Spacer(),
Obx(
() => FilledButton.tonal(
onPressed: enablePublish.value ? onPublish : null,
style: FilledButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
visualDensity: VisualDensity.compact,
@@ -249,6 +282,9 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
message: widget.replyItem != null && widget.replyItem!.root != 0
? ' 回复 @${widget.replyItem!.member.name} : $message'
: message,
atNameToMid: mentions?.isNotEmpty == true
? {for (var e in mentions!) e.name: e.uid}
: null,
pictures: pictures,
syncToDynamic: _syncToDynamic.value,
);

View File

@@ -3,10 +3,13 @@ import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
import 'package:PiliPlus/grpc/reply.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/pages/common/reply_controller.dart';
import 'package:PiliPlus/pages/video/reply_new/view.dart';
import 'package:PiliPlus/utils/id_utils.dart';
import 'package:PiliPlus/utils/request_utils.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/dialog/dialog_route.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
class VideoReplyReplyController extends ReplyController
@@ -129,6 +132,67 @@ class VideoReplyReplyController extends ReplyController
onReload();
}
@override
void onReply(
BuildContext context, {
int? oid,
ReplyInfo? replyItem,
int? replyType,
int? index,
}) {
assert(replyItem != null && index != null);
final oid = replyItem!.oid.toInt();
final root = replyItem.id.toInt();
final key = oid + root;
Navigator.of(context)
.push(
GetDialogRoute(
pageBuilder: (buildContext, animation, secondaryAnimation) {
final saved = savedReplies[key];
return ReplyPage(
oid: oid,
root: root,
parent: root,
replyType: this.replyType,
replyItem: replyItem,
initialValue: saved?.text,
mentions: saved?.mentions,
onSave: (reply) => savedReplies[key] = reply,
);
},
transitionDuration: const Duration(milliseconds: 500),
transitionBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0);
const end = Offset.zero;
const curve = Curves.linear;
var tween =
Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
),
)
.then((res) {
if (res != null) {
savedReplies.remove(key);
ReplyInfo replyInfo = RequestUtils.replyCast(res);
count.value += 1;
loadingState
..value.dataOrNull?.insert(index! + 1, replyInfo)
..refresh();
if (enableCommAntifraud) {
onCheckReply(replyInfo, isManual: false);
}
}
});
}
@override
void onClose() {
controller?.dispose();

View File

@@ -6,15 +6,12 @@ import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/pages/common/common_slide_page.dart';
import 'package:PiliPlus/pages/video/reply/widgets/reply_item_grpc.dart';
import 'package:PiliPlus/pages/video/reply_new/view.dart';
import 'package:PiliPlus/pages/video/reply_reply/controller.dart';
import 'package:PiliPlus/utils/num_util.dart';
import 'package:PiliPlus/utils/page_utils.dart';
import 'package:PiliPlus/utils/request_utils.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/dialog/dialog_route.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
class VideoReplyReplyPanel extends CommonSlidePage {
@@ -51,27 +48,25 @@ class VideoReplyReplyPanel extends CommonSlidePage {
class _VideoReplyReplyPanelState
extends CommonSlidePageState<VideoReplyReplyPanel> {
late VideoReplyReplyController _videoReplyReplyController;
late final _savedReplies = <int, String>{};
late VideoReplyReplyController _controller;
late final itemPositionsListener = ItemPositionsListener.create();
late final _key = GlobalKey<ScaffoldState>();
late final _listKey = GlobalKey();
late final _tag =
Utils.makeHeroTag('${widget.rpid}${widget.dialog}${widget.isDialogue}');
ReplyInfo? get firstFloor =>
widget.firstFloor ?? _videoReplyReplyController.firstFloor;
ReplyInfo? get firstFloor => widget.firstFloor ?? _controller.firstFloor;
bool get _horizontalPreview =>
context.orientation == Orientation.landscape &&
_videoReplyReplyController.horizontalPreview;
_controller.horizontalPreview;
Animation<Color?>? colorAnimation;
@override
void initState() {
super.initState();
_videoReplyReplyController = Get.put(
_controller = Get.put(
VideoReplyReplyController(
hasRoot: widget.firstFloor != null,
id: widget.id,
@@ -159,7 +154,7 @@ class _VideoReplyReplyPanelState
Widget buildList(ThemeData theme) {
return ClipRect(
child: refreshIndicator(
onRefresh: _videoReplyReplyController.onRefresh,
onRefresh: _controller.onRefresh,
child: Obx(
() => Stack(
clipBehavior: Clip.none,
@@ -167,27 +162,27 @@ class _VideoReplyReplyPanelState
ScrollablePositionedList.builder(
key: _listKey,
itemPositionsListener: itemPositionsListener,
itemCount:
_itemCount(_videoReplyReplyController.loadingState.value),
itemScrollController: _videoReplyReplyController.itemScrollCtr,
itemCount: _itemCount(_controller.loadingState.value),
itemScrollController: _controller.itemScrollCtr,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
if (widget.isDialogue) {
return _buildBody(theme,
_videoReplyReplyController.loadingState.value, index);
return _buildBody(
theme, _controller.loadingState.value, index);
} else if (firstFloor != null) {
if (index == 0) {
return ReplyItemGrpc(
replyItem: firstFloor!,
replyLevel: 2,
needDivider: false,
onReply: (replyItem) => _onReply(replyItem, -1),
upMid: _videoReplyReplyController.upMid,
onReply: (replyItem) => _controller.onReply(context,
replyItem: replyItem, index: -1),
upMid: _controller.upMid,
onViewImage: widget.onViewImage,
onDismissed: widget.onDismissed,
callback: _getImageCallback,
onCheckReply: (item) => _videoReplyReplyController
.onCheckReply(context, item, isManual: true),
onCheckReply: (item) =>
_controller.onCheckReply(item, isManual: true),
);
} else if (index == 1) {
return Divider(
@@ -200,7 +195,7 @@ class _VideoReplyReplyPanelState
} else {
return _buildBody(
theme,
_videoReplyReplyController.loadingState.value,
_controller.loadingState.value,
index - 3,
);
}
@@ -210,7 +205,7 @@ class _VideoReplyReplyPanelState
} else {
return _buildBody(
theme,
_videoReplyReplyController.loadingState.value,
_controller.loadingState.value,
index - 1,
);
}
@@ -218,7 +213,7 @@ class _VideoReplyReplyPanelState
},
),
if (!widget.isDialogue &&
_videoReplyReplyController.loadingState.value.isSuccess)
_controller.loadingState.value.isSuccess)
_header(theme),
],
),
@@ -243,9 +238,9 @@ class _VideoReplyReplyPanelState
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Obx(
() => _videoReplyReplyController.count.value != -1
() => _controller.count.value != -1
? Text(
'相关回复共${NumUtil.numFormat(_videoReplyReplyController.count.value)}',
'相关回复共${NumUtil.numFormat(_controller.count.value)}',
style: const TextStyle(fontSize: 13),
)
: const SizedBox.shrink(),
@@ -253,7 +248,7 @@ class _VideoReplyReplyPanelState
SizedBox(
height: 35,
child: TextButton.icon(
onPressed: () => _videoReplyReplyController.queryBySort(),
onPressed: () => _controller.queryBySort(),
icon: Icon(
Icons.sort,
size: 16,
@@ -261,7 +256,7 @@ class _VideoReplyReplyPanelState
),
label: Obx(
() => Text(
_videoReplyReplyController.mode.value == Mode.MAIN_LIST_HOT
_controller.mode.value == Mode.MAIN_LIST_HOT
? '按热度'
: '按时间',
style: TextStyle(
@@ -306,59 +301,6 @@ class _VideoReplyReplyPanelState
}
: null;
void _onReply(ReplyInfo item, int index) {
final oid = item.oid.toInt();
final root = item.id.toInt();
final key = oid + root;
Navigator.of(context)
.push(
GetDialogRoute(
pageBuilder: (buildContext, animation, secondaryAnimation) {
return ReplyPage(
oid: oid,
root: root,
parent: root,
replyType: widget.replyType,
replyItem: item,
initialValue: _savedReplies[key],
onSave: (reply) {
_savedReplies[key] = reply;
},
);
},
transitionDuration: const Duration(milliseconds: 500),
transitionBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0);
const end = Offset.zero;
const curve = Curves.linear;
var tween =
Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
),
)
.then((res) {
if (res != null) {
_savedReplies.remove(key);
ReplyInfo replyInfo = RequestUtils.replyCast(res);
_videoReplyReplyController
..count.value += 1
..loadingState.value.dataOrNull?.insert(index + 1, replyInfo)
..loadingState.refresh();
if (_videoReplyReplyController.enableCommAntifraud && mounted) {
_videoReplyReplyController.onCheckReply(context, replyInfo,
isManual: false);
}
}
});
}
Widget _buildBody(
ThemeData theme, LoadingState<List<ReplyInfo>?> loadingState, int index) {
return switch (loadingState) {
@@ -375,14 +317,14 @@ class _VideoReplyReplyPanelState
Success(:var response) => Builder(
builder: (context) {
if (index == response!.length) {
_videoReplyReplyController.onLoadMore();
_controller.onLoadMore();
return Container(
alignment: Alignment.center,
margin: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom),
height: 125,
child: Text(
_videoReplyReplyController.isEnd ? '没有更多了' : '加载中...',
_controller.isEnd ? '没有更多了' : '加载中...',
style: TextStyle(
fontSize: 12,
color: theme.colorScheme.outline,
@@ -390,12 +332,11 @@ class _VideoReplyReplyPanelState
),
);
} else {
if (_videoReplyReplyController.index != null &&
_videoReplyReplyController.index == index) {
if (_controller.index != null && _controller.index == index) {
colorAnimation ??= ColorTween(
begin: theme.colorScheme.onInverseSurface,
end: theme.colorScheme.surface,
).animate(_videoReplyReplyController.controller!);
).animate(_controller.controller!);
return AnimatedBuilder(
animation: colorAnimation!,
builder: (context, child) {
@@ -413,7 +354,7 @@ class _VideoReplyReplyPanelState
),
Error(:var errMsg) => errorWidget(
errMsg: errMsg,
onReload: _videoReplyReplyController.onReload,
onReload: _controller.onReload,
),
};
}
@@ -422,11 +363,12 @@ class _VideoReplyReplyPanelState
return ReplyItemGrpc(
replyItem: replyItem,
replyLevel: widget.isDialogue ? 3 : 2,
onReply: (replyItem) => _onReply(replyItem, index),
onReply: (replyItem) =>
_controller.onReply(context, replyItem: replyItem, index: index),
onDelete: (item, subIndex) {
_videoReplyReplyController.onRemove(index, item, null);
_controller.onRemove(index, item, null);
},
upMid: _videoReplyReplyController.upMid,
upMid: _controller.upMid,
showDialogue: () => _key.currentState?.showBottomSheet(
backgroundColor: Colors.transparent,
(context) => VideoReplyReplyPanel(
@@ -441,8 +383,7 @@ class _VideoReplyReplyPanelState
onViewImage: widget.onViewImage,
onDismissed: widget.onDismissed,
callback: _getImageCallback,
onCheckReply: (item) => _videoReplyReplyController
.onCheckReply(context, item, isManual: true),
onCheckReply: (item) => _controller.onCheckReply(item, isManual: true),
);
}

View File

@@ -377,7 +377,7 @@ class _SendDanmakuPanelState extends CommonPublishPageState<SendDanmakuPanel> {
} else if (isEmpty && enablePublish.value) {
enablePublish.value = false;
}
widget.onSave?.call(value);
widget.onSave?.call((text: value, mentions: null));
},
textInputAction: TextInputAction.send,
onSubmitted: (value) {