feat(library): add Artist and Album browsing tabs
- Library screen now has a TabBar (Alle / Künstler / Alben) inside a
DefaultTabController; scan/permission/error banners stay above the
TabBarView so they remain visible regardless of the active sub-tab
- New lib/library/song_grouping.dart: pure, unit-tested functions
groupByArtist/groupByAlbum (null artist/album -> "Unbekannt" /
"Unbekanntes Album", alphabetically sorted) plus albumArtistLabel
("Verschiedene Interpreten" when an album mixes artists)
- New lib/library/artist_list.dart + album_list.dart: StreamBuilder on
MeloDb.watchSongs(), grouped client-side, tapping a row pushes a
SongList screen for that artist/album; album rows show a CoverImage
thumbnail from the first song's coverPath
- Existing "Alle" tab content (recently-added strip, full song list,
empty state) preserved unchanged, moved into _AllSongsTab
Genre browsing is intentionally out of scope: the Songs table has no
genre column and neither scanner extracts genre metadata — needs a
schema migration + scanner work in a future task.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
4477370766
commit
58ceb42769
@@ -0,0 +1,38 @@
|
||||
import 'database.dart';
|
||||
|
||||
const unbekannterKuenstler = 'Unbekannt';
|
||||
const unbekanntesAlbum = 'Unbekanntes Album';
|
||||
|
||||
/// Gruppiert [songs] nach Künstler (fehlender Künstler → [unbekannterKuenstler]),
|
||||
/// alphabetisch nach Künstlername sortiert.
|
||||
Map<String, List<Song>> groupByArtist(List<Song> songs) {
|
||||
return _groupBy(songs, (s) => s.artist, unbekannterKuenstler);
|
||||
}
|
||||
|
||||
/// Gruppiert [songs] nach Album (fehlendes Album → [unbekanntesAlbum]),
|
||||
/// alphabetisch nach Albumname sortiert.
|
||||
Map<String, List<Song>> groupByAlbum(List<Song> songs) {
|
||||
return _groupBy(songs, (s) => s.album, unbekanntesAlbum);
|
||||
}
|
||||
|
||||
/// Künstler-Beschriftung für ein Album: der gemeinsame Künstler, falls alle
|
||||
/// Songs im Album vom selben Künstler stammen, sonst "Verschiedene Interpreten".
|
||||
String albumArtistLabel(List<Song> songs) {
|
||||
final artists = songs.map((s) => s.artist ?? unbekannterKuenstler).toSet();
|
||||
return artists.length == 1 ? artists.first : 'Verschiedene Interpreten';
|
||||
}
|
||||
|
||||
Map<String, List<Song>> _groupBy(
|
||||
List<Song> songs,
|
||||
String? Function(Song) keyOf,
|
||||
String fallback,
|
||||
) {
|
||||
final grouped = <String, List<Song>>{};
|
||||
for (final song in songs) {
|
||||
final key = keyOf(song) ?? fallback;
|
||||
grouped.putIfAbsent(key, () => []).add(song);
|
||||
}
|
||||
final sortedKeys = grouped.keys.toList()
|
||||
..sort((a, b) => a.toLowerCase().compareTo(b.toLowerCase()));
|
||||
return {for (final key in sortedKeys) key: grouped[key]!};
|
||||
}
|
||||
Reference in New Issue
Block a user