mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
refactor: remove un-working lyric delay
This commit is contained in:
parent
10d0660972
commit
1ce0972b88
@ -1,113 +0,0 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:platform_ui/platform_ui.dart';
|
||||
import 'package:spotube/collections/spotube_icons.dart';
|
||||
import 'package:spotube/components/root/sidebar.dart';
|
||||
import 'package:spotube/pages/lyrics/synced_lyrics.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 PlatformAlertDialog(
|
||||
macosAppIcon: Sidebar.brandLogo(),
|
||||
title: const Center(child: Text("Adjust Lyrics Delay")),
|
||||
secondaryActions: [
|
||||
PlatformBuilder(
|
||||
fallback: PlatformBuilderFallback.android,
|
||||
android: (context, _) {
|
||||
return PlatformFilledButton(
|
||||
isSecondary: true,
|
||||
child: const Text("Cancel"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
ios: (context, data) {
|
||||
return CupertinoDialogAction(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
isDestructiveAction: true,
|
||||
child: const Text("Cancel"),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
primaryActions: [
|
||||
PlatformBuilder(
|
||||
fallback: PlatformBuilderFallback.android,
|
||||
android: (context, _) {
|
||||
return PlatformFilledButton(
|
||||
child: const Text("Done"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(
|
||||
Duration(
|
||||
milliseconds: getValue().toInt(),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
ios: (context, data) {
|
||||
return CupertinoDialogAction(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(
|
||||
Duration(
|
||||
milliseconds: getValue().toInt(),
|
||||
),
|
||||
);
|
||||
},
|
||||
isDefaultAction: true,
|
||||
child: const Text("Done"),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
content: SizedBox(
|
||||
height: 100,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
PlatformIconButton(
|
||||
icon: const Icon(SpotubeIcons.remove),
|
||||
onPressed: () {
|
||||
controller.text = "${getValue() - 25}ms";
|
||||
},
|
||||
),
|
||||
Flexible(
|
||||
child: PlatformTextField(
|
||||
keyboardType: TextInputType.number,
|
||||
controller: controller,
|
||||
placeholder: "Delay in milliseconds",
|
||||
onSubmitted: (_) {
|
||||
Navigator.of(context).pop(
|
||||
Duration(
|
||||
milliseconds: getValue().toInt(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
PlatformIconButton(
|
||||
icon: const Icon(SpotubeIcons.add),
|
||||
onPressed: () {
|
||||
controller.text = "${getValue() + 25}ms";
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -5,20 +5,18 @@ import 'package:spotube/provider/playlist_queue_provider.dart';
|
||||
int useSyncedLyrics(
|
||||
WidgetRef ref,
|
||||
Map<int, String> lyricsMap,
|
||||
Duration delay,
|
||||
) {
|
||||
final stream = PlaylistQueueNotifier.position;
|
||||
|
||||
final currentTime = useState(0);
|
||||
|
||||
useEffect(() {
|
||||
final lol = stream.listen((pos) {
|
||||
return stream.listen((pos) {
|
||||
if (lyricsMap.containsKey(pos.inSeconds)) {
|
||||
currentTime.value = pos.inSeconds;
|
||||
}
|
||||
});
|
||||
return () => lol.cancel();
|
||||
}).cancel;
|
||||
}, [lyricsMap]);
|
||||
|
||||
return (Duration(seconds: currentTime.value) + delay).inSeconds;
|
||||
return (Duration(seconds: currentTime.value)).inSeconds;
|
||||
}
|
||||
|
@ -2,13 +2,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.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/collections/spotube_icons.dart';
|
||||
import 'package:spotube/components/lyrics/zoom_controls.dart';
|
||||
import 'package:spotube/components/shared/shimmers/shimmer_lyrics.dart';
|
||||
import 'package:spotube/components/shared/spotube_marquee_text.dart';
|
||||
import 'package:spotube/components/lyrics/lyric_delay_adjust_dialog.dart';
|
||||
import 'package:spotube/hooks/use_auto_scroll_controller.dart';
|
||||
import 'package:spotube/hooks/use_breakpoints.dart';
|
||||
import 'package:spotube/hooks/use_synced_lyrics.dart';
|
||||
@ -18,12 +15,6 @@ import 'package:spotube/services/queries/queries.dart';
|
||||
|
||||
import 'package:spotube/utils/type_conversion_utils.dart';
|
||||
|
||||
final lyricDelayState = StateProvider<Duration>(
|
||||
(ref) {
|
||||
return Duration.zero;
|
||||
},
|
||||
);
|
||||
|
||||
class SyncedLyrics extends HookConsumerWidget {
|
||||
final PaletteColor palette;
|
||||
final bool? isModal;
|
||||
@ -37,7 +28,6 @@ class SyncedLyrics extends HookConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, ref) {
|
||||
final playlist = ref.watch(PlaylistQueueNotifier.provider);
|
||||
final lyricDelay = ref.watch(lyricDelayState);
|
||||
|
||||
final breakpoint = useBreakpoints();
|
||||
final controller = useAutoScrollController();
|
||||
@ -54,16 +44,13 @@ class SyncedLyrics extends HookConsumerWidget {
|
||||
{},
|
||||
[lyricValue],
|
||||
);
|
||||
final currentTime = useSyncedLyrics(ref, lyricsMap, lyricDelay);
|
||||
final currentTime = useSyncedLyrics(ref, lyricsMap);
|
||||
final textZoomLevel = useState<int>(100);
|
||||
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
|
||||
useEffect(() {
|
||||
controller.scrollToIndex(0);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ref.read(lyricDelayState.notifier).state = Duration.zero;
|
||||
});
|
||||
return null;
|
||||
}, [playlist?.activeTrack]);
|
||||
|
||||
@ -148,28 +135,6 @@ class SyncedLyrics extends HookConsumerWidget {
|
||||
const Expanded(child: ShimmerLyrics()),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
top: 10,
|
||||
right: 10,
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: PlatformFilledButton(
|
||||
child: const Icon(
|
||||
SpotubeIcons.clock,
|
||||
size: 16,
|
||||
),
|
||||
onPressed: () async {
|
||||
final delay = await showPlatformAlertDialog(
|
||||
context,
|
||||
builder: (context) => const LyricDelayAdjustDialog(),
|
||||
);
|
||||
if (delay != null) {
|
||||
ref.read(lyricDelayState.notifier).state = delay;
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: ZoomControls(
|
||||
|
Loading…
Reference in New Issue
Block a user