mod: add reply: data cast

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-11-24 19:53:22 +08:00
parent 6c62cebdba
commit 2e45fafb0b
5 changed files with 52 additions and 36 deletions

View File

@@ -106,6 +106,7 @@ class NetworkImgLayer extends StatelessWidget {
}
Widget placeholder(BuildContext context) {
int cacheWidth = width.cacheSize(context);
return Container(
width: width,
height: height,
@@ -127,7 +128,7 @@ class NetworkImgLayer extends StatelessWidget {
: 'assets/images/loading.png',
width: width,
height: height,
cacheWidth: width.cacheSize(context),
cacheWidth: cacheWidth == 0 ? null : cacheWidth,
// cacheHeight: height.cacheSize(context),
),
),

View File

@@ -4,6 +4,7 @@ import 'package:PiliPalaX/models/common/reply_type.dart';
import 'package:PiliPalaX/pages/common/common_controller.dart';
import 'package:PiliPalaX/pages/video/detail/reply_new/reply_page.dart';
import 'package:PiliPalaX/utils/extension.dart';
import 'package:PiliPalaX/utils/utils.dart';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
@@ -155,20 +156,18 @@ abstract class ReplyController extends CommonController {
),
)
.then(
(value) {
// TODO: data cast
if (value != null && value['data'] != null) {
(res) {
if (res != null) {
savedReplies[key] = null;
if (value['data'] is ReplyInfo) {
MainListReply response =
(loadingState.value as Success?)?.response ?? MainListReply();
if (oid != null) {
response.replies.insert(0, value['data']);
} else {
response.replies[index].replies.add(value['data']);
}
loadingState.value = LoadingState.success(response);
ReplyInfo replyInfo = Utils.replyCast(res);
MainListReply response =
(loadingState.value as Success?)?.response ?? MainListReply();
if (oid != null) {
response.replies.insert(0, replyInfo);
} else {
response.replies[index].replies.add(replyInfo);
}
loadingState.value = LoadingState.success(response);
}
},
);

View File

@@ -13,7 +13,6 @@ import 'package:get/get.dart';
import 'package:PiliPalaX/http/video.dart';
import 'package:PiliPalaX/models/common/reply_type.dart';
import 'package:PiliPalaX/models/video/reply/emote.dart';
import 'package:PiliPalaX/models/video/reply/item.dart';
import 'package:PiliPalaX/pages/emote/index.dart';
import 'package:PiliPalaX/utils/feed_back.dart';
import 'package:PiliPalaX/pages/emote/view.dart';
@@ -517,9 +516,7 @@ class _ReplyPageState extends State<ReplyPage>
);
if (result['status']) {
SmartDialog.showToast(result['data']['success_toast']);
Get.back(result: {
'data': ReplyItemModel.fromJson(result['data']['reply'], ''),
});
Get.back(result: result['data']['reply']);
} else {
SmartDialog.showToast(result['msg']);
}

View File

@@ -3,6 +3,7 @@ import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/video/detail/reply/widgets/reply_item_grpc.dart';
import 'package:PiliPalaX/pages/video/detail/reply_new/reply_page.dart';
import 'package:PiliPalaX/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:PiliPalaX/common/skeleton/video_reply.dart';
@@ -158,7 +159,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
replyType: widget.replyType,
needDivider: false,
onReply: () {
_onReply(firstFloor!);
_onReply(firstFloor!, -1);
},
upMid: _videoReplyReplyController.upMid,
);
@@ -237,7 +238,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
),
);
void _onReply(ReplyInfo? item) {
void _onReply(ReplyInfo? item, int index) {
dynamic oid = item?.oid.toInt();
dynamic root = item?.id.toInt();
dynamic parent = item?.id.toInt();
@@ -274,20 +275,16 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
},
),
)
.then((value) {
// 完成评论,数据添加 // TODO: data cast
if (value != null && value['data'] != null) {
.then((res) {
if (res != null) {
_savedReplies[key] = null;
if (value['data'] is ReplyInfo) {
List<ReplyInfo> list =
_videoReplyReplyController.loadingState.value is Success
? (_videoReplyReplyController.loadingState.value as Success)
.response
: <ReplyInfo>[];
list.add(value['data']);
_videoReplyReplyController.loadingState.value =
LoadingState.success(list);
}
ReplyInfo replyInfo = Utils.replyCast(res);
List list = (_videoReplyReplyController.loadingState.value as Success?)
?.response ??
<ReplyInfo>[];
list.insert(index + 1, replyInfo);
_videoReplyReplyController.loadingState.value =
LoadingState.success(list);
}
});
}
@@ -320,11 +317,11 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
return ColoredBox(
color: _videoReplyReplyController.colorAnimation?.value ??
Theme.of(Get.context!).colorScheme.onInverseSurface,
child: _replyItem(loadingState.response[index]),
child: _replyItem(loadingState.response[index], index),
);
},
)
: _replyItem(loadingState.response[index]);
: _replyItem(loadingState.response[index], index);
}
} else if (loadingState is Error) {
return CustomScrollView(
@@ -355,14 +352,14 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
}
}
Widget _replyItem(replyItem) {
Widget _replyItem(replyItem, index) {
return ReplyItemGrpc(
replyItem: replyItem,
replyLevel: widget.isDialogue ? '3' : '2',
showReplyRow: false,
replyType: widget.replyType,
onReply: () {
_onReply(replyItem);
_onReply(replyItem, index);
},
onDelete: (rpid, frpid) {
List list =

View File

@@ -5,6 +5,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
import 'package:PiliPalaX/http/member.dart';
import 'package:PiliPalaX/http/search.dart';
import 'package:PiliPalaX/http/video.dart';
@@ -25,6 +26,27 @@ import 'package:url_launcher/url_launcher.dart';
class Utils {
static final Random random = Random();
static ReplyInfo replyCast(res) {
Map emote = res['content']['emote'];
emote.forEach((key, value) {
value['size'] = value['meta']['size'];
});
return ReplyInfo.create()
..mergeFromProto3Json(
res
..['id'] = res['rpid']
..['member']['name'] = res['member']['uname']
..['member']['face'] = res['member']['avatar']
..['member']['level'] = res['member']['level_info']['current_level']
..['member']['vipStatus'] = res['member']['vip']['vipStatus']
..['member']['vipType'] = res['member']['vip']['vipType']
..['member']['officialVerifyType'] =
res['member']['official_verify']['type']
..['content']['emote'] = emote,
ignoreUnknownFields: true,
);
}
static bool isDefault(int attr) {
return (attr & 2) == 0;
}