mod: 支持系统消息查看,美化界面,点击清除未读提示,支持未读刷新

修复私信页点击视频后反复提示已读成功的问题
This commit is contained in:
orz12
2024-02-23 15:09:46 +08:00
parent 2671d0a130
commit 21ed67e569
14 changed files with 522 additions and 134 deletions

View File

@@ -74,22 +74,33 @@ class _AtMePageState extends State<AtMePage> {
src: _atMeController.msgFeedAtMeList[i].user?.avatar,
),
title: Text(
"${_atMeController.msgFeedAtMeList[i].user?.nickname} "
"${_atMeController.msgFeedAtMeList[i].item?.business}中@了我",
style: Theme.of(context).textTheme.bodyMedium!,
),
subtitle: Text(
_atMeController
.msgFeedAtMeList[i].item?.sourceContent ??
"",
maxLines: 2,
overflow: TextOverflow.ellipsis,
"${_atMeController.msgFeedAtMeList[i].user?.nickname} "
"${_atMeController.msgFeedAtMeList[i].item?.business}中@了我",
style: Theme.of(context)
.textTheme
.labelMedium!
.titleMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline)),
color: Theme.of(context).colorScheme.primary,
)),
subtitle:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(
_atMeController
.msgFeedAtMeList[i].item?.sourceContent ??
"",
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline))
],
),
trailing: _atMeController
.msgFeedAtMeList[i].item?.image !=
null &&

View File

@@ -115,45 +115,61 @@ class LikeMeList extends StatelessWidget {
String nativeUri = msgFeedLikeMeList[i].item?.nativeUri ?? "";
SmartDialog.showToast("跳转至:$nativeUri(暂未实现)");
},
leading: SizedBox(
width: 50,
height: 50,
child: Stack(
children: [
for (var j = 0;
j < msgFeedLikeMeList[i].users!.length && j < 4;
j++) ...<Widget>[
Positioned(
left: 15 * (j % 2).toDouble(),
top: 15 * (j ~/ 2).toDouble(),
child: NetworkImgLayer(
width:
msgFeedLikeMeList[i].users!.length > 1 ? 30 : 45,
height:
msgFeedLikeMeList[i].users!.length > 1 ? 30 : 45,
type: 'avatar',
src: msgFeedLikeMeList[i].users![j].avatar,
)),
]
],
)),
leading: Column(
children: [
const Spacer(),
SizedBox(
width: 50,
height: 50,
child: Stack(
children: [
for (var j = 0;
j < msgFeedLikeMeList[i].users!.length && j < 4;
j++) ...<Widget>[
Positioned(
left: 15 * (j % 2).toDouble(),
top: 15 * (j ~/ 2).toDouble(),
child: NetworkImgLayer(
width: msgFeedLikeMeList[i].users!.length > 1
? 30
: 45,
height: msgFeedLikeMeList[i].users!.length > 1
? 30
: 45,
type: 'avatar',
src: msgFeedLikeMeList[i].users![j].avatar,
)),
]
],
)),
const Spacer(),
],
),
title: Text(
"${msgFeedLikeMeList[i].users!.map((e) => e.nickname).join("/")}"
"等共 ${msgFeedLikeMeList[i].counts}"
// "${msgFeedLikeMeList[i].users!.map((e) => e.nickname).join("/")}"
"${msgFeedLikeMeList[i].users?[0].nickname}"
"${msgFeedLikeMeList[i].users!.length > 1 ? '' + msgFeedLikeMeList[i].users![1].nickname.toString() + '' : ''} "
"${msgFeedLikeMeList[i].counts! > 1 ? '' + msgFeedLikeMeList[i].counts.toString() + '' : ''}"
"赞了我的${msgFeedLikeMeList[i].item?.business}",
style:
Theme.of(context).textTheme.labelMedium!.copyWith(height: 1.5),
style: Theme.of(context).textTheme.titleSmall!.copyWith(
height: 1.5, color: Theme.of(context).colorScheme.primary),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
subtitle: msgFeedLikeMeList[i].item?.title != null &&
msgFeedLikeMeList[i].item?.title != ""
? Text(msgFeedLikeMeList[i].item?.title ?? "",
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelMedium!.copyWith(
color: Theme.of(context).colorScheme.outline,
height: 1.5))
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(msgFeedLikeMeList[i].item?.title ?? "",
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.outline,
height: 1.5))
],
)
: null,
trailing: msgFeedLikeMeList[i].item?.image != null &&
msgFeedLikeMeList[i].item?.image != ""

View File

@@ -78,7 +78,8 @@ class _ReplyMePageState extends State<ReplyMePage> {
title: Text(
"${_replyMeController.msgFeedReplyMeList[i].user?.nickname} "
"回复了我的${_replyMeController.msgFeedReplyMeList[i].item?.business}",
style: Theme.of(context).textTheme.bodyMedium!,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.primary),
),
subtitle: Column(
mainAxisAlignment: MainAxisAlignment.start,
@@ -126,7 +127,7 @@ class _ReplyMePageState extends State<ReplyMePage> {
color: Theme.of(context)
.colorScheme
.outline,
height: 1.5)),
height: 1.5)),
]),
);
},

View File

@@ -0,0 +1,63 @@
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:PiliPalaX/http/msg.dart';
import '../../../models/msg/msgfeed_sys_msg.dart';
class SysMsgController extends GetxController {
RxList<SystemNotifyList> msgFeedSysMsgList = <SystemNotifyList>[].obs;
bool isLoading = false;
int cursor = -1;
int cursorTime = -1;
bool isEnd = false;
Future queryMsgFeedSysMsg() async {
if (isLoading) return;
isLoading = true;
var resUserNotify = await MsgHttp.msgFeedSysUserNotify();
var resUnifiedNotify = await MsgHttp.msgFeedSysUnifiedNotify();
isLoading = false;
List<SystemNotifyList> systemNotifyList = [];
if (resUserNotify['status']) {
MsgFeedSysMsg data = MsgFeedSysMsg.fromJson(resUserNotify['data']);
if (data.systemNotifyList != null) {
systemNotifyList.addAll(data.systemNotifyList!);
}
}
if (resUnifiedNotify['status']) {
MsgFeedSysMsg data = MsgFeedSysMsg.fromJson(resUnifiedNotify['data']);
if (data.systemNotifyList != null) {
systemNotifyList.addAll(data.systemNotifyList!);
}
}
if (systemNotifyList.isNotEmpty) {
systemNotifyList.sort((a, b) => b.cursor!.compareTo(a.cursor!));
msgFeedSysMsgList.assignAll(systemNotifyList);
msgSysUpdateCursor(msgFeedSysMsgList.first.cursor!);
} else {
SmartDialog.showToast(
"UserNotify: ${resUserNotify['msg']} UnifiedNotify: ${resUnifiedNotify['msg']}");
}
}
Future msgSysUpdateCursor(int cursor) async {
var res = await MsgHttp.msgSysUpdateCursor(cursor);
if (res['status']) {
SmartDialog.showToast('已读成功');
return true;
} else {
SmartDialog.showToast(res['msg']);
return false;
}
}
Future onLoad() async {
if (isEnd) return;
queryMsgFeedSysMsg();
}
Future onRefresh() async {
cursor = -1;
cursorTime = -1;
queryMsgFeedSysMsg();
}
}

View File

@@ -0,0 +1,4 @@
library whisper;
export './controller.dart';
export './view.dart';

View File

@@ -0,0 +1,123 @@
import 'dart:convert';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'controller.dart';
class SysMsgPage extends StatefulWidget {
const SysMsgPage({super.key});
@override
State<SysMsgPage> createState() => _SysMsgPageState();
}
class _SysMsgPageState extends State<SysMsgPage> {
late final SysMsgController _sysMsgController = Get.put(SysMsgController());
final ScrollController _scrollController = ScrollController();
@override
void initState() {
_sysMsgController.queryMsgFeedSysMsg();
super.initState();
_scrollController.addListener(_scrollListener);
}
Future _scrollListener() async {
if (_scrollController.position.pixels >=
_scrollController.position.maxScrollExtent - 200) {
EasyThrottle.throttle('my-throttler', const Duration(milliseconds: 800),
() async {
await _sysMsgController.onLoad();
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('系统通知'),
),
body: RefreshIndicator(
onRefresh: () async {
await _sysMsgController.onRefresh();
},
child: SingleChildScrollView(
controller: _scrollController,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Obx(
() {
if (_sysMsgController.msgFeedSysMsgList.isEmpty) {
return const Center(
child: CircularProgressIndicator(),
);
}
return ListView.separated(
itemCount: _sysMsgController.msgFeedSysMsgList.length,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (_, int i) {
String? content = _sysMsgController.msgFeedSysMsgList[i].content;
if (content != null) {
try {
dynamic jsonContent = json.decode(content);
if (jsonContent != null && jsonContent['web'] != null) {
content = jsonContent['web'];
}
} catch (_) {}
}
return ListTile(
onTap: () {},
title: Text(
"${_sysMsgController.msgFeedSysMsgList[i].title}",
style: Theme.of(context).textTheme.titleMedium!.copyWith(
color: Theme.of(context).colorScheme.primary
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(
"$content",
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: Theme.of(context)
.colorScheme
.outline)),
const SizedBox(height: 4),
Text(
"${_sysMsgController.msgFeedSysMsgList[i].timeAt}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: Theme.of(context)
.colorScheme
.outline.withOpacity(0.8))),
]));
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 72,
endIndent: 20,
height: 6,
color: Colors.grey.withOpacity(0.1),
);
},
);
},
);
}),
),
),
);
}
}