mod: refresh

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-03-04 12:06:50 +08:00
parent 5986add7dd
commit 8ef163dd38
8 changed files with 568 additions and 559 deletions

View File

@@ -1,3 +1,4 @@
import 'package:PiliPlus/common/widgets/loading_widget.dart';
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
@@ -52,92 +53,85 @@ class _AtMePageState extends State<AtMePage> {
onRefresh: () async {
await _atMeController.onRefresh();
},
child: SingleChildScrollView(
controller: _scrollController,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Obx(
() {
if (_atMeController.msgFeedAtMeList.isEmpty) {
return const Center(
child: CircularProgressIndicator(),
);
}
return ListView.separated(
itemCount: _atMeController.msgFeedAtMeList.length,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, int i) {
return ListTile(
onTap: () {
String? nativeUri =
_atMeController.msgFeedAtMeList[i].item?.nativeUri;
if (nativeUri != null) {
PiliScheme.routePushFromUrl(nativeUri);
}
// SmartDialog.showToast("跳转至:$nativeUri暂未实现");
},
leading: NetworkImgLayer(
width: 45,
height: 45,
type: 'avatar',
src: _atMeController.msgFeedAtMeList[i].user?.avatar,
),
title: Text(
"${_atMeController.msgFeedAtMeList[i].user?.nickname} "
"${_atMeController.msgFeedAtMeList[i].item?.business}中@了我",
child: Obx(
() {
// TODO: refactor
if (_atMeController.msgFeedAtMeList.isEmpty) {
if (_atMeController.cursor == -1 &&
_atMeController.cursorTime == -1) {
return const Center(
child: CircularProgressIndicator(),
);
} else {
return scrollErrorWidget(
callback: _atMeController.queryMsgFeedAtMe);
}
}
return ListView.separated(
controller: _scrollController,
itemCount: _atMeController.msgFeedAtMeList.length,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (context, int i) {
return ListTile(
onTap: () {
String? nativeUri =
_atMeController.msgFeedAtMeList[i].item?.nativeUri;
if (nativeUri != null) {
PiliScheme.routePushFromUrl(nativeUri);
}
// SmartDialog.showToast("跳转至:$nativeUri暂未实现");
},
leading: NetworkImgLayer(
width: 45,
height: 45,
type: 'avatar',
src: _atMeController.msgFeedAtMeList[i].user?.avatar,
),
title: Text(
"${_atMeController.msgFeedAtMeList[i].user?.nickname} "
"${_atMeController.msgFeedAtMeList[i].item?.business}中@了我",
style: Theme.of(context).textTheme.titleMedium!.copyWith(
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
.titleMedium!
.bodyMedium!
.copyWith(
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 &&
_atMeController.msgFeedAtMeList[i].item?.image !=
""
? NetworkImgLayer(
width: 45,
height: 45,
type: 'cover',
src: _atMeController
.msgFeedAtMeList[i].item?.image,
)
: null,
);
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 72,
endIndent: 20,
height: 6,
color: Colors.grey.withOpacity(0.1),
);
},
color: Theme.of(context).colorScheme.outline))
],
),
trailing: _atMeController.msgFeedAtMeList[i].item?.image !=
null &&
_atMeController.msgFeedAtMeList[i].item?.image != ""
? NetworkImgLayer(
width: 45,
height: 45,
type: 'cover',
src: _atMeController.msgFeedAtMeList[i].item?.image,
)
: null,
);
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 72,
endIndent: 20,
height: 6,
color: Colors.grey.withOpacity(0.1),
);
},
);
}),
},
),
),
);

View File

@@ -53,6 +53,7 @@ class _LikeMePageState extends State<LikeMePage> {
onRefresh: () async {
await _likeMeController.onRefresh();
},
// TODO: refactor
child: SingleChildScrollView(
controller: _scrollController,
child: LayoutBuilder(

View File

@@ -51,106 +51,100 @@ class _ReplyMePageState extends State<ReplyMePage> {
onRefresh: () async {
await _replyMeController.onRefresh();
},
child: SingleChildScrollView(
controller: _scrollController,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Obx(
() {
if (_replyMeController.msgFeedReplyMeList.isEmpty) {
return const Center(
child: CircularProgressIndicator(),
);
}
return ListView.separated(
itemCount: _replyMeController.msgFeedReplyMeList.length,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, int i) {
return ListTile(
onTap: () {
String? nativeUri = _replyMeController
.msgFeedReplyMeList[i].item?.nativeUri;
if (nativeUri != null) {
PiliScheme.routePushFromUrl(nativeUri);
}
// SmartDialog.showToast("跳转至:$nativeUri暂未实现");
},
leading: NetworkImgLayer(
width: 45,
height: 45,
type: 'avatar',
src: _replyMeController
.msgFeedReplyMeList[i].user?.avatar,
),
title: Text(
"${_replyMeController.msgFeedReplyMeList[i].user?.nickname} "
"回复了我的${_replyMeController.msgFeedReplyMeList[i].item?.business}",
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.primary),
),
subtitle: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(
_replyMeController.msgFeedReplyMeList[i].item
?.sourceContent ??
"",
style: Theme.of(context).textTheme.bodyMedium),
const SizedBox(height: 4),
if (_replyMeController.msgFeedReplyMeList[i].item
?.targetReplyContent !=
null &&
_replyMeController.msgFeedReplyMeList[i].item
?.targetReplyContent !=
"")
Text(
"| ${_replyMeController.msgFeedReplyMeList[i].item?.targetReplyContent}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color: Theme.of(context)
.colorScheme
.outline,
height: 1.5)),
if (_replyMeController.msgFeedReplyMeList[i].item
?.rootReplyContent !=
null &&
_replyMeController.msgFeedReplyMeList[i].item
?.rootReplyContent !=
"")
Text(
" | ${_replyMeController.msgFeedReplyMeList[i].item?.rootReplyContent}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color: Theme.of(context)
.colorScheme
.outline,
height: 1.5)),
]),
);
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 72,
endIndent: 20,
height: 6,
color: Colors.grey.withOpacity(0.1),
);
// TODO: refactor
child: Obx(
() {
if (_replyMeController.msgFeedReplyMeList.isEmpty) {
return const Center(
child: CircularProgressIndicator(),
);
}
return ListView.separated(
controller: _scrollController,
itemCount: _replyMeController.msgFeedReplyMeList.length,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (context, int i) {
return ListTile(
onTap: () {
String? nativeUri = _replyMeController
.msgFeedReplyMeList[i].item?.nativeUri;
if (nativeUri != null) {
PiliScheme.routePushFromUrl(nativeUri);
}
// SmartDialog.showToast("跳转至:$nativeUri暂未实现");
},
leading: NetworkImgLayer(
width: 45,
height: 45,
type: 'avatar',
src: _replyMeController.msgFeedReplyMeList[i].user?.avatar,
),
title: Text(
"${_replyMeController.msgFeedReplyMeList[i].user?.nickname} "
"回复了我的${_replyMeController.msgFeedReplyMeList[i].item?.business}",
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: Theme.of(context).colorScheme.primary),
),
subtitle: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(
_replyMeController.msgFeedReplyMeList[i].item
?.sourceContent ??
"",
style: Theme.of(context).textTheme.bodyMedium),
const SizedBox(height: 4),
if (_replyMeController.msgFeedReplyMeList[i].item
?.targetReplyContent !=
null &&
_replyMeController.msgFeedReplyMeList[i].item
?.targetReplyContent !=
"")
Text(
"| ${_replyMeController.msgFeedReplyMeList[i].item?.targetReplyContent}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline,
height: 1.5)),
if (_replyMeController.msgFeedReplyMeList[i].item
?.rootReplyContent !=
null &&
_replyMeController.msgFeedReplyMeList[i].item
?.rootReplyContent !=
"")
Text(
" | ${_replyMeController.msgFeedReplyMeList[i].item?.rootReplyContent}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline,
height: 1.5)),
]),
);
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 72,
endIndent: 20,
height: 6,
color: Colors.grey.withOpacity(0.1),
);
},
);
}),
},
),
),
);

View File

@@ -57,112 +57,105 @@ class _SysMsgPageState extends State<SysMsgPage> {
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: (context, 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 (_) {}
// TODO: refactor
child: Obx(
() {
if (_sysMsgController.msgFeedSysMsgList.isEmpty) {
return const Center(
child: CircularProgressIndicator(),
);
}
return ListView.separated(
controller: _scrollController,
itemCount: _sysMsgController.msgFeedSysMsgList.length,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (context, 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'];
}
return ListTile(
onTap: () {},
onLongPress: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('确定删除该通知?'),
actions: [
TextButton(
onPressed: Get.back,
child: Text(
'取消',
style: TextStyle(
color: Theme.of(context)
.colorScheme
.outline,
),
),
} catch (_) {}
}
return ListTile(
onTap: () {},
onLongPress: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('确定删除该通知?'),
actions: [
TextButton(
onPressed: Get.back,
child: Text(
'取消',
style: TextStyle(
color:
Theme.of(context).colorScheme.outline,
),
TextButton(
onPressed: () {
Get.back();
_sysMsgController.onRemove(i);
},
child: const Text('确定'),
),
],
));
},
title: Text(
"${_sysMsgController.msgFeedSysMsgList[i].title}",
style: Theme.of(context).textTheme.titleMedium,
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text.rich(
_buildContent(content ?? ''),
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.85),
),
),
const SizedBox(height: 5),
SizedBox(
width: double.infinity,
child: Text(
"${_sysMsgController.msgFeedSysMsgList[i].timeAt}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color:
Theme.of(context).colorScheme.outline,
),
textAlign: TextAlign.end,
),
),
],
),
TextButton(
onPressed: () {
Get.back();
_sysMsgController.onRemove(i);
},
child: const Text('确定'),
),
],
));
},
title: Text(
"${_sysMsgController.msgFeedSysMsgList[i].title}",
style: Theme.of(context).textTheme.titleMedium,
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text.rich(
_buildContent(content ?? ''),
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.85),
),
),
);
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 72,
endIndent: 20,
height: 6,
color: Colors.grey.withOpacity(0.1),
);
},
const SizedBox(height: 5),
SizedBox(
width: double.infinity,
child: Text(
"${_sysMsgController.msgFeedSysMsgList[i].timeAt}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: Theme.of(context).colorScheme.outline,
),
textAlign: TextAlign.end,
),
),
],
),
);
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 72,
endIndent: 20,
height: 6,
color: Colors.grey.withOpacity(0.1),
);
},
);
}),
},
),
),
);