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(
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!,
@ -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))

View File

@ -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,
@ -67,6 +68,7 @@ class AlbumView extends HookConsumerWidget {
bottomSpace: breakpoint.isLessThanOrEqualTo(Breakpoints.md),
onPlay: ([track]) {
if (tracksSnapshot.asData?.value != null) {
if (!isAlbumPlaying) {
playPlaylist(
playback,
tracksSnapshot.asData!.value
@ -75,6 +77,9 @@ class AlbumView extends HookConsumerWidget {
.toList(),
currentTrack: track,
);
} else {
playback.stop();
}
}
},
onShare: () {

View File

@ -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(
@ -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"

View File

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

View File

@ -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),
@ -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"),

View File

@ -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 = "",