mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-23 02:26:52 +08:00
59
lib/pages/video/reply/controller.dart
Normal file
59
lib/pages/video/reply/controller.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/common/reply_controller.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:fixnum/fixnum.dart' as $fixnum;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get_state_manager/src/rx_flutter/rx_ticket_provider_mixin.dart';
|
||||
|
||||
class VideoReplyController extends ReplyController<MainListReply>
|
||||
with GetSingleTickerProviderStateMixin {
|
||||
VideoReplyController({required this.aid});
|
||||
// 视频aid 请求时使用的oid
|
||||
int aid;
|
||||
|
||||
@override
|
||||
dynamic get sourceId => IdUtils.av2bv(aid);
|
||||
|
||||
bool _isFabVisible = true;
|
||||
late final AnimationController fabAnimationCtr = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 100))
|
||||
..forward();
|
||||
|
||||
void showFab() {
|
||||
if (!_isFabVisible) {
|
||||
_isFabVisible = true;
|
||||
fabAnimationCtr.forward();
|
||||
}
|
||||
}
|
||||
|
||||
void hideFab() {
|
||||
if (_isFabVisible) {
|
||||
_isFabVisible = false;
|
||||
fabAnimationCtr.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<ReplyInfo>? getDataList(MainListReply response) {
|
||||
return response.replies;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<MainListReply>> customGetData() =>
|
||||
ReplyHttp.replyListGrpc(
|
||||
oid: aid,
|
||||
cursor: CursorReq(
|
||||
next: cursor?.next ?? $fixnum.Int64(0),
|
||||
mode: mode.value,
|
||||
),
|
||||
antiGoodsReply: antiGoodsReply,
|
||||
);
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
fabAnimationCtr.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
273
lib/pages/video/reply/view.dart
Normal file
273
lib/pages/video/reply/view.dart
Normal file
@@ -0,0 +1,273 @@
|
||||
import 'package:PiliPlus/common/widgets/custom_sliver_persistent_header_delegate.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/http_error.dart';
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/reply_sort_type.dart';
|
||||
import 'package:PiliPlus/pages/video/reply/widgets/reply_item_grpc.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_reply.dart';
|
||||
import 'package:PiliPlus/models/common/reply_type.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'controller.dart';
|
||||
|
||||
class VideoReplyPanel extends StatefulWidget {
|
||||
final String? bvid;
|
||||
final int oid;
|
||||
final int rpid;
|
||||
final String replyLevel;
|
||||
final String heroTag;
|
||||
final Function(ReplyInfo replyItem, int? rpid) replyReply;
|
||||
final VoidCallback? onViewImage;
|
||||
final ValueChanged<int>? onDismissed;
|
||||
final Function(List<String>, int)? callback;
|
||||
final bool? needController;
|
||||
|
||||
const VideoReplyPanel({
|
||||
super.key,
|
||||
this.bvid,
|
||||
required this.oid,
|
||||
this.rpid = 0,
|
||||
this.replyLevel = '1',
|
||||
required this.heroTag,
|
||||
required this.replyReply,
|
||||
this.onViewImage,
|
||||
this.onDismissed,
|
||||
this.callback,
|
||||
this.needController,
|
||||
});
|
||||
|
||||
@override
|
||||
State<VideoReplyPanel> createState() => _VideoReplyPanelState();
|
||||
}
|
||||
|
||||
class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
late VideoReplyController _videoReplyController;
|
||||
|
||||
String get heroTag => widget.heroTag;
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_videoReplyController = Get.find<VideoReplyController>(tag: heroTag);
|
||||
if (_videoReplyController.loadingState.value is Loading) {
|
||||
_videoReplyController.queryData();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_videoReplyController.showFab();
|
||||
if (widget.needController != false) {
|
||||
_videoReplyController.scrollController.addListener(listener);
|
||||
} else {
|
||||
_videoReplyController.scrollController.removeListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (widget.needController != false) {
|
||||
_videoReplyController.scrollController.removeListener(listener);
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void listener() {
|
||||
final ScrollDirection direction =
|
||||
_videoReplyController.scrollController.position.userScrollDirection;
|
||||
if (direction == ScrollDirection.forward) {
|
||||
if (mounted) {
|
||||
_videoReplyController.showFab();
|
||||
}
|
||||
} else if (direction == ScrollDirection.reverse) {
|
||||
if (mounted) {
|
||||
_videoReplyController.hideFab();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final theme = Theme.of(context);
|
||||
return refreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _videoReplyController.onRefresh();
|
||||
},
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
CustomScrollView(
|
||||
controller: widget.needController == false
|
||||
? null
|
||||
: _videoReplyController.scrollController,
|
||||
physics: widget.needController == false
|
||||
? const AlwaysScrollableScrollPhysics(
|
||||
parent: ClampingScrollPhysics(),
|
||||
)
|
||||
: const AlwaysScrollableScrollPhysics(),
|
||||
key: const PageStorageKey<String>('评论'),
|
||||
slivers: <Widget>[
|
||||
SliverPersistentHeader(
|
||||
pinned: false,
|
||||
floating: true,
|
||||
delegate: CustomSliverPersistentHeaderDelegate(
|
||||
extent: 40,
|
||||
bgColor: theme.colorScheme.surface,
|
||||
child: Container(
|
||||
height: 40,
|
||||
padding: const EdgeInsets.fromLTRB(12, 0, 6, 0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Obx(
|
||||
() => Text(
|
||||
_videoReplyController.sortType.value.title,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
child: TextButton.icon(
|
||||
onPressed: () =>
|
||||
_videoReplyController.queryBySort(),
|
||||
icon: Icon(
|
||||
Icons.sort,
|
||||
size: 16,
|
||||
color: theme.colorScheme.secondary,
|
||||
),
|
||||
label: Obx(
|
||||
() => Text(
|
||||
_videoReplyController.sortType.value.label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: theme.colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(() =>
|
||||
_buildBody(theme, _videoReplyController.loadingState.value)),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
bottom: MediaQuery.of(context).padding.bottom + 14,
|
||||
right: 14,
|
||||
child: SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0, 2),
|
||||
end: const Offset(0, 0),
|
||||
).animate(CurvedAnimation(
|
||||
parent: _videoReplyController.fabAnimationCtr,
|
||||
curve: Curves.easeInOut,
|
||||
)),
|
||||
child: FloatingActionButton(
|
||||
heroTag: null,
|
||||
onPressed: () {
|
||||
feedBack();
|
||||
_videoReplyController.onReply(
|
||||
context,
|
||||
oid: _videoReplyController.aid,
|
||||
replyType: ReplyType.video,
|
||||
);
|
||||
},
|
||||
tooltip: '发表评论',
|
||||
child: const Icon(Icons.reply),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(ThemeData theme, LoadingState loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverList.builder(
|
||||
itemBuilder: (BuildContext context, index) {
|
||||
return const VideoReplySkeleton();
|
||||
},
|
||||
itemCount: 5,
|
||||
),
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverList.builder(
|
||||
itemBuilder: (context, index) {
|
||||
double bottom = MediaQuery.of(context).padding.bottom;
|
||||
if (index == loadingState.response.length) {
|
||||
_videoReplyController.onLoadMore();
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.only(bottom: bottom),
|
||||
height: bottom + 100,
|
||||
child: Text(
|
||||
_videoReplyController.isEnd.not
|
||||
? '加载中...'
|
||||
: loadingState.response.isEmpty
|
||||
? '还没有评论'
|
||||
: '没有更多了',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: theme.colorScheme.outline,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return ReplyItemGrpc(
|
||||
replyItem: loadingState.response[index],
|
||||
replyLevel: widget.replyLevel,
|
||||
replyReply: widget.replyReply,
|
||||
onReply: () {
|
||||
_videoReplyController.onReply(
|
||||
context,
|
||||
replyItem: loadingState.response[index],
|
||||
index: index,
|
||||
);
|
||||
},
|
||||
onDelete: (subIndex) =>
|
||||
_videoReplyController.onRemove(index, subIndex),
|
||||
upMid: _videoReplyController.upMid,
|
||||
getTag: () => heroTag,
|
||||
onViewImage: widget.onViewImage,
|
||||
onDismissed: widget.onDismissed,
|
||||
callback: widget.callback,
|
||||
onCheckReply: (item) =>
|
||||
_videoReplyController.onCheckReply(context, item),
|
||||
onToggleTop: (isUpTop, rpid) =>
|
||||
_videoReplyController.onToggleTop(
|
||||
index,
|
||||
_videoReplyController.aid,
|
||||
ReplyType.video.index,
|
||||
isUpTop,
|
||||
rpid,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
itemCount: loadingState.response.length + 1,
|
||||
)
|
||||
: HttpError(
|
||||
errMsg: '还没有评论',
|
||||
onReload: _videoReplyController.onReload,
|
||||
),
|
||||
Error() => HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
onReload: _videoReplyController.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
1196
lib/pages/video/reply/widgets/reply_item_grpc.dart
Normal file
1196
lib/pages/video/reply/widgets/reply_item_grpc.dart
Normal file
File diff suppressed because it is too large
Load Diff
174
lib/pages/video/reply/widgets/zan_grpc.dart
Normal file
174
lib/pages/video/reply/widgets/zan_grpc.dart
Normal file
@@ -0,0 +1,174 @@
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/utils.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:PiliPlus/http/reply.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:fixnum/fixnum.dart' as $fixnum;
|
||||
|
||||
class ZanButtonGrpc extends StatefulWidget {
|
||||
const ZanButtonGrpc({
|
||||
super.key,
|
||||
required this.replyItem,
|
||||
});
|
||||
|
||||
final ReplyInfo replyItem;
|
||||
|
||||
@override
|
||||
State<ZanButtonGrpc> createState() => _ZanButtonGrpcState();
|
||||
}
|
||||
|
||||
class _ZanButtonGrpcState extends State<ZanButtonGrpc> {
|
||||
Future onHateReply() async {
|
||||
feedBack();
|
||||
final int oid = widget.replyItem.oid.toInt();
|
||||
final int rpid = widget.replyItem.id.toInt();
|
||||
// 1 已点赞 2 不喜欢 0 未操作
|
||||
final int action =
|
||||
widget.replyItem.replyControl.action.toInt() != 2 ? 2 : 0;
|
||||
final res = await ReplyHttp.hateReply(
|
||||
type: widget.replyItem.type.toInt(),
|
||||
action: action == 2 ? 1 : 0,
|
||||
oid: oid,
|
||||
rpid: rpid,
|
||||
);
|
||||
// SmartDialog.dismiss();
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast(
|
||||
widget.replyItem.replyControl.action.toInt() != 2 ? '点踩成功' : '取消踩');
|
||||
if (action == 2) {
|
||||
if (widget.replyItem.replyControl.action.toInt() == 1) {
|
||||
widget.replyItem.like =
|
||||
$fixnum.Int64(widget.replyItem.like.toInt() - 1);
|
||||
}
|
||||
widget.replyItem.replyControl.action = $fixnum.Int64(2);
|
||||
} else {
|
||||
widget.replyItem.replyControl.action = $fixnum.Int64(0);
|
||||
}
|
||||
setState(() {});
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
// 评论点赞
|
||||
Future onLikeReply() async {
|
||||
feedBack();
|
||||
final int oid = widget.replyItem.oid.toInt();
|
||||
final int rpid = widget.replyItem.id.toInt();
|
||||
// 1 已点赞 2 不喜欢 0 未操作
|
||||
final int action =
|
||||
widget.replyItem.replyControl.action.toInt() != 1 ? 1 : 0;
|
||||
final res = await ReplyHttp.likeReply(
|
||||
type: widget.replyItem.type.toInt(),
|
||||
oid: oid,
|
||||
rpid: rpid,
|
||||
action: action,
|
||||
);
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast(
|
||||
widget.replyItem.replyControl.action.toInt() != 1 ? '点赞成功' : '取消赞');
|
||||
if (action == 1) {
|
||||
widget.replyItem.like =
|
||||
$fixnum.Int64(widget.replyItem.like.toInt() + 1);
|
||||
widget.replyItem.replyControl.action = $fixnum.Int64(1);
|
||||
} else {
|
||||
widget.replyItem.like =
|
||||
$fixnum.Int64(widget.replyItem.like.toInt() - 1);
|
||||
widget.replyItem.replyControl.action = $fixnum.Int64(0);
|
||||
}
|
||||
setState(() {});
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
bool isProcessing = false;
|
||||
void handleState(Future Function() action) async {
|
||||
if (isProcessing.not) {
|
||||
isProcessing = true;
|
||||
await action();
|
||||
isProcessing = false;
|
||||
}
|
||||
}
|
||||
|
||||
get _style => TextButton.styleFrom(
|
||||
padding: const EdgeInsets.all(0),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
visualDensity: VisualDensity(horizontal: -2, vertical: -2),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
final Color color = theme.colorScheme.outline;
|
||||
final Color primary = theme.colorScheme.primary;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 32,
|
||||
child: TextButton(
|
||||
style: _style,
|
||||
onPressed: () => handleState(onHateReply),
|
||||
child: Icon(
|
||||
widget.replyItem.replyControl.action.toInt() == 2
|
||||
? FontAwesomeIcons.solidThumbsDown
|
||||
: FontAwesomeIcons.thumbsDown,
|
||||
size: 16,
|
||||
color: widget.replyItem.replyControl.action.toInt() == 2
|
||||
? primary
|
||||
: color,
|
||||
semanticLabel: widget.replyItem.replyControl.action.toInt() == 2
|
||||
? '已踩'
|
||||
: '点踩',
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 32,
|
||||
child: TextButton(
|
||||
style: _style,
|
||||
onPressed: () => handleState(onLikeReply),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
widget.replyItem.replyControl.action.toInt() == 1
|
||||
? FontAwesomeIcons.solidThumbsUp
|
||||
: FontAwesomeIcons.thumbsUp,
|
||||
size: 16,
|
||||
color: widget.replyItem.replyControl.action.toInt() == 1
|
||||
? primary
|
||||
: color,
|
||||
semanticLabel:
|
||||
widget.replyItem.replyControl.action.toInt() == 1
|
||||
? '已赞'
|
||||
: '点赞',
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 400),
|
||||
transitionBuilder:
|
||||
(Widget child, Animation<double> animation) {
|
||||
return ScaleTransition(scale: animation, child: child);
|
||||
},
|
||||
child: Text(
|
||||
Utils.numFormat(widget.replyItem.like.toInt()),
|
||||
style: TextStyle(
|
||||
color: widget.replyItem.replyControl.action.toInt() == 1
|
||||
? primary
|
||||
: color,
|
||||
fontSize: theme.textTheme.labelSmall!.fontSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user