Skip to content

Commit

Permalink
fix: album & playlist card, player view and album view play button logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Aug 25, 2022
1 parent a1d4230 commit 55852bd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 30 deletions.
8 changes: 6 additions & 2 deletions lib/components/Album/AlbumCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AlbumCard extends HookConsumerWidget {
return PlaybuttonCard(
imageUrl: TypeConversionUtils.image_X_UrlString(album.images),
margin: EdgeInsets.symmetric(horizontal: marginH.toDouble()),
isPlaying: playback.playlist?.id == album.id,
isPlaying: isPlaylistPlaying && playback.isPlaying,
isLoading: playback.status == PlaybackStatus.loading &&
playback.playlist?.id == album.id,
title: album.name!,
Expand All @@ -34,7 +34,11 @@ class AlbumCard extends HookConsumerWidget {
},
onPlaybuttonPressed: () async {
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())
.map((track) =>
TypeConversionUtils.simpleTrack_X_Track(track, album))
Expand Down
25 changes: 15 additions & 10 deletions lib/components/Album/AlbumView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ class AlbumView extends HookConsumerWidget {

final breakpoint = useBreakpoints();

final isAlbumPlaying =
playback.playlist?.id != null && playback.playlist?.id == album.id;
return TrackCollectionView(
id: album.id!,
isPlaying:
playback.playlist?.id != null && playback.playlist?.id == album.id,
isPlaying: isAlbumPlaying,
title: album.name!,
titleImage: albumArt,
tracksSnapshot: tracksSnapshot,
Expand All @@ -67,14 +68,18 @@ class AlbumView extends HookConsumerWidget {
bottomSpace: breakpoint.isLessThanOrEqualTo(Breakpoints.md),
onPlay: ([track]) {
if (tracksSnapshot.asData?.value != null) {
playPlaylist(
playback,
tracksSnapshot.asData!.value
.map((track) =>
TypeConversionUtils.simpleTrack_X_Track(track, album))
.toList(),
currentTrack: track,
);
if (!isAlbumPlaying) {
playPlaylist(
playback,
tracksSnapshot.asData!.value
.map((track) =>
TypeConversionUtils.simpleTrack_X_Track(track, album))
.toList(),
currentTrack: track,
);
} else {
playback.stop();
}
}
},
onShare: () {
Expand Down
8 changes: 6 additions & 2 deletions lib/components/Playlist/PlaylistCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PlaylistCard extends HookConsumerWidget {
margin: EdgeInsets.symmetric(horizontal: marginH.toDouble()),
title: playlist.name!,
imageUrl: TypeConversionUtils.image_X_UrlString(playlist.images),
isPlaying: isPlaylistPlaying,
isPlaying: isPlaylistPlaying && playback.isPlaying,
isLoading: playback.status == PlaybackStatus.loading && isPlaylistPlaying,
onTap: () {
GoRouter.of(context).push(
Expand All @@ -33,7 +33,11 @@ class PlaylistCard extends HookConsumerWidget {
);
},
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);

List<Track> tracks = (playlist.id != "user-liked-tracks"
Expand Down
14 changes: 9 additions & 5 deletions lib/components/Playlist/PlaylistView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ class PlaylistView extends HookConsumerWidget {
playlist.owner!.id == meSnapshot.asData?.value.id,
onPlay: ([track]) {
if (tracksSnapshot.asData?.value != null) {
playPlaylist(
playback,
tracksSnapshot.asData!.value,
currentTrack: track,
);
if (!isPlaylistPlaying) {
playPlaylist(
playback,
tracksSnapshot.asData!.value,
currentTrack: track,
);
} else {
playback.stop();
}
}
},
bottomSpace: breakpoint.isLessThanOrEqualTo(Breakpoints.md),
Expand Down
20 changes: 10 additions & 10 deletions lib/components/Shared/TrackTile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ class TrackTile extends HookConsumerWidget {
const SizedBox(width: 10),
AdaptiveActions(
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)
Action(
icon: const Icon(Icons.add_box_rounded),
Expand All @@ -284,16 +294,6 @@ class TrackTile extends HookConsumerWidget {
text: const Text("Remove from playlist"),
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(
icon: const Icon(Icons.share_rounded),
text: const Text("Share"),
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/UserPreferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UserPreferences extends PersistedChangeNotifier {
this.accentColorScheme = Colors.green,
this.backgroundColorScheme = Colors.grey,
this.checkUpdate = true,
this.trackMatchAlgorithm = SpotubeTrackMatchAlgorithm.authenticPopular,
this.trackMatchAlgorithm = SpotubeTrackMatchAlgorithm.youtube,
this.audioQuality = AudioQuality.high,
this.skipSponsorSegments = true,
this.downloadLocation = "",
Expand Down

0 comments on commit 55852bd

Please sign in to comment.