feat(playlists): Playlist-Detailansicht mit Drag&Drop-Umsortieren
PlaylistDetailScreen zeigt die Songs einer Playlist (watchPlaylistSongs), erlaubt Entfernen einzelner Songs und Umsortieren per Drag & Drop (ReorderableListView.builder). Tippen auf einen Song spielt die Playlist ab dieser Stelle. Leer-Zustand mit Hinweistext. Da bestehende position-Werte nach Einfügereihenfolge lückenhaft sein können, schreibt das Umsortieren nicht nur den verschobenen Song um, sondern vergibt für die gesamte Playlist neue lückenlose Positionen (0..N-1): MeloDb.reorderAllPlaylistSongs (in einer Transaktion) + PlaylistService.reorderAll als dünner Wrapper. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
4b5d77c196
commit
96d9f38a64
@@ -232,6 +232,20 @@ class MeloDb extends _$MeloDb {
|
||||
.write(PlaylistSongsCompanion(position: Value(newPosition)));
|
||||
}
|
||||
|
||||
/// Schreibt für die gesamte Playlist neue, lückenlose Positionen (0..N-1)
|
||||
/// gemäß [orderedSongIds] — vermeidet Mehrdeutigkeiten beim Umsortieren,
|
||||
/// da einzelne [reorderPlaylistSong]-Aufrufe nur einen Song verschieben.
|
||||
Future<void> reorderAllPlaylistSongs(String playlistId, List<String> orderedSongIds) async {
|
||||
await transaction(() async {
|
||||
for (var i = 0; i < orderedSongIds.length; i++) {
|
||||
await (update(playlistSongs)
|
||||
..where((ps) =>
|
||||
ps.playlistId.equals(playlistId) & ps.songId.equals(orderedSongIds[i])))
|
||||
.write(PlaylistSongsCompanion(position: Value(i)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// === Favorites ===
|
||||
Future<void> toggleFavorite(String songId) async {
|
||||
final existing = await (select(favorites)..where((f) => f.songId.equals(songId))).getSingleOrNull();
|
||||
|
||||
@@ -34,6 +34,11 @@ class PlaylistService extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> reorderAll(String playlistId, List<String> orderedSongIds) async {
|
||||
await db.reorderAllPlaylistSongs(playlistId, orderedSongIds);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> toggleFavorite(String songId) async {
|
||||
await db.toggleFavorite(songId);
|
||||
notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user