mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00

* feat: add riverpod based favorite album provider * feat: add album is saved, new releases and tracks providers * feat: add artist related providers * feat: add all categories providers * feat: add lyrics provider * feat: add playlist related providers * feat: add search provider * feat: add view and spotify friends provider * feat: add playlist create and update and favorite handlers * feat: use providers in home screen * chore: fix dart lint issues * feat: use new providers for playlist and albums screen * feat: use providers in artist page * feat: use providers on library page * feat: use provider for playlist and album card and heart button * feat: use provider in search page * feat: use providers in generate playlist * feat: use provider in lyrics screen * feat: use provider for create playlist * feat: use provider in add track dialog * feat: use providers in remaining pages and remove fl_query * fix: remove direct access to provider.value * fix: glitching when loading * fix: user album loading next page indicator * feat: make many provider autoDispose after 5 minutes of no usage * fix: ignore episodes in tracks
138 lines
4.3 KiB
Dart
138 lines
4.3 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
import 'package:gap/gap.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:palette_generator/palette_generator.dart';
|
|
import 'package:spotube/collections/spotube_icons.dart';
|
|
import 'package:spotube/components/shared/tracks_view/track_view_props.dart';
|
|
import 'package:spotube/extensions/context.dart';
|
|
import 'package:spotube/provider/proxy_playlist/proxy_playlist_provider.dart';
|
|
import 'package:spotube/services/audio_player/audio_player.dart';
|
|
|
|
class TrackViewHeaderButtons extends HookConsumerWidget {
|
|
final PaletteColor color;
|
|
final bool compact;
|
|
const TrackViewHeaderButtons({
|
|
super.key,
|
|
required this.color,
|
|
this.compact = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context, ref) {
|
|
final props = InheritedTrackView.of(context);
|
|
final playlist = ref.watch(ProxyPlaylistNotifier.provider);
|
|
final playlistNotifier = ref.watch(ProxyPlaylistNotifier.notifier);
|
|
|
|
final isActive = playlist.collections.contains(props.collectionId);
|
|
|
|
final isLoading = useState(false);
|
|
|
|
const progressIndicator = Center(
|
|
child: SizedBox.square(
|
|
dimension: 20,
|
|
child: CircularProgressIndicator(strokeWidth: .8),
|
|
),
|
|
);
|
|
|
|
void onShuffle() async {
|
|
try {
|
|
isLoading.value = true;
|
|
|
|
final allTracks = await props.pagination.onFetchAll();
|
|
|
|
await playlistNotifier.load(
|
|
allTracks,
|
|
autoPlay: true,
|
|
initialIndex: Random().nextInt(allTracks.length),
|
|
);
|
|
await audioPlayer.setShuffle(true);
|
|
playlistNotifier.addCollection(props.collectionId);
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
}
|
|
|
|
void onPlay() async {
|
|
try {
|
|
isLoading.value = true;
|
|
|
|
final allTracks = await props.pagination.onFetchAll();
|
|
|
|
await playlistNotifier.load(allTracks, autoPlay: true);
|
|
playlistNotifier.addCollection(props.collectionId);
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
}
|
|
|
|
if (compact) {
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (!isActive && !isLoading.value)
|
|
IconButton(
|
|
icon: const Icon(SpotubeIcons.shuffle),
|
|
onPressed: props.tracks.isEmpty ? null : onShuffle,
|
|
),
|
|
const Gap(10),
|
|
IconButton.filledTonal(
|
|
icon: isActive
|
|
? const Icon(SpotubeIcons.pause)
|
|
: isLoading.value
|
|
? progressIndicator
|
|
: const Icon(SpotubeIcons.play),
|
|
onPressed: isActive || props.tracks.isEmpty || isLoading.value
|
|
? null
|
|
: onPlay,
|
|
),
|
|
const Gap(10),
|
|
],
|
|
);
|
|
}
|
|
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
AnimatedOpacity(
|
|
duration: const Duration(milliseconds: 300),
|
|
opacity: isActive || isLoading.value ? 0 : 1,
|
|
child: AnimatedSize(
|
|
duration: const Duration(milliseconds: 300),
|
|
child: SizedBox.square(
|
|
dimension: isActive || isLoading.value ? 0 : null,
|
|
child: FilledButton.icon(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.white,
|
|
foregroundColor: Colors.black,
|
|
minimumSize: const Size(150, 40)),
|
|
label: Text(context.l10n.shuffle),
|
|
icon: const Icon(SpotubeIcons.shuffle),
|
|
onPressed: props.tracks.isEmpty ? null : onShuffle,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const Gap(10),
|
|
FilledButton.icon(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: color.color,
|
|
foregroundColor: color.bodyTextColor,
|
|
minimumSize: const Size(150, 40)),
|
|
onPressed: isActive || props.tracks.isEmpty || isLoading.value
|
|
? null
|
|
: onPlay,
|
|
icon: isActive
|
|
? const Icon(SpotubeIcons.pause)
|
|
: isLoading.value
|
|
? progressIndicator
|
|
: const Icon(SpotubeIcons.play),
|
|
label: Text(context.l10n.play),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|