mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-30 23:58:13 +08:00
opt: load more replies
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPalaX/grpc/grpc_repo.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||
import 'package:PiliPalaX/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/http/reply.dart';
|
||||
@@ -29,8 +30,6 @@ class VideoReplyReplyController extends CommonController
|
||||
// rpid 请求楼中楼回复
|
||||
int? rpid;
|
||||
ReplyType replyType; // = ReplyType.video;
|
||||
// 当前页
|
||||
RxString noMore = ''.obs;
|
||||
// 当前回复的回复
|
||||
ReplyInfo? currentReplyItem;
|
||||
|
||||
@@ -45,6 +44,8 @@ class VideoReplyReplyController extends CommonController
|
||||
|
||||
ReplyInfo? firstFloor;
|
||||
|
||||
bool isEnd = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -81,7 +82,7 @@ class VideoReplyReplyController extends CommonController
|
||||
|
||||
@override
|
||||
Future queryData([bool isRefresh = true]) async {
|
||||
if (['没有更多了', '还没有评论'].contains(noMore.value)) return Future.value();
|
||||
if (isRefresh.not && isEnd) return Future.value();
|
||||
if (!isDialogue &&
|
||||
currentPage == 1 &&
|
||||
!hasRoot &&
|
||||
@@ -109,6 +110,7 @@ class VideoReplyReplyController extends CommonController
|
||||
@override
|
||||
Future onRefresh() {
|
||||
cursor = null;
|
||||
isEnd = false;
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@@ -158,24 +160,22 @@ class VideoReplyReplyController extends CommonController
|
||||
}
|
||||
if (isDialogue) {
|
||||
if (replies.replies.isNotEmpty) {
|
||||
noMore.value = '加载中...';
|
||||
if (replies.cursor.isEnd || replies.replies.length >= count.value) {
|
||||
noMore.value = '没有更多了';
|
||||
isEnd = true;
|
||||
}
|
||||
} else {
|
||||
// 未登录状态replies可能返回null
|
||||
noMore.value = currentPage == 1 ? '还没有评论' : '没有更多了';
|
||||
isEnd = true;
|
||||
}
|
||||
} else {
|
||||
if (replies.root.replies.isNotEmpty) {
|
||||
noMore.value = '加载中...';
|
||||
if (replies.cursor.isEnd ||
|
||||
replies.root.replies.length >= count.value) {
|
||||
noMore.value = '没有更多了';
|
||||
isEnd = true;
|
||||
}
|
||||
} else {
|
||||
// 未登录状态replies可能返回null
|
||||
noMore.value = currentPage == 1 ? '还没有评论' : '没有更多了';
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
if (isDialogue) {
|
||||
@@ -210,7 +210,6 @@ class VideoReplyReplyController extends CommonController
|
||||
);
|
||||
|
||||
queryBySort() {
|
||||
noMore.value = '';
|
||||
mode.value = mode.value == Mode.MAIN_LIST_HOT
|
||||
? Mode.MAIN_LIST_TIME
|
||||
: Mode.MAIN_LIST_HOT;
|
||||
|
||||
@@ -3,7 +3,9 @@ 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/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';
|
||||
import 'package:PiliPalaX/common/skeleton/video_reply.dart';
|
||||
@@ -290,66 +292,75 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState, int index) {
|
||||
if (loadingState is Success) {
|
||||
if (index == loadingState.response.length) {
|
||||
_videoReplyReplyController.onLoadMore();
|
||||
return Container(
|
||||
padding:
|
||||
EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
|
||||
height: MediaQuery.of(context).padding.bottom + 100,
|
||||
child: Center(
|
||||
child: Obx(
|
||||
() => Text(
|
||||
_videoReplyReplyController.noMore.value,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
return switch (loadingState) {
|
||||
Loading() => CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
return const VideoReplySkeleton();
|
||||
},
|
||||
childCount: 8,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
Success() => () {
|
||||
if (index == loadingState.response.length) {
|
||||
EasyThrottle.throttle(
|
||||
'replylist', const Duration(milliseconds: 200), () {
|
||||
_videoReplyReplyController.onLoadMore();
|
||||
});
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).padding.bottom),
|
||||
height: MediaQuery.of(context).padding.bottom + 100,
|
||||
child: Center(
|
||||
child: Obx(
|
||||
() => Text(
|
||||
_videoReplyReplyController.isEnd.not
|
||||
? '加载中...'
|
||||
: loadingState.response.isEmpty
|
||||
? '还没有评论'
|
||||
: '没有更多了',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return _videoReplyReplyController.index == index
|
||||
? AnimatedBuilder(
|
||||
animation: _videoReplyReplyController.colorAnimation!,
|
||||
builder: (context, child) {
|
||||
return ColoredBox(
|
||||
color: _videoReplyReplyController.colorAnimation?.value ??
|
||||
Theme.of(Get.context!).colorScheme.onInverseSurface,
|
||||
child: _replyItem(loadingState.response[index], index),
|
||||
);
|
||||
},
|
||||
)
|
||||
: _replyItem(loadingState.response[index], index);
|
||||
}
|
||||
} else if (loadingState is Error) {
|
||||
return CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
callback: _videoReplyReplyController.onReload,
|
||||
)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
return const VideoReplySkeleton();
|
||||
},
|
||||
childCount: 8,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
return _videoReplyReplyController.index == index
|
||||
? AnimatedBuilder(
|
||||
animation: _videoReplyReplyController.colorAnimation!,
|
||||
builder: (context, child) {
|
||||
return ColoredBox(
|
||||
color: _videoReplyReplyController
|
||||
.colorAnimation?.value ??
|
||||
Theme.of(Get.context!).colorScheme.onInverseSurface,
|
||||
child: _replyItem(loadingState.response[index], index),
|
||||
);
|
||||
},
|
||||
)
|
||||
: _replyItem(loadingState.response[index], index);
|
||||
}
|
||||
}(),
|
||||
Error() => CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
callback: _videoReplyReplyController.onReload,
|
||||
)
|
||||
],
|
||||
),
|
||||
LoadingState() => throw UnimplementedError(),
|
||||
};
|
||||
}
|
||||
|
||||
Widget _replyItem(replyItem, index) {
|
||||
|
||||
Reference in New Issue
Block a user