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:
co-authored by
Claude Sonnet 5
parent
90b63c467e
commit
2cabe36a6c
@@ -0,0 +1,73 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:melo/library/database.dart';
|
||||
|
||||
Future<void> _insertSong(MeloDb db, String id, {bool deleted = false}) {
|
||||
return db.into(db.songs).insert(SongsCompanion.insert(
|
||||
id: id,
|
||||
path: '/$id.mp3',
|
||||
title: id,
|
||||
dateAddedMs: 0,
|
||||
updatedAtMs: 0,
|
||||
deleted: Value(deleted),
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> _play(MeloDb db, String songId, int playedAtMs) {
|
||||
return db.into(db.playbackHistory).insert(PlaybackHistoryCompanion.insert(
|
||||
songId: songId,
|
||||
positionMs: 0,
|
||||
playedAtMs: playedAtMs,
|
||||
));
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('ein mehrfach gespielter Song erscheint nur einmal, an der Position '
|
||||
'seines jüngsten Abspielens', () async {
|
||||
final db = MeloDb(NativeDatabase.memory());
|
||||
await _insertSong(db, 'a');
|
||||
await _insertSong(db, 'b');
|
||||
await _play(db, 'a', 1000);
|
||||
await _play(db, 'b', 2000);
|
||||
await _play(db, 'a', 3000); // a erneut gespielt, jetzt jüngster Play
|
||||
|
||||
final result = await db.watchRecentlyPlayed().first;
|
||||
|
||||
expect(result.map((s) => s.id).toList(), ['a', 'b']);
|
||||
|
||||
await db.close();
|
||||
});
|
||||
|
||||
test('mehrere Songs erscheinen absteigend nach ihrem letzten Abspielen',
|
||||
() async {
|
||||
final db = MeloDb(NativeDatabase.memory());
|
||||
await _insertSong(db, 'a');
|
||||
await _insertSong(db, 'b');
|
||||
await _insertSong(db, 'c');
|
||||
await _play(db, 'a', 1000);
|
||||
await _play(db, 'b', 3000);
|
||||
await _play(db, 'c', 2000);
|
||||
|
||||
final result = await db.watchRecentlyPlayed().first;
|
||||
|
||||
expect(result.map((s) => s.id).toList(), ['b', 'c', 'a']);
|
||||
|
||||
await db.close();
|
||||
});
|
||||
|
||||
test('ein gelöschter Song mit Wiedergabe-Historie erscheint nicht',
|
||||
() async {
|
||||
final db = MeloDb(NativeDatabase.memory());
|
||||
await _insertSong(db, 'a', deleted: true);
|
||||
await _insertSong(db, 'b');
|
||||
await _play(db, 'a', 2000);
|
||||
await _play(db, 'b', 1000);
|
||||
|
||||
final result = await db.watchRecentlyPlayed().first;
|
||||
|
||||
expect(result.map((s) => s.id).toList(), ['b']);
|
||||
|
||||
await db.close();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user