mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
Lyric delay adjust support added
theme adjusted for dialogs
This commit is contained in:
parent
c51a9a4c28
commit
acc939c581
74
lib/components/Lyrics/LyricDelayAdjustDialog.dart
Normal file
74
lib/components/Lyrics/LyricDelayAdjustDialog.dart
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:spotube/components/Lyrics/SyncedLyrics.dart';
|
||||||
|
|
||||||
|
class LyricDelayAdjustDialog extends HookConsumerWidget {
|
||||||
|
const LyricDelayAdjustDialog({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, ref) {
|
||||||
|
final controller = useTextEditingController(
|
||||||
|
text: ref.read(lyricDelayState).inMilliseconds.toString(),
|
||||||
|
);
|
||||||
|
|
||||||
|
double getValue() =>
|
||||||
|
double.tryParse(controller.text.replaceAll("ms", "")) ?? 0;
|
||||||
|
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Center(child: Text("Adjust Lyrics Delay")),
|
||||||
|
actions: [
|
||||||
|
ElevatedButton(
|
||||||
|
child: const Text("Cancel"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
child: const Text("Done"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(
|
||||||
|
Duration(
|
||||||
|
milliseconds: getValue().toInt(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
content: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.remove_rounded),
|
||||||
|
onPressed: () {
|
||||||
|
controller.text = "${getValue() - 25}ms";
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Flexible(
|
||||||
|
child: TextField(
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
controller: controller,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
isDense: true,
|
||||||
|
hintText: "Delay in milliseconds",
|
||||||
|
),
|
||||||
|
onSubmitted: (_) {
|
||||||
|
Navigator.of(context).pop(
|
||||||
|
Duration(
|
||||||
|
milliseconds: getValue().toInt(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.add_rounded),
|
||||||
|
onPressed: () {
|
||||||
|
controller.text = "${getValue() + 25}ms";
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:palette_generator/palette_generator.dart';
|
import 'package:palette_generator/palette_generator.dart';
|
||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
import 'package:spotube/components/LoaderShimmers/ShimmerLyrics.dart';
|
import 'package:spotube/components/LoaderShimmers/ShimmerLyrics.dart';
|
||||||
|
import 'package:spotube/components/Lyrics/LyricDelayAdjustDialog.dart';
|
||||||
import 'package:spotube/components/Lyrics/Lyrics.dart';
|
import 'package:spotube/components/Lyrics/Lyrics.dart';
|
||||||
import 'package:spotube/components/Shared/PageWindowTitleBar.dart';
|
import 'package:spotube/components/Shared/PageWindowTitleBar.dart';
|
||||||
import 'package:spotube/components/Shared/SpotubeMarqueeText.dart';
|
import 'package:spotube/components/Shared/SpotubeMarqueeText.dart';
|
||||||
@ -21,12 +22,19 @@ import 'package:spotube/provider/Playback.dart';
|
|||||||
import 'package:scroll_to_index/scroll_to_index.dart';
|
import 'package:scroll_to_index/scroll_to_index.dart';
|
||||||
import 'package:spotube/provider/SpotifyRequests.dart';
|
import 'package:spotube/provider/SpotifyRequests.dart';
|
||||||
|
|
||||||
|
final lyricDelayState = StateProvider<Duration>(
|
||||||
|
(ref) {
|
||||||
|
return Duration.zero;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
class SyncedLyrics extends HookConsumerWidget {
|
class SyncedLyrics extends HookConsumerWidget {
|
||||||
const SyncedLyrics({Key? key}) : super(key: key);
|
const SyncedLyrics({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
final timedLyricsSnapshot = ref.watch(rentanadviserLyricsQuery);
|
final timedLyricsSnapshot = ref.watch(rentanadviserLyricsQuery);
|
||||||
|
final lyricDelay = ref.watch(lyricDelayState);
|
||||||
|
|
||||||
Playback playback = ref.watch(playbackProvider);
|
Playback playback = ref.watch(playbackProvider);
|
||||||
final breakpoint = useBreakpoints();
|
final breakpoint = useBreakpoints();
|
||||||
@ -43,12 +51,15 @@ class SyncedLyrics extends HookConsumerWidget {
|
|||||||
[lyricValue],
|
[lyricValue],
|
||||||
);
|
);
|
||||||
|
|
||||||
final currentTime = useSyncedLyrics(ref, lyricsMap);
|
final currentTime = useSyncedLyrics(ref, lyricsMap, lyricDelay);
|
||||||
|
|
||||||
final textTheme = Theme.of(context).textTheme;
|
final textTheme = Theme.of(context).textTheme;
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
controller.scrollToIndex(0);
|
controller.scrollToIndex(0);
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
ref.read(lyricDelayState.notifier).state = Duration.zero;
|
||||||
|
});
|
||||||
failed.value = false;
|
failed.value = false;
|
||||||
return null;
|
return null;
|
||||||
}, [playback.track]);
|
}, [playback.track]);
|
||||||
@ -130,7 +141,7 @@ class SyncedLyrics extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: BackdropFilter(
|
child: BackdropFilter(
|
||||||
filter: ImageFilter.blur(sigmaX: 15, sigmaY: 15),
|
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
|
||||||
child: Container(
|
child: Container(
|
||||||
color: palette.color.withOpacity(.7),
|
color: palette.color.withOpacity(.7),
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
@ -141,20 +152,50 @@ class SyncedLyrics extends HookConsumerWidget {
|
|||||||
PageWindowTitleBar(
|
PageWindowTitleBar(
|
||||||
foregroundColor: palette.bodyTextColor,
|
foregroundColor: palette.bodyTextColor,
|
||||||
),
|
),
|
||||||
Center(
|
SizedBox(
|
||||||
child: SizedBox(
|
|
||||||
height: breakpoint >= Breakpoints.md ? 50 : 30,
|
height: breakpoint >= Breakpoints.md ? 50 : 30,
|
||||||
child: playback.track?.name != null &&
|
child: Material(
|
||||||
playback.track!.name!.length > 29
|
type: MaterialType.transparency,
|
||||||
? SpotubeMarqueeText(
|
child: Stack(
|
||||||
text: playback.track?.name ?? "Not Playing",
|
children: [
|
||||||
style: headlineTextStyle,
|
Center(
|
||||||
)
|
child: playback.track?.name != null &&
|
||||||
: Text(
|
playback.track!.name!.length > 29
|
||||||
playback.track?.name ?? "Not Playing",
|
? SpotubeMarqueeText(
|
||||||
style: headlineTextStyle,
|
text: playback.track?.name ??
|
||||||
|
"Not Playing",
|
||||||
|
style: headlineTextStyle,
|
||||||
|
)
|
||||||
|
: Text(
|
||||||
|
playback.track?.name ?? "Not Playing",
|
||||||
|
style: headlineTextStyle,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)),
|
Positioned.fill(
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: IconButton(
|
||||||
|
tooltip: "Lyrics Delay",
|
||||||
|
icon: const Icon(Icons.av_timer_rounded),
|
||||||
|
onPressed: () async {
|
||||||
|
final delay = await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) =>
|
||||||
|
const LyricDelayAdjustDialog(),
|
||||||
|
);
|
||||||
|
if (delay != null) {
|
||||||
|
ref
|
||||||
|
.read(lyricDelayState.notifier)
|
||||||
|
.state = delay;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
artistsToString<Artist>(
|
artistsToString<Artist>(
|
||||||
@ -173,6 +214,7 @@ class SyncedLyrics extends HookConsumerWidget {
|
|||||||
final lyricSlice = lyricValue.lyrics[index];
|
final lyricSlice = lyricValue.lyrics[index];
|
||||||
final isActive =
|
final isActive =
|
||||||
lyricSlice.time.inSeconds == currentTime;
|
lyricSlice.time.inSeconds == currentTime;
|
||||||
|
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
controller.scrollToIndex(
|
controller.scrollToIndex(
|
||||||
index,
|
index,
|
||||||
|
@ -2,7 +2,11 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:spotube/provider/Playback.dart';
|
import 'package:spotube/provider/Playback.dart';
|
||||||
|
|
||||||
useSyncedLyrics(WidgetRef ref, Map<int, String> lyricsMap) {
|
int useSyncedLyrics(
|
||||||
|
WidgetRef ref,
|
||||||
|
Map<int, String> lyricsMap,
|
||||||
|
Duration delay,
|
||||||
|
) {
|
||||||
final player = ref.watch(playbackProvider.select(
|
final player = ref.watch(playbackProvider.select(
|
||||||
(value) => (value.player),
|
(value) => (value.player),
|
||||||
));
|
));
|
||||||
@ -19,5 +23,5 @@ useSyncedLyrics(WidgetRef ref, Map<int, String> lyricsMap) {
|
|||||||
return () => lol.cancel();
|
return () => lol.cancel();
|
||||||
}, [lyricsMap]);
|
}, [lyricsMap]);
|
||||||
|
|
||||||
return currentTime.value;
|
return (Duration(seconds: currentTime.value) + delay).inSeconds;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,7 @@ ThemeData darkTheme({
|
|||||||
borderRadius: BorderRadius.circular(18.0),
|
borderRadius: BorderRadius.circular(18.0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
dialogTheme: DialogTheme(backgroundColor: backgroundMaterialColor[900]),
|
||||||
cardColor: backgroundMaterialColor[800],
|
cardColor: backgroundMaterialColor[800],
|
||||||
canvasColor: backgroundMaterialColor[900],
|
canvasColor: backgroundMaterialColor[900],
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user