-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Playing Directly from Artist Page #493
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5561722
Feature Add: Play Directly from artist page
BobcatNoah 6f56c7a
Fixed Genre tab
BobcatNoah 80715a6
Improved artist offline implementation
BobcatNoah 89ecb32
Fixed artist offline view (not artist tab) & queue
BobcatNoah f5796c7
Extra Null Safety
BobcatNoah 141f029
Add shuffle button
BobcatNoah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:hive/hive.dart'; | ||
|
||
|
||
import '../../models/jellyfin_models.dart'; | ||
import '../../models/finamp_models.dart'; | ||
import '../../services/jellyfin_api_helper.dart'; | ||
import '../../services/audio_service_helper.dart'; | ||
import '../../services/finamp_settings_helper.dart'; | ||
import '../../services/downloads_helper.dart'; | ||
|
||
class ArtistPlayButton extends StatefulWidget { | ||
const ArtistPlayButton({ | ||
Key? key, | ||
required this.artist, | ||
}) : super(key: key); | ||
|
||
final BaseItemDto artist; | ||
|
||
|
||
@override | ||
State<ArtistPlayButton> createState() => _ArtistPlayButtonState(); | ||
} | ||
|
||
class _ArtistPlayButtonState extends State<ArtistPlayButton> { | ||
static const _disabledButton = IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.play_arrow) | ||
); | ||
Future<List<BaseItemDto>?>? artistPlayButtonFuture; | ||
|
||
final _jellyfinApiHelper = GetIt.instance<JellyfinApiHelper>(); | ||
final _audioServiceHelper = GetIt.instance<AudioServiceHelper>(); | ||
|
||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ValueListenableBuilder<Box<FinampSettings>>( | ||
valueListenable: FinampSettingsHelper.finampSettingsListener, | ||
builder: (context, box, _) { | ||
final isOffline = box.get("FinampSettings")?.isOffline ?? false; | ||
|
||
if (isOffline) { | ||
final downloadsHelper = GetIt.instance<DownloadsHelper>(); | ||
|
||
final List<BaseItemDto>artistsSongs = []; | ||
|
||
for (DownloadedSong item in downloadsHelper.downloadedItems) { | ||
if (item.song.albumArtist == widget.artist.name) { | ||
artistsSongs.add(item.song); | ||
} | ||
} | ||
|
||
// We have to sort by hand in offline mode because a downloadedParent for artists hasn't been implemented | ||
Map<String, List<BaseItemDto>> groupedSongs = {}; | ||
for (BaseItemDto song in artistsSongs) { | ||
groupedSongs.putIfAbsent((song.albumId ?? 'unknown'), () => []); | ||
groupedSongs[song.albumId]!.add(song); | ||
} | ||
|
||
final List<BaseItemDto> sortedSongs = []; | ||
groupedSongs.forEach((album, albumSongs) { | ||
albumSongs.sort((a, b) => (a.indexNumber ?? 0).compareTo(b.indexNumber ?? 0)); | ||
sortedSongs.addAll(albumSongs); | ||
}); | ||
|
||
return IconButton( | ||
onPressed: () async { | ||
await _audioServiceHelper | ||
.replaceQueueWithItem(itemList: sortedSongs); | ||
}, | ||
icon: const Icon(Icons.play_arrow), | ||
); | ||
} else { | ||
artistPlayButtonFuture ??= _jellyfinApiHelper.getItems( | ||
parentItem: widget.artist, | ||
includeItemTypes: "Audio", | ||
sortBy: 'PremiereDate,Album,SortName', | ||
isGenres: false, | ||
); | ||
|
||
return FutureBuilder<List<BaseItemDto>?>( | ||
future: artistPlayButtonFuture, | ||
builder: (context, snapshot) { | ||
if (snapshot.hasData){ | ||
final List<BaseItemDto> items = snapshot.data!; | ||
|
||
return IconButton( | ||
onPressed: () async { | ||
await _audioServiceHelper | ||
.replaceQueueWithItem(itemList: items); | ||
}, | ||
icon: const Icon(Icons.play_arrow), | ||
); | ||
} else { | ||
return _disabledButton; | ||
} | ||
}, | ||
); | ||
} | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:hive/hive.dart'; | ||
|
||
|
||
import '../../models/jellyfin_models.dart'; | ||
import '../../models/finamp_models.dart'; | ||
import '../../services/jellyfin_api_helper.dart'; | ||
import '../../services/audio_service_helper.dart'; | ||
import '../../services/finamp_settings_helper.dart'; | ||
import '../../services/downloads_helper.dart'; | ||
|
||
class ArtistShuffleButton extends StatefulWidget { | ||
const ArtistShuffleButton({ | ||
Key? key, | ||
required this.artist, | ||
}) : super(key: key); | ||
|
||
final BaseItemDto artist; | ||
|
||
|
||
@override | ||
State<ArtistShuffleButton> createState() => _ArtistShuffleButtonState(); | ||
} | ||
|
||
class _ArtistShuffleButtonState extends State<ArtistShuffleButton> { | ||
static const _disabledButton = IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.play_arrow) | ||
); | ||
Future<List<BaseItemDto>?>? artistShuffleButtonFuture; | ||
|
||
final _jellyfinApiHelper = GetIt.instance<JellyfinApiHelper>(); | ||
final _audioServiceHelper = GetIt.instance<AudioServiceHelper>(); | ||
|
||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ValueListenableBuilder<Box<FinampSettings>>( | ||
valueListenable: FinampSettingsHelper.finampSettingsListener, | ||
builder: (context, box, _) { | ||
final isOffline = box.get("FinampSettings")?.isOffline ?? false; | ||
|
||
if (isOffline) { | ||
final downloadsHelper = GetIt.instance<DownloadsHelper>(); | ||
|
||
final List<BaseItemDto>artistsSongs = []; | ||
|
||
for (DownloadedSong item in downloadsHelper.downloadedItems) { | ||
if (item.song.albumArtist == widget.artist.name) { | ||
artistsSongs.add(item.song); | ||
} | ||
} | ||
|
||
return IconButton( | ||
onPressed: () async { | ||
await _audioServiceHelper | ||
.replaceQueueWithItem(itemList: artistsSongs, shuffle: true); | ||
}, | ||
icon: const Icon(Icons.shuffle), | ||
); | ||
} else { | ||
artistShuffleButtonFuture ??= _jellyfinApiHelper.getItems( | ||
parentItem: widget.artist, | ||
includeItemTypes: "Audio", | ||
sortBy: 'PremiereDate,Album,SortName', | ||
isGenres: false, | ||
); | ||
|
||
return FutureBuilder<List<BaseItemDto>?>( | ||
future: artistShuffleButtonFuture, | ||
builder: (context, snapshot) { | ||
if (snapshot.hasData){ | ||
final List<BaseItemDto> items = snapshot.data!; | ||
|
||
return IconButton( | ||
onPressed: () async { | ||
await _audioServiceHelper | ||
.replaceQueueWithItem(itemList: items, shuffle: true); | ||
}, | ||
icon: const Icon(Icons.shuffle), | ||
); | ||
} else { | ||
return _disabledButton; | ||
} | ||
}, | ||
); | ||
} | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a shuffle button as well?