fix(playbutton): playing state is not updating when playlist is actually playing

This commit is contained in:
Kingkor Roy Tirtho 2023-02-05 12:36:07 +06:00
parent 576e2c6a1f
commit 9bad8c9eb8
4 changed files with 33 additions and 39 deletions

View File

@ -85,7 +85,7 @@ I'm always releasing newer versions of binary of the software each 2-3 month wit
> **Note!:** If you don't understand this download table. You can read [installation instructions][wiki-installation-instructions] from the wiki
## Nightly Builds
Get the latest nightly builds of Spotube [here](https://nightly.link/KRTirtho/spotube/workflows/spotube-nightly/build)
Get the latest nightly builds of Spotube [here](https://github.com/KRTirtho/spotube/releases/tag/nightly)
# TODO:
- [ ] Windows OS Media Control & Media Keys Support

View File

@ -5,11 +5,12 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/components/shared/playbutton_card.dart';
import 'package:spotube/hooks/use_breakpoint_value.dart';
import 'package:spotube/provider/spotify_provider.dart';
import 'package:spotube/provider/playlist_queue_provider.dart';
import 'package:spotube/provider/spotify_provider.dart';
import 'package:spotube/services/queries/queries.dart';
import 'package:spotube/utils/service_utils.dart';
import 'package:spotube/utils/type_conversion_utils.dart';
import 'package:uuid/uuid.dart';
class PlaylistCard extends HookConsumerWidget {
final PlaylistSimple playlist;
@ -24,12 +25,12 @@ class PlaylistCard extends HookConsumerWidget {
final playlistQueue = ref.watch(PlaylistQueueNotifier.provider);
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
final playing = useStream(PlaylistQueueNotifier.playing).data ?? false;
final tracks = QueryBowl.of(context)
.getQuery<List<Track>, SpotifyApi>(
Queries.playlist.tracksOf(playlist.id!).queryKey)
?.data ??
[];
bool isPlaylistPlaying = playlistNotifier.isPlayingPlaylist(tracks);
final queryBowl = QueryBowl.of(context);
final query = queryBowl.getQuery<List<Track>, SpotifyApi>(
Queries.playlist.tracksOf(playlist.id!).queryKey,
);
final tracks = useState(query?.data ?? []);
bool isPlaylistPlaying = playlistNotifier.isPlayingPlaylist(tracks.value);
final int marginH =
useBreakpointValue(sm: 10, md: 15, lg: 20, xl: 20, xxl: 20);
@ -56,20 +57,18 @@ class PlaylistCard extends HookConsumerWidget {
} else if (isPlaylistPlaying && !playing) {
return playlistNotifier.resume();
}
SpotifyApi spotifyApi = ref.read(spotifyProvider);
List<Track> tracks = (playlist.id != "user-liked-tracks"
? await spotifyApi.playlists
.getTracksByPlaylistId(playlist.id!)
.all()
: await spotifyApi.tracks.me.saved
.all()
.then((tracks) => tracks.map((e) => e.track!)))
.toList();
List<Track> fetchedTracks = await queryBowl.fetchQuery(
key: ValueKey(const Uuid().v4()),
Queries.playlist.tracksOf(playlist.id!),
externalData: ref.read(spotifyProvider),
) ??
[];
if (tracks.isEmpty) return;
if (fetchedTracks.isEmpty) return;
await playlistNotifier.loadAndPlay(tracks);
await playlistNotifier.loadAndPlay(fetchedTracks);
tracks.value = fetchedTracks;
},
);
}

View File

@ -286,6 +286,11 @@ class ArtistPage extends HookConsumerWidget {
externalData: spotify,
);
final isPlaylistPlaying =
playlistNotifier.isPlayingPlaylist(
topTracksQuery.data ?? <Track>[],
);
if (topTracksQuery.isLoading || !topTracksQuery.hasData) {
return const PlatformCircularProgressIndicator();
} else if (topTracksQuery.hasError) {
@ -296,10 +301,7 @@ class ArtistPage extends HookConsumerWidget {
final topTracks = topTracksQuery.data!;
final isPlaylistPlaying = useMemoized(() {
return playlistNotifier.isPlayingPlaylist(topTracks);
}, [topTracks]);
playPlaylist(List<Track> tracks,
void playPlaylist(List<Track> tracks,
{Track? currentTrack}) async {
currentTrack ??= tracks.first;
if (!isPlaylistPlaying) {
@ -321,22 +323,16 @@ class ArtistPage extends HookConsumerWidget {
style:
PlatformTheme.of(context).textTheme?.headline,
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 5),
decoration: BoxDecoration(
color: PlatformTheme.of(context).primaryColor,
borderRadius: BorderRadius.circular(50),
),
child: PlatformIconButton(
icon: Icon(
isPlaylistPlaying
? SpotubeIcons.stop
: SpotubeIcons.play,
color: Colors.white,
),
onPressed: () =>
playPlaylist(topTracks.toList()),
PlatformIconButton(
icon: Icon(
isPlaylistPlaying
? SpotubeIcons.stop
: SpotubeIcons.play,
color: Colors.white,
),
backgroundColor:
PlatformTheme.of(context).primaryColor,
onPressed: () => playPlaylist(topTracks.toList()),
)
],
),

View File

@ -45,7 +45,6 @@ class PlaylistView extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final playlistQueue = ref.watch(PlaylistQueueNotifier.provider);
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
SpotifyApi spotify = ref.watch(spotifyProvider);