Skip to content

Commit

Permalink
chore: tweaks & refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jul 15, 2024
1 parent 7d1c8bd commit 0ebbcd6
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 94 deletions.
14 changes: 9 additions & 5 deletions lib/base/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
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,
);
}
}
Expand Down Expand Up @@ -817,7 +815,10 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
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;
},
);
}
}
Expand Down Expand Up @@ -974,7 +975,10 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
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;
},
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/widgets/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,7 @@ class ShimmerWrapper extends StatelessWidget {
class LazyLoadListView extends StatefulWidget {
final ScrollController? scrollController;
final int extend;
final FutureOr<void> Function() onReachingEnd;
final FutureOr<bool> Function() onReachingEnd;
final Widget Function(ScrollController controller) listview;
final bool requiresNetwork;

Expand Down
95 changes: 49 additions & 46 deletions lib/ui/widgets/waveform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class WaveformComponentState extends State<WaveformComponent> 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),
);
Expand Down Expand Up @@ -97,52 +97,55 @@ class WaveformComponentState extends State<WaveformComponent> 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,
),
),
),
);
},
),
],
),
);
},
),
],
);
},
),
);
});
Expand Down
8 changes: 7 additions & 1 deletion lib/youtube/controller/youtube_account_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SupabaseSub>();
final userPatreonTier = Rxn<SupportTier>();

Expand Down
83 changes: 46 additions & 37 deletions lib/youtube/pages/user/youtube_manage_subscription_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,54 @@ class _YoutubeManageSubscriptionPageState extends State<YoutubeManageSubscriptio
snackyy(message: exception.toString(), isError: true, displaySeconds: 3);
}

void _showMembershipChangeSnack(MembershipType? oldMS) {
final newMS = YoutubeAccountController.membership.userMembershipTypeGlobal.value;
if (newMS == null) {
if (oldMS != null) snackyy(message: lang.MEMBERSHIP_UNKNOWN, isError: true, top: false);
} else if (oldMS == newMS) {
final name = YoutubeAccountController.membership.getUsernameGlobal;
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.getUsernameGlobal;
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,
);
}
}

Future<void> _onPossibleMemebershipChange(Future<void> Function() fn) async {
final oldMS = YoutubeAccountController.membership.userMembershipTypeGlobal.value;
try {
await fn();
_showMembershipChangeSnack(oldMS);
} catch (e) {
_showError('', exception: e);
}
}

Future<void> _onFreeCouponSubmit(Future<void> 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<void> _onPatreonLoginTap(BuildContext context, {required SignInDecision signInDecision}) async {
final header = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -90,9 +96,12 @@ class _YoutubeManageSubscriptionPageState extends State<YoutubeManageSubscriptio
NamidaNavigator.inst.navigateToRoot(page, opaque: opaque);
},
);
YoutubeAccountController.membership.claimPatreon(
pageConfig: pageConfig,
signIn: signInDecision,

return _onPossibleMemebershipChange(
() => YoutubeAccountController.membership.claimPatreon(
pageConfig: pageConfig,
signIn: signInDecision,
),
);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/youtube/widgets/yt_playlist_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -72,6 +73,7 @@ class _YoutubePlaylistCardState extends State<YoutubePlaylistCard> {
}

Future<void> _forceFetch() async {
if (!ConnectivityController.inst.hasConnection) return;
_fetchTimer?.cancel();
_isFetching.value = true;
final value = await _fetchFunction(forceRequest: true);
Expand Down
3 changes: 2 additions & 1 deletion lib/youtube/widgets/yt_subscribe_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,18 @@ class _YTSubscribeButtonState extends State<YTSubscribeButton> {
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,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/yt_minplayer_comment_replies_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class _YTMiniplayerCommentRepliesSubpageState extends State<YTMiniplayerCommentR
child: ListView.builder(
padding: EdgeInsets.zero,
physics: const NeverScrollableScrollPhysics(),
itemCount: 10,
itemCount: repliesCount?.withMaximum(20) ?? 10,
shrinkWrap: true,
itemBuilder: (context, index) {
return const YTCommentCard(
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.2.8-beta+240715236
version: 3.3.0-beta+240715236

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ebbcd6

Please sign in to comment.