feat: custom grpc reply (#25)

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-11-29 22:03:02 +08:00
committed by GitHub
parent 9b9e28dcb8
commit be4dfd99c6
28 changed files with 637 additions and 400 deletions

View File

@@ -1,7 +1,9 @@
import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/models/common/reply_type.dart';
import 'package:PiliPalaX/pages/common/reply_controller.dart';
import 'package:PiliPalaX/http/reply.dart';
import 'package:PiliPalaX/utils/global_data.dart';
import 'package:fixnum/fixnum.dart' as $fixnum;
class VideoReplyController extends ReplyController {
@@ -18,11 +20,20 @@ class VideoReplyController extends ReplyController {
String? rpid;
@override
Future<LoadingState> customGetData() => ReplyHttp.replyListGrpc(
oid: aid!,
cursor: CursorReq(
next: cursor?.next ?? $fixnum.Int64(0),
mode: mode,
),
);
Future<LoadingState> customGetData() => GlobalData().grpcReply
? ReplyHttp.replyListGrpc(
oid: aid!,
cursor: CursorReq(
next: cursor?.next ?? $fixnum.Int64(0),
mode: mode,
),
)
: ReplyHttp.replyList(
isLogin: isLogin,
oid: aid!,
nextOffset: nextOffset,
type: ReplyType.video.index,
sort: sortType.index,
page: currentPage,
);
}

View File

@@ -1,8 +1,10 @@
import 'package:PiliPalaX/common/widgets/refresh_indicator.dart';
import 'package:PiliPalaX/common/widgets/http_error.dart';
import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/video/detail/reply/widgets/reply_item.dart';
import 'package:PiliPalaX/pages/video/detail/reply/widgets/reply_item_grpc.dart';
import 'package:PiliPalaX/utils/extension.dart';
import 'package:PiliPalaX/utils/global_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:get/get.dart';
@@ -228,24 +230,43 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
),
);
} else {
return ReplyItemGrpc(
replyItem: loadingState.response.replies[index],
showReplyRow: true,
replyLevel: replyLevel,
replyReply: widget.replyReply,
replyType: ReplyType.video,
onReply: () {
_videoReplyController.onReply(
context,
replyItem: loadingState.response.replies[index],
index: index,
);
},
onDelete: _videoReplyController.onMDelete,
isTop: _videoReplyController.hasUpTop && index == 0,
upMid: loadingState.response.subjectControl.upMid,
getTag: () => heroTag,
);
return GlobalData().grpcReply
? ReplyItemGrpc(
replyItem: loadingState.response.replies[index],
showReplyRow: true,
replyLevel: replyLevel,
replyReply: widget.replyReply,
replyType: ReplyType.video,
onReply: () {
_videoReplyController.onReply(
context,
replyItem: loadingState.response.replies[index],
index: index,
);
},
onDelete: _videoReplyController.onMDelete,
isTop: _videoReplyController.hasUpTop && index == 0,
upMid: loadingState.response.subjectControl.upMid,
getTag: () => heroTag,
)
: ReplyItem(
replyItem: loadingState.response.replies[index],
showReplyRow: true,
replyLevel: replyLevel,
replyReply: widget.replyReply,
replyType: ReplyType.video,
onReply: () {
_videoReplyController.onReply(
context,
replyItem: loadingState.response.replies[index],
index: index,
);
},
onDelete: _videoReplyController.onMDelete,
// isTop: _videoReplyController.hasUpTop && index == 0,
// upMid: loadingState.response.subjectControl.upMid,
// getTag: () => heroTag,
);
}
},
childCount: loadingState.response.replies.length + 1,
@@ -256,7 +277,8 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
callback: _videoReplyController.onReload,
),
Error() => HttpError(
errMsg: loadingState.errMsg,
errMsg:
'如无法加载评论:\n1.关闭代理\n2.设置中关闭使用gRPC加载评论\n\n${loadingState.errMsg}',
callback: _videoReplyController.onReload,
),
LoadingState() => throw UnimplementedError(),

View File

@@ -48,7 +48,7 @@ class ReplyItem extends StatelessWidget {
// 点击整个评论区 评论详情/回复
onTap: () {
feedBack();
replyReply?.call(replyItem);
replyReply?.call(replyItem, null, null);
},
onLongPress: () {
feedBack();
@@ -425,7 +425,7 @@ class ReplyItemRow extends StatelessWidget {
for (int i = 0; i < replies!.length; i++) ...[
InkWell(
// 一楼点击评论展开评论详情
onTap: () => replyReply?.call(replyItem),
onTap: () => replyReply?.call(replyItem, null, null),
onLongPress: () {
feedBack();
showModalBottomSheet(
@@ -525,7 +525,7 @@ class ReplyItemRow extends StatelessWidget {
if (extraRow == 1)
InkWell(
// 一楼点击【共xx条回复】展开评论详情
onTap: () => replyReply?.call(replyItem),
onTap: () => replyReply?.call(replyItem, null, null),
child: Container(
width: double.infinity,
padding: const EdgeInsets.fromLTRB(8, 5, 8, 8),