mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-22 11:41:09 +08:00
@@ -4,16 +4,16 @@ import 'package:PiliPlus/models/common/member/contribute_type.dart';
|
||||
import 'package:PiliPlus/models/member/info.dart';
|
||||
import 'package:PiliPlus/models/space_archive/data.dart';
|
||||
import 'package:PiliPlus/models/space_archive/item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_data_controller.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class HorizontalMemberPageController extends CommonDataController {
|
||||
HorizontalMemberPageController({this.mid, required this.lastAid});
|
||||
class HorizontalMemberPageController
|
||||
extends CommonListController<SpaceArchiveData, SpaceArchiveItem> {
|
||||
HorizontalMemberPageController({this.mid, required this.currAid});
|
||||
|
||||
dynamic mid;
|
||||
|
||||
int currentPage = 0;
|
||||
|
||||
Rx<LoadingState<MemberInfoModel>> userState =
|
||||
LoadingState<MemberInfoModel>.loading().obs;
|
||||
RxMap userStat = {}.obs;
|
||||
@@ -54,27 +54,29 @@ class HorizontalMemberPageController extends CommonDataController {
|
||||
bool customHandleResponse(bool isRefresh, Success response) {
|
||||
SpaceArchiveData data = response.response;
|
||||
count.value = data.count ?? -1;
|
||||
if (currentPage == 0 || isLoadPrevious) {
|
||||
hasPrev = data.hasPrev ?? false;
|
||||
}
|
||||
if (currentPage == 0 || !isLoadPrevious) {
|
||||
hasNext = data.hasNext ?? false;
|
||||
}
|
||||
if (currentPage != 0 && loadingState.value is Success) {
|
||||
data.item ??= <SpaceArchiveItem>[];
|
||||
if (isRefresh) {
|
||||
if (isLoadPrevious) {
|
||||
data.item!.addAll((loadingState.value as Success).response);
|
||||
hasPrev = data.hasPrev ?? false;
|
||||
} else {
|
||||
data.item!.insertAll(0, (loadingState.value as Success).response);
|
||||
hasNext = data.hasNext ?? false;
|
||||
}
|
||||
}
|
||||
if (isLoadPrevious && loadingState.value is Success) {
|
||||
data.item ??= <SpaceArchiveItem>[];
|
||||
data.item!.addAll((loadingState.value as Success).response);
|
||||
} else if (!isRefresh && loadingState.value is Success) {
|
||||
data.item ??= <SpaceArchiveItem>[];
|
||||
data.item!.insertAll(0, (loadingState.value as Success).response);
|
||||
}
|
||||
firstAid = data.item?.firstOrNull?.param;
|
||||
lastAid = data.item?.lastOrNull?.param;
|
||||
loadingState.value = Success(data.item);
|
||||
isLoadPrevious = false;
|
||||
page++;
|
||||
return true;
|
||||
}
|
||||
|
||||
String? currAid;
|
||||
String? firstAid;
|
||||
String? lastAid;
|
||||
RxString order = 'pubdate'.obs;
|
||||
@@ -84,27 +86,45 @@ class HorizontalMemberPageController extends CommonDataController {
|
||||
bool hasNext = true;
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => MemberHttp.spaceArchive(
|
||||
Future<LoadingState<SpaceArchiveData>> customGetData() =>
|
||||
MemberHttp.spaceArchive(
|
||||
type: ContributeType.video,
|
||||
mid: mid,
|
||||
aid: isLoadPrevious ? firstAid : lastAid,
|
||||
aid: page == 1
|
||||
? currAid
|
||||
: isLoadPrevious
|
||||
? firstAid
|
||||
: lastAid,
|
||||
order: order.value,
|
||||
sort: isLoadPrevious ? 'asc' : null,
|
||||
sort: page != 1 && isLoadPrevious ? 'asc' : null,
|
||||
pn: null,
|
||||
next: null,
|
||||
seasonId: null,
|
||||
seriesId: null,
|
||||
includeCursor: currentPage == 0 ? true : null,
|
||||
includeCursor: page == 1 ? true : null,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
currentPage = 0;
|
||||
hasPrev = true;
|
||||
hasNext = true;
|
||||
if (!hasPrev) {
|
||||
return Future.value();
|
||||
}
|
||||
isLoadPrevious = true;
|
||||
return queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onReload() {
|
||||
firstAid = null;
|
||||
lastAid = null;
|
||||
hasNext = true;
|
||||
hasPrev = true;
|
||||
isEnd = false;
|
||||
page = 1;
|
||||
scrollController.jumpToTop();
|
||||
return super.onReload();
|
||||
}
|
||||
|
||||
void queryBySort() {
|
||||
order.value = order.value == 'pubdate' ? 'click' : 'pubdate';
|
||||
onReload();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:PiliPlus/common/skeleton/video_card_h.dart';
|
||||
import 'package:PiliPlus/common/widgets/button/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/custom_sliver_persistent_header_delegate.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/video_card/video_card_h_member_video.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/image_preview_type.dart';
|
||||
@@ -49,31 +51,12 @@ class _HorizontalMemberPageState extends State<HorizontalMemberPage> {
|
||||
_controller = Get.put(
|
||||
HorizontalMemberPageController(
|
||||
mid: widget.mid,
|
||||
lastAid: widget.videoDetailController.oid.value.toString(),
|
||||
currAid: widget.videoDetailController.oid.value.toString(),
|
||||
),
|
||||
tag: widget.videoDetailController.heroTag,
|
||||
);
|
||||
_bvid = widget.videoDetailController.bvid;
|
||||
_ownerMid = Accounts.main.mid;
|
||||
if (_controller.hasPrev) {
|
||||
_controller.scrollController.addListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
void listener() {
|
||||
if (_controller.scrollController.position.pixels == 0) {
|
||||
if (_controller.hasPrev) {
|
||||
_controller
|
||||
..isLoadPrevious = true
|
||||
..onLoadMore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.scrollController.removeListener(listener);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -104,10 +87,22 @@ class _HorizontalMemberPageState extends State<HorizontalMemberPage> {
|
||||
],
|
||||
),
|
||||
_buildUserInfo(theme, response),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => _buildVideoList(theme, _controller.loadingState.value)),
|
||||
child: refreshIndicator(
|
||||
onRefresh: _controller.onRefresh,
|
||||
child: CustomScrollView(
|
||||
controller: _controller.scrollController,
|
||||
// physics: PositionRetainedScrollPhysics(
|
||||
// shouldRetain: _controller.hasPrev,
|
||||
// parent: const ClampingScrollPhysics(),
|
||||
// ),
|
||||
slivers: [
|
||||
_buildSliverHeader(theme),
|
||||
Obx(() =>
|
||||
_buildVideoList(theme, _controller.loadingState.value)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -176,33 +171,34 @@ class _HorizontalMemberPageState extends State<HorizontalMemberPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildVideoList(ThemeData theme, LoadingState loadingState) {
|
||||
Widget _buildVideoList(
|
||||
ThemeData theme, LoadingState<List<SpaceArchiveItem>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => loadingWidget,
|
||||
Success(:var response) => Material(
|
||||
color: Colors.transparent,
|
||||
child: CustomScrollView(
|
||||
controller: _controller.scrollController,
|
||||
physics: PositionRetainedScrollPhysics(
|
||||
shouldRetain: _controller.hasPrev,
|
||||
parent: const ClampingScrollPhysics(),
|
||||
),
|
||||
slivers: [
|
||||
_buildSliverHeader(theme),
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).padding.bottom + 80,
|
||||
),
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: Grid.videoCardHDelegate(context),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == response.length - 1 && _controller.hasNext) {
|
||||
_controller.onLoadMore();
|
||||
}
|
||||
final SpaceArchiveItem videoItem = response[index];
|
||||
return VideoCardHMemberVideo(
|
||||
key: ValueKey('${videoItem.param}'),
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: Grid.videoCardHDelegate(context),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
childCount: 10,
|
||||
(context, index) {
|
||||
return const VideoCardHSkeleton();
|
||||
},
|
||||
),
|
||||
),
|
||||
Success(:var response) => response?.isNotEmpty == true
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).padding.bottom + 80,
|
||||
),
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: Grid.videoCardHDelegate(context),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == response.length - 1 && _controller.hasNext) {
|
||||
_controller.onLoadMore();
|
||||
}
|
||||
final SpaceArchiveItem videoItem = response[index];
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: VideoCardHMemberVideo(
|
||||
videoItem: videoItem,
|
||||
bvid: _bvid,
|
||||
onTap: () {
|
||||
@@ -219,17 +215,15 @@ class _HorizontalMemberPageState extends State<HorizontalMemberPage> {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
childCount: response.length,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
childCount: response!.length,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Error(:var errMsg) => scrollErrorWidget(
|
||||
controller: _controller.scrollController,
|
||||
)
|
||||
: HttpError(onReload: _controller.onReload),
|
||||
Error(:var errMsg) => HttpError(
|
||||
errMsg: errMsg,
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user