feat: 稍后再看&收藏夹播放全部

Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
guozhigq
2024-09-21 15:14:38 +08:00
committed by bggRGjQaUbCoE
parent 47241897de
commit 9e8d34e0dc
13 changed files with 874 additions and 42 deletions

View File

@@ -4,6 +4,7 @@ import 'package:PiliPalaX/models/user/fav_detail.dart';
import 'package:PiliPalaX/models/user/fav_folder.dart';
import 'package:PiliPalaX/pages/common/multi_select_controller.dart';
import 'package:PiliPalaX/utils/storage.dart';
import 'package:PiliPalaX/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
@@ -123,4 +124,25 @@ class FavDetailController extends MultiSelectController {
},
);
}
Future toViewPlayAll() async {
if (loadingState.value is Success) {
final FavDetailItemData firstItem =
(loadingState.value as Success).response.first;
final String heroTag = Utils.makeHeroTag(firstItem.bvid);
Get.toNamed(
'/video?bvid=${firstItem.bvid}&cid=${firstItem.cid}',
arguments: {
'videoItem': firstItem,
'heroTag': heroTag,
'sourceType': 'fav',
'mediaId': item.value.id,
'oid': firstItem.id,
'favTitle': item.value.title,
// 'favInfo': favInfo,
'count': item.value.mediaCount,
},
);
}
}
}

View File

@@ -60,6 +60,15 @@ class _FavDetailPageState extends State<FavDetailPage> {
}
},
child: Scaffold(
floatingActionButton: Obx(
() => (_favDetailController.item.value.mediaCount ?? -1) > 0
? FloatingActionButton.extended(
onPressed: _favDetailController.toViewPlayAll,
label: const Text('播放全部'),
icon: const Icon(Icons.playlist_play),
)
: const SizedBox.shrink(),
),
body: CustomScrollView(
physics: const AlwaysScrollableScrollPhysics(),
controller: _favDetailController.scrollController,

View File

@@ -1,6 +1,7 @@
import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/models/model_hot_video_item.dart';
import 'package:PiliPalaX/pages/common/multi_select_controller.dart';
import 'package:PiliPalaX/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
@@ -162,4 +163,22 @@ class LaterController extends MultiSelectController {
SmartDialog.dismiss();
SmartDialog.showToast(res['msg']);
}
// 稍后再看播放全部
Future toViewPlayAll() async {
if (loadingState.value is Success) {
final HotVideoItemModel firstItem =
(loadingState.value as Success).response.first;
final String heroTag = Utils.makeHeroTag(firstItem.bvid);
Get.toNamed(
'/video?bvid=${firstItem.bvid}&cid=${firstItem.cid}',
arguments: {
'videoItem': firstItem,
'heroTag': heroTag,
'sourceType': 'watchLater',
'count': (loadingState.value as Success).response.length,
},
);
}
}
}

View File

@@ -95,6 +95,15 @@ class _LaterPageState extends State<LaterPage> {
],
),
),
floatingActionButton: Obx(
() => _laterController.loadingState.value is Success
? FloatingActionButton.extended(
onPressed: _laterController.toViewPlayAll,
label: const Text('播放全部'),
icon: const Icon(Icons.playlist_play),
)
: const SizedBox(),
),
body: CustomScrollView(
physics: const AlwaysScrollableScrollPhysics(),
controller: _laterController.scrollController,

View File

@@ -6,9 +6,15 @@ import 'package:PiliPalaX/common/widgets/icon_button.dart';
import 'package:PiliPalaX/common/widgets/loading_widget.dart';
import 'package:PiliPalaX/common/widgets/pair.dart';
import 'package:PiliPalaX/common/widgets/segment_progress_bar.dart';
import 'package:PiliPalaX/common/widgets/watch_later_list.dart';
import 'package:PiliPalaX/http/danmaku.dart';
import 'package:PiliPalaX/http/init.dart';
import 'package:PiliPalaX/http/user.dart';
import 'package:PiliPalaX/models/video/later.dart';
import 'package:PiliPalaX/models/video/play/subtitle.dart';
import 'package:PiliPalaX/pages/video/detail/introduction/controller.dart';
import 'package:PiliPalaX/pages/video/detail/related/controller.dart';
import 'package:PiliPalaX/pages/video/detail/reply/controller.dart';
import 'package:PiliPalaX/utils/extension.dart';
import 'package:canvas_danmaku/models/danmaku_content_item.dart';
import 'package:dio/dio.dart';
@@ -226,6 +232,11 @@ class VideoDetailController extends GetxController
imageStatus = false;
}
// 页面来源 稍后再看 收藏夹
RxString sourceType = 'normal'.obs;
List<MediaVideoItemModel> mediaList = <MediaVideoItemModel>[];
RxString watchLaterTitle = ''.obs;
@override
void onInit() {
super.onInit();
@@ -243,6 +254,17 @@ class VideoDetailController extends GetxController
videoItem['pic'] = argMap['pic'];
}
}
sourceType.value = argMap['sourceType'] ?? 'normal';
if (sourceType.value == 'watchLater') {
watchLaterTitle.value = '稍后再看';
fetchMediaList();
} else if (sourceType.value == 'fav') {
watchLaterTitle.value = argMap['favTitle'];
queryFavVideoList();
}
bool defaultShowComment =
setting.get(SettingBoxKey.defaultShowComment, defaultValue: false);
tabCtr = TabController(
@@ -269,6 +291,7 @@ class VideoDetailController extends GetxController
floating: floating,
heroTag: heroTag,
);
// CDN优化
// enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);
@@ -292,6 +315,78 @@ class VideoDetailController extends GetxController
}
}
// 获取稍后再看列表
Future fetchMediaList() async {
final Map argMap = Get.arguments;
var count = argMap['count'];
var res = await UserHttp.getMediaList(
type: 2,
bizId: userInfo.mid,
ps: count,
);
if (res['status']) {
mediaList = res['data'].reversed.toList();
} else {
SmartDialog.showToast(res['msg']);
}
}
// 稍后再看面板展开
showMediaListPanel() {
if (mediaList.isNotEmpty) {
childKey.currentState?.showBottomSheet(
(context) => MediaListPanel(
mediaList: mediaList,
changeMediaList: changeMediaList,
panelTitle: watchLaterTitle.value,
bvid: bvid,
mediaId: Get.arguments['mediaId'],
hasMore: mediaList.length != Get.arguments['count'],
),
);
}
}
// 切换稍后再看
Future changeMediaList(bvid, cid, aid, cover) async {
try {
this.bvid = bvid;
oid.value = aid ?? IdUtils.bv2av(bvid);
this.cid.value = cid;
danmakuCid.value = cid;
videoItem['pic'] = cover;
queryVideoUrl();
Get.find<VideoReplyController>(tag: heroTag)
..aid = aid
..onRefresh();
Get.find<VideoIntroController>(tag: heroTag)
..lastPlayCid.value = cid
..bvid = bvid
..queryVideoIntro();
Get.find<RelatedController>(tag: heroTag)
..bvid = bvid
..onRefresh();
} catch (_) {}
}
// 获取收藏夹视频列表
Future queryFavVideoList() async {
final Map argMap = Get.arguments;
var mediaId = argMap['mediaId'];
var oid = argMap['oid'];
var res = await UserHttp.parseFavVideo(
mediaId: mediaId,
oid: oid,
bvid: bvid,
);
if (res['status']) {
mediaList = res['data'];
}
}
int? _lastPos;
double? _blockLimit;
List<Pair<SegmentType, SkipType>>? _blockSettings;

View File

@@ -121,7 +121,7 @@ class VideoIntroController extends GetxController
Get.find<VideoDetailController>(tag: heroTag);
// 获取视频简介&分p
void queryVideoIntro() async {
Future queryVideoIntro() async {
await queryVideoTags();
var result = await VideoHttp.videoIntro(bvid: bvid);
if (result['status']) {
@@ -649,7 +649,13 @@ class VideoIntroController extends GetxController
bool nextPlay() {
final List episodes = [];
bool isPages = false;
if ((videoDetail.value.pages?.length ?? 0) > 1) {
final VideoDetailController videoDetailCtr =
Get.find<VideoDetailController>(tag: heroTag);
if (videoDetailController.sourceType.value == 'watchLater' ||
videoDetailController.sourceType.value == 'fav') {
episodes.addAll(videoDetailCtr.mediaList);
} else if ((videoDetail.value.pages?.length ?? 0) > 1) {
isPages = true;
final List<Part> pages = videoDetail.value.pages!;
episodes.addAll(pages);
@@ -661,8 +667,7 @@ class VideoIntroController extends GetxController
episodes.addAll(episodesList);
}
}
final VideoDetailController videoDetailCtr =
Get.find<VideoDetailController>(tag: heroTag);
final PlayRepeat platRepeat = videoDetailCtr.plPlayerController.playRepeat;
if (episodes.isEmpty) {
@@ -676,6 +681,13 @@ class VideoIntroController extends GetxController
episodes.indexWhere((e) => e.cid == lastPlayCid.value);
int nextIndex = currentIndex + 1;
int cid = episodes[nextIndex].cid!;
while (cid == -1) {
nextIndex++;
SmartDialog.showToast('当前视频暂不支持播放,自动跳过');
cid = episodes[nextIndex].cid!;
}
// 列表循环
if (nextIndex >= episodes.length) {
if (platRepeat == PlayRepeat.listCycle) {
@@ -686,7 +698,6 @@ class VideoIntroController extends GetxController
return false;
}
}
final int cid = episodes[nextIndex].cid!;
final String rBvid = isPages ? bvid : episodes[nextIndex].bvid;
final int rAid = isPages ? IdUtils.bv2av(bvid) : episodes[nextIndex].aid!;
changeSeasonOrbangu(null, rBvid, cid, rAid, null);

View File

@@ -1286,46 +1286,102 @@ class _VideoDetailPageState extends State<VideoDetailPage>
);
Widget videoIntro([bool needRelated = true]) {
return CustomScrollView(
controller: _introController,
slivers: [
if (videoDetailController.videoType == SearchType.video) ...[
VideoIntroPanel(
heroTag: heroTag,
showAiBottomSheet: showAiBottomSheet,
showIntroDetail: showIntroDetail,
showEpisodes: showEpisodes,
),
if (needRelated) ...[
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(
top: StyleString.safeSpace,
Widget introPanel() => CustomScrollView(
controller: _introController,
slivers: [
if (videoDetailController.videoType == SearchType.video) ...[
VideoIntroPanel(
heroTag: heroTag,
showAiBottomSheet: showAiBottomSheet,
showIntroDetail: showIntroDetail,
showEpisodes: showEpisodes,
),
if (needRelated) ...[
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(
top: StyleString.safeSpace,
),
child: Divider(
height: 1,
indent: 12,
endIndent: 12,
color: Theme.of(context).dividerColor.withOpacity(0.06),
),
),
),
child: Divider(
height: 1,
indent: 12,
endIndent: 12,
color: Theme.of(context).dividerColor.withOpacity(0.06),
RelatedVideoPanel(heroTag: heroTag),
],
] else if (videoDetailController.videoType ==
SearchType.media_bangumi)
Obx(
() => BangumiIntroPanel(
heroTag: heroTag,
cid: videoDetailController.cid.value,
showEpisodes: showEpisodes,
showIntroDetail: showIntroDetail,
),
),
SliverToBoxAdapter(
child: SizedBox(height: MediaQuery.paddingOf(context).bottom),
)
],
);
if (videoDetailController.sourceType.value == 'watchLater' ||
videoDetailController.sourceType.value == 'fav') {
return Stack(
children: [
introPanel(),
Obx(
() => AnimatedPositioned(
duration: const Duration(milliseconds: 400),
curve: Curves.easeInOut,
left: 12,
right: 12,
bottom: MediaQuery.of(context).padding.bottom + 12,
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: videoDetailController.showMediaListPanel,
borderRadius: const BorderRadius.all(Radius.circular(14)),
child: Container(
height: 54,
padding: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.secondaryContainer
.withOpacity(0.95),
borderRadius: const BorderRadius.all(Radius.circular(14)),
),
child: Row(
children: [
const Icon(Icons.playlist_play, size: 24),
const SizedBox(width: 10),
Text(
videoDetailController.watchLaterTitle.value,
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onSecondaryContainer,
fontWeight: FontWeight.bold,
letterSpacing: 0.2,
),
),
const Spacer(),
const Icon(Icons.keyboard_arrow_up_rounded, size: 26),
],
),
),
),
),
),
RelatedVideoPanel(heroTag: heroTag),
],
] else if (videoDetailController.videoType == SearchType.media_bangumi)
Obx(
() => BangumiIntroPanel(
heroTag: heroTag,
cid: videoDetailController.cid.value,
showEpisodes: showEpisodes,
showIntroDetail: showIntroDetail,
),
),
SliverToBoxAdapter(
child: SizedBox(height: MediaQuery.paddingOf(context).bottom),
)
],
);
],
);
} else {
return introPanel();
}
}
Widget get videoReplyPanel => Obx(