CRIT: - Tag-Leiste: Toggle-Kopf 'Tags & Filter' eingebaut (war unerreichbar) + TagStats - Profil: Cloud-Count vor Dialog aufloesen (kein 'Instance of Future' mehr) HIGH: - CloudEinstellungen: toten Sync-Timer entfernt (echter Timer im ViewModel) - StatistikCard + RecentWidget jetzt eingebaut (gesamtMB/gesamtMin endlich genutzt) - CloudService als Singleton (konsistenter Token-Zustand in allen Services) MED/LOW: - Playlist-Erkennung nur noch via list= Parameter - Player: fehlende Quelle wird geloggt statt still - song_tile: null-ID-Guard vor Tag-Dialog - Scanner-Log mit Exception-Objekt - FavoritenService: anzahlFavoriten() fuer StatistikCard
62 lines
2.0 KiB
Dart
62 lines
2.0 KiB
Dart
import '../database/db_helper.dart';
|
|
import '../models/song.dart';
|
|
|
|
class FavoritenService {
|
|
static final FavoritenService _instanz = FavoritenService._();
|
|
factory FavoritenService() => _instanz;
|
|
FavoritenService._();
|
|
|
|
final DbHelper _db = DbHelper();
|
|
int? _favoritenPlaylistId;
|
|
|
|
int? get favoritenId => _favoritenPlaylistId;
|
|
|
|
Future<void> init() async {
|
|
final playlists = await _db.allePlaylists();
|
|
final vorhanden = playlists.where((p) => p['name'] == '⭐ Favoriten').toList();
|
|
if (vorhanden.isNotEmpty) {
|
|
_favoritenPlaylistId = vorhanden.first['id'] as int;
|
|
} else {
|
|
_favoritenPlaylistId = await _db.playlistErstellen('⭐ Favoriten');
|
|
}
|
|
}
|
|
|
|
Future<bool> istFavorit(int songId) async {
|
|
if (_favoritenPlaylistId == null) return false;
|
|
final songs = await _db.songsDerPlaylist(_favoritenPlaylistId!);
|
|
return songs.any((s) => s.id == songId);
|
|
}
|
|
|
|
Future<void> umschalten(int songId) async {
|
|
if (_favoritenPlaylistId == null) return;
|
|
if (await istFavorit(songId)) {
|
|
await _db.songAusPlaylistEntfernen(_favoritenPlaylistId!, songId);
|
|
} else {
|
|
final songs = await _db.songsDerPlaylist(_favoritenPlaylistId!);
|
|
await _db.songZurPlaylist(_favoritenPlaylistId!, songId, songs.length);
|
|
}
|
|
}
|
|
|
|
Future<List<Song>> alleFavoriten() async {
|
|
if (_favoritenPlaylistId == null) return [];
|
|
return _db.songsDerPlaylist(_favoritenPlaylistId!);
|
|
}
|
|
|
|
Future<int> anzahlFavoriten() async {
|
|
if (_favoritenPlaylistId == null) await init();
|
|
if (_favoritenPlaylistId == null) return 0;
|
|
final songs = await _db.songsDerPlaylist(_favoritenPlaylistId!);
|
|
return songs.length;
|
|
}
|
|
|
|
Future<Set<int>> favoritenIds() async {
|
|
if (_favoritenPlaylistId == null) return {};
|
|
final d = await _db.db;
|
|
final rows = await d.rawQuery(
|
|
'SELECT song_id FROM playlist_songs WHERE playlist_id = ?',
|
|
[_favoritenPlaylistId],
|
|
);
|
|
return rows.map((r) => r['song_id'] as int).toSet();
|
|
}
|
|
}
|