mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
226
lib/pages/member_video/controller.dart
Normal file
226
lib/pages/member_video/controller.dart
Normal file
@@ -0,0 +1,226 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/member.dart';
|
||||
import 'package:PiliPlus/http/search.dart';
|
||||
import 'package:PiliPlus/models/space_archive/data.dart';
|
||||
import 'package:PiliPlus/models/space_archive/episodic_button.dart';
|
||||
import 'package:PiliPlus/models/space_archive/item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/pages/member_contribute/view.dart' show ContributeType;
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class MemberVideoCtr
|
||||
extends CommonListController<SpaceArchiveData, SpaceArchiveItem> {
|
||||
MemberVideoCtr({
|
||||
required this.type,
|
||||
required this.mid,
|
||||
required this.seasonId,
|
||||
required this.seriesId,
|
||||
this.username,
|
||||
this.title,
|
||||
});
|
||||
|
||||
ContributeType type;
|
||||
int? seasonId;
|
||||
int? seriesId;
|
||||
final int mid;
|
||||
late RxString order = 'pubdate'.obs;
|
||||
late RxString sort = 'desc'.obs;
|
||||
RxInt count = (-1).obs;
|
||||
int? next;
|
||||
Rx<EpisodicButton> episodicButton = EpisodicButton().obs;
|
||||
final String? username;
|
||||
final String? title;
|
||||
|
||||
String? firstAid;
|
||||
String? lastAid;
|
||||
String? fromViewAid;
|
||||
bool? isLocating;
|
||||
bool? isLoadPrevious;
|
||||
bool? hasPrev;
|
||||
|
||||
@override
|
||||
Future onRefresh() async {
|
||||
if (isLocating == true) {
|
||||
if (hasPrev == true) {
|
||||
isLoadPrevious = true;
|
||||
await queryData();
|
||||
}
|
||||
} else {
|
||||
firstAid = null;
|
||||
lastAid = null;
|
||||
next = null;
|
||||
isEnd = false;
|
||||
currentPage = 0;
|
||||
await queryData();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
if (type == ContributeType.video) {
|
||||
fromViewAid = Get.parameters['from_view_aid'];
|
||||
}
|
||||
currentPage = 0;
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(
|
||||
bool isRefresh, Success<SpaceArchiveData> response) {
|
||||
SpaceArchiveData data = response.response;
|
||||
episodicButton.value = data.episodicButton ?? EpisodicButton();
|
||||
episodicButton.refresh();
|
||||
next = data.next;
|
||||
if (currentPage == 0 || isLoadPrevious == true) {
|
||||
hasPrev = data.hasPrev;
|
||||
}
|
||||
if (currentPage == 0 || isLoadPrevious != true) {
|
||||
if ((type == ContributeType.video
|
||||
? data.hasNext == false
|
||||
: data.next == 0) ||
|
||||
data.item.isNullOrEmpty) {
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
count.value = type == ContributeType.season
|
||||
? (data.item?.length ?? -1)
|
||||
: (data.count ?? -1);
|
||||
if (currentPage != 0 && loadingState.value is Success) {
|
||||
data.item ??= <SpaceArchiveItem>[];
|
||||
if (isLoadPrevious == true) {
|
||||
data.item!.addAll((loadingState.value as Success).response);
|
||||
} else {
|
||||
data.item!.insertAll(0, (loadingState.value as Success).response);
|
||||
}
|
||||
}
|
||||
firstAid = data.item?.firstOrNull?.param;
|
||||
lastAid = data.item?.lastOrNull?.param;
|
||||
isLoadPrevious = null;
|
||||
loadingState.value = LoadingState.success(data.item);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<SpaceArchiveData>> customGetData() =>
|
||||
MemberHttp.spaceArchive(
|
||||
type: type,
|
||||
mid: mid,
|
||||
aid: type == ContributeType.video
|
||||
? isLoadPrevious == true
|
||||
? firstAid
|
||||
: lastAid
|
||||
: null,
|
||||
order: type == ContributeType.video ? order.value : null,
|
||||
sort: type == ContributeType.video
|
||||
? isLoadPrevious == true
|
||||
? 'asc'
|
||||
: null
|
||||
: sort.value,
|
||||
pn: type == ContributeType.charging ? currentPage : null,
|
||||
next: next,
|
||||
seasonId: seasonId,
|
||||
seriesId: seriesId,
|
||||
includeCursor: isLocating == true && currentPage == 0 ? true : null,
|
||||
);
|
||||
|
||||
queryBySort() {
|
||||
if (type == ContributeType.video) {
|
||||
isLocating = null;
|
||||
order.value = order.value == 'pubdate' ? 'click' : 'pubdate';
|
||||
} else {
|
||||
sort.value = sort.value == 'desc' ? 'asc' : 'desc';
|
||||
}
|
||||
onReload();
|
||||
}
|
||||
|
||||
void toViewPlayAll() async {
|
||||
if (loadingState.value is Success) {
|
||||
List<SpaceArchiveItem>? list = (loadingState.value as Success).response;
|
||||
|
||||
if (list.isNullOrEmpty) return;
|
||||
|
||||
if (episodicButton.value.text == '继续播放') {
|
||||
dynamic oid = RegExp(r'oid=([\d]+)')
|
||||
.firstMatch('${episodicButton.value.uri}')
|
||||
?.group(1);
|
||||
dynamic bvid = IdUtils.av2bv(int.tryParse(oid) ?? 0);
|
||||
dynamic cid = await SearchHttp.ab2c(aid: oid, bvid: bvid);
|
||||
PageUtils.toVideoPage(
|
||||
'bvid=$bvid&cid=$cid',
|
||||
arguments: {
|
||||
'heroTag': Utils.makeHeroTag(oid),
|
||||
'sourceType': 'archive',
|
||||
'mediaId': seasonId ?? seriesId ?? mid,
|
||||
'oid': oid,
|
||||
'favTitle':
|
||||
'$username: ${title ?? episodicButton.value.text ?? '播放全部'}',
|
||||
if (seriesId == null) 'count': count.value,
|
||||
if (seasonId != null || seriesId != null)
|
||||
'mediaType': RegExp(r'page_type=([\d]+)')
|
||||
.firstMatch('${episodicButton.value.uri}')
|
||||
?.group(1),
|
||||
'desc': RegExp(r'desc=([\d]+)')
|
||||
.firstMatch('${episodicButton.value.uri}')
|
||||
?.group(1) ==
|
||||
'1',
|
||||
'sortField': RegExp(r'sort_field=([\d]+)')
|
||||
.firstMatch('${episodicButton.value.uri}')
|
||||
?.group(1),
|
||||
'isContinuePlaying': true,
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for (SpaceArchiveItem element in list!) {
|
||||
if (element.cid == null) {
|
||||
continue;
|
||||
} else {
|
||||
if (element.bvid != list.first.bvid) {
|
||||
SmartDialog.showToast('已跳过不支持播放的视频');
|
||||
}
|
||||
bool desc = seasonId != null ? false : true;
|
||||
desc = (seasonId != null || seriesId != null) &&
|
||||
(type == ContributeType.video
|
||||
? order.value == 'click'
|
||||
: sort.value == 'asc')
|
||||
? desc.not
|
||||
: desc;
|
||||
PageUtils.toVideoPage(
|
||||
'bvid=${element.bvid}&cid=${element.cid}',
|
||||
arguments: {
|
||||
'videoItem': element,
|
||||
'heroTag': Utils.makeHeroTag(element.bvid),
|
||||
'sourceType': 'archive',
|
||||
'mediaId': seasonId ?? seriesId ?? mid,
|
||||
'oid': IdUtils.bv2av(element.bvid!),
|
||||
'favTitle':
|
||||
'$username: ${title ?? episodicButton.value.text ?? '播放全部'}',
|
||||
if (seriesId == null) 'count': count.value,
|
||||
if (seasonId != null || seriesId != null)
|
||||
'mediaType': RegExp(r'page_type=([\d]+)')
|
||||
.firstMatch('${episodicButton.value.uri}')
|
||||
?.group(1),
|
||||
'desc': desc,
|
||||
if (type == ContributeType.video)
|
||||
'sortField': order.value == 'click' ? 2 : 1,
|
||||
},
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future onReload() {
|
||||
isLocating = null;
|
||||
return super.onReload();
|
||||
}
|
||||
}
|
||||
230
lib/pages/member_video/view.dart
Normal file
230
lib/pages/member_video/view.dart
Normal file
@@ -0,0 +1,230 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/custom_sliver_persistent_header_delegate.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/common/widgets/video_card_h_member_video.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/space_archive/item.dart';
|
||||
import 'package:PiliPlus/pages/member_video/controller.dart';
|
||||
import 'package:PiliPlus/pages/member_contribute/view.dart' show ContributeType;
|
||||
import 'package:PiliPlus/pages/member/controller.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class MemberVideo extends StatefulWidget {
|
||||
const MemberVideo({
|
||||
super.key,
|
||||
required this.type,
|
||||
required this.heroTag,
|
||||
required this.mid,
|
||||
this.seasonId,
|
||||
this.seriesId,
|
||||
this.title,
|
||||
});
|
||||
|
||||
final ContributeType type;
|
||||
final String? heroTag;
|
||||
final int mid;
|
||||
final int? seasonId;
|
||||
final int? seriesId;
|
||||
final String? title;
|
||||
|
||||
@override
|
||||
State<MemberVideo> createState() => _MemberVideoState();
|
||||
}
|
||||
|
||||
class _MemberVideoState extends State<MemberVideo>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
late final _controller = Get.put(
|
||||
MemberVideoCtr(
|
||||
type: widget.type,
|
||||
mid: widget.mid,
|
||||
seasonId: widget.seasonId,
|
||||
seriesId: widget.seriesId,
|
||||
username: Get.find<MemberControllerNew>(tag: widget.heroTag).username,
|
||||
title: widget.title,
|
||||
),
|
||||
tag:
|
||||
'${widget.heroTag}${widget.type.name}${widget.seasonId}${widget.seriesId}',
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Obx(() => _buildBody(_controller.loadingState.value));
|
||||
}
|
||||
|
||||
_buildBody(LoadingState<List<SpaceArchiveItem>?> loadingState) {
|
||||
final theme = Theme.of(context);
|
||||
return switch (loadingState) {
|
||||
Loading() => loadingWidget,
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
refreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _controller.onRefresh();
|
||||
},
|
||||
child: CustomScrollView(
|
||||
physics: PositionRetainedScrollPhysics(
|
||||
shouldRetain: _controller.isLocating == true,
|
||||
parent: ClampingScrollPhysics(),
|
||||
),
|
||||
slivers: [
|
||||
SliverPersistentHeader(
|
||||
pinned: false,
|
||||
floating: true,
|
||||
delegate: CustomSliverPersistentHeaderDelegate(
|
||||
extent: 40,
|
||||
bgColor: theme.colorScheme.surface,
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 8),
|
||||
Obx(
|
||||
() => Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: Text(
|
||||
_controller.count.value != -1
|
||||
? '共${_controller.count.value}视频'
|
||||
: '',
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(
|
||||
() => _controller.episodicButton.value.uri !=
|
||||
null
|
||||
? Container(
|
||||
height: 35,
|
||||
padding: EdgeInsets.only(
|
||||
left:
|
||||
_controller.count.value != -1
|
||||
? 6
|
||||
: 0),
|
||||
child: TextButton.icon(
|
||||
onPressed:
|
||||
_controller.toViewPlayAll,
|
||||
icon: Icon(
|
||||
Icons.play_circle_outline_rounded,
|
||||
size: 16,
|
||||
color:
|
||||
theme.colorScheme.secondary,
|
||||
),
|
||||
label: Text(
|
||||
_controller.episodicButton.value
|
||||
.text ??
|
||||
'播放全部',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color:
|
||||
theme.colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
const Spacer(),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
child: TextButton.icon(
|
||||
onPressed: _controller.queryBySort,
|
||||
icon: Icon(
|
||||
Icons.sort,
|
||||
size: 16,
|
||||
color: theme.colorScheme.secondary,
|
||||
),
|
||||
label: Obx(
|
||||
() => Text(
|
||||
widget.type == ContributeType.video
|
||||
? _controller.order.value ==
|
||||
'pubdate'
|
||||
? '最新发布'
|
||||
: '最多播放'
|
||||
: _controller.sort.value == 'desc'
|
||||
? '默认'
|
||||
: '倒序',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: theme.colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
top: StyleString.safeSpace - 5,
|
||||
bottom: MediaQuery.of(context).padding.bottom + 80,
|
||||
),
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: Grid.videoCardHDelegate(context),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (widget.type != ContributeType.season &&
|
||||
index == loadingState.response!.length - 1) {
|
||||
_controller.onLoadMore();
|
||||
}
|
||||
final SpaceArchiveItem item =
|
||||
loadingState.response![index];
|
||||
return VideoCardHMemberVideo(
|
||||
key: ValueKey('${item.param}'),
|
||||
videoItem: item,
|
||||
fromViewAid: _controller.fromViewAid,
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (widget.type == ContributeType.video &&
|
||||
_controller.fromViewAid?.isNotEmpty == true &&
|
||||
_controller.isLocating != true)
|
||||
Positioned(
|
||||
right: 15,
|
||||
bottom: 15,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
left: false,
|
||||
child: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
_controller
|
||||
..isLocating = true
|
||||
..lastAid = _controller.fromViewAid
|
||||
..currentPage = 0
|
||||
..loadingState.value = LoadingState.loading()
|
||||
..queryData();
|
||||
},
|
||||
label: const Text('定位至上次观看'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: scrollErrorWidget(
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
Error() => scrollErrorWidget(
|
||||
errMsg: loadingState.errMsg,
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user