From c00c162bc4e1791f8c4f261da190d0e17a5a2da7 Mon Sep 17 00:00:00 2001 From: MSOB7YY Date: Sun, 18 Aug 2024 01:51:09 +0300 Subject: [PATCH] chore: improve hiding controls mechanism for video container in yt miniplayer --- lib/controller/video_controller.dart | 9 +++++++-- lib/ui/widgets/video_widget.dart | 25 ++++++++++++++++++++++++- lib/youtube/youtube_miniplayer.dart | 2 +- pubspec.yaml | 2 +- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/controller/video_controller.dart b/lib/controller/video_controller.dart index 9d11ef1e..4605396e 100644 --- a/lib/controller/video_controller.dart +++ b/lib/controller/video_controller.dart @@ -30,6 +30,7 @@ import 'package:namida/youtube/widgets/yt_thumbnail.dart'; class NamidaVideoWidget extends StatelessWidget { final bool enableControls; + final double? disableControlsUnderPercentage; final VoidCallback? onMinimizeTap; final bool fullscreen; final bool isPip; @@ -39,7 +40,8 @@ class NamidaVideoWidget extends StatelessWidget { const NamidaVideoWidget({ super.key, - required this.enableControls, + this.enableControls = true, + this.disableControlsUnderPercentage, this.onMinimizeTap, this.fullscreen = false, this.isPip = false, @@ -111,6 +113,7 @@ class NamidaVideoWidget extends StatelessWidget { } }, showControls: showControls, + disableControlsUnderPercentage: disableControlsUnderPercentage, isFullScreen: fullscreen, ), ), @@ -126,12 +129,14 @@ class VideoController { final videoZoomAdditionalScale = 0.0.obs; void updateShouldShowControls(double animationValue) { + final ytmini = videoControlsKey.currentState; + if (ytmini == null) return; final isExpanded = animationValue >= 0.95; if (isExpanded) { // YoutubeMiniplayerUiController.inst.startDimTimer(); // bad experience honestly } else { // YoutubeMiniplayerUiController.inst.cancelDimTimer(); - videoControlsKey.currentState?.setControlsVisibily(false); + ytmini.setControlsVisibily(false); } } diff --git a/lib/ui/widgets/video_widget.dart b/lib/ui/widgets/video_widget.dart index 53028ff1..ae918bf8 100644 --- a/lib/ui/widgets/video_widget.dart +++ b/lib/ui/widgets/video_widget.dart @@ -13,6 +13,7 @@ import 'package:youtipie/core/extensions.dart'; import 'package:namida/class/track.dart'; import 'package:namida/class/video.dart'; import 'package:namida/controller/current_color.dart'; +import 'package:namida/controller/miniplayer_controller.dart'; import 'package:namida/controller/namida_channel.dart'; import 'package:namida/controller/navigator_controller.dart'; import 'package:namida/controller/player_controller.dart'; @@ -211,6 +212,22 @@ class NamidaVideoControlsState extends State with TickerPro await controller.animateTo(target); } + /// disables controls entirely when specified. for example when minplayer is minimized & controls should't be there. + void _disableControlsListener() { + if (!mounted) return; + final value = MiniPlayerController.inst.animation.value; + final hideUnder = widget.disableControlsUnderPercentage!; + if (value < hideUnder && _isControlsEnabled) { + setState(() { + _isControlsEnabled = false; + }); + } else if (value >= hideUnder && !_isControlsEnabled) { + setState(() { + _isControlsEnabled = true; + }); + } + } + @override void initState() { super.initState(); @@ -252,6 +269,10 @@ class NamidaVideoControlsState extends State with TickerPro }, ); } + + if (widget.disableControlsUnderPercentage != null) { + MiniPlayerController.inst.animation.addListener(_disableControlsListener); + } } final _volumeListenerKey = 'video_widget'; @@ -265,6 +286,7 @@ class NamidaVideoControlsState extends State with TickerPro _currentDeviceVolume.close(); _canShowBrightnessSlider.close(); Player.inst.onVolumeChangeRemoveListener(_volumeListenerKey); + MiniPlayerController.inst.animation.removeListener(_disableControlsListener); super.dispose(); } @@ -530,7 +552,8 @@ class NamidaVideoControlsState extends State with TickerPro _doubleTapTimer = null; } - bool get _canShowControls => widget.showControls && !NamidaChannel.inst.isInPip.value; + late bool _isControlsEnabled = widget.showControls; + bool get _canShowControls => _isControlsEnabled && !NamidaChannel.inst.isInPip.value; EdgeInsets _deviceInsets = EdgeInsets.zero; diff --git a/lib/youtube/youtube_miniplayer.dart b/lib/youtube/youtube_miniplayer.dart index 369d834a..f8801d63 100644 --- a/lib/youtube/youtube_miniplayer.dart +++ b/lib/youtube/youtube_miniplayer.dart @@ -1284,7 +1284,7 @@ class YoutubeMiniPlayerState extends State { height: finalthumbnailHeight, child: NamidaVideoWidget( isLocal: false, - enableControls: percentage > 0.5, + disableControlsUnderPercentage: 0.5, onMinimizeTap: () => MiniPlayerController.inst.ytMiniplayerKey.currentState?.animateToState(false), swipeUpToFullscreen: true, ), diff --git a/pubspec.yaml b/pubspec.yaml index 90edf0e3..a7143d2e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: namida description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter publish_to: "none" -version: 3.9.28-beta+240817228 +version: 3.9.29-beta+240817228 environment: sdk: ">=3.4.0 <4.0.0"