From 20a89fbccb7472e1ee93c57fe3e697d7edce953c Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Mon, 30 Dec 2024 23:23:20 +0800 Subject: [PATCH] fix: reverse play Signed-off-by: bggRGjQaUbCoE --- lib/common/widgets/list_sheet.dart | 61 ++++++++++++------- lib/pages/bangumi/widgets/bangumi_panel.dart | 1 - .../detail/introduction/widgets/page.dart | 1 - .../detail/introduction/widgets/season.dart | 24 +++----- lib/pages/video/detail/view.dart | 3 +- lib/plugin/pl_player/view.dart | 1 - 6 files changed, 51 insertions(+), 40 deletions(-) diff --git a/lib/common/widgets/list_sheet.dart b/lib/common/widgets/list_sheet.dart index c5737cc6..bdec5569 100644 --- a/lib/common/widgets/list_sheet.dart +++ b/lib/common/widgets/list_sheet.dart @@ -64,6 +64,10 @@ class _ListSheetContentState extends State @override void didUpdateWidget(ListSheetContent oldWidget) { super.didUpdateWidget(oldWidget); + if (widget.showTitle != false) { + return; + } + int currentIndex = _currentIndex; void jumpToCurrent() { @@ -97,7 +101,7 @@ class _ListSheetContentState extends State void initState() { super.initState(); if (_isList) { - _indexStream ??= StreamController(); + _indexStream ??= StreamController.broadcast(); _ctr = TabController( vsync: this, length: widget.season.sections.length, @@ -358,29 +362,22 @@ class _ListSheetContentState extends State }, ), if (widget.season != null) - _mediumButton( - tooltip: '倒序播放', - icon: Icons.u_turn_right, - onPressed: () async { - // jump to current - if (_ctr != null && _ctr?.index != (_index)) { - _ctr?.animateTo(_index); - await Future.delayed(const Duration(milliseconds: 225)); - } - try { - itemScrollController[_ctr?.index ?? 0].scrollTo( - index: currentIndex, - duration: const Duration(milliseconds: 200), - ); - } catch (_) {} - - widget.onReverse?.call(); - }, - ), + if (!_isList) + _reverseButton + else + StreamBuilder( + stream: _indexStream?.stream, + initialData: _index, + builder: (context, snapshot) { + return snapshot.data == _index + ? _reverseButton + : const SizedBox.shrink(); + }, + ), const Spacer(), StreamBuilder( stream: _indexStream?.stream, - initialData: 0, + initialData: _index, builder: (context, snapshot) => _mediumButton( tooltip: reverse[snapshot.data] ? '正序' : '反序', icon: !reverse[snapshot.data] @@ -436,6 +433,28 @@ class _ListSheetContentState extends State ); } + Widget get _reverseButton => _mediumButton( + tooltip: '倒序播放', + icon: Icons.u_turn_right, + onPressed: () async { + if (widget.showTitle == false) { + // jump to current + if (_ctr != null && _ctr?.index != (_index)) { + _ctr?.animateTo(_index); + await Future.delayed(const Duration(milliseconds: 225)); + } + try { + itemScrollController[_ctr?.index ?? 0].scrollTo( + index: currentIndex, + duration: const Duration(milliseconds: 200), + ); + } catch (_) {} + } + + widget.onReverse?.call(); + }, + ); + Widget _mediumButton({ String? tooltip, IconData? icon, diff --git a/lib/pages/bangumi/widgets/bangumi_panel.dart b/lib/pages/bangumi/widgets/bangumi_panel.dart index c202e1b4..3ebdfa50 100644 --- a/lib/pages/bangumi/widgets/bangumi_panel.dart +++ b/lib/pages/bangumi/widgets/bangumi_panel.dart @@ -127,7 +127,6 @@ class _BangumiPanelState extends State { widget.pages[currentIndex].bvid, widget.pages[currentIndex].aid, cid, - null, ), child: Text( widget.newEp?['desc']?.contains('连载') == true diff --git a/lib/pages/video/detail/introduction/widgets/page.dart b/lib/pages/video/detail/introduction/widgets/page.dart index 3b3c0757..ac22adf6 100644 --- a/lib/pages/video/detail/introduction/widgets/page.dart +++ b/lib/pages/video/detail/introduction/widgets/page.dart @@ -102,7 +102,6 @@ class _PagesPanelState extends State { widget.bvid, IdUtils.bv2av(widget.bvid), cid, - null, ), child: Text( '共${widget.pages.length}集', diff --git a/lib/pages/video/detail/introduction/widgets/season.dart b/lib/pages/video/detail/introduction/widgets/season.dart index ed71b25c..ecf2fb7f 100644 --- a/lib/pages/video/detail/introduction/widgets/season.dart +++ b/lib/pages/video/detail/introduction/widgets/season.dart @@ -29,7 +29,7 @@ class SeasonPanel extends StatefulWidget { } class _SeasonPanelState extends State { - int currentIndex = 0; + RxInt currentIndex = 0.obs; late VideoDetailController _videoDetailController; StreamSubscription? _listener; List episodes = []; @@ -52,7 +52,7 @@ class _SeasonPanelState extends State { // episodes = widget.ugcSeason.sections! // .firstWhere((e) => e.seasonId == widget.ugcSeason.id) // .episodes; - currentIndex = episodes.indexWhere( + currentIndex.value = episodes.indexWhere( (EpisodeItem e) => e.cid == _videoDetailController.seasonCid); _listener = _videoDetailController.cid.listen((int p0) { if (widget.pages != null && widget.pages!.length != 1) { @@ -61,10 +61,9 @@ class _SeasonPanelState extends State { } _videoDetailController.seasonCid = p0; _findEpisode(); - currentIndex = episodes.indexWhere( + currentIndex.value = episodes.indexWhere( (EpisodeItem e) => e.cid == _videoDetailController.seasonCid); if (!mounted) return; - setState(() {}); }); } @@ -112,11 +111,6 @@ class _SeasonPanelState extends State { _videoDetailController.bvid, null, _videoDetailController.seasonCid, - () { - setState(() { - currentIndex = episodes.length - 1 - currentIndex; - }); - }, ), child: Padding( padding: const EdgeInsets.fromLTRB(8, 12, 8, 12), @@ -137,11 +131,13 @@ class _SeasonPanelState extends State { semanticLabel: "正在播放:", ), const SizedBox(width: 10), - Text( - '${currentIndex + 1}/${episodes.length}', - style: Theme.of(context).textTheme.labelMedium, - semanticsLabel: - '第${currentIndex + 1}集,共${episodes.length}集', + Obx( + () => Text( + '${currentIndex.value + 1}/${episodes.length}', + style: Theme.of(context).textTheme.labelMedium, + semanticsLabel: + '第${currentIndex.value + 1}集,共${episodes.length}集', + ), ), const SizedBox(width: 6), const Icon( diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index 659a93ea..a32d2278 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -1577,7 +1577,7 @@ class _VideoDetailPageState extends State ); } - showEpisodes(index, season, episodes, bvid, aid, cid, onReverse) { + showEpisodes(index, season, episodes, bvid, aid, cid) { Widget listSheetContent() => ListSheetContent( index: index, season: season, @@ -1600,7 +1600,6 @@ class _VideoDetailPageState extends State onReverse: () { Get.back(); onReversePlay(); - onReverse(); }, ); if (isFullScreen) { diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index 2f3dcc11..c0a0d911 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -411,7 +411,6 @@ class _PLVideoPlayerState extends State bvid, IdUtils.bv2av(bvid), currentCid, - null, ); }, ),