fix: season currentIndex

This commit is contained in:
guozhigq
2024-11-09 23:22:19 +08:00
parent 9c80112979
commit 43d866bfe1
3 changed files with 45 additions and 4 deletions

View File

@ -21,6 +21,7 @@ class EpisodeBottomSheet {
bool isFullScreen = false; bool isFullScreen = false;
final UgcSeason? ugcSeason; final UgcSeason? ugcSeason;
final int? currentEpisodeIndex; final int? currentEpisodeIndex;
final int? currentIndex;
EpisodeBottomSheet({ EpisodeBottomSheet({
required this.episodes, required this.episodes,
@ -32,6 +33,7 @@ class EpisodeBottomSheet {
this.isFullScreen = false, this.isFullScreen = false,
this.ugcSeason, this.ugcSeason,
this.currentEpisodeIndex, this.currentEpisodeIndex,
this.currentIndex,
}); });
Widget buildShowContent() { Widget buildShowContent() {
@ -45,6 +47,7 @@ class EpisodeBottomSheet {
isFullScreen: isFullScreen, isFullScreen: isFullScreen,
ugcSeason: ugcSeason, ugcSeason: ugcSeason,
currentEpisodeIndex: currentEpisodeIndex, currentEpisodeIndex: currentEpisodeIndex,
currentIndex: currentIndex,
); );
} }
@ -71,6 +74,7 @@ class PagesBottomSheet extends StatefulWidget {
this.isFullScreen = false, this.isFullScreen = false,
this.ugcSeason, this.ugcSeason,
this.currentEpisodeIndex, this.currentEpisodeIndex,
this.currentIndex,
}); });
final List<dynamic> episodes; final List<dynamic> episodes;
@ -82,6 +86,7 @@ class PagesBottomSheet extends StatefulWidget {
final bool isFullScreen; final bool isFullScreen;
final UgcSeason? ugcSeason; final UgcSeason? ugcSeason;
final int? currentEpisodeIndex; final int? currentEpisodeIndex;
final int? currentIndex;
@override @override
State<PagesBottomSheet> createState() => _PagesBottomSheetState(); State<PagesBottomSheet> createState() => _PagesBottomSheetState();
@ -100,7 +105,7 @@ class _PagesBottomSheetState extends State<PagesBottomSheet>
@override @override
void initState() { void initState() {
super.initState(); super.initState();
currentIndex = currentIndex = widget.currentIndex ??
widget.episodes.indexWhere((dynamic e) => e.cid == widget.currentCid); widget.episodes.indexWhere((dynamic e) => e.cid == widget.currentCid);
_scrollToInit(); _scrollToInit();
_scrollPositionInit(); _scrollPositionInit();

View File

@ -641,6 +641,7 @@ class EpisodeItem {
this.page, this.page,
this.bvid, this.bvid,
this.cover, this.cover,
this.pages,
}); });
int? seasonId; int? seasonId;
int? sectionId; int? sectionId;
@ -655,6 +656,7 @@ class EpisodeItem {
int? pubdate; int? pubdate;
int? duration; int? duration;
Stat? stat; Stat? stat;
List<Page>? pages;
EpisodeItem.fromJson(Map<String, dynamic> json) { EpisodeItem.fromJson(Map<String, dynamic> json) {
seasonId = json['season_id']; seasonId = json['season_id'];
@ -670,6 +672,7 @@ class EpisodeItem {
pubdate = json['arc']['pubdate']; pubdate = json['arc']['pubdate'];
duration = json['arc']['duration']; duration = json['arc']['duration'];
stat = Stat.fromJson(json['arc']['stat']); stat = Stat.fromJson(json['arc']['stat']);
pages = json['pages'].map<Page>((e) => Page.fromJson(e)).toList();
} }
} }
@ -712,3 +715,18 @@ class Vip {
status = json['status']; status = json['status'];
} }
} }
class Page {
Page({
this.cid,
this.page,
});
int? cid;
int? page;
Page.fromJson(Map<String, dynamic> json) {
cid = json['cid'];
page = json['page'];
}
}

View File

@ -33,7 +33,7 @@ class _SeasonPanelState extends State<SeasonPanel> {
final String heroTag = Get.arguments['heroTag']; final String heroTag = Get.arguments['heroTag'];
late VideoDetailController _videoDetailController; late VideoDetailController _videoDetailController;
late PersistentBottomSheetController? _bottomSheetController; late PersistentBottomSheetController? _bottomSheetController;
int currentEpisodeIndex = 0; int currentEpisodeIndex = -1;
@override @override
void initState() { void initState() {
@ -55,10 +55,10 @@ class _SeasonPanelState extends State<SeasonPanel> {
} }
/// 取对应 season_id 的 episodes /// 取对应 season_id 的 episodes
currentIndex.value = episodes.indexWhere((EpisodeItem e) => e.cid == cid); getCurrentIndex();
_videoDetailController.cid.listen((int p0) { _videoDetailController.cid.listen((int p0) {
cid = p0; cid = p0;
currentIndex.value = episodes.indexWhere((EpisodeItem e) => e.cid == cid); getCurrentIndex();
}); });
} }
@ -73,6 +73,23 @@ class _SeasonPanelState extends State<SeasonPanel> {
_bottomSheetController?.close(); _bottomSheetController?.close();
} }
// 获取currentIndex
void getCurrentIndex() {
currentIndex.value = episodes.indexWhere((EpisodeItem e) => e.cid == cid);
final List<SectionItem> sections = widget.ugcSeason.sections!;
if (sections.length == 1 && sections.first.type == 1) {
final List<EpisodeItem> episodesList = sections.first.episodes!;
for (int i = 0; i < episodesList.length; i++) {
for (int j = 0; j < episodesList[i].pages!.length; j++) {
if (episodesList[i].pages![j].cid == cid) {
currentIndex.value = i;
continue;
}
}
}
}
}
Widget buildEpisodeListItem( Widget buildEpisodeListItem(
EpisodeItem episode, EpisodeItem episode,
int index, int index,
@ -126,6 +143,7 @@ class _SeasonPanelState extends State<SeasonPanel> {
dataType: VideoEpidoesType.videoEpisode, dataType: VideoEpidoesType.videoEpisode,
ugcSeason: widget.ugcSeason, ugcSeason: widget.ugcSeason,
currentEpisodeIndex: currentEpisodeIndex, currentEpisodeIndex: currentEpisodeIndex,
currentIndex: currentIndex.value,
).show(context); ).show(context);
}, },
child: Padding( child: Padding(