mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-01 08:38:18 +08:00
feat: custom horizontal season panel
Closes #50 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -691,13 +691,6 @@ 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) {
|
||||
@@ -709,6 +702,18 @@ class VideoIntroController extends GetxController
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int cid = episodes[nextIndex].cid!;
|
||||
|
||||
while (cid == -1) {
|
||||
SmartDialog.showToast('当前视频暂不支持播放,自动跳过');
|
||||
nextIndex++;
|
||||
if (nextIndex >= episodes.length) {
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -627,7 +627,11 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
// 点赞收藏转发 布局样式2
|
||||
if (!isHorizontal) actionGrid(context, videoIntroController),
|
||||
// 合集
|
||||
if (!loadingStatus && widget.videoDetail?.ugcSeason != null) ...[
|
||||
if (!loadingStatus &&
|
||||
widget.videoDetail?.ugcSeason != null &&
|
||||
(context.orientation != Orientation.landscape ||
|
||||
(context.orientation == Orientation.landscape &&
|
||||
videoDetailCtr.horizontalSeasonPanel.not)))
|
||||
Obx(
|
||||
() => SeasonPanel(
|
||||
heroTag: heroTag,
|
||||
@@ -641,11 +645,13 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
showEpisodes: widget.showEpisodes,
|
||||
pages: widget.videoDetail!.pages,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
if (!loadingStatus &&
|
||||
widget.videoDetail?.pages != null &&
|
||||
widget.videoDetail!.pages!.length > 1) ...[
|
||||
widget.videoDetail!.pages!.length > 1 &&
|
||||
(context.orientation != Orientation.landscape ||
|
||||
(context.orientation == Orientation.landscape &&
|
||||
videoDetailCtr.horizontalSeasonPanel.not))) ...[
|
||||
Obx(
|
||||
() => PagesPanel(
|
||||
heroTag: heroTag,
|
||||
|
||||
@@ -30,7 +30,7 @@ class PagesPanel extends StatefulWidget {
|
||||
|
||||
class _PagesPanelState extends State<PagesPanel> {
|
||||
late int cid;
|
||||
late int currentIndex;
|
||||
late int pageIndex;
|
||||
// final String heroTag = Get.arguments['heroTag'];
|
||||
late final String heroTag;
|
||||
late VideoDetailController _videoDetailController;
|
||||
@@ -42,14 +42,13 @@ class _PagesPanelState extends State<PagesPanel> {
|
||||
cid = widget.cid;
|
||||
heroTag = widget.heroTag;
|
||||
_videoDetailController = Get.find<VideoDetailController>(tag: heroTag);
|
||||
currentIndex = widget.pages.indexWhere((Part e) => e.cid == cid);
|
||||
pageIndex = widget.pages.indexWhere((Part e) => e.cid == cid);
|
||||
_videoDetailController.cid.listen((int p0) {
|
||||
cid = p0;
|
||||
currentIndex = max(0, widget.pages.indexWhere((Part e) => e.cid == cid));
|
||||
pageIndex = max(0, widget.pages.indexWhere((Part e) => e.cid == cid));
|
||||
if (!mounted) return;
|
||||
const double itemWidth = 150; // 每个列表项的宽度
|
||||
final double targetOffset = min(
|
||||
(currentIndex * itemWidth) - (itemWidth / 2),
|
||||
final double targetOffset = min((pageIndex * itemWidth) - (itemWidth / 2),
|
||||
_scrollController.position.maxScrollExtent);
|
||||
// 滑动至目标位置
|
||||
_scrollController.animateTo(
|
||||
@@ -78,7 +77,7 @@ class _PagesPanelState extends State<PagesPanel> {
|
||||
const Text('视频选集 '),
|
||||
Expanded(
|
||||
child: Text(
|
||||
' 正在播放:${widget.pages[currentIndex].pagePart}',
|
||||
' 正在播放:${widget.pages[pageIndex].pagePart}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
@@ -119,7 +118,7 @@ class _PagesPanelState extends State<PagesPanel> {
|
||||
itemCount: widget.pages.length,
|
||||
itemExtent: 150,
|
||||
itemBuilder: (BuildContext context, int i) {
|
||||
bool isCurrentIndex = currentIndex == i;
|
||||
bool isCurrentIndex = pageIndex == i;
|
||||
return Container(
|
||||
width: 150,
|
||||
margin: EdgeInsets.only(
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/models/video_detail_res.dart';
|
||||
@@ -12,6 +14,7 @@ class SeasonPanel extends StatefulWidget {
|
||||
required this.heroTag,
|
||||
required this.showEpisodes,
|
||||
required this.pages,
|
||||
this.onTap,
|
||||
});
|
||||
final UgcSeason ugcSeason;
|
||||
final int? cid;
|
||||
@@ -19,48 +22,55 @@ class SeasonPanel extends StatefulWidget {
|
||||
final String heroTag;
|
||||
final Function showEpisodes;
|
||||
final List<Part>? pages;
|
||||
final bool? onTap;
|
||||
|
||||
@override
|
||||
State<SeasonPanel> createState() => _SeasonPanelState();
|
||||
}
|
||||
|
||||
class _SeasonPanelState extends State<SeasonPanel> {
|
||||
List<EpisodeItem>? episodes;
|
||||
late int cid;
|
||||
int? _index;
|
||||
int currentIndex = 0;
|
||||
late VideoDetailController _videoDetailController;
|
||||
StreamSubscription? _listener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
cid = widget.cid!;
|
||||
_videoDetailController =
|
||||
Get.find<VideoDetailController>(tag: widget.heroTag);
|
||||
Get.find<VideoDetailController>(tag: widget.heroTag)
|
||||
..seasonCid = widget.cid!;
|
||||
|
||||
/// 根据 cid 找到对应集,找到对应 episodes
|
||||
/// 有多个episodes时,只显示其中一个
|
||||
_findEpisode();
|
||||
if (episodes == null) {
|
||||
if (_videoDetailController.episodes.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
/// 取对应 season_id 的 episodes
|
||||
// episodes = widget.ugcSeason.sections!
|
||||
// .firstWhere((e) => e.seasonId == widget.ugcSeason.id)
|
||||
// .episodes!;
|
||||
currentIndex = episodes!.indexWhere((EpisodeItem e) => e.cid == cid);
|
||||
_videoDetailController.cid.listen((int p0) {
|
||||
// .episodes;
|
||||
currentIndex = _videoDetailController.episodes.indexWhere(
|
||||
(EpisodeItem e) => e.cid == _videoDetailController.seasonCid);
|
||||
_listener = _videoDetailController.cid.listen((int p0) {
|
||||
bool isPart = widget.pages?.indexWhere((item) => item.cid == p0) != -1;
|
||||
if (isPart) return;
|
||||
cid = p0;
|
||||
_videoDetailController.seasonCid = p0;
|
||||
_findEpisode();
|
||||
currentIndex = episodes!.indexWhere((EpisodeItem e) => e.cid == cid);
|
||||
currentIndex = _videoDetailController.episodes.indexWhere(
|
||||
(EpisodeItem e) => e.cid == _videoDetailController.seasonCid);
|
||||
if (!mounted) return;
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_listener?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// void changeFucCall(item, int i) async {
|
||||
// await widget.changeFuc!(
|
||||
// IdUtils.av2bv(item.aid),
|
||||
@@ -74,7 +84,7 @@ class _SeasonPanelState extends State<SeasonPanel> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (episodes == null) {
|
||||
if (_videoDetailController.episodes.isEmpty) {
|
||||
return const SizedBox();
|
||||
}
|
||||
return Builder(builder: (BuildContext context) {
|
||||
@@ -90,14 +100,16 @@ class _SeasonPanelState extends State<SeasonPanel> {
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: InkWell(
|
||||
onTap: () => widget.showEpisodes(
|
||||
_index,
|
||||
widget.ugcSeason,
|
||||
episodes,
|
||||
_videoDetailController.bvid,
|
||||
null,
|
||||
cid,
|
||||
),
|
||||
onTap: widget.onTap == false
|
||||
? null
|
||||
: () => widget.showEpisodes(
|
||||
_videoDetailController.seasonIndex.value,
|
||||
widget.ugcSeason,
|
||||
_videoDetailController.episodes,
|
||||
_videoDetailController.bvid,
|
||||
null,
|
||||
_videoDetailController.seasonCid,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 12, 8, 12),
|
||||
child: Row(
|
||||
@@ -118,10 +130,10 @@ class _SeasonPanelState extends State<SeasonPanel> {
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'${currentIndex + 1}/${episodes!.length}',
|
||||
'${currentIndex + 1}/${_videoDetailController.episodes.length}',
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
semanticsLabel:
|
||||
'第${currentIndex + 1}集,共${episodes!.length}集',
|
||||
'第${currentIndex + 1}集,共${_videoDetailController.episodes.length}集',
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
const Icon(
|
||||
@@ -143,9 +155,9 @@ class _SeasonPanelState extends State<SeasonPanel> {
|
||||
for (int i = 0; i < sections.length; i++) {
|
||||
final List<EpisodeItem> episodesList = sections[i].episodes!;
|
||||
for (int j = 0; j < episodesList.length; j++) {
|
||||
if (episodesList[j].cid == cid) {
|
||||
_index = i;
|
||||
episodes = episodesList;
|
||||
if (episodesList[j].cid == _videoDetailController.seasonCid) {
|
||||
_videoDetailController.seasonIndex.value = i;
|
||||
_videoDetailController.episodes.value = episodesList;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user