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>
47 lines
1.5 KiB
Dart
47 lines
1.5 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'database.dart';
|
|
|
|
/// Koordiniert Playlisten- und Favoriten-Operationen; benachrichtigt Listener
|
|
/// nach jeder Mutation (für Feedback wie SnackBars — die Listen selbst
|
|
/// beobachten UIs direkt über die watch()-Streams von [MeloDb]).
|
|
class PlaylistService extends ChangeNotifier {
|
|
PlaylistService(this.db);
|
|
final MeloDb db;
|
|
|
|
Future<String> createPlaylist(String name, {String? description}) async {
|
|
final id = await db.createPlaylist(name, description: description);
|
|
notifyListeners();
|
|
return id;
|
|
}
|
|
|
|
Future<void> deletePlaylist(String id) async {
|
|
await db.deletePlaylist(id);
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> addSongToPlaylist(String playlistId, String songId, int position) async {
|
|
await db.addSongToPlaylist(playlistId, songId, position);
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> removeSongFromPlaylist(String playlistId, String songId) async {
|
|
await db.removeSongFromPlaylist(playlistId, songId);
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> reorderSong(String playlistId, String songId, int newPosition) async {
|
|
await db.reorderPlaylistSong(playlistId, songId, newPosition);
|
|
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();
|
|
}
|
|
}
|