Skip to content

Commit 38ad60a

Browse files
authored
Merge pull request #98 from Kreedyy/Features-testing
Feat: Add artist to queue button
2 parents 746400a + 1039c86 commit 38ad60a

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

lib/l10n/app_en.arb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,12 @@
12511251
"artistDataNotFound": "Artist not found",
12521252
"@artistDataNotFound": { "description": "Error state on the artist screen when artist data fails to load" },
12531253

1254+
"addedArtistToQueue": "Added artist to Queue",
1255+
"@addedArtistToQueue": { "description": "Snackbar when user adds artist to queue" },
1256+
1257+
"addedArtistToQueueError": "Failed adding artist to Queue",
1258+
"@addedArtistToQueueError": { "description": "Error shown in snackbar when adding artist to queue fails" },
1259+
12541260
"@_CAST_DLNA": {},
12551261
"casting": "Casting",
12561262
"@casting": { "description": "Title shown in the Chromecast control dialog when actively casting" },

lib/providers/player_provider.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,11 @@ class PlayerProvider extends ChangeNotifier {
12551255
notifyListeners();
12561256
}
12571257

1258+
void addAllToQueue(Iterable<Song> songs) {
1259+
_queue.addAll(songs);
1260+
notifyListeners();
1261+
}
1262+
12581263
void removeFromQueue(int index) {
12591264
if (index >= 0 && index < _queue.length) {
12601265
_queue.removeAt(index);

lib/screens/artist_screen.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,54 @@ class _ArtistScreenState extends State<ArtistScreen> {
7474
}
7575
}
7676

77+
Future<void> _addArtistToQueue() async {
78+
if (_albums.isEmpty) return;
79+
80+
final playerProvider = Provider.of<PlayerProvider>(context, listen: false);
81+
final libraryProvider = Provider.of<LibraryProvider>(context, listen: false);
82+
final subsonicService = libraryProvider.subsonicService;
83+
84+
final messenger = ScaffoldMessenger.of(context);
85+
final loc = AppLocalizations.of(context);
86+
87+
try {
88+
final songsToQueue = <Song>[];
89+
for (final album in _albums) {
90+
final albumSongs = libraryProvider.isLocalOnlyMode
91+
? libraryProvider.cachedAllSongs
92+
.where((s) => s.albumId == album.id)
93+
.toList()
94+
: await subsonicService.getAlbumSongs(album.id);
95+
96+
songsToQueue.addAll(albumSongs);
97+
}
98+
99+
if (songsToQueue.isNotEmpty) {
100+
playerProvider.addAllToQueue(songsToQueue);
101+
}
102+
103+
if (!mounted) return;
104+
105+
final addedToQueueMessage = loc?.addedArtistToQueue ?? 'Added artist to Queue';
106+
messenger.showSnackBar(
107+
SnackBar(
108+
content: Text(addedToQueueMessage),
109+
duration: const Duration(seconds: 2),
110+
),
111+
);
112+
} catch (e) {
113+
if (!mounted) return;
114+
115+
final addedToQueueErrorMessage = loc?.addedArtistToQueueError ?? 'Failed adding artist to Queue';
116+
messenger.showSnackBar(
117+
SnackBar(
118+
content: Text(addedToQueueErrorMessage),
119+
duration: const Duration(seconds: 2),
120+
),
121+
);
122+
}
123+
}
124+
77125
void _playTopSongs({bool shuffle = false}) {
78126
if (_topSongs.isEmpty) return;
79127

@@ -144,6 +192,11 @@ class _ArtistScreenState extends State<ArtistScreen> {
144192
),
145193
),
146194
actions: [
195+
IconButton(
196+
icon: const Icon(Icons.queue_music_rounded),
197+
tooltip: AppLocalizations.of(context)!.addToQueue,
198+
onPressed: _albums.isEmpty ? null : () => _addArtistToQueue(),
199+
),
147200
IconButton(
148201
icon: const Icon(CupertinoIcons.play_circle_fill),
149202
onPressed: () => _playTopSongs(),

0 commit comments

Comments
 (0)