Skip to content

Commit

Permalink
Show song artists on album screen (and more) (#287)
Browse files Browse the repository at this point in the history
* SongListTile track artists WIP

* ignore artist order

* Offset DownloadedIndicator to align with track number, use ellipsis overflow for artists

* Pass now played item to FavoriteButton

* Use default color for FavoriteButton if not favorited

* Add settings option

* Replace stars with hearts in favorite buttons

* Add favorite button to album and artist screen

* Don't show favorite button for genres

* Put download indicator in TextSpan, specify size

* Align top, add 3 to widget size

* Add offset

* Remove redundant initState/dispose

Co-authored-by: UnicornsOnLSD <44349936+UnicornsOnLSD@users.noreply.github.com>
  • Loading branch information
rom4nik and jmshrv committed Jul 25, 2022
1 parent c5a177d commit 6c372eb
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 105 deletions.
24 changes: 19 additions & 5 deletions lib/components/AlbumScreen/album_screen_content.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';

import '../../models/jellyfin_models.dart';
import '../../services/finamp_settings_helper.dart';
import '../../components/favourite_button.dart';
import 'album_screen_content_flexible_space_bar.dart';
import 'download_button.dart';
import 'song_list_tile.dart';
Expand Down Expand Up @@ -54,6 +56,7 @@ class AlbumScreenContent extends StatelessWidget {
if (parent.type == "Playlist" &&
!FinampSettingsHelper.finampSettings.isOffline)
PlaylistNameEditButton(playlist: parent),
FavoriteButton(item: parent),
DownloadButton(parent: parent, items: children)
],
),
Expand All @@ -73,13 +76,13 @@ class AlbumScreenContent extends StatelessWidget {
sliver: _SongsSliverList(
childrenForList: childrenOfThisDisc,
childrenForQueue: children,
parentId: parent.id),
parent: parent),
)
else
_SongsSliverList(
childrenForList: children,
childrenForQueue: children,
parentId: parent.id),
parent: parent),
],
),
);
Expand All @@ -91,12 +94,12 @@ class _SongsSliverList extends StatelessWidget {
Key? key,
required this.childrenForList,
required this.childrenForQueue,
required this.parentId,
required this.parent,
}) : super(key: key);

final List<BaseItemDto> childrenForList;
final List<BaseItemDto> childrenForQueue;
final String? parentId;
final BaseItemDto parent;

@override
Widget build(BuildContext context) {
Expand All @@ -112,7 +115,18 @@ class _SongsSliverList extends StatelessWidget {
item: item,
children: childrenForQueue,
index: index + indexOffset,
parentId: parentId,
parentId: parent.id,
// show artists except for this one scenario
showArtists: !(
// we're on album screen
parent.type == "MusicAlbum"
// "hide song artists if they're the same as album artists" == true
&& FinampSettingsHelper.finampSettings
.hideSongArtistsIfSameAsAlbumArtists
// song artists == album artists
&& setEquals(parent.albumArtists?.map((e) => e.name).toSet(),
item.artists?.toSet())
)
);
}, childCount: childrenForList.length),
);
Expand Down
12 changes: 9 additions & 3 deletions lib/components/AlbumScreen/downloaded_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class DownloadedIndicator extends StatefulWidget {
const DownloadedIndicator({
Key? key,
required this.item,
this.size,
}) : super(key: key);

final BaseItemDto item;
final double? size;

@override
State<DownloadedIndicator> createState() => _DownloadedIndicatorState();
Expand Down Expand Up @@ -89,25 +91,29 @@ class _DownloadedIndicatorState extends State<DownloadedIndicator> {
return const SizedBox(width: 0, height: 0);
} else if (_currentStatus == DownloadTaskStatus.complete) {
return Icon(
Icons.file_download,
Icons.download,
color: Theme.of(context).colorScheme.secondary,
size: widget.size,
);
} else if (_currentStatus == DownloadTaskStatus.failed ||
_currentStatus == DownloadTaskStatus.undefined) {
return const Icon(
return Icon(
Icons.error,
color: Colors.red,
size: widget.size,
);
} else if (_currentStatus == DownloadTaskStatus.paused) {
return const Icon(
return Icon(
Icons.pause,
color: Colors.yellow,
size: widget.size,
);
} else if (_currentStatus == DownloadTaskStatus.enqueued ||
_currentStatus == DownloadTaskStatus.running) {
return Icon(
Icons.download_outlined,
color: Colors.white.withOpacity(0.5),
size: widget.size,
);
} else {
return const SizedBox(width: 0, height: 0);
Expand Down
52 changes: 42 additions & 10 deletions lib/components/AlbumScreen/song_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../../services/process_artist.dart';
import '../../services/music_player_background_task.dart';
import '../../screens/album_screen.dart';
import '../../screens/add_to_playlist_screen.dart';
import '../favourite_button.dart';
import '../album_image.dart';
import '../print_duration.dart';
import '../error_snackbar.dart';
Expand Down Expand Up @@ -42,13 +43,15 @@ class SongListTile extends StatefulWidget {
this.index,
this.parentId,
this.isSong = false,
this.showArtists = true,
}) : super(key: key);

final BaseItemDto item;
final List<BaseItemDto>? children;
final int? index;
final bool isSong;
final String? parentId;
final bool showArtists;

@override
State<SongListTile> createState() => _SongListTileState();
Expand Down Expand Up @@ -100,16 +103,45 @@ class _SongListTileState extends State<SongListTile> {
);
},
),
subtitle: Text(widget.isSong
? processArtist(
mutableItem.artists?.join(", ") ?? mutableItem.albumArtist)
: printDuration(
Duration(
subtitle: RichText(
text: TextSpan(
children: [
WidgetSpan(
child: Transform.translate(
offset: const Offset(-3, 0),
child: DownloadedIndicator(
item: mutableItem,
size: Theme.of(context).textTheme.bodyText2!.fontSize! + 3,
),
),
alignment: PlaceholderAlignment.top,
),
TextSpan(
text: printDuration(Duration(
microseconds: (mutableItem.runTimeTicks == null
? 0
: mutableItem.runTimeTicks! ~/ 10)),
)),
trailing: DownloadedIndicator(item: mutableItem),
: mutableItem.runTimeTicks! ~/ 10))),
style: TextStyle(
color: Theme.of(context)
.textTheme
.bodyText2
?.color
?.withOpacity(0.7)),
),
if (widget.showArtists)
TextSpan(
text:
" · ${processArtist(mutableItem.artists?.join(", ") ?? mutableItem.albumArtist)}",
style: TextStyle(color: Theme.of(context).disabledColor),
)
],
),
overflow: TextOverflow.ellipsis,
),
trailing: FavoriteButton(
item: mutableItem,
onlyIfFav: true,
),
onTap: () {
_audioServiceHelper.replaceQueueWithItem(
itemList: widget.children ?? [mutableItem],
Expand Down Expand Up @@ -193,14 +225,14 @@ class _SongListTileState extends State<SongListTile> {
? const PopupMenuItem<SongListTileMenuItems>(
value: SongListTileMenuItems.removeFavourite,
child: ListTile(
leading: Icon(Icons.star_border),
leading: Icon(Icons.favorite_border),
title: Text("Remove Favourite"),
),
)
: const PopupMenuItem<SongListTileMenuItems>(
value: SongListTileMenuItems.addFavourite,
child: ListTile(
leading: Icon(Icons.star),
leading: Icon(Icons.favorite),
title: Text("Add Favourite"),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';

import '../../models/finamp_models.dart';
import '../../services/finamp_settings_helper.dart';

class HideSongArtistsIfSameAsAlbumArtistsSelector extends StatelessWidget {
const HideSongArtistsIfSameAsAlbumArtistsSelector({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return ValueListenableBuilder<Box<FinampSettings>>(
valueListenable: FinampSettingsHelper.finampSettingsListener,
builder: (_, box, __) {
return SwitchListTile(
title: const Text("Hide Song Artists if same as Album Artists"),
subtitle: const Text(
"Whether or not to hide song artists on album screen if they don't differ from album artists."),
value: FinampSettingsHelper.finampSettings.hideSongArtistsIfSameAsAlbumArtists,
onChanged: (value) =>
FinampSettingsHelper.setHideSongArtistsIfSameAsAlbumArtists(value),
);
},
);
}
}
4 changes: 2 additions & 2 deletions lib/components/MusicScreen/album_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ class _AlbumItemState extends State<AlbumItem> {
? const PopupMenuItem<_AlbumListTileMenuItems>(
value: _AlbumListTileMenuItems.removeFavourite,
child: ListTile(
leading: Icon(Icons.star_border),
leading: Icon(Icons.favorite_border),
title: Text("Remove Favourite"),
),
)
: const PopupMenuItem<_AlbumListTileMenuItems>(
value: _AlbumListTileMenuItems.addFavourite,
child: ListTile(
leading: Icon(Icons.star),
leading: Icon(Icons.favorite),
title: Text("Add Favourite"),
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/components/MusicScreen/artist_item_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ class _ArtistListTileState extends State<ArtistListTile> {
? const PopupMenuItem<ArtistListTileMenuItems>(
value: ArtistListTileMenuItems.removeFromFavourite,
child: ListTile(
leading: Icon(Icons.star_border),
leading: Icon(Icons.favorite_border),
title: Text("Remove Favourite"),
),
)
: const PopupMenuItem<ArtistListTileMenuItems>(
value: ArtistListTileMenuItems.addToFavourite,
child: ListTile(
leading: Icon(Icons.star),
leading: Icon(Icons.favorite),
title: Text("Add Favourite"),
),
),
Expand Down
76 changes: 0 additions & 76 deletions lib/components/PlayerScreen/favourite_button.dart

This file was deleted.

0 comments on commit 6c372eb

Please sign in to comment.