fix: reverse play

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-12-31 17:02:12 +08:00
parent 273e5649c3
commit df41729d74
12 changed files with 142 additions and 125 deletions

View File

@@ -28,6 +28,7 @@ class ListSheetContent extends StatefulWidget {
this.onReverse,
this.showTitle,
this.isSupportReverse,
this.isReversed,
});
final dynamic index;
@@ -41,6 +42,7 @@ class ListSheetContent extends StatefulWidget {
final VoidCallback? onReverse;
final bool? showTitle;
final bool? isSupportReverse;
final bool? isReversed;
@override
State<ListSheetContent> createState() => _ListSheetContentState();
@@ -381,10 +383,10 @@ class _ListSheetContentState extends State<ListSheetContent>
stream: _indexStream?.stream,
initialData: _index,
builder: (context, snapshot) => _mediumButton(
tooltip: reverse[snapshot.data] ? '' : '',
tooltip: reverse[snapshot.data] ? '' : '',
icon: !reverse[snapshot.data]
? MdiIcons.sortAscending
: MdiIcons.sortDescending,
? MdiIcons.sortNumericAscending
: MdiIcons.sortNumericDescending,
onPressed: () {
setState(() {
reverse[_ctr?.index ?? 0] = !reverse[_ctr?.index ?? 0];
@@ -436,8 +438,10 @@ class _ListSheetContentState extends State<ListSheetContent>
}
Widget get _reverseButton => _mediumButton(
tooltip: '倒序播放',
icon: Icons.u_turn_right,
tooltip: widget.isReversed == true ? '正序播放' : '倒序播放',
icon: widget.isReversed == true
? MdiIcons.sortDescending
: MdiIcons.sortAscending,
onPressed: () async {
if (widget.showTitle == false) {
// jump to current
@@ -479,7 +483,7 @@ class _ListSheetContentState extends State<ListSheetContent>
Widget _buildBody(i, episodes) => Material(
child: ScrollablePositionedList.separated(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom + 20,
bottom: MediaQuery.of(context).padding.bottom + 80,
),
reverse: reverse[i ?? 0],
itemCount: episodes.length,

View File

@@ -31,6 +31,7 @@ class MediaVideoItemModel {
this.forbidFav,
this.moreType,
this.businessOid,
this.isReversed = false,
});
int? id;
@@ -64,6 +65,7 @@ class MediaVideoItemModel {
bool? forbidFav;
int? moreType;
int? businessOid;
bool isReversed;
factory MediaVideoItemModel.fromJson(Map<String, dynamic> json) =>
MediaVideoItemModel(
@@ -101,6 +103,7 @@ class MediaVideoItemModel {
forbidFav: json["forbid_fav"],
moreType: json["more_type"],
businessOid: json["business_oid"],
isReversed: false,
);
}

View File

@@ -69,6 +69,8 @@ class VideoDetailData {
bool? needJumpBv;
String? epId;
List<Staff>? staff;
late bool isPageReversed;
late bool isSeasonReversed;
VideoDetailData({
this.bvid,
@@ -107,6 +109,8 @@ class VideoDetailData {
this.needJumpBv,
this.epId,
this.staff,
this.isPageReversed = false,
this.isSeasonReversed = false,
});
VideoDetailData.fromJson(Map<String, dynamic> json) {
@@ -163,6 +167,8 @@ class VideoDetailData {
if (json['redirect_url'] != null) {
epId = resolveEpId(json['redirect_url']);
}
isPageReversed = false;
isSeasonReversed = false;
}
String resolveEpId(url) {

View File

@@ -66,7 +66,7 @@ class _FollowListState extends State<FollowList> {
if (index == list.length) {
return Container(
height:
MediaQuery.of(context).padding.bottom + 60,
MediaQuery.of(context).padding.bottom + 80,
padding: EdgeInsets.only(
bottom:
MediaQuery.of(context).padding.bottom),

View File

@@ -404,7 +404,7 @@ class _ExtraSettingState extends State<ExtraSetting> {
SetSwitchItem(
title: '分P/合集:倒序播放从首集开始播放',
subTitle: '开启则自动切换为倒序首集,否则保持当前集',
leading: const Icon(Icons.u_turn_right),
leading: Icon(MdiIcons.sort),
setKey: SettingBoxKey.reverseFromFirst,
defaultVal: true,
),

View File

@@ -228,12 +228,18 @@ class _SubDetailPageState extends State<SubDetailPage> {
return Obx(
() => subList.isEmpty
? const SliverToBoxAdapter(child: SizedBox())
: SliverGrid(
: SliverPadding(
padding: EdgeInsets.only(
bottom:
MediaQuery.paddingOf(context).bottom + 80,
),
sliver: SliverGrid(
gridDelegate:
SliverGridDelegateWithExtentAndRatio(
mainAxisSpacing: 2,
maxCrossAxisExtent: Grid.maxRowWidth * 2,
childAspectRatio: StyleString.aspectRatio * 2.2,
childAspectRatio:
StyleString.aspectRatio * 2.2,
),
delegate: SliverChildBuilderDelegate(
childCount: subList.length,
@@ -244,6 +250,7 @@ class _SubDetailPageState extends State<SubDetailPage> {
},
),
),
),
);
}
} else {
@@ -271,25 +278,6 @@ class _SubDetailPageState extends State<SubDetailPage> {
}
},
),
SliverToBoxAdapter(
child: Container(
height: MediaQuery.of(context).padding.bottom + 60,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom,
),
child: Center(
child: Obx(
() => Text(
_subDetailController.loadingText.value,
style: TextStyle(
color: Theme.of(context).colorScheme.outline,
fontSize: 13,
),
),
),
),
),
)
],
),
);

View File

@@ -222,7 +222,7 @@ class VideoDetailController extends GetxController
videoType == SearchType.video ? _showVideoReply : _showBangumiReply;
late final horizontalSeasonPanel = GStorage.horizontalSeasonPanel;
late int seasonCid = 0;
int? seasonCid;
late RxInt seasonIndex = 0.obs;
late final reverseFromFirst = GStorage.reverseFromFirst;

View File

@@ -133,10 +133,12 @@ class VideoIntroController extends GetxController
if (videoDetail.value.ugcSeason?.id == result['data']?.ugcSeason?.id) {
// keep reversed season
result['data']?.ugcSeason = videoDetail.value.ugcSeason;
result['data']?.isSeasonReversed = videoDetail.value.isSeasonReversed;
}
if (videoDetail.value.cid == result['data']?.cid) {
// keep reversed pages
result['data']?.pages = videoDetail.value.pages;
result['data']?.isPageReversed = videoDetail.value.isPageReversed;
}
videoDetail.value = result['data'];
videoItem!['staff'] = result['data'].staff;

View File

@@ -82,6 +82,7 @@ class _VideoIntroPanelState extends State<VideoIntroPanel>
onShowMemberPage: widget.onShowMemberPage,
)
: VideoInfo(
key: ValueKey(widget.heroTag),
loadingStatus: false,
videoIntroController: videoIntroController,
heroTag: widget.heroTag,
@@ -109,12 +110,12 @@ class VideoInfo extends StatefulWidget {
const VideoInfo({
super.key,
this.loadingStatus = false,
required this.videoIntroController,
required this.heroTag,
required this.showAiBottomSheet,
required this.showIntroDetail,
required this.showEpisodes,
required this.onShowMemberPage,
required this.videoIntroController,
});
@override
@@ -642,10 +643,9 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
),
),
),
const SizedBox(height: 8),
Obx(
() => videoIntroController.queryVideoIntroData.value["status"]
? const SizedBox()
? const SizedBox.shrink()
: Center(
child: TextButton.icon(
icon: const Icon(Icons.refresh),
@@ -676,19 +676,13 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
(context.orientation != Orientation.landscape ||
(context.orientation == Orientation.landscape &&
videoDetailCtr.horizontalSeasonPanel.not)))
Obx(
() => SeasonPanel(
SeasonPanel(
heroTag: widget.heroTag,
ugcSeason: videoDetail.ugcSeason!,
cid: videoIntroController.lastPlayCid.value != 0
? (videoDetail.pages?.isNotEmpty == true
? videoDetail.pages!.first.cid
: videoIntroController.lastPlayCid.value)
: videoDetail.pages!.first.cid,
changeFuc: videoIntroController.changeSeasonOrbangu,
showEpisodes: widget.showEpisodes,
pages: videoDetail.pages,
),
videoIntroController: videoIntroController,
),
if (!widget.loadingStatus &&
videoDetail.pages != null &&
@@ -696,16 +690,13 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
(context.orientation != Orientation.landscape ||
(context.orientation == Orientation.landscape &&
videoDetailCtr.horizontalSeasonPanel.not))) ...[
Obx(
() => PagesPanel(
PagesPanel(
heroTag: widget.heroTag,
videoDetailData: videoIntroController.videoDetail.value,
cid: videoIntroController.lastPlayCid.value,
videoIntroController: videoIntroController,
bvid: videoIntroController.bvid,
changeFuc: videoIntroController.changeSeasonOrbangu,
showEpisodes: widget.showEpisodes,
),
),
],
],
)),

View File

@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:math';
import 'package:PiliPalaX/pages/video/detail/introduction/controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:PiliPalaX/models/video_detail_res.dart';
@@ -11,19 +12,17 @@ import '../../../../../utils/id_utils.dart';
class PagesPanel extends StatefulWidget {
const PagesPanel({
super.key,
required this.cid,
required this.bvid,
required this.changeFuc,
required this.heroTag,
required this.showEpisodes,
required this.videoDetailData,
required this.videoIntroController,
});
final int cid;
final String bvid;
final Function changeFuc;
final String heroTag;
final Function showEpisodes;
final VideoDetailData videoDetailData;
final VideoIntroController videoIntroController;
@override
State<PagesPanel> createState() => _PagesPanelState();
@@ -36,19 +35,20 @@ class _PagesPanelState extends State<PagesPanel> {
final ScrollController _scrollController = ScrollController();
StreamSubscription? _listener;
List<Part> get pages => widget.videoIntroController.videoDetail.value.pages!;
@override
void initState() {
super.initState();
cid = widget.cid;
cid = widget.videoIntroController.lastPlayCid.value;
_videoDetailController =
Get.find<VideoDetailController>(tag: widget.heroTag);
pageIndex =
widget.videoDetailData.pages!.indexWhere((Part e) => e.cid == cid);
pageIndex = pages.indexWhere((Part e) => e.cid == cid);
_listener = _videoDetailController.cid.listen((int cid) {
this.cid = cid;
pageIndex = max(0,
widget.videoDetailData.pages!.indexWhere((Part e) => e.cid == cid));
pageIndex = max(0, pages.indexWhere((Part e) => e.cid == cid));
if (!mounted) return;
setState(() {});
const double itemWidth = 150; // 每个列表项的宽度
final double targetOffset = min((pageIndex * itemWidth) - (itemWidth / 2),
_scrollController.position.maxScrollExtent);
@@ -73,14 +73,14 @@ class _PagesPanelState extends State<PagesPanel> {
return Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 10, bottom: 2),
padding: const EdgeInsets.only(top: 8, bottom: 2),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('视频选集 '),
Expanded(
child: Text(
' 正在播放:${widget.videoDetailData.pages![pageIndex].pagePart}',
' 正在播放:${pages[pageIndex].pagePart}',
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
@@ -98,13 +98,13 @@ class _PagesPanelState extends State<PagesPanel> {
onPressed: () => widget.showEpisodes(
null,
null,
widget.videoDetailData.pages!,
pages,
widget.bvid,
IdUtils.bv2av(widget.bvid),
cid,
),
child: Text(
'${widget.videoDetailData.pages!.length}',
'${pages.length}',
style: const TextStyle(fontSize: 13),
),
),
@@ -112,20 +112,19 @@ class _PagesPanelState extends State<PagesPanel> {
],
),
),
Container(
SizedBox(
height: 35,
margin: const EdgeInsets.only(bottom: 8),
child: ListView.builder(
controller: _scrollController,
scrollDirection: Axis.horizontal,
itemCount: widget.videoDetailData.pages!.length,
itemCount: pages.length,
itemExtent: 150,
itemBuilder: (BuildContext context, int i) {
bool isCurrentIndex = pageIndex == i;
return Container(
width: 150,
margin: EdgeInsets.only(
right: i != widget.videoDetailData.pages!.length - 1 ? 10 : 0,
right: i != pages.length - 1 ? 10 : 0,
),
child: Material(
color: Theme.of(context).colorScheme.onInverseSurface,
@@ -136,7 +135,7 @@ class _PagesPanelState extends State<PagesPanel> {
widget.changeFuc(
null,
widget.bvid,
widget.videoDetailData.pages![i].cid,
pages[i].cid,
IdUtils.bv2av(widget.bvid),
null,
)
@@ -157,7 +156,7 @@ class _PagesPanelState extends State<PagesPanel> {
],
Expanded(
child: Text(
widget.videoDetailData.pages![i].pagePart!,
pages[i].pagePart!,
maxLines: 1,
style: TextStyle(
fontSize: 13,

View File

@@ -1,5 +1,7 @@
import 'dart:async';
import 'package:PiliPalaX/pages/video/detail/introduction/controller.dart';
import 'package:PiliPalaX/utils/extension.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:PiliPalaX/models/video_detail_res.dart';
@@ -9,20 +11,20 @@ class SeasonPanel extends StatefulWidget {
const SeasonPanel({
super.key,
required this.ugcSeason,
this.cid,
required this.changeFuc,
required this.heroTag,
required this.showEpisodes,
required this.pages,
this.onTap,
required this.videoIntroController,
});
final UgcSeason ugcSeason;
final int? cid;
final Function changeFuc;
final String heroTag;
final Function showEpisodes;
final List<Part>? pages;
final bool? onTap;
final VideoIntroController videoIntroController;
@override
State<SeasonPanel> createState() => _SeasonPanelState();
@@ -34,12 +36,26 @@ class _SeasonPanelState extends State<SeasonPanel> {
StreamSubscription? _listener;
List<EpisodeItem> episodes = <EpisodeItem>[];
VideoIntroController get videoIntroController => widget.videoIntroController;
VideoDetailData get videoDetail =>
widget.videoIntroController.videoDetail.value;
@override
void initState() {
super.initState();
_videoDetailController =
Get.find<VideoDetailController>(tag: widget.heroTag)
..seasonCid = widget.cid!;
Get.find<VideoDetailController>(tag: widget.heroTag);
_videoDetailController.seasonCid =
videoIntroController.lastPlayCid.value != 0
? (videoDetail.pages?.isNotEmpty == true
? videoDetail.isPageReversed
? videoDetail.pages!.last.cid
: videoDetail.pages!.first.cid
: videoIntroController.lastPlayCid.value)
: videoDetail.isPageReversed
? videoDetail.pages!.last.cid
: videoDetail.pages!.first.cid;
/// 根据 cid 找到对应集,找到对应 episodes
/// 有多个episodes时只显示其中一个
@@ -55,16 +71,12 @@ class _SeasonPanelState extends State<SeasonPanel> {
currentIndex.value = episodes.indexWhere(
(EpisodeItem e) => e.cid == _videoDetailController.seasonCid);
_listener = _videoDetailController.cid.listen((int cid) {
if (_videoDetailController.seasonCid == cid) {
//refresh
_findEpisode();
currentIndex.value = episodes.indexWhere(
(EpisodeItem e) => e.cid == _videoDetailController.seasonCid);
return;
}
if (_videoDetailController.seasonCid != cid) {
bool isPart = widget.pages?.indexWhere((item) => item.cid == cid) != -1;
if (isPart) return;
if (isPart.not) {
_videoDetailController.seasonCid = cid;
}
}
_findEpisode();
currentIndex.value = episodes.indexWhere(
(EpisodeItem e) => e.cid == _videoDetailController.seasonCid);
@@ -99,7 +111,6 @@ class _SeasonPanelState extends State<SeasonPanel> {
top: 8,
left: 2,
right: 2,
bottom: 2,
),
child: Material(
color: Theme.of(context).colorScheme.onInverseSurface,

View File

@@ -1375,9 +1375,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
if (needRelated && videoDetailController.showRelatedVideo) ...[
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(
top: StyleString.safeSpace,
),
padding: const EdgeInsets.only(top: StyleString.safeSpace),
child: Divider(
height: 1,
indent: 12,
@@ -1387,7 +1385,13 @@ class _VideoDetailPageState extends State<VideoDetailPage>
),
),
RelatedVideoPanel(heroTag: heroTag),
],
] else
SliverToBoxAdapter(
child: SizedBox(
height: MediaQuery.paddingOf(context).bottom +
StyleString.safeSpace,
),
),
] else if (videoDetailController.videoType ==
SearchType.media_bangumi)
Obx(
@@ -1465,42 +1469,35 @@ class _VideoDetailPageState extends State<VideoDetailPage>
Widget get seasonPanel => Column(
children: [
if ((videoIntroController.videoDetail.value.pages?.length ?? 0) > 1)
Obx(
() => Padding(
Padding(
padding: const EdgeInsets.symmetric(horizontal: 14),
child: PagesPanel(
heroTag: heroTag,
videoDetailData: videoIntroController.videoDetail.value,
cid: videoIntroController.lastPlayCid.value,
videoIntroController: videoIntroController,
bvid: videoIntroController.bvid,
changeFuc: videoIntroController.changeSeasonOrbangu,
showEpisodes: showEpisodes,
),
),
),
if (videoIntroController.videoDetail.value.ugcSeason != null) ...[
if ((videoIntroController.videoDetail.value.pages?.length ?? 0) > 1)
if ((videoIntroController.videoDetail.value.pages?.length ?? 0) >
1) ...[
const SizedBox(height: 8),
Divider(
height: 1,
color: Theme.of(context).colorScheme.outline.withOpacity(0.1),
),
],
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: SeasonPanel(
heroTag: heroTag,
onTap: false,
ugcSeason: videoIntroController.videoDetail.value.ugcSeason!,
cid: videoIntroController.lastPlayCid.value != 0
? (videoIntroController
.videoDetail.value.pages?.isNotEmpty ==
true
? videoIntroController
.videoDetail.value.pages!.first.cid
: videoIntroController.lastPlayCid.value)
: videoIntroController.videoDetail.value.pages!.first.cid,
changeFuc: videoIntroController.changeSeasonOrbangu,
showEpisodes: showEpisodes,
pages: videoIntroController.videoDetail.value.pages,
videoIntroController: videoIntroController,
),
),
Expanded(
@@ -1510,7 +1507,9 @@ class _VideoDetailPageState extends State<VideoDetailPage>
season: videoIntroController.videoDetail.value.ugcSeason,
bvid: videoDetailController.bvid,
aid: IdUtils.bv2av(videoDetailController.bvid),
currentCid: videoDetailController.seasonCid,
currentCid: videoDetailController.seasonCid ?? 0,
isReversed:
videoIntroController.videoDetail.value.isSeasonReversed,
changeFucCall: videoDetailController.videoType ==
SearchType.media_bangumi
? bangumiIntroController.changeSeasonOrbangu
@@ -1595,6 +1594,12 @@ class _VideoDetailPageState extends State<VideoDetailPage>
aid: aid,
currentCid: cid,
episodes: episodes,
isReversed:
videoDetailController.videoType == SearchType.media_bangumi
? null
: season != null
? videoIntroController.videoDetail.value.isSeasonReversed
: videoIntroController.videoDetail.value.isPageReversed,
isSupportReverse:
videoDetailController.videoType != SearchType.media_bangumi,
changeFucCall:
@@ -1651,6 +1656,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
if (isSeason) {
// reverse season
videoIntroController.videoDetail.value.isSeasonReversed =
!videoIntroController.videoDetail.value.isSeasonReversed;
videoIntroController.videoDetail.value.ugcSeason!
.sections![videoDetailController.seasonIndex.value].episodes =
videoIntroController
@@ -1672,13 +1679,17 @@ class _VideoDetailPageState extends State<VideoDetailPage>
.sections![videoDetailController.seasonIndex.value].episodes!.first;
if (episode.cid != videoDetailController.cid.value) {
changeEpisode(episode);
} else {
videoDetailController.seasonIndex.refresh();
videoDetailController.cid.refresh();
}
}
} else {
// reverse part
videoIntroController.videoDetail.value.isPageReversed =
!videoIntroController.videoDetail.value.isPageReversed;
videoIntroController.videoDetail.value.pages =
videoIntroController.videoDetail.value.pages!.reversed.toList();
videoIntroController.lastPlayCid.refresh();
if (videoDetailController.reverseFromFirst.not) {
// keep current episode
videoDetailController.cid.refresh();
@@ -1687,6 +1698,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
dynamic episode = videoIntroController.videoDetail.value.pages!.first;
if (episode.cid != videoDetailController.cid.value) {
changeEpisode(episode);
} else {
videoDetailController.cid.refresh();
}
}
}