Skip to content

Commit

Permalink
Fix inconsistent popup menu items.
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-kast committed Aug 7, 2023
1 parent 6ae1af9 commit 7b0f169
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
26 changes: 14 additions & 12 deletions lib/components/AlbumScreen/song_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,22 @@ class _SongListTileState extends State<SongListTile> {
screenSize.height - details.globalPosition.dy,
),
items: [
PopupMenuItem<SongListTileMenuItems>(
value: SongListTileMenuItems.addToQueue,
child: ListTile(
leading: const Icon(Icons.queue_music),
title: Text(AppLocalizations.of(context)!.addToQueue),
if (_audioServiceHelper.hasQueueItems()) ...[
PopupMenuItem<SongListTileMenuItems>(
value: SongListTileMenuItems.addToQueue,
child: ListTile(
leading: const Icon(Icons.queue_music),
title: Text(AppLocalizations.of(context)!.addToQueue),
),
),
),
PopupMenuItem<SongListTileMenuItems>(
value: SongListTileMenuItems.playNext,
child: ListTile(
leading: const Icon(Icons.queue_music),
title: Text(AppLocalizations.of(context)!.playNext),
PopupMenuItem<SongListTileMenuItems>(
value: SongListTileMenuItems.playNext,
child: ListTile(
leading: const Icon(Icons.queue_music),
title: Text(AppLocalizations.of(context)!.playNext),
),
),
),
],
PopupMenuItem<SongListTileMenuItems>(
value: SongListTileMenuItems.replaceQueueWithItem,
child: ListTile(
Expand Down
40 changes: 23 additions & 17 deletions lib/components/MusicScreen/album_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ class _AlbumItemState extends State<AlbumItem> {
onLongPressStart: (details) async {
Feedback.forLongPress(context);

if (FinampSettingsHelper.finampSettings.isOffline) {
// If offline, don't show the context menu since the only options here
// are for online.
return;
}
final isOffline = FinampSettingsHelper.finampSettings.isOffline;

final jellyfinApiHelper = GetIt.instance<JellyfinApiHelper>();

Expand All @@ -115,48 +111,58 @@ class _AlbumItemState extends State<AlbumItem> {
screenSize.height - details.globalPosition.dy,
),
items: [
PopupMenuItem<_AlbumListTileMenuItems>(
value: _AlbumListTileMenuItems.addToQueue,
child: ListTile(
leading: const Icon(Icons.queue_music),
title: Text(AppLocalizations.of(context)!.addToQueue),
if (_audioServiceHelper.hasQueueItems()) ...[
PopupMenuItem<_AlbumListTileMenuItems>(
value: _AlbumListTileMenuItems.addToQueue,
child: ListTile(
leading: const Icon(Icons.queue_music),
title: Text(AppLocalizations.of(context)!.addToQueue),
),
),
),
PopupMenuItem<_AlbumListTileMenuItems>(
value: _AlbumListTileMenuItems.playNext,
child: ListTile(
leading: const Icon(Icons.queue_music),
title: Text(AppLocalizations.of(context)!.playNext),
PopupMenuItem<_AlbumListTileMenuItems>(
value: _AlbumListTileMenuItems.playNext,
child: ListTile(
leading: const Icon(Icons.queue_music),
title: Text(AppLocalizations.of(context)!.playNext),
),
),
),
],
mutableAlbum.userData!.isFavorite
? PopupMenuItem<_AlbumListTileMenuItems>(
enabled: !isOffline,
value: _AlbumListTileMenuItems.removeFavourite,
child: ListTile(
enabled: !isOffline,
leading: const Icon(Icons.favorite_border),
title:
Text(AppLocalizations.of(context)!.removeFavourite),
),
)
: PopupMenuItem<_AlbumListTileMenuItems>(
enabled: !isOffline,
value: _AlbumListTileMenuItems.addFavourite,
child: ListTile(
enabled: !isOffline,
leading: const Icon(Icons.favorite),
title: Text(AppLocalizations.of(context)!.addFavourite),
),
),
jellyfinApiHelper.selectedMixAlbumIds.contains(mutableAlbum.id)
? PopupMenuItem<_AlbumListTileMenuItems>(
enabled: !isOffline,
value: _AlbumListTileMenuItems.removeFromMixList,
child: ListTile(
enabled: !isOffline,
leading: const Icon(Icons.explore_off),
title:
Text(AppLocalizations.of(context)!.removeFromMix),
),
)
: PopupMenuItem<_AlbumListTileMenuItems>(
enabled: !isOffline,
value: _AlbumListTileMenuItems.addToMixList,
child: ListTile(
enabled: !isOffline,
leading: const Icon(Icons.explore),
title: Text(AppLocalizations.of(context)!.addToMix),
),
Expand Down
4 changes: 4 additions & 0 deletions lib/services/audio_service_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class AudioServiceHelper {
}
}

bool hasQueueItems() {
return (_audioHandler.queue.valueOrNull?.length ?? 0) != 0;
}

@Deprecated("Use addQueueItems instead")
Future<void> addQueueItem(BaseItemDto item) async {
await addQueueItems([item]);
Expand Down

0 comments on commit 7b0f169

Please sign in to comment.