From 0ebbcd6cb084a17074c557919335a91979338b75 Mon Sep 17 00:00:00 2001 From: MSOB7YY Date: Tue, 16 Jul 2024 02:42:48 +0300 Subject: [PATCH] chore: tweaks & refinements --- lib/base/audio_handler.dart | 14 ++- lib/ui/widgets/custom_widgets.dart | 2 +- lib/ui/widgets/waveform.dart | 95 ++++++++++--------- .../youtube_account_controller.dart | 8 +- .../youtube_manage_subscription_page.dart | 83 ++++++++-------- lib/youtube/widgets/yt_playlist_card.dart | 2 + lib/youtube/widgets/yt_subscribe_buttons.dart | 3 +- .../yt_minplayer_comment_replies_subpage.dart | 2 +- pubspec.yaml | 4 +- 9 files changed, 119 insertions(+), 94 deletions(-) diff --git a/lib/base/audio_handler.dart b/lib/base/audio_handler.dart index 50832c50..1453dea3 100644 --- a/lib/base/audio_handler.dart +++ b/lib/base/audio_handler.dart @@ -785,9 +785,7 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { return WaveformController.inst.generateWaveform( path: audioPath, duration: dur, - stillPlaying: (path) => - currentItem.value is YoutubeID && currentItem.value == video && (_nextSeekSetAudioCache != null && path == _nextSeekSetAudioCache?.path) || - (currentCachedAudio.value != null && path == currentCachedAudio.value?.file.path), + stillPlaying: (path) => video == currentItem.value, ); } } @@ -817,7 +815,10 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { WaveformController.inst.generateWaveform( path: audioCacheFile.path, duration: dur, - stillPlaying: (path) => currentItem.value is YoutubeID && _nextSeekSetAudioCache != null && path == _nextSeekSetAudioCache?.path, + stillPlaying: (path) { + final curr = currentItem.value; + return curr is YoutubeID && curr.id == vId; + }, ); } } @@ -974,7 +975,10 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { WaveformController.inst.generateWaveform( path: audioDetails.file.path, duration: dur, - stillPlaying: (path) => currentItem.value is YoutubeID && path == currentCachedAudio.value?.file.path, + stillPlaying: (path) { + final curr = currentItem.value; + return curr is YoutubeID && curr.id == item.id; + }, ); } } diff --git a/lib/ui/widgets/custom_widgets.dart b/lib/ui/widgets/custom_widgets.dart index 99f322f7..b5a7ac7f 100644 --- a/lib/ui/widgets/custom_widgets.dart +++ b/lib/ui/widgets/custom_widgets.dart @@ -3133,7 +3133,7 @@ class ShimmerWrapper extends StatelessWidget { class LazyLoadListView extends StatefulWidget { final ScrollController? scrollController; final int extend; - final FutureOr Function() onReachingEnd; + final FutureOr Function() onReachingEnd; final Widget Function(ScrollController controller) listview; final bool requiresNetwork; diff --git a/lib/ui/widgets/waveform.dart b/lib/ui/widgets/waveform.dart index 163611a6..952f42f8 100644 --- a/lib/ui/widgets/waveform.dart +++ b/lib/ui/widgets/waveform.dart @@ -43,7 +43,7 @@ class WaveformComponentState extends State with SingleTickerP vsync: this, lowerBound: 0.0, upperBound: 1.0, - value: 1.0, + value: WaveformController.inst.isWaveformUIEnabled.value ? 1.0 : 0.0, duration: Duration(milliseconds: widget.durationInMilliseconds), reverseDuration: Duration(milliseconds: widget.durationInMilliseconds), ); @@ -97,52 +97,55 @@ class WaveformComponentState extends State with SingleTickerP return Center( child: AnimatedBuilder( animation: _animation, - builder: (context, _) => Stack( - children: [ - NamidaWaveBars( - heightPercentage: _animation.value, - decorationBox: decorationBoxBehind, - waveList: downscaled, - barWidth: barWidth, - barMinHeight: widget.barsMinHeight, - barMaxHeight: widget.barsMaxHeight, - ), - Obx( - () { - final seekValue = MiniPlayerController.inst.seekValue.valueR; - final position = seekValue != 0.0 ? seekValue : Player.inst.nowPlayingPositionR; - final durInMs = _currentDurationInMSR; - final percentage = (position / durInMs).clamp(0.0, durInMs.toDouble()); - return ShaderMask( - blendMode: BlendMode.srcIn, - shaderCallback: (Rect bounds) { - return LinearGradient( - tileMode: TileMode.decal, - stops: [0.0, percentage, percentage + 0.005, 1.0], - colors: [ - Color.alphaBlend(CurrentColor.inst.miniplayerColor.withAlpha(220), context.theme.colorScheme.onSurface), - Color.alphaBlend(CurrentColor.inst.miniplayerColor.withAlpha(180), context.theme.colorScheme.onSurface), - Colors.transparent, - Colors.transparent, - ], - ).createShader(bounds); - }, - child: SizedBox( - width: namida.width - 16.0 / 2, - child: NamidaWaveBars( - heightPercentage: _animation.value, - decorationBox: decorationBoxFront, - waveList: downscaled, - barWidth: barWidth, - barMinHeight: widget.barsMinHeight, - barMaxHeight: widget.barsMaxHeight, + builder: (context, _) { + final colors = [ + Color.alphaBlend(CurrentColor.inst.miniplayerColor.withAlpha(220), context.theme.colorScheme.onSurface), + Color.alphaBlend(CurrentColor.inst.miniplayerColor.withAlpha(180), context.theme.colorScheme.onSurface), + Colors.transparent, + Colors.transparent, + ]; + return Stack( + children: [ + NamidaWaveBars( + heightPercentage: _animation.value, + decorationBox: decorationBoxBehind, + waveList: downscaled, + barWidth: barWidth, + barMinHeight: widget.barsMinHeight, + barMaxHeight: widget.barsMaxHeight, + ), + Obx( + () { + final seekValue = MiniPlayerController.inst.seekValue.valueR; + final position = seekValue != 0.0 ? seekValue : Player.inst.nowPlayingPositionR; + final durInMs = _currentDurationInMSR; + final percentage = (position / durInMs).clamp(0.0, durInMs.toDouble()); + return ShaderMask( + blendMode: BlendMode.srcIn, + shaderCallback: (Rect bounds) { + return LinearGradient( + tileMode: TileMode.decal, + stops: [0.0, percentage, percentage + 0.005, 1.0], + colors: colors, + ).createShader(bounds); + }, + child: SizedBox( + width: namida.width - 16.0 / 2, + child: NamidaWaveBars( + heightPercentage: _animation.value, + decorationBox: decorationBoxFront, + waveList: downscaled, + barWidth: barWidth, + barMinHeight: widget.barsMinHeight, + barMaxHeight: widget.barsMaxHeight, + ), ), - ), - ); - }, - ), - ], - ), + ); + }, + ), + ], + ); + }, ), ); }); diff --git a/lib/youtube/controller/youtube_account_controller.dart b/lib/youtube/controller/youtube_account_controller.dart index 719bb603..8127c60a 100644 --- a/lib/youtube/controller/youtube_account_controller.dart +++ b/lib/youtube/controller/youtube_account_controller.dart @@ -92,7 +92,7 @@ class YoutubeAccountController { if (ms == null || ms.index < MembershipType.cutie.index) { // -- has account but no membership _showError( - '${lang.OPERATION_REQUIRES_MEMBERSHIP.replaceFirst('_OPERATION_', '`${operation.name}`').replaceFirst('_NAME_', '`${MembershipType.cutie.name}`')}. ${lang.YOUR_CURRENT_MEMBERSHIP_IS.replaceFirst('_NAME_', "`${ms?.name ?? MembershipType.unknown}`")}', + '${lang.OPERATION_REQUIRES_MEMBERSHIP.replaceFirst('_OPERATION_', '`${operation.name}`').replaceFirst('_NAME_', '`${MembershipType.cutie.name}`')}. ${lang.YOUR_CURRENT_MEMBERSHIP_IS.replaceFirst('_NAME_', "`${ms?.name ?? MembershipType.unknown.name}`")}', manageSubscriptionButton: true, ); return false; @@ -277,6 +277,12 @@ class YoutubeAccountController { class _CurrentMembership { _CurrentMembership._(); + String? get getUsernameGlobal { + String? name = userSupabaseSub.value?.name; + if (name == null || name.isEmpty) name = userPatreonTier.value?.userName; + return name; + } + final userSupabaseSub = Rxn(); final userPatreonTier = Rxn(); diff --git a/lib/youtube/pages/user/youtube_manage_subscription_page.dart b/lib/youtube/pages/user/youtube_manage_subscription_page.dart index f38d9772..5cc2b0bf 100644 --- a/lib/youtube/pages/user/youtube_manage_subscription_page.dart +++ b/lib/youtube/pages/user/youtube_manage_subscription_page.dart @@ -31,48 +31,54 @@ class _YoutubeManageSubscriptionPageState extends State _onPossibleMemebershipChange(Future Function() fn) async { + final oldMS = YoutubeAccountController.membership.userMembershipTypeGlobal.value; + try { + await fn(); + _showMembershipChangeSnack(oldMS); + } catch (e) { + _showError('', exception: e); + } + } + Future _onFreeCouponSubmit(Future Function(String code, String email) fn) async { final code = _codeController.text; final email = _emailController.text; final validated = _formKey.currentState?.validate(); if (validated ?? (code.isNotEmpty && email.isNotEmpty)) { - final old = YoutubeAccountController.membership.userMembershipTypeGlobal.value; - try { - await fn(code, email); - - final newMS = YoutubeAccountController.membership.userMembershipTypeGlobal.value; - - if (newMS == null) { - if (old != null) snackyy(message: lang.MEMBERSHIP_UNKNOWN, isError: true, top: false); - } else if (old == newMS) { - final name = YoutubeAccountController.membership.userSupabaseSub.value?.name; - String trailing = ''; - if (name != null && name.isNotEmpty) trailing += '$name '; - snackyy(message: '${lang.MEMBERSHIP_DIDNT_CHANGE}, `${newMS.name}` $trailing', top: false); - } else { - final name = YoutubeAccountController.membership.userSupabaseSub.value?.name; - String trailing = ''; - if (name != null && name.isNotEmpty) trailing += '$name '; - if (newMS.index <= MembershipType.none.index) { - trailing = ':('; - } else if (newMS == MembershipType.owner) { - trailing = 'o7'; - } else { - trailing = ':D'; - } - snackyy( - message: '${lang.MEMBERSHIP_ENJOY_NEW}, `${newMS.name}` $trailing', - borderColor: Colors.green.withOpacity(0.8), - top: false, - ); - } - } catch (e) { - _showError('', exception: e); - } + return _onPossibleMemebershipChange(() => fn(code, email)); } } - void _onPatreonLoginTap(BuildContext context, {required SignInDecision signInDecision}) { + Future _onPatreonLoginTap(BuildContext context, {required SignInDecision signInDecision}) async { final header = Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, @@ -90,9 +96,12 @@ class _YoutubeManageSubscriptionPageState extends State YoutubeAccountController.membership.claimPatreon( + pageConfig: pageConfig, + signIn: signInDecision, + ), ); } diff --git a/lib/youtube/widgets/yt_playlist_card.dart b/lib/youtube/widgets/yt_playlist_card.dart index 56887f59..300dba3b 100644 --- a/lib/youtube/widgets/yt_playlist_card.dart +++ b/lib/youtube/widgets/yt_playlist_card.dart @@ -8,6 +8,7 @@ import 'package:youtipie/core/enum.dart'; import 'package:youtipie/youtipie.dart'; import 'package:namida/class/route.dart'; +import 'package:namida/controller/connectivity.dart'; import 'package:namida/controller/player_controller.dart'; import 'package:namida/core/enums.dart'; import 'package:namida/core/extensions.dart'; @@ -72,6 +73,7 @@ class _YoutubePlaylistCardState extends State { } Future _forceFetch() async { + if (!ConnectivityController.inst.hasConnection) return; _fetchTimer?.cancel(); _isFetching.value = true; final value = await _fetchFunction(forceRequest: true); diff --git a/lib/youtube/widgets/yt_subscribe_buttons.dart b/lib/youtube/widgets/yt_subscribe_buttons.dart index 499016ee..6b8ba6a0 100644 --- a/lib/youtube/widgets/yt_subscribe_buttons.dart +++ b/lib/youtube/widgets/yt_subscribe_buttons.dart @@ -225,17 +225,18 @@ class _YTSubscribeButtonState extends State { ChannelNotifications.all => Icon( Broken.notification_bing, size: iconSize, + color: context.defaultIconColor(), ), ChannelNotifications.personalized => Icon( Broken.notification_1, size: iconSize, + color: context.defaultIconColor(), ), ChannelNotifications.none => StackedIcon( baseIcon: Broken.notification_1, secondaryIcon: Broken.slash, iconSize: iconSize, secondaryIconSize: 11.0, - disableColor: true, ), null => null, }; diff --git a/lib/youtube/yt_minplayer_comment_replies_subpage.dart b/lib/youtube/yt_minplayer_comment_replies_subpage.dart index 23fcc8b7..ee16ba4b 100644 --- a/lib/youtube/yt_minplayer_comment_replies_subpage.dart +++ b/lib/youtube/yt_minplayer_comment_replies_subpage.dart @@ -223,7 +223,7 @@ class _YTMiniplayerCommentRepliesSubpageState extends State=3.4.0 <4.0.0" @@ -40,7 +40,7 @@ dependencies: device_info_plus: ^10.1.0 intl: ^0.19.0 flutter_archive: ^6.0.3 - url_launcher: ^6.1.10 + url_launcher: ^6.3.0 connectivity_plus: ^6.0.3 selectable_autolink_text: ^2.6.0 share_plus: ^9.0.0