Skip to content

Commit

Permalink
fix: shuffle play logic
Browse files Browse the repository at this point in the history
cd(nightly): fix linux runner bug
  • Loading branch information
KRTirtho committed Dec 8, 2022
1 parent 166710f commit 65cad07
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 62 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/spotube-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build_ubuntu:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: subosito/[email protected]
Expand All @@ -20,9 +20,9 @@ jobs:
sudo apt-get update -y
sudo apt-get install -y tar clang cmake ninja-build pkg-config libgtk-3-dev make python3-pip python3-setuptools patchelf desktop-file-utils libgdk-pixbuf2.0-dev fakeroot strace fuse libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
- run: |
wget -O appimage-builder-x86_64.AppImage https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.0.0-beta.1/appimage-builder-1.0.0-677acbd-x86_64.AppImage
chmod +x appimage-builder-x86_64.AppImage
mv appimage-builder-x86_64.AppImage /usr/local/bin/appimage-builder
wget -O appimage-builder https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage
chmod +x appimage-builder
mv appimage-builder /usr/local/bin/
- run: |
curl -sS https://webi.sh/yq | sh
Expand Down
20 changes: 0 additions & 20 deletions lib/components/shared/playlist_shuffle_button.dart

This file was deleted.

13 changes: 10 additions & 3 deletions lib/components/shared/track_table/track_collection_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class TrackCollectionView<T> extends HookConsumerWidget {
final String titleImage;
final bool isPlaying;
final void Function([Track? currentTrack]) onPlay;
final void Function([Track? currentTrack]) onShuffledPlay;
final void Function() onShare;
final Widget? heartBtn;
final Widget? shuffleButton;
final AlbumSimple? album;

final bool showShare;
Expand All @@ -41,10 +41,10 @@ class TrackCollectionView<T> extends HookConsumerWidget {
required this.titleImage,
required this.isPlaying,
required this.onPlay,
required this.onShuffledPlay,
required this.onShare,
required this.routePath,
this.heartBtn,
this.shuffleButton,
this.album,
this.description,
this.showShare = true,
Expand All @@ -70,7 +70,14 @@ class TrackCollectionView<T> extends HookConsumerWidget {
onPressed: onShare,
),
if (heartBtn != null) heartBtn!,
if (shuffleButton != null) shuffleButton!,
PlatformIconButton(
tooltip: "Shuffle",
icon: Icon(
Icons.shuffle,
color: color?.titleTextColor,
),
onPressed: onShuffledPlay,
),
const SizedBox(width: 5),
// play playlist
PlatformIconButton(
Expand Down
43 changes: 24 additions & 19 deletions lib/pages/album/album.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:spotube/utils/type_conversion_utils.dart';
import 'package:spotube/models/current_playlist.dart';
import 'package:spotube/provider/playback_provider.dart';
import 'package:spotube/provider/spotify_provider.dart';
import 'package:spotube/components/shared/playlist_shuffle_button.dart';

class AlbumPage extends HookConsumerWidget {
final AlbumSimple album;
Expand Down Expand Up @@ -113,26 +112,32 @@ class AlbumPage extends HookConsumerWidget {
);
},
heartBtn: AlbumHeartButton(album: album),
shuffleButton: PlaylistShuffleButton(onPressed: () {
var albumTracks = tracksSnapshot.data!
.map((track) =>
TypeConversionUtils.simpleTrack_X_Track(track, album))
.toList();
onShuffledPlay: ([track]) {
// Shuffle the tracks (create a copy of playlist)
var tracks = [...albumTracks];
tracks.shuffle();

// If playback is playing a track then pause it
if (playback.isPlaying) {
playback.pause();
if (tracksSnapshot.hasData) {
final tracks = tracksSnapshot.data!
.map((track) =>
TypeConversionUtils.simpleTrack_X_Track(track, album))
.toList()
..shuffle();
if (!isAlbumPlaying) {
playPlaylist(
playback,
tracks,
ref,
);
} else if (isAlbumPlaying && track != null) {
playPlaylist(
playback,
tracks,
ref,
currentTrack: track,
);
} else {
playback.stop();
}
}

// Play the shuffled playlist
playPlaylist( playback,
tracks,
ref,
);
}),
},
);
}
}
37 changes: 21 additions & 16 deletions lib/pages/playlist/playlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'package:spotube/services/queries/queries.dart';

import 'package:spotube/utils/service_utils.dart';
import 'package:spotube/utils/type_conversion_utils.dart';
import 'package:spotube/components/shared/playlist_shuffle_button.dart';

class PlaylistView extends HookConsumerWidget {
final logger = getLogger(PlaylistView);
Expand Down Expand Up @@ -127,23 +126,29 @@ class PlaylistView extends HookConsumerWidget {
});
},
heartBtn: PlaylistHeartButton(playlist: playlist),
shuffleButton: PlaylistShuffleButton(onPressed: () {
// Shuffle the tracks (create a copy of playlist)
var tracks = [...?tracksSnapshot.data];
tracks.shuffle();
onShuffledPlay: ([track]) {
final tracks = [...?tracksSnapshot.data]..shuffle();

// If playback is playing a track then pause it
if (playback.isPlaying) {
playback.pause();
if (tracksSnapshot.hasData) {
if (!isPlaylistPlaying) {
playPlaylist(
playback,
tracks,
ref,
currentTrack: track,
);
} else if (isPlaylistPlaying && track != null) {
playPlaylist(
playback,
tracks,
ref,
currentTrack: track,
);
} else {
playback.stop();
}
}

// Play the shuffled playlist
playPlaylist( playback,
tracks,
ref,
currentTrack: null,
);
}),
},
);
}
}

0 comments on commit 65cad07

Please sign in to comment.