Skip to content

Commit

Permalink
fix: player view artist link when local playlist is playing, lyric de…
Browse files Browse the repository at this point in the history
…lay adjust button alignment
  • Loading branch information
KRTirtho committed Dec 7, 2022
1 parent bc8a04e commit ee5c417
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 70 deletions.
8 changes: 5 additions & 3 deletions lib/components/Home/Genres.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ class Genres extends HookConsumerWidget {
.toList()
];

final isMounted = useIsMounted();

return PlatformScaffold(
appBar: kIsDesktop ? PageWindowTitleBar() : null,
body: Waypoint(
onTouchEdge: () {
if (categoriesQuery.hasNextPage) {
categoriesQuery.fetchNextPage();
onTouchEdge: () async {
if (categoriesQuery.hasNextPage && isMounted()) {
await categoriesQuery.fetchNextPage();
}
},
controller: scrollController,
Expand Down
36 changes: 17 additions & 19 deletions lib/components/Lyrics/SyncedLyrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SyncedLyrics extends HookConsumerWidget {
return Column(
children: [
SizedBox(
height: breakpoint >= Breakpoints.md ? 50 : 30,
height: breakpoint >= Breakpoints.md ? 50 : 40,
child: Material(
type: MaterialType.transparency,
textStyle: PlatformTheme.of(context).textTheme!.body!,
Expand All @@ -84,27 +84,25 @@ class SyncedLyrics extends HookConsumerWidget {
isHovering: true,
),
),
Positioned.fill(
Positioned(
top: 10,
right: 10,
child: Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: PlatformFilledButton(
child: const Icon(
Icons.av_timer_rounded,
size: 16,
),
onPressed: () async {
final delay = await showPlatformAlertDialog(
context,
builder: (context) =>
const LyricDelayAdjustDialog(),
);
if (delay != null) {
ref.read(lyricDelayState.notifier).state = delay;
}
},
child: PlatformFilledButton(
child: const Icon(
Icons.av_timer_rounded,
size: 16,
),
onPressed: () async {
final delay = await showPlatformAlertDialog(
context,
builder: (context) => const LyricDelayAdjustDialog(),
);
if (delay != null) {
ref.read(lyricDelayState.notifier).state = delay;
}
},
),
),
),
Expand Down
57 changes: 30 additions & 27 deletions lib/components/Player/PlayerActions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PlayerActions extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final Playback playback = ref.watch(playbackProvider);
final isLocalTrack = playback.playlist?.isLocal == true;
final downloader = ref.watch(downloaderProvider);
final isInQueue =
downloader.inQueue.any((element) => element.id == playback.track?.id);
Expand Down Expand Up @@ -74,32 +75,33 @@ class PlayerActions extends HookConsumerWidget {
}
: null,
),
PlatformIconButton(
icon: const Icon(Icons.alt_route_rounded),
tooltip: "Alternative Track Sources",
onPressed: playback.track != null
? () {
showModalBottomSheet(
context: context,
isDismissible: true,
enableDrag: true,
isScrollControlled: true,
backgroundColor: Colors.black12,
barrierColor: Colors.black12,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * .5,
),
builder: (context) {
return SiblingTracksSheet(floating: floatingQueue);
},
);
}
: null,
),
if (!kIsWeb)
if (!isLocalTrack)
PlatformIconButton(
icon: const Icon(Icons.alt_route_rounded),
tooltip: "Alternative Track Sources",
onPressed: playback.track != null
? () {
showModalBottomSheet(
context: context,
isDismissible: true,
enableDrag: true,
isScrollControlled: true,
backgroundColor: Colors.black12,
barrierColor: Colors.black12,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * .5,
),
builder: (context) {
return SiblingTracksSheet(floating: floatingQueue);
},
);
}
: null,
),
if (!kIsWeb && !isLocalTrack)
if (isInQueue)
const SizedBox(
height: 20,
Expand All @@ -120,7 +122,8 @@ class PlayerActions extends HookConsumerWidget {
? () => downloader.addToQueue(playback.track!)
: null,
),
if (playback.track != null) TrackHeartButton(track: playback.track!),
if (playback.track != null && !isLocalTrack)
TrackHeartButton(track: playback.track!),
...(extraActions ?? [])
],
);
Expand Down
40 changes: 28 additions & 12 deletions lib/components/Player/PlayerView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:palette_generator/palette_generator.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/components/Player/PlayerActions.dart';
import 'package:spotube/components/Player/PlayerControls.dart';
import 'package:spotube/components/Shared/PageWindowTitleBar.dart';
Expand All @@ -28,6 +29,9 @@ class PlayerView extends HookConsumerWidget {
final currentTrack = ref.watch(playbackProvider.select(
(value) => value.track,
));
final isLocalTrack = ref.watch(playbackProvider.select(
(value) => value.playlist?.isLocal == true,
));
final breakpoint = useBreakpoints();
final canRotate = ref.watch(
userPreferencesProvider.select((s) => s.rotatingAlbumArt),
Expand Down Expand Up @@ -102,18 +106,30 @@ class PlayerView extends HookConsumerWidget {
isHovering: true,
),
),
TypeConversionUtils.artists_X_ClickableArtists(
currentTrack?.artists ?? [],
textStyle:
Theme.of(context).textTheme.headline6!.copyWith(
fontWeight: FontWeight.bold,
color: paletteColor.bodyTextColor,
),
onRouteChange: (route) {
GoRouter.of(context).pop();
GoRouter.of(context).push(route);
},
),
if (isLocalTrack)
Text(
TypeConversionUtils.artists_X_String<Artist>(
currentTrack?.artists ?? [],
),
style:
Theme.of(context).textTheme.headline6!.copyWith(
fontWeight: FontWeight.bold,
color: paletteColor.bodyTextColor,
),
)
else
TypeConversionUtils.artists_X_ClickableArtists(
currentTrack?.artists ?? [],
textStyle:
Theme.of(context).textTheme.headline6!.copyWith(
fontWeight: FontWeight.bold,
color: paletteColor.bodyTextColor,
),
onRouteChange: (route) {
GoRouter.of(context).pop();
GoRouter.of(context).push(route);
},
),
],
),
),
Expand Down
24 changes: 15 additions & 9 deletions lib/components/Shared/Waypoint.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:visibility_detector/visibility_detector.dart';

class Waypoint extends HookWidget {
final void Function()? onTouchEdge;
final FutureOr<void> Function()? onTouchEdge;
final Widget? child;
final ScrollController controller;
final bool isGrid;
Expand All @@ -18,27 +20,31 @@ class Waypoint extends HookWidget {

@override
Widget build(BuildContext context) {
final isMounted = useIsMounted();

useEffect(() {
if (isGrid) {
return null;
}
listener() {
Future<void> listener() async {
// nextPageTrigger will have a value equivalent to 80% of the list size.
final nextPageTrigger = 0.8 * controller.position.maxScrollExtent;

// scrollController fetches the next paginated data when the current postion of the user on the screen has surpassed
if (controller.position.pixels >= nextPageTrigger) {
onTouchEdge?.call();
if (controller.position.pixels >= nextPageTrigger && isMounted()) {
await onTouchEdge?.call();
}
}

if (controller.hasClients) {
listener();
}
WidgetsBinding.instance.addPostFrameCallback((_) {
if (controller.hasClients && isMounted()) {
listener();
}

controller.addListener(listener);
controller.addListener(listener);
});
return () => controller.removeListener(listener);
}, [controller, onTouchEdge]);
}, [controller, onTouchEdge, isMounted]);

if (isGrid) {
return VisibilityDetector(
Expand Down
12 changes: 12 additions & 0 deletions lib/themes/light-theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,24 @@ const iosDarkTheme = CupertinoThemeData(
);

final linuxTheme = AdwaitaThemeData.light().copyWith(
extensions: [
ShimmerColorTheme(
shimmerBackgroundColor: Colors.grey[300],
shimmerColor: Colors.grey[400],
)
],
listTileTheme: ListTileThemeData(
iconColor: Colors.grey[900],
horizontalTitleGap: 0,
),
);
final linuxDarkTheme = AdwaitaThemeData.dark().copyWith(
extensions: [
ShimmerColorTheme(
shimmerBackgroundColor: Colors.grey[800],
shimmerColor: Colors.grey[900],
)
],
listTileTheme: ListTileThemeData(
iconColor: Colors.grey[50],
horizontalTitleGap: 0,
Expand Down

0 comments on commit ee5c417

Please sign in to comment.