Zuletzt zeigt zuletzt Gehörtes statt neu Hinzugefügtes; Herz sitzt jetzt neben dem Songnamen

- MeloDb.watchRecentlyPlayed(): wertet PlaybackHistory statt dateAddedMs aus,
  ein mehrfach gehörter Song erscheint nur einmal, an der Position seines
  jüngsten Abspielens (Subquery mit GROUP BY songId / MAX(playedAtMs)).
- "Zuletzt" (Karte + RecentlyPlayedScreen, vormals RecentlyAddedScreen) in
  my_music_screen.dart nutzt jetzt watchRecentlyPlayed() statt watchRecent().
- Herz im Vollbild-Player: aus der AppBar-actions-Row entfernt, sitzt jetzt
  direkt neben dem Songtitel in _Angaben (now_playing_screen.dart).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012A2pmbnVNPiHdyf2GW8eLP
This commit is contained in:
Hermes (Server)
2026-08-29 11:24:42 +02:00
co-authored by Claude Sonnet 5
parent 90b63c467e
commit 2cabe36a6c
6 changed files with 345 additions and 32 deletions
+29
View File
@@ -212,6 +212,35 @@ class MeloDb extends _$MeloDb {
.watch();
}
/// Überwacht die zuletzt GEHÖRTEN Songs (nicht getombstonte), aus
/// [PlaybackHistory]. Ein mehrfach gespielter Song erscheint nur einmal —
/// an der Position seines jüngsten Abspielens. Dafür wird pro [songId]
/// zuerst der jüngste `playedAtMs`-Eintrag ermittelt (Subquery mit
/// `GROUP BY`), und darüber zurück auf [songs] verknüpft.
Stream<List<Song>> watchRecentlyPlayed({int limit = 50}) {
final letzterPlay = playbackHistory.playedAtMs.max();
final letztePlaysProSong = selectOnly(playbackHistory)
..addColumns([playbackHistory.songId, letzterPlay])
..groupBy([playbackHistory.songId]);
final subquery = Subquery(letztePlaysProSong, 'letzte_plays');
final letzterPlayRef = subquery.ref(letzterPlay);
final query = select(songs).join([
innerJoin(
subquery,
subquery.ref(playbackHistory.songId).equalsExp(songs.id),
useColumns: false,
),
])
..where(songs.deleted.equals(false))
..orderBy([
OrderingTerm(expression: letzterPlayRef, mode: OrderingMode.desc)
])
..limit(limit);
return query.watch().map((rows) => rows.map((r) => r.readTable(songs)).toList());
}
/// Alle Songs inkl. getombstonte. Intern für ID-Stabilität beim Scan.
Future<List<Song>> allSongs() => select(songs).get();
+9 -9
View File
@@ -234,17 +234,17 @@ class _QuickAccessRow extends StatelessWidget {
),
if (sektionen.contains(AppSettings.sektionZuletzt))
StreamBuilder<List<Song>>(
stream: db.watchRecent(limit: 50),
stream: db.watchRecentlyPlayed(limit: 50),
builder: (context, snapshot) {
final recent = snapshot.data ?? const <Song>[];
return _QuickCard(
icon: Icons.schedule,
label: 'Zuletzt',
subtitle: 'Neu hinzugefügt',
subtitle: 'Zuletzt gehört',
coverPath: recent.isEmpty ? null : recent.first.coverPath,
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => const RecentlyAddedScreen()),
builder: (_) => const RecentlyPlayedScreen()),
),
);
},
@@ -363,22 +363,22 @@ class _Empty extends StatelessWidget {
}
}
/// Vollbild-Liste der zuletzt hinzugefügten Songs (Schnellzugriff "Zuletzt").
class RecentlyAddedScreen extends StatelessWidget {
const RecentlyAddedScreen({super.key});
/// Vollbild-Liste der zuletzt gehörten Songs (Schnellzugriff "Zuletzt").
class RecentlyPlayedScreen extends StatelessWidget {
const RecentlyPlayedScreen({super.key});
@override
Widget build(BuildContext context) {
final db = context.read<MeloDb>();
return Scaffold(
appBar: AppBar(title: const Text('Zuletzt hinzugefügt')),
appBar: AppBar(title: const Text('Zuletzt gehört')),
body: StreamBuilder<List<Song>>(
stream: db.watchRecent(limit: 100),
stream: db.watchRecentlyPlayed(limit: 100),
builder: (context, snapshot) {
final songs = snapshot.data ?? const <Song>[];
if (songs.isEmpty) {
return const Center(
child: Text('Noch nichts hinzugefügt',
child: Text('Noch nichts abgespielt',
style: TextStyle(color: MeloTheme.text2)),
);
}
+25 -23
View File
@@ -49,23 +49,14 @@ class NowPlayingScreen extends StatelessWidget {
// mit der fragte die App den Server nach einem Titel namens
// "https://…" und bekam nie einen Text.
final songId = songIdOf(item) ?? navidromeIdOf(item) ?? '';
return Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
tooltip: songId.isEmpty
? 'Kein Songtext für diesen Titel verfügbar'
: 'Songtext',
icon: const Icon(Icons.lyrics),
onPressed: songId.isEmpty
? null
: () => _showLyrics(context, songId),
),
// Ein Titel der Bibliothek wird lokal favorisiert, einer
// vom Server am Server — beide bekommen dasselbe Herz,
// statt dass eines davon ausgegraut bleibt.
_Herz(item: item),
],
return IconButton(
tooltip: songId.isEmpty
? 'Kein Songtext für diesen Titel verfügbar'
: 'Songtext',
icon: const Icon(Icons.lyrics),
onPressed: songId.isEmpty
? null
: () => _showLyrics(context, songId),
);
},
),
@@ -240,12 +231,23 @@ class _Angaben extends StatelessWidget {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
item.title,
style: Theme.of(context).textTheme.headlineSmall,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Text(
item.title,
style: Theme.of(context).textTheme.headlineSmall,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
),
// Ein Titel der Bibliothek wird lokal favorisiert, einer
// vom Server am Server — beide bekommen dasselbe Herz,
// statt dass eines davon ausgegraut bleibt.
_Herz(item: item),
],
),
const SizedBox(height: MeloSpace.sm),
Text(