Fix: Review-Findings korrigiert (Tag-Leiste, Profil, Singleton u.a.)

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
This commit is contained in:
Hermes (Server)
2026-07-31 15:42:54 +02:00
parent b3aedc53f9
commit 8b6a04ead8
18 changed files with 767 additions and 503 deletions
+5 -25
View File
@@ -1,4 +1,3 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../services/cloud_service.dart';
@@ -16,7 +15,6 @@ class CloudEinstellungen extends StatefulWidget {
class _CloudEinstellungenState extends State<CloudEinstellungen> {
bool _autoSync = true;
int _syncIntervall = 6; // Stunden
Timer? _syncTimer;
@override
void initState() {
@@ -24,12 +22,6 @@ class _CloudEinstellungenState extends State<CloudEinstellungen> {
_ladeSettings();
}
@override
void dispose() {
_syncTimer?.cancel();
super.dispose();
}
Future<void> _ladeSettings() async {
final p = await SharedPreferences.getInstance();
if (mounted) {
@@ -39,19 +31,9 @@ class _CloudEinstellungenState extends State<CloudEinstellungen> {
});
}
}
void _starteAutoSync() {
_syncTimer?.cancel();
if (!_autoSync || _syncIntervall == 0) return;
_syncTimer = Timer.periodic(
Duration(hours: _syncIntervall),
(_) => _triggerSync(),
);
}
void _triggerSync() {
// Wird vom CloudService in cloud_screen.dart erledigt
}
// Hinweis: Der echte Auto-Sync-Timer läuft im MeloHomeViewModel
// (_starteCloudSyncScheduler). Dieser Dialog speichert nur die Einstellungen;
// die Änderungen greifen beim nächsten App-Start bzw. über "Jetzt synchronisieren".
@override
Widget build(BuildContext context) {
@@ -76,8 +58,7 @@ class _CloudEinstellungenState extends State<CloudEinstellungen> {
onChanged: (v) async {
setState(() => _autoSync = v);
final p = await SharedPreferences.getInstance();
p.setBool('cloud_auto', v);
_starteAutoSync();
await p.setBool('cloud_auto', v);
},
),
const Divider(color: MeloTheme.dunkel2),
@@ -95,8 +76,7 @@ class _CloudEinstellungenState extends State<CloudEinstellungen> {
if (v == null) return;
setState(() => _syncIntervall = v);
final p = await SharedPreferences.getInstance();
p.setInt('cloud_interval', v);
_starteAutoSync();
await p.setInt('cloud_interval', v);
},
);
}),
+6 -1
View File
@@ -5,8 +5,9 @@ class MeloHeader extends StatelessWidget {
final VoidCallback onDownload;
final VoidCallback onSearch;
final VoidCallback? onServer;
final VoidCallback? onSettings;
const MeloHeader({super.key, required this.onDownload, required this.onSearch, this.onServer});
const MeloHeader({super.key, required this.onDownload, required this.onSearch, this.onServer, this.onSettings});
@override
Widget build(BuildContext context) {
@@ -39,6 +40,10 @@ class MeloHeader extends StatelessWidget {
_btn(Icons.download, onDownload),
const SizedBox(width: 8),
_btn(Icons.search, onSearch),
if (onSettings != null) ...[
const SizedBox(width: 8),
_btn(Icons.settings, onSettings!),
],
]),
],
),
+13 -2
View File
@@ -1,7 +1,9 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
import '../services/player_service.dart';
import '../models/song.dart';
import '../utils/farb_theme.dart';
class MiniPlayer extends StatefulWidget {
@@ -18,6 +20,7 @@ class _MiniPlayerState extends State<MiniPlayer> {
bool _spielt = false;
StreamSubscription<Duration>? _posSub;
StreamSubscription<PlayerState>? _stateSub;
StreamSubscription<Song?>? _songSub;
@override
void initState() {
@@ -36,12 +39,17 @@ class _MiniPlayerState extends State<MiniPlayer> {
});
}
});
// Sofortige UI-Aktualisierung bei jedem Songwechsel
_songSub = _player.onSongWechsel.listen((_) {
if (mounted) setState(() {});
});
}
@override
void dispose() {
_posSub?.cancel();
_stateSub?.cancel();
_songSub?.cancel();
super.dispose();
}
@@ -52,6 +60,7 @@ class _MiniPlayerState extends State<MiniPlayer> {
final progress = _dauer.inSeconds > 0
? _position.inSeconds / _dauer.inSeconds : 0.0;
final hatCover = song.coverPfad != null && File(song.coverPfad!).existsSync();
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16),
@@ -67,13 +76,15 @@ class _MiniPlayerState extends State<MiniPlayer> {
padding: const EdgeInsets.fromLTRB(12, 10, 12, 6),
child: Row(
children: [
// Cover
// Cover mit Fallback auf Notensymbol
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
width: 36, height: 36,
color: MeloTheme.rot,
child: const Center(child: Text('', style: TextStyle(fontSize: 16))),
child: hatCover
? Image.file(File(song.coverPfad!), fit: BoxFit.cover)
: const Center(child: Text('', style: TextStyle(fontSize: 16))),
),
),
const SizedBox(width: 10),
+4 -1
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import '../services/navidrome_service.dart';
import '../utils/farb_theme.dart';
import '../viewmodels/melo_home_viewmodel.dart';
import '../config/app_config.dart';
/// Navidrome-Browser als Bottom-Sheet.
/// Manuell in home_screen.dart einbaubar.
@@ -216,7 +217,7 @@ class _NavidromeBrowserState extends State<NavidromeBrowser> {
}
void _zeigeLoginDialog(BuildContext context) {
final urlCtrl = TextEditingController();
final urlCtrl = TextEditingController(text: AppConfig.navidromeUrl);
final userCtrl = TextEditingController();
final passCtrl = TextEditingController();
bool verbindet = false;
@@ -258,6 +259,8 @@ class _NavidromeBrowserState extends State<NavidromeBrowser> {
final ok = await widget.vm.ladeNavidromeAlben();
verbindet = false;
if (ok && ctx.mounted) {
// Zugangsdaten speichern
await widget.vm.navidrome.speichereZugangsdaten(urlCtrl.text, userCtrl.text, passCtrl.text);
Navigator.pop(ctx);
if (context.mounted) setState(() {});
} else if (ctx.mounted) {
+44 -14
View File
@@ -118,7 +118,7 @@ class _PlaylistSheetState extends State<PlaylistSheet> {
isScrollControlled: true,
builder: (_) => SizedBox(
height: MediaQuery.of(context).size.height * 0.6,
child: _PlaylistDetail(p: p, songs: songs, vm: widget.vm, onChanged: _laden),
child: _PlaylistDetail(p: p, initialSongs: songs, vm: widget.vm, onChanged: _laden),
),
);
}
@@ -172,19 +172,32 @@ class _PlaylistSheetState extends State<PlaylistSheet> {
}
/// Detailansicht einer Playlist mit Songs
class _PlaylistDetail extends StatelessWidget {
class _PlaylistDetail extends StatefulWidget {
final Playlist p;
final List<Song> songs;
final List<Song> initialSongs;
final MeloHomeViewModel vm;
final VoidCallback onChanged;
const _PlaylistDetail({
required this.p,
required this.songs,
required this.initialSongs,
required this.vm,
required this.onChanged,
});
@override
State<_PlaylistDetail> createState() => _PlaylistDetailState();
}
class _PlaylistDetailState extends State<_PlaylistDetail> {
late List<Song> _songs;
@override
void initState() {
super.initState();
_songs = List<Song>.from(widget.initialSongs);
}
@override
Widget build(BuildContext context) {
return Padding(
@@ -209,18 +222,29 @@ class _PlaylistDetail extends StatelessWidget {
child: const Icon(Icons.arrow_back, size: 20, color: MeloTheme.rot),
),
const SizedBox(width: 8),
Text(p.name, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Colors.white)),
Text(widget.p.name, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Colors.white)),
const Spacer(),
Text('${songs.length} Songs', style: const TextStyle(fontSize: 12, color: MeloTheme.textSekundaer)),
Text('${_songs.length} Songs', style: const TextStyle(fontSize: 12, color: MeloTheme.textSekundaer)),
],
),
const SizedBox(height: 12),
Expanded(
child: songs.isEmpty
child: _songs.isEmpty
? const Center(child: Text('Playlist ist leer', style: TextStyle(fontSize: 12, color: MeloTheme.textSekundaer)))
: ListView.builder(
itemCount: songs.length,
itemBuilder: (_, i) => _songTile(context, songs[i]),
: ReorderableListView.builder(
itemCount: _songs.length,
onReorder: (oldIndex, newIndex) async {
if (newIndex > oldIndex) newIndex--;
setState(() {
final moved = _songs.removeAt(oldIndex);
_songs.insert(newIndex, moved);
});
if (widget.p.id != null) {
await widget.vm.playlists.reihenfolgeSpeichern(widget.p.id!, _songs);
}
widget.onChanged();
},
itemBuilder: (_, i) => _songTile(context, _songs[i]),
),
),
],
@@ -230,6 +254,7 @@ class _PlaylistDetail extends StatelessWidget {
Widget _songTile(BuildContext context, Song song) {
return Container(
key: ValueKey(song.id ?? song.dateiPfad),
margin: const EdgeInsets.only(bottom: 4),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
@@ -249,7 +274,10 @@ class _PlaylistDetail extends StatelessWidget {
const SizedBox(width: 8),
Expanded(
child: GestureDetector(
onTap: () { Navigator.pop(context); vm.spieleSong(song); },
onTap: () {
Navigator.pop(context);
widget.vm.spieleSong(song, warteschlange: _songs);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -261,9 +289,11 @@ class _PlaylistDetail extends StatelessWidget {
),
GestureDetector(
onTap: () async {
await vm.playlists.songEntfernen(p.id!, song.id!);
onChanged();
if (context.mounted) Navigator.pop(context);
await widget.vm.playlists.songEntfernen(widget.p.id!, song.id!);
setState(() {
_songs.removeWhere((s) => s.id == song.id);
});
widget.onChanged();
},
child: const Icon(Icons.remove_circle_outline, size: 18, color: MeloTheme.textSekundaer),
),
+68 -6
View File
@@ -1,7 +1,9 @@
import 'dart:io';
import 'package:flutter/material.dart';
import '../models/song.dart';
import '../utils/farb_theme.dart';
import 'metadaten_dialog.dart';
import 'tag_auswahl_dialog.dart';
class SongTile extends StatelessWidget {
final Song song;
@@ -10,6 +12,7 @@ class SongTile extends StatelessWidget {
final ValueChanged<Song> onPlay;
final VoidCallback onMetadataChanged;
final ValueChanged<Song>? onAddToPlaylist;
final ValueChanged<Song>? onDelete;
const SongTile({
super.key,
@@ -19,20 +22,26 @@ class SongTile extends StatelessWidget {
required this.onPlay,
required this.onMetadataChanged,
this.onAddToPlaylist,
this.onDelete,
});
@override
Widget build(BuildContext context) {
final hatDatei = song.dateiPfad.isNotEmpty;
final hatCover = song.coverPfad != null && File(song.coverPfad!).existsSync();
return ListTile(
contentPadding: const EdgeInsets.symmetric(vertical: 2),
leading: Container(
width: 44, height: 44,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: const LinearGradient(colors: [Color(0xFF1A0000), Color(0xFF660000)]),
leading: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
width: 44, height: 44,
decoration: const BoxDecoration(
gradient: LinearGradient(colors: [Color(0xFF1A0000), Color(0xFF660000)]),
),
child: hatCover
? Image.file(File(song.coverPfad!), fit: BoxFit.cover)
: const Center(child: Text('', style: TextStyle(fontSize: 18, color: Colors.white54))),
),
child: const Center(child: Text('', style: TextStyle(fontSize: 18, color: Colors.white54))),
),
title: Text(song.titel, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white)),
subtitle: Text(song.kuenstler, style: const TextStyle(fontSize: 12, color: MeloTheme.textSekundaer)),
@@ -53,6 +62,26 @@ class SongTile extends StatelessWidget {
child: Icon(Icons.edit, size: 14, color: MeloTheme.textSekundaer),
),
),
InkWell(
borderRadius: BorderRadius.circular(50),
onTap: () {
// Guard gegen null-ID (defensive)
final id = song.id;
if (id == null) return;
showDialog(
context: context,
builder: (_) => TagAuswahlDialog(
songId: id,
songTitel: song.titel,
onChanged: onMetadataChanged,
),
);
},
child: Padding(
padding: const EdgeInsets.all(6),
child: const Icon(Icons.label_outline, size: 14, color: MeloTheme.textSekundaer),
),
),
if (onAddToPlaylist != null)
InkWell(
borderRadius: BorderRadius.circular(50),
@@ -77,6 +106,39 @@ class SongTile extends StatelessWidget {
],
),
onTap: hatDatei ? () => onPlay(song) : null,
onLongPress: onDelete != null ? () {
showModalBottomSheet(
context: context,
backgroundColor: MeloTheme.dunkel1,
builder: (ctx) => SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.edit, color: Colors.white),
title: const Text('Bearbeiten', style: TextStyle(color: Colors.white)),
onTap: () async {
Navigator.pop(ctx);
final geaendert = await showDialog<bool>(
context: context,
builder: (_) => MetadatenDialog(song: song),
);
if (geaendert == true) onMetadataChanged();
},
),
ListTile(
leading: const Icon(Icons.delete, color: Colors.red),
title: const Text('Löschen', style: TextStyle(color: Colors.red)),
onTap: () {
Navigator.pop(ctx);
onDelete!(song);
},
),
],
),
),
);
} : null,
);
}
}
+93
View File
@@ -0,0 +1,93 @@
import 'package:flutter/material.dart';
import '../database/db_helper.dart';
import '../models/tag.dart';
import '../utils/farb_theme.dart';
import '../services/melo_logger.dart';
/// Dialog: Tags für einen Song zuweisen/entfernen
class TagAuswahlDialog extends StatefulWidget {
final int songId;
final String songTitel;
final VoidCallback onChanged;
const TagAuswahlDialog({
super.key,
required this.songId,
required this.songTitel,
required this.onChanged,
});
@override
State<TagAuswahlDialog> createState() => _TagAuswahlDialogState();
}
class _TagAuswahlDialogState extends State<TagAuswahlDialog> {
final _db = DbHelper();
List<Tag> _alleTags = [];
Set<int> _zugewiesenIds = {};
@override
void initState() {
super.initState();
_laden();
}
Future<void> _laden() async {
final alle = await _db.alleTags();
final zugewiesen = await _db.tagsFuerSong(widget.songId);
if (mounted) {
setState(() {
_alleTags = alle;
_zugewiesenIds = zugewiesen.map((t) => t.id!).toSet();
});
}
}
Future<void> _toggle(int tagId) async {
if (_zugewiesenIds.contains(tagId)) {
await _db.songTagEntfernen(widget.songId, tagId);
_zugewiesenIds.remove(tagId);
} else {
await _db.songTagHinzufuegen(widget.songId, tagId);
_zugewiesenIds.add(tagId);
}
widget.onChanged();
if (mounted) setState(() {});
}
@override
Widget build(BuildContext context) {
return AlertDialog(
backgroundColor: MeloTheme.dunkel1,
title: Text(
'🏷 Tags für "${widget.songTitel}"',
style: const TextStyle(color: Colors.white, fontSize: 15),
maxLines: 2, overflow: TextOverflow.ellipsis,
),
content: SizedBox(
width: double.maxFinite,
child: _alleTags.isEmpty
? const Center(child: CircularProgressIndicator(color: MeloTheme.rot))
: ListView.builder(
shrinkWrap: true,
itemCount: _alleTags.length,
itemBuilder: (_, i) {
final tag = _alleTags[i];
final aktiv = _zugewiesenIds.contains(tag.id);
return CheckboxListTile(
value: aktiv,
activeColor: MeloTheme.rot,
title: Text(
'${tag.icon ?? ''} ${tag.name}',
style: const TextStyle(color: Colors.white, fontSize: 14),
),
onChanged: (_) => _toggle(tag.id!),
controlAffinity: ListTileControlAffinity.leading,
contentPadding: EdgeInsets.zero,
);
},
),
),
);
}
}