mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: query data (#659)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -111,7 +111,7 @@ class VideoInfo extends StatefulWidget {
|
||||
State<VideoInfo> createState() => _VideoInfoState();
|
||||
}
|
||||
|
||||
class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
class _VideoInfoState extends State<VideoInfo> {
|
||||
late final VideoDetailController videoDetailCtr;
|
||||
|
||||
Map get videoItem => videoIntroController.videoItem;
|
||||
|
||||
@@ -2,13 +2,13 @@ import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/member.dart';
|
||||
import 'package:PiliPlus/models/space_archive/data.dart';
|
||||
import 'package:PiliPlus/models/space_archive/item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/pages/common/common_data_controller.dart';
|
||||
import 'package:PiliPlus/pages/member/new/content/member_contribute/member_contribute.dart'
|
||||
show ContributeType;
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class HorizontalMemberPageController extends CommonController {
|
||||
class HorizontalMemberPageController extends CommonDataController {
|
||||
HorizontalMemberPageController({this.mid, required this.lastAid});
|
||||
|
||||
dynamic mid;
|
||||
@@ -52,7 +52,7 @@ class HorizontalMemberPageController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
bool customHandleResponse(bool isRefresh, Success response) {
|
||||
Data data = response.response;
|
||||
count.value = data.count ?? -1;
|
||||
if (currentPage == 0 || isLoadPrevious) {
|
||||
|
||||
@@ -130,7 +130,7 @@ class _NoteListPageState extends CommonSlidePageState<NoteListPage> {
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<dynamic>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => CustomScrollView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
@@ -145,7 +145,7 @@ class _NoteListPageState extends CommonSlidePageState<NoteListPage> {
|
||||
)
|
||||
],
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? refreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _controller.onRefresh();
|
||||
@@ -156,12 +156,13 @@ class _NoteListPageState extends CommonSlidePageState<NoteListPage> {
|
||||
slivers: [
|
||||
SliverList.separated(
|
||||
itemBuilder: (context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_controller.onLoadMore();
|
||||
}
|
||||
return _itemWidget(context, loadingState.response[index]);
|
||||
return _itemWidget(
|
||||
context, loadingState.response![index]);
|
||||
},
|
||||
itemCount: loadingState.response.length,
|
||||
itemCount: loadingState.response!.length,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
height: 1,
|
||||
color: Theme.of(context)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class NoteListPageCtr extends CommonController {
|
||||
class NoteListPageCtr extends CommonListController {
|
||||
NoteListPageCtr({this.oid, this.upperMid});
|
||||
final dynamic oid;
|
||||
final dynamic upperMid;
|
||||
@@ -18,21 +17,22 @@ class NoteListPageCtr extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
List? getDataList(response) {
|
||||
return response['list'];
|
||||
}
|
||||
|
||||
@override
|
||||
void checkIsEnd(int length) {
|
||||
if (count.value != -1 && length >= count.value) {
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success response) {
|
||||
dynamic data = response.response;
|
||||
count.value = data['page']?['total'] ?? -1;
|
||||
if ((data['list'] as List?).isNullOrEmpty) {
|
||||
isEnd = true;
|
||||
}
|
||||
if (currentPage != 1 && loadingState.value is Success) {
|
||||
data['list'] ??= [];
|
||||
data['list'].insertAll(0, (loadingState.value as Success).response);
|
||||
}
|
||||
if (isEnd.not && count.value != -1 && data['list'].length >= count.value) {
|
||||
isEnd = true;
|
||||
}
|
||||
loadingState.value = LoadingState.success(data['list']);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/models/model_hot_video_item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
|
||||
class RelatedController extends CommonController {
|
||||
class RelatedController
|
||||
extends CommonListController<List<HotVideoItemModel>?, HotVideoItemModel> {
|
||||
// 视频aid
|
||||
String bvid = Get.parameters['bvid'] ?? "";
|
||||
|
||||
@@ -14,6 +16,6 @@ class RelatedController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() =>
|
||||
Future<LoadingState<List<HotVideoItemModel>?>> customGetData() =>
|
||||
VideoHttp.relatedVideoList(bvid: bvid);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/model_hot_video_item.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_card_h.dart';
|
||||
@@ -32,7 +33,7 @@ class _RelatedVideoPanelState extends State<RelatedVideoPanel>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<HotVideoItemModel>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
@@ -47,7 +48,7 @@ class _RelatedVideoPanelState extends State<RelatedVideoPanel>
|
||||
childCount: 5,
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: 2,
|
||||
@@ -55,17 +56,17 @@ class _RelatedVideoPanelState extends State<RelatedVideoPanel>
|
||||
childAspectRatio: StyleString.aspectRatio * 2.2,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
if (index == loadingState.response.length) {
|
||||
if (index == loadingState.response!.length) {
|
||||
return SizedBox(
|
||||
height: MediaQuery.of(context).padding.bottom,
|
||||
);
|
||||
} else {
|
||||
return VideoCardH(
|
||||
videoItem: loadingState.response[index],
|
||||
videoItem: loadingState.response![index],
|
||||
showPubdate: true,
|
||||
);
|
||||
}
|
||||
}, childCount: loadingState.response.length + 1),
|
||||
}, childCount: loadingState.response!.length + 1),
|
||||
)
|
||||
: SliverToBoxAdapter(),
|
||||
Error() => HttpError(
|
||||
|
||||
@@ -7,7 +7,7 @@ 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
|
||||
class VideoReplyController extends ReplyController<MainListReply>
|
||||
with GetTickerProviderStateMixin {
|
||||
VideoReplyController({required this.aid});
|
||||
// 视频aid 请求时使用的oid
|
||||
@@ -36,7 +36,13 @@ class VideoReplyController extends ReplyController
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => ReplyHttp.replyListGrpc(
|
||||
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),
|
||||
|
||||
@@ -45,7 +45,7 @@ class VideoReplyPanel extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
late VideoReplyController _videoReplyController;
|
||||
|
||||
String get heroTag => widget.heroTag;
|
||||
@@ -202,12 +202,12 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
childCount: 5,
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response.replies as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, index) {
|
||||
double bottom = MediaQuery.of(context).padding.bottom;
|
||||
if (index == loadingState.response.replies.length) {
|
||||
if (index == loadingState.response.length) {
|
||||
_videoReplyController.onLoadMore();
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
@@ -216,7 +216,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
child: Text(
|
||||
_videoReplyController.isEnd.not
|
||||
? '加载中...'
|
||||
: loadingState.response.replies.isEmpty
|
||||
: loadingState.response.isEmpty
|
||||
? '还没有评论'
|
||||
: '没有更多了',
|
||||
style: TextStyle(
|
||||
@@ -227,18 +227,19 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
);
|
||||
} else {
|
||||
return ReplyItemGrpc(
|
||||
replyItem: loadingState.response.replies[index],
|
||||
replyItem: loadingState.response[index],
|
||||
replyLevel: widget.replyLevel,
|
||||
replyReply: widget.replyReply,
|
||||
onReply: () {
|
||||
_videoReplyController.onReply(
|
||||
context,
|
||||
replyItem: loadingState.response.replies[index],
|
||||
replyItem: loadingState.response[index],
|
||||
index: index,
|
||||
);
|
||||
},
|
||||
onDelete: _videoReplyController.onMDelete,
|
||||
upMid: loadingState.response.subjectControl.upMid,
|
||||
onDelete: (subIndex) =>
|
||||
_videoReplyController.onRemove(index, subIndex),
|
||||
upMid: _videoReplyController.upMid,
|
||||
getTag: () => heroTag,
|
||||
onViewImage: widget.onViewImage,
|
||||
onDismissed: widget.onDismissed,
|
||||
@@ -256,7 +257,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
);
|
||||
}
|
||||
},
|
||||
childCount: loadingState.response.replies.length + 1,
|
||||
childCount: loadingState.response.length + 1,
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
|
||||
@@ -49,7 +49,7 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
final Function(ReplyInfo replyItem, int? rpid)? replyReply;
|
||||
final bool needDivider;
|
||||
final VoidCallback? onReply;
|
||||
final Function(dynamic rpid, dynamic frpid)? onDelete;
|
||||
final ValueChanged<int?>? onDelete;
|
||||
final dynamic upMid;
|
||||
final VoidCallback? showDialogue;
|
||||
final Function? getTag;
|
||||
@@ -88,8 +88,8 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
return morePanel(
|
||||
context: context,
|
||||
item: replyItem,
|
||||
onDelete: (rpid) {
|
||||
onDelete?.call(rpid, null);
|
||||
onDelete: () {
|
||||
onDelete?.call(null);
|
||||
},
|
||||
isSubReply: false,
|
||||
);
|
||||
@@ -549,8 +549,8 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
return morePanel(
|
||||
context: context,
|
||||
item: replyItem.replies[i],
|
||||
onDelete: (rpid) {
|
||||
onDelete?.call(rpid, replyItem.id.toInt());
|
||||
onDelete: () {
|
||||
onDelete?.call(i);
|
||||
},
|
||||
isSubReply: true,
|
||||
);
|
||||
@@ -1116,7 +1116,7 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
Options(contentType: Headers.formUrlEncodedContentType),
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
onDelete?.call(item.id.toInt());
|
||||
onDelete?.call();
|
||||
}
|
||||
return res.data as Map;
|
||||
},
|
||||
@@ -1199,7 +1199,7 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
SmartDialog.dismiss();
|
||||
if (result['status']) {
|
||||
SmartDialog.showToast('删除成功');
|
||||
onDelete?.call(item.id.toInt());
|
||||
onDelete?.call();
|
||||
} else {
|
||||
SmartDialog.showToast('删除失败, ${result["msg"]}');
|
||||
}
|
||||
|
||||
@@ -31,8 +31,6 @@ class VideoReplyReplyController extends ReplyController
|
||||
int rpid;
|
||||
ReplyType replyType; // = ReplyType.video;
|
||||
|
||||
int? upMid;
|
||||
|
||||
dynamic firstFloor;
|
||||
|
||||
int? index;
|
||||
@@ -58,17 +56,26 @@ class VideoReplyReplyController extends ReplyController
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
dynamic replies = response.response;
|
||||
List<ReplyInfo>? getDataList(response) {
|
||||
return isDialogue ? response.replies : response.root.replies;
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success response) {
|
||||
final data = response.response;
|
||||
|
||||
upMid ??= data.subjectControl.upMid.toInt();
|
||||
cursor = data.cursor;
|
||||
isEnd = cursor?.isEnd ?? false;
|
||||
|
||||
// reply2Reply // isDialogue.not
|
||||
if (replies is DetailListReply) {
|
||||
count.value = replies.root.count.toInt();
|
||||
if (data is DetailListReply) {
|
||||
count.value = data.root.count.toInt();
|
||||
if (cursor == null && firstFloor == null) {
|
||||
firstFloor = replies.root;
|
||||
firstFloor = data.root;
|
||||
}
|
||||
if (id != null) {
|
||||
index =
|
||||
replies.root.replies.indexWhere((item) => item.id.toInt() == id);
|
||||
index = data.root.replies.indexWhere((item) => item.id.toInt() == id);
|
||||
if (index == -1) {
|
||||
index = null;
|
||||
} else {
|
||||
@@ -93,43 +100,8 @@ class VideoReplyReplyController extends ReplyController
|
||||
id = null;
|
||||
}
|
||||
}
|
||||
upMid ??= replies.subjectControl.upMid.toInt();
|
||||
cursor = replies.cursor;
|
||||
if (isDialogue) {
|
||||
if (replies.replies.isEmpty) {
|
||||
isEnd = true;
|
||||
}
|
||||
} else {
|
||||
if (replies.root.replies.isEmpty) {
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
if (currentPage != 1) {
|
||||
List<ReplyInfo> list = loadingState.value is Success
|
||||
? (loadingState.value as Success).response
|
||||
: <ReplyInfo>[];
|
||||
if (isDialogue) {
|
||||
replies.replies.insertAll(0, list);
|
||||
} else {
|
||||
replies.root.replies.insertAll(0, list);
|
||||
}
|
||||
}
|
||||
if (isDialogue) {
|
||||
if (replies.cursor.isEnd || replies.replies.length >= count.value) {
|
||||
isEnd = true;
|
||||
}
|
||||
} else {
|
||||
if (replies.cursor.isEnd || replies.root.replies.length >= count.value) {
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
if (isDialogue) {
|
||||
loadingState.value = LoadingState.success(replies.replies);
|
||||
} else {
|
||||
loadingState.value = LoadingState.success(replies.root.replies);
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -358,8 +358,7 @@ class _VideoReplyReplyPanelState
|
||||
: <ReplyInfo>[];
|
||||
list.insert(index + 1, replyInfo);
|
||||
_videoReplyReplyController.count.value += 1;
|
||||
_videoReplyReplyController.loadingState.value =
|
||||
LoadingState.success(list);
|
||||
_videoReplyReplyController.loadingState.refresh();
|
||||
if (_videoReplyReplyController.enableCommAntifraud && mounted) {
|
||||
_videoReplyReplyController.checkReply(
|
||||
context: context,
|
||||
@@ -456,13 +455,12 @@ class _VideoReplyReplyPanelState
|
||||
onReply: () {
|
||||
_onReply(replyItem, index);
|
||||
},
|
||||
onDelete: (rpid, frpid) {
|
||||
List list =
|
||||
onDelete: (subIndex) {
|
||||
List<ReplyInfo> list =
|
||||
(_videoReplyReplyController.loadingState.value as Success).response;
|
||||
list = list.where((item) => item.id != rpid).toList();
|
||||
list.removeAt(index);
|
||||
_videoReplyReplyController.count.value -= 1;
|
||||
_videoReplyReplyController.loadingState.value =
|
||||
LoadingState.success(list);
|
||||
_videoReplyReplyController.loadingState.refresh();
|
||||
},
|
||||
upMid: _videoReplyReplyController.upMid,
|
||||
showDialogue: () {
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:PiliPlus/common/widgets/episode_panel.dart';
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/main.dart';
|
||||
import 'package:PiliPlus/models/bangumi/info.dart';
|
||||
import 'package:PiliPlus/models/common/reply_type.dart';
|
||||
import 'package:PiliPlus/pages/bangumi/introduction/widgets/intro_detail.dart'
|
||||
as bangumi;
|
||||
@@ -140,7 +141,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
|
||||
_listenerLoadingState =
|
||||
bangumiIntroController.loadingState.listen((value) {
|
||||
if (!context.mounted) return;
|
||||
if (value is Success) {
|
||||
if (value is Success<BangumiInfoModel>) {
|
||||
videoPlayerServiceHandler.onVideoDetailChange(
|
||||
value.response, videoDetailController.cid.value, heroTag);
|
||||
}
|
||||
|
||||
@@ -30,16 +30,6 @@ class _ExpandedSectionState extends State<ExpandedSection>
|
||||
_runExpandCheck();
|
||||
}
|
||||
|
||||
///Setting up the animation
|
||||
// void prepareAnimations() {
|
||||
// expandController = AnimationController(
|
||||
// vsync: this, duration: const Duration(milliseconds: 500));
|
||||
// animation = CurvedAnimation(
|
||||
// parent: expandController,
|
||||
// curve: Curves.fastOutSlowIn,
|
||||
// );
|
||||
// }
|
||||
|
||||
void prepareAnimations() {
|
||||
expandController = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 400));
|
||||
|
||||
Reference in New Issue
Block a user