fix: album & playlist card, player view and album view play button logic

This commit is contained in:
Kingkor Roy Tirtho 2022-08-25 11:22:52 +06:00
parent a1d423090c
commit 55852bd15b
6 changed files with 47 additions and 30 deletions

View File

@ -23,7 +23,7 @@ class AlbumCard extends HookConsumerWidget {
return PlaybuttonCard( return PlaybuttonCard(
imageUrl: TypeConversionUtils.image_X_UrlString(album.images), imageUrl: TypeConversionUtils.image_X_UrlString(album.images),
margin: EdgeInsets.symmetric(horizontal: marginH.toDouble()), margin: EdgeInsets.symmetric(horizontal: marginH.toDouble()),
isPlaying: playback.playlist?.id == album.id, isPlaying: isPlaylistPlaying && playback.isPlaying,
isLoading: playback.status == PlaybackStatus.loading && isLoading: playback.status == PlaybackStatus.loading &&
playback.playlist?.id == album.id, playback.playlist?.id == album.id,
title: album.name!, title: album.name!,
@ -34,7 +34,11 @@ class AlbumCard extends HookConsumerWidget {
}, },
onPlaybuttonPressed: () async { onPlaybuttonPressed: () async {
SpotifyApi spotify = ref.read(spotifyProvider); SpotifyApi spotify = ref.read(spotifyProvider);
if (isPlaylistPlaying) return; if (isPlaylistPlaying && playback.isPlaying) {
return playback.pause();
} else if (isPlaylistPlaying && !playback.isPlaying) {
return playback.resume();
}
List<Track> tracks = (await spotify.albums.getTracks(album.id!).all()) List<Track> tracks = (await spotify.albums.getTracks(album.id!).all())
.map((track) => .map((track) =>
TypeConversionUtils.simpleTrack_X_Track(track, album)) TypeConversionUtils.simpleTrack_X_Track(track, album))

View File

@ -55,10 +55,11 @@ class AlbumView extends HookConsumerWidget {
final breakpoint = useBreakpoints(); final breakpoint = useBreakpoints();
final isAlbumPlaying =
playback.playlist?.id != null && playback.playlist?.id == album.id;
return TrackCollectionView( return TrackCollectionView(
id: album.id!, id: album.id!,
isPlaying: isPlaying: isAlbumPlaying,
playback.playlist?.id != null && playback.playlist?.id == album.id,
title: album.name!, title: album.name!,
titleImage: albumArt, titleImage: albumArt,
tracksSnapshot: tracksSnapshot, tracksSnapshot: tracksSnapshot,
@ -67,14 +68,18 @@ class AlbumView extends HookConsumerWidget {
bottomSpace: breakpoint.isLessThanOrEqualTo(Breakpoints.md), bottomSpace: breakpoint.isLessThanOrEqualTo(Breakpoints.md),
onPlay: ([track]) { onPlay: ([track]) {
if (tracksSnapshot.asData?.value != null) { if (tracksSnapshot.asData?.value != null) {
playPlaylist( if (!isAlbumPlaying) {
playback, playPlaylist(
tracksSnapshot.asData!.value playback,
.map((track) => tracksSnapshot.asData!.value
TypeConversionUtils.simpleTrack_X_Track(track, album)) .map((track) =>
.toList(), TypeConversionUtils.simpleTrack_X_Track(track, album))
currentTrack: track, .toList(),
); currentTrack: track,
);
} else {
playback.stop();
}
} }
}, },
onShare: () { onShare: () {

View File

@ -24,7 +24,7 @@ class PlaylistCard extends HookConsumerWidget {
margin: EdgeInsets.symmetric(horizontal: marginH.toDouble()), margin: EdgeInsets.symmetric(horizontal: marginH.toDouble()),
title: playlist.name!, title: playlist.name!,
imageUrl: TypeConversionUtils.image_X_UrlString(playlist.images), imageUrl: TypeConversionUtils.image_X_UrlString(playlist.images),
isPlaying: isPlaylistPlaying, isPlaying: isPlaylistPlaying && playback.isPlaying,
isLoading: playback.status == PlaybackStatus.loading && isPlaylistPlaying, isLoading: playback.status == PlaybackStatus.loading && isPlaylistPlaying,
onTap: () { onTap: () {
GoRouter.of(context).push( GoRouter.of(context).push(
@ -33,7 +33,11 @@ class PlaylistCard extends HookConsumerWidget {
); );
}, },
onPlaybuttonPressed: () async { onPlaybuttonPressed: () async {
if (isPlaylistPlaying) return; if (isPlaylistPlaying && playback.isPlaying) {
return playback.pause();
} else if (isPlaylistPlaying && !playback.isPlaying) {
return playback.resume();
}
SpotifyApi spotifyApi = ref.read(spotifyProvider); SpotifyApi spotifyApi = ref.read(spotifyProvider);
List<Track> tracks = (playlist.id != "user-liked-tracks" List<Track> tracks = (playlist.id != "user-liked-tracks"

View File

@ -77,11 +77,15 @@ class PlaylistView extends HookConsumerWidget {
playlist.owner!.id == meSnapshot.asData?.value.id, playlist.owner!.id == meSnapshot.asData?.value.id,
onPlay: ([track]) { onPlay: ([track]) {
if (tracksSnapshot.asData?.value != null) { if (tracksSnapshot.asData?.value != null) {
playPlaylist( if (!isPlaylistPlaying) {
playback, playPlaylist(
tracksSnapshot.asData!.value, playback,
currentTrack: track, tracksSnapshot.asData!.value,
); currentTrack: track,
);
} else {
playback.stop();
}
} }
}, },
bottomSpace: breakpoint.isLessThanOrEqualTo(Breakpoints.md), bottomSpace: breakpoint.isLessThanOrEqualTo(Breakpoints.md),

View File

@ -272,6 +272,16 @@ class TrackTile extends HookConsumerWidget {
const SizedBox(width: 10), const SizedBox(width: 10),
AdaptiveActions( AdaptiveActions(
actions: [ actions: [
if (auth.isLoggedIn)
Action(
icon: Icon(isSaved
? Icons.favorite_rounded
: Icons.favorite_border_rounded),
text: const Text("Save as favorite"),
onPressed: () {
actionFavorite(isSaved);
},
),
if (auth.isLoggedIn) if (auth.isLoggedIn)
Action( Action(
icon: const Icon(Icons.add_box_rounded), icon: const Icon(Icons.add_box_rounded),
@ -284,16 +294,6 @@ class TrackTile extends HookConsumerWidget {
text: const Text("Remove from playlist"), text: const Text("Remove from playlist"),
onPressed: actionRemoveFromPlaylist, onPressed: actionRemoveFromPlaylist,
), ),
if (auth.isLoggedIn)
Action(
icon: Icon(isSaved
? Icons.favorite_rounded
: Icons.favorite_border_rounded),
text: const Text("Save as favorite"),
onPressed: () {
actionFavorite(isSaved);
},
),
Action( Action(
icon: const Icon(Icons.share_rounded), icon: const Icon(Icons.share_rounded),
text: const Text("Share"), text: const Text("Share"),

View File

@ -39,7 +39,7 @@ class UserPreferences extends PersistedChangeNotifier {
this.accentColorScheme = Colors.green, this.accentColorScheme = Colors.green,
this.backgroundColorScheme = Colors.grey, this.backgroundColorScheme = Colors.grey,
this.checkUpdate = true, this.checkUpdate = true,
this.trackMatchAlgorithm = SpotubeTrackMatchAlgorithm.authenticPopular, this.trackMatchAlgorithm = SpotubeTrackMatchAlgorithm.youtube,
this.audioQuality = AudioQuality.high, this.audioQuality = AudioQuality.high,
this.skipSponsorSegments = true, this.skipSponsorSegments = true,
this.downloadLocation = "", this.downloadLocation = "",