Compare commits

...
317 Commits
Author SHA1 Message Date
marcandClaude Opus 5 4cbeca268c docs: Web-Aenderung als 3.4 fuehren, Android-Anpassung bleibt 3.3
Die Seitenleiste ist ein eigener, nur im Web ausgelieferter Stand — getrennt von der
Fold-/Flip-Anpassung, zu der das APK 1.27 gehoert.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-13 23:45:43 +02:00
marcandClaude Opus 5 9afd73ae7f feat(web): Playlists und Favoriten als Liste in der Seitenleiste
Statt zweier Knoepfe, die erst eine Uebersichtsseite oeffnen, steht unter den
Navigationsrubriken der Abschnitt "Deine Musik": angepinnt Favoriten und "Neu von
deinen Kuenstlern", darunter die Playlists mit Cover und Titelzahl.

Links und nicht rechts, weil rechts belegt ist: dort faehrt die Warteschlange als
290-px-Panel ein und am Rand sitzt der Rollbalken aus 3.1.

Der Listenteil rollt eigenstaendig (nav ist jetzt eine Flex-Spalte), auf niedrigen
Fenstern rollt als Rueckfall die ganze Leiste. Dieselbe gecachte Abfrage wie die
Uebersichtsseite; nach Anlegen/Umbenennen/Loeschen wird der Cache verworfen und neu
gezeichnet, ein Coverwechsel tauscht nur die betroffene Zeile (gleiche Adresse pl-<id>,
sonst kaeme dasselbe Bild aus dem Browser-Cache).

Die Kachel-Uebersicht bleibt per "Alle" erreichbar, die untere Leiste auf dem Handy
bleibt unveraendert.

Ausserdem: in 3.2 uebersehene Mischstelle nachgezogen — der Shuffle-Knopf der
Playlist-Seite benutzte weiter sort(() => Math.random()-.5). Mein Suchmuster hatte nur
die Schreibweise mit 0.5 erfasst, nicht die mit .5.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-13 19:40:56 +02:00
marcandClaude Opus 5 7cdcc352d6 fix(android): Handy-Layout im Now-Playing unangetastet lassen
Nachtrag zu 6248329: zwei der Aenderungen hatten doch Wirkung auf gewoehnliche Handys.

1. Senkrechte Zentrierung galt fuer alle Anzeigen und verschob den Block auf einem hohen
   Handy um etwa 60 dp nach unten. Jetzt wird nur zentriert, wenn eine der neuen Grenzen
   wirklich greift (Hoehe oder 400-dp-Deckel); solange die Breite das engste Mass ist,
   bleibt es beim alten Aufbau samt 28 dp Abstand oben.
2. Die Schwelle fuer die kompakte Kopfzeile lag bei 400 dp und erfasste damit jedes
   uebliche Handy. Jetzt 356 dp oder kurze Anzeige — also Fold-Deckel und
   Flip-Frontdisplay, nicht aber ein 360- oder 384-dp-Handy.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-13 19:04:38 +02:00
marcandClaude Opus 5 624832959d fix(android): Now-Playing an Fold und Flip anpassen — Deckel, Hoehenmass, Rollbereich
Die Seite hatte keine Breitengrenze: das Cover war fillMaxWidth() mal aspectRatio(1f).
Aufgeklappt sind das ueber 800 dp, womit Titel, Fortschritt und Knoepfe aus dem Bild
geschoben wurden. Das Cover nimmt jetzt das Kleinste aus Breite, Hoehe abzueglich
Restbedarf und 400 dp; Titelblock/Fortschritt/Knoepfe sind auf 480 dp gedeckelt (wie
.np-inner im Web), Liedtext und Warteschlange auf 560 dp.

Auf kurzen Anzeigen (Flip-Frontdisplay, Querformat, kleine Handys) wurde die Knopfreihe
abgeschnitten. Jetzt schrumpfen dort Abstaende, Reiter und Abspielknopf, und die
Player-Seite laesst sich rollen, wenn es weiterhin nicht reicht: der Inhalt ist
mindestens so hoch wie die Seite, passt er, wird zentriert, passt er nicht, waechst er
darueber hinaus. Die Wischgeste zum Schliessen bleibt, weil ein Rollbereich ohne Weg die
Geste nicht verbraucht.

Entschieden wird nach Maszen, nicht nach Gerätenamen: schmal < 400 dp, kurz < 560 dp.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-13 18:47:03 +02:00
marcandClaude Opus 5 b6e98463ee feat(web+android): Lyrics-Mitlaufen umschaltbar, echtes Mischen, Wiederholung am Queue-Ende
Lyrics: Schalter "Mitlaufen" im Lyrics-Reiter, Vorgabe AUS. Hervorgehoben wird die
laufende Zeile immer, gescrollt nur bei eingeschaltetem Mitlaufen. Nur bei synchronen
Texten sichtbar. Android speichert den Schluessel einzeln, damit das Speichern im
Einstellungsbildschirm ihn nicht auf die Vorgabe zuruecksetzt.

Mischen (Web): sort(() => Math.random() - 0.5) ist keine Mischung. Gemessen blieb der
erste Titel drei- bis fuenfmal zu oft vorn (18,8 % statt 10 % bei n=10, 0,23 % statt
0,05 % bei n=2000). Ersetzt durch Fisher-Yates in queueMath.mischeListe.

Queue-Ende (Web): ein beendetes <audio> meldet sich als pausiert, die Wiederaufnahme
nach unfreiwilligem Hintergrund-Stop rief play() und spielte den letzten Titel erneut.
Jetzt Abbruch bei audio.ended.

Shuffle (Android): das Mischen macht jetzt der Player (playSongs(liste, -1)), damit die
ungemischte Liste erhalten bleibt — vorher leuchtete das Symbol nicht und "Shuffle aus"
konnte die Albumreihenfolge nicht wiederherstellen.

Radio-Modus (beide): der laufende Titel ist aus der letzten Rueckfallebene ausgenommen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-01 17:13:38 +02:00
marcandClaude Opus 5 ae357b0eb9 change: Konzerte ohne Zeitfenster — Chips nur noch bei den Veroeffentlichungen
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-27 10:46:05 +02:00
marcandClaude Opus 5 17a677a5a5 feat(web+android+backend): Konzerte gefolgter Kuenstler als zweiter Reiter
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-25 19:23:00 +02:00
marcandClaude Opus 5 1366ec3832 docs: Entwurf fuer die Konzert-Meldungen im Backlog festhalten
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-25 17:56:17 +02:00
marcandClaude Opus 5 7879e37a7b test(backend): Filterprobe fragt auch YT Music ab — erste Fassung meldete erfundene Fehler
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-25 17:03:14 +02:00
marcandClaude Opus 5 2f87a12f08 fix(backend): Kuenstler vor Dauer in der Suchkaskade, mit Regressionsprobe
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-25 09:48:35 +02:00
marcandClaude Opus 5 748b1446a2 fix(backend): Umschrift-Muster toleranter, Kanji-Kuenstler ueber Romaji erkennbar
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-25 00:09:01 +02:00
marcandClaude Opus 5 06b13caea9 fix(backend): Download-Filter konnte ohne Titel- oder Kuenstlermerkmal zugreifen
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-24 23:31:29 +02:00
marcandClaude Opus 5 1432a960fb style: Honigtopf auf Feldbreite aufgezogen, wirkt jetzt so gross wie das Zahnrad
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-24 23:11:07 +02:00
marcandClaude Opus 5 37f8f8acac feat(web+android): Gesamtdauer mit Stunden, in Android neu
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-24 22:38:40 +02:00
marcandClaude Opus 5 c7fed82736 style(web): Honigtopf in der Kopfzeile groesser
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-24 18:25:22 +02:00
marcandClaude Opus 5 e8582381ec feat(web+android): Honigtopf mit Brief statt Glocke fuer Benachrichtigungen
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-24 16:53:06 +02:00
marcandClaude Opus 5 899c98977a feat: Wischgeste wechselt Titel, Designs Violet und Crimson, Mischen-Anzeige gefixt
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 21:04:37 +02:00
marcandClaude Opus 5 549bec85ce feat(web): Rollbalken nur ueber dem Inhalt, X-Knopf in der Warteschlange
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 20:50:23 +02:00
marcandClaude Opus 5 2258e5465f fix(android): Songzeilen halten rechts Platz fuer den Rollbalken
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 20:47:37 +02:00
marcandClaude Opus 5 2641a6df44 fix(android): Rollbalken verschluckte das Kontextmenue der Songzeilen
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 20:45:20 +02:00
marcandClaude Opus 5 d5b5c8cf84 feat(web+android): Warteschlange bearbeiten — ziehen und entfernen
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 20:31:08 +02:00
marcandClaude Opus 5 77a3bb33f0 fix(android): Rollbalken-Geste brach ab, weil pointerInput auf die Geometrie geschluesselt war
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 20:24:37 +02:00
marcandClaude Opus 5 d420123a44 fix(web): Rollbalken lief ueber die Player-Leiste
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 20:21:37 +02:00
marcandClaude Opus 5 f083fad986 fix(android): Rollbalken liess sich nicht greifen — Greifflaeche und Gestenvorrang
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 20:20:08 +02:00
marcandClaude Opus 5 363eb2b1aa docs: Rollbalken in Android im Changelog (3.1, APK 1.16)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 20:13:37 +02:00
marcandClaude Opus 5 1aa218f3e3 feat(android): Rollbalken zum Ziehen in den langen Listen
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 20:13:10 +02:00
marcandClaude Opus 5 6652fb4d2b feat(web): greifbarer Rollbalken, Zeitleiste in die Favoriten verlegt (3.1)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 19:41:09 +02:00
marcandClaude Opus 5 073593d963 change(backend): nur noch der erste Kuenstler im Dateinamen
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 22:57:04 +02:00
marcandClaude Opus 5 8d25bf0404 feat(web+backend): Dubletten im Editor aufloesen, Favoriten ueberleben das Umbenennen
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 21:41:42 +02:00
marcandClaude Opus 5 24558497da fix(backend): Schraegstrich im Namen und zu lockere Titelsuche fuehrten auf die falsche Datei
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 20:35:36 +02:00
marcandClaude Opus 5 eb72e5c27d feat(android): Album-Knopfleiste wie im Playlist-Detail; Changelog-Backlog aufgeraeumt
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 20:06:30 +02:00
marcandClaude Opus 5 66fcdbba05 docs: Release als Version 3.0 festhalten
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-19 12:39:22 +02:00
marcandClaude Opus 5 86810b6a51 feat(web+android): gefolgte Künstler begrenzt anzeigen, mit "Alle anzeigen"
Vorher landeten alle gefolgten Künstler in der waagerechten Reihe der
Favoriten — bei 200 Gefolgten 200 Karten samt Bildern, von denen man vier
sieht. Am Ende steht jetzt "Alle anzeigen (+n weitere)" und springt in die
Künstlerliste mit aktivem Gefolgt-Filter.

Im Web richtet sich die Anzahl nach der Fensterbreite statt nach einer
festen Zahl (passende Karten minus eine, damit der Knopf nicht
angeschnitten klebt; Untergrenze zwei), und bei Größenänderung wird neu
aufgeteilt. Android zeigt zehn; die LazyRow baut ohnehin nur Sichtbares,
dort ging es allein um Durchsehbarkeit.

LibraryIntent reicht die Absicht einmalig durch, weil das
LibraryViewModel am Navigationseintrag hängt und einen Zielwechsel nicht
überlebt.

Dazu: die Zeitfenster-Chips der Android-Zeitleiste beginnen mit 90 Tagen,
der Vorgabe — Web war schon so.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 18:37:47 +02:00
marcandClaude Opus 5 cb43c3375e feat(android): Gefolgt-Filter im Künstler-Reiter und Zeitleiste "Neu von deinen Künstlern"
Filter statt eigenem Reiter: die Bibliotheksleiste trägt schon Playlists,
Alben, Künstler und Offline. Die markierten IDs kommen bei jedem
Einschalten frisch, damit ein eben entfolgter Künstler nicht dasteht.

Die Zeitleiste ist über "✨ Neu" in den Favoriten erreichbar — dort stehen
die gefolgten Künstler, also liegt die Frage nach Neuem dort nahe.
Gleiche Darstellung wie im Web: nach Monat gruppiert, neueste zuerst,
Vorhandenes mit Haken statt Download-Knopf, Künstlername anklickbar.
Download läuft über den bekannten Weg samt Fortschrittsmeldung.

Neu: api/ReleasesClient.kt, api/model/ReleaseModels.kt,
viewmodel/ArtistNewsViewModel.kt, ui/screen/ArtistNewsScreen.kt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 14:10:37 +02:00
marcandClaude Opus 5 ea7167f851 perf(web): Künstlerbilder ohne einen API-Aufruf pro Künstler
Das Künstlerraster feuerte pro Künstler ein getArtistInfo2 nur für die
Bildadresse: bei 200 Künstlern 200 gleichzeitige Aufrufe, die der Browser
zu sechst abarbeitet, und jeder konnte Navidrome zu einer externen
Last.fm-Abfrage zwingen. Fehlende Bilder kamen aus derselben Quelle —
Last.fm liefert für viele Künstler nur noch einen Platzhalter.

getArtists liefert das Bild längst mit (toArtistID3 setzt coverArt, und
Navidrome löst Künstlerbilder selbst über ArtistArtPriority auf und cacht
sie). Jetzt geht nur noch das Bild über die Leitung; ohne coverArt sparen
wir uns den Versuch ganz. Im Test 0 statt 120 Zusatzaufrufe.

Gleiches für die Künstlerkarten in der lokalen Suche und die gefolgten
Künstler in den Favoriten. Android war nie betroffen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 14:05:11 +02:00
marcandClaude Opus 5 f3d54158d3 feat(web): Filter "❤ Gefolgt" plus Suche auf der Künstlerseite
Die Liste, wem man folgt, gehört dorthin, wo man Künstler ohnehin sucht —
bisher gab es sie nur als waagerechte Reihe unter den Favoriten.
getArtists liefert kein starred mit, die Markierungen kommen deshalb aus
getStarred2 und werden 30 s gehalten, damit das Umschalten flott bleibt.

Ein Herz-Klick verwirft diesen Zwischenspeicher sofort — sonst zeigte der
Filter nach dem Entfolgen noch eine halbe Minute den alten Stand. Beim
Testen aufgefallen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 13:58:09 +02:00
marcandClaude Opus 5 908488a337 feat: Zeitleiste "Neu von deinen Künstlern" (Web) + Backend-Endpunkt
Eigener Punkt in der Seitenleiste: jüngste Veröffentlichungen aller
gefolgten Künstler, nach Monat gruppiert, neueste zuerst, umschaltbar auf
30/90/365 Tage. Was schon in der Bibliothek liegt, ist markiert (Vergleich
über Künstler + Albumname, akzent- und zeichenunabhängig); alles andere
bekommt einen Laden-Knopf zum vertrauten Download-Dialog.

Neuer Endpunkt POST /api/artist-releases (backend/lib/releases.js): die
Deezer-Zuordnung passiert serverseitig, weil die Künstler-Pins dort
ohnehin liegen. Gepinnte nutzen die feste ID, ungepinnte werden über den
Namen gesucht und nach Fan-Zahl sortiert; ohne Treffer kommt der Name als
ohneZuordnung zurück und die Oberfläche rät zum Pinnen.

Cache im Backend statt im Client — bei 30 gefolgten Künstlern wären das
sonst 30 Deezer-Aufrufe pro Gerät und App-Start. 6 h für Alben, 24 h für
die Namenszuordnung, max. 4 Anfragen parallel, bei Deezer-Fehlern wird
der abgelaufene Stand ausgeliefert statt einer leeren Liste.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 13:50:33 +02:00
marcandClaude Opus 5 19f241e493 feat(web+android): Folgen-Herz ins Künstler-Banner, Favoriten zeigen Künstler und Alben
Das Herz sitzt jetzt im Banner neben dem Pin-Zahnrad statt in der
Aktionsleiste: die Leiste ist "was ich jetzt tue" (abspielen, mischen,
Konzerte), Folgen ist ein Zustand und gehört an den Künstler. Auf beiden
Plattformen gleich. Beim Album bleibt das Herz in der Aktionsleiste, dort
gibt es kein Banner.

Dazu die Übersicht, wem man folgt: die Favoritenseite bekommt Abschnitte
Künstler / Alben / Songs. Ohne zusätzlichen Aufruf — getStarred2 liefert
Künstler und Alben im selben Paket wie die Songs, wir haben sie bisher
verworfen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 13:11:18 +02:00
marcandClaude Opus 5 5f043beb5d feat(web+android): Künstlern folgen, Alben merken, Top Songs per Künstler-ID
Folgen ist kein eigener Speicher, sondern Navidromes Stern auf dem
Künstler (star&id=<ndArtistId>) — Navidrome wirft id, albumId und
artistId beim Markieren in eine Liste und behandelt sie gleich, der
vorhandene Aufruf trug also ohne Änderung. Zustand aus `starred` in
getArtist/getAlbum, beide Plattformen schalten optimistisch um.

Android nutzt den vorhandenen StarState, der ohnehin über IDs arbeitet.

Dazu: getTopSongs bekommt seit Navidrome 0.64 zusätzlich `id`. Der
Namensweg sucht mit LIKE und Max:1, bei gleichnamigen Künstlern gewann
der erste Treffer. Jetzt id + artist zusammen; in Erkunden bleibt es beim
Namen, weil die artistId dort Deezers ist.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 17:51:53 +02:00
marcandClaude Opus 5 de674dbe3f fix(android): Offline-Downloads vollständig löschen, Fortschritt selbst begradigen
Löschen ließ Dateien zurück: Cover wurden nie entfernt (nur die
Audiodatei), unfertige Titel behielten ihre Datei, weil der Pfad aus der
Karte der FERTIGEN Titel kam, und laufende Downloadarbeit lief nach dem
Löschen noch minutenlang ins Leere. Jetzt kommt der Pfad aus der
Datenbankzeile, .tmp wird mitgenommen, Cover gehen nur weg wenn kein
anderer Titel sie noch benutzt, und die Arbeit der Gruppe wird
abgebrochen.

Dazu: ein zu hoch gezählter Fortschritt aus der Zeit vor 1.10 konnte sich
nie mehr korrigieren — die Gruppe galt als vollständig, der Knopf war
unantastbar und das Fortsetzen sucht nur Gruppen unter dem Sollwert. Beim
App-Start wird der Fortschritt aller Gruppen einmal aus dem echten
Zustand neu berechnet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 12:00:08 +02:00
marcandClaude Opus 5 ffedc7532b feat(android): Schalter "Nur über WLAN herunterladen" (Standard an)
Die Downloadarbeit lief mit NetworkType.CONNECTED, also über jede
Verbindung. Das war selbstbegrenzend, solange nach zehn Minuten Schluss
war — mit der automatischen Wiederholung aus 1.9 hätte sich eine große
Playlist unterwegs ununterbrochen weitergeladen (1900 Titel ≈ 9-10 GB).

Neuer Schalter unter "Offline-Downloads", standardmäßig an: dann gilt
UNMETERED, der Download pausiert ohne WLAN und läuft von selbst weiter.
Abschalten nur über eine Rückfrage, die das Datenvolumen benennt.

Beim Speichern werden laufende Gruppen mit REPLACE neu eingereiht —
WorkManager ändert die Bedingungen eingereihter Arbeit nicht mehr, der
Schalter hätte sonst erst beim nächsten App-Start gewirkt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 22:34:44 +02:00
marcandClaude Opus 5 e2e7b2490f fix(android): Zählfehler im Downloader — halb geladene Gruppen galten als vollständig
Der Worker startete done bei group.downloadedTracks und zählte dieselben
fertigen Titel beim Überspringen nochmal: 412 fertige wurden zu 824.
Übersteigt der Wert totalTracks, gilt die Gruppe als vollständig, der
Fortschrittsbalken verschwindet und der Herunterladen-Knopf wird
unantastbar, obwohl Titel fehlen.

Der Fehler ist älter, fiel aber kaum auf, solange Fortsetzen nur von Hand
passierte — mit der automatischen Wiederholung aus 1.9 hätte er bei jedem
Lauf zugeschlagen. Zähler beginnt jetzt bei 0.

Dazu: beim Überspringen wurde der unveränderte Fortschritt geschrieben,
1900 überflüssige DB-Writes je Lauf. Jetzt nur nach echtem Versuch und
einmal beim Abbruch.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 20:22:18 +02:00
marcandClaude Opus 5 8bc03da88e fix(android): große Offline-Downloads laufen jetzt bis zum Ende
WorkManager stoppt einen Hintergrund-Worker nach ~10 Minuten (ein
Vordergrunddienst scheidet aus, FOREGROUND_SERVICE_TYPE_DATA_SYNC stürzt
unter Android 15 ab). Der Worker prüfte nie isStopped, lief blind weiter
und meldete Result.failure() ohne Backoff — WorkManager startete nichts
neu, bei 1900 Titeln musste man wiederholt von Hand antippen.

Jetzt: sauberer Ausstieg bei isStopped mit Result.retry() und linearem
Backoff, Selbst-Fortsetzung solange Titel offen sind (max. 20 Versuche,
damit dauerhaft kaputte Titel keine Endlosschleife auslösen), Retry statt
Failure im äußeren catch, und beim App-Start werden unvollständige
Gruppen weitergeführt.

Dazu: die Zahl offener Titel kam aus einer Abfrage pro Titel am Ende
jedes Laufs — jetzt ein einzelnes COUNT mit JOIN.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 23:17:50 +02:00
marcandClaude Opus 5 35e36067af fix(android): große Offline-Playlists ließen sich nicht abspielen
Die Warteschlange wurde aus allen Titeln einer Gruppe gebaut, ohne den
Download-Zustand zu prüfen. Die Map für lokale Dateien kennt aber nur
state = 'DONE' — für wartende oder fehlgeschlagene Titel lieferte
streamUrl() die Netz-Adresse, die offline nichts tut. Bei 100 Titeln ist
der Download durch, bei 1900 nicht; steht so ein Titel vorn, scheitert
die Wiedergabe sofort.

Play und Shuffle nehmen jetzt nur fertige Titel, ein Toast nennt die Zahl
der übersprungenen. Die Liste zeigt weiter alle, damit sichtbar bleibt,
was fehlt; Tippen auf einen unfertigen sagt es ebenfalls.

Nicht die Ursache: Media3 reicht große Listen als BundleListRetriever
durch, die 1-MB-Binder-Grenze greift dort nicht.

Dazu Backlog-Notiz: Künstler/Alben liken als Basis für "Künstler folgen".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 22:50:27 +02:00
marcandClaude Opus 5 cb5ea26c77 fix: Maus-Zurück im PWA-Fenster, sprechende Player-Namen, Pfad-Etikett
Im installierten Fenster ("display": standalone) gibt es keine Zurück-/
Vorwärts-Knöpfe, und die Maus-Seitentasten werden nicht auf den Verlauf
umgelenkt — im Tab ging es, im Fenster nicht. Die App übernimmt X1/X2
jetzt selbst, aber nur im Standalone-Fenster (im Tab würde das doppelt
navigieren; beide Fälle im Test abgedeckt). Zurück läuft über _navGoBack,
schließt also erst ein offenes Now-Playing.

Backend meldet sich jetzt als NovaSonic-Backend, der Scrobble-Dienst als
NovaSonic-Scrobble. Vorher novasonic vs. NovaSonic — in Navidromes
Player-Liste (Name = "client [User-Agent]") zwei Zeilen "[node]", die
sich nur an einem Großbuchstaben unterschieden.

Pfad-Etikett wieder ohne "(Navidrome)": der Wert kommt ohnehin aus der
Subsonic-API, die Erklärung gehört in den Code und nicht ins Fenster.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 14:34:17 +02:00
marcandClaude Opus 5 568bb5002c fix(web): Zurück-Knopf tat oft nichts + Besitzer geteilter Playlists (2.6)
navigate() ließ den Stack-Eintrag weg, wenn sich die Ansicht nicht
geändert hatte, rief history.pushState aber trotzdem. Zweimal auf
denselben Tab geklickt = zwei Browser-Einträge auf dieselbe Ansicht,
jeder davon ein Zurück-Druck ohne sichtbare Wirkung. Im Test: 3x "Alben"
-> 3 Browser-Einträge bei 1 Stack-Eintrag, danach bewegten 4 Zurück-
Drücke die Ansicht einmal. Jetzt pusht nur eine wirklich neue Ansicht,
sonst replaceState. Vorwärts mitgetestet, unverändert.

Playlists: Navidrome liefert owner mit, das Web nutzte es nie. Übersicht
und Detail zeigen "· von <Name>", nur bei fremden Listen. Android zeigte
ihn bisher bei jeder Liste und unbeschriftet; beide Plattformen jetzt
gleich, Bibliotheks-Übersicht ebenfalls.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 14:12:07 +02:00
marcandClaude Opus 5 ea448e109f docs(changelog): Android-Versionen je Release in einer Zeile bündeln
Die APK-Versionen standen als eigene Einträge zwischen den Features und
wiederholten deren Inhalt: "Android 1.6: Warteschlange ist sofort da"
neben "Zuletzt Gehörtes überlebt den Neustart" — die beiden
widersprachen sich sogar (nur Song-Ids vs. volles JSON), weil 1.6 den
Ansatz aus 1.4 abgelöst hatte.

Jede Release-Überschrift trägt jetzt eine "Android:"-Zeile mit Spanne und
je einem Halbsatz; die Einträge darunter beschreiben nur noch die
Änderung. Die Warteschlangen-Einträge sind zu einem zusammengezogen, mit
dem Weg 1.4 -> 1.6 als Unterpunkt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 23:58:46 +02:00
marcandClaude Opus 5 4ee20de359 fix(docs+web): "NN-NN im Dateinamen" war kein Bug — Navidromes fakePath
Der Pfad Rising Insane/DEATHRACE/01-02 - DEATHRACE.mp3 existiert so nicht
auf der Platte. Navidrome gibt über Subsonic standardmäßig nicht den
echten Pfad heraus, sondern baut ihn per fakePath() aus den Tags:
{AlbumArtist}/{Album}/{DD}-{TT} - {Titel}.{ext} — 01 ist die Disc, 02 die
Tracknummer. An der Künstlerstelle steht also kein kaputter Wert, dort
steht gar kein Künstler.

Known-Bug-Eintrag entsprechend widerlegt statt gelöscht, samt Hinweis auf
"Report Real Path" am Player novasonic — das ist die Wurzel der
Datei-Ratearbeit im Backend und damit auch des Fehlers "Metadaten springen
zurück". Das Backend nimmt einen absoluten Pfad bereits ohne Änderung.

Info-Dialog beschriftet das Feld jetzt als "Pfad (Navidrome)".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 23:56:15 +02:00
marcandClaude Opus 5 ac69d259d5 fix(web): Künstler in den Albumansichten sichtbar machen
Der Name stand in --text2 (#8888aa) und 14px unter einem 28px starken
Albumtitel — er ging darin unter, und dass er anklickbar ist, war nicht
erkennbar. Jetzt --text, 15px, halbfett; wo ein Ziel dahintersteht,
zusätzlich dezent unterstrichen (Hover in Akzentfarbe).

Gilt für lokale Albumseite, Deezer-Albumseite und die Inline-Ansicht in
der globalen Suche. Die Teil-Album-Seite bleibt ohne Link, dorthin kommt
man nur von der Künstlerseite.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 13:43:17 +02:00
marcandClaude Opus 5 ec75fdef7b feat(web+android): vom Album in der globalen Suche zum Künstler springen (2.5 / Android 1.8)
Der Künstlername unter einem Deezer-Album war reiner Text — von dort zum
Künstler ging nur über Zurück und neu suchen. Er ist jetzt anklickbar und
öffnet dieselbe Deezer-Künstlerseite wie eine Künstler-Kachel.

Kostet keinen zusätzlichen API-Aufruf: Deezer legt /search/album und
/album/{id} das artist-Objekt samt id bei (120/120 Treffer über zwölf
Suchen geprüft), beide Mappings übernahmen die id längst.

/artist/{id}/albums lässt das artist-Objekt weg — Alben von dort bleiben
bewusst reiner Text, statt ins Leere zu zeigen.

Android zeigte in der Album-Detailansicht bisher gar keinen Künstler und
lädt Bild + Fanzahl nach, wenn der Künstler aus einem Album stammt.

.album-artist-name trug cursor:pointer auch ohne Ziel — jetzt nur noch,
wo wirklich etwas dahintersteht.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 22:22:37 +02:00
marcandClaude Opus 5 fca7cc79c1 feat(android): Cache nach einem Update einmalig leeren (1.7)
Im cacheDir liegen Coils Bildspeicher und heruntergeladene APK-Updates, beides
jederzeit neu beschaffbar. Blieb dort nach einer neuen Version etwas Altes
liegen, war "Cache leeren" von Hand in den Systemeinstellungen die einzige
Abhilfe — nichts, das sich einem normalen Nutzer erklaeren laesst.

Geleert wird jetzt beim ersten Start nach einem Versionswechsel, verglichen wird
der gespeicherte versionCode. Im laufenden Betrieb passiert nichts, sonst waeren
die Cover bei jedem Start neu zu laden. Beim allerersten Start nach der
Installation ebenfalls nicht, da gibt es nichts aufzuraeumen.

Offline-Downloads bleiben unberuehrt: die liegen unter filesDir/offline.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-09 08:42:27 +02:00
marcandClaude Opus 5 651f979401 perf(android): Warteschlange sofort wiederherstellen, SW-Cache automatisch versionieren
Android speicherte nur die Song-Ids und lud beim Start jeden Titel EINZELN und
nacheinander ueber das Netz nach. Das dauerte Sekunden, war unzuverlaessig und
ohne Verbindung unmoeglich. Gespeichert werden jetzt die vollstaendigen Songs als
JSON — Wiederherstellen ist ein lokaler Lesevorgang, wie im Web. Der Preis ist
ein veralteter Titel oder Cover bis zum naechsten Abspielen, was die deutlich
kleinere Unschoenheit ist.

Dazu sichert MusicService.onTaskRemoved die Warteschlange beim Wegwischen der
App: dort feuert onIsPlayingChanged nicht zuverlaessig, genau dieser Fall ging
vorher verloren.

Service Worker: die Cache-Version stand handgepflegt als ns-v78 in sw.js und
wurde beim Ausliefern vergessen — die Aktivierung loescht nur Caches mit
abweichendem Namen, also blieb der alte bestehen und Nutzer mussten den
Browsercache von Hand leeren. Ein Vite-Plugin setzt sie jetzt aus der Bauzeit,
die Quelldatei bleibt unveraendert.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-09 00:01:30 +02:00
marcandClaude Opus 5 0b23a07039 fix(android): Warteschlangen-Wiederherstellung robuster und nachvollziehbar (1.5)
Das Wiederherstellen schlug still fehl. Mehrere runCatching verschluckten jeden
Grund, sodass von aussen nur "passiert nichts" zu sehen war.

Zwei wahrscheinliche Ursachen adressiert:
- connect() laeuft in Application.onCreate(), wo der DataStore mit den
  Navidrome-Zugangsdaten unter Umstaenden noch nicht gelesen ist. Dann scheitert
  das Aufloesen ALLER Song-Ids und die Warteschlange bleibt leer. Es wird jetzt
  bis zu fuenfmal mit wachsendem Abstand versucht.
- Wischt man die App aus den letzten Apps, wurde nichts gesichert:
  onIsPlayingChanged feuert dabei nicht zuverlaessig. MusicService.onTaskRemoved
  sichert jetzt vor dem Beenden.

Dazu Protokollausgaben unter dem Tag NsQueue an jeder Stufe (gesichert,
gefunden, Id nicht aufloesbar, wiederhergestellt, aufgegeben), damit ein
weiterer Fehlschlag per logcat zu klaeren ist statt per Vermutung.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 23:26:17 +02:00
marcandClaude Opus 5 8da67e0975 chore(android): versionCode 7, versionName 1.4
Erste Android-Version mit Warteschlangen-Wiederherstellung und Streitpunkten.
Das zuvor hochgeladene 1.3 enthielt restoreQueue noch nicht — daher blieb die
Now-Playing-Leiste nach dem Oeffnen leer. Release-Beschreibung mit angehoben,
sonst meldet der In-App-Updater kein Update.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 22:44:25 +02:00
marcandClaude Opus 5 e8108b0a7a docs(changelog): Dateinamen-Fehler richtig beschrieben (NN-NN im Kuenstlerfeld)
Die erste Fassung beschrieb einen anderen Mechanismus (doppelte Tracknummer aus
dem Titel-Tag). Marcs Beispiel zeigt etwas anderes: 01-02 steht an der Stelle des
Kuenstlers, die Tracknummer fehlt. trackPrefix kann diese Form nicht erzeugen,
die Quelle muss also das Kuenstlerfeld so geliefert haben — dieselbe Form ist in
metadata.test.js bereits als "garbage artist prefix" festgehalten.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 23:46:47 +02:00
marcandClaude Opus 5 871ecdd72e docs(changelog): doppelte Tracknummern im Dateinamen als bekannten Fehler notiert
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 23:44:59 +02:00
marcandClaude Opus 5 a2211a62d2 refactor(web+android): nur Warteschlange und Titel sichern, keine Sekunden
Das Mitschreiben der Abspielposition war zu viel des Guten: es bedeutete
staendiges Schreiben waehrend der Wiedergabe fuer einen Gewinn, den man kaum
bemerkt. Gesichert werden jetzt nur Warteschlange und aktueller Titel, der dann
von vorn beginnt.

Der eigentliche Gewinn bleibt und war der Ausloeser: unter Android war die
Now-Playing-Leiste nach dem Oeffnen leer, bis man einmal auf Play drueckte —
gesichert war nur der letzte Song, nicht die Warteschlange. Das Wiederherstellen
fuellt den Zustand jetzt ueber syncState(), also ohne Abspielen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 23:25:06 +02:00
marcandClaude Opus 5 65fa950043 feat(web+android): Wiedergabe fortsetzen und Streitpunkte im Duell (2.4)
Wiedergabe fortsetzen:
Im Web ueberlebten Warteschlange und letzter Titel bereits, die POSITION im
Titel aber nicht — beim Neuladen begann der Song von vorn. Android sicherte nur
den letzten Song ohne Warteschlange. Beide merken sich jetzt Warteschlange,
Listenposition und Sekunde.

Web schreibt gedrosselt (alle 5 s) waehrend der Wiedergabe und sicher beim
Pausieren, Wegwischen und Tabwechsel — pagehide/visibilitychange statt
beforeunload, das am Handy unzuverlaessig feuert. Android sichert bei jedem
Titelwechsel und beim Pausieren und stellt nach dem Verbinden wieder her:
vorbereitet, aber NICHT abgespielt, wer die App oeffnet will nicht ueberfallen
werden. Laeuft schon etwas (Android Auto), passiert nichts.

Zwei Feinheiten: lag die Position im letzten Rest des Titels, faengt er von vorn
an, statt zwei Sekunden Abspann zu spielen; und gespeichert werden nur Song-Ids,
weil Titel und Cover sich durch Metadaten-Bearbeitung aendern koennen —
verschwundene Titel werden beim Wiederherstellen uebersprungen.

Streitpunkte im Duell:
Gemeinsame Kuenstler nach groesstem Ungleichgewicht statt nach Summe, mit
Kraefteverhaeltnis-Balken. Mindestens vier gemeinsame Plays und 50 % Unwucht,
sonst gilt ein einzelner Play gegen null schon als Streit. Web und Android mit
identischen Schwellen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 23:20:40 +02:00
marcandClaude Opus 5 92c3d96936 docs(changelog): Dublettenprüfung nachgezogen, Unterstrich-Lücke im Variantenfilter notiert
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 23:11:42 +02:00
marcandClaude Opus 5 dfae34c706 feat(android): Navidrome-Adresse als Vorgabe, Login vorbelegt (1.3)
Ergaenzt Backend und Scrobble um die Navidrome-Adresse: alle drei kommen als
buildConfigField aus dem Build und greifen, wenn im Geraetespeicher nichts steht.
Der Anmeldebildschirm ist damit vorbelegt — beim ersten Start bleiben nur noch
Benutzer und Passwort. Die Felder in den Einstellungen bleiben sichtbar und
ueberschreibbar, ein Umzug ist also ohne neues APK zu korrigieren.

Zugangsdaten bleiben aussen vor. Das Publish-Skript reicht die Werte aus
scripts/.env.release durch, damit kuenftige Builds sie nicht verlieren.
Am erzeugten BuildConfig geprueft, alle vier Werte stehen darin.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 20:37:13 +02:00
marcandClaude Opus 5 334aa51a09 feat(android): Backend- und Scrobble-Adresse als Vorgabe aus dem Build
Beide Adressen stehen ohnehin in der docker-compose.yml — sie zusaetzlich auf
jedem Geraet einzutippen ist Arbeit ohne Nutzen. Sie kommen jetzt als
buildConfigField aus -PnovasonicBackend= / -PnovasonicScrobble= und greifen,
wenn im Geraetespeicher nichts steht.

Die Felder in den Einstellungen bleiben sichtbar und ueberschreibbar: zieht ein
Dienst um oder aendert sich ein Port, laesst sich das am Geraet korrigieren,
statt ein APK bauen, hochladen und installieren zu muessen. Ohne gesetzte
Eigenschaften verhaelt sich die App exakt wie bisher.

Zugangsdaten bleiben bewusst aussen vor — die gehoeren pro Person, nicht in ein
APK, das im Release liegt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 20:35:37 +02:00
marcandClaude Opus 5 83570b22b5 refactor(android): Web-Adresse aus BuildConfig statt als vierte Einstellung
Der Host stand ohnehin schon beim Bauen fest, weil die App-Links ihn im Manifest
brauchen. Ihn zusaetzlich als Einstellung zu fuehren hiess: eine vierte Adresse
pflegen, die vom Manifest abweichen kann, ohne dass es jemand merkt — und der
Teilen-Eintrag versteckte sich, solange sie leer war, was beim Suchen schlicht
wie ein fehlendes Feature aussah.

Jetzt kommt beides aus -PnovasonicHost=…: das Manifest fuer eingehende Links,
BuildConfig.SHARE_HOST fuer ausgehende. Die Einstellung samt Speicherfeld ist
entfernt, Teilen ist immer sichtbar. versionCode 5 / 1.2, APK hochgeladen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 20:27:27 +02:00
marcandClaude Opus 5 dea0485a54 docs(changelog): Android 1.1 und die Sichtbarkeit des Teilen-Eintrags
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 20:03:57 +02:00
marcandClaude Opus 5 4323d68edc chore(android): versionCode 4, versionName 1.1
Der In-App-Updater vergleicht versionCode aus der Gitea-Release-Beschreibung mit
BuildConfig.VERSION_CODE. Beide standen auf 3, das hochgeladene APK meldete sich
also korrekt als "kein Update" — trotz Teilen-per-Link, Songloeschen,
Playlist-aus-Import und Duell-Anzeigetafel. Version angehoben und die
Release-Beschreibung auf versionCode=4 gesetzt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 19:03:17 +02:00
marcandClaude Opus 5 91d0d5fd0b feat(web+android): Musik-Match wird zum Duell mit Anzeigetafel
Statt eines Prozentrings ("wie aehnlich seid ihr") zeigt die Ansicht jetzt, wer
worin gewinnt: fuenf Kategorien mit je einem Sieger und ein Gesamtstand.
Hoerzeit, Vielfalt, Tiefe (Plays je Kuenstler), Nachteule (Anteil vor 5 Uhr) und
Entdeckerdrang (Anteil exklusiver Kuenstler) — bewusst Kennzahlen zur Hoerweise
statt zur Menge, sonst gewinnt immer, wer laenger dabei ist.

Am laufenden Dienst mit zwei gegensaetzlichen Nutzern geprueft: 60 Plays a 300 s
ergeben 5,0 h und Tiefe 12,0, jeder dritte Play nachts ergibt 33 %, 60 von 62
exklusiven Kuenstlern ergeben 97 % — Endstand 3:2. Das JSON-Feldschema wurde
gegen das Kotlin-Modell abgeglichen.

Dazu drei Fixes im selben Bereich:
- Die Web-Ansicht lebte nur von Inline-Stilen mit festen Flex-Verhaeltnissen und
  zerfiel am Desktop. Jetzt ein Raster mit eigenen Klassen, eine Spalte am Handy,
  zwei ab 780 px; das Fenster musste dafuer von 720 auf 940 px, sonst haette die
  zweite Spalte nie ausgeloest.
- Gemeinsame Songs wurden ueber song_id abgeglichen und fielen auseinander,
  sobald eine Datei umbenannt wurde. Jetzt normalisierter Titel+Kuenstler.
- Media-Session: die Metadaten wurden feldweise mutiert (gegen Kachel-Flackern
  unter Windows), ueber MPRIS kam davon nichts an — Plasma-Widgets zeigten
  dauerhaft den zuerst gespielten Titel. Bei echtem Titelwechsel jetzt ein neues
  MediaMetadata, sonst weiter in-place.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 13:55:16 +02:00
marcandClaude Opus 5 5a6cff8105 chore(share): echten Signatur-Fingerabdruck in assetlinks.json
Die veroeffentlichten APKs sind Debug-signiert (kein signingConfig im
Release-Buildtype), der Fingerabdruck ist deshalb der des Debug-Keys:
1039A00E… — geprueft mit apksigner am gebauten APK und identisch mit dem
Schluessel des bisher veroeffentlichten Release, Updates laufen also in-place.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 13:42:37 +02:00
marcandClaude Opus 5 5f1650b82a build(apk): Publish-Skript reicht den App-Link-Host an Gradle durch
Der Host steht fest im Manifest und muss beim Bauen mitgegeben werden. Das
Publish-Skript rief Gradle bisher ohne ihn auf, ein so veroeffentlichtes APK
haette also den Platzhalter aus build.gradle.kts getragen und geteilte Links
waeren im Browser gelandet statt in der App. NOVASONIC_HOST (und optional
NOVASONIC_HOST2) kommen aus scripts/.env.release; fehlt der Wert, warnt das
Skript deutlich, statt still das Falsche zu bauen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 12:25:14 +02:00
marcandClaude Opus 5 94fdc3274e docs(share): Ablauf eines Domainwechsels als Reihenfolge
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 12:23:05 +02:00
marcandClaude Opus 5 a89e2974bc feat(android): zweiter App-Link-Host fuer einen Domainwechsel
Der Host eingehender Links steht fest im Manifest, ein Domainwechsel brauchte
also zwingend ein neues APK und liess alte Links sofort ins Leere laufen. Mit
-PnovasonicHost2= laesst sich waehrend des Umzugs eine zweite Adresse angeben;
ohne Angabe wird der erste Host wiederholt. Bewusst kein Platzhalter-Host als
Vorgabe: auf Android 11 und aelter verifiziert das System nur, wenn ALLE Hosts
eine gueltige assetlinks.json liefern — ein toter Eintrag wuerde alle blockieren.
Am zusammengefuehrten Manifest geprueft, beide Hosts landen darin.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 03:47:35 +02:00
marcandClaude Opus 5 430ecdc737 feat(web+android): Teilen per Link
Ein Song oder Album laesst sich per https://<host>/?song=<id> an jemanden auf
derselben Instanz schicken. Der Link traegt nur die Navidrome-Id, keine
Zugangsdaten — der Empfaenger sieht den Inhalt mit seinem eigenen Konto.

Web: Teilen ueber navigator.share() mit Rueckfall auf die Zwischenablage. Beim
Start wird ?song= / ?album= aufgeloest (nach der Anmeldung, vorher fehlen die
Zugangsdaten), das Album geoeffnet, der Song gestartet und der Parameter aus der
Adresszeile entfernt, damit ein Neuladen nicht erneut losspielt. Das Manifest
bekommt launch_handler=navigate-existing, damit der Link in einem bereits
offenen PWA-Fenster landet statt in einem neuen.

Android: Teilen ueber ACTION_SEND, Empfang ueber einen App-Link-Intent-Filter.
Der Host ist eine Build-Eigenschaft (-PnovasonicHost=…, verifiziert am
zusammengefuehrten Manifest), die Web-Adresse fuer ausgehende Links eine neue
Einstellung. Weil der NavController in der Compose-Hierarchie lebt und die
Activity nicht selbst navigieren kann, reicht DeepLinkState den Link durch;
onNewIntent ist mitbedacht, sonst passierte beim zweiten Link nichts.

assetlinks.json liegt als Vorlage in public/ und wird vom Frontend-Image
ausgeliefert (im Build verifiziert); ohne den Release-Fingerabdruck oeffnet der
Link die Web-App im Browser statt die App. Anleitung: docs/share-links.md.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 03:30:32 +02:00
marcandClaude Opus 5 3c99778567 fix(backend): Dublettenpruefung erkennt Akzente und Soundtrack-Ordner
Drei Luecken derselben Familie, die dazu fuehrten, dass dieselben Songs ein
zweites Mal geladen wurden:

- Kuenstlernamen wurden zeichengenau verglichen: "Cécile Corbel" und "Cecile
  Corbel" galten als zwei Personen. Welche Schreibweise ankommt, haengt an der
  Quelle (Deezer vs. Spotify). Der Vergleich normalisiert jetzt Akzente weg —
  nur der Vergleich, Tags und Dateinamen behalten das Original.
- Typografische Apostrophe: "Arrietty’s Song" (U+2019) und "Arrietty's Song"
  fielen auseinander. Fiel beim Testen auf, betrifft viele Soundtracks.
- findExistingTrack durchsucht nur den Ordner des uebergebenen Kuenstlers. Bei
  Soundtracks weicht der Album- vom Titel-Kuenstler ab, der Song landet je nach
  Ladeweg unter dem einen oder anderen — geprueft wurde jeweils der falsche.
  Weicht der Titel-Kuenstler ab, wird nun auch dessen Ordner geprueft (~0,6 ms
  bei 28.801 Dateien, gegenueber 3-9 s pro Download).

Sieben neue Tests zielen gezielt auf Fehlalarme: aehnliche Namen (Cecil Taylor
vs. Cécile Corbel), gleicher Titel bei verschiedenen Kuenstlern, Remix gegen
Basistitel, fremder Titel im Soundtrack-Ordner — alle bleiben getrennt.
Gesamte Suite: 42 Tests gruen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-05 08:40:02 +02:00
marcandClaude Opus 5 f62b248bb6 fix(backend): Metadaten-Edit trifft nicht mehr die falsche Datei
Findet das Backend die von Navidrome gemeldete Datei nicht am angegebenen Pfad
(Subsonic liefert oft einen aus Tags gebauten virtuellen Pfad), sucht es ueber
Dateiname bzw. Kuenstler+Titel weiter. Liegt derselbe Song mehrfach auf der
Platte, konnte das die falsche Kopie treffen: die wurde getaggt, der bearbeitete
Song blieb unveraendert — die Aenderung "sprang zurueck". Das erklaert, warum es
bei Songs ohne Dublette immer ging und bei anderen nie.

Der ueber Aehnlichkeit gefundene Kandidat wird jetzt per ffprobe gegen die Tags
geprueft, die Navidrome fuer diesen Song meldet, und bei Widerspruch mit 409 und
erklaerender Meldung abgebrochen statt geraten. Zusaetzlich melden uebersprungene
Umbenennungen und Verschiebungen sich als Warnung, statt stumm zu bleiben; die
Antwort nennt den tatsaechlich bearbeiteten Pfad, der Editor zeigt beides an.

Ausserdem: -dontwarn org.slf4j.** — der Release-APK-Build brach seit laengerem an
R8 ab (Ktors Logging referenziert den slf4j-1.x-Binder, den es auf Android nicht
gibt). Vorbestehend, mit HEAD~1 verifiziert.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 23:46:44 +02:00
marcandClaude Opus 5 aae358c4c7 feat(android): Songs loeschen und Playlist aus dem Import, plus Web-Scrollfix
Android holt zwei Sachen nach, die es im Web laengst gibt:

- Song von der Festplatte loeschen, im Kontextmenue unten abgesetzt und rot, mit
  derselben Sicherheitsabfrage wie im Web. Laeuft ueber /api/delete-song und
  erscheint nur mit konfiguriertem Backend — Navidrome allein loescht nichts.
- Playlist direkt aus dem Import anlegen: Haekchen plus Namensfeld ab zwei
  Titeln, danach Scan anstossen, Titel suchen, Playlist aus den gefundenen.
  Nicht gefundene werden gezaehlt statt die Erstellung scheitern zu lassen.

Dazu der Web-Fix zur Album-Position: die gespeicherte Scrollposition wurde in
genau einem requestAnimationFrame gesetzt. Solange Cover und Eintraege noch
nachluden, war scrollHeight kleiner als das Ziel und der Browser kappte den Wert
stillschweigend — man landete wieder oben. Jetzt wird er ueber bis zu ~0,5 s
erneut gesetzt, bis er sitzt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 23:40:57 +02:00
marcandClaude Opus 5 a05c15df93 docs(changelog): YTM-Wächter, Album-Zurück und Scrobble-Gruppierung
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:52:03 +02:00
marcandClaude Opus 5 da32d2911a fix(scrobble): Metadaten-Bearbeitung zerlegt die Statistik nicht mehr
Top-Titel gruppierte nach song_id. Wird eine Datei beim Bearbeiten umbenannt,
vergibt Navidrome eine neue id — der Titel erschien danach zweimal mit geteilten
Zaehlern. Kuenstler/Alben/Genres gruppierten nach lower(), sodass schon ein
doppeltes Leerzeichen zwei Eintraege ergab.

Schluessel ist jetzt durchgehend normalisiert (lower + trim + Leerzeichen
gefaltet), Top-Titel gruppiert nach Titel+Kuenstler statt nach song_id. Die
Anzeigefelder kommen aus dem JUENGSTEN Play statt aus MAX(), sonst zeigte die
Statistik nach einer Korrektur weiter die alte Schreibweise. Am laufenden Dienst
geprueft: 40 Plays vor und 10 nach einer Umbenennung erscheinen als ein Eintrag
mit 50 Plays, neuer Schreibweise und neuer songId.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:51:47 +02:00
marcandClaude Opus 5 39d47b78d4 fix(web): Zurueck im Album fuehrt dorthin zurueck, wo man geklickt hat
album-back-btn war die einzige Detailseite, die per navigate() VORWAERTS auf die
Albenliste sprang statt einen Schritt im Verlauf zurueck. Dadurch landete man
nicht dort, wo man das Album angeklickt hatte (z. B. Home), und es kam ein
zusaetzlicher History-Eintrag auf den Stapel, durch den sich der Browser-Zurueck-
Knopf erst arbeiten musste. Jetzt _navGoBack() wie bei Artist, Genre, Deezer- und
Partial-Album; die Albenliste bleibt nur das Ziel, wenn es keinen Verlauf gibt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:51:47 +02:00
marcandClaude Opus 5 eee98d193f fix(backend): Kanaltreffer in der YTM-Suche verwirft nicht mehr die Trefferliste
getYtmVideoUrls wertete jedes /browse/UC in der Ausgabe als "yt-dlp hat einen
Artist-Channel aufgeklappt" und gab [] zurueck — samt der bereits gesammelten
Song-URLs. Bei "DAT ADAM UFO" stand der Kanal auf Platz 9 und riss sieben gute
Treffer mit, darunter den offiziellen Art Track auf Platz 1; uebrig blieb der
YouTube-Fallback mit einem Live-Mitschnitt. An 8 echten Suchen gemessen feuerte
das in 7 Faellen, Schritt 1 der Kaskade war also praktisch tot.

Mit --flat-playlist kann gar nichts aufgeklappt werden, ein Kanal ist EINE Zeile.
pickYtmVideoUrls() behaelt daher alle watch?v=-Zeilen und ueberspringt browse/UC
(Kanal) wie browse/MPREb_ (Album). Ueber 20k Zufallsausgaben geprueft: die neue
Funktion ist eine Obermenge der alten, kann also nur Kandidaten hinzufuegen.
Drei echte Downloads liefen end-to-end sauber durch (Dauer sekundengenau auf
Deezer, korrekte Tags), alle aus Schritt 1 statt aus dem Fallback.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:51:32 +02:00
marcandClaude Opus 5 33b3df609a fix(backend): Live-Mitschnitte aus der Suche ausschliessen
is_live meint nur "laeuft gerade als Stream" — eine Konzert-AUFNAHME kam
ungehindert durch und landete als Albumtrack in der Bibliothek ("Dat Adam - Ufo
Video Days 2015 Live" auf dem echten Kuenstlerkanal, Dauer im Fenster). Der
Variantenfilter bekommt daher eine live-Regel. Sie schaltet sich ab, wenn der
gesuchte Titel selbst live enthaelt; die Pruefung nutzt \blive\b statt includes,
sonst wuerde "deliver" die Regel aushebeln. Drei Tests dazu.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-03 22:35:44 +02:00
marcandClaude Opus 5 6d8a8a1d5e fix(backend): Neuauflage-Jahreszahl nicht als Pflicht-Keyword fordern
Folgekorrektur zu 02b5905: "… - 2020 Remaster" steht auf der Veroeffentlichung,
aber nie im YouTube-Titel — als Pflicht-Keyword haette die Zahl den richtigen
Upload abgelehnt. Jahreszahlen neben einem Qualifier (remaster/version/edition/
anniversary/mono/stereo) fallen daher wieder raus; ein Titel, der selbst eine
Jahreszahl ist ("1999", "Berlin 2020"), behaelt sie. Gegen 29 Beispieltitel
gemessen verhalten sich 24 exakt wie vorher.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-03 22:20:44 +02:00
marcandClaude Opus 5 02b590505a fix(backend): Zahlen im Titel sind Pflicht-Keywords, Abkuerzungen erlaubt
"700 Main Street" lud "777 Main Street" eines fremden Artists: buildTitleKeywords
behielt nur die zwei laengsten Woerter (Street, Main), die unterscheidende 700
fiel als zu kurz raus — und Schritt 3 der Kaskade prueft den Kuenstler-Channel
nicht mehr. Zahlen werden jetzt immer als \b<n>\b gefordert. Dazu eine kleine
Abkuerzungstabelle (street/st, saint/st, mount/mt, doctor/dr, versus/vs,
number/no), denn der korrekte Art Track heisst "700 Main st" und scheiterte
bisher an jedem Schritt. Tests in backend/test/ytdlp.test.js.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-03 22:04:00 +02:00
marcandClaude Opus 5 9f0d4c3153 docs(changelog): 2.3 — Pull-Stack, APK-Download-Fix, Alben-Tab-Scrollfix
Fasst die Aenderungen seit 2.2 als Release zusammen: image-basiertes
docker-compose.yml (Bauen wandert nach .dev.yml), der auf GITEA_URL
umgeschriebene APK-Asset-Download und der Alben-Tab-Fix, dazu das
veroeffentlichte versionCode 3. Am Handy bestaetigt: Update-Dialog,
In-Place-Install und die Scrollpositionen funktionieren.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-03 21:36:59 +02:00
marcandClaude Opus 5 e91708bc97 chore(android): versionCode 3 veroeffentlicht (Scroll-Fixes im Release)
APK mit dem Debug-Key vom alten Rechner gebaut (Signatur 1039a00e…, passend zur
installierten App) und als Asset im Release apk-latest ersetzt, Body auf
versionCode=3. Dazu das ausfuehrbare Bit auf gradlew, das im Clone fehlte, und
.idea/ ignoriert.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-03 21:25:25 +02:00
marcandClaude Opus 5 0029b89de4 fix(android): Alben-Tab behaelt die Scrollposition beim Zurueck
LaunchedEffect(state.albumSort) { scrollToItem(0) } feuerte nicht nur beim
Sortierwechsel, sondern auch beim ersten Compose nach der Rueckkehr aus einem
Album — die im ViewModel gehaltene Position wurde also sofort ueberschrieben.
Das Hochscrollen sitzt jetzt in setAlbumSort() und laeuft nur bei echtem
Wechsel; dazu zwei ungenutzte remember*State-Importe entfernt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 21:21:38 +02:00
marcandClaude Opus 5 3e8897b551 fix(backend): APK-Download nutzt den erreichbaren Gitea-Host statt der ROOT_URL
Gitea baut browser_download_url aus seiner eigenen ROOT_URL (hier
192.168.178.153:3000), die vom Backend-Container nicht erreichbar ist. Der
API-Call gelang, der Asset-Download nicht — der stille Fallback auf die nicht
vorhandene lokale Datei meldete dann "Keine APK hinterlegt". Asset- und
Redirect-URLs werden jetzt auf GITEA_URL umgeschrieben; scheitert der Weg
trotzdem, sagen Log und Fehlermeldung welcher der beiden Wege fehlt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 16:21:31 +02:00
marcandClaude Opus 5 043ec3a108 refactor(docker): docker-compose.yml ist der Pull-Weg, Bauen wandert nach .dev.yml
Namen getauscht: das Standard-Compose zieht jetzt die fertigen Registry-Images
(vorher docker-compose.prod.yml), die Build-Variante heisst docker-compose.dev.yml.
Weniger verwirrend, weil der Produktivfall ohne -f auskommt. Kopfkommentare,
README, CLAUDE.md, .env.example und build-push-images.mjs entsprechend angepasst.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 16:15:46 +02:00
marcandClaude Opus 5 62391e4aae feat(docker): pull-based prod stack (docker-compose.prod.yml + Registry-Images)
Produktivsystem baut nicht mehr selbst, sondern zieht die drei fertigen Images
(novasonic-frontend/-backend/-scrobble) aus der Gitea-Registry. Das bestehende
docker-compose.yml bleibt der Build-auf-dem-Host-Weg. Dazu .dockerignore fuers
Frontend-Image (android/, backend/, .git raus) und README/CLAUDE.md aktualisiert.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 16:13:46 +02:00
HoneyandClaude Opus 4.8 767d088665 refactor(docker): default compose builds from Dockerfiles (baked deps, cached)
Chosen flow: build on the host from backend/scrobble Dockerfiles instead of
pulling from a registry (no registry / no Docker-on-dev needed). Heavy deps are
baked, so restarts are instant and rebuilds after git pull are cache-fast.
Removed the now-obsolete docker-compose.dev.yml (runtime-install variant); the
optional push-to-registry script stays for a future CI flow. Updated README,
CLAUDE.md, .env.example.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 13:34:00 +02:00
HoneyandClaude Opus 4.8 1d8d8143f2 refactor(docker): make image-based the default compose, build variant is .dev
Less confusion: docker-compose.yml is now the default (pulls pre-built images)
and the build-on-host variant is docker-compose.dev.yml. Updated all references
(CLAUDE.md, README, .env.example, build-push-images.mjs, compose header).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 08:03:14 +02:00
HoneyandClaude Opus 4.8 149443e4f7 feat(docker): image-based prod stack (Dockerfiles + prod compose + push script)
Adds a pull-based production option so the host no longer builds/installs deps
on every restart:
- backend/Dockerfile + scrobble/Dockerfile bake the heavy deps (ffmpeg, Deno,
  yt-dlp, node libs). Backend still refreshes yt-dlp on start (non-fatal).
- docker-compose.prod.yml pulls ${REGISTRY}/novasonic-*:${TAG}.
- scripts/build-push-images.mjs (npm run push-images) builds + pushes all three.
- .env.example documents every var incl. REGISTRY/TAG; .env gitignored.

The build-on-host docker-compose.yml stays as-is.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 07:45:17 +02:00
HoneyandClaude Opus 4.8 93ee958434 feat: artist-page scroll/search memory (android) + move APK button to bottom (web)
- Android: the artist page's main list and the "Alle anzeigen" album overlay
  (grid scroll + search query) are hoisted into the Artist/Explore ViewModels,
  so drilling into an album/artist and back keeps position + query. Covers the
  library artist and Deezer (Explore) artist screens.
- Web: the "Android App" download section now sits at the very bottom of
  Settings, below the Navidrome-Server (account) section.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 07:42:24 +02:00
HoneyandClaude Opus 4.8 a780f6622b chore(android): versionCode 2 (first apk-latest release upload)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 07:27:06 +02:00
HoneyandClaude Opus 4.8 6da40d9e63 docs(scripts): add .env.release.example template for publish-apk
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 00:52:49 +02:00
HoneyandClaude Opus 4.8 2fd4d978d0 feat(android): in-app updater (backend/Gitea APK), auto-bump versionCode
The app checks {backend}/api/apk/info on launch and, if a newer versionCode
than BuildConfig.VERSION_CODE is offered, shows an update dialog that
downloads {backend}/api/apk into a single wiped-each-time cache file and
hands it to the system installer (FileProvider + REQUEST_INSTALL_PACKAGES).
No APK hoarding; in-place install preserves data (stable signing key needed).

- backend /api/apk/info now returns versionCode (parsed from the release body).
- publish-apk.mjs auto-increments versionCode, sets versionName, and writes
  versionCode/versionName into the Gitea release body.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 00:46:11 +02:00
HoneyandClaude Opus 4.8 845f125d76 feat: remember scroll + search position on Back (web + android)
Going into an album/artist and back now restores the scroll position and
keeps the typed query, instead of resetting to the top.

- Web: navigation.js snapshots each history entry's #main-content scroll and
  any open local (header) search, restoring them on Back/Forward; a genuine
  new navigation still starts at the top.
- Android: the Alben/Künstler lists (LibraryViewModel) and the global/local
  search-results lists (ExploreViewModel/SearchViewModel) hoist their
  LazyListState/LazyGridState, so scroll survives a drill-in/back for the
  tab's lifetime.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 00:06:46 +02:00
HoneyandClaude Opus 4.8 3ceba8a365 feat(android): partial-album detail gets Play/Shuffle + track 3-dot menu
You can still enjoy an incomplete album: the downloaded-tracks section now has
Abspielen + Zufall buttons (play/shuffle the downloaded songs) and each
downloaded row gets the 3-dot context menu, threaded from both artist screens.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-01 23:58:24 +02:00
HoneyandClaude Opus 4.8 3000dc1622 feat(scripts): one-command APK build + upload to the fixed Gitea release
`npm run publish-apk` builds the APK (assembleDebug by default — the release
build type is unsigned) and uploads it to the apk-latest Gitea release,
replacing the old .apk asset, so the web download button always serves the
latest build. Config via env or a gitignored scripts/.env.release
(GITEA_URL/REPO/TOKEN, APK_GRADLE_TASK). Release title tracks versionName.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-25 18:23:27 +02:00
HoneyandClaude Opus 4.8 33d24c6ed4 feat(backend): APK download proxies a fixed Gitea release (local fallback)
The /api/apk + /api/apk/info routes now fetch a fixed Gitea release
("apk-latest") server-side over the LAN and stream its .apk asset, falling
back to /data/novasonic.apk. Gitea can stay internal-only — the backend holds
the token, the browser only ever talks to the backend. Follows redirects,
constant ~30 MB (overwrite the one release's asset each build).

env: GITEA_URL, GITEA_REPO, GITEA_TOKEN (private repo only), GITEA_APK_TAG.
docker-compose documents them; unset = local-file fallback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-25 18:16:13 +02:00
HoneyandClaude Opus 4.8 908b50bcd9 feat(web): download the Android APK from Settings
Backend serves a staged APK so co-users self-serve the latest build:
- GET /api/apk streams APK_PATH (default /data/novasonic.apk) with the
  android package content-type + attachment disposition; 404 if absent.
- GET /api/apk/info reports availability, size, mtime, and an optional
  version from /data/novasonic.version.txt.
- Settings gets a "🤖 Android App" section that appears only when an APK is
  present and shows version/size/date.

Maintainer updates the APK with:
  docker cp app-release.apk novasonic-backend:/data/novasonic.apk

Android source is already tracked; only build artifacts stay out of git.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-25 18:00:36 +02:00
HoneyandClaude Opus 4.8 7996971ba0 fix(web): search results panel spans full content width
The header search overlay was anchored to the search bar's width, leaving a
dead strip on the right where scrolling hit the background page. Anchor it to
the sticky #mobile-header instead (which already sits right of the sidebar), so
it spans the full main-content width — sidebar stays visible, no dead strip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-23 12:46:50 +02:00
HoneyandClaude Opus 4.8 026b392657 fix: Japanese/CJK albums vanished from artist discography (web + android)
The album-name normaliser stripped everything but a-z0-9, so any JP/CJK
title collapsed to "". All of an artist's Japanese singles then normalised
identically, de-duplicated into one entry and "matched" each other — e.g.
inabakumori (稲葉曇) showed only 2 of 9 releases. Normalisers now keep
Unicode letters/numbers (\p{L}\p{N}) in:
- web _normAlbum (detail.js)
- android normAlbum (categorizeAlbums), normTrack (partial-album split),
  the enrichPartialCounts helpers, and the Deezer artist-name match.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 18:49:59 +02:00
HoneyandClaude Opus 4.8 ed641e999c fix(web): artist hero name no longer clips last letter; fold 2.3 into 2.2
- .artist-hero-name: add padding-right so the heavy/negative-letter-spacing
  final glyph isn't cut by overflow:hidden.
- CHANGELOG: merge the 2.3 batch into a single 2.2 (2026-08-22) section.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 00:48:33 +02:00
HoneyandClaude Opus 4.8 67642f8ab8 fix(web): header search dropdown no longer covers the sidebar
Anchor #header-search-overlay to the search bar (position:absolute inside a
relative .header-search-wrap) instead of position:fixed full-viewport width,
so the results drop down at the bar's width and the left sidebar stays visible.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-22 00:41:29 +02:00
HoneyandClaude Opus 4.8 b7c96451d8 feat(android): download notifications everywhere + swipe tabs (NowPlaying, Library)
- Downloads started from global search / Bibliothek now poll via the
  app-lifetime NotificationStore, so they show success/failure like the
  importer and artist page did (was a silent toast only).
- Swipe between tabs, synced with the tab bar, matching Erkunden:
  * Now Playing: Player <-> Lyrics <-> Queue (cover's skip-track swipe
    still wins as a child gesture).
  * Bibliothek: Playlists <-> Alben <-> Künstler <-> Offline.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 23:19:20 +02:00
HoneyandClaude Opus 4.8 d11de8a69e feat(android): importer 30s preview + partial-album detection
- Importer: each resolved track gets a play/stop button that plays its
  Deezer/Spotify preview via the app-level preview bar (pauses library
  playback, highlights the row). Parity with the web importer.
- Artist "Unvollständig" now works: Deezer's /artist/{id}/albums omits
  nb_tracks, so owned albums never registered as partial. The artist VM
  now resolves the real total for matched albums via a per-album lookup
  (like web), so the partial section + downloaded/missing split populate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 23:10:28 +02:00
HoneyandClaude Opus 4.8 b584159568 fix: reliable concerts (backend events cache) + web importer preview layout
- Backend now caches Ticketmaster events per artist and prefers the larger
  recent result, so a flaky partial/empty response can't shrink a good list;
  every client (web/Android) stays consistent (1h TTL self-heals).
- Web SoundCloud importer preview: add the missing .gtrack-num grid cell so
  the 4-column row no longer squeezes the cover/title (title was wrapping one
  char per line).
- CHANGELOG [2.3] opened for this batch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 23:02:56 +02:00
HoneyandClaude Opus 4.8 f56d47800c fix(android): even concert rows — fixed calendar-style date block
The "16. Sep. 2026" date wrapped inside the 52dp column, so rows with/without
a time ended up different heights and the divider/venue misaligned. The date
block is now a fixed 56dp calendar block: big day number, small month/year and
time, each single-line — every row is the same height and lines up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 20:00:49 +02:00
HoneyandClaude Opus 4.8 2208ce77b6 fix(events): show the venue-local concert time consistently
Backend sent the UTC `dateTime` (a 20:00 local show read as 08:00Z), and
Android's ZonedDateTime.parse choked on zone-less values → some rows had a
wrong time, others none at all.

- Backend: prefer localDate+localTime (venue-local, naive) over the UTC instant.
- Android: parse a naive LocalDateTime first, fall back to ZonedDateTime for
  older "…Z" values. Web already renders the naive string as-is.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 19:59:26 +02:00
HoneyandClaude Opus 4.8 f27eaf9c82 fix(android): surface concert-fetch errors instead of swallowing them
Events were fetched with runCatching{}.getOrDefault(emptyList()), so any
network/deserialization failure looked identical to "no concerts". The
backend + Ticketmaster work (verified), so the failure is client-side.

- EventsClient: expectSuccess + timeouts so a non-2xx (e.g. an SSO/HTML
  redirect) becomes a real exception instead of an obscure body() failure.
- ArtistViewModel: capture the failure into eventsError (+ Logcat) rather
  than defaulting to empty.
- ConcertsSheet: show "Konzerte konnten nicht geladen werden" + the reason
  when the fetch failed, vs. "Keine Konzerte angekündigt" when genuinely none.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 19:46:16 +02:00
HoneyandClaude Opus 4.8 7b4599c50a feat(artist): minimal icon-only pin button + show all Deezer releases (Android)
- Pin ("Falscher Künstler?") is now a small icon-only ⚙ chip on both web
  and Android — accent-blue when pinned, subtle white otherwise; no more
  text banner over the hero.
- Android artist discography no longer filters to record_type=="album";
  it now shows albums, EPs AND singles (ordered albums→EPs→singles),
  matching Deezer's own artist page. Web already showed all.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 19:19:17 +02:00
HoneyandClaude Opus 4.8 934253a036 feat(web): merge Song Importer into Global Suche (one unified field)
The importer no longer has its own sidebar/bottom-nav entry. The Global
Suche field now handles both jobs: plain text runs the Deezer search;
a pasted Spotify/SoundCloud/YouTube link switches into importer mode
(badge + "Importieren" button + preview), matching the Android app and
tidying the left nav.

- New onGlobalInput/tryImporterResolve; importer DOM moved into
  page-discover; old page-spotify-importer removed; routing cleaned up.
- Existing resolvers unchanged (still read the mirrored importer-link-input).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-21 17:59:44 +02:00
HoneyandClaude Opus 4.8 0a6c81b4a1 docs: tidy CHANGELOG (drop duplicated [0.9] block) + refresh README
- CHANGELOG: remove the accidentally duplicated Changed/Fixed/Investigated
  block that sat orphaned before [0.8]; [0.9] now appears once.
- README: artist-pages bullet now mentions the same-name artist pin
  (Deezer link/id) and that a pinned artist's similar list comes from Deezer.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-19 00:54:19 +02:00
HoneyandClaude Opus 4.8 593c9fdb7b fix(backend): YouTube downloads — install Deno + pull yt-dlp nightly
Downloads were 403ing on two fronts: (1) recent yt-dlp needs a JS runtime to
solve YouTube's signature/nsig challenge (Deno, added in cb7a3d7), and (2) the
current yt-dlp *stable* had a bug that 403'd the android_vr client on every video
(yt-dlp#17456, fixed in nightly). Switch the backend from the stable yt-dlp
binary to nightly via pip (`--pre 'yt-dlp[default]'`). Verified end-to-end incl.
a real frontend download. No cookies / PO-token service / proxy needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-19 00:40:31 +02:00
HoneyandClaude Opus 4.8 cb7a3d77be fix(backend): install Deno so yt-dlp can solve YouTube's signature/nsig challenge
Recent yt-dlp (which the backend re-pulls latest on every restart) needs an
external JavaScript runtime to solve YouTube's signature/nsig challenge — without
it, "Signature solving failed" → formats get skipped/HTTP 403. Install Deno in the
backend container (+ unzip for its installer) and put it on PATH for the node
process so spawned yt-dlp finds it. No extra container, no account, no proxy.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-18 23:58:22 +02:00
HoneyandClaude Opus 4.8 635ba8d353 revert: drop the YouTube cookies/PO-token/proxy workarounds (back to pre-saga state)
None of it got downloads working on the flagged datacenter IP (web_music media
403, then 429 rate-limiting), so revert the whole lot to keep things clean:
- config.js: remove potProviderUrl + ytdlpProxy
- ytdlp.js: remove potArgs/proxyArgs; player_client back to web_music,default
- novasonic-server.js: remove pot/proxy args from importer resolve
- docker-compose.yml: remove the bgutil-provider service + backend env/plugin/depends_on
- CHANGELOG: drop the [2.2] section

Kept the one genuine fix: a failed direct-link download now reports failure
(moved its note into [2.1]).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 20:24:13 +02:00
HoneyandClaude Opus 4.8 31d4a72e62 fix(backend): download via default client (web_music media 403s); add optional proxy
The PO token provider works (web_music gets a token) but web_music's media URLs
still 403 from a datacenter IP. Prefer the default player clients for the
DOWNLOAD (their URLs go through with a PO token), keeping web_music only as a
fallback for Art-Track extraction; the YTM search still leads with web_music.

Also add an optional YTDLP_PROXY (--proxy) — the durable fix if the IP stays
flagged (403/429) even with a PO token. Empty → unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 17:07:34 +02:00
HoneyandClaude Opus 4.8 4daf87b550 docs(changelog): split download fixes into [2.2] (PO token provider + false-success)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 12:34:15 +02:00
HoneyandClaude Opus 4.8 8fc6a3aaef feat(backend): PO token provider for YouTube downloads; drop the cookies approach
Replace the cookies-file stopgap (needs a throwaway account + manual refresh)
with a self-hosted PO token provider — the cookie-less way past YouTube's
datacenter-IP block (bot check + media 403).

- docker-compose: new bgutil-provider service (brainicism/bgutil-ytdlp-pot-provider)
  + install the bgutil-ytdlp-pot-provider plugin in the backend + POT_PROVIDER_URL
  env + depends_on.
- ytdlp.js / server.js: when POT_PROVIDER_URL is set, pass
  --extractor-args youtubepot-bgutilhttp:base_url=... to the download cascade, the
  YTM search probe and the importer resolve. Empty → omitted (unchanged behaviour).
- Removed the cookiesFile config + --cookies wiring so there's no dead code.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 12:28:32 +02:00
HoneyandClaude Opus 4.8 ef019b9b9d fix(backend): direct-link download failure was reported as success
The direct-URL (sourceUrl) path returned { success: true } even when no audio
file was produced (e.g. YouTube 403 / bot check), so the job was marked
"done/Fertig!" and web + Android both said the track was added. It now returns
{ failed: true } → the server sets status 'error' with a clear message, which
both frontends already render as a failure. Search-cascade path was already
correct.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 12:20:52 +02:00
HoneyandClaude Opus 4.8 0990dfadb5 fix(backend): pass YouTube cookies to yt-dlp to beat the datacenter bot check
YouTube now returns "Sign in to confirm you're not a bot" for yt-dlp from
datacenter IPs, blocking downloads, search and link-resolve. When a cookies file
is present (YTDLP_COOKIES, default /data/youtube-cookies.txt) every yt-dlp call
passes --cookies so it authenticates. Checked at call time (drop the file in, no
code change); absent → unchanged behaviour. Applied to the download cascade, the
YTM search probe, and the importer resolve.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 12:02:26 +02:00
HoneyandClaude Opus 4.8 e82dec7e01 docs(changelog): 2.1 — Musik-Match, Android artist pin, pin/search/similar fixes, player + swipe polish
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 11:45:28 +02:00
HoneyandClaude Opus 4.8 6f455b565f fix(android): smoother Erkunden swipe + top charts no longer vertically centered
- Pre-compose the neighbour page (beyondViewportPageCount = 1) so the first
  swipe doesn't hitch while the heavy LazyColumn builds.
- Drive the TabRow indicator off pagerState.currentPage so it moves with the
  swipe (at the half-way point) instead of only on settle — the lag read as
  "not smooth".
- Wrap each pager page in Box(fillMaxSize) so short content (the Top-Alben
  charts row) sits at the top again, not vertically centered.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-16 22:01:34 +02:00
HoneyandClaude Opus 4.8 7f5d25a03b feat(android): swipe between Erkunden sub-tabs (Bibliothek ↔ Global)
Wrap the Erkunden content in a HorizontalPager so a left/right swipe switches
between the Bibliothek and Global search tabs, two-way synced with the TabRow: a
chip tap animates the pager; a settled swipe updates the selected tab (and stops
any preview, like a tap). Removes the idea from the backlog now that it's built.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-16 21:52:11 +02:00
HoneyandClaude Opus 4.8 87ee8cd097 fix(android player): seek broke after seamless track transitions (durationMs stuck at 0)
After skipping through already-buffered tracks the player stays READY, so
onPlaybackStateChanged never fires and syncState() isn't re-called; ctrl.duration
was TIME_UNSET(→0) at the transition, leaving state.durationMs stuck at 0. The
seek bar then computed fraction*0 = 0 and snapped playback to the start every time
(or to a stale value → "only 10s"). Restarting the app re-read the real duration,
which is why it recovered.

Fix: durationMs now self-heals — the 500ms ticker refreshes it too, and
resolveDurationMs() falls back to the current song's known duration while
ctrl.duration is still unset. Also record the Erkunden swipe-between-tabs idea.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-16 21:47:58 +02:00
HoneyandClaude Opus 4.8 803331e807 feat(android): pinned similar artists tap through to library; note Following view idea
Pinned similar artists (Deezer related) were non-clickable on Android because
Deezer artists carry no Navidrome id. On tap, resolve the name against the
library (exact case-insensitive match) and navigate to that Navidrome artist if
present, else a short "not in your library" toast.

Also: extend the CHANGELOG "Artist following" backlog idea with a dedicated
"Following" view (grid of followed artists) + follow/unfollow toggle.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-14 01:12:47 +02:00
HoneyandClaude Opus 4.8 26de85a140 fix(artist pin): apply pins in search + fix similar artists (web + android)
Two gaps the pin left, on both platforms:

1. Search still showed the wrong same-name artist's photo. The library search
   now prefers the pin's Deezer picture for a pinned artist (web: search.js
   artist cards; android: LibrarySearchContent via SearchViewModel overrides).

2. Similar Artists were "weird" — they come from Last.fm keyed to the (merged/
   wrong) Navidrome artist. When pinned, use Deezer "related" of the pinned
   artist instead (new deezerRelatedArtists / ItunesClient.lookupRelatedArtists).

Also: web Similar Artists now render with profile pictures (avatar chips), like
the Android app, instead of plain text chips.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 18:42:15 +02:00
HoneyandClaude Opus 4.8 1ee85482f3 feat(android): artist pin (same-name disambiguation) — parity with web
Android now reads AND writes the shared server-side artist overrides
(/api/artist-overrides), so pins set on web apply here and can be set/removed
in-app — closing the web-only gap.

- ArtistOverride model + ArtistOverrideClient (GET/POST/DELETE on the backend);
  MusicRepository caches the map and exposes get/set/remove.
- ArtistViewModel resolves the pin up front; when pinned it enriches the artist
  page straight from the pinned Deezer id (albums/top-tracks/fans/image) instead
  of the name-guess. Picker: Deezer search candidates + a "paste Deezer link/id"
  route (reliable when /search/artist can't surface a low-profile same-name
  artist), plus clear-pin.
- ArtistDetailScreen: "⚙ Falscher Künstler? / Gepinnt" pill top-right of the hero,
  pinned Deezer picture overrides the hero image, ModalBottomSheet picker.
- ItunesClient.lookupArtist(id) (Deezer-backed) for the link-paste flow.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 18:28:29 +02:00
HoneyandClaude Opus 4.8 a5e5d414b4 docs: record ideas in the bottom Planned/Backlog, mention Musik-Match in README
Move the share-links / Wrapped / household-leaderboard / ListenBrainz ideas
into the existing "Planned / Backlog" section at the bottom of the CHANGELOG
(not a new top section), and add a short Musik-Match clause to the README
listening-stats feature.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 01:18:12 +02:00
HoneyandClaude Opus 4.8 e34a934460 docs(changelog): add Ideas / Backlog section (share-links, Wrapped, leaderboard, ListenBrainz)
The CHANGELOG is the home for feature ideas going forward. Records the
share-by-link deep-link idea (PWA on PC / Android app on phone via App Links +
assetlinks.json), plus the already-tracked Wrapped, household leaderboard, and
optional ListenBrainz relay.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 01:16:09 +02:00
HoneyandClaude Opus 4.8 19f82ad076 fix(android settings): move gap below Musik-Match, not above it
The Column already spaces children 12dp; the extra Spacer(8dp) between
"Meine Statistiken" and "Musik-Match" stacked to ~20dp, making that gap look
too big while Musik-Match↔Speichern stayed tight. Group the two stat buttons
together (12dp) and add the separating space (4dp) before the Save button.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 01:08:19 +02:00
HoneyandClaude Opus 4.8 c933847201 feat(android): Head-to-Head "Musik-Match" screen (parity with web)
Android CompareScreen mirroring the web feature: partner picker fed by
GET /scrobble/users, then GET /scrobble/compare?with= → a match-score ring
(Canvas arc), per-user totals, mirrored shared-artist bars, shared tracks,
and each side's unique top artists. Rows navigate to artist/album. Reuses the
one PlayLogClient HttpClient (fetchUsers/fetchCompare). Opened from Settings
"🎧 Musik-Match". Parity matrix updated (Android ✅).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 00:52:33 +02:00
HoneyandClaude Opus 4.8 cbedbba6fc feat(scrobble): Head-to-Head "Musik-Match" — compare two users' listening
Adds GET /scrobble/users (distinct users for the partner picker) and
GET /scrobble/compare?with= to the scrobble service. Taste match = cosine
of the two users' artist-play vectors (0..100); also returns shared artists
(mirrored bars), shared tracks, and each side's unique top artists. Reuses
the existing per-user play-log — no new data capture.

Web UI src/ui/compare.js (overlay from Settings "🎧 Musik-Match"): partner
picker fed by /scrobble/users, match-score ring, per-user totals, shared +
unique lists with clickable artist/album rows. Cosine + shared logic verified
against a hand computation on an in-memory DB. Android pending (parity: 🔜).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 00:46:29 +02:00
HoneyandClaude Opus 4.8 ba2306656e feat(artist pin): pin by Deezer link/ID when search can't surface the artist
Deezer's /search/artist is a ranked, incomplete fuzzy match — low-profile
same-name artists (e.g. Nana id 80239872) never appear in results. Add a
"paste Deezer link or ID" field to the pin picker that looks the artist up
directly via /artist/{id} (new deezerLookupArtist) and pins it. Same reliable
route as the importer direct link vs yt-dlp search.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 00:38:33 +02:00
HoneyandClaude Opus 4.8 5f251d555f fix(artist pin): esc() crashed on numeric Deezer id; move pin button to banner top-right
- esc() now coerces to string first (String(s ?? '')), so passing a number (e.g. the
  Deezer artist id in the pin picker) no longer throws 'replace is not a function'.
- The '⚙ Falscher Künstler?' button moved from under the fan count to the top-right
  of the artist banner (absolute, on the hero). SW cache -> ns-v75.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 00:16:14 +02:00
HoneyandClaude Opus 4.8 02960cf886 feat(artist): pin a local artist to a specific Deezer artist (same-name fix, shared)
Fixes same-name collisions where NovaSonic guessed the wrong Deezer artist (e.g.
'Nana' → a random DJ): fans, top songs, missing albums and the hero image were all
off. A '⚙ Falscher Künstler?' button on the artist page opens a picker (same-name
Deezer candidates with image + fan count); the chosen mapping is stored SERVER-SIDE
(shared across users, like the romaji overrides) in /data/deezer-artist-overrides.json.

Once pinned, the artist page short-circuits the name search to the pinned Deezer id
(drives albums/top-songs/fans) and overrides the hero image with the pinned artist's
Deezer picture (NovaSonic-side, so it works even for tag-merged same-name artists —
Navidrome can't disambiguate them without an MBID). New endpoints
GET/POST/DELETE /api/artist-overrides; api.js load/get/set/remove; loaded at startup.
SW cache -> ns-v74. Needs on-device runtime test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 21:38:42 +02:00
HoneyandClaude Opus 4.8 b788fedec3 fix(download): dedup missed re-downloads when the title contains ' - ' (KH triple/quadruple)
findExistingTrack split the filename at the first ' - ' assuming 'Artist - Title',
so a title with internal dashes ('Kingdom Hearts 2 - Dearly Beloved - Main Theme')
or a garbage/absent artist prefix ('01-01 - …') was mis-parsed → the duplicate went
undetected and got re-downloaded (3-4x). Now match the query title against BOTH the
full stem AND the part after the first ' - ', so titles with dashes and prefix-only
filenames are recognized. Normal 'Artist - Title' files still match; no false
positives; remix-vs-base distinction preserved. Unit-tested on the exact KH case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 17:06:14 +02:00
HoneyandClaude Opus 4.8 75dceba97b fix(editor): 'Deezer' autofill button is Deezer-only again (MusicBrainz has its own button)
Stufe B routed /api/meta/lookup through the combined resolver, so the editor's
'Deezer' button could silently return MusicBrainz data while the status said
'von Deezer'. The editor already has a dedicated 'MusicBrainz' button, so keep the
two explicit and honest: Deezer button = Deezer only. The combined
Deezer→MusicBrainz→clean resolver stays on the DOWNLOAD paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 16:53:25 +02:00
HoneyandClaude Opus 4.8 e61d57425e docs(CLAUDE): document the single-track metadata resolver (Deezer→MusicBrainz→clean fallback)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 01:51:54 +02:00
HoneyandClaude Opus 4.8 6d084a7b7a fix(download): stop wrong album/cover from same-titled tracks; add MusicBrainz fallback
Root cause: deezer pickTrackMatch fell back to a blind title-only match, grabbing a
same-titled song by a completely different artist (e.g. 'Memories' by Rab Noakes for
'☆NoAki☆') and applying its album/cover/year. The download's clean fallback existed
but was never reached because the lookup almost always returned *something*.

Stufe A — deezer.js: the title-only fallback now REQUIRES an artist correspondence
(equal, or one name contained in the other after normalization). No match → {} →
the existing clean fallback finally runs (album_artist = song artist, album =
'Singles', cover = source thumbnail, year/genre untouched). Test that encoded the old
blind behaviour replaced; NoAki + loose-match regression tests added.

Stufe B — musicbrainz.js: a rate-limited (~1/s, User-Agent) MusicBrainz recording
lookup with the SAME artist discipline + Cover Art Archive cover. trackmeta.js is the
single resolver (Deezer → MusicBrainz → clean fallback); the three single-track call
sites use it (album batch stays Deezer-only to avoid MB rate-limit slowdowns).

Unit-tested (17/17) + live-verified: NoAki→clean fallback, real track→Deezer, MB finds
real albums when Deezer misses. Backend-only; no frontend/Android change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 01:51:29 +02:00
HoneyandClaude Opus 4.8 16f76a4236 fix(web): show non-Japanese names as-is with Romaji on (e.g. ☆NoAki☆ kept its stars)
With 'show Romaji' enabled, dispArtist/dispArtistById/dispArtistParts/dispTitle
substituted the sort tag for the display name unconditionally. For non-Japanese
names the sort tag is just a sort key (leading symbols/articles stripped, so
'☆NoAki☆' → 'NoAki'), which wrongly replaced the real name. Guard the substitution
on the original being Japanese — mirroring what dispAlbumName already did — so
Romaji only applies to Japanese names and everything else shows unchanged.
SW cache -> ns-v73.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 00:48:22 +02:00
HoneyandClaude Opus 4.8 d195518dfb fix(android settings): remove open delay — seed theme instead of a loading gate
The previous flicker fix gated the whole settings form behind a 'loaded' spinner,
which read as a small lag when opening Settings (it waited for DataStore's first
emit even though it's already warm). Instead, expose the applied theme id
(NsColors.themeId, set in applyNsTheme) and seed the ViewModel's initial state with
it, so the theme picker no longer jumps from the default — no gate, no spinner, no
delay. Remaining text fields fill within a frame from the warm DataStore.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 00:40:38 +02:00
HoneyandClaude Opus 4.8 711a084686 fix(android): scrobble respects 1/3 & 2/3 again; no settings flicker on open
Scrobble timing: at onMediaItemTransition ctrl.duration is still TIME_UNSET (→0),
so getScrobbleDelayMs's third/two_thirds modes hit the 15s floor and scrobbled way
too early (both Navidrome + our play-log). Use the song's KNOWN duration
(song.duration), falling back to the player only if absent. Web was unaffected
(it already used the song's duration).

Settings flicker: the ViewModel started with default state (theme = Dark Ocean)
and rendered a frame before DataStore emitted the real values, so the theme picker
visibly jumped. Gate the form on a 'loaded' flag set after the first emit; show a
spinner until then.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 00:24:55 +02:00
HoneyandClaude Opus 4.8 0c7132a7f2 feat(scrobble stats): genre ranking (Top-Genres) — web + android
Play-log now stores each play's genre (from the song tags; web scrobbleLog +
android PlayLogClient capture song.genre). The stats endpoint returns topGenres
(GROUP BY lower(genre), case-insensitive, blanks ignored); web + android render a
Top-Genres section. Schema migrates via ALTER TABLE. Old plays have no genre
(fills going forward, like cover art). SW cache -> ns-v72.

Android compileDebugKotlin + web build green; genre grouping + null-ignore unit-tested.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 01:35:00 +02:00
HoneyandClaude Opus 4.8 249b693936 feat(android auto): tapping a song plays its whole list from that song
Browse songs now carry their context in the mediaId (songctx:<contextId>|<songId>).
A new onSetMediaItems override expands a single tapped song into its full list
(Favoriten / album / playlist) and returns it with the tapped index as the start
position, so playback continues through the rest instead of stopping after one song.
onAddMediaItems shares the same resolver; onGetItem resolves context songs too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 01:25:38 +02:00
HoneyandClaude Opus 4.8 d35fb01306 fix(android auto): tapping a song (e.g. in Favoriten) did nothing — re-attach stream URI
Android Auto strips a MediaItem's URI (localConfiguration) when a browse-tree item
crosses the process boundary, so onAddMediaItems received the tapped song without a
playable URI and the else branch passed it through unchanged → no playback. Rebuild
the item with the stream URI resolved from its mediaId.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-10 20:22:09 +02:00
HoneyandClaude Opus 4.8 1d98b273e7 fix(web player + stats modal): no auto-resume after user pause; stable stats modal
Player: opening the PWA no longer auto-plays when the user had paused. Pausing via
the media notification while backgrounded routes through togglePlay, which now sets
S._userPaused; _onForeground only auto-resumes an INVOLUNTARY background stop
(_wasPlayingBeforeHide && !_userPaused). playCurrent clears the flag on a new track.
Involuntary-stop/freeze recovery on foreground is preserved.

Stats modal: no more small→big flash when switching period/tab — the body keeps a
stable min-height and retains its current content until the new data arrives (only
the first open shows 'Lade…'); a per-request token drops out-of-order responses.
SW cache -> ns-v71.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-10 18:06:18 +02:00
HoneyandClaude Opus 4.8 3129333f9a feat(scrobble stats): navigator lower bound, clickable rows, android button to top
- Navigator can't step before logging began: the endpoint returns firstPlayedAt
  (MIN(played_at) over all the user's plays, unfiltered by window); web + android
  disable the back arrow once the shown year/month is at/before that first play.
- Top artists/tracks/albums are now clickable → open the artist / album page (web
  navigates and closes the overlay; android navigates via nav routes). Tracks open
  their album.
- Android: moved the 'Meine Statistiken' button to the top of Settings (was at the
  bottom near logout). SW cache -> ns-v70.

Android compileDebugKotlin + web build green; firstPlayedAt verified server-side.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-08 21:50:27 +02:00
HoneyandClaude Opus 4.8 86eb893f40 feat(scrobble): time-travel navigator (year/month) + fix stats cover art
Navigator (web + android): browse Alles / Jahr / Monat with a ‹ › stepper — see
top plays for a specific month or year (e.g. March 2024). Steps into the future
are disabled. Uses the existing /scrobble/stats endpoint with computed from/to +
bucket (month for year view, day for month view). All windows verified.

Cover art fix: the app resolves covers from the Subsonic **coverArt token**, not
the raw entity id — so stats covers (which used albumId/songId) never loaded.
Now the play-log stores each play's coverArt (web + android capture), the stats
endpoint returns it for top tracks/albums, and both clients render coverUrl(coverArt)
with an id fallback. Old plays lack coverArt (blank until re-listened); artist
images still use artistId (may need getArtistInfo2 later if blank). Schema migrates
existing DBs via ALTER TABLE. SW cache -> ns-v69.

Android compileDebugKotlin + web build green; server windows + cover storage unit-tested.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-08 13:11:34 +02:00
HoneyandClaude Opus 4.8 14c0dea7e4 fix(scrobble): 'Alles' (all-time) stats returned nothing — from=0 mapped to now
The client sends from=0 for the all-time range, but the string "0" is truthy, so it
was routed through _toEpochSec which maps 0 -> now, producing an empty window. Parse
'from' directly (0/absent/invalid -> all-time) instead. Affects web + Android.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-08 12:55:29 +02:00
HoneyandClaude Opus 4.8 561014c83f docs: v2.0 — document the scrobble / listening-stats system
- CHANGELOG: new [2.0] entry (own timestamped play-log service, stats view on
  web + android with cover art, remix-dedup fix, user-select UI fix, node 20->22);
  Platform Parity Matrix gains play-log / stats / stats-cover rows (+ Wrapped 🔜).
- README: Listening stats feature, scrobble/ in the project tree, SCROBBLE_URL
  env + scrobble container table, port 3710 + SSO-exclusion note in setup.
- CLAUDE.md: new 'Listening stats / scrobble system' section (isolation rationale,
  node:sqlite gotchas, ping.view multi-user auth, capture point, cover resolution,
  SSO deploy gotcha).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 19:33:46 +02:00
HoneyandClaude Opus 4.8 906b3b48cb ui(scrobble): label the totals tile 'Plays' instead of 'Wiedergaben' (web + android)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 19:29:55 +02:00
HoneyandClaude Opus 4.8 fff6f9e4da feat(scrobble): Android stats screen + cover art in stats (web + android)
Phase 4 (part B): Android statistics screen consuming GET /scrobble/stats —
tiles (plays + listening time), day/month/year play series, top artists/tracks/
albums, 24h listening clock, period tabs; opened from a Settings button
("Meine Statistiken"). New StatsViewModel + StatsScreen + ScrobbleModels;
PlayLogClient.fetchStats() (tolerant JSON decode, null on any failure);
repo.fetchScrobbleStats(); nav route + SettingsScreen(onOpenStats).

Cover art everywhere: top artists show a circular artist image, tracks/albums
a square cover — resolved client-side from Navidrome via artistId/albumId/songId
(no coverArt knowledge in the scrobble service). Endpoint now also returns
albumId for top tracks so track covers resolve reliably. Web stats list gets the
same thumbnails. SW cache -> ns-v67.

Android compileDebugKotlin + web build green. Needs on-device runtime test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 18:41:27 +02:00
HoneyandClaude Opus 4.8 cc1ec1653f fix(ui): stop accidental text-selection of UI chrome when dragging near controls
Dragging the mouse near a field edge (Global Suche, the importer, etc.) started
a text selection of the surrounding page titles/labels instead of feeling like an
app. Disable user-select on the #app shell; re-enable it for real text fields
(input/textarea/contenteditable) and copyable content (lyrics). Setup screen is
outside #app and unaffected. SW cache -> ns-v66.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 17:40:18 +02:00
HoneyandClaude Opus 4.8 26880016e9 feat(scrobble): web statistics view (Phase 3 UI)
Opens from Settings ("Meine Statistiken") as a self-contained modal overlay
(no router changes). Fetches GET /scrobble/stats and renders: totals tiles
(plays + listening time), a per-bucket play series, top artists/tracks/albums
with mini bars, and a 24h listening clock. Period tabs (all / this year /
last 30 days) switch from/to + bucket. Vanilla inline SVG-free bars, no chart
lib. Reuses .modal-overlay.open + design tokens; sends local tz offset for
day bucketing. Graceful empty/error/unconfigured states. SW cache -> ns-v65.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 17:17:14 +02:00
HoneyandClaude Opus 4.8 e782b75bd9 feat(scrobble): /scrobble/stats aggregation endpoint (Phase 3 backend)
Per-user listening stats via on-the-fly GROUP BY strftime (no rollup tables):
totals (plays + seconds), top artists/albums/tracks, a day/month/year time
series, and a 24h listening clock. Local-day bucketing via a tz offset.
Params exactly matched per query (node:sqlite throws on extra named params);
from defaults to all-time (avoiding the _toEpochSec(0)->now trap). Unit-verified.

Next: the web statistics view. Wrapped endpoint is Phase 4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 17:09:42 +02:00
HoneyandClaude Opus 4.8 eb55184118 fix(download): remix/live/acoustic/instrumental no longer skipped as duplicate of base track
findExistingTrack normalized titles by stripping ALL bracketed content, so
"Therapy (Remix)" collapsed to "Therapy" and was skipped because the base
track existed. Keep brackets that contain a version marker (remix/live/acoustic/
instrumental/vip/flip/edit/mix/…) so distinct recordings are recognized as new;
still strip noise brackets (feat. X, Official Video). Verified via Deezer that the
remix track carries the marker in its title. Unit-tested both directions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 17:06:00 +02:00
HoneyandClaude Opus 4.8 71190488ca feat(scrobble): own timestamped play-log service (stats/Wrapped foundation)
Phase 1+2 of a self-hosted, multi-user listening archive — the basis for
day/month/year stats and a yearly "Wrapped". Runs IN ADDITION to the existing
Navidrome/Last.fm scrobble; never replaces it.

Service (isolated, own container):
- scrobble/scrobble-server.js — node:sqlite play-log (own volume), routes
  POST /scrobble/plays (idempotent by uuid), GET /scrobble/history (archive),
  DELETE /scrobble/plays?user= (test cleanup), GET /scrobble/health.
  Multi-user auth via Navidrome ping.view (cached) -> user not spoofable.
- docker-compose: novasonic-scrobble service (node:22, port 3710) + volume;
  backend bumped node:20->22 (EOL); SCROBBLE_URL plumbing (entrypoint, .env.example).

Capture (both platforms, offline-safe queue, idempotent batch flush):
- Fires at the existing scrobbleMode counted-play moment — consistent with
  Last.fm, respects the user's setting (no separate 50%/4min rule).
- Web: src/player/scrobbleLog.js (localStorage queue) + subsonicAuthParams()
  in api.js + hooks in player.js + flush init in main.js; S.cfg.scrobbleUrl.
- Android: data/PlayLogClient.kt (filesDir queue, reused Ktor client) +
  repo.logPlay/flushPlayLog + PlayerController hook + NovaSonicApp flush +
  scrobbleUrl in PrefsStore/SettingsViewModel/SettingsScreen (with test button).

Plan + design decisions documented in docs/scrobble-plan.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-06 22:54:25 +02:00
HoneyandClaude Opus 4.8 e69fbaf75e fix(android): back focus lost after tabbing out — re-assert overlay back callbacks on resume
With NowPlaying (or an ABS player) open, backgrounding and resuming the app made the next back
press pop the NavHost invisibly to Home before dismissing the overlay. Returning from the
background re-registers the NavController's own OnBackPressedCallback on top of the dispatcher,
stealing back-priority from the overlays.

AppNavigation now bumps a resumeTick on Lifecycle.Event.ON_RESUME and keys every overlay
DisposableEffect (NowPlaying, ABS player, ABS item, Erkunden overlay) on resumeTick +
currentBackEntry, so each overlay re-adds its callback above the NavController after a resume or
navigation. Needs on-device verification.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-06 10:00:04 +02:00
HoneyandClaude Opus 4.8 17bb527e1d fix: download notification opened the wrong song (same-name album)
The finished-download notification resolved the album by name via search3, then fell back to
a same-named album by a DIFFERENT artist (or the first result) when the exact artist match
wasn't found — e.g. right after download, before Navidrome rescans. Many artists share an album
title ("I LIKE IT!"), so the notification navigated to a completely different song.

- Web (notify.js) + Android (AppNavigation): require the artist to match when known (fuzzy for
  multi-artist / album-artist drift); drop the name-only and first-result fallbacks. If nothing
  matches, show "wird evtl. gerade gescannt" instead of opening a wrong album.

The download itself was correct all along (verified: it grabbed UPSAHL's official "I LIKE IT!"
visualizer) — only the notification's navigation was wrong. SW ns-v63.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-01 02:30:53 +02:00
HoneyandClaude Opus 4.8 1e206e8df3 fix(web): 'Unknown Artist' download from artist page + rename itunes*→deezer* identifiers
Fix (the reported bug):
- Deezer's /artist/{id}/albums omits the artist object, so discography album cards had an
  empty artist name → the download modal fell back to the literal "Unknown Artist", which
  poisoned the yt-dlp search ("Unknown Artist <album>") and its artist/channel filter, failing
  with "Nicht eindeutig gefunden".
- deezerLookupArtistAlbums now backfills the known artist name (we're on that artist's page).
- openDlModal now defaults album cards to an ALBUM download (was always Track), so a one-click
  download no longer grabs an album as a single track named after the album.

Rename (requested cleanup, dependency-checked so nothing breaks):
- All frontend itunes* identifiers → deezer* (functions, the ItunesItem-shape field keys
  itunesData/itunesArtistId/itunesFanCount/itunesId, the itunes-album-detail route + DOM ids,
  the badge-itunes CSS class). The backend reads none of these fields, so the boundary is safe.
- Verified: build passes; route/DOM-id/CSS producer↔consumer all consistent; only the factual
  "Apple's iTunes /search 403" comments keep the historical name. SW ns-v62.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-01 00:31:09 +02:00
HoneyandClaude Opus 4.8 bc87a04da5 docs(changelog): note the 'Unknown Artist' download failure from artist-page album cards
Empty artist name (Deezer /artist/albums omits the artist object) + openDlModal defaulting to
type=track for album cards + downloads.js 'Unknown Artist' literal → yt-dlp searches
'Unknown Artist <album>' and fails. Documented as a Known Bug; no code change yet.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-01 00:19:23 +02:00
HoneyandClaude Opus 4.8 96861bea06 docs(web): unify the artist / album-artist separator hints in the editor
Both fields already accept ; and , (the backend normalizer splits on •·;,). The hints now
read uniformly — "mehrere mit ; oder , trennen" — and explain the actual difference: artist
is split into individual artists, album-artist stays one combined credit. SW ns-v61.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-01 00:10:04 +02:00
HoneyandClaude Opus 4.8 e4f030c98d fix: artist page resolved "Flay!" to the far more popular "K.FLAY"
The Deezer artist match required only that every query word appear in the candidate name, so
"Flay!" (query word: flay) matched "K.FLAY" (words: k, flay). Sorted by fan count, K.FLAY
(54,822 fans) buried the real "Flay!" (39 fans) — the page showed K.FLAY's fans + top tracks.

Now prefer an EXACT normalized-name match ("flay" == "flay", not "kflay"), falling back to the
loose match only when there's no exact one. Web (detail.js) + Android (ArtistViewModel).
Verified against Deezer: exact match selects the real Flay! (id 12242284, whose top tracks
are actually Flay!). SW ns-v60.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 23:53:42 +02:00
HoneyandClaude Opus 4.8 b3cf01dd3b fix: duplicate rows in artist "Top Songs" when a track exists twice in the library
Navidrome can hold the same track twice (downloaded as a single AND as an album track), so
getTopSongs returned two identical rows ("PIXELATED KISSES" x2). Collapse the top-songs list
by title+album for display (keeps the highest play count) on web + Android. SW ns-v59.

Note: this is a display fix — the underlying duplicate files remain a library-cleanup matter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 17:48:02 +02:00
HoneyandClaude Opus 4.8 fbee695aad fix: album shown 2-3x in "In Library" on the artist page
Deezer returns the same album as several variants (single/EP/album/regional/explicit), and
each variant matched the same Navidrome album, so one owned album rendered 2-3 times
("PIXELATED KISSES" x3).

- Web (detail.js): collapse matched entries to one per owned Navidrome album and one per
  not-owned title before classifying (also avoids duplicate track-count fetches).
- Android (categorizeAlbums): distinctBy(collectionId) missed variants with different ids;
  now also skip an owned album already classified.
SW ns-v58.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 17:41:33 +02:00
HoneyandClaude Opus 4.8 cc4d3b72d2 chore: bump SW to ns-v57 after reverting the artist-image fallback
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 17:21:31 +02:00
Honey e059c358b3 Revert "feat: Deezer artist photo fallback for local artists with no Navidrome image"
This reverts commit 569af968c5.
2026-07-31 17:20:45 +02:00
HoneyandClaude Opus 4.8 569af968c5 feat: Deezer artist photo fallback for local artists with no Navidrome image
Niche local artists (e.g. N!GHT) whose Navidrome metadata agents have no image showed a
blank hero. Now, when Navidrome has no artist image, the hero falls back to the matched
Deezer artist's photo (Navidrome image → Deezer photo → album cover), on web + Android.

- Web (detail.js): the Deezer-photo fallback previously ran only for non-local artists;
  now it runs whenever the Navidrome image is absent, local or not.
- Android: ArtistViewModel captures the matched Deezer artist's photo (deezerImage);
  ArtistDetailScreen uses it as the hero fallback.
SW ns-v56.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 17:07:53 +02:00
HoneyandClaude Opus 4.8 640e475c51 fix: owned albums wrongly shown as "Unvollständig 1/0" on artist page
Deezer's /artist/{id}/albums list omits nb_tracks, so the album total read as 0 and every
owned album (e.g. N!GHT's "Moonlight"/"Yume") was classified as incomplete "1 / 0 Tracks".

- Web (detail.js): resolve the real Deezer track count via the album endpoint for MATCHED
  (owned) albums only — a couple of calls, not the whole discography — and treat an unknown
  total as complete. Genuine partials still work when the true count is known.
- Android (categorizeAlbums): mark partial only when a known total exceeds what you own;
  unknown total counts as complete (never a false "1 / 0").
- CHANGELOG: documented the fix; corrected the Android lyrics known bug (auto-scroll follows
  playback but isn't smooth — it jumps rather than glides). SW ns-v55.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 17:05:14 +02:00
HoneyandClaude Opus 4.8 5528947a93 feat: fans on local Navidrome artists (android) + harmonize web fan layout
- Android local artist page (ArtistDetailScreen/ArtistViewModel) now resolves the Deezer
  artist (fan-sorted, so same-name collisions pick the popular one) and shows "<n> Fans"
  under the name — parity with the web local artist page.
- Also migrated ArtistViewModel's preview to the app-level PreviewController: the local
  artist page had its OWN uncontrollable MediaPlayer preview, which had the same
  "keeps playing after navigating away" bug. Now every preview uses the global bar.
- Web: the artist-hero fan line was laid out in a row next to the name (flex without
  column direction) and used an odd tinted color — now stacked cleanly under the name in
  a muted white. SW ns-v54.
- CHANGELOG: documented the above + added a Known Bug (Android synced-lyrics auto-scroll
  still doesn't follow playback).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 16:31:55 +02:00
HoneyandClaude Opus 4.8 9167bfaf0e feat(android): global 30s-preview control bar + artist fan count
Preview bar:
- 30s previews used to keep playing with no control once you left the album/artist/Explore
  screen they started on. Moved the preview player from ExploreViewModel to an app-level
  PreviewController, and added a global PreviewBar (above the mini player, on every screen)
  to pause/resume/stop it. Starting real library playback cancels the preview.

Artist fan count (parity with web):
- ItunesItem carries fanCount (Deezer nb_fan); shown on search artist cards and the artist
  page ("559.542 Fans" / "1,2 Mio. Fans"). Combined with the existing nb_fan sort this makes
  same-name collisions (5x "Joji") resolve to the right artist on Android too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 16:24:46 +02:00
HoneyandClaude Opus 4.8 c92ac3d719 fix(web): cleaner German fan-count format (559.542 instead of "559,5 Tsd.")
fmtCount now shows the full grouped number below a million (toLocaleString de-DE) and only
compacts millions ("1,2 Mio."). The old "Tsd." form read awkwardly on the artist hero. SW ns-v53.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 16:16:03 +02:00
HoneyandClaude Opus 4.8 065d2f7319 feat: disambiguate same-name artists by Deezer fan count + show fans
Deezer's artist search doesn't rank by popularity, so a name collision (5 artists named
"Joji") returned a niche one first (62 fans) instead of the real Joji (559k) — the artist
page then loaded the wrong discography and owned songs didn't show as downloaded.

- api.js: _dzArtist carries fanCount (nb_fan); artist search sorts by fanCount desc.
- search.js: artist cards show the fan count as subtitle; fan count passed to the artist page.
- detail.js: pick the most-popular name match (not the first); for local Navidrome artists
  with a real collision (>=2 same-name candidates), tie-break by SONG OVERLAP — prefer the
  Deezer candidate whose top tracks actually overlap the library (each artist has different
  songs, so this nails the right person). Costs a few calls only on a collision.
- Artist hero shows "<n> Fans" (immediately for global-search artists, after match for local).
- Android: DzArtist.nb_fan + /search/artist sorted by nb_fan so the right artist is first.
- Also: web global-search "unavailable" message now says Deezer, not Apple. SW ns-v52.

Verified live against Deezer: both fan-sort and overlap select the real Joji (id 5078097).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 16:11:45 +02:00
HoneyandClaude Opus 4.8 1e69831dd8 feat: move the whole metadata/search stack from iTunes to Deezer (1.3)
Apple's iTunes /search returns 403 from server/datacenter IPs, which had broken global
search, charts, album/artist/single downloads and the metadata-editor autofill in
production. Everything now sources metadata from Deezer (free, no key, more requests,
returns explicit versions + real artist images + durations). Web + Android share one
source, so an artist resolves to one consistent name everywhere. Deezer results are
mapped to the legacy "ItunesItem" shape, so the UI + download flow are unchanged.

Backend:
- New backend/lib/deezer.js: lookupTrackMeta, fetchAlbumTracks, searchAlbumTracks,
  fetchArtistAlbums (+ pure pickTrackMatch/mapAlbumTrack for tests).
- metadata.js drops the iTunes lookups; novasonic-server download paths (track, album,
  artist, playlist enrich, spotify artwork) + autofill now use Deezer.
- Artist download uses Deezer discography (real albums only), not the iTunes album search.
- Editor autofill endpoint /api/itunes/lookup -> /api/meta/lookup; removed the dead
  iTunes /search proxy and the Apple charts RSS proxy.
- backend/test/deezer.test.js: unit tests for numbering, mixed-artist album-artist
  stability, explicit flags, the Japanese-title match guard (npm test; RUN_LIVE=1 for live).

Web:
- api.js search/lookups already on Deezer; charts now use Deezer /chart. Artist cards
  show the real Deezer photo. Visible "iTunes"/"Apple Music" labels -> "Deezer"
  (search badge, charts badge, preview bar, editor button, artist heading). SW ns-v51.

Android:
- New DeezerModels.kt with Dz* models + mappers to ItunesItem/ItunesRssEntry.
- ItunesClient is Deezer-backed (search = tracks+albums+artists in parallel; album/artist
  lookups; /chart charts), same method signatures. Visible strings -> Deezer.

Docs: README, CLAUDE.md and CHANGELOG (1.3) updated; Platform Parity Matrix reflects the
shared Deezer source + Android non-local artist page.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 12:48:33 +02:00
HoneyandClaude Opus 4.8 a65613b5a1 fix(web): Deezer artist images + rename the search label
- Search artist cards now use the Deezer artist picture directly (Deezer artists carry
  a photo, unlike iTunes entities) instead of a null image + an extra album lookup;
  the lookup stays only as a fallback when no picture is present.
- Non-local (Deezer) artist pages: fetch the Deezer artist picture (/artist/{id}) for
  the hero photo, which was blank because getArtistImage only runs for Navidrome artists.
- Label "iTunes Künstler" → "Deezer Künstler".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 22:01:59 +02:00
HoneyandClaude Opus 4.8 ad433c4dbc fix(backend): Deezer proxy route crashed the whole server on Express 5
`app.get('/api/deezer/*', …)` — a bare "*" — throws "Missing parameter name" in
Express 5's path-to-regexp at startup, so the server never came up and EVERY endpoint
(abs-proxy, romaji-overrides, deezer, …) failed with a CORS/ERR_FAILED in the browser.
Use a RegExp route instead, which registers cleanly on both Express 4 and 5. Verified
against express 5.2.1: bare "*" crashes, the regex is OK.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 21:54:36 +02:00
HoneyandClaude Opus 4.8 68a9cdd7d1 feat(web): switch the Apple/Erkunden search to Deezer
Apple's iTunes /search returns 403 from server IPs, killing the Erkunden search. Deezer
is free, needs no key, and is actually better: it returns explicit versions, artist
images, track durations and 30s previews.

- Backend: /api/deezer/* proxy (CORS-safe); album download accepts a `tracks` array in
  the request body (Deezer albums send their tracks directly, pre-mapped).
- api.js: itunesSearch / itunesLookupAlbum / itunesLookupArtistSongs|Albums now hit
  Deezer and map results to the existing ItunesItem shape, so the UI + download flow are
  unchanged. Function names kept.
- downloads.js: album downloads fetch the Deezer album's tracks and send them in the body.

iTunes /lookup (by ID) and the charts RSS proxy stay. Known follow-ups: artist-type
download still calls iTunes /search server-side; the metadata-editor iTunes autofill;
and the Android client — all still on iTunes for now.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 20:54:10 +02:00
HoneyandClaude Opus 4.8 ccf704754a fix(web): proxy Apple charts (CORS) + clear message when Apple search is blocked
Confirmed via curl from a clean IP: Apple's iTunes /search returns 403 (blocked
server-side, likely datacenter-IP anti-scraping) while /lookup?id= still returns 200.
So the Erkunden Apple search fails through no fault of ours.

- Charts: the "most-played" RSS (rss.applemarketingtools.com) was fetched directly
  from the browser and hit CORS; proxy it via /api/itunes-charts/:kind.
- Error visibility: itunesSearch records the last outcome (HTTP status / network);
  the global-search view now shows "Apple-Suche gerade nicht verfügbar" with the
  reason (403 = Apple blocks the API, not you) instead of a blank "no results".
- iTunes proxy now forwards the upstream status code instead of always 200.

Deezer (free, no key, ~50 req/5s) is the planned search fallback; MusicBrainz is too
rate-limited (1/s) for interactive search.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 20:32:08 +02:00
HoneyandClaude Opus 4.8 9c8b4775ea fix: use the US iTunes store everywhere for consistent artist naming
Search (web api.js) was JP-first, the download lookups were JP-first, and the Android
client was already US — so the same artist resolved inconsistently: sometimes kanji,
sometimes katakana, sometimes romaji, depending on which path and which store matched.

Switch everything to the US store:
- api.js itunesSearch → country=us (one fetch, matches the Android client)
- metadata.js lookupItunesTrackMeta → US only (drops the JP fetch: consistent names +
  halves the download's iTunes calls, which also eases the rate limit)
- searchItunesAlbumTracks → country=us
- remove the JP-katakana guards in the album/artist download paths (redundant now, and
  they wrongly romanized genuine Japanese artists like 羽岡佳 → "Kei Haneoka")

Titles still come from the source, so a Japanese title the user picked stays Japanese;
only iTunes-derived fields (album_artist, genre, year, artwork) follow the US store.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-29 10:37:07 +02:00
HoneyandClaude Opus 4.8 d98978a6c7 feat(web): refresh the current view after deleting a song or playlist
Deletes left the removed item visible because the list loaders are cached (getPlaylists
~3 min): deletePlaylist navigated to a still-cached list, and deleteSong only reloaded
playlists. Add refreshCurrentView() — drops the API cache and re-runs the active nav
entry's loader (playlists, playlist/album/artist detail, starred, home, …). deleteSong
calls it after the delete+rescan delay; deletePlaylist invalidates getPlaylists before
navigating. Bump SW cache to ns-v46.

Also record the post-1.2 work in the 1.2 changelog (importer Enter, search single-song
+ radio, NowPlaying order, official-audio artist-metadata match, JP-katakana album
artist fix, year back-fill, delete refresh).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-26 23:27:29 +02:00
HoneyandClaude Opus 4.8 966b318d9e fix(backend): back-fill the release year from iTunes on single-track downloads
embedMetadata already writes date/track/totaltracks/disc, but the single-track path's
"album already known" branch back-filled genre/total/disc/duration/track# from iTunes
and omitted the year — so a source track without a year got no `date` tag written.
Add !meta.year to the fetch trigger and merge genreMeta.year, so the release year is
set at download time like the other fields.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-26 23:15:41 +02:00
HoneyandClaude Opus 4.8 72b612f5ff fix(backend): don't tag Western artists with the JP store's katakana album-artist
The iTunes lookup is JP-first (for correct Japanese titles/artwork), but the Japanese
store returns katakana-localized names for Western artists — so DJ Snake's single got
album_artist / folder "DJスネイク • アルーナジョージ" while the title/artist stayed English.

- lookupItunesTrackMeta: take the NAMES (album, album-artist, track, artist) from the US
  store when the search isn't Japanese; keep JP names for actual Japanese songs.
- album & artist download paths: if iTunes' collectionArtistName is Japanese but the
  request artist isn't, keep the request's English name for the tag and folder.

Already-downloaded files aren't rewritten — re-download or fix via the editor.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-26 22:54:15 +02:00
Honey 8cd3e9ac23 Revert "fix(backend): cache the iTunes proxy to avoid Apple rate-limiting the search"
This reverts commit a3c8b1afd1.
2026-07-26 22:42:46 +02:00
HoneyandClaude Opus 4.8 a3c8b1afd1 fix(backend): cache the iTunes proxy to avoid Apple rate-limiting the search
The web Apple-Music search proxies through /api/itunes (browsers can't call
itunes.apple.com — no CORS). The proxy forwarded every request uncached, so heavy
download activity (each download does several album/track lookups) plus client
searches blew past Apple's ~20 req/min/IP limit and the search started returning
nothing. Add a 30-min in-memory cache keyed by the target URL; only genuine 200
responses (with the resultCount signature) are cached, never throttle/error pages.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-26 22:39:21 +02:00
HoneyandClaude Opus 4.8 04a29b684d fix(backend): match official audio by yt-dlp artist metadata, not just channel name
The strict cascade steps required the YouTube channel name to contain the artist, so
official uploads on label channels (BANGTANTV, HYBE LABELS, …) were rejected and the
no-channel fallback grabbed a fan reupload instead (observed: BTS "Pied Piper").

Add yt-dlp's music `artist` field as an OR alternative to the channel check in the
strict steps (two --match-filter args = OR). A metadata dump of "BTS Pied Piper"
confirmed only the official upload has artist=BTS (fan/live/lyric reuploads: NA), and
it's the #1 result — so it now passes strict step 2. channel_is_verified was rejected
as a signal: lyric videos and fan MVs also run on verified channels.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-26 21:19:09 +02:00
HoneyandClaude Opus 4.8 f097dddc64 feat(web): Enter in the importer field starts the import
Pressing Enter in the importer link input now triggers resolveImporterLink()
(same as the Importieren button). Bump SW cache to ns-v45.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-25 23:11:44 +02:00
HoneyandClaude Opus 4.8 1e242796fe feat(web+android): search play queues only the tapped song (radio fills the rest)
Playing a song from search results queued the whole result list. Now it plays only
the clicked song; Radio mode, if on, fills the rest — closer to Spotify. Both
platforms already trigger a radio top-up on the first track (web playQueue →
fillRadioQueue; Android onMediaItemTransition → checkRadioRefill), so no extra wiring
is needed. Album/playlist play still queues the full list. Bump SW cache to ns-v44.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-25 22:00:58 +02:00
HoneyandClaude Opus 4.8 14fd5119f2 fix(android): NowPlaying shows album above artists, matching the web player
Reordered the NowPlaying track info to title → album → artists (was title → artists
→ album), so the Android layout matches the PC/web player.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-25 14:09:27 +02:00
HoneyandClaude Opus 4.8 f21174bd2c docs: changelog 1.2 + CLAUDE.md notes (web router, album_artist derivation)
CHANGELOG: 1.2 entry for the post-1.1 work — web forward/back navigation, album
detail album-artist, metadata autofill "&" normalization, Android Erkunden back
re-assert + directional tab transitions, and the backend mixed-artist / album_artist
download fixes.

CLAUDE.md: album/artist download album_artist comes from iTunes collectionArtistName
(not the request/lead-single artist); client-side History router applies nsIdx on
popstate for both directions and must never pushState in the back path.

README left unchanged — the post-1.1 changes are fixes/polish, not new features.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-25 10:29:40 +02:00
HoneyandClaude Opus 4.8 b1a32f5130 feat(android): directional tab transitions in the bottom nav
Tab switches slid in a fixed direction (and sometimes flipped between push/pop feel,
so the direction felt random). Now the slide follows the target tab's position in the
bottom bar: tapping a tab to the right slides in from the right, a tab to the left
slides in from the left — applied across all four enter/exit/popEnter/popExit
transitions so it's consistent regardless of how Compose classifies the move. Detail
screen push/pop transitions are unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-25 10:24:42 +02:00
HoneyandClaude Opus 4.8 179e0eb902 fix(web): center NowPlaying star vertically with the whole track-info block
The favorite star lived inside .np-title-row, so it sat pinned to the title line
rather than centered against the title + album + artist block. Move it out to be a
flex sibling of .np-text inside .np-info (align-items:center), so it centers on the
full text block. Bump SW cache to ns-v43.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-25 01:42:09 +02:00
HoneyandClaude Opus 4.8 e78ce43019 fix(backend): artist download also derives album_artist from iTunes album artist
Apply the same collectionArtistName derivation to the per-album loop of the artist
download, so a collaboration/soundtrack in an artist's discography is not tagged with
the searched artist. Each track still gets its own iTunes artistName; album_artist
stays the iTunes album-level artist (consistent, no Navidrome splitting).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-25 00:07:40 +02:00
HoneyandClaude Opus 4.8 48a13fbccb fix(backend): album_artist from iTunes collectionArtistName, not the lead single's artist
The album download tagged album_artist with the request's `artist`, which can be a
single track's performer — the lead single "TAKEDOWN" is by TWICE, so a whole
KPop-Demon-Hunters soundtrack got album_artist=TWICE on every track. Derive the album
artist from the iTunes tracks' collectionArtistName (the album-level artist, identical
across the album) and fall back to the request artist only if iTunes omits it. This is
the documented intent (mainArtist = collectionArtistName when available) and keeps
album_artist consistent so Navidrome doesn't split the album.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-25 00:02:35 +02:00
HoneyandClaude Opus 4.8 4d44a476a5 docs: note per-track artist search for mixed-artist album downloads
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 23:42:50 +02:00
HoneyandClaude Opus 4.8 bdf2867bdd fix(backend): album downloads search by per-track artist, not the album artist
downloadAlbumTracks passed each track's artistName as `artist` but no `rawArtist`,
so in ytdlp.js the YTM/YouTube search query and the channel filter used
`mainArtist = albumArtist || artist` — always the album-artist blob. On mixed-artist
soundtracks that matched nothing: e.g. TWICE's "Strategy" and MeloMance's "Love,
Maybe" were searched as "KPop Demon Hunters Cast, HUNTR/X & Saja Boys <title>" with
`channel ~= KPop`, and failed with "Nicht eindeutig gefunden".

Pass rawArtist = track.artistName so the search + channel filter use the actual
performer ("TWICE Strategy", channel ~= TWICE). The album_artist tag still comes from
`albumArtist`, so album grouping is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 23:42:20 +02:00
HoneyandClaude Opus 4.8 e8b82c177f fix(web): album detail shows the album artist, not the first track's artist
loadAlbumDetail overwrote the header artist with parseArtists(songs[0]) — the first
track's artist. On soundtracks/compilations that is wrong (e.g. "KPop Demon Hunters"
showed "TWICE" from track 1 "TAKEDOWN"). Use r.album (the getAlbum response, which
carries the album's own album-artist tags in .artists / .artist) so it matches the
Android app: "KPop Demon Hunters Cast • HUNTR/X • Saja Boys".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 23:28:39 +02:00
HoneyandClaude Opus 4.8 ea98d81146 chore(web): bump service-worker cache to ns-v42
Forces installed PWAs to pull the new build (metadata "&" split + forward
navigation fixes) instead of serving stale cached assets.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 22:54:36 +02:00
HoneyandClaude Opus 4.8 79100c5321 fix(web): browser/mouse Forward navigation now works (not only Back)
The popstate listener always called _navGoBack(), but both Back and Forward fire
popstate — so Forward was treated as Back and never restored the page you came from.
_navGoBack also pushState()'d on every back, which wiped the browser's forward stack
entirely.

Route all history through the History API: navigate() pushes a state (nsIdx) only on
genuine new navigation; popstate now applies whichever entry the browser moved to via
_navOnPopState(state.nsIdx), covering Back AND Forward with no pushState in the
handler. In-app back buttons / Backspace go through history.back() so there's a single
path and the browser stack stays in sync. NowPlaying overlays still close first on a
back press.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 22:49:40 +02:00
HoneyandClaude Opus 4.8 3f57e2ae26 fix(web): metadata autofill normalizes trailing " & " in multi-artist lists
Apple Music / MusicBrainz render multi-artist credits as "A, B, C & D" — the last
artist is joined with " & " instead of the list separator, so it stayed glued to the
previous one (e.g. "REI AMI & KPop Demon Hunters Cast" became a single artist that
Navidrome's ";" split could not break apart).

_fmtArtists now also rewrites " & " to the list separator, but only when the string
is already a list (contains ; , • ·), so real band names like "Simon & Garfunkel"
stay intact. The iTunes and MusicBrainz autofill results are now run through
_fmtArtists too (previously set raw), so the artist field comes out ";"-separated
and matches the Navidrome Tags.artist.Split config.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 22:41:53 +02:00
HoneyandClaude Opus 4.8 315b8aaacc fix(android): re-assert Erkunden overlay back priority on every navigation
The root-level overlay back callback was keyed only on the overlay state, so after an
album drill-down or tab switch the NavHost could re-register its own back callback
above ours and regain priority — one back press then popped Erkunden → Home instead
of dismissing the overlay ("sometimes" bug). Key the DisposableEffect on
currentBackEntry as well, so the callback is removed and re-added (bumped to the top
of the OnBackPressedDispatcher) after every navigation while an overlay is open.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 19:56:10 +02:00
HoneyandClaude Opus 4.8 c5649ac22f docs: record 1.1 hard-won knowledge in CLAUDE.md; refresh README
CLAUDE.md:
- Download pipeline: leading aesthetic characters in artist names must be trimmed
  before the iTunes lookup (a missed match cascades into a wrong-duration YouTube
  grab), and an album tag is always written (defaulting to Singles) so Navidrome
  and the metadata editor agree.
- New Android section covering the traps this release cost the most time on: a
  BackHandler inside a NavHost destination loses back priority (overlay back must
  be registered at the app root), overlay state must live in the ViewModel rather
  than remember/rememberSaveable, bottomBar and ModalBottomSheet inset handling,
  reusing the Ktor client, global optimistic StarState, and iTunes artists having
  no artwork.

README: offline downloads also cover single songs and work without a server
connection; StarState added to the data/ listing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 18:15:21 +02:00
HoneyandClaude Opus 4.8 a80ac3deb0 docs: changelog for 1.1
Polish release covering Android navigation and offline resilience, download
accuracy for stylised artist names, and the lrclib lyrics-throttling fix.

Also updates the parity matrix (single-song offline downloads, player bar on all
screens) and corrects the Windows media-tile known bug — the two-element gapless
handoff was kept for skip speed, not reverted as the entry claimed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 18:13:36 +02:00
HoneyandClaude Opus 4.8 4503bbe54e fix(android): uniform icon-only action buttons in playlist detail
Since the offline-download button was added, four buttons shared one row while Play
and Shuffle also carried text labels — the labels got squeezed out and the buttons
looked compressed. All four are now equal-width and icon-only (play, shuffle, edit,
download); Play stays filled as the primary action, the rest tint accent when
active/done. Icons carry contentDescriptions for accessibility.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 17:21:41 +02:00
HoneyandClaude Opus 4.8 9270d31608 fix(android): playbar clears system nav bar on detail screens; Erkunden all-albums survives drill-down
- On detail screens (album/artist/playlist) the MiniPlayer was the bottom-most bar
  with no NavigationBar to absorb the system-navigation inset, so it sat behind the
  phone's gesture/nav bar. Pad the bar with navigationBarsPadding() when the tab bar
  is absent.
- The Erkunden (iTunes) artist "show all albums" view used local remember state, so
  drilling into an album and back reset it to the main artist view. Hoist the open
  section into ExploreViewModel.artistAllAlbums so it survives both nav-route and
  overlay round-trips, and wire its back into the root overlay-back handler.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 16:21:01 +02:00
HoneyandClaude Opus 4.8 e50b4dc93c fix(android): Erkunden (Apple) overlay back no longer jumps to Home
The iTunes artist / album detail in the Erkunden tab are in-screen overlays on the
NavHost "erkunden" destination, not real routes. Their BackHandler lost back priority
to the NavHost, so one back press popped Erkunden → Home instead of dismissing the
overlay (artist→search, album→artist).

Handle the overlay's back at the app root via OnBackPressedCallback (the same proven
mechanism as the NowPlaying overlay): ExploreScreen reports its current overlay close
action up through onOverlayBackChange, and AppNavigation registers a root-level back
callback for it. Also covers an album opened straight from search (no artist), which
had no back handling at all. Removes the temporary nav-debug strip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 11:11:52 +02:00
HoneyandClaude Opus 4.8 b07212fdce chore(android): TEMP nav back-stack debug strip (diagnosing back→home bug)
Shows the live NavController back stack at the top of the screen so we can see
whether detail screens are being pushed correctly or the back button isn't being
handled. To be reverted once the back-navigation issue is diagnosed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 10:10:50 +02:00
HoneyandClaude Opus 4.8 419f80568c feat(android): playbar everywhere, song-search context menu, offline tab loads offline
- MiniPlayer now shows on every screen (album/artist/playlist detail), not just
  top-level tabs; the tab bar stays top-level-only.
- Local library song search results get the 3-dot context menu (add to playlist,
  favorite, queue, download, …) via onShowContextMenu.
- Offline tab is fed by the local Room DB and no longer waits on the online library:
  it stays usable while the library is loading or the server is unreachable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 09:21:02 +02:00
HoneyandClaude Opus 4.8 03046cd631 fix(android): show artist images in Apple-Music search (Erkunden)
iTunes artist entities carry no artwork, so search results rendered as bare grey
circles. Mirror the web PWA: after showing results, fetch one album per artist and
borrow its cover (entity=album, limit=1), applied only if the user is still viewing
the same artist set. Also give ArtistCard a Person-icon fallback instead of an empty
grey dot, and fall back to the artist id for Subsonic (library) artist covers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-09 10:04:48 +02:00
HoneyandClaude Opus 4.8 03bc736725 fix(android): iTunes download sheet opens fully so the download button is reachable
The "was herunterladen" sheet (track/album/artist + Herunterladen) opened only
half-expanded, hiding the download button behind the system nav bar until you
dragged it up. skipPartiallyExpanded=true opens it fully (button already clears
the nav bar via navigationBarsPadding).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 00:46:44 +02:00
HoneyandClaude Opus 4.8 abb4047966 fix(android): full-height song context sheet + styled playlist-picker input
- Song context sheet now opens fully expanded (skipPartiallyExpanded) so the
  "Herunterladen" option at the bottom is reachable without an extra drag-up.
- The "new playlist" field in the playlist picker now matches the app's search
  bars: rounded 12dp, filled surface, leading icon, NsAccent/NsOnSurface3 borders.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 00:42:31 +02:00
HoneyandClaude Opus 4.8 17a28b3011 feat(playlists): show playlist cover in the "add to playlist" picker (web + Android)
The picker listed playlists with a generic list icon; now each row shows the
playlist's cover art (falling back to the icon when there's none), so you can
tell them apart at a glance when adding a song.

- web (modals.js): 34px cover thumbnail per row.
- android (PlaylistPickerSheet): 40dp AsyncImage cover, coverUrl passed from AppNavigation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-05 23:21:18 +02:00
HoneyandClaude Opus 4.8 1775ec5b9b fix(search): trim leading aesthetic punctuation in artist lookups
Artists like ".diedlonely" (leading dot, †, ✝, _ …) weren't surfaced by iTunes,
so the download's metadata lookup fell through to a titleOnly match — grabbing a
same-titled track by another artist (e.g. the "In the Bleak Midwinter" Christmas
carol: Holiday genre, 176s single) and steering the YouTube search to the wrong
(slowed) version.

- backend/metadata.js: strip leading non-alphanumeric from the search artist and
  the first-word comparison so the real artist matches (and the right album/genre/
  duration are used).
- android ExploreViewModel: strip leading symbols from the search term so the
  Explore tab finds these artists.

Keeps the original name for display/storage — only the search/compare is trimmed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 22:34:44 +02:00
HoneyandClaude Opus 4.8 d50e22b62d perf: stop per-cover HttpClient churn (Android) + scroll-arrow reflow (web)
Android: MusicRepository.coverArtUrl/streamUrl built a fresh SubsonicClient
per call — each spins up (and never closes) a Ktor HttpClient. That ran for
every cover on every recomposition, causing heavy GC/alloc churn (and a leak)
that showed up as scroll/tab lag. Reuse the cached ClientHolder client for URL
building instead.

Web: the home scroll-row arrows called getBoundingClientRect on every scroll
event (layout thrashing). Split it: only toggle arrow visibility on scroll
(rAF-throttled); do the getBoundingClientRect vertical-centering only on
resize/content change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 23:02:11 +02:00
HoneyandClaude Opus 4.8 ef25ac3100 fix(android): use the heart icon for favorite in Now Playing (was a star)
Every other favorite toggle uses Favorite/FavoriteBorder (heart); Now Playing
was the odd one out with Star/StarBorder. Make it a heart everywhere.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 22:53:56 +02:00
HoneyandClaude Opus 4.8 ec4d5d0572 fix(android): instant star/favorite feedback everywhere
Tapping the star only fired the API and never updated any UI state, so the
icon didn't change (no feedback). Add a global reactive StarState with
optimistic overrides: the star flips instantly across every screen showing
that song (SongRow lists, Now Playing, context sheet), the API runs in the
background, and the override reverts if the call fails.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 21:30:17 +02:00
HoneyandClaude Opus 4.8 8741c2fb88 fix(android): back from album returns to the "all albums" view, not the artist page
The artist screen's "show all albums" overlay state was plain remember(), so
navigating into an album and pressing back reset it — dumping you on the
collapsed artist page instead of the list you came from. Persist which section
is open via rememberSaveable (a String? title) so it survives the round-trip,
and re-derive the overlay entries from the (surviving) categorized albums.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 21:35:01 +02:00
HoneyandClaude Opus 4.8 445a7bf583 fix(backend): consistent album for no-album downloads + tolerant editor resolve
Two-part fix for "[Unknown Album]" vs "Singles" mismatch that broke the
metadata editor (File not found):

- Download: always write an album tag, defaulting to "Singles" so it matches
  the on-disk folder (album || 'Singles'). No-album tracks no longer show as
  "[Unknown Album]" while living in a "Singles" folder. (Future downloads.)
- Editor resolve: Subsonic getSong returns a *virtual* tag-built path (e.g.
  "[Unknown Album]/Title.mp3" with raw "|"), not the physical file ("Singles/
  Artist - Title_YTPMV.mp3"). Add findExistingTrack as a final fallback, and
  make its normalizer map the sanitized chars (/ \ : * ? " < > | and _) to a
  space so a title tag matches the sanitized filename. (Fixes existing tracks.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 20:33:20 +02:00
HoneyandClaude Opus 4.8 63a7260c94 fix(lyrics): stop hammering lrclib (caused IP throttling → no lyrics)
Rapid skips + lyrics prefetch fired the full lrclib cascade many times over,
so lrclib throttled the IP and requests timed out (canceled) on both web and
Android. Reduce the request volume:

- Web: de-dupe concurrent fetches per song (prefetch + tab-open now share one
  cascade); bump the per-request timeout 6s → 8s.
- Android: per-song Mutex so prefetch + on-open load don't both run the cascade;
  send a proper User-Agent (lrclib asks for one and treats it better); debounce
  the prefetch (1.5s, cancelled on the next skip) instead of firing immediately
  on every track change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 21:12:01 +02:00
HoneyandClaude Opus 4.8 ddb9418603 feat(web): send a "now playing" scrobble at track start
Ping Navidrome with scrobble?submission=false when a track starts so
getNowPlaying reflects it instantly (feeds e.g. a Discord rich-presence
plugin / other clients' Now Playing). Independent of the existing delayed
"played" scrobble used for play counts and Last.fm.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 15:58:30 +02:00
HoneyandClaude Opus 4.8 7f7d7740e4 docs: plan artist following + new-release/concert notifications
Follow artists and get notified on new releases (iTunes/MusicBrainz/Last.fm)
and nearby concerts (reusing the existing Ticketmaster integration), surfaced
in the in-app notification bell, with a download action from the alert.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 15:47:01 +02:00
HoneyandClaude Opus 4.8 17a38e9c64 docs: plan Discover Mixes (auto-download, temporary) in backlog
Themed/random discovery mixes (Rock/Charts/Random) that auto-download via the
yt-dlp backend, auto-delete after a configurable retention time, with an option
to keep tracks in the permanent library. Captures sources, retention, keep flow,
and open questions for later implementation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 15:42:54 +02:00
HoneyandClaude Opus 4.8 7cba39dfaf fix(web): NowPlaying showed a stale cover after rapid skips
The NP overlay only refreshed its cover while open, so skipping with it closed
left the <img> on the last-opened song; reopening briefly showed that old cover
until the current one loaded. Now the NP cover element is kept pointed at the
current song even while closed (loads in the background), so opening it always
shows the right artwork.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 11:32:19 +02:00
HoneyandClaude Opus 4.8 46e252b494 perf(web): instant skips via gapless handoff to a pre-buffered element
Reintroduce the two-element handoff, this time as a skip-speed optimization
(not for the OS tile). A second <audio> element pre-buffers the next track;
on a forward skip playCurrent hands playback over to it instead of reloading
the source, so playback starts immediately instead of ~1s. Covers are
pre-warmed in parallel so the new artwork is ready too.

Listeners are bound to both elements once (handlers guard with el !== S.audio).
Safety: handoff only when the standby is buffered (readyState >= 2); otherwise
falls back to the unchanged source-swap path, and a failed handoff play()
recovers with a fresh source load. Web-only; the native bridge path is untouched.

Note: this does not change the OS media-tile flicker (a separate, MSE-only fix).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 11:17:16 +02:00
Honey be73f717ac Revert "experiment(web): drop separate preload <audio> element (single-element like Navidrome)"
This reverts commit f252586398.
2026-06-26 21:50:06 +02:00
Honey e1ec1f3660 Revert "polish(web): warm next track via fetch to shrink media-tile gap"
This reverts commit 6131eea9ec.
2026-06-26 21:00:44 +02:00
HoneyandClaude Opus 4.8 6131eea9ec polish(web): warm next track via fetch to shrink media-tile gap
Removing the second <audio> element fixed most of the OS media-tile flicker,
but skips now load the next track fresh → a brief gap where Windows shows the
generic site entry. Prefetch the next track's first ~4MB with fetch() (not a
media element, so no Chromium session flip) to warm the HTTP cache + TLS
connection; the src-swap then starts faster and the gap shrinks. Abortable on
queue change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 20:50:44 +02:00
HoneyandClaude Opus 4.8 f252586398 experiment(web): drop separate preload <audio> element (single-element like Navidrome)
Navidrome's player (react-jinke fork) uses one persistent <audio> element and
does not flicker the OS media tile, so the source-swap itself isn't the cause.
Our one structural difference was a second buffering <audio> (_preAudio) for
preload. A second media element seems to make Chromium hand the OS media
session over on skip → Windows tile flicker. This drops it; we rely on the main
element's preload="auto" + browser HTTP cache. Cover art is still prewarmed.

Trade-off: next-track start may be marginally slower. Easy to revert if it
doesn't fix the flicker.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 18:01:38 +02:00
HoneyandClaude Opus 4.8 bed007258a docs: record desktop media-tile flicker as a known limitation
The two-element gapless handoff was reverted (switching <audio> elements
still ends/starts the OS media session, so Windows rebuilds the tile).
Correct the changelog claim and add a Known Bugs entry; the real fix is MSE.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 17:46:35 +02:00
Honey 420c84d191 Revert "feat(web): gapless audio handoff to fix desktop media-tile flicker"
This reverts commit 98d7c84269.
2026-06-26 17:45:40 +02:00
HoneyandClaude Opus 4.8 98d7c84269 feat(web): gapless audio handoff to fix desktop media-tile flicker
Add a second <audio> element; S.audio always points at the active one and
listeners are bound to both once (handlers guard with el !== S.audio).
preloadNext buffers the next track into the standby element, and playCurrent
hands playback over to it on skip instead of swapping the source — so the
active element never empties and Windows keeps the media tile (also makes
forward skips instant/gapless).

Safety: handoff only when the standby is buffered (readyState >= 2); falls
back to the unchanged source-swap path otherwise, if there's no second
element, or if handoff play() rejects. Web-only — the native bridge path is
untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 17:13:22 +02:00
HoneyandClaude Opus 4.8 687650518e perf(web): defer lyrics prefetch so it doesn't slow playback start
prefetchLyrics now fires ~1.5s after a song change instead of immediately,
so the lrclib requests no longer compete with audio-stream buffering when a
new track starts. Timer is cleared on rapid song changes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 16:56:11 +02:00
HoneyandClaude Opus 4.8 d65fbcd11e feat(web): scroll-row arrows + stable desktop media tile
Home rows get hover left/right arrows that only show for the scrollable
direction (enhanceScrollRow + initScrollRows, called from startApp);
visibility recomputed on scroll/resize/content-load.

Fix the OS media tile flicker when skipping on desktop PWA: mutate the
existing MediaMetadata in place instead of assigning a new one each track
(the replacement made Windows tear down and rebuild the tile). Action
handlers are now set once.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 14:43:43 +02:00
HoneyandClaude Opus 4.8 7498e45b16 feat(web): desktop keyboard shortcuts
Space = play/pause, ←/→ = seek 5s, Shift+←/→ = prev/next, ↑/↓ = volume.
Handler lives in player.js (where _pos/_dur/seekToMs are in scope), wired
from startApp via initKeyboardShortcuts(). Ignored while typing in inputs,
and yields Space to focused buttons/links so it never double-fires.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 14:21:36 +02:00
HoneyandClaude Opus 4.8 ffa4fb35ea chore(pwa): desktop install polish for manifest
Add PNG icons (192/512) for a crisp taskbar/Start-menu icon, drop the
portrait orientation lock so the window resizes freely on desktop, and add
a stable app id. Installs as a standalone desktop window.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 13:59:58 +02:00
HoneyandClaude Opus 4.8 58dacbabc3 fix(web): refresh Home on explicit Home click
loadHomeData now takes a force flag; navigating to Home via a click
(not back/forward) invalidates the home rows' API cache so they re-fetch
and the random row re-randomizes — matching the Android re-tap behavior.

CHANGELOG: note the Home-refresh fix under 1.0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 08:19:38 +02:00
HoneyandClaude Opus 4.8 211b8ec6c2 feat(lyrics): prefetch on play + smooth measured-position autoscroll
Warm the lrclib cache the moment a track starts (Android PlayerController
onMediaItemTransition; web onNpSongChange) so opening the Lyrics tab is
instant. Extract a DOM-free fetch helper on web for reuse.

Rewrite Android lyrics autoscroll to center on the active line's measured
position in a LazyColumn instead of a fixed line-height estimate — removes
stutter and the downward drift on wrapped lines; active line sits at a
~40%-from-top reading anchor.

CHANGELOG: fold into 1.0; drop the now-fixed lyrics known-issue note.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 00:59:51 +02:00
HoneyandClaude Opus 4.8 7a5197b776 docs: mark 1.0 — first stable release
Promote the 0.10 changelog entry to 1.0; feature-complete across web and
Android. Android versionName was already 1.0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 17:02:51 +02:00
HoneyandClaude Opus 4.8 73fcfae30f feat(android): offline downloads — albums, playlists, detail screen & playback
Download albums/playlists to private device storage (Room + WorkManager,
HttpURLConnection streaming). New Offline tab lists groups with progress;
tapping a group opens a detail screen (cover-art rows, play/shuffle, per-song
delete from device). Downloaded tracks play from disk on every screen.
Album/playlist cards show a downloaded badge; download button resumes missing
songs. Song storage is dedup'd by ID and reference-counted on delete.

Fixes: Android 15 download crash (dropped banned DATA_SYNC foreground service);
offline detail flash-back (initial empty state no longer mistaken for deleted).

Docs: CHANGELOG 0.10 + parity matrix; condensed README Features.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 10:06:43 +02:00
HoneyandClaude Sonnet 4.6 5a2ab54bbb docs: merge 0.10 back into 0.9, single release entry
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 22:45:01 +02:00
HoneyandClaude Sonnet 4.6 ac8ce6b7d8 docs: add 0.10 changelog entry
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 22:24:59 +02:00
HoneyandClaude Sonnet 4.6 e246382caf fix(ui): star button sits right next to track info, not far right
- Sidebar: replace ♫ emoji with new equalizer SVG icon (icon.svg)
- Mobile header: remove duplicate logo+name next to search bar

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 20:41:15 +02:00
HoneyandClaude Sonnet 4.6 c802ef99d7 fix(ui): revert vite base /app/ — broke CSS/JS asset loading
Keep nginx /app/ alias for favicon resolution only.
CSS/JS stay at root-relative paths via location /.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 20:35:12 +02:00
HoneyandClaude Sonnet 4.6 e326ee6350 feat(ui): new equalizer logo, favicon link, fix favicon path
- icon.svg / icon-192/512.png: blue→purple equalizer gradient design
- nginx.conf: add /app/ alias so reverse-proxy prefix resolves assets
- vite.config.js: base /app/ + %BASE_URL% in favicon links so path
  resolves correctly whether app is served at / or /app/
- ic_launcher.xml: same equalizer design for Android app icon

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 19:50:30 +02:00
HoneyandClaude Sonnet 4.6 8e81404ab6 fix(ui): new equalizer logo, favicon link, fix favicon path
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 19:37:15 +02:00
HoneyandClaude Sonnet 4.6 d4ebcf0447 fix(ui): fix shuffle badge shift, regenerate PNG icons, fix favicon path
- styles.css: remove overflow:hidden from .player-info-wrap — it was
  clipping the player-status-row and shifting the shuffle badge
- index.html: use absolute /icon.svg path for favicon; add PNG fallback
  for browsers without SVG favicon support
- icon-192.png / icon-512.png: regenerated from new equalizer SVG design

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 22:24:28 +02:00
HoneyandClaude Sonnet 4.6 db81595b02 fix(ui): star button sits right next to track info, not far right
Wrap player-info + star in .player-info-wrap (flex, align-items:center)
so the star is immediately to the right of the text block and centered
vertically with it, instead of floating to the far end of the 1fr column.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 22:12:20 +02:00
HoneyandClaude Sonnet 4.6 3d6b74b873 feat(ui): new equalizer logo, favicon link, fix star vertical alignment
- icon.svg: replaced music-note with 5-bar equalizer waveform (gold
  gradient on dark bg) — works well as favicon and app icon at all sizes
- index.html: add <link rel="icon"> so browsers pick up the favicon;
  move #btn-star-current out of the title row and into player-track so
  player-track's align-items:center centers it with the full info block
- styles.css: add flex:1 to .player-info base rule; remove stale mobile
  overrides that assumed the star was inside player-info (position:absolute,
  padding-right hack)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 21:38:40 +02:00
Honey 9aa1947568 Revert "fix(backend): keep source artist name as-is, no iTunes override"
This reverts commit 1616d98fa6.
2026-06-21 16:44:26 +02:00
HoneyandClaude Sonnet 4.6 1616d98fa6 fix(backend): keep source artist name as-is, no iTunes override
Artist name from Spotify/source is stored directly in folder, filename,
and tags without being replaced by the iTunes artistName. iTunes is used
only for supplemental metadata (genre, year, cover, duration, trackNum,
albumArtist/collectionArtistName). Sort tags still receive romaji via
romajiForStorage() in ytdlp.js.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 16:43:15 +02:00
HoneyandClaude Sonnet 4.6 ff79428683 fix(backend): fix-artist-sort uses kanji for folder/filename, romaji only for sort tags
Consistent with point 7: original (kanji) names in folder, filename,
and main tags — romaji only in ARTISTSORT/ALBUMARTISTSORT.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 16:05:21 +02:00
HoneyandClaude Sonnet 4.6 38d21cf2e0 fix(backend): remove title keyword filter for Japanese tracks
Japanese Art Tracks on YTM/YouTube are often romanized ("Souiunatsu"
for "そういう夏") — the Japanese keyword filter in --match-filter always
rejected the correct video. Channel + duration are sufficient quality
gates for JP tracks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 14:10:08 +02:00
HoneyandClaude Sonnet 4.6 d5b088a658 fix(backend): remove album suffix from YTM search query
Album words ("KAGUYA Music", "OST" etc.) appended to the search query
caused wrong or no results — "Kei Haneoka 確信 KAGUYA Music" would miss
tracks the plain "Kei Haneoka 確信" query finds immediately.
Artist + cleanTitle is sufficient for both JP and Western tracks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 13:50:37 +02:00
HoneyandClaude Sonnet 4.6 fa4c954ab9 feat(0.9): romaji sort-tags only, robust dupe detection, Mittelweg no-duration, autofill all fields
- Japanese tracks stored with original names in folder/filename/tags; romaji only in sort tags
- findExistingTrack: case-insensitive, searches all album folders under artist, strips release suffix
- --max-filesize 30M + 2x duration cap on all yt-dlp calls
- iTunes collectionArtistName captured as album_artist; fixes compilation album splitting
- album_artist tag uses mainArtist (not rawArtist) so all tracks in one album are consistent
- No-duration cascade: steps 5-8 (title-only/no-filter) removed — fail cleanly like with-duration
- Autofill iTunes: fills title, artist, albumArtist, discNum (was album/genre/year/track/total only)
- Autofill MusicBrainz: fills albumArtist, discNum (was missing both)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 13:26:11 +02:00
HoneyandClaude Opus 4.8 8be3a515e6 docs(changelog): autofill should fill every resolved field, not a subset
Both iTunes/MusicBrainz autofill buttons currently fill only partial form
fields; they should populate title, artist, album-artist, album, genre, year,
track, disc, total, cover — backend endpoints must return those fields too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 13:03:47 +02:00
HoneyandClaude Opus 4.8 a57e18198f docs(changelog): correct metadata-editor autofill bug description
Artists are stored ;-separated (feat./ft. normalized away at download), and
both lookups already use the first artist. The real gap is the strict match
failing for multi-artist tracks (no fallback) plus iTunes autofill not filling
the artist/album-artist fields.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 13:00:46 +02:00
HoneyandClaude Opus 4.8 6e7a18302a docs(changelog): note duplicate check is case-sensitive (filename FS match)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 12:58:19 +02:00
HoneyandClaude Opus 4.8 8b6b4b0839 docs(changelog): track playlist re-download (dupe drift) + no-duration wrong-cover bugs
Duplicate check matches exact computed path only, so iTunes/romaji/trackNum/
album drift between runs re-downloads existing tracks. The no-duration cascade
branch lacks Mittelweg protection and grabs wrong covers (Yorushika 車窓 →
Piano Echoes Shasou).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 12:52:58 +02:00
HoneyandClaude Opus 4.8 f3fa68928c docs(changelog): track metadata-editor autofill bugs (album artist + multi-artist split)
iTunes/MusicBrainz autofill don't fill the Album-Artist field; multi-artist
lookup splitting is inconsistent across the two endpoints (neither handles
/, feat., ft.).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 12:49:59 +02:00
HoneyandClaude Opus 4.8 feaa8ee61f docs(changelog): track known backend download/metadata bugs
Duplicate detection (filename-only), missing download size cap (52MB wrong
video), and uncaptured iTunes album artist (collectionArtistName) affecting
Navidrome grouping/sorting.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 12:45:36 +02:00
HoneyandClaude Opus 4.8 4c85fec4ca docs: add CLAUDE.md with project conventions and download-pipeline knowledge
Captures the rules and hard-won details from recent work: no mocked frontend
data, two-part versioning, yt-dlp-only download cascade + Mittelweg rule, file
naming, the YTM-search limitation for obscure tracks, and edit/delete file
resolution. Loaded automatically by Claude Code at session start.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 20:48:29 +02:00
HoneyandClaude Opus 4.8 0fe2de5084 docs(changelog): release 0.8 + switch to two-part MAJOR.MINOR versioning
- Promote 0.7.1 → 0.8 with this session's work (Mittelweg cascade, web_music
  client, clean filename, duration-filter + metadata-editor fixes, squid removal)
- Drop the patch component from all historical versions (0.7.0 → 0.7, etc.)
- Add Metadata editor and Song delete rows to the parity matrix (Web only)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 18:35:21 +02:00
HoneyandClaude Opus 4.8 a870f50c87 feat(backend): Mittelweg cascade — never download wrong song on no duration match
When a track's duration is known but nothing matches the duration window, the
cascade no longer falls back to blind title-only/no-filter grabs (which pulled
same-titled videos by other uploaders, e.g. a "recognize" fan clip). Instead it
relaxes only the duration constraint while still REQUIRING the artist channel +
title. If nothing matches, the download produces no file and the job now fails
cleanly with "Nicht eindeutig gefunden — bitte Direktlink im Importer nutzen"
(previously it falsely reported success with no file).

Single, album and playlist paths all surface the not-found state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 18:13:59 +02:00
HoneyandClaude Opus 4.8 cf6e75b312 fix(backend): restore YTM Songs filter param for cleaner song search
Re-add the &params= Songs-shelf filter (the documented way to song-search
YouTube Music) so results exclude videos/playlists/clips. Verified neutral
for the ambiguous-artist case (yt-dlp's search can't surface that track
regardless) but cleaner for normal tracks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 17:51:43 +02:00
HoneyandClaude Opus 4.8 1e8e5e8874 fix(backend): strip release suffix from filename too (01 - Artist - Title)
The filename used the raw title, so "recognize - Single" leaked into the
filename ("01 - MINA - recognize - Single.mp3"). Now the cleaned title drives
both the filename and the embedded title tag, giving "01 - MINA - recognize.mp3"
(Track - Artist - Title). The album folder keeps the full album name.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 12:29:14 +02:00
HoneyandClaude Opus 4.8 902243586b fix(backend): match files when Navidrome stem desyncs by release suffix
After the embedded-title change (recognize vs "recognize - Single"),
Navidrome's title-derived stem can drop the "- Single"/"- EP" suffix the
on-disk filename still carries, so _findFileByStem matched neither exact nor
suffix and every fallback failed -> "File not found on disk" on edit/delete.
Now also match on the structured prefix in both directions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 11:39:35 +02:00
HoneyandClaude Opus 4.8 77bbb18c8d chore(backend): include resolved path in delete-song "file not found" error
The delete-song endpoint returned a bare "File not found on disk" with no
context, making path-resolution mismatches impossible to diagnose. Now
reports the Navidrome path, music root, and searched filename — matching the
detail the edit-metadata endpoint already provides.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 11:32:46 +02:00
HoneyandClaude Opus 4.8 e93c0c7ab1 fix(backend): drop YTM Songs filter param — it dropped the exact track
The &params= Songs-tab filter re-ranked YTM results toward a same-named
artist's discography and excluded the official track (qNffDItRUeo) entirely,
even logged-out. The default blended search (what the browser shows) ranks
the exact track first. Removing the param so yt-dlp gets the same result set.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 11:15:12 +02:00
HoneyandClaude Opus 4.8 c4e4c8c090 fix(backend): use space (not dash) between artist and title in search query
"MINA - recognize" skewed YTM ranking toward a same-named artist's full
discography, so the actual track (qNffDItRUeo) never appeared in results.
"MINA recognize" — matching how users type in the YTM search box — ranks
the exact official track first.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 11:06:00 +02:00
HoneyandClaude Opus 4.8 c34123af38 fix(backend): apply web_music client to YTM search extraction too
The YTM search (getYtmVideoUrls) ran without the web_music client, so yt-dlp
parsed the search page as a generic YouTube search and returned unrelated
videos instead of the native Songs shelf — the actual artist track (e.g.
qNffDItRUeo for MINA - recognize) never appeared in results. Apply the same
player_client=web_music,default arg to the search step.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 10:48:26 +02:00
HoneyandClaude Opus 4.8 9014659112 fix(backend): use web_music player client for YTM track access
yt-dlp's android_vr player client returns "This video is not available" for
many YouTube Music Art Track / topic uploads (e.g. MINA - recognize) that
play fine in the browser. Switch to player_client=web_music with default
fallback so these tracks become downloadable, fixing the cascade falling
through to wrong YouTube videos.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 10:46:53 +02:00
HoneyandClaude Sonnet 4.6 ce4577e8f4 fix(backend): strip release suffix from title metadata tag
searchTitle (e.g. "recognize") is now passed to embedMetadata instead of
the raw title ("recognize - Single"), so the ID3 title tag matches the
actual song name. Album tag stays unchanged ("recognize - Single").

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 10:44:13 +02:00
HoneyandClaude Sonnet 4.6 bb0be52f46 fix(backend): fix getYtmVideoUrls always returning empty + remove unsupported ytmsearch5
[youtube:tab] in stderr fires for all YTM search page processing, not just
artist channel expansion, causing channelExpanded=true for every search and
returning [] — bypassing all YTM cascade steps entirely. Fix: only check
stdout for /browse/UC (actual channel URL in results). Remove ytmsearch5:
scheme which is not supported by this yt-dlp version. Revert pool to 10.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 10:32:22 +02:00
HoneyandClaude Sonnet 4.6 3c54850cca fix(backend): add ytmsearch5 step + expand YTM pool to 20 for better coverage
ytmsearch5 (yt-dlp native YTM search) added as step 2 — returns different
result ordering than the manual YTM URL, recovering songs that the URL
approach ranks too low. YTM pool expanded from 10 → 20 results to reduce
fallthrough to YouTube.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 10:25:37 +02:00
HoneyandClaude Sonnet 4.6 4804023a98 fix(backend): don't abort cascade on yt-dlp non-zero exit (e.g. video not available)
spawnYtdlp now always resolves so the hasAudio() cascade continues when a
single YTM result is geo-blocked or unavailable. Error is still logged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 10:23:59 +02:00
HoneyandClaude Sonnet 4.6 88d3e336c8 fix(backend): use searchTitle in YTM URL (was using raw title with release suffix)
YTM search used `title` directly, so "recognize - Single" was searched on
YouTube Music instead of "recognize" — causing no YTM results and falling
through to the less reliable YouTube search cascade.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 10:19:43 +02:00
HoneyandClaude Sonnet 4.6 d5bc887f31 fix(backend): tighten duration filter margin from ±15% to ±10% (min 10s)
Matches spotdl behaviour; still covers YouTube intros/outros while
reducing false positives from similarly-lengthed wrong songs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 10:07:19 +02:00
HoneyandClaude Sonnet 4.6 4cbfa35655 fix(backend): normalize iTunes lookup across all download paths
- Track path: always fetch iTunes when durationMs/trackNum missing (not just genre)
- Both paths: strip release suffixes from title before iTunes lookup
- Log "Album:" instead of "Album aus Spotify:" (also fires for iTunes global search)
- Log duration when fetched from iTunes so it's visible in job log

Ensures all importers have consistent yt-dlp search filters (duration filter
now always runs when iTunes finds the track).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 10:00:32 +02:00
HoneyandClaude Sonnet 4.6 86d3999628 fix(download): pass Spotify durationMs through to yt-dlp duration filter
- downloads.js: use durationMs (Spotify) before trackTimeMillis (iTunes)
- server: read durationMs from top-level body, not only from tracks[0]
- server: also grab durationMs + trackNum from iTunes in the Spotify path

Without durationMs the duration filter never ran, allowing a 58s fan video
to pass all text filters and be downloaded instead of the actual song.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 09:55:17 +02:00
HoneyandClaude Sonnet 4.6 5f257bf451 fix(backend): generalize release-suffix stripping from search title
Handles all Spotify trailing suffixes: Single, EP, Remaster, Deluxe Edition,
Bonus Tracks, B-Sides, bare years (2024), Official Music Single, etc.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 09:44:06 +02:00
HoneyandClaude Sonnet 4.6 bff652a415 fix(backend): strip release-type suffixes from YTM search title + extend stopwords
- "recognize - Single" title → search uses "recognize" (strips "- Single/EP/Album/…")
- Adds Single/EP/Remaster/Deluxe/… to titleKws STOPWORDS so they never become
  mandatory title-match filters (no YouTube video title contains "Single")

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 09:42:07 +02:00
HoneyandClaude Sonnet 4.6 d1b107ae71 docs: add CHANGELOG v0.7.1 (squid removal + ytdlp search fix)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 09:36:42 +02:00
HoneyandClaude Sonnet 4.6 ecb7721e3b fix(backend): only append album to YTM query for Japanese titles
Western tracks now use artist + title only (matches spotdl behaviour).
Album suffix was causing noise for short English titles like singles
where album name = title + "Single".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 09:35:32 +02:00
HoneyandClaude Sonnet 4.6 319a3804f3 fix(backend): strip title-duplicate and generic words from album search suffix
Album "recognize - Single" produced query "MINA - recognize recognize Single"
because "recognize" appeared in both title and album name. Now filters album
words already present in the title, plus generic words (Single, EP, Remaster…).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 09:29:39 +02:00
HoneyandClaude Sonnet 4.6 f1bdd811ca chore: remove squid.wtf (Qobuz) backend — yt-dlp only
Deletes backend/lib/squid.js; strips all references from downloader.js,
config.js, novasonic-server.js, docker-compose.yml, .env.example, README,
and CHANGELOG. Default DOWNLOAD_BACKEND is now ytdlp.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 20:59:30 +02:00
HoneyandClaude Sonnet 4.6 925c173c15 chore: stage previously uncommitted screen changes (ArtistDetail, ItunesArtist, NowPlaying)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 20:52:42 +02:00
Honey 85252e24df fix: unresolved reference 'albums' after rename to albumsByNewest/albumsByName 2026-06-18 20:21:36 +02:00
HoneyandClaude Sonnet 4.6 7030f029b7 docs: finalize CHANGELOG v0.7.0
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 20:15:11 +02:00
HoneyandClaude Sonnet 4.6 93c5fb481d feat(android): add description field to playlist edit dialog
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 20:13:19 +02:00
HoneyandClaude Sonnet 4.6 43cf11465e fix: playlist edit — cover upload in pencil dialog, remove cover-remove button
Android: camera hero button removed; cover upload moved into edit dialog.
Web: trash icon removed from cover actions in edit modal.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 20:12:27 +02:00
HoneyandClaude Sonnet 4.6 6a1bf33f31 fix(android): album Neueste now uses Navidrome type=newest (add-date), not year sort
Loads albumsByNewest (type=newest) and albumsByName (alphabetical) in parallel.
Neueste → Navidrome add-date order; A-Z → alphabetical; Älteste → client-side by year asc.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 20:09:32 +02:00
HoneyandClaude Sonnet 4.6 9ffd071c58 feat(android): artist fast-scroll index bar with letter bubble
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 20:06:44 +02:00
HoneyandClaude Sonnet 4.6 dd484df636 fix(android): album sort — scroll to top on change, remove Künstler, default Neueste
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 20:05:00 +02:00
HoneyandClaude Sonnet 4.6 6be7981b8a feat(android): playlist mgmt, album sort, home hero parity, notification fix
- Playlist: create (FAB + dialog), rename, delete, remove songs, cover upload/remove
- Library Albums tab: sort chips (Neueste/Älteste/A-Z/Künstler) matching StarredScreen
- ABS notification: shows current chapter title; updates live without re-buffering
- Home hero: pool now matches web (frequent(5) ∪ recentlyPlayed(5)); label MEISTGESPIELT / ZULETZT GEHÖRT
- Home: added Zuletzt gehört section (type=recent) matching web layout
- Notifications: fixed delivery bug — polling moved to NotificationStore app-lifetime scope so notifications arrive even after user navigates away from ImporterScreen
- NotificationStore.startPoll() extended with navType/navAlbum/navArtist/navId params
- Removed defunct AbsPlayerService.kt

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 19:04:36 +02:00
HoneyandClaude Sonnet 4.6 eacce487df fix: lyrics scroll — center active line only, remove drift phase
The 'drift to next line' animation moved the text while the user was
still reading/singing the current line, making it feel out of sync.
Now matches the web behavior: smooth-scroll to center the active line
when it changes, nothing more.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-17 01:39:51 +02:00
HoneyandClaude Sonnet 4.6 ec9c0add9e feat: notification nav + ABS search + HTML desc fix + brighter NowPlaying bg
- Notification sheet: add 'Zum Album →' / 'Öffnen →' button; tapping searches
  Navidrome and navigates to the matching album/playlist
- AppNotification: add navType/navAlbum/navArtist/navId fields (mirrors web notify.js)
- ImporterViewModel: store resolved album/artist/type in notification after download
- ABS Android: search bar with 400ms debounce, server-side search via /search endpoint
- AbsClient: add searchLibraryItems() for library-specific search
- AbsScreen/abs.js: strip HTML tags from book descriptions (<p> tags no longer visible)
- NowPlayingScreen: vibrant palette swatch + lighter scrim (0.15) + wider gradient
  for more visible dominant color background

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-17 01:38:58 +02:00
HoneyandClaude Sonnet 4.6 72feac41bb fix: ABS skip library list + nav label overflow + NowPlaying top bar + dominant color bg
- ABS: new AbsBooksScreen loads books directly on tab open; library pills shown only when >1 library — no more two-step library→books navigation
- Nav: shorten "Hörbücher"→"Bücher", "Einstellungen"→"Einst.", reduce label font to 9sp with maxLines=1 to prevent label wrapping
- NowPlaying: increase top padding so the tab bar sits lower on screen (statusBarTop + 16dp, min 52dp)
- NowPlaying: replace blurred-cover background with dominant-color gradient extracted via Palette from cover art; animates on track change; falls back to dark color

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 00:23:43 +02:00
HoneyandClaude Sonnet 4.6 820a75f40b feat: ABS full playback on Android — chapters, speed, sleep timer, progress sync
- AbsClient: add session API (startSession, closeSession, getProgress, saveProgress, getItemChapters) and data classes (AbsChapter, AbsAudioTrack, AbsPlaySession, AbsProgress)
- AbsPlayerController (new): standalone ExoPlayer controller for ABS audio; tracks global time across multi-track audiobooks, syncs progress to ABS every 30 s, chapter navigation, speed control, sleep timer
- AbsScreen: book detail screen with cover/meta/progress/chapter list/play button; AbsNowPlayingScreen overlay (progress bar, prev/+30s/play/-30s/next controls, speed picker, sleep timer, chapter list with auto-scroll)
- AppNavigation: create AbsPlayerController, wire up book detail and player overlay, hardware back button handling for all ABS sub-screens
- PrefsStore + SettingsViewModel + SettingsScreen: absChapterTrackMode toggle — progress bar shows current chapter length instead of full book
- README: update ABS section to cover both web and Android features

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 00:15:30 +02:00
HoneyandClaude Sonnet 4.6 3280ffee37 docs: trim README to core features only; fix: remove duplicate save button in Android settings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 23:58:15 +02:00
HoneyandClaude Sonnet 4.6 ba16f88355 docs: update README — accurate feature list + Android native app description
Removed:
- "WebView wrapper" — Android is native Jetpack Compose, not a WebView
- "Artwork pre-warming / pre-buffer on cold start" — not implemented this way
- ABS chapters/speed/sleep/progress on Android — web only for now

Added:
- Lyrics section: lrclib.net, fallback chain, in-memory cache, synced scroll
- Android: last played song in MiniPlayer across restarts
- Android: ABS library browser tab (hidden until configured)
- Android: no login flash on startup
- Settings: connection status dots, save button top+bottom, matched web order
- Multi-artist support in NowPlaying
- Artist cards with images in search
- Genre browsing
- ABS web vs Android split into separate entries
- Accurate Android project structure

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 23:56:02 +02:00
HoneyandClaude Sonnet 4.6 613d5156fa fix: settings order now matches web — Theme → Bibliothek → ABS → Discover APIs → Navidrome
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 23:54:11 +02:00
HoneyandClaude Sonnet 4.6 a0d3c7a592 feat: ABS integration, last played song, settings reorder + conn dots
Settings:
- Reordered to match web: Navidrome → Bibliothek → Theme → Audiobookshelf → Discover APIs
- Save button now appears at top AND bottom for easy access
- Audiobookshelf section: Server URL + API Key (masked) + green/red status dot with Test button
- NovaSonic Backend section: same green/red conn dot + Test button
- Connection status uses ConnStatus sealed class (Idle/Checking/Ok/Err)

Audiobookshelf:
- New AbsClient.kt: Ktor HTTP client, proxies through NovaSonic backend or direct with Bearer token
- New AbsScreen.kt: library list → book list with covers, author, duration
- Hörbücher tab appears in bottom nav only when ABS URL + API key are both set
- absUrl + absApiKey persisted in DataStore

Last played song:
- PlayerController saves song to DataStore on every media item transition
- MiniPlayer shows last song (dimmed, single play button) when no active queue
- Tapping play fetches the song from Navidrome and resumes
- LastPlayedSong stored in DataStore (id, title, artist, coverArt)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 23:49:36 +02:00
HoneyandClaude Sonnet 4.6 f7012dab49 fix: login flash, album name casing, lrclib duration mismatch
- Android: show nothing while DataStore loads credentials (null initial
  value) to prevent login screen flash on startup when already logged in
- Web: dispAlbumName now only uses sortName as romaji for Japanese titles;
  English albums with lowercase ALBUMSORT tags now display correct casing
- lrclib: add no-duration fallback exact match to find songs where local
  file duration differs from lrclib entry (e.g. Sanctuary Opening 5:58 vs 4:24)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 22:50:11 +02:00
HoneyandClaude Sonnet 4.6 0272b9e99f chore: remove NetEase lyrics fallback from Android and web
NetEase returned wrong/unsynced results. lrclib with exact + fuzzy
search is sufficient; no third-party Chinese platform needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 21:48:46 +02:00
HoneyandClaude Sonnet 4.6 eb5b0ea360 fix: lrclib rate limit — exact first, then 2 parallel searches; check HTTP 200
3 simultaneous requests were hitting lrclib rate limiter.
Now: exact match alone → if no content, 2 parallel searches.
Also check response.status === 200 before parsing to avoid treating
404/429 error bodies as valid empty lyrics responses.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 21:46:09 +02:00
HoneyandClaude Sonnet 4.6 d7f8b301ab perf: parallel lrclib requests + in-memory cache for lyrics
- Android + web: fire exact/artist-search/title-search in parallel so
  total wait = slowest single request instead of sum of all three
- Android: HashMap cache keyed by artist|title, cleared on app restart
- Web: Map cache (session lifetime), cache hit is instant re-open
- Web: extract _showLyricsResult helper, safeJson wrapper

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 21:26:07 +02:00
HoneyandClaude Sonnet 4.6 d0df01a76d fix: lyrics faster + title-only search fallback for metadata mismatches
- Android: add 6s HttpTimeout to LrcLibClient, wrap each step in withTimeoutOrNull
- Both: add title-only lrclib search (step 3) so "Sanctuary (Opening)" is found
  even when artist tag differs ("Utada" vs "Hikaru Utada")
- Web: reduce all timeouts 8s → 5s, extract bestMatch helper

Search order: lrclib exact → lrclib artist+title → lrclib title-only → NetEase

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 21:20:47 +02:00
HoneyandClaude Sonnet 4.6 71667d1a03 feat: add NetEase as lyrics fallback after lrclib (Android + web)
Search order: lrclib exact → lrclib fuzzy search → NetEase.
NetEase has strong coverage for Asian/Japanese music that lrclib misses.
Duration-matched candidate selection on all three steps.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 20:50:16 +02:00
HoneyandClaude Sonnet 4.6 8b9bfd3098 fix: restore direct lrclib lyrics search with fuzzy fallback (both platforms)
Navidrome lyrics plugin does not implement getLyricsBySongId for synced
lyrics — removed all plugin calls. Both Android and web now query
lrclib.net/api/get (exact match) with /api/search fallback for metadata
mismatches (e.g. artist tagged differently in Navidrome vs lrclib).
Also fixes Android lyrics scroll tween<Int> type inference error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 20:45:32 +02:00
HoneyandClaude Sonnet 4.6 7e20062995 feat: Android Auto, radio mode, lyrics overhaul + web lyrics cleanup
Android:
- fix: Android Auto credentials never set on MusicService → artwork/stream null
- feat: Android Auto tabs reduced to Zuletzt gespielt, Favoriten, Playlists
- feat: radio mode (getSimilarSongs2 → getRandomSongs fallback, <5 songs refill)
- fix: lyrics now use Navidrome getLyricsBySongId plugin exclusively
- fix: lyrics scroll rewritten with Column+ScrollState absolute animateScrollTo
- fix: lyrics recomposition lag — extracted LyricsLineItem + key(idx) per line
- chore: remove dead LrcLibClient (direct lrclib bypassed Navidrome plugin)

Web:
- fix: lyrics now use Navidrome getLyricsBySongId only, removed direct lrclib fallback

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 20:30:20 +02:00
HoneyandClaude Sonnet 4.6 8c8f03503b fix: multi-artist click in NowPlaying — individual composables per artist
Replace AnnotatedString/ClickableText (offset-based click was unreliable)
with a horizontally-scrollable Row of individual Text composables. Each
artist has its own explicit clickable modifier bound directly to its ID.

ID de-duplication: if Navidrome copies the primary artistId to all entries
in the artists array, only the first keeps the ID; others render as
non-navigable text (dimmed NsAccent) instead of silently going to wrong page.

Fallback: split song.artist by ';' when artists array is absent/single,
matching the web app's parseArtists() logic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 00:44:59 +02:00
HoneyandClaude Sonnet 4.6 55eef2f831 feat: randomized home greetings (web PWA)
Same pool of music-themed phrases as Android — picks randomly each load.
With username: "Ready for some beats, Marc" — without: "Pick something great"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 00:38:21 +02:00
HoneyandClaude Sonnet 4.6 f15c005a3c feat: multi-artist support in NowPlaying (OpenSubsonic artists array)
- Song model: add SongArtist{id,name} + artists: List<SongArtist>
  Navidrome sends this via OpenSubsonic extension — previously ignored
- NowPlaying: if song.artists has >1 entry, render each name as an
  inline AnnotatedString with ClickableText, separated by ' · ';
  every artist navigates to their own page with their real ID
  Falls back to single artist/artistId entry when array is absent
- AppNavigation: onArtistClick now receives artistId: String instead
  of a fixed closure, enabling per-artist navigation from the sheet

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 00:37:08 +02:00
HoneyandClaude Sonnet 4.6 0e651e8be3 feat: randomized home greetings (music-themed, EN)
Replace static time-of-day greetings (Guten Morgen/Tag/Abend) with a random
pick from a pool of 10-12 music-themed phrases each time HomeScreen is composed.
With username: "Ready for some beats, Marc" — without: "What's on the playlist today?"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 00:28:44 +02:00
HoneyandClaude Sonnet 4.6 3855207530 feat: artist cards with image in search + fix action bar overflow
Search: replace SmallArtistChip (text pill) with ArtistCard showing
circular profile image (72dp) + name below; works for both Navidrome
artists (uses coverArt) and iTunes artists (uses artworkUrl100 if present)

ArtistDetailScreen: convert action bar Row → LazyRow so Play / Shuffle /
Konzerte pills sit comfortably with horizontal scroll instead of cramming

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 00:24:18 +02:00
HoneyandClaude Sonnet 4.6 13e9ec9d9a feat: Konzerte button on artist page (Android)
- EventModels: ConcertEvent / ConcertVenue / ConcertOffer (Kotlinx Serializable)
- EventsClient: Ktor client fetching backendUrl/api/events/{artist}
- ArtistViewModel: fetches events in parallel with iTunes data on load;
  openEventsSheet / dismissEventsSheet
- ConcertsSheet: ModalBottomSheet with event rows (date, venue, city,
  Tickets → button that opens browser, Ausverkauft state)
- ArtistDetailScreen: Konzerte pill in action bar showing event count,
  tapping opens ConcertsSheet

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-15 00:17:55 +02:00
HoneyandClaude Sonnet 4.6 b5aa484c20 fix: push NowPlaying cover and controls down by 28dp
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 23:35:59 +02:00
HoneyandClaude Sonnet 4.6 42c12cbd3a fix: genre loading spinner + NowPlaying back button priority
GenreViewModel: GenreUiState(genres = it) left isLoading=true (default),
so genres loaded but spinner never cleared. Added isLoading=false explicitly.

AppNavigation: replace BackHandler + navController.enableOnBackPressed with a
DisposableEffect that re-adds an OnBackPressedCallback each time NowPlaying
opens. Since callbacks are LIFO, a freshly-added callback always beats the
BackHandler NavHost registers internally, regardless of composition order.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 22:49:40 +02:00
HoneyandClaude Sonnet 4.6 f01fc71f54 feat: back navigation, NowPlaying fix, home refresh, genre top-6
- ExploreScreen: add BackHandlers for state-based overlays (partialAlbum →
  albumTracks → artistDetail hierarchy) so system back navigates correctly
- AppNavigation: disable NavController's OnBackPressedCallback while NowPlaying
  is open so our BackHandler always intercepts first (fixes tab-switch-then-back bug)
- Home tab: tapping Home while already on Home triggers vm.load() refresh via refreshKey
- HomeViewModel: load all genres sorted by songCount desc (removed take(12) cap)
- HomeScreen: show only top-6 genres + 'Alle anzeigen' button with total count
- New GenreListScreen + GenreViewModel: full scrollable genre list at 'genres' route

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 22:40:48 +02:00
179 changed files with 21353 additions and 2200 deletions

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
# Frontend build context (root Dockerfile) — keep it to what `vite build` needs.
.git
node_modules
dist
android
docs
scripts
backend
scrobble
.env
*.log
+32 -25
View File
@@ -1,29 +1,36 @@
# Copy to .env and fill in your values # Copy to .env next to your docker-compose file and fill in. cp .env.example .env
# Used by docker-compose.yml (zieht fertige Images) und docker-compose.dev.yml (baut lokal).
# REGISTRY/TAG unten braucht nur der Pull-Weg (docker-compose.yml).
# Pre-fills the URLs on the setup screen # ── URLs pre-filled on the frontend setup screen ─────────────────────────────
NAVIDROME_URL=https://music.yourdomain.com NAVIDROME_URL=https://music.example.com
BACKEND_URL=https://novasonic-api.yourdomain.com BACKEND_URL=https://backend.example.com
SCROBBLE_URL=https://scrobble.example.com
# Absolute path to your Navidrome music library on the host # ── Library / downloads (backend) ────────────────────────────────────────────
MUSIC_PATH=/srv/navidrome/music # Absolute music path — mounted 1:1 into the backend (no remapping), same value inside the container.
MUSIC_PATH=/opt/navidrome/music
AUDIO_FMT=mp3 # mp3 | flac | opus | best (used by yt-dlp) AUDIO_FMT=mp3
AUDIO_QUALITY=0 # 0 = best quality (used by yt-dlp) AUDIO_QUALITY=0
MAX_PARALLEL=2 MAX_PARALLEL=2
DOWNLOAD_BACKEND=ytdlp
# Download backend: ytdlp | squid | auto
# ytdlp - always use yt-dlp
# squid - always use squid.wtf (Qobuz)
# auto - try squid.wtf first, fall back to yt-dlp if not found (default)
DOWNLOAD_BACKEND=auto
# Quality for squid.wtf / Qobuz downloads
# mp3 - MP3 320 kbps
# flac - FLAC 16-bit / 44.1 kHz
# hi-res - FLAC 24-bit / 96 kHz
SQUID_QUALITY=mp3
# Ticketmaster Events (optional — free API key)
# 1. Sign up at https://developer.ticketmaster.com/
# 2. Create an app — copy the Consumer Key
TICKETMASTER_API_KEY= TICKETMASTER_API_KEY=
# ── Android APK download button + in-app updater ─────────────────────────────
# The backend proxies the fixed Gitea release ("apk-latest") over the LAN, so Gitea can stay internal.
GITEA_URL=http://192.168.2.51:3000 # Gitea-Basis, die der BACKEND-CONTAINER erreicht.
# Muss nicht Giteas eigene ROOT_URL sein — das Backend baut
# die Asset-URL auf diesen Host um (Test aus dem Container:
# curl -sI $GITEA_URL/api/v1/version).
GITEA_REPO=Docker/NovaSonic
GITEA_TOKEN= # read token (only needed for a private repo)
GITEA_APK_TAG=apk-latest
# ── Fertige Images (nur docker-compose.yml) ──────────────────────────────────
# REGISTRY = where `npm run push-images` pushed to and where the host pulls from.
# Gitea container registry (lowercase owner): gitea.honeyy.duckdns.org/docker
# Docker Hub: docker.io/youruser
# Plain-HTTP internal registries need the host's Docker daemon to allow it
# (/etc/docker/daemon.json → {"insecure-registries":["192.168.2.51:3000"]}).
REGISTRY=gitea.honeyy.duckdns.org/docker
TAG=latest
+3
View File
@@ -2,3 +2,6 @@
*.log *.log
node_modules/ node_modules/
dist/ dist/
scripts/.env.release
.env
.idea/
+1518
View File
File diff suppressed because it is too large. Load diff
+251
View File
@@ -0,0 +1,251 @@
# CLAUDE.md
Guidance for Claude Code when working in this repository.
## What this is
NovaSonic — a self-hosted music streaming **PWA** (Vite + vanilla ES modules) and
**Android app** (Jetpack Compose + Media3/ExoPlayer) for Navidrome / Subsonic servers,
plus a **Node.js/Express backend** that downloads tracks via yt-dlp and proxies APIs.
## Critical rules
- **Never hardcode or mock frontend data.** All library data comes from the Navidrome
(Subsonic) API. No placeholder songs/albums/artists, ever.
- **Don't commit or push unless asked.** When asked, push to the Gitea remote.
- **Two-part versioning** `MAJOR.MINOR` (e.g. `0.8`) — no patch component. Each release
bumps the minor; features and fixes go in the same release. See `CHANGELOG.md`.
- Keep the `CHANGELOG.md` Platform Parity Matrix accurate when adding cross-platform features.
## Layout
- `src/` — web PWA (vanilla ES modules). State in `src/state.js` (the `S` object);
Subsonic/Deezer API in `src/api.js`; views in `src/views/`, UI in `src/ui/`.
- **Client-side router** (`src/views/navigation.js`, History API): `navigate()` pushStates `{nsIdx}`
only on genuine new navigation; `popstate` applies the target entry's `nsIdx` for **both** back and
forward. Never `pushState` inside the `popstate`/back path — it wipes the browser's forward stack
(that was the "forward doesn't work" bug). In-app back buttons call `history.back()` (one path).
- `backend/novasonic-server.js` — Express API (downloads, metadata edit/delete, events/ABS proxy).
- `backend/lib/` — `ytdlp.js` (download + cascade + ffmpeg tagging), `downloader.js`,
`deezer.js` (Deezer metadata: track/album/artist lookups + matching),
`metadata.js` (artwork, file resolution helpers, duplicate detection), `config.js`, `jobs.js`, `romaji.js`.
- `scrobble/scrobble-server.js` — **separate** listening-stats service (own container + DB), see below.
- `android/` — native Kotlin app (separate; backend-dependent web features like the
metadata editor are **not** in the Android app).
## Commands
```bash
npm run dev # Vite dev server (HMR)
npm run build # production build → dist/
npm run preview # preview the production build
```
Der Stack läuft in Docker. **`docker-compose.yml` ist der Normalfall und zieht fertige Images**
(`${REGISTRY}/novasonic-frontend|-backend|-scrobble:${TAG:-latest}`) — der Server baut nichts:
`docker compose pull && docker compose up -d`. Ein einfacher Restart ist `docker compose restart
novasonic-backend` (das Backend zieht bei jedem Start das neueste yt-dlp nach).
Gepusht wird von der Dev-Maschine mit `npm run push-images` (`scripts/build-push-images.mjs`, liest
`REGISTRY`/`TAG` aus `.env`); ohne Node tut es direkt `docker build -t $REGISTRY/<name>:latest
<context>` + `docker push` mit den Kontexten `.`, `backend/`, `scrobble/`. Registry ist die
Gitea-Registry (`…/docker`, Owner klein geschrieben).
**`docker-compose.dev.yml`** ist die Variante, die stattdessen lokal aus den Dockerfiles baut
(`backend/Dockerfile` + `scrobble/Dockerfile`), ohne Registry: `docker compose -f
docker-compose.dev.yml up -d --build`. Die schweren Deps (ffmpeg, Deno, yt-dlp, node libs) sind in
den Images gebacken, deshalb sind **Restarts sofort da** und Rebuilds nach `git pull` cache-schnell.
On the deploy host the music lives at `/opt/navidrome/music`.
## Download pipeline (hard-won knowledge)
- Downloads are **yt-dlp only** (the old squid.wtf/Qobuz backend was removed).
- **Metadata source = Deezer, not iTunes** (as of 1.3). Apple's iTunes `/search` returns **403 from
server/datacenter IPs**, which broke search + downloads + charts + editor autofill in production.
All metadata now comes from Deezer (`backend/lib/deezer.js` server-side; `_deezerBase()` in
`src/api.js`; Android `ItunesClient` is Deezer-backed). Free, no key, more requests, returns
explicit versions + real artist images + durations. Deezer generally gives one consistent name per
artist, so the old JP/US-store inconsistency (Western artists as katakana "DJスネイク" on some tracks,
kanji on others) is gone. Titles come from the source, so a Japanese title the user picked stays
Japanese; only Deezer-derived fields (album\_artist, genre, year, artwork) follow Deezer. The
Deezer results are mapped to the legacy "ItunesItem" shape, so the UI + download flow are unchanged.
`lookupTrackMeta`/`fetchAlbumTracks`/`searchAlbumTracks`/`fetchArtistAlbums` replace the old
`lookupItunesTrackMeta`/`fetchItunesTracks`/`searchItunesAlbumTracks`. Editor autofill endpoint:
`/api/meta/lookup` (was `/api/itunes/lookup`). Matching logic (`pickTrackMatch`) is unit-tested in
`backend/test/deezer.test.js` (`npm test`).
- **File naming:** `{NN - }Artist - Title.ext` with the release suffix stripped from the
title (no `- Single`/`- EP`). The **album folder keeps the full album name**. Original names
are used for folder, filename, and all main tags (artist/title/album/album\_artist) — even
for Japanese tracks. Romaji goes **only** into sort tags (TITLESORT / ARTISTSORT / etc.).
- **Search cascade** (`ytdlp.js`): YTM search first (`web_music` player client, Songs filter
param), then regular YouTube; each candidate filtered by duration (±10%, min 10s),
title keyword, artist channel, and variant exclusions (remix/cover/sped/…).
- **Official audio via `artist` metadata (not just channel).** The strict steps accept a candidate
if the channel name matches the artist **OR** yt-dlp's music `artist` field does. YouTube "Art
Tracks" (label-provided official audio) carry `artist=<Artist>` even when the channel is
`BANGTANTV`/`HYBE LABELS`/… (no artist name). Confirmed on "BTS Pied Piper": only the official
upload had `artist=BTS`; every fan/live/lyric reupload had `artist=NA`. `channel_is_verified` was
rejected as a signal — lyric videos and fan MVs also run on verified channels. Implemented as two
`--match-filter` args (yt-dlp OR's them) in `mf()`.
- **"Mittelweg" rule** (with AND without duration): when nothing matches in the filtered steps,
relax only the duration constraint while **still requiring the artist channel**. If nothing
matches, download **nothing** and fail cleanly with "Nicht eindeutig gefunden — bitte
Direktlink im Importer nutzen". Never fall back to a blind title-only/no-filter grab — it
pulled same-titled covers by other uploaders, and wrong Piano Echoes for Japanese tracks.
- **Numbers in a title are always required keywords.** `buildTitleKeywords` kept only the two
LONGEST words, and numbers are short — so "700 Main Street" was filtered on Street+Main only and
the cascade happily saved **"777 Main Street" by a different artist** (step 3 drops the channel
check, so nothing else caught it). Numeric tokens are now emitted as `\b<n>\b` in addition to the
two longest words. Same fix carries a small abbreviation map (street/st, saint/st, mount/mt,
doctor/dr, versus/vs, number/no): uploaders write "700 Main St" where the release says "Street",
which had rejected the correct official Art Track in every step. One exception: a **re-release year
next to a qualifier** ("… - 2020 Remaster") is dropped again — it sits on the release but never in
the YouTube title, so requiring it would reject the correct upload. A title that IS a year ("1999",
"Berlin 2020") keeps it. Unit-tested in `backend/test/ytdlp.test.js`.
- **Live recordings are excluded by title, not by `is_live`.** `!is_live` only means "not a running
stream" — a concert RECORDING passes it. On the artist's own channel nothing else distinguishes it
from the studio track, which is how "Dat Adam - Ufo Video Days 2015 Live" (channel `Dat Adam`,
209 s, title contains UFO) got saved as the album track. `buildVariantFilter` therefore carries a
`live` rule like remix/cover/…. It self-disables when the searched title itself says live, so
"Live Forever" or a deliberately requested live version still works — that check uses a `\blive\b`
regex (`skipRe`), because a plain substring test would let "deliver"/"delivery" switch the rule off.
- **A channel hit in the YTM results is a line to skip, not a reason to abort.** `getYtmVideoUrls`
used to treat any `/browse/UC…` in the output as "yt-dlp expanded an artist channel" and returned
`[]` — discarding the song URLs it had already collected. Measured on 8 real searches, that fired
in **7 of 8**, so step 1 (YTM, where the official Art Tracks live) was effectively dead and almost
every download came from the YouTube fallback. With `--flat-playlist` a channel is printed as ONE
line, so expansion cannot happen; `pickYtmVideoUrls()` now keeps every `watch?v=` line and skips
`browse/UC…` (channel) and `browse/MPREb_…` (album) alike. It is a strict superset of the old
behaviour — fuzz-checked over 20k random outputs — so it can only add candidates, never remove any.
- **Size cap:** `--max-filesize 30M` on every yt-dlp call; Mittelweg steps also cap at 2×
expected duration. Prevents saving a 28-min video (52 MB) when the wrong result slips through.
- **Leading aesthetic characters:** artists often style their name with leading punctuation
(`.diedlonely`, `†…`). `deezer.js` strips leading non-alphanumerics (`stripLeadSym`) before the
Deezer lookup and in `firstWord`. Without it the lookup misses, falls through to a title-only
match, and returns an unrelated same-titled track — whose wrong duration then *also* misleads the
YouTube duration filter (observed: a 96 s track resolved to a 176 s slowed version). The same trim
runs client-side in Android's `ExploreViewModel.search()`.
- **Mixed-artist albums search per track.** `downloadAlbumTracks` passes `rawArtist = track.artistName`
so the YTM/YouTube search query and the channel filter use each track's *own* performer, not the
album artist. `ytdlp.js` derives both from `rawArtist || mainArtist`, and `mainArtist = albumArtist`,
so without this every track on a soundtrack searched the album-artist blob + its channel filter and
matched nothing (e.g. "Strategy" = TWICE, "Love, Maybe" = MeloMance failed). The `album_artist` tag
still uses `albumArtist`, so album grouping is unaffected.
- **Album/artist download `album_artist`** comes from the Deezer tracks' `collectionArtistName`
(= the album-level `album.artist`, identical across the album), derived in `novasonic-server.js` —
**not** the request's `artist`, which can be the lead single's performer (a KPop soundtrack got
tagged `album_artist=TWICE` from track 1 "TAKEDOWN"). Falls back to the request artist only when
Deezer omits it.
- **Always write an `album` tag.** `ytdlp.js` defaults it to `Singles` when no album is known.
Previously no tag was written at all, so Navidrome showed its own "Singles" fallback while the
metadata editor showed "[Unknown Album]" — the two never matched and file resolution failed.
- **Duplicate detection** (`metadata.js findExistingTrack`): searches case-insensitively across
all album folders under the matching artist folder; compares normalized artist+title ignoring
track prefix and release/variant suffix. Handles DJ OKAWARI vs DJ Okawari and "- Single" drift.
- **Single-track metadata resolver = `backend/lib/trackmeta.js`** (Deezer → MusicBrainz → clean
fallback). Deezer's `pickTrackMatch` requires an **artist correspondence** (equal, or one name
contained in the other after stripping non-alphanumerics) — the old blind *title-only* fallback
grabbed a same-titled song by a different artist (e.g. "Memories" by Rab Noakes for "☆NoAki☆") and
applied its wrong album/cover/year. On no match it returns `{}`; then `musicbrainz.js` (rate-limited
~1/s, `User-Agent` required, Cover Art Archive for covers, **same** artist discipline) is tried; if
that also misses, the download's built-in clean fallback runs (**album_artist = song artist, album =
"Singles", cover = source thumbnail, year/genre left untouched**). Only the three *single-track*
call sites use `trackmeta`; the album batch stays Deezer-only (avoids MB's rate limit). The clean
fallback always existed but was unreachable while the match was too greedy. Matching is unit-tested
(`deezer.test.js`, `musicbrainz.test.js`).
- **Known limitation:** yt-dlp's YTM/YouTube *search* can't surface very obscure Art Tracks by
ambiguously-named artists (e.g. "MINA") — the browser finds them, yt-dlp's API extraction
doesn't (confirmed across params/clients/deno). For those, the **direct link in the importer**
(`sourceUrl` path) is the reliable route.
- **File resolution for edit/delete:** Navidrome's stored path may use a different mount root
or a stale stem. `metadata.js` rebases the path and falls back to recursive/stem matching
(tolerant of release-suffix mismatch). A ghost Navidrome entry needs a full library rescan.
- **Album splitting:** prevented by consistent `album_artist` tag. All tracks in a download
share the same `mainArtist` value (= Deezer `collectionArtistName` when available, else
`albumArtist` param, else track artist). Never use `rawArtist` for `album_artist`.
## Listening stats / scrobble system (v2.0)
- **Why separate:** Navidrome stores only a play *count* + *last* play date (no timestamps), so
per-day/month/year stats and a "Wrapped" are impossible from it. NovaSonic *is* the player, so it
records every counted play into its **own** timestamped, multi-user log.
- **Own container `novasonic-scrobble`** (`scrobble/scrobble-server.js`) — deliberately isolated from
the download backend: the backend is heavy (yt-dlp/ffmpeg) and restarts often; an archive needs
uptime + data integrity. Runs on `node:22-slim` with the **built-in `node:sqlite`** (run with
`--experimental-sqlite`; no native build). DB `/data/novasonic-plays.db` in its own volume.
- **Routes:** `POST /scrobble/plays` (batch, **idempotent by uuid**), `GET /scrobble/history`,
`GET /scrobble/stats` (totals, top artists/albums/tracks, day/month/year series, 24h clock),
`DELETE /scrobble/plays?user=` (test cleanup), `GET /scrobble/health`.
- **Multi-user auth:** every request carries the same Subsonic token creds (`u`, `t`, `s`) the app
already uses; the service verifies them via Navidrome **`ping.view`** (cached 5 min) → the stored
`user` is real, not spoofable. `node:sqlite` **throws on extra named params**, so each query gets
exactly the params its SQL references. `from` defaults to all-time (do **not** route `0` through
`_toEpochSec`, which maps `0`→now).
- **Denormalized on purpose:** title/artist/album are stored per play so the archive survives even if
the song is later deleted from Navidrome. Deleting a song does **not** touch the play-log.
- **Capture point (Web + Android):** `logPlay()` fires at the **existing** counted-scrobble moment
(respects the user's `scrobbleMode`, consistent with Last.fm) — **not** a separate 50%/4-min rule.
It runs **in addition to** the Navidrome/Last.fm scrobble, never replacing it. Web:
`src/player/scrobbleLog.js` (localStorage queue) + `subsonicAuthParams()` in `api.js`. Android:
`data/PlayLogClient.kt` (JSON-file queue, **one reused Ktor client**) + `repo.logPlay/flushPlayLog`
+ hook in `PlayerController.scheduleScrobble`. Both queue offline and flush as an **idempotent**
batch (server dedups by uuid) on start / when connectivity returns.
- **Stats view:** Web `src/ui/stats.js` (overlay from Settings), Android `ui/screen/StatsScreen.kt` +
`StatsViewModel.kt` (from a Settings button). **Cover art is resolved client-side** from Navidrome
(`coverUrl`/`coverArtUrl` via `artistId`/`albumId`/`songId`) — the scrobble service stays
cover-agnostic; the stats endpoint just returns the IDs.
- **Config:** `SCROBBLE_URL` env → `window.NS_SCROBBLE_URL` (entrypoint) → `S.cfg.scrobbleUrl` (web) /
`scrobbleUrl` pref (Android), mirroring `backendUrl`. Port **3710**.
- **Deploy gotcha:** the scrobble subdomain **must be excluded from any SSO / forward-auth gateway**
(like the download backend) — it self-authenticates via `ping.view`, and a gateway in front
302-redirects the browser's API calls to the login portal (breaks `fetch` → "nicht erreichbar").
- **Planned:** `/scrobble/wrapped` (yearly story) + optional ListenBrainz relay. See
`docs/scrobble-plan.md`.
## Android offline system
- **Storage:** `context.filesDir/offline/audio/{songId}.{ext}` and `.../covers/{coverArtId}.jpg` — private internal storage, not accessible via file manager.
- **Database:** Room DB `novasonic_offline.db` (version 1) with three tables: `downloaded_tracks` (track metadata + local paths + state), `download_groups` (album/playlist/song group + progress), `group_track_cross_refs` (many-to-many). See [OfflineEntities.kt](android/app/src/main/kotlin/com/novasonic/app/offline/OfflineEntities.kt) and [OfflineDao.kt](android/app/src/main/kotlin/com/novasonic/app/offline/OfflineDao.kt).
- **OfflineRepository** ([OfflineRepository.kt](android/app/src/main/kotlin/com/novasonic/app/offline/OfflineRepository.kt)): holds hot `StateFlow` maps (`_audioMap`, `_coverMap`) keyed by songId/coverArtId for O(1) lookups in `MusicRepository.streamUrl()`. Call `enqueueGroup()` to schedule a download.
- **DownloadWorker** ([DownloadWorker.kt](android/app/src/main/kotlin/com/novasonic/app/offline/DownloadWorker.kt)): `CoroutineWorker` using plain `HttpURLConnection` streaming to `.tmp` → rename. **No `setExpedited()` and no `setForeground()`** — `FOREGROUND_SERVICE_TYPE_DATA_SYNC` is banned on Android 15 (targetSdk=35) and crashes the app; downloads are silent background work.
- **Playback:** `MusicRepository.streamUrl()` checks `offlineRepo.localAudioPath(id)` first; if the file exists it returns a `file://` URI. This applies to every play path — album, playlist, Offline tab — no special offline mode needed.
- **Offline tab:** Library → tab 2 (OFFLINE). Driven by `OfflineViewModel`. Play button on a completed group calls `offlineVm.songsForGroup()` (JOIN query → `DownloadedTrackEntity.toSong()`) then `player.playSongs()`.
## Android navigation, state & insets (hard-won)
- **A `BackHandler` inside a NavHost destination loses back priority to the NavHost.** The Erkunden
(Apple) artist/album are in-screen *overlays* on the `erkunden` destination, not routes — their
`BackHandler` never fired, so one back press popped the whole tab to Home. Fix: the overlay reports
its close action upward via `onOverlayBackChange`, and `AppNavigation` registers a **root-level**
`OnBackPressedCallback` for it (the same mechanism the NowPlaying overlay always used successfully).
Real nav routes (`album/{id}`, `artist/{id}`) are unaffected — `popBackStack()` is correct there.
- **Re-assert root-level back callbacks on `ON_RESUME`, not just on navigation.** Returning from the
background re-registers the NavController's own `OnBackPressedCallback` on **top** of the dispatcher,
which steals back-priority from the NowPlaying/ABS/Erkunden overlays — back then pops the NavHost
(invisibly, to Home) before dismissing the visible overlay. Fix in `AppNavigation`: a `resumeTick`
(`LifecycleEventEffect(ON_RESUME)`) plus `currentBackEntry` are keys on every overlay's
`DisposableEffect`, so each re-adds (bumps itself above the NavController) after a resume or a nav.
- **Overlay state belongs in the ViewModel, not `remember`.** Anything an overlay shows (e.g. the
artist's "all albums" section) is destroyed when the user drills into an album, because the overlay
leaves composition. `rememberSaveable` does **not** save you — it only survives for real nav
destinations. Hoist it into the ViewModel (see `ExploreViewModel.artistAllAlbums`).
- **`bottomBar` insets:** the tab `NavigationBar` absorbs the system-navigation inset. Detail screens
have no tab bar, so the MiniPlayer needs `navigationBarsPadding()` itself — otherwise it sits behind
the phone's gesture/navigation bar.
- **`ModalBottomSheet`:** use `rememberModalBottomSheetState(skipPartiallyExpanded = true)` *and*
`navigationBarsPadding()` on the content, or the bottom-most action (e.g. "Herunterladen") opens
hidden behind the navigation bar and needs an extra drag-up.
- **Reuse the Ktor client.** `MusicRepository.coverArtUrl()/streamUrl()` must go through
`ClientHolder.get(creds)`. Constructing a `SubsonicClient` per call spins up (and never closes) an
`HttpClient` for *every cover art request* — this was the cause of visible scroll/tab-switch lag.
- **Star/favorite is optimistic and global** via `data/StarState.kt`. Toggle through it so every icon
(song rows, NowPlaying, context sheet) flips instantly and rolls back if the API call fails.
- **Deezer artists carry a real photo** (`picture_*`), so artist search cards show it directly — no
album-cover borrowing needed. (The old iTunes artist entities had no `artworkUrl100`, which is why
the `entity=album&limit=1` album-cover fallback exists; it now only runs if a picture is missing.)
## UI / references
When referencing files in chat, use clickable markdown links, not backticks:
`[ytdlp.js](backend/lib/ytdlp.js)`.
+74 -82
View File
@@ -1,70 +1,24 @@
# NovaSonic # NovaSonic
A self-hosted music streaming PWA and Android app for Navidrome / Subsonic-compatible servers. A self-hosted music streaming PWA and Android app for Navidrome / Subsonic-compatible servers.
Built with Vite + vanilla ES modules, served via nginx in Docker. Built with Vite + vanilla ES modules (web) and Jetpack Compose + Media3/ExoPlayer (Android).
--- ---
## Features ## Features
### Music Library - **Library** — Stream from Navidrome / Subsonic; browse artists, albums, playlists, genres, starred, and random; search; star + context menu on every row.
- Stream music from your Navidrome / Subsonic library - **Playback** — Queue with shuffle, repeat, and radio mode (endless similar songs); gapless-style preload; lock-screen / notification controls; Navidrome scrobbling.
- Browse artists, albums, playlists, starred tracks, and random picks - **Lyrics** — Synced and plain lyrics via lrclib.net, auto-fetched and cached per session.
- Sort and filter views with chip filters - **Artist pages** — Hero card, bio / similar artists / top songs, Ticketmaster events, and a Deezer cross-reference showing owned vs. missing tracks. Same-name artists can be **pinned** (Deezer search or a pasted Deezer link/id) to fix the wrong-discography and wrong-photo problem; a pinned artist's similar list comes from Deezer.
- Search / filter bar inside playlist detail and favorites (instant, client-side) - **Playlists** — Create, rename, delete, add/remove tracks, and upload a cover (Web + Android).
- Synced and plain lyrics via LRCLIB (auto-fetched per track) - **Importer & downloads** — Paste a Spotify / YouTube / YouTube Music / SoundCloud link to download via yt-dlp, with Deezer metadata enrichment and duplicate detection.
- Play count display — optional toggle in Settings - **Metadata editor** (web) — Edit tags + cover art; files are renamed/moved and Navidrome is rescanned on save.
- Star and context menu on every song row - **Offline** (Android) — Download albums, playlists, or single songs to private storage; an Offline tab to play and manage them (works without a server connection); downloaded tracks play from disk on every screen.
- **Listening stats** — A separate, self-hosted scrobble service records **timestamped plays** (multi-user; Navidrome only keeps a play *count*). A statistics view (Web + Android, from Settings) shows totals, top artists/tracks/albums with cover art, a day/month/year play series, and a 24h listening clock, plus a **Musik-Match** that compares two users' taste. Runs *in addition to* Navidrome/Last.fm scrobbling.
- **Audiobookshelf** — Browse and stream audiobooks with chapter navigation, speed control, sleep timer, and progress sync.
### Artist Pages Web is an installable PWA (themes, German UI); Android is native Jetpack Compose + Media3/ExoPlayer with a mini player, media/ABS notifications, and Android Auto. See [CHANGELOG.md](CHANGELOG.md) for the full web/Android parity matrix.
- Full-bleed hero card — artist photo as portrait + blurred background (desktop); full-bleed image with name overlay (mobile)
- Bio, similar artists, top songs pulled from Last.fm via Navidrome
- Concert events via Ticketmaster (upcoming shows with venue, date, ticket link)
- Albums cross-referenced against iTunes catalog — shows what's downloaded, partially downloaded, or missing
- Quick actions: play top songs, shuffle all, open concerts
### Playback
- Queue management with shuffle, repeat (all / one), and radio mode (endless random)
- Spotify-style shuffle — pre-shuffles the full queue so every song plays exactly once
- Now Playing overlay with swipe-to-dismiss
- Gapless-style playback — next track pre-buffered 60 seconds before current track ends
- Lock screen / notification media controls (Android / iOS / desktop)
- Scrobbling — reported to Navidrome (configurable: 15 s / 30 s / ⅓ / ⅔ / end)
### Discovery
- iTunes / Last.fm integration — charts, global search, 30-second previews, similar artists, recommendations
- Song Importer — paste a Spotify, YouTube, YouTube Music, or SoundCloud link to preview and download tracks
### Downloads (yt-dlp backend)
- Download individual tracks, full albums, or entire artists
- Sources: YouTube Music (primary), YouTube, SoundCloud, Spotify (via importer)
- iTunes enrichment — album, year, track number, genre, 1000×1000 cover art
- Duplicate detection — skips tracks already present on the server
- Standard filename: `01 - Artist - Title.ext`, organised into `AlbumArtist/Album/` folders
### Metadata Editor
- Edit title, artist, album artist, album, genre, year, track number, disc number
- Update embedded cover art via URL or file upload
- File renamed and moved automatically on save
- Navidrome rescan triggered after every save
### Playlists
- Create, edit, and delete playlists
- Edit name, description, cover art, public/private toggle
- Add / remove tracks; reorder via drag and drop
### Audiobookshelf Integration
- Browse and stream audiobooks from your Audiobookshelf server
- Chapters list, playback speed, sleep timer, progress sync
### App
- PWA — installable on Android / iOS / desktop
- Android APK — native WebView wrapper with Media3 / ExoPlayer backend
- Native OS notification with skip buttons
- Pre-buffers last played track on cold start for instant resume
- Artwork pre-warming so notification never shows blank cover
- Multiple color themes, dark mode, mobile-first responsive layout
- German UI
--- ---
@@ -75,12 +29,13 @@ NovaSonic/
├── src/ ├── src/
│ ├── player/ │ ├── player/
│ │ ├── player.js # Playback, queue, transport, media session, preload │ │ ├── player.js # Playback, queue, transport, media session, preload
│ │ └── nowplaying.js # Now Playing overlay │ │ ├── nowplaying.js # Now Playing overlay + synced lyrics
│ │ └── scrobbleLog.js # Play-log capture + offline queue → scrobble service
│ ├── views/ │ ├── views/
│ │ ├── detail.js # Artist / album detail pages │ │ ├── detail.js # Artist / album detail pages
│ │ ├── views.js # Navigation, page loaders, search │ │ ├── views.js # Navigation, page loaders, search
│ │ ├── events.js # Ticketmaster concert events │ │ ├── events.js # Ticketmaster concert events
│ │ ├── home.js # Home page, artist image cache │ │ ├── home.js # Home page
│ │ ├── search.js # Search, artist/album navigation │ │ ├── search.js # Search, artist/album navigation
│ │ ├── playlists.js # Playlist management │ │ ├── playlists.js # Playlist management
│ │ ├── spotify.js # Spotify importer │ │ ├── spotify.js # Spotify importer
@@ -89,28 +44,41 @@ NovaSonic/
│ │ ├── navigation.js # Client-side router │ │ ├── navigation.js # Client-side router
│ │ └── abs.js # Audiobookshelf integration │ │ └── abs.js # Audiobookshelf integration
│ ├── ui/ │ ├── ui/
│ │ ├── ui.js # Modals, sidebar, settings, context menu │ │ ├── ui.js # Modals, sidebar, context menu
│ │ ├── components.js # Song rows, cards, shared UI │ │ ├── components.js # Song rows, cards, shared UI
│ │ ├── downloads.js # Download modal + job tracker │ │ ├── downloads.js # Download modal + job tracker
│ │ ├── metadata.js # Metadata editor │ │ ├── metadata.js # Metadata editor
│ │ ├── modals.js # Song info, events modals │ │ ├── modals.js # Song info, events modals
│ │ ├── notify.js # Toast notifications │ │ ├── notify.js # Toast notifications
│ │ ├── stats.js # Listening statistics view (overlay)
│ │ └── settings.js # Settings page │ │ └── settings.js # Settings page
│ ├── state.js # Shared mutable state (S object) │ ├── state.js # Shared mutable state (S object)
│ ├── utils.js # md5, esc, formatDur, toast │ ├── utils.js # Helpers (md5, esc, formatDur, toast)
│ ├── api.js # Subsonic API, iTunes API, cover art │ ├── api.js # Subsonic API, Deezer API, cover art
│ └── main.js # App init, audio wiring, window globals │ └── main.js # App init, audio wiring, window globals
├── backend/ ├── backend/
│ ├── novasonic-server.js # Express API: downloads, metadata, events proxy │ ├── novasonic-server.js # Express API: downloads, metadata, events proxy, ABS proxy
│ └── lib/ │ └── lib/
│ ├── config.js # Env var → config object │ ├── config.js # Env var → config object
│ ├── jobs.js # In-memory download job store │ ├── jobs.js # In-memory download job store
│ ├── metadata.js # iTunes lookup, artwork, lyrics, filename helpers │ ├── deezer.js # Deezer metadata: track/album/artist lookups
│ ├── metadata.js # Artwork, filename helpers, duplicate detection
│ ├── ytdlp.js # yt-dlp download + ffmpeg metadata embedding │ ├── ytdlp.js # yt-dlp download + ffmpeg metadata embedding
│ ├── squid.js # Qobuz (squid.wtf) download backend
│ ├── downloader.js # Unified downloadTrack / downloadAlbumTracks │ ├── downloader.js # Unified downloadTrack / downloadAlbumTracks
│ └── romaji.js # Japanese → romaji search index │ └── romaji.js # Japanese → romaji search index
├── android/ # Android APK (WebView + Media3/ExoPlayer) ├── scrobble/ # Isolated listening-stats service (own container + DB)
│ └── scrobble-server.js # node:sqlite play-log: ingest / history / stats / health
├── android/ # Native Android app (Jetpack Compose + Media3)
│ └── app/src/main/kotlin/com/novasonic/app/
│ ├── api/ # SubsonicClient, AbsClient, LrcLibClient, ItunesClient (Deezer-backed)
│ ├── data/ # PrefsStore (DataStore), MusicRepository, StarState
│ ├── offline/ # Room DB, DAO, OfflineRepository, DownloadWorker (offline downloads)
│ ├── player/ # PlayerController, MusicService (Media3)
│ ├── ui/
│ │ ├── screen/ # HomeScreen, NowPlayingScreen, AbsScreen, SettingsScreen, …
│ │ ├── component/ # MiniPlayer, SongRow, SongContextSheet, …
│ │ └── theme/ # Color, Type, Theme
│ └── viewmodel/ # ViewModel per screen
├── public/ ├── public/
│ ├── sw.js # Service worker │ ├── sw.js # Service worker
│ ├── manifest.json # PWA manifest │ ├── manifest.json # PWA manifest
@@ -119,9 +87,10 @@ NovaSonic/
├── styles.css ├── styles.css
├── vite.config.js ├── vite.config.js
├── Dockerfile ├── Dockerfile
├── docker-compose.yml ├── docker-compose.yml # Standard: zieht die fertigen Images aus der Registry
├── docker-compose.dev.yml # Variante: baut lokal aus den Dockerfiles
├── nginx.conf ├── nginx.conf
└── docker-entrypoint.sh # Injects NAVIDROME_URL / BACKEND_URL at runtime └── docker-entrypoint.sh # Injects NAVIDROME_URL / BACKEND_URL / SCROBBLE_URL at runtime
``` ```
--- ---
@@ -141,32 +110,48 @@ Edit `.env`:
```env ```env
NAVIDROME_URL=https://music.yourdomain.com NAVIDROME_URL=https://music.yourdomain.com
BACKEND_URL=https://novasonic-api.yourdomain.com BACKEND_URL=https://novasonic-api.yourdomain.com
SCROBBLE_URL=https://novasonic-scrobble.yourdomain.com # listening-stats service
MUSIC_PATH=/srv/navidrome/music # absolute path to your music folder on the host MUSIC_PATH=/srv/navidrome/music
AUDIO_FMT=mp3 # mp3 | flac | opus | best AUDIO_FMT=mp3 # mp3 | flac | opus | best
AUDIO_QUALITY=0 # 0 = best (yt-dlp) AUDIO_QUALITY=0 # 0 = best (yt-dlp)
MAX_PARALLEL=2 MAX_PARALLEL=2
DOWNLOAD_BACKEND=auto # ytdlp | squid | auto
SQUID_QUALITY=mp3 # mp3 | flac | hi-res
TICKETMASTER_API_KEY= # optional — free key from developer.ticketmaster.com TICKETMASTER_API_KEY= # optional — free key from developer.ticketmaster.com
``` ```
### 2. Start ### 2. Start
```bash ```bash
docker compose pull
docker compose up -d docker compose up -d
``` ```
This starts both the frontend (nginx on port 8080) and the backend (Node.js on port 3700). Route both ports through your reverse proxy. Zieht die drei fertigen Images aus der Registry — nichts wird auf dem Server gebaut. Dafür in der
`.env` `REGISTRY` (und optional `TAG`) setzen; die Images heißen
`$REGISTRY/novasonic-frontend|-backend|-scrobble`. Neue Stände lädt man von der Dev-Maschine mit
`npm run push-images` hoch (bzw. `docker build -t $REGISTRY/<name>:latest <context> && docker push …`
— Kontexte: `.` (frontend), `backend/`, `scrobble/`).
**Selbst bauen statt ziehen** (keine Registry nötig):
```bash
docker compose -f docker-compose.dev.yml up -d --build
```
Baut lokal aus den Dockerfiles; die Deps stecken in den Images, also sind Restarts sofort da und
Rebuilds nach einem `git pull` dank Layer-Cache schnell.
Frontend on port 8080, backend on port 3700, scrobble service on port 3710. Route each through your reverse proxy. **Important:** the scrobble subdomain must *not* sit behind an SSO / forward-auth gateway — it authenticates itself via Navidrome (`ping.view`), and a gateway in front redirects the app's API calls to a login page.
### 3. First launch ### 3. First launch
1. Open the app and enter your Navidrome server URL, username and password 1. Enter your Navidrome server URL, username, and password
2. Optionally add a Last.fm API key in Settings for recommendations and artist bios 2. Optionally add a Last.fm API key in Settings for bios and recommendations
3. Optionally connect Audiobookshelf in Settings to stream audiobooks 3. Optionally connect Audiobookshelf in Settings
4. Optionally add the NovaSonic backend URL in Settings to enable downloads
5. Optionally add the NovaSonic scrobble URL in Settings to record listening stats
--- ---
@@ -178,19 +163,26 @@ This starts both the frontend (nginx on port 8080) and the backend (Node.js on p
|---|---| |---|---|
| `NAVIDROME_URL` | Pre-fills the Navidrome server URL on the login screen | | `NAVIDROME_URL` | Pre-fills the Navidrome server URL on the login screen |
| `BACKEND_URL` | Pre-fills the download backend URL on the login screen | | `BACKEND_URL` | Pre-fills the download backend URL on the login screen |
| `SCROBBLE_URL` | Pre-fills the listening-stats (scrobble) service URL on the login screen |
### Backend container ### Backend container
| Variable | Default | Description | | Variable | Default | Description |
|---|---|---| |---|---|---|
| `PORT` | `3700` | Port the backend listens on | | `PORT` | `3700` | Port the backend listens on |
| `MUSIC_PATH` | `/music` | Absolute path to your Navidrome music folder (mounted as volume) | | `MUSIC_PATH` | `/music` | Absolute path to your Navidrome music folder |
| `AUDIO_FMT` | `mp3` | Download output format (`mp3`, `flac`, `opus`, `best`) | | `AUDIO_FMT` | `mp3` | Download format (`mp3`, `flac`, `opus`, `best`) |
| `AUDIO_QUALITY` | `0` | yt-dlp audio quality (0 = best) | | `AUDIO_QUALITY` | `0` | yt-dlp audio quality (0 = best) |
| `MAX_PARALLEL` | `2` | Max concurrent download jobs | | `MAX_PARALLEL` | `2` | Max concurrent download jobs |
| `DOWNLOAD_BACKEND` | `auto` | `ytdlp` / `squid` / `auto` (tries Qobuz first, falls back to yt-dlp) | | `TICKETMASTER_API_KEY` | — | Free key from [developer.ticketmaster.com](https://developer.ticketmaster.com) |
| `SQUID_QUALITY` | `mp3` | Qobuz quality: `mp3`, `flac`, `hi-res` |
| `TICKETMASTER_API_KEY` | — | Free API key from [developer.ticketmaster.com](https://developer.ticketmaster.com) — enables concert events on artist pages | ### Scrobble container
| Variable | Default | Description |
|---|---|---|
| `PORT` | `3710` | Port the scrobble service listens on |
| `DATA_PATH` | `/data` | Where the play-log SQLite DB is stored (own volume) |
| `NAVIDROME_URL` | — | Used to verify user credentials via `ping.view` (multi-user auth) |
--- ---
+38 -2
View File
@@ -14,8 +14,35 @@ android {
applicationId = "com.novasonic.app" applicationId = "com.novasonic.app"
minSdk = 26 minSdk = 26
targetSdk = 35 targetSdk = 35
versionCode = 1 versionCode = 30
versionName = "1.0" versionName = "1.27"
// Host der eigenen NovaSonic-Web-App — Ziel der geteilten Links. Einmal in
// gradle.properties setzen (novasonicHost=music.example.com); ohne Angabe bleibt der
// Platzhalter stehen und der App-Link greift schlicht nicht.
val host1 = (project.findProperty("novasonicHost") as String?) ?: "music.example.com"
// Zweiter Host fuer einen Domainwechsel: solange beide Adressen erreichbar sind, oeffnen
// Links von der alten UND der neuen in der App. Ohne Angabe wird host1 wiederholt — ein
// doppelter Eintrag ist harmlos, ein Platzhalter-Host waere es NICHT: auf Android 11 und
// aelter verifiziert das System nur, wenn ALLE angegebenen Hosts eine gueltige
// assetlinks.json ausliefern, ein toter Host wuerde also alle blockieren.
val host2 = (project.findProperty("novasonicHost2") as String?) ?: host1
manifestPlaceholders["shareHost"] = host1
manifestPlaceholders["shareHost2"] = host2
// Derselbe Host auch fuer AUSGEHENDE Links. Er steht ohnehin schon fest im Manifest, eine
// zusaetzliche Einstellung in der App waere also nur eine weitere Adresse zum Pflegen —
// und eine, die vom Manifest abweichen koennte, ohne dass es jemand merkt.
buildConfigField("String", "SHARE_HOST", "\"$host1\"")
// Vorgabe-Adressen fuer Backend und Scrobble-Dienst. Sie stehen ohnehin in der
// docker-compose.yml — sie zusaetzlich auf jedem Geraet einzutippen ist Arbeit ohne Nutzen.
// Leer gelassen verhaelt sich die App wie bisher (Felder sichtbar, nichts vorbelegt).
// Zugangsdaten bleiben bewusst aussen vor: die gehoeren pro Person, nicht ins APK.
val backendUrl = (project.findProperty("novasonicBackend") as String?) ?: ""
val scrobbleUrl = (project.findProperty("novasonicScrobble") as String?) ?: ""
val navidromeUrl= (project.findProperty("novasonicNavidrome") as String?) ?: ""
buildConfigField("String", "DEFAULT_BACKEND_URL", "\"$backendUrl\"")
buildConfigField("String", "DEFAULT_SCROBBLE_URL", "\"$scrobbleUrl\"")
buildConfigField("String", "DEFAULT_ND_URL", "\"$navidromeUrl\"")
} }
buildFeatures { buildFeatures {
@@ -87,12 +114,21 @@ dependencies {
implementation(libs.room.ktx) implementation(libs.room.ktx)
ksp(libs.room.compiler) ksp(libs.room.compiler)
// WorkManager
implementation(libs.work.runtime.ktx)
// DataStore // DataStore
implementation(libs.datastore.preferences) implementation(libs.datastore.preferences)
// Coil // Coil
implementation(libs.coil.compose) implementation(libs.coil.compose)
// Palette (dominant cover color extraction in NowPlaying)
implementation("androidx.palette:palette-ktx:1.0.0")
// MediaStyle for ABS notification (already transitive via media3-session, made explicit)
implementation("androidx.media:media:1.7.0")
// Google Fonts (Outfit) // Google Fonts (Outfit)
implementation(libs.compose.ui.google.fonts) implementation(libs.compose.ui.google.fonts)
} }
+6
View File
@@ -6,3 +6,9 @@
# Keep Media3 session / exoplayer classes used by reflection / service binding. # Keep Media3 session / exoplayer classes used by reflection / service binding.
-keep class androidx.media3.** { *; } -keep class androidx.media3.** { *; }
-keep class com.google.android.exoplayer2.** { *; } -keep class com.google.android.exoplayer2.** { *; }
# Ktors Logging referenziert ueber slf4j den Binder aus slf4j 1.x. Auf Android existiert der nicht
# (slf4j 2.x sucht Implementierungen per ServiceLoader, und wir binden ohnehin keine), deshalb bricht
# R8 den Release-Build mit "Missing class org.slf4j.impl.StaticLoggerBinder" ab. Die Referenz ist zur
# Laufzeit unerreichbar — slf4j faengt das Fehlen selbst ab und schaltet auf einen No-op-Logger.
-dontwarn org.slf4j.**
+28 -1
View File
@@ -5,9 +5,11 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- In-app updater: install a downloaded APK (user still confirms the install) -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<application <application
android:name=".NovaSonicApp" android:name=".NovaSonicApp"
@@ -31,6 +33,19 @@
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
<!-- Geteilte Links (https://<host>/?song=…) direkt in der App oeffnen.
autoVerify greift erst, wenn unter https://<host>/.well-known/assetlinks.json der
SHA-256 des RELEASE-Signaturschluessels hinterlegt ist. Ohne das bleibt der Filter
wirkungslos, bis der Nutzer die App in den Systemeinstellungen unter
"Standardmaessig oeffnen" fuer diese Domain zulaesst. -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https" android:host="${shareHost}"/>
<data android:scheme="https" android:host="${shareHost2}"/>
</intent-filter>
</activity> </activity>
<service <service
@@ -43,6 +58,18 @@
</intent-filter> </intent-filter>
</service> </service>
<!-- FileProvider — hands the downloaded update APK to the system installer -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
<!-- Android Auto --> <!-- Android Auto -->
<meta-data <meta-data
android:name="com.google.android.gms.car.application" android:name="com.google.android.gms.car.application"
@@ -2,7 +2,14 @@ package com.novasonic.app
import android.app.Application import android.app.Application
import com.novasonic.app.data.MusicRepository import com.novasonic.app.data.MusicRepository
import com.novasonic.app.offline.OfflineRepository
import com.novasonic.app.player.AbsPlayerController
import com.novasonic.app.player.PlayerController import com.novasonic.app.player.PlayerController
import com.novasonic.app.player.PreviewController
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
class NovaSonicApp : Application() { class NovaSonicApp : Application() {
@@ -10,12 +17,52 @@ class NovaSonicApp : Application() {
private set private set
lateinit var playerController: PlayerController lateinit var playerController: PlayerController
private set private set
lateinit var absPlayerController: AbsPlayerController
private set
lateinit var offlineRepository: OfflineRepository
private set
// 30s preview player — app-level so its control bar survives navigation (see AppNavigation).
val previewController: PreviewController = PreviewController()
/**
* Raeumt den Cache nach einem App-Update einmalig auf.
*
* Im cacheDir liegen Coils Bildspeicher (Cover) und heruntergeladene APK-Updates — beides
* jederzeit neu beschaffbar. Nach einem Update konnten dort Reste liegen, die zu alten Anzeigen
* fuehrten; die einzige Abhilfe war bisher "Cache leeren" von Hand in den Systemeinstellungen,
* was man einem normalen Nutzer nicht erklaeren moechte. Das passiert jetzt automatisch und
* ausschliesslich beim Versionswechsel, nicht im laufenden Betrieb — sonst waeren die Cover bei
* jedem Start neu zu laden.
*
* Offline-Downloads sind NICHT betroffen: die liegen unter filesDir/offline, nicht im cacheDir.
*/
private fun cacheNachUpdateLeeren() {
val prefs = getSharedPreferences("app_state", MODE_PRIVATE)
val zuletzt = prefs.getInt("last_version_code", -1)
val jetzt = BuildConfig.VERSION_CODE
if (zuletzt == jetzt) return
if (zuletzt != -1) {
runCatching { cacheDir.deleteRecursively() }
.onSuccess { android.util.Log.i("NsCache", "Cache nach Update $zuletzt -> $jetzt geleert") }
.onFailure { android.util.Log.w("NsCache", "Cache-Leeren fehlgeschlagen", it) }
}
prefs.edit().putInt("last_version_code", jetzt).apply()
}
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
cacheNachUpdateLeeren()
offlineRepository = OfflineRepository(applicationContext) // must be first
repository = MusicRepository(applicationContext) repository = MusicRepository(applicationContext)
playerController = PlayerController(applicationContext, repository) playerController = PlayerController(applicationContext, repository)
playerController.connect() playerController.connect()
absPlayerController = AbsPlayerController(applicationContext)
// Angefangene Downloads weiterlaufen lassen (grosse Playlists brauchen viele Laeufe).
offlineRepository.setzeUnvollstaendigeFort()
// Flush any plays queued while offline to the scrobble service.
CoroutineScope(Dispatchers.IO + SupervisorJob()).launch {
runCatching { repository.flushPlayLog() }
}
} }
} }
@@ -0,0 +1,205 @@
package com.novasonic.app.api
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.android.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.client.statement.HttpResponse
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
@Serializable
data class AbsLibrary(
val id: String = "",
val name: String = "",
val mediaType: String = "book",
)
@Serializable
data class AbsLibrariesResponse(val libraries: List<AbsLibrary> = emptyList())
@Serializable
data class AbsMediaMetadata(
val title: String? = null,
val authorName: String? = null,
val description: String? = null,
)
@Serializable
data class AbsMedia(
val metadata: AbsMediaMetadata = AbsMediaMetadata(),
val duration: Double = 0.0,
val numFiles: Int = 0,
val chapters: List<AbsChapter> = emptyList(),
)
@Serializable
data class AbsLibraryItem(
val id: String = "",
val media: AbsMedia = AbsMedia(),
)
@Serializable
data class AbsItemsResponse(
val results: List<AbsLibraryItem> = emptyList(),
val total: Int = 0,
)
@Serializable
data class AbsSearchBookResult(
val libraryItem: AbsLibraryItem = AbsLibraryItem(),
)
@Serializable
data class AbsSearchResponse(
val book: List<AbsSearchBookResult> = emptyList(),
)
@Serializable
data class AbsChapter(
val id: Int = 0,
val start: Double = 0.0,
val end: Double = 0.0,
val title: String = "",
)
@Serializable
data class AbsAudioTrack(
val index: Int = 0,
val startOffset: Double = 0.0,
val duration: Double = 0.0,
val contentUrl: String = "",
val mimeType: String = "audio/mpeg",
)
@Serializable
data class AbsPlaySession(
val id: String = "",
val audioTracks: List<AbsAudioTrack> = emptyList(),
val chapters: List<AbsChapter> = emptyList(),
val currentTime: Double = 0.0,
)
@Serializable
data class AbsProgress(
val currentTime: Double = 0.0,
val duration: Double = 0.0,
val progress: Double = 0.0,
val isFinished: Boolean = false,
)
class AbsClient(
val absUrl: String,
val apiKey: String,
private val backendUrl: String = "",
) {
private val http = HttpClient(Android) {
install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true; isLenient = true }) }
install(HttpTimeout) { requestTimeoutMillis = 30_000; connectTimeoutMillis = 8_000 }
}
private suspend fun apiGet(path: String): HttpResponse =
if (backendUrl.isNotBlank()) {
http.get("$backendUrl/api/abs-proxy$path") {
header("X-ABS-URL", absUrl)
header("X-ABS-Token", apiKey)
}
} else {
http.get("$absUrl$path") {
header("Authorization", "Bearer $apiKey")
}
}
private suspend fun apiPost(path: String, jsonBody: String): HttpResponse =
if (backendUrl.isNotBlank()) {
http.post("$backendUrl/api/abs-proxy$path") {
header("X-ABS-URL", absUrl)
header("X-ABS-Token", apiKey)
contentType(ContentType.Application.Json)
setBody(jsonBody)
}
} else {
http.post("$absUrl$path") {
header("Authorization", "Bearer $apiKey")
contentType(ContentType.Application.Json)
setBody(jsonBody)
}
}
private suspend fun apiPatch(path: String, jsonBody: String): HttpResponse =
if (backendUrl.isNotBlank()) {
http.patch("$backendUrl/api/abs-proxy$path") {
header("X-ABS-URL", absUrl)
header("X-ABS-Token", apiKey)
contentType(ContentType.Application.Json)
setBody(jsonBody)
}
} else {
http.patch("$absUrl$path") {
header("Authorization", "Bearer $apiKey")
contentType(ContentType.Application.Json)
setBody(jsonBody)
}
}
suspend fun ping(): Boolean = runCatching { apiGet("/api/me").status == HttpStatusCode.OK }.getOrDefault(false)
suspend fun getLibraries(): List<AbsLibrary> = runCatching {
apiGet("/api/libraries").body<AbsLibrariesResponse>().libraries
}.getOrDefault(emptyList())
suspend fun getLibraryItems(libId: String, page: Int = 0): AbsItemsResponse = runCatching {
apiGet("/api/libraries/$libId/items?expanded=1&limit=50&page=$page&sort=media.metadata.title&asc=1")
.body<AbsItemsResponse>()
}.getOrDefault(AbsItemsResponse())
suspend fun searchLibraryItems(libId: String, query: String): List<AbsLibraryItem> = runCatching {
val q = java.net.URLEncoder.encode(query.trim(), "UTF-8")
apiGet("/api/libraries/$libId/search?q=$q&limit=40")
.body<AbsSearchResponse>().book.map { it.libraryItem }
}.getOrDefault(emptyList())
suspend fun getItemChapters(itemId: String): List<AbsChapter> = runCatching {
apiGet("/api/items/$itemId?expanded=1").body<AbsLibraryItem>().media.chapters
}.getOrDefault(emptyList())
suspend fun startSession(itemId: String): AbsPlaySession = runCatching {
apiPost(
"/api/items/$itemId/play",
"""{"deviceInfo":{"clientName":"NovaSonic","clientVersion":"1.0"},"supportedMimeTypes":["audio/mpeg","audio/mp4","audio/aac","audio/ogg","audio/flac","audio/m4b"],"mediaPlayer":"html5","forceDirectPlay":true,"forceTranscode":false}"""
).body<AbsPlaySession>()
}.getOrThrow()
suspend fun closeSession(sessionId: String) {
runCatching { apiPost("/api/session/$sessionId/close", "{}") }
}
suspend fun getProgress(itemId: String): AbsProgress? = runCatching {
apiGet("/api/me/progress/$itemId").body<AbsProgress>()
}.getOrNull()
suspend fun saveProgress(itemId: String, currentTime: Double, duration: Double) {
val progress = if (duration > 0) (currentTime / duration).coerceAtMost(1.0) else 0.0
val finished = progress >= 0.99
runCatching {
apiPatch(
"/api/me/progress/$itemId",
"""{"currentTime":$currentTime,"duration":$duration,"progress":$progress,"isFinished":$finished,"lastUpdate":${System.currentTimeMillis()}}"""
)
}
}
fun coverUrl(itemId: String): String =
"$absUrl/api/items/$itemId/cover?token=${java.net.URLEncoder.encode(apiKey, "UTF-8")}"
fun audioTrackUrl(contentUrl: String): String {
val sep = if (contentUrl.contains('?')) "&" else "?"
return "$absUrl$contentUrl${sep}token=${java.net.URLEncoder.encode(apiKey, "UTF-8")}"
}
fun close() = http.close()
}
@@ -0,0 +1,59 @@
package com.novasonic.app.api
import com.novasonic.app.api.model.ArtistOverride
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.android.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
/**
* Reads/writes the shared artist-pin overrides on the download backend
* (GET/POST /api/artist-overrides, DELETE /api/artist-overrides/:id).
* The pins fix same-name artist collisions; see [ArtistOverride].
*/
class ArtistOverrideClient(private val backendUrl: String) {
private val http = HttpClient(Android) {
install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true; coerceInputValues = true }) }
install(HttpTimeout) { requestTimeoutMillis = 15_000; connectTimeoutMillis = 8_000 }
}
private fun base() = backendUrl.trimEnd('/')
@Serializable
private data class SetReq(
val ndArtistId: String,
val deezerArtistId: String,
val name: String,
val image: String,
val fanCount: Long?,
)
/** Full map { ndArtistId -> override }. */
suspend fun loadAll(): Map<String, ArtistOverride> =
http.get("${base()}/api/artist-overrides").body()
/** Upsert a pin. Returns true on 2xx. */
suspend fun set(ndArtistId: String, ov: ArtistOverride): Boolean {
val resp: HttpResponse = http.post("${base()}/api/artist-overrides") {
contentType(ContentType.Application.Json)
setBody(SetReq(ndArtistId, ov.deezerArtistId, ov.name, ov.image, ov.fanCount))
}
return resp.status.isSuccess()
}
/** Remove a pin. Returns true on 2xx. */
suspend fun remove(ndArtistId: String): Boolean {
val resp: HttpResponse = http.delete("${base()}/api/artist-overrides/${ndArtistId.encodeURLPath()}")
return resp.status.isSuccess()
}
fun close() = http.close()
}
@@ -0,0 +1,31 @@
package com.novasonic.app.api
import com.novasonic.app.api.model.ConcertEvent
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.android.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.Json
object EventsClient {
private val http = HttpClient(Android) {
// Surface non-2xx as a real exception (e.g. an SSO redirect / HTML login page) instead of
// letting .body() fail obscurely — the ViewModel turns it into a visible "load failed".
expectSuccess = true
install(HttpTimeout) { requestTimeoutMillis = 15_000; connectTimeoutMillis = 10_000 }
install(ContentNegotiation) {
json(Json { ignoreUnknownKeys = true; coerceInputValues = true })
}
}
suspend fun fetchEvents(backendUrl: String, artistName: String): List<ConcertEvent> {
if (backendUrl.isBlank()) return emptyList()
val base = backendUrl.trimEnd('/')
val encoded = java.net.URLEncoder.encode(artistName, "UTF-8")
return http.get("$base/api/events/$encoded").body()
}
}
@@ -8,6 +8,7 @@ import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.http.* import io.ktor.http.*
import io.ktor.http.isSuccess
import io.ktor.serialization.kotlinx.json.* import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
@@ -54,5 +55,18 @@ class ImporterClient(private val backendUrl: String) {
suspend fun status(jobId: String): DownloadStatus = suspend fun status(jobId: String): DownloadStatus =
http.get("${base()}/api/status/$jobId").body() http.get("${base()}/api/status/$jobId").body()
/**
* Loescht einen Song endgueltig von der Platte — derselbe Endpunkt, den der Web-Client nutzt.
* Das Backend braucht die Navidrome-Zugangsdaten, weil es den Dateipfad ueber getSong aufloest.
* Wirft bei HTTP != 2xx (Ktor `expectSuccess` ist hier aus, deshalb der explizite Check).
*/
suspend fun deleteSong(ndUrl: String, user: String, pass: String, songId: String) {
val res = http.post("${base()}/api/delete-song") {
contentType(ContentType.Application.Json)
setBody(DeleteSongRequest(ndUrl.trimEnd('/'), user, pass, songId))
}
if (!res.status.isSuccess()) error("HTTP ${res.status.value}")
}
fun close() = http.close() fun close() = http.close()
} }
@@ -8,63 +8,107 @@ import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.http.ContentType import io.ktor.http.ContentType
import io.ktor.serialization.kotlinx.json.* import io.ktor.serialization.kotlinx.json.*
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
/**
* Metadata/search client. Backed by **Deezer** (api.deezer.com) — Apple's iTunes /search
* returns 403 from datacenter IPs, and Deezer keeps the phone + web PWA on the *same* source
* (identical naming + explicit versions). Deezer responses are mapped to the legacy ItunesItem
* shape (see DeezerModels.kt) so the screens/view models did not change. The public method names
* are kept for the same reason.
*/
object ItunesClient { object ItunesClient {
private const val BASE = "https://api.deezer.com"
private val http = HttpClient(Android) { private val http = HttpClient(Android) {
install(ContentNegotiation) { install(ContentNegotiation) {
// iTunes returns text/javascript instead of application/json — accept any content type
json(Json { ignoreUnknownKeys = true; coerceInputValues = true }, contentType = ContentType.Any) json(Json { ignoreUnknownKeys = true; coerceInputValues = true }, contentType = ContentType.Any)
} }
} }
/**
* Combined search. Deezer splits by type, so `entity` "album" hits /search/album; anything else
* runs tracks + albums + artists in parallel and merges them (the view model filters by wrapperType).
*/
suspend fun search( suspend fun search(
query: String, query: String,
entity: String = "musicTrack,album,musicArtist", entity: String = "musicTrack,album,musicArtist",
limit: Int = 30, limit: Int = 30,
country: String = "us", country: String = "us",
): ItunesSearchResponse = http.get("https://itunes.apple.com/search") { ): ItunesSearchResponse {
parameter("term", query) if (entity == "album") {
parameter("media", "music") val albums: DzList<DzAlbum> = http.get("$BASE/search/album") {
parameter("entity", entity) parameter("q", query); parameter("limit", limit)
parameter("limit", limit)
parameter("country", country)
}.body() }.body()
return ItunesSearchResponse(results = albums.data.map { it.toItunesItem() })
suspend fun lookupAlbum(collectionId: Long): List<ItunesItem> { }
val resp: ItunesSearchResponse = http.get("https://itunes.apple.com/lookup") { return coroutineScope {
parameter("id", collectionId) val tracksD = async { runCatching { http.get("$BASE/search") { parameter("q", query); parameter("limit", limit) }.body<DzList<DzTrack>>().data }.getOrDefault(emptyList()) }
parameter("entity", "song") val albumsD = async { runCatching { http.get("$BASE/search/album") { parameter("q", query); parameter("limit", 12) }.body<DzList<DzAlbum>>().data }.getOrDefault(emptyList()) }
}.body() val artistsD = async { runCatching { http.get("$BASE/search/artist") { parameter("q", query); parameter("limit", 8) }.body<DzList<DzArtist>>().data }.getOrDefault(emptyList()) }
// First result is the album itself; rest are tracks // Deezer doesn't rank artists by popularity — sort by nb_fan so a name collision
return resp.results.filter { it.kind == "song" } // (5× "Joji") resolves to the artist the user means (real Joji has 559k fans, not 62).
val results = artistsD.await().sortedByDescending { it.nb_fan ?: 0 }.map { it.toItunesItem() } +
albumsD.await().map { it.toItunesItem() } +
tracksD.await().map { it.toItunesItem() }
ItunesSearchResponse(results = results)
}
} }
/** All albums for an iTunes artist */ /** All tracks of a Deezer album, in the ItunesItem song shape. */
suspend fun lookupAlbum(collectionId: Long): List<ItunesItem> {
val album: DzAlbum = http.get("$BASE/album/$collectionId").body()
return album.tracks?.data.orEmpty().mapIndexed { i, t -> t.toAlbumTrackItem(album, i) }
}
/** A Deezer artist's full discography — albums, EPs AND singles, matching what Deezer's own
* artist page shows. Ordered albums → EPs → singles (Deezer returns newest-first within each). */
suspend fun lookupArtistAlbums(artistId: Long): List<ItunesItem> { suspend fun lookupArtistAlbums(artistId: Long): List<ItunesItem> {
val resp: ItunesSearchResponse = http.get("https://itunes.apple.com/lookup") { val albums: DzList<DzAlbum> = http.get("$BASE/artist/$artistId/albums") {
parameter("id", artistId)
parameter("entity", "album")
parameter("limit", 200) parameter("limit", 200)
}.body() }.body()
return resp.results.filter { it.wrapperType == "collection" } val rank = { rt: String? -> when (rt) { "album" -> 0; "ep" -> 1; "single" -> 2; else -> 3 } }
return albums.data.sortedBy { rank(it.record_type) }.map { it.toItunesItem() }
} }
/** Worldwide top tracks for an iTunes artist */ /**
* A single Deezer artist by id (name / picture / fan count), as an ItunesItem. The reliable
* route when /search/artist can't surface a low-profile same-name artist — used by the
* artist-pin "paste Deezer link/id" flow. Null on a bad id / error.
*/
suspend fun lookupArtist(artistId: Long): ItunesItem? {
val a = runCatching { http.get("$BASE/artist/$artistId").body<DzArtist>() }.getOrNull()
return if (a?.id != null) a.toItunesItem() else null
}
/** Top tracks for a Deezer artist. */
suspend fun lookupArtistTopTracks(artistId: Long, limit: Int = 10): List<ItunesItem> { suspend fun lookupArtistTopTracks(artistId: Long, limit: Int = 10): List<ItunesItem> {
val resp: ItunesSearchResponse = http.get("https://itunes.apple.com/lookup") { val tracks: DzList<DzTrack> = http.get("$BASE/artist/$artistId/top") {
parameter("id", artistId) parameter("limit", limit)
parameter("entity", "musicTrack")
parameter("limit", limit + 1) // first result is the artist itself
}.body() }.body()
return resp.results.filter { it.wrapperType == "track" && it.kind == "song" }.take(limit) return tracks.data.map { it.toItunesItem() }
} }
/** Top albums RSS feed for a given country */ /**
* Related Deezer artists (real pictures + fan counts). Used for the "Similar Artists" row when
* a pin is active — Last.fm's similar list is keyed to the (possibly merged/wrong) Navidrome
* artist, so it goes "weird"; Deezer's related are correct for the pinned artist.
*/
suspend fun lookupRelatedArtists(artistId: Long, limit: Int = 12): List<ItunesItem> {
val artists: DzList<DzArtist> = http.get("$BASE/artist/$artistId/related") {
parameter("limit", limit)
}.body()
return artists.data.map { it.toItunesItem() }
}
/** "Neu & Beliebt" — Deezer's global album chart, mapped to the RSS-entry shape. */
suspend fun topAlbums(country: String = "us", limit: Int = 25): List<ItunesRssEntry> { suspend fun topAlbums(country: String = "us", limit: Int = 25): List<ItunesRssEntry> {
val resp: ItunesRssResponse = val albums: DzList<DzAlbum> = http.get("$BASE/chart/0/albums") {
http.get("https://itunes.apple.com/$country/rss/topalbums/limit=$limit/json").body() parameter("limit", limit)
return resp.feed?.entry ?: emptyList() }.body()
return albums.data.map { it.toRssEntry() }
} }
} }
@@ -1,12 +1,17 @@
package com.novasonic.app.api package com.novasonic.app.api
import io.ktor.client.* import io.ktor.client.*
import io.ktor.client.call.* import io.ktor.client.call.*
import io.ktor.client.engine.android.* import io.ktor.client.engine.android.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.* import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.SerialName import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
@@ -22,6 +27,7 @@ data class LrcLibResponse(
val syncedLyrics: String? = null, val syncedLyrics: String? = null,
) )
data class LrcLine(val timeMs: Long, val text: String) data class LrcLine(val timeMs: Long, val text: String)
fun parseLrc(lrc: String): List<LrcLine> { fun parseLrc(lrc: String): List<LrcLine> {
@@ -46,19 +52,105 @@ object LrcLibClient {
install(ContentNegotiation) { install(ContentNegotiation) {
json(Json { ignoreUnknownKeys = true; isLenient = true }) json(Json { ignoreUnknownKeys = true; isLenient = true })
} }
install(HttpTimeout) {
requestTimeoutMillis = 8_000
connectTimeoutMillis = 5_000
socketTimeoutMillis = 8_000
} }
// lrclib asks clients to identify themselves; a proper UA also avoids being throttled.
install(UserAgent) { agent = "NovaSonic/1.0 (+https://gitea.honeyy.duckdns.org/Docker/NovaSonic)" }
}
private val cache = HashMap<String, LrcLibResponse?>()
// Per-song lock so a prefetch + an on-open load don't both fire the whole cascade (→ throttling).
private val locks = java.util.concurrent.ConcurrentHashMap<String, Mutex>()
suspend fun getLyrics( suspend fun getLyrics(
artist: String, artist: String,
title: String, title: String,
album: String?, album: String?,
durationSecs: Int?, durationSecs: Int?,
): LrcLibResponse? = runCatching { ): LrcLibResponse? {
client.get("https://lrclib.net/api/get") { val cacheKey = "$artist|$title"
if (cache.containsKey(cacheKey)) return cache[cacheKey]
val mutex = locks.getOrPut(cacheKey) { Mutex() }
return mutex.withLock { getLyricsInner(artist, title, album, durationSecs, cacheKey) }
}
private suspend fun getLyricsInner(
artist: String,
title: String,
album: String?,
durationSecs: Int?,
cacheKey: String,
): LrcLibResponse? {
if (cache.containsKey(cacheKey)) return cache[cacheKey] // populated while we waited on the lock
// 1a. lrclib exact match with duration
val exact = runCatching {
val resp = client.get("https://lrclib.net/api/get") {
parameter("artist_name", artist) parameter("artist_name", artist)
parameter("track_name", title) parameter("track_name", title)
if (!album.isNullOrBlank()) parameter("album_name", album) if (!album.isNullOrBlank()) parameter("album_name", album)
if (durationSecs != null && durationSecs > 0) parameter("duration", durationSecs) if (durationSecs != null && durationSecs > 0) parameter("duration", durationSecs)
}.body<LrcLibResponse>() }
if (resp.status == HttpStatusCode.OK) resp.body<LrcLibResponse>() else null
}.getOrNull() }.getOrNull()
if (exact.hasContent()) return exact.also { cache[cacheKey] = it }
// 1b. lrclib exact match without duration — handles version mismatches (e.g. 5:58 file vs 4:24 in lrclib)
val exactNoDur = if (durationSecs != null && !album.isNullOrBlank()) runCatching {
val resp = client.get("https://lrclib.net/api/get") {
parameter("artist_name", artist)
parameter("track_name", title)
parameter("album_name", album)
}
if (resp.status == HttpStatusCode.OK) resp.body<LrcLibResponse>() else null
}.getOrNull() else null
if (exactNoDur.hasContent()) return exactNoDur.also { cache[cacheKey] = it }
// 2+3. lrclib search — artist+title and title-only in parallel (2 requests, not 3)
val lrclibResult = coroutineScope {
val artistDef = async {
runCatching {
val resp = client.get("https://lrclib.net/api/search") {
parameter("track_name", title)
if (artist.isNotBlank()) parameter("artist_name", artist)
}
if (resp.status == HttpStatusCode.OK) resp.body<List<LrcLibResponse>>() else null
}.getOrNull()
}
val titleDef = async {
runCatching {
val resp = client.get("https://lrclib.net/api/search") {
parameter("track_name", title)
}
if (resp.status == HttpStatusCode.OK) resp.body<List<LrcLibResponse>>() else null
}.getOrNull()
}
bestMatch(artistDef.await(), durationSecs)
?: bestMatch(titleDef.await(), durationSecs)
}
cache[cacheKey] = lrclibResult
return lrclibResult
}
private fun LrcLibResponse?.hasContent() =
this != null && (instrumental || !syncedLyrics.isNullOrBlank() || !plainLyrics.isNullOrBlank())
private fun bestMatch(candidates: List<LrcLibResponse>?, durationSecs: Int?): LrcLibResponse? {
if (candidates.isNullOrEmpty()) return null
val synced = candidates.filter { !it.syncedLyrics.isNullOrBlank() }
val pool = synced.ifEmpty { candidates }
return if (durationSecs != null && durationSecs > 0) {
val best = pool.minByOrNull { kotlin.math.abs(it.duration - durationSecs) }
?: return synced.firstOrNull() ?: candidates.firstOrNull()
if (kotlin.math.abs(best.duration - durationSecs) <= 5.0) best
else synced.firstOrNull() ?: candidates.firstOrNull()
} else {
pool.firstOrNull()
}
}
} }
@@ -0,0 +1,51 @@
package com.novasonic.app.api
import com.novasonic.app.api.model.ArtistRef
import com.novasonic.app.api.model.ArtistReleasesRequest
import com.novasonic.app.api.model.ArtistKonzerteRequest
import com.novasonic.app.api.model.ArtistKonzerteResponse
import com.novasonic.app.api.model.ArtistReleasesResponse
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.android.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.Json
/**
* Neue Veröffentlichungen der gefolgten Künstler. Die Deezer-Auflösung macht das Backend — dort
* liegen auch die Künstler-Pins, und der Cache gilt dann für alle Geräte gemeinsam statt pro App.
*/
object ReleasesClient {
private val http = HttpClient(Android) {
expectSuccess = true
// Der erste Aufruf kann dauern: das Backend holt pro Künstler die Deezer-Diskografie.
// Danach liegt es dort im Cache.
install(HttpTimeout) { requestTimeoutMillis = 60_000; connectTimeoutMillis = 10_000 }
install(ContentNegotiation) {
json(Json { ignoreUnknownKeys = true; coerceInputValues = true })
}
}
suspend fun fetch(backendUrl: String, artists: List<ArtistRef>, days: Int): ArtistReleasesResponse {
if (backendUrl.isBlank() || artists.isEmpty()) return ArtistReleasesResponse()
return http.post("${backendUrl.trimEnd('/')}/api/artist-releases") {
contentType(ContentType.Application.Json)
setBody(ArtistReleasesRequest(artists, days))
}.body()
}
/** Anstehende Konzerte derselben Kuenstler — gleicher Weg, anderer Endpunkt. */
suspend fun konzerte(backendUrl: String, artists: List<ArtistRef>): ArtistKonzerteResponse {
if (backendUrl.isBlank() || artists.isEmpty()) return ArtistKonzerteResponse()
// Ohne `days`: das Backend liefert alles Angekuendigte.
return http.post("${backendUrl.trimEnd('/')}/api/artist-concerts") {
contentType(ContentType.Application.Json)
setBody(ArtistKonzerteRequest(artists))
}.body()
}
}
@@ -8,7 +8,10 @@ import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.* import io.ktor.client.plugins.logging.*
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.client.request.forms.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.* import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import java.security.MessageDigest import java.security.MessageDigest
import kotlin.random.Random import kotlin.random.Random
@@ -133,6 +136,9 @@ class SubsonicClient(
suspend fun getRandomSongs(size: Int = 50): List<Song> = suspend fun getRandomSongs(size: Int = 50): List<Song> =
get("getRandomSongs.view", mapOf("size" to size)).randomSongs?.song ?: emptyList() get("getRandomSongs.view", mapOf("size" to size)).randomSongs?.song ?: emptyList()
suspend fun getSimilarSongs(songId: String, count: Int = 20): List<Song> =
get("getSimilarSongs2.view", mapOf("id" to songId, "count" to count)).similarSongs2?.song ?: emptyList()
suspend fun star(id: String) = get("star.view", mapOf("id" to id)) suspend fun star(id: String) = get("star.view", mapOf("id" to id))
suspend fun unstar(id: String) = get("unstar.view", mapOf("id" to id)) suspend fun unstar(id: String) = get("unstar.view", mapOf("id" to id))
@@ -143,9 +149,16 @@ class SubsonicClient(
get("getArtistInfo2.view", mapOf("id" to id, "count" to count)).artistInfo2 get("getArtistInfo2.view", mapOf("id" to id, "count" to count)).artistInfo2
?: com.novasonic.app.api.model.ArtistInfo() ?: com.novasonic.app.api.model.ArtistInfo()
suspend fun getTopSongs(artist: String, count: Int = 10): List<com.novasonic.app.api.model.Song> = /**
get("getTopSongs.view", mapOf("artist" to artist, "count" to count)).topSongs?.song * id + artist zusammen: Navidrome nimmt seit 0.64 die Kuenstler-ID und faellt nur dann auf den
?: emptyList() * Namen zurueck, wenn es sie nicht kennt; aeltere Versionen ignorieren id. Der Namensweg sucht
* mit LIKE und Max:1 — bei gleichnamigen Kuenstlern gewann bisher der erste Treffer.
*/
suspend fun getTopSongs(artist: String, count: Int = 10, artistId: String? = null): List<com.novasonic.app.api.model.Song> =
get("getTopSongs.view", buildMap {
put("artist", artist); put("count", count)
artistId?.takeIf { it.isNotBlank() }?.let { put("id", it) }
}).topSongs?.song ?: emptyList()
suspend fun getGenres(): List<com.novasonic.app.api.model.Genre> = suspend fun getGenres(): List<com.novasonic.app.api.model.Genre> =
get("getGenres.view").genres?.genre ?: emptyList() get("getGenres.view").genres?.genre ?: emptyList()
@@ -154,13 +167,12 @@ class SubsonicClient(
get("getSongsByGenre.view", mapOf("genre" to genre, "count" to count)).songsByGenre?.song get("getSongsByGenre.view", mapOf("genre" to genre, "count" to count)).songsByGenre?.song
?: emptyList() ?: emptyList()
suspend fun getLyrics(songId: String): List<com.novasonic.app.api.model.StructuredLyrics> =
get("getLyricsBySongId.view", mapOf("id" to songId)).lyricsList?.structuredLyrics
?: emptyList()
suspend fun addSongToPlaylist(playlistId: String, songId: String) = suspend fun addSongToPlaylist(playlistId: String, songId: String) =
getList("updatePlaylist.view", listOf("playlistId" to playlistId, "songIdToAdd" to songId)) getList("updatePlaylist.view", listOf("playlistId" to playlistId, "songIdToAdd" to songId))
/** Stoesst Navidromes Bibliotheks-Scan an — nach einem Import, damit frische Dateien auffindbar sind. */
suspend fun startScan() = get("startScan.view")
suspend fun createPlaylist(name: String, songIds: List<String> = emptyList()): com.novasonic.app.api.model.PlaylistWithSongs { suspend fun createPlaylist(name: String, songIds: List<String> = emptyList()): com.novasonic.app.api.model.PlaylistWithSongs {
val params = mutableListOf("name" to name) val params = mutableListOf("name" to name)
songIds.forEach { params += "songId" to it } songIds.forEach { params += "songId" to it }
@@ -168,6 +180,58 @@ class SubsonicClient(
?: throw SubsonicException(-1, "Failed to create playlist") ?: throw SubsonicException(-1, "Failed to create playlist")
} }
suspend fun updatePlaylistMeta(playlistId: String, name: String, comment: String? = null) =
getList("updatePlaylist.view", listOfNotNull(
"playlistId" to playlistId,
"name" to name,
comment?.let { "comment" to it },
))
suspend fun removeSongsFromPlaylist(playlistId: String, indices: List<Int>) =
getList("updatePlaylist.view",
listOf("playlistId" to playlistId) + indices.map { "songIndexToRemove" to it.toString() })
suspend fun deletePlaylist(playlistId: String) =
getList("deletePlaylist.view", listOf("id" to playlistId))
// ── Navidrome REST API (cover art) ────────────────────────────────────────
@Serializable private data class NdLoginReq(val username: String, val password: String)
@Serializable private data class NdLoginResp(val token: String = "")
private var _ndToken: String? = null
private suspend fun ndToken(): String {
_ndToken?.let { return it }
val resp = http.post("$serverUrl/auth/login") {
contentType(ContentType.Application.Json)
setBody(NdLoginReq(username, password))
}.body<NdLoginResp>()
val token = resp.token.ifBlank { throw Exception("Navidrome login fehlgeschlagen") }
_ndToken = token
return token
}
suspend fun uploadPlaylistCover(playlistId: String, imageBytes: ByteArray, mimeType: String) {
val token = ndToken()
http.post("$serverUrl/api/playlist/$playlistId/image") {
header("X-Nd-Authorization", "Bearer $token")
setBody(MultiPartFormDataContent(formData {
append("image", imageBytes, Headers.build {
append(HttpHeaders.ContentType, mimeType)
append(HttpHeaders.ContentDisposition, "filename=\"cover\"")
})
}))
}
}
suspend fun removePlaylistCover(playlistId: String) {
val token = ndToken()
http.delete("$serverUrl/api/playlist/$playlistId/image") {
header("X-Nd-Authorization", "Bearer $token")
}
}
fun close() = http.close() fun close() = http.close()
private suspend fun getList(path: String, params: List<Pair<String, String>>): SubsonicResponse { private suspend fun getList(path: String, params: List<Pair<String, String>>): SubsonicResponse {
@@ -0,0 +1,17 @@
package com.novasonic.app.api.model
import kotlinx.serialization.Serializable
/**
* A manual "pin" mapping a local Navidrome artist → a specific Deezer artist, fixing same-name
* collisions where NovaSonic would otherwise guess the wrong one (fans / top songs / albums / image).
* Stored server-side (shared across users) on the download backend at /api/artist-overrides, keyed
* by the Navidrome artist id. Mirrors the web PWA's override shape exactly.
*/
@Serializable
data class ArtistOverride(
val deezerArtistId: String = "",
val name: String = "",
val image: String = "",
val fanCount: Long? = null,
)
@@ -0,0 +1,131 @@
package com.novasonic.app.api.model
import kotlinx.serialization.Serializable
// ─── DEEZER API MODELS ────────────────────────────────────────────────────────
// Apple's iTunes /search returns 403 from server IPs, so the Explore/search source is
// Deezer (free, no key, returns explicit flags + artist images + durations). Deezer JSON is
// mapped to the existing ItunesItem/ItunesRssEntry shapes so the screens + view models are
// unchanged. See ItunesClient for the endpoint calls.
@Serializable
data class DzList<T>(val data: List<T> = emptyList())
@Serializable
data class DzArtist(
val id: Long? = null,
val name: String? = null,
val picture_medium: String? = null,
val picture_big: String? = null,
val picture_xl: String? = null,
val nb_fan: Long? = null, // popularity — disambiguates same-name artists (5× "Joji")
)
@Serializable
data class DzGenre(val name: String? = null)
@Serializable
data class DzGenres(val data: List<DzGenre> = emptyList())
@Serializable
data class DzAlbum(
val id: Long? = null,
val title: String? = null,
val cover_medium: String? = null,
val cover_big: String? = null,
val cover_xl: String? = null,
val release_date: String? = null,
val nb_tracks: Int? = null,
val record_type: String? = null,
val genres: DzGenres? = null,
val artist: DzArtist? = null,
val tracks: DzList<DzTrack>? = null,
val position: Int? = null,
)
@Serializable
data class DzTrack(
val id: Long? = null,
val title: String? = null,
val duration: Long? = null,
val track_position: Int? = null,
val disk_number: Int? = null,
val explicit_lyrics: Boolean = false,
val preview: String? = null,
val artist: DzArtist? = null,
val album: DzAlbum? = null,
)
// ─── MAPPERS to the legacy ItunesItem shape ───────────────────────────────────
private fun DzAlbum.coverXl(): String? = cover_xl ?: cover_big ?: cover_medium
private fun DzArtist.pictureXl(): String? = picture_xl ?: picture_big ?: picture_medium
/** A Deezer search-result track → ItunesItem (album cover for artwork). */
fun DzTrack.toItunesItem(): ItunesItem = ItunesItem(
wrapperType = "track",
kind = "song",
trackId = id,
artistId = artist?.id,
collectionId = album?.id,
artistName = artist?.name,
collectionName = album?.title,
trackName = title,
artworkUrl100 = album?.coverXl() ?: artist?.pictureXl(),
previewUrl = preview,
trackTimeMillis = duration?.let { it * 1000 },
trackNumber = track_position,
)
/** A Deezer album → ItunesItem collection. */
fun DzAlbum.toItunesItem(): ItunesItem = ItunesItem(
wrapperType = "collection",
kind = "album",
collectionId = id,
artistId = artist?.id,
artistName = artist?.name,
collectionName = title,
artworkUrl100 = coverXl(),
trackCount = nb_tracks,
releaseDate = release_date,
primaryGenreName = genres?.data?.firstOrNull()?.name,
)
/** A Deezer artist → ItunesItem artist (carries a real picture, unlike iTunes). */
fun DzArtist.toItunesItem(): ItunesItem = ItunesItem(
wrapperType = "artist",
artistId = id,
artistName = name,
artworkUrl100 = pictureXl(),
fanCount = nb_fan,
)
/**
* A Deezer album track (from /album/{id}) → ItunesItem song. The embedded tracks carry no
* track_position, so the album ordering supplies the number; genre/release come from the album.
*/
fun DzTrack.toAlbumTrackItem(album: DzAlbum, index: Int): ItunesItem = ItunesItem(
wrapperType = "track",
kind = "song",
trackId = id,
artistId = artist?.id ?: album.artist?.id,
collectionId = album.id,
artistName = artist?.name ?: album.artist?.name,
collectionName = album.title,
trackName = title,
artworkUrl100 = album.coverXl(),
previewUrl = preview,
trackTimeMillis = duration?.let { it * 1000 },
trackNumber = track_position ?: (index + 1),
trackCount = album.nb_tracks,
releaseDate = album.release_date,
primaryGenreName = album.genres?.data?.firstOrNull()?.name,
)
/** A Deezer chart album → ItunesRssEntry (keeps the charts UI unchanged). */
fun DzAlbum.toRssEntry(): ItunesRssEntry = ItunesRssEntry(
name = ItunesLabel(title),
artist = ItunesLabel(artist?.name),
image = listOfNotNull(coverXl()?.let { ItunesLabel(it) }),
id = ItunesId(attributes = ItunesIdAttributes(imId = id?.toString())),
)
@@ -0,0 +1,23 @@
package com.novasonic.app.api.model
import kotlinx.serialization.Serializable
@Serializable
data class ConcertEvent(
val datetime: String = "",
val venue: ConcertVenue? = null,
val offers: List<ConcertOffer> = emptyList(),
)
@Serializable
data class ConcertVenue(
val name: String? = null,
val city: String? = null,
val country: String? = null,
)
@Serializable
data class ConcertOffer(
val url: String? = null,
val status: String? = null,
)
@@ -42,6 +42,15 @@ data class DownloadRequest(
@Serializable @Serializable
data class ResolveRequest(val url: String) data class ResolveRequest(val url: String)
/** Body fuer POST {backend}/api/delete-song — loescht die Datei von der Platte (wie im Web). */
@Serializable
data class DeleteSongRequest(
val ndUrl: String,
val user: String,
val pass: String,
val songId: String,
)
/** Response from GET {backend}/api/status/{jobId} */ /** Response from GET {backend}/api/status/{jobId} */
@Serializable @Serializable
data class DownloadStatus( data class DownloadStatus(
@@ -27,8 +27,18 @@ data class ItunesItem(
val trackCount: Int? = null, val trackCount: Int? = null,
val trackNumber: Int? = null, val trackNumber: Int? = null,
val collectionPrice: Double? = null, val collectionPrice: Double? = null,
val fanCount: Long? = null, // Deezer nb_fan — disambiguates same-name artists + shown in UI
) )
// German fan-count format: 559542 → "559.542", 1200000 → "1,2 Mio." (matches the web PWA).
fun fmtFanCount(n: Long): String {
if (n >= 1_000_000) {
val s = String.format(java.util.Locale.GERMAN, "%.1f", n / 1_000_000.0).removeSuffix(",0")
return "$s Mio."
}
return String.format(java.util.Locale.GERMAN, "%,d", n)
}
// iTunes RSS feed response // iTunes RSS feed response
@Serializable @Serializable
data class ItunesRssResponse( data class ItunesRssResponse(
@@ -27,12 +27,12 @@ data class SubsonicResponse(
val song: Song? = null, val song: Song? = null,
val starred2: Starred2? = null, val starred2: Starred2? = null,
val randomSongs: SongListResult? = null, val randomSongs: SongListResult? = null,
val similarSongs2: SongListResult? = null,
val scanStatus: ScanStatus? = null, val scanStatus: ScanStatus? = null,
val artistInfo2: ArtistInfo? = null, val artistInfo2: ArtistInfo? = null,
val topSongs: SongListResult? = null, val topSongs: SongListResult? = null,
val genres: GenresResult? = null, val genres: GenresResult? = null,
val songsByGenre: SongListResult? = null, val songsByGenre: SongListResult? = null,
val lyricsList: LyricsListResult? = null,
) )
@Serializable @Serializable
@@ -40,6 +40,12 @@ data class SubsonicError(val code: Int, val message: String)
// ── Domain models ───────────────────────────────────────────────────────────── // ── Domain models ─────────────────────────────────────────────────────────────
@Serializable
data class SongArtist(
val id: String = "",
val name: String = "",
)
@Serializable @Serializable
data class Song( data class Song(
val id: String, val id: String,
@@ -48,6 +54,7 @@ data class Song(
val albumId: String? = null, val albumId: String? = null,
val artist: String? = null, val artist: String? = null,
val artistId: String? = null, val artistId: String? = null,
val artists: List<SongArtist> = emptyList(),
val track: Int? = null, val track: Int? = null,
val year: Int? = null, val year: Int? = null,
val genre: String? = null, val genre: String? = null,
@@ -176,19 +183,3 @@ data class Genre(
@Serializable @Serializable
data class GenresResult(val genre: List<Genre> = emptyList()) data class GenresResult(val genre: List<Genre> = emptyList())
// ── Lyrics ────────────────────────────────────────────────────────────────────
@Serializable
data class LyricsLine(val start: Long? = null, val value: String = "")
@Serializable
data class StructuredLyrics(
val lang: String = "",
val synced: Boolean = false,
val line: List<LyricsLine> = emptyList(),
val displayArtist: String? = null,
val displayTitle: String? = null,
val offset: Long? = null,
)
@Serializable
data class LyricsListResult(val structuredLyrics: List<StructuredLyrics> = emptyList())
@@ -0,0 +1,59 @@
package com.novasonic.app.api.model
import kotlinx.serialization.Serializable
/** Eine Veröffentlichung eines gefolgten Künstlers, wie sie das Backend liefert. */
@Serializable
data class ArtistRelease(
val artistId: String = "",
val artistName: String = "",
val deezerArtistId: String? = null,
val albumId: String = "",
val title: String = "",
val cover: String = "",
val releaseDate: String = "",
val recordType: String = "album",
val trackCount: Int? = null,
val explicit: Boolean = false,
)
@Serializable
data class ArtistReleasesResponse(
val releases: List<ArtistRelease> = emptyList(),
/** Künstler, zu denen kein Deezer-Profil gefunden wurde — dort hilft nur ein Pin. */
val ohneZuordnung: List<String> = emptyList(),
)
@Serializable
data class ArtistRef(val id: String, val name: String)
@Serializable
data class ArtistReleasesRequest(val artists: List<ArtistRef>, val days: Int)
/** Ein anstehendes Konzert eines gefolgten Künstlers. */
@Serializable
data class ArtistKonzert(
val artistId: String = "",
val artistName: String = "",
val eventId: String = "",
val titel: String = "",
/** Ortszeit ohne Zone, z. B. "2026-11-04T20:00:00" — bewusst nicht UTC. */
val datum: String = "",
val ort: String = "",
val stadt: String = "",
val land: String = "",
val url: String = "",
val abgesagt: Boolean = false,
)
@Serializable
data class ArtistKonzerteResponse(
val konzerte: List<ArtistKonzert> = emptyList(),
/** Künstler ohne anstehende Termine — nur zur Erklärung einer leeren Liste. */
val ohneTermine: List<String> = emptyList(),
/** Im Backend ist kein Ticketmaster-Schlüssel hinterlegt. */
val keinSchluessel: Boolean = false,
)
@Serializable
data class ArtistKonzerteRequest(val artists: List<ArtistRef>)
@@ -0,0 +1,146 @@
package com.novasonic.app.api.model
import kotlinx.serialization.Serializable
// Mirrors the JSON from the scrobble service GET /scrobble/stats.
@Serializable
data class ScrobbleStats(
val firstPlayedAt: Long? = null,
val totalPlays: Int = 0,
val totalSeconds: Long = 0,
val topArtists: List<StatArtist> = emptyList(),
val topAlbums: List<StatAlbum> = emptyList(),
val topTracks: List<StatTrack> = emptyList(),
val topGenres: List<StatGenre> = emptyList(),
val series: List<StatBucket> = emptyList(),
val byHour: List<StatHour> = emptyList(),
)
@Serializable
data class StatGenre(
val name: String? = null,
val plays: Int = 0,
)
@Serializable
data class StatArtist(
val name: String? = null,
val artistId: String? = null,
val plays: Int = 0,
val seconds: Long = 0,
)
@Serializable
data class StatAlbum(
val name: String? = null,
val albumId: String? = null,
val artist: String? = null,
val coverArt: String? = null,
val plays: Int = 0,
)
@Serializable
data class StatTrack(
val title: String? = null,
val artist: String? = null,
val album: String? = null,
val albumId: String? = null,
val artistId: String? = null,
val coverArt: String? = null,
val songId: String? = null,
val plays: Int = 0,
)
@Serializable
data class StatBucket(
val bucket: String = "",
val plays: Int = 0,
val seconds: Long = 0,
)
@Serializable
data class StatHour(
val hour: Int = 0,
val plays: Int = 0,
)
// ─── Head-to-Head "Musik-Match" ─────────────────────────────────────────────
// GET /scrobble/users — distinct users in the log, for the partner picker.
@Serializable
data class ScrobbleUsersResponse(
val me: String = "",
val users: List<ScrobbleUser> = emptyList(),
)
@Serializable
data class ScrobbleUser(
val user: String = "",
val plays: Int = 0,
val lastPlayedAt: Long? = null,
)
// GET /scrobble/compare?with= — taste comparison of the authed user (A) vs another (B).
@Serializable
data class CompareResult(
val userA: String = "",
val userB: String = "",
val matchScore: Int = 0,
val battle: Battle? = null,
val totalsA: CompareTotals = CompareTotals(),
val totalsB: CompareTotals = CompareTotals(),
val sharedArtists: List<SharedArtist> = emptyList(),
val sharedTracks: List<SharedTrack> = emptyList(),
val onlyA: List<UniqueArtist> = emptyList(),
val onlyB: List<UniqueArtist> = emptyList(),
)
/** Anzeigetafel: je Kategorie ein Sieger ("A"/"B"/null bei Gleichstand) plus Gesamtstand. */
@Serializable
data class Battle(
val kategorien: List<BattleKategorie> = emptyList(),
val punkteA: Int = 0,
val punkteB: Int = 0,
)
@Serializable
data class BattleKategorie(
val key: String = "",
val label: String = "",
val textA: String = "",
val textB: String = "",
val sieger: String? = null,
)
@Serializable
data class CompareTotals(
val plays: Int = 0,
val seconds: Long = 0,
val artists: Int = 0,
)
@Serializable
data class SharedArtist(
val name: String? = null,
val artistId: String? = null,
val playsA: Int = 0,
val playsB: Int = 0,
)
@Serializable
data class SharedTrack(
val songId: String? = null,
val title: String? = null,
val artist: String? = null,
val artistId: String? = null,
val albumId: String? = null,
val coverArt: String? = null,
val playsA: Int = 0,
val playsB: Int = 0,
)
@Serializable
data class UniqueArtist(
val name: String? = null,
val artistId: String? = null,
val plays: Int = 0,
)
@@ -0,0 +1,96 @@
package com.novasonic.app.data
import android.content.Context
import android.content.Intent
import androidx.core.content.FileProvider
import com.novasonic.app.BuildConfig
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import java.io.File
import java.net.HttpURLConnection
import java.net.URL
/**
* In-app updater for the sideloaded APK. Talks ONLY to the backend the app already knows:
* GET {backend}/api/apk/info → is there a newer versionCode than this build?
* GET {backend}/api/apk → download it (the backend proxies the fixed Gitea release)
* The user still confirms the system install (Android requires that for sideloaded APKs).
*
* No APK hoarding: the download goes to a single file under cacheDir/updates that is wiped before
* each download. An update (same package + signature) is an in-place install, so app data / offline
* downloads survive — provided the signing key stays stable across builds.
*/
object AppUpdater {
@Serializable
data class ApkInfo(
val available: Boolean = false,
val version: String? = null,
val versionCode: Int? = null,
val size: Long? = null,
)
private val json = Json { ignoreUnknownKeys = true }
private val _available = MutableStateFlow<ApkInfo?>(null)
val available: StateFlow<ApkInfo?> = _available
private val _downloading = MutableStateFlow(false)
val downloading: StateFlow<Boolean> = _downloading
// Versions the user waved away this session — don't nag again until app restart.
@Volatile private var dismissedCode: Int = -1
suspend fun check(backendUrl: String) {
if (backendUrl.isBlank()) return
val info = withContext(Dispatchers.IO) {
runCatching {
val c = (URL("${backendUrl.trimEnd('/')}/api/apk/info").openConnection() as HttpURLConnection)
.apply { connectTimeout = 8000; readTimeout = 8000 }
c.inputStream.bufferedReader().use { it.readText() }
.let { json.decodeFromString<ApkInfo>(it) }
}.getOrNull()
} ?: return
val vc = info.versionCode ?: return // no reliable integer → don't prompt
if (info.available && vc > BuildConfig.VERSION_CODE && vc != dismissedCode) {
_available.value = info
}
}
fun dismiss() {
dismissedCode = _available.value?.versionCode ?: dismissedCode
_available.value = null
}
suspend fun downloadAndInstall(context: Context, backendUrl: String, onError: (String) -> Unit) {
if (_downloading.value || backendUrl.isBlank()) return
_downloading.value = true
try {
val apk = withContext(Dispatchers.IO) {
val dir = File(context.cacheDir, "updates").apply { mkdirs(); listFiles()?.forEach { it.delete() } }
val out = File(dir, "NovaSonic-update.apk")
val c = (URL("${backendUrl.trimEnd('/')}/api/apk").openConnection() as HttpURLConnection)
.apply { connectTimeout = 15000; readTimeout = 30000; instanceFollowRedirects = true }
if (c.responseCode !in 200..299) throw RuntimeException("HTTP ${c.responseCode}")
c.inputStream.use { input -> out.outputStream().use { input.copyTo(it) } }
out
}
val uri = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", apk)
context.startActivity(
Intent(Intent.ACTION_VIEW).apply {
setDataAndType(uri, "application/vnd.android.package-archive")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
}
)
_available.value = null // installer takes over
} catch (e: Exception) {
onError(e.message ?: "Download fehlgeschlagen")
} finally {
_downloading.value = false
}
}
}
@@ -0,0 +1,26 @@
package com.novasonic.app.data
import android.net.Uri
import kotlinx.coroutines.flow.MutableStateFlow
/**
* Uebergabepunkt fuer geteilte Links (https://<host>/?song=… bzw. ?album=…).
*
* Die Activity kann nicht selbst navigieren — der NavController lebt in der Compose-Hierarchie.
* Deshalb legt MainActivity den eingehenden Link hier ab, und AppNavigation holt ihn sich, sobald
* es bereit ist. Ein einzelner Slot genuegt: der letzte geoeffnete Link gewinnt.
*/
object DeepLinkState {
val pending = MutableStateFlow<Uri?>(null)
fun offer(uri: Uri?) {
// Nur Links mit einer fuer uns verwertbaren Kennung annehmen — ein blosser Start ueber das
// App-Symbol darf keine Navigation ausloesen.
if (uri == null) return
if (uri.getQueryParameter("song") == null && uri.getQueryParameter("album") == null) return
pending.value = uri
}
/** Holt den Link und leert den Slot, damit er bei Drehung o. ae. nicht erneut greift. */
fun consume(): Uri? = pending.value.also { pending.value = null }
}
@@ -0,0 +1,11 @@
package com.novasonic.app.data
/**
* Einmalige Absicht beim Öffnen der Bibliothek. Das LibraryViewModel hängt am Navigationseintrag,
* überlebt also keinen Wechsel des Ziels — ein Zustand, den ein anderer Screen setzen will, muss
* deshalb hier durch. Wird beim Verarbeiten sofort zurückgesetzt, damit er nicht nachwirkt.
*/
object LibraryIntent {
/** Direkt in den Künstler-Reiter mit aktivem "Gefolgt"-Filter springen. */
var oeffneGefolgte: Boolean = false
}
@@ -1,9 +1,13 @@
package com.novasonic.app.data package com.novasonic.app.data
import android.content.Context import android.content.Context
import android.net.Uri
import com.novasonic.app.NovaSonicApp
import com.novasonic.app.api.SubsonicClient import com.novasonic.app.api.SubsonicClient
import com.novasonic.app.api.model.* import com.novasonic.app.api.model.*
import com.novasonic.app.offline.OfflineRepository
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import java.io.File
object ClientHolder { object ClientHolder {
@Volatile private var client: SubsonicClient? = null @Volatile private var client: SubsonicClient? = null
@@ -28,6 +32,7 @@ object ClientHolder {
class MusicRepository(private val context: Context) { class MusicRepository(private val context: Context) {
private val prefs = PrefsStore(context) private val prefs = PrefsStore(context)
private val playLog = PlayLogClient(context)
private suspend fun api(): SubsonicClient = private suspend fun api(): SubsonicClient =
ClientHolder.get(prefs.credentials.first()) ClientHolder.get(prefs.credentials.first())
@@ -48,27 +53,94 @@ class MusicRepository(private val context: Context) {
suspend fun getPlaylist(id: String) = api().getPlaylist(id) suspend fun getPlaylist(id: String) = api().getPlaylist(id)
suspend fun getStarred() = api().getStarred() suspend fun getStarred() = api().getStarred()
suspend fun getRandomSongs() = api().getRandomSongs() suspend fun getRandomSongs() = api().getRandomSongs()
suspend fun getSimilarSongs(songId: String, count: Int = 20) = api().getSimilarSongs(songId, count)
suspend fun star(id: String) = api().star(id) suspend fun star(id: String) = api().star(id)
suspend fun unstar(id: String) = api().unstar(id) suspend fun unstar(id: String) = api().unstar(id)
suspend fun scrobble(id: String) = api().scrobble(id) suspend fun scrobble(id: String) = api().scrobble(id)
// Our own timestamped play-log (stats + Wrapped), in addition to the Navidrome scrobble above.
suspend fun logPlay(song: Song) = playLog.logPlay(song)
suspend fun flushPlayLog() = playLog.flush()
suspend fun fetchScrobbleStats(from: Long, to: Long, tz: Int, bucket: String, limit: Int) =
playLog.fetchStats(from, to, tz, bucket, limit)
suspend fun fetchScrobbleUsers() = playLog.fetchUsers()
suspend fun fetchScrobbleCompare(with: String) = playLog.fetchCompare(with)
// ── Artist pins (shared, server-side same-name disambiguation) ───────────────
@Volatile private var _artistOverrides: Map<String, ArtistOverride>? = null
/** Full pin map, cached after first load. Empty if no backend / unreachable. */
suspend fun artistOverrides(): Map<String, ArtistOverride> {
_artistOverrides?.let { return it }
val url = getBackendUrl()
if (url.isBlank()) return emptyMap<String, ArtistOverride>().also { _artistOverrides = it }
val c = com.novasonic.app.api.ArtistOverrideClient(url)
val m = runCatching { c.loadAll() }.getOrDefault(emptyMap())
c.close()
return m.also { _artistOverrides = it }
}
suspend fun getArtistOverride(ndArtistId: String): ArtistOverride? = artistOverrides()[ndArtistId]
suspend fun setArtistOverride(ndArtistId: String, ov: ArtistOverride): Boolean {
val url = getBackendUrl()
if (url.isBlank()) return false
val c = com.novasonic.app.api.ArtistOverrideClient(url)
val ok = runCatching { c.set(ndArtistId, ov) }.getOrDefault(false)
c.close()
if (ok) _artistOverrides = (_artistOverrides ?: emptyMap()) + (ndArtistId to ov)
return ok
}
suspend fun removeArtistOverride(ndArtistId: String): Boolean {
val url = getBackendUrl()
if (url.isBlank()) return false
val c = com.novasonic.app.api.ArtistOverrideClient(url)
val ok = runCatching { c.remove(ndArtistId) }.getOrDefault(false)
c.close()
if (ok) _artistOverrides = (_artistOverrides ?: emptyMap()) - ndArtistId
return ok
}
suspend fun getArtistInfo(id: String) = api().getArtistInfo(id) suspend fun getArtistInfo(id: String) = api().getArtistInfo(id)
suspend fun getTopSongs(artistName: String) = api().getTopSongs(artistName) /** artistId ist die NAVIDROME-Kuenstler-ID (nicht Deezers) — ohne sie sucht Navidrome
* ueber den Namen und nimmt bei Gleichnamigen den ersten Treffer. */
suspend fun getTopSongs(artistName: String, artistId: String? = null) =
api().getTopSongs(artistName, artistId = artistId)
suspend fun getGenres() = api().getGenres() suspend fun getGenres() = api().getGenres()
suspend fun getSongsByGenre(genre: String) = api().getSongsByGenre(genre) suspend fun getSongsByGenre(genre: String) = api().getSongsByGenre(genre)
suspend fun getLyrics(songId: String) = api().getLyrics(songId)
suspend fun addSongToPlaylist(playlistId: String, songId: String) = api().addSongToPlaylist(playlistId, songId) suspend fun addSongToPlaylist(playlistId: String, songId: String) = api().addSongToPlaylist(playlistId, songId)
suspend fun createPlaylist(name: String, songIds: List<String>) = api().createPlaylist(name, songIds) suspend fun createPlaylist(name: String, songIds: List<String>) = api().createPlaylist(name, songIds)
suspend fun startScan() = api().startScan()
suspend fun updatePlaylistMeta(playlistId: String, name: String, comment: String? = null) = api().updatePlaylistMeta(playlistId, name, comment)
suspend fun removeSongsFromPlaylist(playlistId: String, indices: List<Int>) = api().removeSongsFromPlaylist(playlistId, indices)
suspend fun deletePlaylist(playlistId: String) = api().deletePlaylist(playlistId)
suspend fun uploadPlaylistCover(playlistId: String, imageBytes: ByteArray, mimeType: String) = api().uploadPlaylistCover(playlistId, imageBytes, mimeType)
suspend fun removePlaylistCover(playlistId: String) = api().removePlaylistCover(playlistId)
fun coverArtUrl(id: String?, size: Int = 300): String? { fun coverArtUrl(id: String?, size: Int = 300): String? {
if (id != null) {
offlineRepo()?.localCoverPath(id)?.let { path ->
val f = File(path)
if (f.exists()) return Uri.fromFile(f).toString()
}
}
val creds = lastCredentials ?: return null val creds = lastCredentials ?: return null
return SubsonicClient(creds.serverUrl, creds.username, creds.password) // Reuse the cached client — building a fresh SubsonicClient here spins up a whole Ktor
.coverArtUrl(id ?: return null, size) // HttpClient per cover (and never closes it), which is heavy GC/alloc churn while scrolling.
return ClientHolder.get(creds).coverArtUrl(id ?: return null, size)
} }
fun streamUrl(id: String): String? { fun streamUrl(id: String): String? {
val creds = lastCredentials ?: return null offlineRepo()?.localAudioPath(id)?.let { path ->
return SubsonicClient(creds.serverUrl, creds.username, creds.password).streamUrl(id) val f = File(path)
if (f.exists()) return Uri.fromFile(f).toString()
} }
val creds = lastCredentials ?: return null
return ClientHolder.get(creds).streamUrl(id) // reuse cached client (no per-call HttpClient)
}
private fun offlineRepo(): OfflineRepository? = runCatching {
(context.applicationContext as NovaSonicApp).offlineRepository
}.getOrNull()
var lastCredentials: PrefsStore.Credentials? = null var lastCredentials: PrefsStore.Credentials? = null
@@ -100,6 +172,20 @@ class MusicRepository(private val context: Context) {
suspend fun saveTheme(themeId: String) = prefs.saveTheme(themeId) suspend fun saveTheme(themeId: String) = prefs.saveTheme(themeId)
suspend fun saveQueueState(songs: List<com.novasonic.app.api.model.Song>, index: Int) =
prefs.saveQueueState(songs, index)
suspend fun readQueueState() = prefs.readQueueState()
suspend fun saveLastSong(song: com.novasonic.app.api.model.Song) =
prefs.saveLastSong(song.id, song.title, song.artist ?: "", song.coverArt)
fun lastPlayedSongFlow() = prefs.lastPlayedSong
suspend fun absClient(): com.novasonic.app.api.AbsClient? {
val s = prefs.appSettings.first()
if (s.absUrl.isBlank() || s.absApiKey.isBlank()) return null
return com.novasonic.app.api.AbsClient(s.absUrl.trimEnd('/'), s.absApiKey, s.backendUrl.trimEnd('/'))
}
suspend fun saveAppSettings(settings: PrefsStore.AppSettings) { suspend fun saveAppSettings(settings: PrefsStore.AppSettings) {
val urlChanged = settings.serverUrl != lastCredentials?.serverUrl || val urlChanged = settings.serverUrl != lastCredentials?.serverUrl ||
settings.username != lastCredentials?.username || settings.username != lastCredentials?.username ||
@@ -0,0 +1,94 @@
package com.novasonic.app.data
import com.novasonic.app.api.ImporterClient
import com.novasonic.app.api.model.DownloadStatus
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
data class AppNotification(
val id: String,
val title: String,
val artist: String = "",
val status: String, // "done" | "error" | "pending"
val message: String = "",
val timestamp: Long = System.currentTimeMillis(),
val read: Boolean = false,
// Navigation — mirrors web notify.js fields
val navType: String = "", // "track" | "album" | "playlist"
val navAlbum: String = "",
val navArtist: String = "",
val navId: String = "", // playlist ID if known
)
object NotificationStore {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
private val _items = MutableStateFlow<List<AppNotification>>(emptyList())
val items: StateFlow<List<AppNotification>> = _items.asStateFlow()
fun add(n: AppNotification) = _items.update { listOf(n) + it }
fun markAllRead() = _items.update { list -> list.map { it.copy(read = true) } }
fun remove(id: String) = _items.update { it.filter { n -> n.id != id } }
fun clear() { _items.value = emptyList() }
/**
* Submit a download job to the backend and poll until done/error,
* then add a notification. Safe to call from any ViewModel — uses
* an app-lifetime coroutine scope so the ViewModel can be cleared
* while polling continues.
*/
fun startPoll(
backendUrl: String,
jobId: String,
title: String,
artist: String,
navType: String = "",
navAlbum: String = "",
navArtist: String = "",
navId: String = "",
) {
add(AppNotification(id = jobId, title = title, artist = artist, status = "pending"))
scope.launch {
val client = ImporterClient(backendUrl)
try {
repeat(400) { // up to ~10 minutes at 1.5 s interval
delay(1500)
val st: DownloadStatus = runCatching { client.status(jobId) }.getOrNull()
?: return@repeat
when (st.status) {
"done" -> {
replace(AppNotification(
id = jobId, title = title, artist = artist,
status = "done", message = st.message ?: "Fertig!",
navType = navType, navAlbum = navAlbum,
navArtist = navArtist, navId = navId,
))
return@launch
}
"error" -> {
replace(AppNotification(
id = jobId, title = title, artist = artist,
status = "error", message = st.message ?: "Fehler",
navType = navType, navAlbum = navAlbum,
navArtist = navArtist, navId = navId,
))
return@launch
}
}
}
} finally {
client.close()
}
}
}
private fun replace(n: AppNotification) =
_items.update { list -> listOf(n) + list.filter { it.id != n.id } }
}
@@ -0,0 +1,186 @@
package com.novasonic.app.data
import android.content.Context
import com.novasonic.app.api.model.ScrobbleStats
import com.novasonic.app.api.model.Song
import io.ktor.client.HttpClient
import io.ktor.client.engine.android.Android
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.request.get
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.client.statement.HttpResponse
import io.ktor.client.statement.bodyAsText
import io.ktor.http.ContentType
import io.ktor.http.contentType
import io.ktor.http.encodeURLParameter
import io.ktor.http.isSuccess
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.io.File
import java.security.MessageDigest
import java.util.UUID
import kotlin.random.Random
/**
* Records timestamped plays into NovaSonic's own scrobble service (separate origin,
* settings.scrobbleUrl) — the basis for day/month/year stats + Wrapped.
*
* Runs IN ADDITION to the existing Navidrome scrobble (playCount + Last.fm); never
* replaces it. Called at the same "counted play" moment as the Navidrome scrobble
* (see PlayerController.scheduleScrobble).
*
* Offline-safe: entries persist to a JSON file and flush as an idempotent batch
* (the service dedups by uuid), so a play made offline is delivered later exactly once.
*
* One instance lives on MusicRepository → a single reused HttpClient (never per-call).
*/
class PlayLogClient(context: Context) {
private val prefs = PrefsStore(context)
private val queueFile = File(context.filesDir, "play-queue.json")
private val mutex = Mutex()
private val json = Json { ignoreUnknownKeys = true; encodeDefaults = true }
private val http = HttpClient(Android) {
install(HttpTimeout) { requestTimeoutMillis = 15_000; connectTimeoutMillis = 8_000 }
}
@Serializable
data class PlayEntry(
val uuid: String,
val songId: String,
val title: String? = null,
val artist: String? = null,
val artistId: String? = null,
val album: String? = null,
val albumId: String? = null,
val coverArt: String? = null,
val genre: String? = null,
val duration: Int? = null,
val playedAt: Long,
val source: String = "android",
)
@Serializable
private data class Batch(val plays: List<PlayEntry>)
/** Queue one counted play and try to deliver it. */
suspend fun logPlay(song: Song) {
val s = prefs.appSettings.first()
if (s.scrobbleUrl.isBlank()) return
val entry = PlayEntry(
uuid = UUID.randomUUID().toString(),
songId = song.id,
title = song.title,
artist = song.artist,
artistId = song.artistId,
album = song.album,
albumId = song.albumId,
coverArt = song.coverArt,
genre = song.genre,
duration = song.duration,
playedAt = System.currentTimeMillis() / 1000,
)
mutex.withLock {
val q = readQueue().toMutableList()
q.add(entry)
writeQueue(q.takeLast(MAX_QUEUE))
}
flush(s)
}
/** Deliver everything queued as one idempotent batch. Safe to call repeatedly. */
suspend fun flush(settings: PrefsStore.AppSettings? = null) {
val s = settings ?: prefs.appSettings.first()
val base = s.scrobbleUrl.trimEnd('/')
if (base.isBlank() || s.username.isBlank() || s.password.isBlank()) return
val batch = mutex.withLock { readQueue() }
if (batch.isEmpty()) return
val auth = authParams(s.username, s.password)
val ok = runCatching {
val resp: HttpResponse = http.post("$base/scrobble/plays?$auth") {
contentType(ContentType.Application.Json)
setBody(json.encodeToString(Batch(batch)))
}
resp.status.isSuccess()
}.getOrDefault(false)
if (ok) {
// Remove exactly what we sent (accepted + duplicates are durable), preserving
// any plays queued while the request was in flight.
val sent = batch.map { it.uuid }.toHashSet()
mutex.withLock { writeQueue(readQueue().filterNot { it.uuid in sent }) }
}
}
/** Read aggregated stats for the current user. Returns null on any failure (unconfigured,
* unauthorized, network). Decodes with the tolerant json instance (ignoreUnknownKeys). */
suspend fun fetchStats(from: Long, to: Long, tz: Int, bucket: String, limit: Int): ScrobbleStats? {
val s = prefs.appSettings.first()
val base = s.scrobbleUrl.trimEnd('/')
if (base.isBlank() || s.username.isBlank() || s.password.isBlank()) return null
val auth = authParams(s.username, s.password)
val url = "$base/scrobble/stats?$auth&from=$from&to=$to&tz=$tz&bucket=$bucket&limit=$limit"
return runCatching {
val resp = http.get(url)
if (!resp.status.isSuccess()) return null
json.decodeFromString<ScrobbleStats>(resp.bodyAsText())
}.getOrNull()
}
/** Head-to-Head: list the users in the log (for the partner picker). Null on failure. */
suspend fun fetchUsers(): com.novasonic.app.api.model.ScrobbleUsersResponse? {
val s = prefs.appSettings.first()
val base = s.scrobbleUrl.trimEnd('/')
if (base.isBlank() || s.username.isBlank() || s.password.isBlank()) return null
val auth = authParams(s.username, s.password)
return runCatching {
val resp = http.get("$base/scrobble/users?$auth")
if (!resp.status.isSuccess()) return null
json.decodeFromString<com.novasonic.app.api.model.ScrobbleUsersResponse>(resp.bodyAsText())
}.getOrNull()
}
/** Head-to-Head: compare the authed user against [with]. Null on failure. */
suspend fun fetchCompare(with: String): com.novasonic.app.api.model.CompareResult? {
val s = prefs.appSettings.first()
val base = s.scrobbleUrl.trimEnd('/')
if (base.isBlank() || s.username.isBlank() || s.password.isBlank()) return null
val auth = authParams(s.username, s.password)
val url = "$base/scrobble/compare?$auth&with=${with.encodeURLParameter()}"
return runCatching {
val resp = http.get(url)
if (!resp.status.isSuccess()) return null
json.decodeFromString<com.novasonic.app.api.model.CompareResult>(resp.bodyAsText())
}.getOrNull()
}
private fun readQueue(): List<PlayEntry> =
runCatching {
if (!queueFile.exists()) emptyList()
else json.decodeFromString<List<PlayEntry>>(queueFile.readText())
}.getOrDefault(emptyList())
private fun writeQueue(q: List<PlayEntry>) {
runCatching { queueFile.writeText(json.encodeToString(q)) }
}
private fun authParams(user: String, pass: String): String {
val salt = Random.nextInt(100_000, 999_999).toString()
val token = md5(pass + salt)
return "u=${user.encodeURLParameter()}&t=$token&s=$salt"
}
private fun md5(input: String): String =
MessageDigest.getInstance("MD5").digest(input.toByteArray())
.joinToString("") { "%02x".format(it) }
companion object { private const val MAX_QUEUE = 500 }
}
@@ -1,11 +1,13 @@
package com.novasonic.app.data package com.novasonic.app.data
import android.content.Context import android.content.Context
import androidx.datastore.preferences.core.booleanPreferencesKey import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
private val Context.dataStore by preferencesDataStore("novasonic_prefs") private val Context.dataStore by preferencesDataStore("novasonic_prefs")
@@ -18,9 +20,26 @@ class PrefsStore(private val context: Context) {
val KEY_PASSWORD = stringPreferencesKey("password") val KEY_PASSWORD = stringPreferencesKey("password")
val KEY_LASTFM_KEY = stringPreferencesKey("lastfm_key") val KEY_LASTFM_KEY = stringPreferencesKey("lastfm_key")
val KEY_BACKEND_URL = stringPreferencesKey("backend_url") val KEY_BACKEND_URL = stringPreferencesKey("backend_url")
val KEY_SCROBBLE_MODE = stringPreferencesKey("scrobble_mode") // 15s|30s|third|two_thirds|end val KEY_SCROBBLE_URL = stringPreferencesKey("scrobble_url")
val KEY_SCROBBLE_MODE = stringPreferencesKey("scrobble_mode")
val KEY_SHOW_COUNT = booleanPreferencesKey("show_play_count") val KEY_SHOW_COUNT = booleanPreferencesKey("show_play_count")
val KEY_THEME = stringPreferencesKey("theme") val KEY_THEME = stringPreferencesKey("theme")
val KEY_ABS_URL = stringPreferencesKey("abs_url")
val KEY_ABS_API_KEY = stringPreferencesKey("abs_api_key")
val KEY_ABS_CHAPTER_TRACK = booleanPreferencesKey("abs_chapter_track")
val KEY_DL_WIFI_ONLY = booleanPreferencesKey("download_wifi_only")
val KEY_WISCH_TITEL = booleanPreferencesKey("swipe_changes_track")
val KEY_LYRICS_FOLGEN = booleanPreferencesKey("lyrics_autoscroll")
val KEY_LAST_SONG_ID = stringPreferencesKey("last_song_id")
val KEY_LAST_SONG_TITLE = stringPreferencesKey("last_song_title")
val KEY_LAST_SONG_ARTIST = stringPreferencesKey("last_song_artist")
val KEY_LAST_SONG_COVER = stringPreferencesKey("last_song_cover")
// Warteschlange fortsetzen. Gespeichert werden die VOLLSTAENDIGEN Songs als JSON, nicht nur
// Ids: mit Ids musste beim Start jeder Titel einzeln ueber das Netz nachgeladen werden, was
// Sekunden dauerte und ohne Verbindung gar nicht ging. So ist es ein lokaler Lesevorgang.
// Ohne Sekunde im Titel — der zuletzt gehoerte Titel beginnt von vorn.
val KEY_QUEUE_JSON = stringPreferencesKey("queue_json")
val KEY_QUEUE_INDEX = intPreferencesKey("queue_index")
} }
data class Credentials(val serverUrl: String, val username: String, val password: String) { data class Credentials(val serverUrl: String, val username: String, val password: String) {
@@ -33,14 +52,37 @@ class PrefsStore(private val context: Context) {
val password: String = "", val password: String = "",
val lastFmKey: String = "", val lastFmKey: String = "",
val backendUrl: String = "", val backendUrl: String = "",
val scrobbleUrl: String = "",
val scrobbleMode: String = "30s", val scrobbleMode: String = "30s",
val showPlayCount: Boolean = false, val showPlayCount: Boolean = false,
val theme: String = "dark-ocean", val theme: String = "dark-ocean",
val absUrl: String = "",
val absApiKey: String = "",
val absChapterTrackMode: Boolean = false,
/** Offline-Downloads nur ueber WLAN. Standard an: eine grosse Playlist sind schnell
* mehrere Gigabyte, und die Wiederholkette laeuft ohne Zutun weiter. */
val downloadWifiOnly: Boolean = true,
/** Waagerechtes Wischen im Now-Playing wechselt den Titel statt der Ansicht.
* Standard an — Titelwechsel ist die Geste, die man dort staendig braucht. */
val wischenWechseltTitel: Boolean = true,
/** Im Lyrics-Tab automatisch zur laufenden Zeile scrollen. Standard AUS: wer selbst
* blaettert, will nicht, dass der Text unter dem Finger wegspringt. Umschalten direkt
* im Lyrics-Tab, wirkt nur bei synchronen Texten. */
val lyricsFolgenAutomatisch: Boolean = false,
)
data class LastPlayedSong(
val id: String,
val title: String,
val artist: String,
val coverArtId: String?,
) )
val credentials: Flow<Credentials> = context.dataStore.data.map { prefs -> val credentials: Flow<Credentials> = context.dataStore.data.map { prefs ->
Credentials( Credentials(
serverUrl = prefs[KEY_SERVER] ?: "", // Adresse vorbelegt, Zugangsdaten bewusst nicht — die gehoeren pro Person.
serverUrl = prefs[KEY_SERVER]?.ifBlank { null }
?: com.novasonic.app.BuildConfig.DEFAULT_ND_URL,
username = prefs[KEY_USERNAME] ?: "", username = prefs[KEY_USERNAME] ?: "",
password = prefs[KEY_PASSWORD] ?: "", password = prefs[KEY_PASSWORD] ?: "",
) )
@@ -48,14 +90,36 @@ class PrefsStore(private val context: Context) {
val appSettings: Flow<AppSettings> = context.dataStore.data.map { prefs -> val appSettings: Flow<AppSettings> = context.dataStore.data.map { prefs ->
AppSettings( AppSettings(
serverUrl = prefs[KEY_SERVER] ?: "", serverUrl = prefs[KEY_SERVER]?.ifBlank { null }
?: com.novasonic.app.BuildConfig.DEFAULT_ND_URL,
username = prefs[KEY_USERNAME] ?: "", username = prefs[KEY_USERNAME] ?: "",
password = prefs[KEY_PASSWORD] ?: "", password = prefs[KEY_PASSWORD] ?: "",
lastFmKey = prefs[KEY_LASTFM_KEY] ?: "", lastFmKey = prefs[KEY_LASTFM_KEY] ?: "",
backendUrl = prefs[KEY_BACKEND_URL] ?: "", backendUrl = prefs[KEY_BACKEND_URL]?.ifBlank { null }
?: com.novasonic.app.BuildConfig.DEFAULT_BACKEND_URL,
// Leerer Speicherwert => eingebaute Vorgabe. So muss auf einem frischen Geraet nichts
// eingetippt werden, ein eigener Eintrag hat aber weiterhin Vorrang.
scrobbleUrl = prefs[KEY_SCROBBLE_URL]?.ifBlank { null }
?: com.novasonic.app.BuildConfig.DEFAULT_SCROBBLE_URL,
scrobbleMode = prefs[KEY_SCROBBLE_MODE] ?: "30s", scrobbleMode = prefs[KEY_SCROBBLE_MODE] ?: "30s",
showPlayCount = prefs[KEY_SHOW_COUNT] ?: false, showPlayCount = prefs[KEY_SHOW_COUNT] ?: false,
theme = prefs[KEY_THEME] ?: "dark-ocean", theme = prefs[KEY_THEME] ?: "dark-ocean",
absUrl = prefs[KEY_ABS_URL] ?: "",
absApiKey = prefs[KEY_ABS_API_KEY] ?: "",
absChapterTrackMode = prefs[KEY_ABS_CHAPTER_TRACK] ?: false,
downloadWifiOnly = prefs[KEY_DL_WIFI_ONLY] ?: true,
wischenWechseltTitel = prefs[KEY_WISCH_TITEL] ?: true,
lyricsFolgenAutomatisch = prefs[KEY_LYRICS_FOLGEN] ?: false,
)
}
val lastPlayedSong: Flow<LastPlayedSong?> = context.dataStore.data.map { prefs ->
val id = prefs[KEY_LAST_SONG_ID]?.takeIf { it.isNotBlank() } ?: return@map null
LastPlayedSong(
id = id,
title = prefs[KEY_LAST_SONG_TITLE] ?: "",
artist = prefs[KEY_LAST_SONG_ARTIST] ?: "",
coverArtId = prefs[KEY_LAST_SONG_COVER]?.takeIf { it.isNotBlank() },
) )
} }
@@ -74,16 +138,74 @@ class PrefsStore(private val context: Context) {
prefs[KEY_PASSWORD] = settings.password prefs[KEY_PASSWORD] = settings.password
prefs[KEY_LASTFM_KEY] = settings.lastFmKey prefs[KEY_LASTFM_KEY] = settings.lastFmKey
prefs[KEY_BACKEND_URL] = settings.backendUrl prefs[KEY_BACKEND_URL] = settings.backendUrl
prefs[KEY_SCROBBLE_URL] = settings.scrobbleUrl
prefs[KEY_SCROBBLE_MODE] = settings.scrobbleMode prefs[KEY_SCROBBLE_MODE] = settings.scrobbleMode
prefs[KEY_SHOW_COUNT] = settings.showPlayCount prefs[KEY_SHOW_COUNT] = settings.showPlayCount
prefs[KEY_THEME] = settings.theme prefs[KEY_THEME] = settings.theme
prefs[KEY_ABS_URL] = settings.absUrl
prefs[KEY_ABS_API_KEY] = settings.absApiKey
prefs[KEY_ABS_CHAPTER_TRACK] = settings.absChapterTrackMode
prefs[KEY_DL_WIFI_ONLY] = settings.downloadWifiOnly
prefs[KEY_WISCH_TITEL] = settings.wischenWechseltTitel
// KEY_LYRICS_FOLGEN bewusst NICHT: der Schalter sitzt im Lyrics-Tab und wird mit
// saveLyricsFolgen() einzeln geschrieben. Wuerde er hier mitgeschrieben, setzte jedes
// Speichern in den Einstellungen ihn auf die Vorgabe zurueck — der Bildschirm fuehrt
// dieses Feld gar nicht mit.
} }
} }
/** Einzeln speicherbar: der Schalter sitzt im Lyrics-Tab, nicht in den Einstellungen, und
* darf dort nicht den ganzen Einstellungssatz ueberschreiben. */
suspend fun saveLyricsFolgen(an: Boolean) {
context.dataStore.edit { prefs -> prefs[KEY_LYRICS_FOLGEN] = an }
}
suspend fun saveTheme(themeId: String) { suspend fun saveTheme(themeId: String) {
context.dataStore.edit { prefs -> prefs[KEY_THEME] = themeId } context.dataStore.edit { prefs -> prefs[KEY_THEME] = themeId }
} }
suspend fun saveLastSong(id: String, title: String, artist: String, coverArt: String?) {
context.dataStore.edit { prefs ->
prefs[KEY_LAST_SONG_ID] = id
prefs[KEY_LAST_SONG_TITLE] = title
prefs[KEY_LAST_SONG_ARTIST] = artist
prefs[KEY_LAST_SONG_COVER] = coverArt ?: ""
}
}
private val queueJson = kotlinx.serialization.json.Json { ignoreUnknownKeys = true }
/**
* Sichert die Warteschlange als VOLLSTAENDIGE Songs, nicht nur als Ids. Mit Ids musste beim
* Start jeder Titel einzeln ueber das Netz nachgeladen werden — das dauerte Sekunden und ging
* ohne Verbindung gar nicht. So ist das Wiederherstellen ein rein lokaler Lesevorgang.
* Der Preis: zwischenzeitlich geaenderte Titel oder Cover zeigen bis zum naechsten Abspielen
* den alten Stand. Das ist die deutlich kleinere Unschoenheit.
*/
suspend fun saveQueueState(songs: List<com.novasonic.app.api.model.Song>, index: Int) {
val kodiert = runCatching {
queueJson.encodeToString(kotlinx.serialization.builtins.ListSerializer(
com.novasonic.app.api.model.Song.serializer()), songs)
}.getOrNull() ?: return
context.dataStore.edit { prefs ->
prefs[KEY_QUEUE_JSON] = kodiert
prefs[KEY_QUEUE_INDEX] = index.coerceAtLeast(0)
}
}
data class QueueState(val songs: List<com.novasonic.app.api.model.Song>, val index: Int)
suspend fun readQueueState(): QueueState? {
val prefs = context.dataStore.data.first()
val roh = prefs[KEY_QUEUE_JSON]?.takeIf { it.isNotBlank() } ?: return null
val songs = runCatching {
queueJson.decodeFromString(kotlinx.serialization.builtins.ListSerializer(
com.novasonic.app.api.model.Song.serializer()), roh)
}.getOrNull().orEmpty()
if (songs.isEmpty()) return null
return QueueState(songs, (prefs[KEY_QUEUE_INDEX] ?: 0).coerceIn(0, songs.lastIndex))
}
suspend fun clear() { suspend fun clear() {
context.dataStore.edit { it.clear() } context.dataStore.edit { it.clear() }
} }
@@ -0,0 +1,33 @@
package com.novasonic.app.data
import com.novasonic.app.api.model.Song
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
/**
* Global, reactive star/favorite overrides. Tapping a star flips the state here *immediately*
* (optimistic), so every screen showing that song updates at once — regardless of when each
* screen last fetched `song.starred`. The API call runs in the background and reverts on failure.
*/
object StarState {
private val _overrides = MutableStateFlow<Map<String, Boolean>>(emptyMap())
val overrides: StateFlow<Map<String, Boolean>> = _overrides.asStateFlow()
/** Current starred state for a song: the live override if present, else the song's own flag. */
fun isStarred(song: Song): Boolean = _overrides.value[song.id] ?: (song.starred != null)
fun isStarred(songId: String, fallback: Boolean): Boolean = _overrides.value[songId] ?: fallback
/** Optimistically toggle, then hit the API; revert the override if the call fails. */
fun toggle(repo: MusicRepository, scope: CoroutineScope, songId: String, fallbackStarred: Boolean) {
val current = _overrides.value[songId] ?: fallbackStarred
val next = !current
_overrides.value = _overrides.value + (songId to next)
scope.launch {
val ok = runCatching { if (next) repo.star(songId) else repo.unstar(songId) }.isSuccess
if (!ok) _overrides.value = _overrides.value + (songId to current) // revert on failure
}
}
}
@@ -0,0 +1,155 @@
package com.novasonic.app.offline
import android.content.Context
import android.util.Log
import androidx.work.*
import com.novasonic.app.app
import com.novasonic.app.data.PrefsStore
import com.novasonic.app.api.SubsonicClient
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileOutputStream
import java.net.HttpURLConnection
import java.net.URL
class DownloadWorker(
appContext: Context,
params: WorkerParameters,
) : CoroutineWorker(appContext, params) {
companion object {
const val EXTRA_GROUP_ID = "group_id"
private const val TAG = "DownloadWorker"
/** Obergrenze fuer selbst angeforderte Wiederholungen, damit dauerhaft kaputte Titel
* (auf dem Server geloescht, immer 404) die Kette nicht endlos weiterlaufen lassen. */
private const val MAX_VERSUCHE = 20
}
private val offlineRepo = applicationContext.app.offlineRepository
override suspend fun doWork(): Result {
val groupId = inputData.getString(EXTRA_GROUP_ID) ?: return Result.failure()
// Nur die Existenz zaehlt — der Fortschritt wird unten neu gezaehlt, nicht fortgeschrieben.
offlineRepo.getGroup(groupId) ?: return Result.failure()
val songIds = offlineRepo.songIdsForGroup(groupId)
if (songIds.isEmpty()) return Result.success()
val creds = PrefsStore(applicationContext).credentials.first()
if (!creds.isValid) return Result.failure()
val subsonicClient = SubsonicClient(creds.serverUrl, creds.username, creds.password)
// Bei 0 anfangen und JEDEN fertigen Titel zaehlen — auch die aus frueheren Laeufen, die
// gleich uebersprungen werden. Frueher stand hier group.downloadedTracks, und die Schleife
// zaehlte dieselben Titel gleich nochmal: nach einem Fortsetzen mit 412 fertigen Titeln
// meldete die Gruppe 824. Ueberschreitet der Wert totalTracks, gilt die Gruppe als
// "Vollstaendig" und der Herunterladen-Knopf wird unantastbar, obwohl Titel fehlen.
var done = 0
val dao = OfflineDatabase.get(applicationContext).offlineDao()
return try {
var gestoppt = false
for (songId in songIds) {
// WorkManager raeumt Hintergrundarbeit rund 10 Minuten ein und stoppt sie dann.
// Ohne diese Pruefung laeuft die Schleife blind weiter, bis sie hart abgebrochen
// wird — der angefangene Titel geht verloren und niemand startet neu. So steigen
// wir sauber aus und fordern den naechsten Lauf an; Fertiges wird uebersprungen.
if (isStopped) { gestoppt = true; break }
if (offlineRepo.getTrackState(songId) == DownloadState.DONE) {
// Kein Schreibvorgang beim Ueberspringen: der Fortschritt aendert sich dabei
// nicht, und bei 1900 Titeln waeren das 1900 unnoetige Schreibzugriffe je Lauf.
done++
continue
}
val track = offlineRepo.getTrack(songId) ?: continue
dao.updateState(songId, DownloadState.DOWNLOADING, 0f)
val suffix = track.suffix?.takeIf { it.isNotBlank() } ?: "mp3"
val audioFile = offlineRepo.audioFile(songId, suffix)
try {
streamToFile(subsonicClient.streamUrl(songId), audioFile)
val coverPath = track.coverArt?.let { coverArtId ->
val existing = offlineRepo.localCoverPath(coverArtId)
if (existing != null && File(existing).exists()) {
existing
} else {
val coverFile = offlineRepo.coverFile(coverArtId)
runCatching { streamToFile(subsonicClient.coverArtUrl(coverArtId, 512), coverFile) }
if (coverFile.exists()) coverFile.absolutePath else null
}
}
offlineRepo.markDone(songId, audioFile.absolutePath, coverPath)
done++
} catch (e: Exception) {
Log.e(TAG, "Titel $songId fehlgeschlagen", e)
audioFile.delete()
offlineRepo.markFailed(songId)
}
dao.updateGroupProgress(groupId, done)
}
// Beim Abbruch ist der letzte Stand sonst nicht gesichert.
if (gestoppt) dao.updateGroupProgress(groupId, done)
val offen = dao.offeneTitel(groupId)
when {
gestoppt -> {
Log.i(TAG, "Gestoppt bei $done/${songIds.size} — fordere naechsten Lauf an")
Result.retry()
}
offen == 0 -> {
Log.i(TAG, "Gruppe $groupId vollstaendig (${songIds.size} Titel)")
Result.success()
}
runAttemptCount < MAX_VERSUCHE -> {
Log.i(TAG, "$offen Titel offen (Versuch $runAttemptCount) — noch ein Lauf")
Result.retry()
}
else -> {
// Aufgeben, aber nicht stillschweigend: die Gruppenzeile zeigt weiterhin
// "x/y Titel", und ein Tipp auf Herunterladen startet die Kette neu.
Log.w(TAG, "$offen Titel bleiben offen — nach $runAttemptCount Versuchen aufgegeben")
Result.success()
}
}
} catch (e: Exception) {
Log.e(TAG, "Lauf fuer Gruppe $groupId abgebrochen", e)
// Frueher Result.failure(): ein einzelner Netzfehler beendete die ganze Kette endgueltig.
if (runAttemptCount < MAX_VERSUCHE) Result.retry() else Result.failure()
}
}
private suspend fun streamToFile(url: String, dest: File) = withContext(Dispatchers.IO) {
val tmp = File("${dest.absolutePath}.tmp")
try {
val conn = URL(url).openConnection() as HttpURLConnection
conn.connectTimeout = 30_000
conn.readTimeout = 120_000
conn.connect()
if (conn.responseCode !in 200..299) {
throw Exception("HTTP ${conn.responseCode} for ${dest.name}")
}
conn.inputStream.use { input ->
FileOutputStream(tmp).use { out ->
val buf = ByteArray(32_768)
var n: Int
while (input.read(buf).also { n = it } >= 0) {
out.write(buf, 0, n)
}
}
}
if (!tmp.renameTo(dest)) {
tmp.copyTo(dest, overwrite = true)
tmp.delete()
}
} catch (e: Exception) {
tmp.delete()
throw e
}
}
}
@@ -0,0 +1,125 @@
package com.novasonic.app.offline
import androidx.room.*
import kotlinx.coroutines.flow.Flow
@Dao
interface OfflineDao {
// ── Tracks ────────────────────────────────────────────────────────────────
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertTrack(track: DownloadedTrackEntity)
@Query("UPDATE downloaded_tracks SET state = :state, progress = :progress WHERE songId = :songId")
suspend fun updateState(songId: String, state: DownloadState, progress: Float)
@Query("UPDATE downloaded_tracks SET state = 'DONE', progress = 1, localPath = :localPath, coverPath = :coverPath, downloadedAt = :at WHERE songId = :songId")
suspend fun markDone(songId: String, localPath: String, coverPath: String?, at: Long)
/** Emits whenever any downloaded track changes — drives the hot in-memory maps. */
@Query("SELECT songId, localPath, coverArt, coverPath FROM downloaded_tracks WHERE state = 'DONE'")
fun doneTracksFlow(): Flow<List<DoneTrackInfo>>
@Query("SELECT * FROM downloaded_tracks WHERE songId = :songId")
fun trackFlow(songId: String): Flow<DownloadedTrackEntity?>
@Query("SELECT * FROM downloaded_tracks WHERE songId = :songId")
suspend fun getTrackById(songId: String): DownloadedTrackEntity?
@Query("SELECT state FROM downloaded_tracks WHERE songId = :songId")
suspend fun getTrackStateRaw(songId: String): String?
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insertTrackIfAbsent(track: DownloadedTrackEntity)
@Query("SELECT * FROM downloaded_tracks ORDER BY downloadedAt DESC")
fun allTracksFlow(): Flow<List<DownloadedTrackEntity>>
@Query("SELECT COUNT(*) FROM group_track_cross_refs WHERE songId = :songId")
suspend fun groupCountForSong(songId: String): Int
@Query("DELETE FROM downloaded_tracks WHERE songId = :songId")
suspend fun deleteTrackById(songId: String)
// ── Groups ────────────────────────────────────────────────────────────────
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertGroup(group: DownloadGroupEntity)
@Query("SELECT * FROM download_groups ORDER BY createdAt DESC")
fun allGroupsFlow(): Flow<List<DownloadGroupEntity>>
@Query("SELECT * FROM download_groups WHERE groupId = :groupId")
suspend fun getGroup(groupId: String): DownloadGroupEntity?
/**
* Rechnet den gespeicherten Fortschritt ALLER Gruppen aus dem tatsaechlichen Zustand der Titel
* neu. Noetig, weil der Worker bis 1.10 doppelt zaehlte: der Wert konnte totalTracks
* uebersteigen, die Gruppe galt als "Vollstaendig", der Herunterladen-Knopf wurde unantastbar
* und das Fortsetzen uebersprang sie — der falsche Wert konnte sich also nie mehr korrigieren.
* Eine Anweisung fuer alle Gruppen, laeuft beim App-Start.
*/
@Query("""
UPDATE download_groups SET downloadedTracks = (
SELECT COUNT(*) FROM group_track_cross_refs r
INNER JOIN downloaded_tracks t ON t.songId = r.songId
WHERE r.groupId = download_groups.groupId AND t.state = 'DONE'
)
""")
suspend fun fortschrittNeuBerechnen()
/** Gruppen, bei denen noch Titel fehlen — Grundlage fuers Fortsetzen beim App-Start. */
@Query("SELECT * FROM download_groups WHERE totalTracks > 0 AND downloadedTracks < totalTracks")
suspend fun incompleteGroups(): List<DownloadGroupEntity>
@Query("DELETE FROM download_groups WHERE groupId = :groupId")
suspend fun deleteGroup(groupId: String)
@Query("UPDATE download_groups SET downloadedTracks = :count WHERE groupId = :groupId")
suspend fun updateGroupProgress(groupId: String, count: Int)
@Query("UPDATE download_groups SET totalTracks = :total WHERE groupId = :groupId")
suspend fun updateGroupTotal(groupId: String, total: Int)
// ── Cross-refs ────────────────────────────────────────────────────────────
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insertCrossRef(ref: GroupTrackCrossRef)
@Query("SELECT songId FROM group_track_cross_refs WHERE groupId = :groupId")
suspend fun songIdsForGroup(groupId: String): List<String>
@Query("""
SELECT t.* FROM downloaded_tracks t
INNER JOIN group_track_cross_refs r ON t.songId = r.songId
WHERE r.groupId = :groupId
""")
suspend fun tracksForGroup(groupId: String): List<DownloadedTrackEntity>
@Query("""
SELECT t.* FROM downloaded_tracks t
INNER JOIN group_track_cross_refs r ON t.songId = r.songId
WHERE r.groupId = :groupId
""")
fun tracksForGroupFlow(groupId: String): Flow<List<DownloadedTrackEntity>>
/** Wie viele Titel der Gruppe noch nicht fertig sind — eine Abfrage statt einer pro Titel. */
@Query("""
SELECT COUNT(*) FROM downloaded_tracks t
INNER JOIN group_track_cross_refs r ON t.songId = r.songId
WHERE r.groupId = :groupId AND t.state != 'DONE'
""")
suspend fun offeneTitel(groupId: String): Int
@Query("DELETE FROM group_track_cross_refs WHERE groupId = :groupId AND songId = :songId")
suspend fun removeCrossRef(groupId: String, songId: String)
/** Wie viele Titel dieses Cover noch benutzen — Cover werden geteilt gespeichert. */
@Query("SELECT COUNT(*) FROM downloaded_tracks WHERE coverArt = :coverArtId")
suspend fun titelMitCover(coverArtId: String): Int
/** Find a locally-stored cover path by Navidrome coverArt ID (deduped storage). */
@Query("SELECT coverPath FROM downloaded_tracks WHERE coverArt = :coverArtId AND state = 'DONE' AND coverPath IS NOT NULL LIMIT 1")
suspend fun localCoverPathByCoverArt(coverArtId: String): String?
}
@@ -0,0 +1,38 @@
package com.novasonic.app.offline
import android.content.Context
import androidx.room.*
@TypeConverters(OfflineConverters::class)
@Database(
entities = [
DownloadedTrackEntity::class,
DownloadGroupEntity::class,
GroupTrackCrossRef::class,
],
version = 1,
exportSchema = false,
)
abstract class OfflineDatabase : RoomDatabase() {
abstract fun offlineDao(): OfflineDao
companion object {
@Volatile private var INSTANCE: OfflineDatabase? = null
fun get(context: Context): OfflineDatabase = INSTANCE ?: synchronized(this) {
INSTANCE ?: Room.databaseBuilder(
context.applicationContext,
OfflineDatabase::class.java,
"novasonic_offline.db",
).build().also { INSTANCE = it }
}
}
}
class OfflineConverters {
@TypeConverter fun fromState(v: DownloadState): String = v.name
@TypeConverter fun toState(v: String): DownloadState = DownloadState.valueOf(v)
@TypeConverter fun fromType(v: GroupType): String = v.name
@TypeConverter fun toType(v: String): GroupType = GroupType.valueOf(v)
}
@@ -0,0 +1,91 @@
package com.novasonic.app.offline
import androidx.room.*
import com.novasonic.app.api.model.Song
enum class DownloadState { QUEUED, DOWNLOADING, DONE, FAILED }
enum class GroupType { SONG, ALBUM, PLAYLIST, FAVORITES }
/** Maps a stored offline track back to a domain [Song] for playback / list display. */
fun DownloadedTrackEntity.toSong() = Song(
id = songId,
title = title,
album = album,
albumId = albumId,
artist = artist,
artistId = artistId,
track = track,
year = year,
genre = genre,
coverArt = coverArt,
duration = duration,
suffix = suffix,
contentType = contentType,
bitRate = bitRate,
starred = starred,
)
/** Lightweight projection used to keep the hot in-memory maps up to date. */
data class DoneTrackInfo(
val songId: String,
val localPath: String,
val coverArt: String?,
val coverPath: String?,
)
@Entity(tableName = "downloaded_tracks")
data class DownloadedTrackEntity(
@PrimaryKey val songId: String,
val title: String,
val artist: String?,
val artistId: String?,
val album: String?,
val albumId: String?,
val coverArt: String?,
val track: Int?,
val year: Int?,
val genre: String?,
val duration: Int?,
val suffix: String?,
val contentType: String?,
val bitRate: Int?,
val starred: String?,
val localPath: String,
val coverPath: String?,
val state: DownloadState,
val progress: Float = 0f,
val downloadedAt: Long = 0L,
)
@Entity(tableName = "download_groups")
data class DownloadGroupEntity(
@PrimaryKey val groupId: String, // e.g. "album:abc123", "playlist:xyz", "favorites"
val type: GroupType,
val sourceId: String,
val name: String,
val coverArt: String?,
val totalTracks: Int = 0,
val downloadedTracks: Int = 0,
val createdAt: Long = System.currentTimeMillis(),
)
@Entity(
tableName = "group_track_cross_refs",
primaryKeys = ["groupId", "songId"],
foreignKeys = [
ForeignKey(
entity = DownloadGroupEntity::class,
parentColumns = ["groupId"],
childColumns = ["groupId"],
onDelete = ForeignKey.CASCADE,
),
ForeignKey(
entity = DownloadedTrackEntity::class,
parentColumns = ["songId"],
childColumns = ["songId"],
onDelete = ForeignKey.CASCADE,
),
],
indices = [Index("songId")],
)
data class GroupTrackCrossRef(val groupId: String, val songId: String)
@@ -0,0 +1,287 @@
package com.novasonic.app.offline
import android.content.Context
import android.util.Log
import androidx.work.*
import com.novasonic.app.api.model.Song
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import java.io.File
class OfflineRepository(context: Context) {
private val appContext = context.applicationContext
private val dao = OfflineDatabase.get(appContext).offlineDao()
private val scope = CoroutineScope(
SupervisorJob() + Dispatchers.IO +
CoroutineExceptionHandler { _, t -> Log.e("OfflineRepository", "Unhandled exception", t) }
)
// ── Hot in-memory maps (no suspend needed for lookups) ────────────────────
// songId → absolute local audio path
private val _audioMap = MutableStateFlow<Map<String, String>>(emptyMap())
// coverArtId (Navidrome) → absolute local cover path
private val _coverMap = MutableStateFlow<Map<String, String>>(emptyMap())
/** Reactive set of all downloaded song IDs — collect in UI for per-row indicators. */
val downloadedIds: StateFlow<Set<String>> = _audioMap
.map { it.keys.toSet() }
.stateIn(scope, SharingStarted.Eagerly, emptySet())
init {
scope.launch {
dao.doneTracksFlow().collect { tracks ->
_audioMap.value = tracks.associate { it.songId to it.localPath }
_coverMap.value = tracks
.filter { it.coverArt != null && it.coverPath != null }
.associate { it.coverArt!! to it.coverPath!! }
}
}
}
// ── Synchronous lookups (called from MusicRepository — no coroutine) ──────
fun isDownloaded(songId: String): Boolean = songId in _audioMap.value
fun localAudioPath(songId: String): String? = _audioMap.value[songId]
fun localCoverPath(coverArtId: String): String? = _coverMap.value[coverArtId]
// ── Storage layout ────────────────────────────────────────────────────────
fun audioDir(): File = File(appContext.filesDir, "offline/audio").also { it.mkdirs() }
fun coversDir(): File = File(appContext.filesDir, "offline/covers").also { it.mkdirs() }
fun audioFile(songId: String, suffix: String): File = File(audioDir(), "$songId.$suffix")
fun coverFile(coverArtId: String): File = File(coversDir(), "$coverArtId.jpg")
// ── Reactive flows for UI ─────────────────────────────────────────────────
val allGroupsFlow: Flow<List<DownloadGroupEntity>> = dao.allGroupsFlow()
val allTracksFlow: Flow<List<DownloadedTrackEntity>> = dao.allTracksFlow()
fun trackFlow(songId: String): Flow<DownloadedTrackEntity?> = dao.trackFlow(songId)
// ── Write operations (used by DownloadWorker — Phase 2) ──────────────────
suspend fun insertTrack(entity: DownloadedTrackEntity) = dao.insertTrack(entity)
suspend fun updateState(songId: String, state: DownloadState, progress: Float) =
dao.updateState(songId, state, progress)
suspend fun markDone(songId: String, localPath: String, coverPath: String?) =
dao.markDone(songId, localPath, coverPath, System.currentTimeMillis())
suspend fun markFailed(songId: String) =
dao.updateState(songId, DownloadState.FAILED, 0f)
suspend fun insertGroup(group: DownloadGroupEntity) = dao.insertGroup(group)
suspend fun getGroup(groupId: String) = dao.getGroup(groupId)
suspend fun updateGroupProgress(groupId: String, count: Int) =
dao.updateGroupProgress(groupId, count)
suspend fun updateGroupTotal(groupId: String, total: Int) =
dao.updateGroupTotal(groupId, total)
suspend fun insertCrossRef(groupId: String, songId: String) =
dao.insertCrossRef(GroupTrackCrossRef(groupId, songId))
suspend fun songIdsForGroup(groupId: String): List<String> = dao.songIdsForGroup(groupId)
suspend fun getTrack(songId: String): DownloadedTrackEntity? = dao.getTrackById(songId)
suspend fun tracksForGroup(groupId: String): List<DownloadedTrackEntity> = dao.tracksForGroup(groupId)
fun tracksForGroupFlow(groupId: String): Flow<List<DownloadedTrackEntity>> = dao.tracksForGroupFlow(groupId)
suspend fun getTrackState(songId: String): DownloadState? =
dao.getTrackStateRaw(songId)?.let { DownloadState.valueOf(it) }
/**
* Inserts all songs as QUEUED into Room, creates a download group, and enqueues a WorkManager
* job that downloads the files in the background. Already-DONE tracks are counted but not
* re-downloaded. Safe to call for an existing groupId — WorkManager KEEP policy is used.
*/
suspend fun enqueueGroup(
type: GroupType,
sourceId: String,
name: String,
coverArt: String?,
songs: List<Song>,
) {
val groupId = "${type.name.lowercase()}:$sourceId"
// Preserve creation time + progress when re-enqueuing (resume / re-download missing songs).
val existing = dao.getGroup(groupId)
dao.insertGroup(
DownloadGroupEntity(
groupId = groupId,
type = type,
sourceId = sourceId,
name = name,
coverArt = coverArt,
totalTracks = songs.size,
downloadedTracks = existing?.downloadedTracks ?: 0,
createdAt = existing?.createdAt ?: System.currentTimeMillis(),
)
)
var alreadyDone = 0
for (song in songs) {
if (isDownloaded(song.id)) {
dao.insertCrossRef(GroupTrackCrossRef(groupId, song.id))
alreadyDone++
} else {
dao.insertTrackIfAbsent(
DownloadedTrackEntity(
songId = song.id,
title = song.title,
artist = song.artist,
artistId = song.artistId,
album = song.album,
albumId = song.albumId,
coverArt = song.coverArt,
track = song.track,
year = song.year,
genre = song.genre,
duration = song.duration,
suffix = song.suffix,
contentType = song.contentType,
bitRate = song.bitRate,
starred = song.starred,
localPath = "",
coverPath = null,
state = DownloadState.QUEUED,
)
)
dao.insertCrossRef(GroupTrackCrossRef(groupId, song.id))
}
}
dao.updateGroupProgress(groupId, alreadyDone)
starteWorker(groupId)
}
/**
* Startet (oder setzt fort) die Downloadarbeit einer Gruppe. KEEP heisst: laeuft schon etwas
* fuer diese Gruppe, passiert nichts — sonst beginnt ein Lauf, der alles Fertige ueberspringt.
*/
private suspend fun starteWorker(groupId: String, ersetzen: Boolean = false) {
// UNMETERED = WLAN (bzw. jede nicht getaktete Verbindung). WorkManager pausiert den Download
// dann von selbst, sobald das WLAN weg ist, und setzt fort, sobald es zurueck ist. Mit
// CONNECTED liefe die Wiederholkette auch ueber Mobilfunk durch — bei einer grossen Playlist
// sind das schnell mehrere Gigabyte ohne Zutun des Nutzers.
val nurWlan = runCatching {
com.novasonic.app.data.PrefsStore(appContext).appSettings.first().downloadWifiOnly
}.getOrDefault(true)
val request = OneTimeWorkRequestBuilder<DownloadWorker>()
.setInputData(workDataOf(DownloadWorker.EXTRA_GROUP_ID to groupId))
.setConstraints(
Constraints.Builder()
.setRequiredNetworkType(if (nurWlan) NetworkType.UNMETERED else NetworkType.CONNECTED)
.setRequiresStorageNotLow(true)
.build()
)
// Ohne Backoff wuerde ein Result.retry() sofort erneut anlaufen; 30 s linear geben dem
// Geraet Luft und halten die Kette trotzdem in Gang.
.setBackoffCriteria(BackoffPolicy.LINEAR, 30, java.util.concurrent.TimeUnit.SECONDS)
.build()
WorkManager.getInstance(appContext).enqueueUniqueWork(
groupId,
if (ersetzen) ExistingWorkPolicy.REPLACE else ExistingWorkPolicy.KEEP,
request,
)
}
/**
* Nach einer Aenderung an "nur ueber WLAN" die laufende Arbeit neu einreihen. WorkManager
* aendert die Bedingungen einer bereits eingereihten Arbeit nicht mehr — ohne das bliebe der
* Schalter bis zum naechsten App-Start wirkungslos. REPLACE ist unbedenklich, weil der Worker
* ohnehin fortsetzt statt von vorn zu laden.
*/
fun netzbedingungAktualisieren() {
scope.launch {
runCatching { dao.incompleteGroups() }.getOrDefault(emptyList())
.forEach { starteWorker(it.groupId, ersetzen = true) }
}
}
/**
* Beim App-Start unvollstaendige Gruppen weiterlaufen lassen. WorkManager stoppt einen
* Hintergrund-Worker nach rund 10 Minuten; eine Playlist mit 1900 Titeln braucht daher viele
* Laeufe. Der Worker fordert selbst einen neuen an (Result.retry()), aber wenn die Kette doch
* einmal reisst — Neustart des Geraets, aufgebrauchte Versuche — faengt das hier es auf, statt
* darauf zu warten, dass jemand von Hand erneut auf Herunterladen tippt.
*/
fun setzeUnvollstaendigeFort() {
scope.launch {
// Erst den gespeicherten Fortschritt begradigen: Gruppen mit einem zu hohen Wert aus
// der Zeit vor 1.10 sehen sonst vollstaendig aus und werden hier gar nicht gefunden.
runCatching { dao.fortschrittNeuBerechnen() }
.onFailure { Log.w("OfflineRepository", "Fortschritt neu berechnen fehlgeschlagen", it) }
val offen = runCatching { dao.incompleteGroups() }.getOrDefault(emptyList())
offen.forEach { g ->
Log.i("OfflineRepository",
"Setze fort: ${g.groupId} (${g.downloadedTracks}/${g.totalTracks})")
starteWorker(g.groupId)
}
}
}
/**
* Entfernt alle Dateien eines Titels und dann die Datenbankzeile.
*
* Frueher lief das ueber _audioMap — die kennt aber nur FERTIGE Titel. Ein abgebrochener oder
* fehlgeschlagener Download hinterliess seine Datei also unberuehrt. Jetzt kommt der Pfad aus
* der Zeile selbst, dazu die angefangene .tmp und das Cover, sofern es kein anderer Titel mehr
* benutzt (Cover werden geteilt gespeichert).
*/
private suspend fun loescheTitelVollstaendig(songId: String) {
val track = dao.getTrackById(songId)
val pfade = listOfNotNull(track?.localPath, _audioMap.value[songId])
pfade.distinct().forEach { p ->
runCatching { File(p).delete(); File("$p.tmp").delete() }
}
track?.coverArt?.let { coverArtId ->
// Diese Zeile zaehlt noch mit, deshalb ist 1 der letzte Benutzer.
if (dao.titelMitCover(coverArtId) <= 1) {
runCatching { File(coversDir(), "$coverArtId.jpg").delete() }
track.coverPath?.let { runCatching { File(it).delete() } }
}
}
dao.deleteTrackById(songId)
}
// ── Delete with reference-count file cleanup ──────────────────────────────
/** Removes a group and any tracks that are no longer referenced by another group. */
suspend fun deleteGroup(groupId: String) {
val songIds = dao.songIdsForGroup(groupId)
// Laufende Downloadarbeit stoppen, sonst laedt sie noch Minuten weiter ins Leere.
WorkManager.getInstance(appContext).cancelUniqueWork(groupId)
dao.deleteGroup(groupId) // cascades GroupTrackCrossRef rows
for (songId in songIds) {
if (dao.groupCountForSong(songId) == 0) loescheTitelVollstaendig(songId)
}
}
/** Removes a single track from a group, deleting the file if no other group still needs it. */
suspend fun removeSongFromGroup(groupId: String, songId: String) {
dao.removeCrossRef(groupId, songId)
if (dao.groupCountForSong(songId) == 0) loescheTitelVollstaendig(songId)
recountGroup(groupId)
}
/** Recomputes a group's total + downloaded counts from its cross-refs; deletes it if empty. */
private suspend fun recountGroup(groupId: String) {
val tracks = dao.tracksForGroup(groupId)
if (tracks.isEmpty()) {
dao.deleteGroup(groupId)
return
}
dao.updateGroupTotal(groupId, tracks.size)
dao.updateGroupProgress(groupId, tracks.count { it.state == DownloadState.DONE })
}
// ── Storage accounting ────────────────────────────────────────────────────
fun storageUsedBytes(): Long =
audioDir().walkTopDown().filter { it.isFile }.sumOf { it.length() } +
coversDir().walkTopDown().filter { it.isFile }.sumOf { it.length() }
}
@@ -0,0 +1,314 @@
package com.novasonic.app.player
import android.content.Context
import android.net.Uri
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import com.novasonic.app.app
import com.novasonic.app.api.AbsChapter
import com.novasonic.app.api.AbsClient
import com.novasonic.app.api.AbsLibraryItem
import com.novasonic.app.api.AbsAudioTrack
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
data class AbsPlayState(
val isLoading: Boolean = false,
val isPlaying: Boolean = false,
val item: AbsLibraryItem? = null,
val chapters: List<AbsChapter> = emptyList(),
val duration: Double = 0.0,
val currentTime: Double = 0.0,
val chapterIdx: Int = 0,
val speed: Float = 1f,
val sleepRemainingSecs: Int? = null,
val chapterTrackMode: Boolean = false,
val sessionId: String? = null,
val error: String? = null,
)
class AbsPlayerController(context: Context) {
private val appContext = context.applicationContext
var scope = CoroutineScope(
Dispatchers.Main + SupervisorJob() +
CoroutineExceptionHandler { _, t -> android.util.Log.e("AbsPlayerController", "Uncaught coroutine exception", t) }
)
private set
private val _state = MutableStateFlow(AbsPlayState())
val state: StateFlow<AbsPlayState> = _state.asStateFlow()
val isActive: Boolean get() = _state.value.item != null
private var absClient: AbsClient? = null
private var audioTracks: List<AbsAudioTrack> = emptyList()
private var currentItemId: String? = null
private var isClosed = false
private var positionObserverJob: Job? = null
private var syncJob: Job? = null
private var sleepJob: Job? = null
private var sleepTickJob: Job? = null
fun currentCoverUrl(): String? {
val item = _state.value.item ?: return null
val base = absClient?.coverUrl(item.id) ?: return null
return "$base&width=512"
}
fun setChapterTrackMode(enabled: Boolean) {
_state.value = _state.value.copy(chapterTrackMode = enabled)
}
suspend fun playItem(item: AbsLibraryItem, client: AbsClient) {
if (isClosed) {
isClosed = false
scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
}
absClient = client
currentItemId = item.id
val prevSpeed = _state.value.speed
val chTrackMode = _state.value.chapterTrackMode
_state.value = AbsPlayState(isLoading = true, item = item, speed = prevSpeed, chapterTrackMode = chTrackMode)
// Cancel in-progress jobs from a previous session
positionObserverJob?.cancel()
stopSync()
cancelSleepInternal()
try {
val session = client.startSession(item.id)
val tracks = session.audioTracks
val chapters = session.chapters.ifEmpty { client.getItemChapters(item.id) }
val duration = tracks.sumOf { it.duration }.let { if (it > 0.0) it else item.media.duration }
val saved = client.getProgress(item.id)
val startTime = when {
(saved?.currentTime ?: 0.0) > 10.0 -> saved!!.currentTime
session.currentTime > 10.0 -> session.currentTime
else -> 0.0
}
audioTracks = tracks
currentItemId = item.id
_state.value = _state.value.copy(
isLoading = false,
sessionId = session.id,
chapters = chapters,
duration = duration,
currentTime = startTime,
chapterIdx = findChapterIdx(chapters, startTime),
)
if (tracks.isEmpty()) {
_state.value = _state.value.copy(error = "Keine Audiotracks gefunden")
return
}
val meta = item.media.metadata
val artworkUri = client.coverUrl(item.id)?.let { Uri.parse(it) }
// Each ABS track gets mediaId "abs:<contentUrl>" so PlayerController can detect
// ABS items and skip Navidrome scrobbling / last-song tracking.
val mediaItems = tracks.map { t ->
MediaItem.Builder()
.setMediaId("abs:${t.contentUrl}")
.setUri(client.audioTrackUrl(t.contentUrl))
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle(meta?.title ?: "Hörbuch")
.setArtist(meta?.authorName ?: "")
.setArtworkUri(artworkUri)
.build()
)
.build()
}
val (trackIdx, localSecs) = findTrack(tracks, startTime)
// Route audio through MusicService — same notification, same mini player
appContext.app.playerController.playAbsItems(
items = mediaItems,
startIndex = trackIdx,
startPositionMs = (localSecs * 1000).toLong(),
speed = prevSpeed,
)
startPositionObserver()
startSync()
} catch (e: Exception) {
_state.value = _state.value.copy(isLoading = false, error = e.message ?: "Fehler beim Laden")
}
}
// ── Position observer — keeps AbsPlayState in sync with MusicService player ──
private fun startPositionObserver() {
positionObserverJob?.cancel()
positionObserverJob = scope.launch {
appContext.app.playerController.state.collect { playerState ->
val s = _state.value
if (s.item == null || audioTracks.isEmpty()) return@collect
val trackIdx = playerState.currentIndex.coerceAtLeast(0)
val track = audioTracks.getOrNull(trackIdx) ?: return@collect
val localSecs = playerState.positionMs / 1000.0
val globalTime = track.startOffset + localSecs
val chapterIdx = findChapterIdx(s.chapters, globalTime)
_state.value = s.copy(
isPlaying = playerState.isPlaying,
currentTime = globalTime,
chapterIdx = chapterIdx,
)
if (playerState.isPlaying) startSync() else { stopSync(); doSync() }
}
}
}
// ── Playback controls — delegate to PlayerController ─────────────────────
fun togglePlay() = appContext.app.playerController.togglePlay()
fun pause() = appContext.app.playerController.pause()
fun resume() = appContext.app.playerController.play()
fun seekToGlobal(globalSecs: Double) {
val clamped = globalSecs.coerceIn(0.0, _state.value.duration)
val (trackIdx, localSecs) = findTrack(audioTracks, clamped)
appContext.app.playerController.seekToAbs(trackIdx, (localSecs * 1000).toLong())
_state.value = _state.value.copy(
currentTime = clamped,
chapterIdx = findChapterIdx(_state.value.chapters, clamped),
)
}
fun nextChapter() {
val s = _state.value
val next = s.chapters.getOrNull(s.chapterIdx + 1) ?: return
seekToGlobal(next.start)
}
fun prevChapter() {
val s = _state.value
val cur = s.chapters.getOrNull(s.chapterIdx)
if (cur != null && s.currentTime - cur.start > 5) { seekToGlobal(cur.start); return }
val prev = s.chapters.getOrNull(s.chapterIdx - 1) ?: return
seekToGlobal(prev.start)
}
fun seekToChapter(idx: Int) {
val ch = _state.value.chapters.getOrNull(idx) ?: return
seekToGlobal(ch.start)
}
fun skipSecs(secs: Double) = seekToGlobal(_state.value.currentTime + secs)
fun setSpeed(speed: Float) {
_state.value = _state.value.copy(speed = speed)
appContext.app.playerController.setSpeed(speed)
}
// ── Sleep timer ───────────────────────────────────────────────────────────
fun setSleepTimer(minutes: Int) {
cancelSleepInternal()
if (minutes <= 0) { _state.value = _state.value.copy(sleepRemainingSecs = null); return }
val totalSecs = minutes * 60
_state.value = _state.value.copy(sleepRemainingSecs = totalSecs)
sleepJob = scope.launch {
delay(totalSecs * 1000L)
appContext.app.playerController.pause()
_state.value = _state.value.copy(sleepRemainingSecs = null)
}
sleepTickJob = scope.launch {
var rem = totalSecs
while (rem > 0 && isActive) {
delay(1000)
rem--
_state.value = _state.value.copy(sleepRemainingSecs = rem)
}
}
}
fun cancelSleep() {
cancelSleepInternal()
_state.value = _state.value.copy(sleepRemainingSecs = null)
}
private fun cancelSleepInternal() {
sleepJob?.cancel(); sleepJob = null
sleepTickJob?.cancel(); sleepTickJob = null
}
// ── Progress sync to ABS server ───────────────────────────────────────────
private fun startSync() {
if (syncJob?.isActive == true) return
syncJob = scope.launch {
while (isActive) {
delay(30_000)
doSync()
}
}
}
private fun stopSync() { syncJob?.cancel(); syncJob = null }
private fun doSync() {
val itemId = currentItemId ?: return
val client = absClient ?: return
val s = _state.value
scope.launch { runCatching { client.saveProgress(itemId, s.currentTime, s.duration) } }
}
// ── Close ─────────────────────────────────────────────────────────────────
fun close() {
if (isClosed) return
isClosed = true
// Save progress and close ABS session on a detached scope so it survives
// cancellation of the main scope below.
val sessionId = _state.value.sessionId
val client = absClient
val itemId = currentItemId
val ct = _state.value.currentTime
val dur = _state.value.duration
if (sessionId != null && client != null && itemId != null) {
CoroutineScope(Dispatchers.IO).launch {
runCatching { client.saveProgress(itemId, ct, dur) }
runCatching { client.closeSession(sessionId) }
}
}
positionObserverJob?.cancel()
stopSync()
cancelSleepInternal()
appContext.app.playerController.stop()
_state.value = AbsPlayState()
scope.cancel()
}
// ── Helpers ───────────────────────────────────────────────────────────────
private fun findChapterIdx(chapters: List<AbsChapter>, time: Double): Int {
if (chapters.isEmpty()) return 0
var idx = 0
for (i in chapters.indices) { if (chapters[i].start <= time) idx = i }
return idx
}
private fun findTrack(tracks: List<AbsAudioTrack>, globalTime: Double): Pair<Int, Double> {
if (tracks.isEmpty()) return Pair(0, globalTime)
var idx = 0
for (i in tracks.indices) { if (tracks[i].startOffset <= globalTime) idx = i }
val local = (globalTime - tracks[idx].startOffset).coerceAtLeast(0.0)
return Pair(idx, local)
}
}
@@ -15,8 +15,11 @@ import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.MoreExecutors import com.google.common.util.concurrent.MoreExecutors
import com.google.common.util.concurrent.SettableFuture import com.google.common.util.concurrent.SettableFuture
import com.novasonic.app.NovaSonicApp
import com.novasonic.app.R
import com.novasonic.app.data.MusicRepository import com.novasonic.app.data.MusicRepository
import com.novasonic.app.ui.MainActivity import com.novasonic.app.ui.MainActivity
import android.util.Log
import kotlinx.coroutines.* import kotlinx.coroutines.*
import java.util.concurrent.Executors import java.util.concurrent.Executors
@@ -26,18 +29,32 @@ class MusicService : MediaLibraryService() {
// Android Auto root IDs // Android Auto root IDs
const val ROOT_ID = "ROOT" const val ROOT_ID = "ROOT"
const val RECENT_ID = "RECENT" const val RECENT_ID = "RECENT"
const val ALBUMS_ID = "ALBUMS"
const val ARTISTS_ID = "ARTISTS"
const val PLAYLISTS_ID = "PLAYLISTS" const val PLAYLISTS_ID = "PLAYLISTS"
const val FAVORITES_ID = "FAVORITES"
const val ITEM_PREFIX_ALBUM = "album:" const val ITEM_PREFIX_ALBUM = "album:"
const val ITEM_PREFIX_ARTIST = "artist:"
const val ITEM_PREFIX_PL = "playlist:" const val ITEM_PREFIX_PL = "playlist:"
// Pseudo-items for play-all / shuffle at top of each list
const val PLAY_ALL_PREFIX = "playall:"
const val SHUFFLE_PREFIX = "shuffle:"
// Encodes a song's browse context so a tap plays the whole list from that song:
// "songctx:<contextId>|<songId>" (contextId may itself be "album:…"/"playlist:…").
const val SONG_CTX_PREFIX = "songctx:"
// ABS session commands (handled via onCustomCommand)
const val ACTION_ABS_PREV_CH = "novasonic.abs.PREV_CHAPTER"
const val ACTION_ABS_SKIP_BACK = "novasonic.abs.SKIP_BACK"
const val ACTION_ABS_SKIP_FWD = "novasonic.abs.SKIP_FORWARD"
const val ACTION_ABS_NEXT_CH = "novasonic.abs.NEXT_CHAPTER"
const val ACTION_ABS_TOGGLE = "novasonic.abs.TOGGLE_PLAY"
} }
private lateinit var player: ExoPlayer private lateinit var player: ExoPlayer
private lateinit var session: MediaLibrarySession private lateinit var session: MediaLibrarySession
private lateinit var repo: MusicRepository private lateinit var repo: MusicRepository
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob()) private val scope = CoroutineScope(
Dispatchers.Main + SupervisorJob() +
CoroutineExceptionHandler { _, t -> Log.e("MusicService", "Uncaught coroutine exception", t) }
)
private var lastAbsChapterIdx = -1
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@@ -68,6 +85,8 @@ class MusicService : MediaLibraryService() {
.setWakeMode(C.WAKE_MODE_NETWORK) .setWakeMode(C.WAKE_MODE_NETWORK)
.build() .build()
val wrappedPlayer = AbsAwareForwardingPlayer(player)
val activityIntent = PendingIntent.getActivity( val activityIntent = PendingIntent.getActivity(
this, 0, this, 0,
Intent(this, MainActivity::class.java).apply { Intent(this, MainActivity::class.java).apply {
@@ -76,15 +95,157 @@ class MusicService : MediaLibraryService() {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
) )
session = MediaLibrarySession.Builder(this, player, LibraryCallback()) session = MediaLibrarySession.Builder(this, wrappedPlayer, LibraryCallback())
.setBitmapLoader(bitmapLoader) .setBitmapLoader(bitmapLoader)
.setSessionActivity(activityIntent) .setSessionActivity(activityIntent)
.build() .build()
scope.launch {
repo.credentialsFlow().collect { creds -> repo.lastCredentials = creds }
}
scope.launch {
(applicationContext as NovaSonicApp).absPlayerController.state.collect { s ->
session.setCustomLayout(if (s.item != null) buildAbsCustomLayout() else ImmutableList.of())
val newIdx = if (s.item != null) s.chapterIdx else -1
if (newIdx != lastAbsChapterIdx) {
lastAbsChapterIdx = newIdx
if (s.item != null) {
val chapter = s.chapters.getOrNull(s.chapterIdx)
val bookTitle = s.item.media.metadata?.title ?: "Hörbuch"
val idx = player.currentMediaItemIndex.takeIf { it >= 0 } ?: return@collect
val cur = player.getMediaItemAt(idx)
player.replaceMediaItem(idx, cur.buildUpon()
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle(chapter?.title?.takeIf { it.isNotBlank() } ?: bookTitle)
.setArtist(if (!chapter?.title.isNullOrBlank()) bookTitle else cur.mediaMetadata.artist)
.setArtworkUri(cur.mediaMetadata.artworkUri)
.build()
).build()
)
}
}
}
}
setMediaNotificationProvider(AbsAwareDnmp())
}
private fun buildAbsButtons(isPlaying: Boolean): ImmutableList<CommandButton> {
val ppIcon = if (isPlaying) R.drawable.ic_abs_pause else R.drawable.ic_abs_play
val ppLabel = if (isPlaying) "Pause" else "Abspielen"
return ImmutableList.of(
CommandButton.Builder()
.setSessionCommand(SessionCommand(ACTION_ABS_PREV_CH, Bundle.EMPTY))
.setIconResId(R.drawable.ic_abs_skip_prev)
.setDisplayName("Kapitel zurück")
.build(),
CommandButton.Builder()
.setSessionCommand(SessionCommand(ACTION_ABS_SKIP_BACK, Bundle.EMPTY))
.setIconResId(R.drawable.ic_abs_rewind)
.setDisplayName("30s zurück")
.setExtras(Bundle().apply { putInt(DefaultMediaNotificationProvider.COMMAND_KEY_COMPACT_VIEW_INDEX, 0) })
.build(),
CommandButton.Builder()
.setSessionCommand(SessionCommand(ACTION_ABS_TOGGLE, Bundle.EMPTY))
.setIconResId(ppIcon)
.setDisplayName(ppLabel)
.setExtras(Bundle().apply { putInt(DefaultMediaNotificationProvider.COMMAND_KEY_COMPACT_VIEW_INDEX, 1) })
.build(),
CommandButton.Builder()
.setSessionCommand(SessionCommand(ACTION_ABS_SKIP_FWD, Bundle.EMPTY))
.setIconResId(R.drawable.ic_abs_forward)
.setDisplayName("30s vor")
.setExtras(Bundle().apply { putInt(DefaultMediaNotificationProvider.COMMAND_KEY_COMPACT_VIEW_INDEX, 2) })
.build(),
CommandButton.Builder()
.setSessionCommand(SessionCommand(ACTION_ABS_NEXT_CH, Bundle.EMPTY))
.setIconResId(R.drawable.ic_abs_skip_next)
.setDisplayName("Kapitel vor")
.build(),
)
}
// 4-button layout for the Samsung media widget — play/pause is the standard player control.
// prevOrCustom → Kapitel zurück, custom0 → 30s zurück, custom1 → 30s vor, nextOrCustom → Kapitel vor.
// Samsung One UI slot mapping (empirically determined):
// prevOrCustom → custom[2], custom0 → custom[0], custom1 → custom[1], nextOrCustom → custom[3]
// Desired display: Kapitel zurück | 30s zurück | play | 30s vor | Kapitel vor
// Required layout order: [30s zurück, 30s vor, Kapitel zurück, Kapitel vor]
private fun buildAbsCustomLayout(): ImmutableList<CommandButton> = ImmutableList.of(
CommandButton.Builder()
.setSessionCommand(SessionCommand(ACTION_ABS_SKIP_BACK, Bundle.EMPTY))
.setIconResId(R.drawable.ic_abs_rewind)
.setDisplayName("30s zurück")
.build(),
CommandButton.Builder()
.setSessionCommand(SessionCommand(ACTION_ABS_SKIP_FWD, Bundle.EMPTY))
.setIconResId(R.drawable.ic_abs_forward)
.setDisplayName("30s vor")
.build(),
CommandButton.Builder()
.setSessionCommand(SessionCommand(ACTION_ABS_PREV_CH, Bundle.EMPTY))
.setIconResId(R.drawable.ic_abs_skip_prev)
.setDisplayName("Kapitel zurück")
.build(),
CommandButton.Builder()
.setSessionCommand(SessionCommand(ACTION_ABS_NEXT_CH, Bundle.EMPTY))
.setIconResId(R.drawable.ic_abs_skip_next)
.setDisplayName("Kapitel vor")
.build(),
)
// Removes SEEK_TO_PREV/NEXT from available commands when ABS is active so Samsung One UI
// replaces its standard prev/next slots with our first/last custom layout buttons.
private inner class AbsAwareForwardingPlayer(player: ExoPlayer) : ForwardingPlayer(player) {
override fun getAvailableCommands(): Player.Commands {
val base = super.getAvailableCommands()
val isAbs = currentMediaItem?.mediaId?.startsWith("abs:") == true ||
(applicationContext as NovaSonicApp).absPlayerController.state.value.item != null
return if (isAbs) {
base.buildUpon()
.remove(Player.COMMAND_SEEK_TO_PREVIOUS)
.remove(Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)
.remove(Player.COMMAND_SEEK_TO_NEXT)
.remove(Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)
.build()
} else base
}
}
// Subclasses DNMP so we stay inside the class hierarchy Media3 expects.
// createNotification() stores the session and always passes ImmutableList.of() to super
// so DNMP never appends setCustomLayout() buttons after getMediaButtons().
// getMediaButtons() detects ABS via currentMediaItem.mediaId — reliable, no state race.
// getMediaButtons() receives the full MediaSession — detect ABS via currentMediaItem.mediaId.
// No createNotification() override needed. setCustomLayout() is always called with empty list
// (in the onCreate observer) so DNMP appends zero extra buttons after getMediaButtons().
private inner class AbsAwareDnmp : DefaultMediaNotificationProvider(this@MusicService) {
override fun getMediaButtons(
mediaSession: MediaSession,
playerCommands: Player.Commands,
customLayout: ImmutableList<CommandButton>,
showPauseButton: Boolean,
): ImmutableList<CommandButton> {
val mediaId = mediaSession.player.currentMediaItem?.mediaId
val absItem = (applicationContext as NovaSonicApp).absPlayerController.state.value.item
android.util.Log.e("ABS_NOTIF", "getMediaButtons: mediaId=$mediaId absItem=${absItem?.id} customLayout.size=${customLayout.size}")
val isAbs = mediaId?.startsWith("abs:") == true || absItem != null
if (!isAbs) return super.getMediaButtons(mediaSession, playerCommands, ImmutableList.of(), showPauseButton)
return buildAbsButtons(mediaSession.player.isPlaying)
}
} }
override fun onGetSession(info: MediaSession.ControllerInfo) = session override fun onGetSession(info: MediaSession.ControllerInfo) = session
override fun onTaskRemoved(rootIntent: Intent?) { player.stop(); stopSelf() } override fun onTaskRemoved(rootIntent: Intent?) {
// Wischt jemand die App aus den letzten Apps, wird der Prozess gleich beendet — hier ist die
// letzte Gelegenheit, die Warteschlange festzuhalten. Ohne das ginge sie genau in dem Fall
// verloren, in dem man sie beim naechsten Oeffnen am ehesten erwartet.
runCatching { (application as? com.novasonic.app.NovaSonicApp)?.playerController?.saveQueueNow() }
player.stop()
stopSelf()
}
override fun onDestroy() { override fun onDestroy() {
scope.cancel() scope.cancel()
@@ -97,12 +258,46 @@ class MusicService : MediaLibraryService() {
private inner class LibraryCallback : MediaLibrarySession.Callback { private inner class LibraryCallback : MediaLibrarySession.Callback {
override fun onConnect(
session: MediaSession,
controller: MediaSession.ControllerInfo,
): MediaSession.ConnectionResult {
val absCommands = listOf(
SessionCommand(ACTION_ABS_PREV_CH, Bundle.EMPTY),
SessionCommand(ACTION_ABS_SKIP_BACK, Bundle.EMPTY),
SessionCommand(ACTION_ABS_SKIP_FWD, Bundle.EMPTY),
SessionCommand(ACTION_ABS_NEXT_CH, Bundle.EMPTY),
SessionCommand(ACTION_ABS_TOGGLE, Bundle.EMPTY),
)
return MediaSession.ConnectionResult.AcceptedResultBuilder(session)
.setAvailableSessionCommands(
MediaSession.ConnectionResult.DEFAULT_SESSION_AND_LIBRARY_COMMANDS.buildUpon()
.addSessionCommands(absCommands).build()
).build()
}
override fun onCustomCommand(
session: MediaSession,
controller: MediaSession.ControllerInfo,
customCommand: SessionCommand,
args: Bundle,
): ListenableFuture<SessionResult> {
val abs = (applicationContext as NovaSonicApp).absPlayerController
when (customCommand.customAction) {
ACTION_ABS_PREV_CH -> abs.prevChapter()
ACTION_ABS_SKIP_BACK -> abs.skipSecs(-30.0)
ACTION_ABS_SKIP_FWD -> abs.skipSecs(30.0)
ACTION_ABS_NEXT_CH -> abs.nextChapter()
ACTION_ABS_TOGGLE -> abs.togglePlay()
}
return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
}
override fun onGetLibraryRoot( override fun onGetLibraryRoot(
session: MediaLibrarySession, session: MediaLibrarySession,
browser: MediaSession.ControllerInfo, browser: MediaSession.ControllerInfo,
params: LibraryParams?, params: LibraryParams?,
): ListenableFuture<LibraryResult<MediaItem>> { ): ListenableFuture<LibraryResult<MediaItem>> {
val isAuto = params?.isRecent == true || isAndroidAuto(browser)
val root = MediaItem.Builder() val root = MediaItem.Builder()
.setMediaId(ROOT_ID) .setMediaId(ROOT_ID)
.setMediaMetadata( .setMediaMetadata(
@@ -125,7 +320,6 @@ class MusicService : MediaLibraryService() {
params: LibraryParams?, params: LibraryParams?,
): ListenableFuture<LibraryResult<ImmutableList<MediaItem>>> { ): ListenableFuture<LibraryResult<ImmutableList<MediaItem>>> {
val future = scope.async { buildChildren(parentId) } val future = scope.async { buildChildren(parentId) }
val executor = MoreExecutors.directExecutor()
val settable = SettableFuture.create<LibraryResult<ImmutableList<MediaItem>>>() val settable = SettableFuture.create<LibraryResult<ImmutableList<MediaItem>>>()
scope.launch { scope.launch {
try { try {
@@ -150,6 +344,25 @@ class MusicService : MediaLibraryService() {
val album = repo.getAlbum(mediaId.removePrefix(ITEM_PREFIX_ALBUM)) val album = repo.getAlbum(mediaId.removePrefix(ITEM_PREFIX_ALBUM))
album.toMediaItem(repo) album.toMediaItem(repo)
} }
mediaId.startsWith(ITEM_PREFIX_PL) -> {
val pl = repo.getPlaylist(mediaId.removePrefix(ITEM_PREFIX_PL))
val artUri = pl.coverArt?.let { repo.coverArtUrl(it, 300)?.let { url -> android.net.Uri.parse(url) } }
MediaItem.Builder()
.setMediaId(mediaId)
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle(pl.name)
.setArtworkUri(artUri)
.setIsPlayable(false)
.setIsBrowsable(true)
.setMediaType(MediaMetadata.MEDIA_TYPE_PLAYLIST)
.build()
).build()
}
mediaId.startsWith(SONG_CTX_PREFIX) -> {
val songId = mediaId.removePrefix(SONG_CTX_PREFIX).substringAfter('|')
repo.getSong(songId).toMediaItem(repo).buildUpon().setMediaId(mediaId).build()
}
else -> null else -> null
} }
if (item != null) settable.set(LibraryResult.ofItem(item, null)) if (item != null) settable.set(LibraryResult.ofItem(item, null))
@@ -161,35 +374,96 @@ class MusicService : MediaLibraryService() {
return settable return settable
} }
// When Android Auto selects a browsable item (album/playlist), load its songs. // Android Auto "add to queue" path — resolve browsable items to their songs.
override fun onAddMediaItems( override fun onAddMediaItems(
mediaSession: MediaSession, mediaSession: MediaSession,
controller: MediaSession.ControllerInfo, controller: MediaSession.ControllerInfo,
mediaItems: MutableList<MediaItem>, mediaItems: MutableList<MediaItem>,
): ListenableFuture<MutableList<MediaItem>> { ): ListenableFuture<MutableList<MediaItem>> {
val settable = SettableFuture.create<MutableList<MediaItem>>() val settable = SettableFuture.create<MutableList<MediaItem>>()
scope.launch {
try { settable.set(expandForPlayback(mediaItems).first.toMutableList()) }
catch (e: Exception) { settable.set(mediaItems) }
}
return settable
}
// Android Auto "tap to play" path — return the resolved list AND the index to start at, so
// tapping a song plays its whole list from that song (not just the one song).
override fun onSetMediaItems(
mediaSession: MediaSession,
controller: MediaSession.ControllerInfo,
mediaItems: MutableList<MediaItem>,
startIndex: Int,
startPositionMs: Long,
): ListenableFuture<MediaSession.MediaItemsWithStartPosition> {
val settable = SettableFuture.create<MediaSession.MediaItemsWithStartPosition>()
scope.launch { scope.launch {
try { try {
val resolved = mediaItems.flatMap { item -> val (list, idx) = expandForPlayback(mediaItems)
when { // A single browse tap expands into a full list → start at the tapped index.
item.mediaId.startsWith(ITEM_PREFIX_ALBUM) -> { // Otherwise honour the caller's startIndex.
val album = repo.getAlbum(item.mediaId.removePrefix(ITEM_PREFIX_ALBUM)) val expanded = list.size != mediaItems.size
album.song.map { song -> song.toMediaItem(repo) } val start = if (expanded) idx else startIndex.coerceIn(0, (list.size - 1).coerceAtLeast(0))
} settable.set(MediaSession.MediaItemsWithStartPosition(list, start, startPositionMs))
item.mediaId.startsWith(ITEM_PREFIX_PL) -> {
val pl = repo.getPlaylist(item.mediaId.removePrefix(ITEM_PREFIX_PL))
pl.entry.map { song -> song.toMediaItem(repo) }
}
else -> listOf(item)
}
}
settable.set(resolved.toMutableList())
} catch (e: Exception) { } catch (e: Exception) {
settable.set(mediaItems) settable.set(MediaSession.MediaItemsWithStartPosition(mediaItems, startIndex, startPositionMs))
} }
} }
return settable return settable
} }
// Resolve browse items (play-all / shuffle / album / playlist / context-song / plain song)
// into a flat, playable song list plus the index to start at (the tapped song, else 0).
private suspend fun expandForPlayback(items: List<MediaItem>): Pair<List<MediaItem>, Int> {
if (items.size == 1 && items[0].mediaId.startsWith(SONG_CTX_PREFIX)) {
val rest = items[0].mediaId.removePrefix(SONG_CTX_PREFIX)
val ctx = rest.substringBefore('|')
val songId = rest.substringAfter('|')
val full = resolveSongs(ctx, shuffle = false)
if (full.isNotEmpty()) {
val idx = full.indexOfFirst { it.mediaId == songId }.coerceAtLeast(0)
return full to idx
}
return listOf(reattachUri(items[0], songId)) to 0
}
val resolved = items.flatMap { item ->
when {
item.mediaId.startsWith(PLAY_ALL_PREFIX) -> resolveSongs(item.mediaId.removePrefix(PLAY_ALL_PREFIX), false)
item.mediaId.startsWith(SHUFFLE_PREFIX) -> resolveSongs(item.mediaId.removePrefix(SHUFFLE_PREFIX), true)
item.mediaId.startsWith(ITEM_PREFIX_ALBUM) -> repo.getAlbum(item.mediaId.removePrefix(ITEM_PREFIX_ALBUM)).song.map { it.toMediaItem(repo) }
item.mediaId.startsWith(ITEM_PREFIX_PL) -> repo.getPlaylist(item.mediaId.removePrefix(ITEM_PREFIX_PL)).entry.map { it.toMediaItem(repo) }
item.mediaId.startsWith(SONG_CTX_PREFIX) -> listOf(reattachUri(item, item.mediaId.removePrefix(SONG_CTX_PREFIX).substringAfter('|')))
else -> listOf(reattachUri(item))
}
}
return resolved to 0
}
// Android Auto strips the URI when a browse item crosses the process boundary — re-resolve it.
private fun reattachUri(item: MediaItem, songId: String = item.mediaId): MediaItem {
val uri = repo.streamUrl(songId)?.let { android.net.Uri.parse(it) }
return item.buildUpon().setMediaId(songId).setUri(uri).build()
}
private suspend fun resolveSongs(contextId: String, shuffle: Boolean): List<MediaItem> {
val songs: List<com.novasonic.app.api.model.Song> = when {
contextId.startsWith(ITEM_PREFIX_ALBUM) ->
repo.getAlbum(contextId.removePrefix(ITEM_PREFIX_ALBUM)).song
contextId.startsWith(ITEM_PREFIX_PL) ->
repo.getPlaylist(contextId.removePrefix(ITEM_PREFIX_PL)).entry
contextId == FAVORITES_ID ->
repo.getStarred().song
contextId == RECENT_ID -> {
repo.getRecentlyPlayedAlbums(20).flatMap { album ->
runCatching { repo.getAlbum(album.id).song }.getOrDefault(emptyList())
}
}
else -> emptyList()
}
val ordered = if (shuffle) songs.shuffled() else songs
return ordered.map { it.toMediaItem(repo) }
}
} }
// ── Build Android Auto browsable tree ───────────────────────────────────── // ── Build Android Auto browsable tree ─────────────────────────────────────
@@ -197,27 +471,27 @@ class MusicService : MediaLibraryService() {
private suspend fun buildChildren(parentId: String): ImmutableList<MediaItem> { private suspend fun buildChildren(parentId: String): ImmutableList<MediaItem> {
val items = when (parentId) { val items = when (parentId) {
ROOT_ID -> listOf( ROOT_ID -> listOf(
browseFolder(RECENT_ID, "Recently Played", MediaMetadata.MEDIA_TYPE_FOLDER_ALBUMS), browseFolder(RECENT_ID, "Zuletzt gespielt", MediaMetadata.MEDIA_TYPE_FOLDER_ALBUMS),
browseFolder(ALBUMS_ID, "Albums", MediaMetadata.MEDIA_TYPE_FOLDER_ALBUMS), browseFolder(FAVORITES_ID, "Favoriten", MediaMetadata.MEDIA_TYPE_FOLDER_MIXED),
browseFolder(ARTISTS_ID, "Artists", MediaMetadata.MEDIA_TYPE_FOLDER_ARTISTS),
browseFolder(PLAYLISTS_ID, "Playlists", MediaMetadata.MEDIA_TYPE_FOLDER_PLAYLISTS), browseFolder(PLAYLISTS_ID, "Playlists", MediaMetadata.MEDIA_TYPE_FOLDER_PLAYLISTS),
) )
RECENT_ID -> repo.getRecentlyPlayedAlbums(20).map { it.toMediaItem(repo) } RECENT_ID -> {
ALBUMS_ID -> repo.getAlphaAlbums(40).map { it.toMediaItem(repo) } val albums = repo.getRecentlyPlayedAlbums(20)
PLAYLISTS_ID -> repo.getPlaylists().map { it.toMediaItem() } listOf(playAllItem(RECENT_ID), shuffleItem(RECENT_ID)) + albums.map { it.toMediaItem(repo) }
ARTISTS_ID -> repo.getArtists().flatMap { idx -> idx.artist.map { it.toMediaItem() } } }
PLAYLISTS_ID -> repo.getPlaylists().map { it.toMediaItem(repo) }
FAVORITES_ID -> {
val songs = repo.getStarred().song
listOf(playAllItem(FAVORITES_ID), shuffleItem(FAVORITES_ID)) + songs.map { browseSong(it, FAVORITES_ID) }
}
else -> when { else -> when {
parentId.startsWith(ITEM_PREFIX_ALBUM) -> { parentId.startsWith(ITEM_PREFIX_ALBUM) -> {
val album = repo.getAlbum(parentId.removePrefix(ITEM_PREFIX_ALBUM)) val album = repo.getAlbum(parentId.removePrefix(ITEM_PREFIX_ALBUM))
album.song.map { it.toMediaItem(repo) } listOf(playAllItem(parentId), shuffleItem(parentId)) + album.song.map { browseSong(it, parentId) }
}
parentId.startsWith(ITEM_PREFIX_ARTIST) -> {
val artist = repo.getArtist(parentId.removePrefix(ITEM_PREFIX_ARTIST))
artist.album.map { it.toMediaItem(repo) }
} }
parentId.startsWith(ITEM_PREFIX_PL) -> { parentId.startsWith(ITEM_PREFIX_PL) -> {
val pl = repo.getPlaylist(parentId.removePrefix(ITEM_PREFIX_PL)) val pl = repo.getPlaylist(parentId.removePrefix(ITEM_PREFIX_PL))
pl.entry.map { it.toMediaItem(repo) } listOf(playAllItem(parentId), shuffleItem(parentId)) + pl.entry.map { browseSong(it, parentId) }
} }
else -> emptyList() else -> emptyList()
} }
@@ -225,6 +499,13 @@ class MusicService : MediaLibraryService() {
return ImmutableList.copyOf(items) return ImmutableList.copyOf(items)
} }
// A song shown in a browse list, with its context encoded in the mediaId so a tap can play the
// whole list from that song (Android Auto strips the URI, so it's re-resolved on playback).
private fun browseSong(song: com.novasonic.app.api.model.Song, contextId: String): MediaItem =
song.toMediaItem(repo).buildUpon()
.setMediaId("$SONG_CTX_PREFIX$contextId|${song.id}")
.build()
private fun browseFolder(id: String, title: String, mediaType: Int) = private fun browseFolder(id: String, title: String, mediaType: Int) =
MediaItem.Builder() MediaItem.Builder()
.setMediaId(id) .setMediaId(id)
@@ -237,6 +518,28 @@ class MusicService : MediaLibraryService() {
.build() .build()
).build() ).build()
private fun playAllItem(contextId: String) = MediaItem.Builder()
.setMediaId("$PLAY_ALL_PREFIX$contextId")
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle("▶ Alle abspielen")
.setIsPlayable(true)
.setIsBrowsable(false)
.setMediaType(MediaMetadata.MEDIA_TYPE_MUSIC)
.build()
).build()
private fun shuffleItem(contextId: String) = MediaItem.Builder()
.setMediaId("$SHUFFLE_PREFIX$contextId")
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle("⇀ Zufällig abspielen")
.setIsPlayable(true)
.setIsBrowsable(false)
.setMediaType(MediaMetadata.MEDIA_TYPE_MUSIC)
.build()
).build()
private fun isAndroidAuto(info: MediaSession.ControllerInfo): Boolean = private fun isAndroidAuto(info: MediaSession.ControllerInfo): Boolean =
info.packageName.contains("android.auto", ignoreCase = true) || info.packageName.contains("android.auto", ignoreCase = true) ||
info.packageName.contains("goog.android.projected", ignoreCase = true) info.packageName.contains("goog.android.projected", ignoreCase = true)
@@ -282,26 +585,18 @@ fun com.novasonic.app.api.model.Album.toMediaItem(repo: MusicRepository): MediaI
).build() ).build()
} }
fun com.novasonic.app.api.model.Artist.toMediaItem(): MediaItem =
MediaItem.Builder()
.setMediaId("${MusicService.ITEM_PREFIX_ARTIST}$id")
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle(name)
.setIsPlayable(false)
.setIsBrowsable(true)
.setMediaType(MediaMetadata.MEDIA_TYPE_ARTIST)
.build()
).build()
fun com.novasonic.app.api.model.Playlist.toMediaItem(): MediaItem = fun com.novasonic.app.api.model.Playlist.toMediaItem(repo: MusicRepository): MediaItem {
MediaItem.Builder() val artUri = coverArt?.let { repo.coverArtUrl(it, 300)?.let { url -> android.net.Uri.parse(url) } }
return MediaItem.Builder()
.setMediaId("${MusicService.ITEM_PREFIX_PL}$id") .setMediaId("${MusicService.ITEM_PREFIX_PL}$id")
.setMediaMetadata( .setMediaMetadata(
MediaMetadata.Builder() MediaMetadata.Builder()
.setTitle(name) .setTitle(name)
.setIsPlayable(true) .setArtworkUri(artUri)
.setIsPlayable(false) // browse-only: Auto opens the song list instead of playing immediately
.setIsBrowsable(true) .setIsBrowsable(true)
.setMediaType(MediaMetadata.MEDIA_TYPE_PLAYLIST) .setMediaType(MediaMetadata.MEDIA_TYPE_PLAYLIST)
.build() .build()
).build() ).build()
}
@@ -1,11 +1,14 @@
package com.novasonic.app.player package com.novasonic.app.player
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
import androidx.media3.common.MediaItem import androidx.media3.common.MediaItem
import androidx.media3.common.Player import androidx.media3.common.Player
import androidx.media3.common.Timeline
import androidx.media3.session.MediaController import androidx.media3.session.MediaController
import androidx.media3.session.SessionToken import androidx.media3.session.SessionToken
import com.novasonic.app.NovaSonicApp
import com.novasonic.app.api.LrcLibClient
import com.novasonic.app.api.model.Song import com.novasonic.app.api.model.Song
import com.novasonic.app.data.MusicRepository import com.novasonic.app.data.MusicRepository
import kotlinx.coroutines.* import kotlinx.coroutines.*
@@ -25,6 +28,8 @@ data class PlayerState(
val repeatMode: Int = Player.REPEAT_MODE_OFF, val repeatMode: Int = Player.REPEAT_MODE_OFF,
val shuffled: Boolean = false, val shuffled: Boolean = false,
val volume: Float = 1f, val volume: Float = 1f,
val artworkUri: String? = null,
val radioMode: Boolean = false,
) )
class PlayerController(private val context: Context, private val repo: MusicRepository) { class PlayerController(private val context: Context, private val repo: MusicRepository) {
@@ -32,7 +37,12 @@ class PlayerController(private val context: Context, private val repo: MusicRepo
private val _state = MutableStateFlow(PlayerState()) private val _state = MutableStateFlow(PlayerState())
val state: StateFlow<PlayerState> = _state.asStateFlow() val state: StateFlow<PlayerState> = _state.asStateFlow()
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob()) private val TAG_QUEUE = "NsQueue"
private val scope = CoroutineScope(
Dispatchers.Main + SupervisorJob() +
CoroutineExceptionHandler { _, t -> android.util.Log.e("PlayerController", "Uncaught coroutine exception", t) }
)
private var controller: MediaController? = null private var controller: MediaController? = null
private var queue: List<Song> = emptyList() private var queue: List<Song> = emptyList()
private var originalQueue: List<Song> = emptyList() private var originalQueue: List<Song> = emptyList()
@@ -48,25 +58,129 @@ class PlayerController(private val context: Context, private val repo: MusicRepo
controller = runCatching { future.get() }.getOrNull() controller = runCatching { future.get() }.getOrNull()
controller?.addListener(PlayerListener()) controller?.addListener(PlayerListener())
syncState() syncState()
restoreQueue()
}, context.mainExecutor) }, context.mainExecutor)
} }
} }
/**
* Haelt Warteschlange und Listenposition fest — ohne die Sekunde im Titel: der zuletzt gehoerte
* Titel beginnt von vorn. ABS-Hoerbuecher bleiben aussen vor, die haben ihren eigenen
* Fortschritt auf dem Server.
*/
private fun persistQueueState() {
val ctrl = controller ?: return
val songs = queue
if (songs.isEmpty() || songs.any { it.id.startsWith("abs:") }) return
val index = ctrl.currentMediaItemIndex
scope.launch {
runCatching { repo.saveQueueState(songs, index) }
.onSuccess { android.util.Log.i(TAG_QUEUE, "gesichert: ${songs.size} Titel, Index $index") }
.onFailure { android.util.Log.w(TAG_QUEUE, "Sichern fehlgeschlagen", it) }
}
}
/** Von aussen aufrufbar (Dienst-Ende beim Wegwischen der App). */
fun saveQueueNow() = persistQueueState()
/**
* Stellt die zuletzt gehoerte Warteschlange wieder her — vorbereitet, aber NICHT abgespielt.
* Wer die App oeffnet, will nicht ueberfallen werden; ein Druck auf Play macht dort weiter.
* Laeuft schon etwas (etwa ueber Android Auto gestartet), passiert nichts.
*
* Die Aufloesung der Song-Ids braucht die Navidrome-Zugangsdaten. connect() laeuft aber schon in
* Application.onCreate(), wo der DataStore unter Umstaenden noch nicht gelesen ist — dann
* scheitern alle Abfragen und die Warteschlange bliebe still leer. Deshalb wird es mehrfach mit
* wachsendem Abstand versucht, statt beim ersten Fehlschlag aufzugeben.
*/
fun restoreQueue() {
scope.launch {
val zustand = runCatching { repo.readQueueState() }.getOrNull()
if (zustand == null) {
android.util.Log.i(TAG_QUEUE, "nichts gesichert — nichts wiederherzustellen")
return@launch
}
val ctrl = controller
if (ctrl == null) {
android.util.Log.w(TAG_QUEUE, "kein Controller — Wiederherstellen verworfen")
return@launch
}
if (ctrl.mediaItemCount > 0) {
android.util.Log.i(TAG_QUEUE, "Player hat bereits Titel — nicht angefasst")
return@launch
}
val songs = zustand.songs
val index = zustand.index.coerceIn(0, songs.lastIndex)
queue = songs
originalQueue = songs
runCatching {
ctrl.setMediaItems(songs.map { it.toMediaItem(repo) }, index, 0L)
ctrl.prepare()
}.onFailure { android.util.Log.w(TAG_QUEUE, "setMediaItems fehlgeschlagen", it) }
syncState()
android.util.Log.i(TAG_QUEUE, "wiederhergestellt: ${songs.size} Titel, Index $index")
}
}
// ── Playback commands ───────────────────────────────────────────────────── // ── Playback commands ─────────────────────────────────────────────────────
/**
* Startet eine Liste. Ein `startIndex` KLEINER 0 bedeutet "gemischt starten".
*
* Warum das Mischen hier passiert und nicht beim Aufrufer: vorher mischte jeder
* Shuffle-Knopf selbst (`liste.shuffled()`) und uebergab die fertige Reihenfolge. Damit war
* `originalQueue` schon die gemischte Liste, `isManuallyShuffled` blieb false — das
* Shuffle-Symbol leuchtete nicht, obwohl gemischt gespielt wurde, und ein Druck auf
* "Shuffle aus" stellte die Albumreihenfolge nie wieder her, weil es keine mehr gab.
*/
fun playSongs(songs: List<Song>, startIndex: Int = 0) { fun playSongs(songs: List<Song>, startIndex: Int = 0) {
// If ABS is active, close it — user explicitly switched to music
(context.applicationContext as? NovaSonicApp)?.absPlayerController?.let { abs ->
if (abs.isActive) abs.close()
}
val ctrl = controller ?: return val ctrl = controller ?: return
queue = songs val gemischt = startIndex < 0
originalQueue = songs val reihenfolge = if (gemischt) songs.shuffled() else songs
isManuallyShuffled = false queue = reihenfolge
originalQueue = songs // immer die UNGEMISCHTE Liste — Rueckweg fuer "Shuffle aus"
isManuallyShuffled = gemischt
ctrl.shuffleModeEnabled = false ctrl.shuffleModeEnabled = false
val items = songs.map { it.toMediaItem(repo) } val items = reihenfolge.map { it.toMediaItem(repo) }
ctrl.setMediaItems(items, startIndex, 0L) ctrl.setMediaItems(items, if (gemischt) 0 else startIndex.coerceIn(0, maxOf(0, songs.lastIndex)), 0L)
ctrl.prepare() ctrl.prepare()
ctrl.play() ctrl.play()
syncState() syncState()
} }
/** Called by AbsPlayerController to route ABS audio through this service. */
fun playAbsItems(
items: List<MediaItem>,
startIndex: Int,
startPositionMs: Long,
speed: Float = 1f,
) {
val ctrl = controller ?: return
queue = emptyList()
originalQueue = emptyList()
isManuallyShuffled = false
ctrl.setMediaItems(items, startIndex, startPositionMs)
ctrl.prepare()
ctrl.setPlaybackSpeed(speed)
ctrl.play()
syncState()
}
/** Stop playback and clear the queue (used when ABS session ends). */
fun stop() {
val ctrl = controller ?: return
ctrl.setPlaybackSpeed(1f)
ctrl.pause()
ctrl.clearMediaItems()
queue = emptyList()
originalQueue = emptyList()
syncState()
}
fun play() = controller?.play() fun play() = controller?.play()
fun pause() = controller?.pause() fun pause() = controller?.pause()
fun togglePlay() = controller?.let { if (it.isPlaying) it.pause() else it.play() } fun togglePlay() = controller?.let { if (it.isPlaying) it.pause() else it.play() }
@@ -75,6 +189,11 @@ class PlayerController(private val context: Context, private val repo: MusicRepo
fun skipPrev() = controller?.seekToPreviousMediaItem() fun skipPrev() = controller?.seekToPreviousMediaItem()
fun seekToItem(index: Int) = controller?.seekToDefaultPosition(index) fun seekToItem(index: Int) = controller?.seekToDefaultPosition(index)
/** Seek to a specific track index and position within that track (for ABS chapter navigation). */
fun seekToAbs(windowIndex: Int, positionMs: Long) = controller?.seekTo(windowIndex, positionMs)
fun setSpeed(speed: Float) = controller?.setPlaybackSpeed(speed)
fun setVolume(v: Float) { fun setVolume(v: Float) {
val clamped = v.coerceIn(0f, 1f) val clamped = v.coerceIn(0f, 1f)
controller?.volume = clamped controller?.volume = clamped
@@ -96,6 +215,40 @@ class PlayerController(private val context: Context, private val repo: MusicRepo
ctrl.addMediaItem(song.toMediaItem(repo)) ctrl.addMediaItem(song.toMediaItem(repo))
} }
// ── Warteschlange bearbeiten ────────────────────────────────────────────
// queue (lokal) und die MediaItems des Controllers muessen im Gleichschritt bleiben:
// syncState() liest den laufenden Index vom Controller, den Titel dazu aber aus queue.
// Liefen die beiden auseinander, zeigte die Oberflaeche den falschen Song an.
/** Entfernt Position [index]. Traf es den laufenden Titel, rueckt Media3 selbst weiter. */
fun entferneAusQueue(index: Int) {
val ctrl = controller ?: return
if (index !in queue.indices) return
val raus = queue[index]
queue = queue.toMutableList().apply { removeAt(index) }
// originalQueue haelt die Reihenfolge fuer das Zuruecknehmen des Mischens — dort denselben
// Titel EINMAL entfernen, sonst taucht er beim Entmischen wieder auf.
originalQueue = originalQueue.toMutableList().apply {
val i = indexOfFirst { it.id == raus.id }
if (i >= 0) removeAt(i)
}
ctrl.removeMediaItem(index)
if (queue.isEmpty()) {
ctrl.stop()
ctrl.clearMediaItems()
}
syncState()
}
/** Verschiebt Position [von] auf [nach]. */
fun verschiebeInQueue(von: Int, nach: Int) {
val ctrl = controller ?: return
if (von == nach || von !in queue.indices || nach !in queue.indices) return
queue = queue.toMutableList().apply { add(nach, removeAt(von)) }
ctrl.moveMediaItem(von, nach)
syncState()
}
fun toggleRepeat() { fun toggleRepeat() {
val ctrl = controller ?: return val ctrl = controller ?: return
ctrl.repeatMode = when (ctrl.repeatMode) { ctrl.repeatMode = when (ctrl.repeatMode) {
@@ -109,29 +262,73 @@ class PlayerController(private val context: Context, private val repo: MusicRepo
val ctrl = controller ?: return val ctrl = controller ?: return
val currentIdx = ctrl.currentMediaItemIndex val currentIdx = ctrl.currentMediaItemIndex
if (!isManuallyShuffled) { // Der Rest hinter dem laufenden Titel wird in EINEM Zug ersetzt. Vorher lief das als
// Turn ON: shuffle everything after the current song // Schleife aus removeMediaItem + addMediaItem, und dazwischen hatte der Controller
// voruebergehend weniger Titel als unsere Liste. Genau darauf reagiert onTimelineChanged
// mit "die Titel kamen von aussen" — es baute die Warteschlange neu auf und setzte dabei
// isManuallyShuffled ZURUECK. Das Mischen lief, aber das Symbol leuchtete nie.
val neuerRest = if (!isManuallyShuffled) {
isManuallyShuffled = true isManuallyShuffled = true
val played = queue.take(currentIdx + 1) queue.drop(currentIdx + 1).shuffled()
val remaining = queue.drop(currentIdx + 1).shuffled()
queue = played + remaining
for (i in ctrl.mediaItemCount - 1 downTo currentIdx + 1) ctrl.removeMediaItem(i)
remaining.forEach { s -> ctrl.addMediaItem(s.toMediaItem(repo)) }
} else { } else {
// Turn OFF: restore original order from the current song's position
isManuallyShuffled = false isManuallyShuffled = false
val currentSong = queue.getOrNull(currentIdx) val currentSong = queue.getOrNull(currentIdx)
val origIdx = originalQueue.indexOfFirst { it.id == currentSong?.id }.coerceAtLeast(0) val origIdx = originalQueue.indexOfFirst { it.id == currentSong?.id }.coerceAtLeast(0)
val restOfOriginal = originalQueue.drop(origIdx + 1) originalQueue.drop(origIdx + 1)
queue = originalQueue.take(origIdx + 1) + restOfOriginal
for (i in ctrl.mediaItemCount - 1 downTo currentIdx + 1) ctrl.removeMediaItem(i)
restOfOriginal.forEach { s -> ctrl.addMediaItem(s.toMediaItem(repo)) }
} }
queue = queue.take(currentIdx + 1) + neuerRest
ctrl.replaceMediaItems(currentIdx + 1, ctrl.mediaItemCount, neuerRest.map { it.toMediaItem(repo) })
syncState() syncState()
} }
fun addToQueue(song: Song) = addToQueueEnd(song) fun addToQueue(song: Song) = addToQueueEnd(song)
// ── Radio mode ────────────────────────────────────────────────────────────
private var _radioMode = false
fun toggleRadio() {
_radioMode = !_radioMode
_state.update { it.copy(radioMode = _radioMode) }
if (_radioMode) scope.launch { fillRadioQueue() }
}
private fun checkRadioRefill() {
if (!_radioMode) return
val remaining = queue.size - (_state.value.currentIndex + 1)
if (remaining < 5) scope.launch { fillRadioQueue() }
}
private suspend fun fillRadioQueue() {
val currentSong = _state.value.currentSong ?: return
val recentIds = queue.takeLast(50).map { it.id }.toHashSet()
var candidates = runCatching {
repo.getSimilarSongs(currentSong.id, 20)
}.getOrDefault(emptyList()).filter { it.id !in recentIds }
if (candidates.isEmpty()) {
candidates = runCatching {
repo.getRandomSongs()
}.getOrDefault(emptyList()).filter { it.id !in recentIds }
}
if (candidates.isEmpty()) {
// Letzte Rueckfallebene: Wiederholungen sind erlaubt, damit Musik weiterlaeuft — aber
// nicht der gerade laufende Titel. Der haengte sich sonst direkt hinter sich selbst.
candidates = runCatching { repo.getRandomSongs() }.getOrDefault(emptyList())
.filter { it.id != currentSong.id }
}
val ctrl = controller ?: return
candidates.forEach { song ->
queue = queue + song
originalQueue = originalQueue + song
ctrl.addMediaItem(song.toMediaItem(repo))
}
syncState()
}
// ── Ticker ──────────────────────────────────────────────────────────────── // ── Ticker ────────────────────────────────────────────────────────────────
private fun startTicker() { private fun startTicker() {
@@ -140,11 +337,25 @@ class PlayerController(private val context: Context, private val repo: MusicRepo
while (isActive) { while (isActive) {
delay(500) delay(500)
val ctrl = controller ?: break val ctrl = controller ?: break
_state.update { it.copy(positionMs = ctrl.currentPosition) } // Refresh durationMs too — after a SEAMLESS track transition (skipping through
// already-buffered tracks) the player stays READY, so onPlaybackStateChanged never
// fires and syncState() isn't re-called; ctrl.duration was TIME_UNSET(→0) at the
// transition, leaving durationMs stuck at 0. Seek then computes fraction*0 = 0 and
// snaps to the start every time. Re-reading here lets it self-heal within 500ms.
_state.update { it.copy(positionMs = ctrl.currentPosition, durationMs = resolveDurationMs(ctrl)) }
} }
} }
} }
/** Player duration, falling back to the current song's known duration while ctrl.duration is
* still TIME_UNSET (right after a media transition). Prevents a 0-duration seek → snap-to-0. */
private fun resolveDurationMs(ctrl: MediaController): Long {
val d = ctrl.duration
if (d > 0) return d
val songDurSecs = queue.getOrNull(ctrl.currentMediaItemIndex)?.duration?.toLong() ?: 0L
return songDurSecs * 1000L
}
private fun stopTicker() { private fun stopTicker() {
tickerJob?.cancel() tickerJob?.cancel()
tickerJob = null tickerJob = null
@@ -158,11 +369,23 @@ class PlayerController(private val context: Context, private val repo: MusicRepo
val delayMs = runCatching { repo.getScrobbleDelayMs(durationMs) }.getOrDefault(30_000L) val delayMs = runCatching { repo.getScrobbleDelayMs(durationMs) }.getOrDefault(30_000L)
delay(delayMs) delay(delayMs)
runCatching { repo.scrobble(song.id) } runCatching { repo.scrobble(song.id) }
runCatching { repo.logPlay(song) } // our own play-log, same counted moment
} }
} }
// ── Internal ────────────────────────────────────────────────────────────── // ── Internal ──────────────────────────────────────────────────────────────
private fun songFromMediaItem(item: MediaItem): Song {
val meta = item.mediaMetadata
return Song(
id = item.mediaId,
title = meta.title?.toString() ?: "",
artist = meta.artist?.toString(),
album = meta.albumTitle?.toString(),
track = meta.trackNumber,
)
}
private fun syncState() { private fun syncState() {
val ctrl = controller ?: return val ctrl = controller ?: return
val idx = ctrl.currentMediaItemIndex val idx = ctrl.currentMediaItemIndex
@@ -172,31 +395,76 @@ class PlayerController(private val context: Context, private val repo: MusicRepo
currentSong = queue.getOrNull(idx), currentSong = queue.getOrNull(idx),
currentIndex = idx, currentIndex = idx,
positionMs = ctrl.currentPosition, positionMs = ctrl.currentPosition,
durationMs = ctrl.duration.coerceAtLeast(0), durationMs = resolveDurationMs(ctrl),
queue = queue, queue = queue,
repeatMode = ctrl.repeatMode, repeatMode = ctrl.repeatMode,
shuffled = isManuallyShuffled, shuffled = isManuallyShuffled,
volume = ctrl.volume, volume = ctrl.volume,
artworkUri = ctrl.currentMediaItem?.mediaMetadata?.artworkUri?.toString(),
radioMode = _radioMode,
) )
} }
private var _lyricsPrefetchJob: Job? = null
/** Warm the LrcLib cache shortly after a track settles. Debounced so rapid skips don't
* hammer lrclib (which throttles the IP and then no lyrics load at all). */
private fun prefetchLyrics(song: Song) {
_lyricsPrefetchJob?.cancel()
_lyricsPrefetchJob = scope.launch {
delay(1500) // skip quickly without firing a request per track
runCatching {
LrcLibClient.getLyrics(
artist = song.artist ?: "",
title = song.title,
album = song.album,
durationSecs = song.duration,
)
}
}
}
private inner class PlayerListener : Player.Listener { private inner class PlayerListener : Player.Listener {
override fun onIsPlayingChanged(isPlaying: Boolean) { override fun onIsPlayingChanged(isPlaying: Boolean) {
if (isPlaying) startTicker() else stopTicker() if (isPlaying) startTicker() else stopTicker()
syncState() syncState()
// Beim Pausieren die Position festhalten: von da soll es beim naechsten Start weitergehen.
if (!isPlaying) persistQueueState()
} }
override fun onPlaybackStateChanged(state: Int) = syncState() override fun onPlaybackStateChanged(state: Int) = syncState()
override fun onMediaItemTransition(item: MediaItem?, reason: Int) { override fun onMediaItemTransition(item: MediaItem?, reason: Int) {
syncState() syncState()
checkRadioRefill()
val ctrl = controller ?: return val ctrl = controller ?: return
// Skip scrobble and last-song tracking for ABS tracks (mediaId starts with "abs:")
val mediaId = ctrl.currentMediaItem?.mediaId ?: return
if (mediaId.startsWith("abs:")) return
val song = queue.getOrNull(ctrl.currentMediaItemIndex) ?: return val song = queue.getOrNull(ctrl.currentMediaItemIndex) ?: return
val dur = ctrl.duration.coerceAtLeast(0) // Use the song's KNOWN duration — at a media transition ctrl.duration is still
// TIME_UNSET (→0), which collapsed the 1/3 / 2/3 modes to the 15s floor and scrobbled
// far too early. Fall back to the player only if the song has no duration.
val songDurMs = (song.duration?.toLong() ?: 0L) * 1000L
val dur = if (songDurMs > 0) songDurMs else ctrl.duration.coerceAtLeast(0)
scheduleScrobble(song, dur) scheduleScrobble(song, dur)
scope.launch { runCatching { repo.saveLastSong(song) } }
persistQueueState()
prefetchLyrics(song)
} }
override fun onShuffleModeEnabledChanged(enabled: Boolean) = syncState() override fun onShuffleModeEnabledChanged(enabled: Boolean) = syncState()
override fun onRepeatModeChanged(mode: Int) = syncState() override fun onRepeatModeChanged(mode: Int) = syncState()
override fun onTimelineChanged(timeline: Timeline, reason: Int) {
val ctrl = controller ?: return
val ctrlCount = ctrl.mediaItemCount
// Rebuild queue from controller when items were set externally (e.g. Android Auto or ABS)
if (reason == Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED && ctrlCount != queue.size) {
queue = (0 until ctrlCount).map { i -> songFromMediaItem(ctrl.getMediaItemAt(i)) }
originalQueue = queue
isManuallyShuffled = false
}
syncState()
}
} }
} }
@@ -0,0 +1,79 @@
package com.novasonic.app.player
import android.media.MediaPlayer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
/**
* App-level 30s preview player (iTunes/Deezer preview clips). Kept on the Application — NOT in a
* screen ViewModel — so a preview keeps a **global control bar** (see AppNavigation) even after the
* user leaves the album/artist/Explore screen it started on. Previously the preview lived in
* ExploreViewModel and became uncontrollable once you navigated away.
*/
data class PreviewState(
val trackId: Long? = null,
val title: String = "",
val artist: String = "",
val artworkUrl: String? = null,
val isPlaying: Boolean = false, // true = actively playing, false = paused
)
class PreviewController {
private val _state = MutableStateFlow(PreviewState())
val state: StateFlow<PreviewState> = _state
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
private var mp: MediaPlayer? = null
/** Tap on a track: same track → toggle play/pause; different track → start it. */
fun toggle(trackId: Long, url: String, title: String, artist: String, artworkUrl: String?) {
val cur = _state.value
when {
cur.trackId == trackId && cur.isPlaying -> pause()
cur.trackId == trackId && mp != null -> resume()
else -> start(trackId, url, title, artist, artworkUrl)
}
}
private fun start(trackId: Long, url: String, title: String, artist: String, artworkUrl: String?) {
stop()
_state.value = PreviewState(trackId, title, artist, artworkUrl, isPlaying = true)
scope.launch(Dispatchers.IO) {
try {
val player = MediaPlayer().apply {
setDataSource(url)
prepare()
start()
setOnCompletionListener { stop() }
}
mp = player
} catch (e: Exception) {
stop()
}
}
}
fun pause() {
mp?.runCatching { pause() }
_state.update { it.copy(isPlaying = false) }
}
fun resume() {
val player = mp
if (player == null) return
player.runCatching { start() }
_state.update { it.copy(isPlaying = true) }
}
fun stop() {
mp?.runCatching { stop(); release() }
mp = null
_state.value = PreviewState()
}
}
@@ -1,6 +1,7 @@
package com.novasonic.app.ui package com.novasonic.app.ui
import androidx.activity.compose.BackHandler import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.compose.animation.* import androidx.compose.animation.*
import androidx.compose.animation.core.FastOutSlowInEasing import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
@@ -15,22 +16,28 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import android.app.DownloadManager
import android.content.Context import android.content.Context
import android.net.Uri
import android.os.Environment
import android.widget.Toast import android.widget.Toast
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleEventEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.* import androidx.navigation.*
import androidx.navigation.compose.* import androidx.navigation.compose.*
import com.novasonic.app.api.AbsClient
import com.novasonic.app.api.AbsLibraryItem
import com.novasonic.app.api.model.Song import com.novasonic.app.api.model.Song
import com.novasonic.app.player.AbsPlayerController
import com.novasonic.app.app import com.novasonic.app.app
import com.novasonic.app.data.AppNotification
import com.novasonic.app.data.PrefsStore
import com.novasonic.app.ui.component.MiniPlayer import com.novasonic.app.ui.component.MiniPlayer
import com.novasonic.app.ui.component.PreviewBar
import com.novasonic.app.ui.component.NotificationSheet
import com.novasonic.app.ui.component.PlaylistPickerSheet import com.novasonic.app.ui.component.PlaylistPickerSheet
import com.novasonic.app.ui.component.SongContextSheet import com.novasonic.app.ui.component.SongContextSheet
import com.novasonic.app.ui.component.SongInfoSheet import com.novasonic.app.ui.component.SongInfoSheet
@@ -43,11 +50,16 @@ private enum class TopLevel(val route: String, val icon: ImageVector, val label:
LIBRARY("library", Icons.Default.LibraryMusic, "Bibliothek"), LIBRARY("library", Icons.Default.LibraryMusic, "Bibliothek"),
ERKUNDEN("erkunden", Icons.Default.Explore, "Erkunden"), ERKUNDEN("erkunden", Icons.Default.Explore, "Erkunden"),
STARRED("starred", Icons.Default.Favorite, "Favoriten"), STARRED("starred", Icons.Default.Favorite, "Favoriten"),
SETTINGS("settings", Icons.Default.Settings, "Einstellungen"), ABS("abs", Icons.Default.Book, "Bücher"),
SETTINGS("settings", Icons.Default.Settings, "Einst."),
} }
private val NavBg = Color(0xF7080814) private val NavBg = Color(0xF7080814)
// Position of a route among the top-level tabs (in bottom-bar order), or -1 if it isn't one.
// Used to slide tab switches toward the side the target tab sits on, instead of a push/pop feel.
private fun topLevelIndex(route: String?): Int = TopLevel.entries.indexOfFirst { it.route == route }
@Composable @Composable
fun AppNavigation() { fun AppNavigation() {
val context = LocalContext.current val context = LocalContext.current
@@ -60,72 +72,242 @@ fun AppNavigation() {
repo.credentialsFlow().collect { creds -> repo.lastCredentials = creds } repo.credentialsFlow().collect { creds -> repo.lastCredentials = creds }
} }
// Apply saved theme whenever settings change
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
repo.appSettingsFlow().collect { settings -> applyNsTheme(settings.theme) } repo.appSettingsFlow().collect { settings -> applyNsTheme(settings.theme) }
} }
val playerState by player.state.collectAsStateWithLifecycle() val playerState by player.state.collectAsStateWithLifecycle()
val appSettings by repo.appSettingsFlow().collectAsStateWithLifecycle(PrefsStore.AppSettings())
val lastPlayedSong by repo.lastPlayedSongFlow().collectAsStateWithLifecycle(null)
// ── In-app updater — offer the newer APK the backend advertises ─────────────
val updateInfo by com.novasonic.app.data.AppUpdater.available.collectAsStateWithLifecycle()
val updating by com.novasonic.app.data.AppUpdater.downloading.collectAsStateWithLifecycle()
val updateScope = rememberCoroutineScope()
LaunchedEffect(appSettings.backendUrl) { com.novasonic.app.data.AppUpdater.check(appSettings.backendUrl) }
updateInfo?.let { info ->
AlertDialog(
onDismissRequest = { com.novasonic.app.data.AppUpdater.dismiss() },
title = { Text("Update verfügbar") },
text = { Text("NovaSonic ${info.version ?: ""} ist verfügbar. Jetzt laden und installieren? Deine Downloads und Einstellungen bleiben erhalten.") },
confirmButton = {
TextButton(enabled = !updating, onClick = {
updateScope.launch {
com.novasonic.app.data.AppUpdater.downloadAndInstall(context, appSettings.backendUrl) { msg ->
android.widget.Toast.makeText(context, msg, android.widget.Toast.LENGTH_LONG).show()
}
}
}) { Text(if (updating) "Lädt…" else "Laden & installieren") }
},
dismissButton = { TextButton(onClick = { com.novasonic.app.data.AppUpdater.dismiss() }) { Text("Später") } },
)
}
// 30s preview (app-level, so its control bar survives navigation). Starting real playback
// cancels any active preview so the two don't overlap.
val previewState by app.previewController.state.collectAsStateWithLifecycle()
LaunchedEffect(playerState.isPlaying) { if (playerState.isPlaying) app.previewController.stop() }
val absConfigured = appSettings.absUrl.isNotBlank() && appSettings.absApiKey.isNotBlank()
val absClient: AbsClient? = remember(appSettings.absUrl, appSettings.absApiKey, appSettings.backendUrl) {
if (absConfigured) AbsClient(appSettings.absUrl.trimEnd('/'), appSettings.absApiKey, appSettings.backendUrl.trimEnd('/'))
else null
}
val absPlayerController = context.app.absPlayerController
val absState by absPlayerController.state.collectAsStateWithLifecycle()
DisposableEffect(Unit) { onDispose { absPlayerController.close() } }
LaunchedEffect(appSettings.absChapterTrackMode) {
absPlayerController.setChapterTrackMode(appSettings.absChapterTrackMode)
}
val navController = rememberNavController() val navController = rememberNavController()
// Geteilten Link aufloesen, sobald die Navigation steht: Song abspielen und sein Album oeffnen,
// bzw. direkt zum Album. Laeuft ueber denselben Weg wie im Web, damit sich beide gleich
// verhalten. Fehlschlaege (geloeschter Song, fremde Instanz) enden in einer Meldung statt still.
LaunchedEffect(Unit) {
com.novasonic.app.data.DeepLinkState.pending.collect { uri ->
if (uri == null) return@collect
com.novasonic.app.data.DeepLinkState.consume()
val songId = uri.getQueryParameter("song")
val albumId = uri.getQueryParameter("album")
runCatching {
when {
songId != null -> {
val song = repo.getSong(songId)
song.albumId?.let { navController.navigate("album/$it") }
player.playSongs(listOf(song), 0)
}
albumId != null -> navController.navigate("album/$albumId")
}
}.onFailure {
Toast.makeText(context, "Link konnte nicht geöffnet werden: ${it.message}",
Toast.LENGTH_LONG).show()
}
}
}
var showNowPlaying by remember { mutableStateOf(false) } var showNowPlaying by remember { mutableStateOf(false) }
var contextMenuSong by remember { mutableStateOf<Song?>(null) } var contextMenuSong by remember { mutableStateOf<Song?>(null) }
var playlistPickerSong by remember { mutableStateOf<Song?>(null) } var playlistPickerSong by remember { mutableStateOf<Song?>(null) }
var infoSheetSong by remember { mutableStateOf<Song?>(null) } var infoSheetSong by remember { mutableStateOf<Song?>(null) }
var songToDelete by remember { mutableStateOf<Song?>(null) }
var showNotifications by remember { mutableStateOf(false) }
var selectedAbsItem by remember { mutableStateOf<AbsLibraryItem?>(null) }
var showAbsPlayer by remember { mutableStateOf(false) }
// Close action for the Erkunden (Apple) in-screen overlay (iTunes artist / album). Handled at the
// app root because a BackHandler inside the NavHost "erkunden" destination loses back priority to
// the NavHost, which pops Erkunden → Home instead of dismissing the overlay.
var exploreOverlayBack by remember { mutableStateOf<(() -> Unit)?>(null) }
val backDispatcher = LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher
val currentBackEntry by navController.currentBackStackEntryAsState()
// Returning from the background re-registers the NavController's OWN back callback on top of the
// dispatcher, which stole back-priority from the NowPlaying/ABS overlays: pressing back then popped
// the NavHost (invisibly, all the way to Home) before dismissing the overlay. Bump this tick on
// ON_RESUME (and re-key on navigation) so the overlay callbacks below re-add above it again.
var resumeTick by remember { mutableIntStateOf(0) }
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { resumeTick++ }
DisposableEffect(showNowPlaying, backDispatcher, currentBackEntry, resumeTick) {
if (!showNowPlaying || backDispatcher == null) return@DisposableEffect onDispose {}
val cb = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { showNowPlaying = false }
}
backDispatcher.addCallback(cb)
onDispose { cb.remove() }
}
DisposableEffect(showAbsPlayer, backDispatcher, currentBackEntry, resumeTick) {
if (!showAbsPlayer || backDispatcher == null) return@DisposableEffect onDispose {}
val cb = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { showAbsPlayer = false }
}
backDispatcher.addCallback(cb)
onDispose { cb.remove() }
}
DisposableEffect(selectedAbsItem, backDispatcher, currentBackEntry, resumeTick) {
if (selectedAbsItem == null || backDispatcher == null) return@DisposableEffect onDispose {}
val cb = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { selectedAbsItem = null }
}
backDispatcher.addCallback(cb)
onDispose { cb.remove() }
}
fun coverUrl(coverId: String?) = repo.coverArtUrl(coverId, 600) fun coverUrl(coverId: String?) = repo.coverArtUrl(coverId, 600)
fun heroCoverUrl(coverId: String?) = repo.coverArtUrl(coverId, 1000) fun heroCoverUrl(coverId: String?) = repo.coverArtUrl(coverId, 1000)
fun starToggle(songId: String, currentlyStarred: Boolean) { fun starToggle(songId: String, currentlyStarred: Boolean) {
scope.launch { runCatching { if (currentlyStarred) repo.unstar(songId) else repo.star(songId) } } // Optimistic + reactive: flips StarState instantly so every star icon updates, then hits the API.
com.novasonic.app.data.StarState.toggle(repo, scope, songId, currentlyStarred)
} }
fun showContextMenu(song: Song) { contextMenuSong = song } fun showContextMenu(song: Song) { contextMenuSong = song }
val currentBackEntry by navController.currentBackStackEntryAsState() var homeRefreshKey by remember { mutableIntStateOf(0) }
val currentRoute = currentBackEntry?.destination?.route val currentRoute = currentBackEntry?.destination?.route
val isTopLevel = TopLevel.entries.any { it.route == currentRoute } val isTopLevel = TopLevel.entries.any { it.route == currentRoute }
// Root-level back for the Erkunden (Apple) overlay. Keyed on currentBackEntry as well, so the
// callback is re-added (bumped to the top of the OnBackPressedDispatcher) after every navigation
// — otherwise, once the NavHost re-registers its own callback during an album drill-down or tab
// switch, it could regain priority and pop Erkunden → Home on the next back ("sometimes" bug).
DisposableEffect(exploreOverlayBack, backDispatcher, currentBackEntry, resumeTick) {
val action = exploreOverlayBack
if (action == null || backDispatcher == null) return@DisposableEffect onDispose {}
val cb = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { action() }
}
backDispatcher.addCallback(cb)
onDispose { cb.remove() }
}
val bgGlow = Brush.radialGradient( val bgGlow = Brush.radialGradient(
colors = listOf(Color(0x0AE8A020), Color(0x00000000)), colors = listOf(Color(0x0AE8A020), Color(0x00000000)),
center = Offset.Unspecified, radius = 900f, center = Offset.Unspecified, radius = 900f,
) )
// Nav items — ABS tab only shown when configured; Settings moved to HomeScreen header
val navItems = remember(absConfigured) {
TopLevel.entries.filter { it != TopLevel.ABS || absConfigured }
.filter { it != TopLevel.SETTINGS }
}
Box(Modifier.fillMaxSize()) { Box(Modifier.fillMaxSize()) {
Scaffold( Scaffold(
containerColor = NsBackground, containerColor = NsBackground,
modifier = Modifier.background(NsBackground).background(bgGlow), modifier = Modifier.background(NsBackground).background(bgGlow),
bottomBar = { bottomBar = {
if (isTopLevel) { // MiniPlayer shows on EVERY screen (incl. album/artist/playlist detail) so playback
Column { // is always reachable; the tab bar stays top-level-only. On detail screens there is no
// NavigationBar to absorb the system-navigation inset, so pad the bar itself — otherwise
// the MiniPlayer sits behind the phone's gesture/nav bar.
Column(modifier = if (isTopLevel) Modifier else Modifier.navigationBarsPadding()) {
// 30s preview control bar — above the MiniPlayer, on every screen, so a preview
// started on an album/artist/Explore screen can be paused/stopped from anywhere.
AnimatedVisibility( AnimatedVisibility(
visible = playerState.currentSong != null, visible = previewState.trackId != null,
enter = slideInVertically { it } + fadeIn(tween(220)),
exit = slideOutVertically { it } + fadeOut(tween(180)),
) {
PreviewBar(
state = previewState,
onToggle = { if (previewState.isPlaying) app.previewController.pause() else app.previewController.resume() },
onClose = { app.previewController.stop() },
)
}
// ABS audio routes through MusicService — one notification, one mini player.
// When an ABS book is loaded, tapping the mini player opens the ABS overlay
// instead of the music NowPlaying screen.
val hasAbsItem = absState.item != null
val showMiniPlayer = playerState.isPlaying ||
playerState.currentSong != null ||
(lastPlayedSong != null && !showNowPlaying)
AnimatedVisibility(
visible = showMiniPlayer,
enter = slideInVertically { it } + fadeIn(tween(220)), enter = slideInVertically { it } + fadeIn(tween(220)),
exit = slideOutVertically { it } + fadeOut(tween(180)), exit = slideOutVertically { it } + fadeOut(tween(180)),
) { ) {
MiniPlayer( MiniPlayer(
state = playerState, state = playerState,
coverUrl = coverUrl(playerState.currentSong?.coverArt), coverUrl = coverUrl(playerState.currentSong?.coverArt) ?: playerState.artworkUri,
onTap = { showNowPlaying = true }, onTap = { if (hasAbsItem) showAbsPlayer = true else showNowPlaying = true },
onTogglePlay = { player.togglePlay() }, onTogglePlay = { if (hasAbsItem) absPlayerController.togglePlay() else player.togglePlay() },
onSkipPrev = { player.skipPrev() }, onSkipPrev = { if (hasAbsItem) absPlayerController.prevChapter() else player.skipPrev() },
onSkipNext = { player.skipNext() }, onSkipNext = { if (hasAbsItem) absPlayerController.nextChapter() else player.skipNext() },
lastSong = if (playerState.currentSong == null) lastPlayedSong else null,
lastSongCoverUrl = lastPlayedSong?.coverArtId?.let { coverUrl(it) },
onPlayLast = {
lastPlayedSong?.let { ls ->
scope.launch {
runCatching {
val song = repo.getSong(ls.id)
player.playSongs(listOf(song), 0)
}
}
}
},
) )
} }
if (isTopLevel) {
NavigationBar(containerColor = NavBg, tonalElevation = 0.dp) { NavigationBar(containerColor = NavBg, tonalElevation = 0.dp) {
TopLevel.entries.forEach { dest -> navItems.forEach { dest ->
NavigationBarItem( NavigationBarItem(
selected = currentRoute == dest.route, selected = currentRoute == dest.route,
onClick = { onClick = {
if (dest == TopLevel.HOME && currentRoute == TopLevel.HOME.route) {
homeRefreshKey++
} else {
navController.navigate(dest.route) { navController.navigate(dest.route) {
popUpTo(navController.graph.startDestinationId) { saveState = true } popUpTo(navController.graph.startDestinationId) { saveState = true }
launchSingleTop = true; restoreState = true launchSingleTop = true; restoreState = true
} }
}
}, },
icon = { Icon(dest.icon, contentDescription = dest.label) }, icon = { Icon(dest.icon, contentDescription = dest.label) },
label = { label = { Text(dest.label, style = TextStyle(fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 9.sp), maxLines = 1) },
Text(dest.label, style = TextStyle(
fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 10.sp))
},
colors = NavigationBarItemDefaults.colors( colors = NavigationBarItemDefaults.colors(
selectedIconColor = NsAccent, selectedIconColor = NsAccent,
selectedTextColor = NsAccent, selectedTextColor = NsAccent,
@@ -144,26 +326,45 @@ fun AppNavigation() {
navController = navController, navController = navController,
startDestination = TopLevel.HOME.route, startDestination = TopLevel.HOME.route,
modifier = Modifier.padding(innerPadding), modifier = Modifier.padding(innerPadding),
// Direction of a tab switch: +1 if the target tab sits to the right of the current
// one, -1 if to the left, 0 if this isn't a tab-to-tab move (detail push/pop).
enterTransition = { enterTransition = {
slideInHorizontally(initialOffsetX = { it }, animationSpec = tween(280, easing = FastOutSlowInEasing)) + val f = topLevelIndex(initialState.destination.route)
fadeIn(tween(200)) val t = topLevelIndex(targetState.destination.route)
val dir = if (f >= 0 && t >= 0 && f != t) (if (t > f) 1 else -1) else 0
if (dir != 0) slideInHorizontally(tween(280, easing = FastOutSlowInEasing)) { dir * it } + fadeIn(tween(200))
else slideInHorizontally(tween(280, easing = FastOutSlowInEasing)) { it } + fadeIn(tween(200))
}, },
exitTransition = { exitTransition = {
slideOutHorizontally(targetOffsetX = { -it / 3 }, animationSpec = tween(280, easing = FastOutSlowInEasing)) + val f = topLevelIndex(initialState.destination.route)
fadeOut(tween(180)) val t = topLevelIndex(targetState.destination.route)
val dir = if (f >= 0 && t >= 0 && f != t) (if (t > f) 1 else -1) else 0
if (dir != 0) slideOutHorizontally(tween(280, easing = FastOutSlowInEasing)) { -dir * it } + fadeOut(tween(180))
else slideOutHorizontally(tween(280, easing = FastOutSlowInEasing)) { -it / 3 } + fadeOut(tween(180))
}, },
popEnterTransition = { popEnterTransition = {
slideInHorizontally(initialOffsetX = { -it / 3 }, animationSpec = tween(280, easing = FastOutSlowInEasing)) + val f = topLevelIndex(initialState.destination.route)
fadeIn(tween(200)) val t = topLevelIndex(targetState.destination.route)
val dir = if (f >= 0 && t >= 0 && f != t) (if (t > f) 1 else -1) else 0
if (dir != 0) slideInHorizontally(tween(280, easing = FastOutSlowInEasing)) { dir * it } + fadeIn(tween(200))
else slideInHorizontally(tween(280, easing = FastOutSlowInEasing)) { -it / 3 } + fadeIn(tween(200))
}, },
popExitTransition = { popExitTransition = {
slideOutHorizontally(targetOffsetX = { it }, animationSpec = tween(280, easing = FastOutSlowInEasing)) + val f = topLevelIndex(initialState.destination.route)
fadeOut(tween(180)) val t = topLevelIndex(targetState.destination.route)
val dir = if (f >= 0 && t >= 0 && f != t) (if (t > f) 1 else -1) else 0
if (dir != 0) slideOutHorizontally(tween(280, easing = FastOutSlowInEasing)) { -dir * it } + fadeOut(tween(180))
else slideOutHorizontally(tween(280, easing = FastOutSlowInEasing)) { it } + fadeOut(tween(180))
}, },
) { ) {
composable(TopLevel.HOME.route) { composable(TopLevel.HOME.route) {
HomeScreen( HomeScreen(
coverUrl = { album -> coverUrl(album.coverArt) }, coverUrl = { album -> coverUrl(album.coverArt) },
onBellClick = { showNotifications = true },
onSettingsClick = { navController.navigate(TopLevel.SETTINGS.route) {
popUpTo(navController.graph.startDestinationId) { saveState = true }
launchSingleTop = true; restoreState = true
} },
onAlbumClick = { album -> navController.navigate("album/${album.id}") }, onAlbumClick = { album -> navController.navigate("album/${album.id}") },
onAlbumPlay = { album -> onAlbumPlay = { album ->
scope.launch { runCatching { scope.launch { runCatching {
@@ -175,9 +376,11 @@ fun AppNavigation() {
onGenrePlay = { genre -> onGenrePlay = { genre ->
scope.launch { runCatching { scope.launch { runCatching {
val songs = repo.getSongsByGenre(genre.value) val songs = repo.getSongsByGenre(genre.value)
if (songs.isNotEmpty()) player.playSongs(songs.shuffled(), 0) if (songs.isNotEmpty()) player.playSongs(songs, -1) // -1 = gemischt
}} }}
}, },
onShowAllGenres = { navController.navigate("genres") },
refreshKey = homeRefreshKey,
) )
} }
composable(TopLevel.LIBRARY.route) { composable(TopLevel.LIBRARY.route) {
@@ -186,6 +389,8 @@ fun AppNavigation() {
onAlbumClick = { album -> navController.navigate("album/${album.id}") }, onAlbumClick = { album -> navController.navigate("album/${album.id}") },
onArtistClick = { artist -> navController.navigate("artist/${artist.id}") }, onArtistClick = { artist -> navController.navigate("artist/${artist.id}") },
onPlaylistClick = { pl -> navController.navigate("playlist/${pl.id}") }, onPlaylistClick = { pl -> navController.navigate("playlist/${pl.id}") },
onPlay = { songs, idx -> player.playSongs(songs, idx) },
onOpenOffline = { group -> navController.navigate("offline/${encodeRoute(group.groupId)}") },
) )
} }
composable(TopLevel.ERKUNDEN.route) { composable(TopLevel.ERKUNDEN.route) {
@@ -195,6 +400,8 @@ fun AppNavigation() {
onSongPlay = { songs, idx -> player.playSongs(songs, idx) }, onSongPlay = { songs, idx -> player.playSongs(songs, idx) },
onAlbumClick = { album -> navController.navigate("album/${album.id}") }, onAlbumClick = { album -> navController.navigate("album/${album.id}") },
onArtistClick = { artist -> navController.navigate("artist/${artist.id}") }, onArtistClick = { artist -> navController.navigate("artist/${artist.id}") },
onShowContextMenu = ::showContextMenu,
onOverlayBackChange = { exploreOverlayBack = it },
onOpenImporter = { navController.navigate("importer") }, onOpenImporter = { navController.navigate("importer") },
) )
} }
@@ -208,9 +415,62 @@ fun AppNavigation() {
onPlay = { songs, idx -> player.playSongs(songs, idx) }, onPlay = { songs, idx -> player.playSongs(songs, idx) },
onStarToggle = { song -> starToggle(song.id, song.starred != null) }, onStarToggle = { song -> starToggle(song.id, song.starred != null) },
onShowContextMenu = ::showContextMenu, onShowContextMenu = ::showContextMenu,
onArtistClick = { id -> navController.navigate("artist/$id") },
onAlbumClick = { id -> navController.navigate("album/$id") },
onOpenNews = { navController.navigate("artist-news") },
onOpenFollowed = {
com.novasonic.app.data.LibraryIntent.oeffneGefolgte = true
navController.navigate(TopLevel.LIBRARY.route)
},
)
}
composable("artist-news") {
ArtistNewsScreen(
onBack = { navController.popBackStack() },
onArtistClick = { id -> navController.navigate("artist/$id") },
)
}
composable(TopLevel.ABS.route) {
val client = absClient
if (client != null) {
if (selectedAbsItem != null) {
AbsBookDetailScreen(
absClient = client,
libraryItem = selectedAbsItem!!,
absPlayerController = absPlayerController,
onPlay = { showAbsPlayer = true },
onBack = { selectedAbsItem = null },
)
} else {
AbsBooksScreen(
absClient = client,
onItemClick = { selectedAbsItem = it },
)
}
}
}
composable(TopLevel.SETTINGS.route) {
SettingsScreen(
onOpenStats = { navController.navigate("stats") },
onOpenCompare = { navController.navigate("compare") },
)
}
composable("stats") {
StatsScreen(
coverUrl = { id -> coverUrl(id) },
onBack = { navController.popBackStack() },
onArtistClick = { id -> navController.navigate("artist/$id") },
onAlbumClick = { id -> navController.navigate("album/$id") },
)
}
composable("compare") {
CompareScreen(
coverUrl = { id -> coverUrl(id) },
onBack = { navController.popBackStack() },
onArtistClick = { id -> navController.navigate("artist/$id") },
onAlbumClick = { id -> navController.navigate("album/$id") },
) )
} }
composable(TopLevel.SETTINGS.route) { SettingsScreen() }
composable( composable(
"album/{albumId}", "album/{albumId}",
@@ -237,6 +497,7 @@ fun AppNavigation() {
onAlbumClick = { album -> navController.navigate("album/${album.id}") }, onAlbumClick = { album -> navController.navigate("album/${album.id}") },
onStarToggle = { song -> starToggle(song.id, song.starred != null) }, onStarToggle = { song -> starToggle(song.id, song.starred != null) },
onShowContextMenu = ::showContextMenu, onShowContextMenu = ::showContextMenu,
onArtistClick = { artistId -> navController.navigate("artist/$artistId") },
onBack = { navController.popBackStack() }, onBack = { navController.popBackStack() },
) )
} }
@@ -250,6 +511,18 @@ fun AppNavigation() {
onPlay = { songs, idx -> player.playSongs(songs, idx) }, onPlay = { songs, idx -> player.playSongs(songs, idx) },
onStarToggle = { song -> starToggle(song.id, song.starred != null) }, onStarToggle = { song -> starToggle(song.id, song.starred != null) },
onShowContextMenu = ::showContextMenu, onShowContextMenu = ::showContextMenu,
onDeleted = { navController.popBackStack() },
onBack = { navController.popBackStack() },
)
}
composable(
"offline/{groupId}",
arguments = listOf(navArgument("groupId") { type = NavType.StringType }),
) {
OfflineDetailScreen(
coverUrl = { id -> coverUrl(id) },
playerState = playerState,
onPlay = { songs, idx -> player.playSongs(songs, idx) },
onBack = { navController.popBackStack() }, onBack = { navController.popBackStack() },
) )
} }
@@ -268,13 +541,22 @@ fun AppNavigation() {
onBack = { navController.popBackStack() }, onBack = { navController.popBackStack() },
) )
} }
composable("genres") {
GenreListScreen(
onGenreClick = { genre -> navController.navigate("genre/${encodeRoute(genre.value)}") },
onGenrePlay = { genre ->
scope.launch { runCatching {
val songs = repo.getSongsByGenre(genre.value)
if (songs.isNotEmpty()) player.playSongs(songs, -1) // -1 = gemischt
}}
},
onBack = { navController.popBackStack() },
)
}
} }
} }
// Dismiss NowPlaying with hardware back button // NowPlaying overlay
BackHandler(enabled = showNowPlaying) { showNowPlaying = false }
// NowPlaying overlay — outside Scaffold so WindowInsets are not double-consumed
AnimatedVisibility( AnimatedVisibility(
visible = showNowPlaying, visible = showNowPlaying,
enter = slideInVertically { it } + fadeIn(tween(220)), enter = slideInVertically { it } + fadeIn(tween(220)),
@@ -282,58 +564,123 @@ fun AppNavigation() {
) { ) {
NowPlayingScreen( NowPlayingScreen(
state = playerState, state = playerState,
coverUrl = heroCoverUrl(playerState.currentSong?.coverArt), coverUrl = heroCoverUrl(playerState.currentSong?.coverArt) ?: playerState.artworkUri,
queueCoverUrl = { id -> coverUrl(id) }, queueCoverUrl = { id -> coverUrl(id) },
controller = player, controller = player,
onDismiss = { showNowPlaying = false }, onDismiss = { showNowPlaying = false },
onStarToggle = { onStarToggle = { playerState.currentSong?.let { s -> starToggle(s.id, s.starred != null) } },
playerState.currentSong?.let { s -> starToggle(s.id, s.starred != null) } onShowOptions = { playerState.currentSong?.let { s -> contextMenuSong = s } },
}, onArtistClick = { artistId ->
onShowOptions = {
playerState.currentSong?.let { s -> contextMenuSong = s }
},
onArtistClick = playerState.currentSong?.artistId?.let { artistId ->
{
showNowPlaying = false showNowPlaying = false
navController.navigate("artist/$artistId") if (artistId.isNotBlank()) navController.navigate("artist/$artistId")
}
}, },
onToggleRadio = { player.toggleRadio() },
) )
} }
// Song context menu bottom sheet // ABS player overlay
AnimatedVisibility(
visible = showAbsPlayer,
enter = slideInVertically { it } + fadeIn(tween(220)),
exit = slideOutVertically { it } + fadeOut(tween(180)),
) {
val client = absClient
if (client != null) {
AbsNowPlayingScreen(
absPlayerController = absPlayerController,
absClient = client,
onDismiss = { showAbsPlayer = false },
)
}
}
contextMenuSong?.let { song -> contextMenuSong?.let { song ->
SongContextSheet( SongContextSheet(
song = song, song = song,
isStarred = song.starred != null, isStarred = com.novasonic.app.data.StarState.isStarred(song),
onDismiss = { contextMenuSong = null }, onDismiss = { contextMenuSong = null },
onPlay = { player.playSongs(listOf(song), 0) }, onPlay = { player.playSongs(listOf(song), 0) },
onInsertNext = { player.insertNext(song) }, onInsertNext = { player.insertNext(song) },
onAddToQueue = { player.addToQueueEnd(song) }, onAddToQueue = { player.addToQueueEnd(song) },
onStarToggle = { starToggle(song.id, song.starred != null) }, onStarToggle = { starToggle(song.id, com.novasonic.app.data.StarState.isStarred(song)) },
onAddToPlaylist = { onAddToPlaylist = { playlistPickerSong = song; contextMenuSong = null },
playlistPickerSong = song onGoToAlbum = song.albumId?.let { albumId -> { navController.navigate("album/$albumId") } },
contextMenuSong = null onShowInfo = { infoSheetSong = song; contextMenuSong = null },
},
onGoToAlbum = song.albumId?.let { albumId ->
{ navController.navigate("album/$albumId") }
},
onShowInfo = {
infoSheetSong = song
contextMenuSong = null
},
onDownload = { onDownload = {
downloadSong(context, song, repo.streamUrl(song.id) ?: "") scope.launch {
runCatching {
app.offlineRepository.enqueueGroup(
type = com.novasonic.app.offline.GroupType.SONG,
sourceId = song.id,
name = song.title,
coverArt = song.coverArt,
songs = listOf(song),
)
}.onFailure { android.util.Log.e("AppNavigation", "enqueueGroup failed", it) }
}
Toast.makeText(context, "Download gestartet: ${song.title}", android.widget.Toast.LENGTH_SHORT).show()
contextMenuSong = null contextMenuSong = null
}, },
// Link auf die eigene Web-App, den der Empfaenger mit SEINEN Zugangsdaten oeffnet —
// uebertragen wird nur die Song-Id, kein Geheimnis. Der Host kommt aus BuildConfig
// (dieselbe Angabe wie fuer die App-Links im Manifest), damit es keine vierte
// Adresse zum Pflegen gibt und beide Richtungen nie auseinanderlaufen koennen.
onShare = {
val link = "https://${com.novasonic.app.BuildConfig.SHARE_HOST}/?song=${song.id}"
val text = listOfNotNull(song.title, song.artist).joinToString(" — ")
context.startActivity(android.content.Intent.createChooser(
android.content.Intent(android.content.Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(android.content.Intent.EXTRA_SUBJECT, text)
putExtra(android.content.Intent.EXTRA_TEXT, "$text\n$link")
}, "Song teilen"))
},
// Nur mit Backend: das Loeschen laeuft ueber /api/delete-song, Navidrome allein
// kann keine Dateien entfernen.
onDelete = if (appSettings.backendUrl.isNotBlank()) {
{ songToDelete = song; contextMenuSong = null }
} else null,
)
}
// Sicherheitsabfrage vor dem endgueltigen Loeschen — Wortlaut wie im Web.
songToDelete?.let { song ->
AlertDialog(
onDismissRequest = { songToDelete = null },
title = { Text("Song löschen") },
text = { Text("\"${song.title}\" wird unwiderruflich von der Festplatte gelöscht. " +
"Leere Album- und Künstlerordner werden ebenfalls entfernt.") },
confirmButton = {
TextButton(onClick = {
songToDelete = null
scope.launch {
val creds = repo.lastCredentials
val client = com.novasonic.app.api.ImporterClient(appSettings.backendUrl)
val res = runCatching {
client.deleteSong(creds?.serverUrl ?: "", creds?.username ?: "",
creds?.password ?: "", song.id)
}
client.close()
Toast.makeText(
context,
res.fold({ "🗑 \"${song.title}\" gelöscht" },
{ "Löschen fehlgeschlagen: ${it.message}" }),
Toast.LENGTH_LONG,
).show()
// Navidrome braucht einen Moment zum Nachscannen, dann die Ansicht neu laden.
if (res.isSuccess) { kotlinx.coroutines.delay(3000); homeRefreshKey++ }
}
}) { Text("Löschen", color = MaterialTheme.colorScheme.error) }
},
dismissButton = { TextButton(onClick = { songToDelete = null }) { Text("Abbrechen") } },
) )
} }
// Playlist picker sheet
playlistPickerSong?.let { song -> playlistPickerSong?.let { song ->
PlaylistPickerSheet( PlaylistPickerSheet(
song = song, song = song,
loadPlaylists = { repo.getPlaylists() }, loadPlaylists = { repo.getPlaylists() },
coverUrl = { id -> coverUrl(id) },
onAdd = { pl -> onAdd = { pl ->
playlistPickerSong = null playlistPickerSong = null
scope.launch { scope.launch {
@@ -354,29 +701,48 @@ fun AppNavigation() {
) )
} }
// Song info sheet
infoSheetSong?.let { song -> infoSheetSong?.let { song ->
SongInfoSheet(song = song, onDismiss = { infoSheetSong = null }) SongInfoSheet(song = song, onDismiss = { infoSheetSong = null })
} }
if (showNotifications) {
NotificationSheet(
onDismiss = { showNotifications = false },
onNavigate = { n ->
showNotifications = false
scope.launch {
runCatching {
when {
n.navType == "playlist" && n.navId.isNotBlank() -> {
navController.navigate("playlist/${n.navId}")
}
n.navAlbum.isNotBlank() -> {
val res = repo.search(n.navAlbum)
val albums = res.album
val norm = { s: String -> s.lowercase().trim() }
val na = norm(n.navArtist)
// REQUIRE the artist match when we know it — several artists share an
// album title ("I LIKE IT!"); the old name-only / firstOrNull fallback
// opened a completely different artist's album (wrong song).
val match = albums.firstOrNull {
val aa = norm(it.artist ?: "")
norm(it.name) == norm(n.navAlbum) && na.isNotBlank() &&
(aa == na || aa.contains(na) || na.contains(aa))
} ?: if (na.isBlank()) albums.firstOrNull { norm(it.name) == norm(n.navAlbum) } else null
if (match != null) {
navController.navigate("album/${match.id}")
} else {
Toast.makeText(context, "Album noch nicht gefunden — evtl. wird die Library gerade gescannt", Toast.LENGTH_SHORT).show()
}
}
}
}
}
},
)
}
} }
} }
private fun downloadSong(context: Context, song: Song, streamUrl: String) {
if (streamUrl.isBlank()) {
Toast.makeText(context, "Stream-URL nicht verfügbar", Toast.LENGTH_SHORT).show()
return
}
val safe = (song.title + "." + (song.suffix ?: "mp3"))
.replace(Regex("[/\\\\:*?\"<>|]"), "_")
val request = DownloadManager.Request(Uri.parse(streamUrl))
.setTitle(song.title)
.setDescription(song.artist ?: "")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC, safe)
.setMimeType(song.contentType ?: "audio/mpeg")
val dm = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
dm.enqueue(request)
Toast.makeText(context, "Download gestartet: ${song.title}", Toast.LENGTH_SHORT).show()
}
private fun encodeRoute(s: String) = java.net.URLEncoder.encode(s, "UTF-8") private fun encodeRoute(s: String) = java.net.URLEncoder.encode(s, "UTF-8")
@@ -0,0 +1,16 @@
package com.novasonic.app.ui
/**
* Gesamtdauer einer Playlist oder eines Albums, in Sekunden hereingereicht.
*
* Ab einer Stunde werden Stunden ausgewiesen: "134 Min." muss man sonst selbst umrechnen, und bei
* einer Playlist mit 2000 Titeln staende dort eine vierstellige Minutenzahl. Gleiche Regel und
* gleiche Schreibweise wie `formatGesamtdauer` im Web (src/utils.js).
*/
fun formatGesamtdauer(sekunden: Int): String {
val min = Math.round((sekunden.coerceAtLeast(0)) / 60.0).toInt()
if (min < 60) return "$min Min."
val std = min / 60
val rest = min % 60
return if (rest > 0) "$std Std. $rest Min." else "$std Std."
}
@@ -19,6 +19,8 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
// Geteilter Link, mit dem die App gestartet wurde.
com.novasonic.app.data.DeepLinkState.offer(intent?.data)
enableEdgeToEdge() enableEdgeToEdge()
setContent { setContent {
NovaSonicTheme { NovaSonicTheme {
@@ -28,6 +30,14 @@ class MainActivity : ComponentActivity() {
} }
} }
} }
// launchMode=singleTask: laeuft die App bereits, kommt ein weiterer Link hier an statt in
// onCreate. Ohne das passierte beim zweiten geteilten Link schlicht nichts.
override fun onNewIntent(intent: android.content.Intent) {
super.onNewIntent(intent)
setIntent(intent)
com.novasonic.app.data.DeepLinkState.offer(intent.data)
}
} }
@Composable @Composable
@@ -35,12 +45,15 @@ private fun NovaSonicRoot() {
val context = LocalContext.current val context = LocalContext.current
val prefs = remember { PrefsStore(context) } val prefs = remember { PrefsStore(context) }
val creds by prefs.credentials.collectAsStateWithLifecycle( val creds by prefs.credentials.collectAsStateWithLifecycle(
initialValue = PrefsStore.Credentials("", "", ""), initialValue = null,
) )
var forceLogin by remember { mutableStateOf(false) } var forceLogin by remember { mutableStateOf(false) }
if (!creds.isValid || forceLogin) { // null = still loading from DataStore; don't show anything yet to avoid login screen flash
if (creds == null) return
if (!creds!!.isValid || forceLogin) {
LoginScreen(onLoggedIn = { forceLogin = false }) LoginScreen(onLoggedIn = { forceLogin = false })
} else { } else {
AppNavigation() AppNavigation()
@@ -0,0 +1,107 @@
package com.novasonic.app.ui.component
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Pause
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.novasonic.app.api.AbsClient
import com.novasonic.app.player.AbsPlayState
import com.novasonic.app.ui.theme.*
@Composable
fun AbsMiniPlayer(
state: AbsPlayState,
absClient: AbsClient,
onTap: () -> Unit,
onTogglePlay: () -> Unit,
modifier: Modifier = Modifier,
) {
val item = state.item ?: return
val meta = item.media.metadata
val chapterName = state.chapters.getOrNull(state.chapterIdx)?.title
Column(
modifier = modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
.padding(top = 6.dp, bottom = 4.dp)
.shadow(12.dp, RoundedCornerShape(18.dp))
.clip(RoundedCornerShape(18.dp))
.background(NsSurface),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = onTap)
.padding(horizontal = 12.dp, vertical = 10.dp),
) {
AsyncImage(
model = absClient.coverUrl(item.id),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.size(44.dp)
.clip(RoundedCornerShape(8.dp))
.background(NsSurface2),
)
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(
text = meta?.title ?: "Hörbuch",
fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 14.sp, color = NsOnSurface,
maxLines = 1, overflow = TextOverflow.Ellipsis,
)
Text(
text = chapterName ?: meta?.authorName ?: "",
fontFamily = Outfit, fontSize = 12.sp,
color = NsOnSurface2, maxLines = 1, overflow = TextOverflow.Ellipsis,
)
}
Spacer(Modifier.width(8.dp))
Box(
modifier = Modifier
.size(40.dp)
.clip(CircleShape)
.background(NsAccent)
.clickable(onClick = onTogglePlay),
contentAlignment = Alignment.Center,
) {
Icon(
imageVector = if (state.isPlaying) Icons.Default.Pause else Icons.Default.PlayArrow,
contentDescription = null,
tint = Color.White,
modifier = Modifier.size(22.dp),
)
}
}
if (state.duration > 0) {
LinearProgressIndicator(
progress = { (state.currentTime / state.duration).toFloat().coerceIn(0f, 1f) },
modifier = Modifier.fillMaxWidth().height(3.dp),
color = NsAccent,
trackColor = NsAccent.copy(alpha = 0.15f),
)
}
}
}
@@ -4,10 +4,15 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DownloadForOffline
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@@ -28,6 +33,7 @@ fun AlbumCard(
album: Album, album: Album,
coverUrl: String?, coverUrl: String?,
width: Dp = 145.dp, width: Dp = 145.dp,
downloaded: Boolean = false,
onClick: () -> Unit, onClick: () -> Unit,
) { ) {
val shape = RoundedCornerShape(12.dp) val shape = RoundedCornerShape(12.dp)
@@ -40,6 +46,7 @@ fun AlbumCard(
.border(1.dp, cardBorder, shape) .border(1.dp, cardBorder, shape)
.clickable(onClick = onClick), .clickable(onClick = onClick),
) { ) {
Box {
AsyncImage( AsyncImage(
model = coverUrl, model = coverUrl,
contentDescription = album.name, contentDescription = album.name,
@@ -49,6 +56,25 @@ fun AlbumCard(
.aspectRatio(1f) .aspectRatio(1f)
.background(NsSurface2), .background(NsSurface2),
) )
if (downloaded) {
Box(
Modifier
.align(Alignment.BottomEnd)
.padding(6.dp)
.size(22.dp)
.clip(CircleShape)
.background(Color.Black.copy(alpha = 0.55f)),
contentAlignment = Alignment.Center,
) {
Icon(
Icons.Default.DownloadForOffline,
contentDescription = "Heruntergeladen",
tint = NsAccent,
modifier = Modifier.size(16.dp),
)
}
}
}
Column(Modifier.padding(10.dp)) { Column(Modifier.padding(10.dp)) {
Text( Text(
text = album.name, text = album.name,
@@ -0,0 +1,193 @@
package com.novasonic.app.ui.component
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.novasonic.app.api.model.ConcertEvent
import com.novasonic.app.ui.theme.*
import java.time.LocalDateTime
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ConcertsSheet(
artistName: String,
events: List<ConcertEvent>,
onDismiss: () -> Unit,
eventsError: String? = null,
) {
val context = LocalContext.current
ModalBottomSheet(
onDismissRequest = onDismiss,
containerColor = NsSurface,
shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp),
) {
Text(
"Konzerte · $artistName",
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 16.sp,
color = NsOnSurface,
modifier = Modifier.padding(start = 20.dp, end = 20.dp, bottom = 16.dp),
)
if (events.isEmpty()) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp, vertical = 40.dp),
) {
Text(
if (eventsError != null) "Konzerte konnten nicht geladen werden" else "Keine Konzerte angekündigt",
fontFamily = Outfit, fontSize = 14.sp,
color = NsOnSurface2,
)
if (eventsError != null) {
Spacer(Modifier.height(6.dp))
Text(
eventsError,
fontFamily = Outfit, fontSize = 11.sp,
color = NsOnSurface2.copy(alpha = 0.6f),
)
}
}
} else {
LazyColumn(
contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = 32.dp),
verticalArrangement = Arrangement.spacedBy(10.dp),
) {
items(events) { event ->
EventRow(event = event, onTicketClick = { url ->
runCatching {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}
})
}
}
}
}
}
@Composable
private fun EventRow(event: ConcertEvent, onTicketClick: (String) -> Unit) {
val w = formatEventWhen(event.datetime)
val venue = event.venue?.name.orEmpty()
val city = listOfNotNull(event.venue?.city, event.venue?.country).joinToString(", ")
val offer = event.offers.firstOrNull { !it.url.isNullOrBlank() }
val soldOut = offer?.status == "unavailable"
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
.background(NsSurface2)
.padding(horizontal = 14.dp, vertical = 12.dp),
) {
// Date block — fixed width, calendar style (day big, month/year + time small) so every
// row is the same height and the divider/venue line up.
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.width(56.dp),
) {
Text(
w.day,
fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 18.sp, color = NsAccent, maxLines = 1,
)
if (w.monthYear.isNotBlank()) {
Text(
w.monthYear,
fontFamily = Outfit, fontSize = 10.sp, color = NsOnSurface2, maxLines = 1,
)
}
if (w.time.isNotBlank()) {
Text(
w.time,
fontFamily = Outfit, fontSize = 10.sp, color = NsOnSurface2, maxLines = 1,
)
}
}
Spacer(Modifier.width(14.dp))
Box(Modifier.width(1.dp).height(40.dp).background(NsBorder))
Spacer(Modifier.width(14.dp))
// Venue
Column(Modifier.weight(1f)) {
if (venue.isNotBlank()) {
Text(
venue, fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 13.sp, color = NsOnSurface,
maxLines = 1,
)
}
if (city.isNotBlank()) {
Text(
city, fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
maxLines = 1,
)
}
}
// Ticket button
if (offer?.url != null) {
Spacer(Modifier.width(10.dp))
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.clip(RoundedCornerShape(8.dp))
.then(
if (soldOut) Modifier.border(1.dp, NsOnSurface2.copy(alpha = 0.3f), RoundedCornerShape(8.dp))
else Modifier.background(NsAccent)
)
.clickable(enabled = !soldOut) { onTicketClick(offer.url) }
.padding(horizontal = 10.dp, vertical = 6.dp),
) {
Text(
if (soldOut) "Ausverkauft" else "Tickets →",
fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 11.sp,
color = if (soldOut) NsOnSurface2 else Color.White,
)
}
}
}
}
private data class EventWhen(val day: String, val monthYear: String, val time: String)
private val DAY_FMT = DateTimeFormatter.ofPattern("dd", Locale.GERMAN)
private val MONTH_FMT = DateTimeFormatter.ofPattern("MMM yyyy", Locale.GERMAN)
private val TIME_FMT = DateTimeFormatter.ofPattern("HH:mm")
private fun formatEventWhen(datetime: String): EventWhen {
return try {
// Backend now sends a naive venue-local datetime ("2026-09-16T20:00:00"); older/zoned
// values ("…Z") still parse via the ZonedDateTime fallback.
val ldt = runCatching { LocalDateTime.parse(datetime) }
.getOrElse { ZonedDateTime.parse(datetime).toLocalDateTime() }
val time = if (ldt.hour == 0 && ldt.minute == 0) "" else ldt.format(TIME_FMT)
EventWhen(ldt.format(DAY_FMT), ldt.format(MONTH_FMT), time)
} catch (_: Exception) {
EventWhen(datetime.take(10), "", "")
}
}
@@ -40,6 +40,9 @@ fun ItunesDownloadSheet(
ModalBottomSheet( ModalBottomSheet(
onDismissRequest = onDismiss, onDismissRequest = onDismiss,
// Open fully so the "Herunterladen" button is visible right away (it sits above the system
// nav bar via navigationBarsPadding below) — no drag-up needed.
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
containerColor = NsSurface, containerColor = NsSurface,
dragHandle = { BottomSheetDefaults.DragHandle(color = NsOnSurface2.copy(0.3f)) }, dragHandle = { BottomSheetDefaults.DragHandle(color = NsOnSurface2.copy(0.3f)) },
) { ) {
@@ -23,6 +23,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.novasonic.app.data.PrefsStore
import com.novasonic.app.player.PlayerState import com.novasonic.app.player.PlayerState
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
@@ -34,9 +35,25 @@ fun MiniPlayer(
onTogglePlay: () -> Unit, onTogglePlay: () -> Unit,
onSkipPrev: () -> Unit, onSkipPrev: () -> Unit,
onSkipNext: () -> Unit, onSkipNext: () -> Unit,
lastSong: PrefsStore.LastPlayedSong? = null,
lastSongCoverUrl: String? = null,
onPlayLast: (() -> Unit)? = null,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val song = state.currentSong ?: return val song = state.currentSong
// If no active song but last song exists, show it in "resume" mode
if (song == null) {
val ls = lastSong ?: return
LastSongMiniPlayer(
lastSong = ls,
coverUrl = lastSongCoverUrl,
onTap = onTap,
onPlay = onPlayLast ?: {},
modifier = modifier,
)
return
}
Column( Column(
modifier = modifier modifier = modifier
@@ -55,78 +72,93 @@ fun MiniPlayer(
.padding(horizontal = 12.dp, vertical = 10.dp), .padding(horizontal = 12.dp, vertical = 10.dp),
) { ) {
AsyncImage( AsyncImage(
model = coverUrl, model = coverUrl, contentDescription = null,
contentDescription = null,
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier modifier = Modifier.size(44.dp).clip(RoundedCornerShape(8.dp)).background(NsSurface2),
.size(44.dp)
.clip(RoundedCornerShape(8.dp))
.background(NsSurface2),
) )
Spacer(Modifier.width(12.dp)) Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) { Column(Modifier.weight(1f)) {
Text( Text(
text = song.title, text = song.title, fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontFamily = Outfit, fontSize = 14.sp, color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis,
fontWeight = FontWeight.SemiBold,
fontSize = 14.sp,
color = NsOnSurface,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
) )
if (!song.artist.isNullOrBlank()) { if (!song.artist.isNullOrBlank()) {
Text( Text(
text = song.artist!!, text = song.artist!!, fontFamily = Outfit, fontSize = 12.sp,
fontFamily = Outfit, color = NsOnSurface2, maxLines = 1, overflow = TextOverflow.Ellipsis,
fontSize = 12.sp,
color = NsOnSurface2,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
) )
} }
} }
IconButton(onClick = onSkipPrev, modifier = Modifier.size(40.dp)) { IconButton(onClick = onSkipPrev, modifier = Modifier.size(40.dp)) {
Icon( Icon(Icons.Default.SkipPrevious, contentDescription = null, tint = NsOnSurface2, modifier = Modifier.size(24.dp))
Icons.Default.SkipPrevious,
contentDescription = null,
tint = NsOnSurface2,
modifier = Modifier.size(24.dp),
)
} }
// Accent play/pause circle button
Box( Box(
Modifier Modifier.size(40.dp).clip(CircleShape).background(NsAccent).clickable(onClick = onTogglePlay),
.size(40.dp)
.clip(CircleShape)
.background(NsAccent)
.clickable(onClick = onTogglePlay),
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
) { ) {
Icon( Icon(
imageVector = if (state.isPlaying) Icons.Default.Pause else Icons.Default.PlayArrow, imageVector = if (state.isPlaying) Icons.Default.Pause else Icons.Default.PlayArrow,
contentDescription = null, contentDescription = null, tint = Color.White, modifier = Modifier.size(22.dp),
tint = Color.White,
modifier = Modifier.size(22.dp),
) )
} }
Spacer(Modifier.width(4.dp)) Spacer(Modifier.width(4.dp))
IconButton(onClick = onSkipNext, modifier = Modifier.size(40.dp)) { IconButton(onClick = onSkipNext, modifier = Modifier.size(40.dp)) {
Icon( Icon(Icons.Default.SkipNext, contentDescription = null, tint = NsOnSurface2, modifier = Modifier.size(24.dp))
Icons.Default.SkipNext,
contentDescription = null,
tint = NsOnSurface2,
modifier = Modifier.size(24.dp),
)
} }
} }
// Progress bar anchored to the bottom of the card
if (state.durationMs > 0) { if (state.durationMs > 0) {
LinearProgressIndicator( LinearProgressIndicator(
progress = { (state.positionMs.toFloat() / state.durationMs).coerceIn(0f, 1f) }, progress = { (state.positionMs.toFloat() / state.durationMs).coerceIn(0f, 1f) },
modifier = Modifier.fillMaxWidth().height(3.dp), modifier = Modifier.fillMaxWidth().height(3.dp),
color = NsAccent, color = NsAccent, trackColor = NsAccent.copy(alpha = 0.15f),
trackColor = NsAccent.copy(alpha = 0.15f),
) )
} }
} }
} }
@Composable
private fun LastSongMiniPlayer(
lastSong: PrefsStore.LastPlayedSong,
coverUrl: String?,
onTap: () -> Unit,
onPlay: () -> Unit,
modifier: Modifier = Modifier,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
.padding(top = 6.dp, bottom = 4.dp)
.shadow(12.dp, RoundedCornerShape(18.dp))
.clip(RoundedCornerShape(18.dp))
.background(NsSurface)
.clickable(onClick = onTap)
.padding(horizontal = 12.dp, vertical = 10.dp),
) {
AsyncImage(
model = coverUrl, contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.size(44.dp).clip(RoundedCornerShape(8.dp)).background(NsSurface2),
)
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(
text = lastSong.title, fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 14.sp, color = NsOnSurface.copy(alpha = 0.7f), maxLines = 1, overflow = TextOverflow.Ellipsis,
)
if (lastSong.artist.isNotBlank()) {
Text(
text = lastSong.artist, fontFamily = Outfit, fontSize = 12.sp,
color = NsOnSurface2.copy(alpha = 0.7f), maxLines = 1, overflow = TextOverflow.Ellipsis,
)
}
}
Box(
Modifier.size(40.dp).clip(CircleShape).background(NsAccent.copy(alpha = 0.6f)).clickable(onClick = onPlay),
contentAlignment = Alignment.Center,
) {
Icon(Icons.Default.PlayArrow, contentDescription = null, tint = Color.White, modifier = Modifier.size(22.dp))
}
}
}
@@ -0,0 +1,200 @@
package com.novasonic.app.ui.component
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.novasonic.app.data.AppNotification
import com.novasonic.app.data.NotificationStore
import com.novasonic.app.ui.theme.*
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import androidx.compose.ui.res.painterResource
import com.novasonic.app.R
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NotificationSheet(
onDismiss: () -> Unit,
onNavigate: (AppNotification) -> Unit = {},
) {
val items by NotificationStore.items.collectAsStateWithLifecycle()
LaunchedEffect(Unit) { NotificationStore.markAllRead() }
ModalBottomSheet(
onDismissRequest = onDismiss,
containerColor = NsSurface,
dragHandle = null,
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(start = 20.dp, end = 8.dp, top = 18.dp, bottom = 12.dp),
) {
Icon(painterResource(R.drawable.ic_honigtopf_brief), null,
tint = NsAccent, modifier = Modifier.size(18.dp))
Spacer(Modifier.width(8.dp))
Text(
"Benachrichtigungen",
fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 16.sp, color = NsOnSurface,
modifier = Modifier.weight(1f),
)
if (items.isNotEmpty()) {
TextButton(onClick = { NotificationStore.clear() }) {
Text("Alle löschen", color = NsOnSurface2, fontFamily = Outfit, fontSize = 12.sp)
}
}
}
HorizontalDivider(color = NsBorder)
if (items.isEmpty()) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxWidth().height(140.dp),
) {
Text("Keine Benachrichtigungen", color = NsOnSurface2, fontFamily = Outfit)
}
} else {
LazyColumn(
contentPadding = PaddingValues(top = 4.dp, bottom = 24.dp),
modifier = Modifier.navigationBarsPadding(),
) {
items(items, key = { it.id }) { n ->
NotifCard(
n = n,
onDelete = { NotificationStore.remove(n.id) },
onNavigate = { onNavigate(n); onDismiss() },
)
}
}
}
}
}
@Composable
private fun NotifCard(n: AppNotification, onDelete: () -> Unit, onNavigate: () -> Unit) {
val hasNav = n.status == "done" && n.navType.isNotBlank()
val navLabel = when (n.navType) {
"playlist" -> "Öffnen →"
else -> "Zum Album →"
}
Column(
modifier = Modifier
.fillMaxWidth()
.background(if (!n.read) NsAccent.copy(alpha = 0.05f) else Color.Transparent),
) {
Row(
verticalAlignment = Alignment.Top,
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 8.dp, top = 12.dp, bottom = if (hasNav) 6.dp else 12.dp),
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(36.dp)
.background(
color = if (n.status == "done") Color(0xFF22C55E).copy(0.15f)
else if (n.status == "error") Color(0xFFEF4444).copy(0.15f)
else NsAccent.copy(0.15f),
shape = RoundedCornerShape(8.dp),
),
) {
Text(
text = when (n.status) {
"done" -> "✓"
"error" -> "✕"
else -> "…"
},
fontSize = 14.sp,
color = when (n.status) {
"done" -> Color(0xFF22C55E)
"error" -> Color(0xFFEF4444)
else -> NsAccent
},
fontWeight = FontWeight.Bold,
)
}
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(
n.title,
fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 14.sp, color = NsOnSurface,
)
if (n.artist.isNotBlank()) {
Text(n.artist, fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
if (n.message.isNotBlank() && n.status != "pending") {
Text(
n.message,
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
modifier = Modifier.padding(top = 2.dp),
)
}
Text(
formatTs(n.timestamp),
fontFamily = Outfit, fontSize = 11.sp, color = NsOnSurface2.copy(alpha = 0.55f),
modifier = Modifier.padding(top = 4.dp),
)
}
if (n.status != "pending") {
IconButton(onClick = onDelete, modifier = Modifier.size(32.dp)) {
Icon(Icons.Default.Close, null, tint = NsOnSurface2, modifier = Modifier.size(16.dp))
}
}
}
if (hasNav) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(start = 64.dp, end = 16.dp, bottom = 12.dp)
.clip(RoundedCornerShape(8.dp))
.background(NsAccent.copy(alpha = 0.12f))
.clickable(onClick = onNavigate)
.padding(horizontal = 12.dp, vertical = 6.dp),
) {
Text(
navLabel,
fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 12.sp, color = NsAccent,
)
Spacer(Modifier.width(4.dp))
Icon(
Icons.AutoMirrored.Filled.ArrowForward, null,
tint = NsAccent, modifier = Modifier.size(13.dp),
)
}
}
HorizontalDivider(
color = NsBorder.copy(alpha = 0.4f),
modifier = Modifier.padding(horizontal = 16.dp),
)
}
}
private val _fmt = SimpleDateFormat("dd.MM. HH:mm", Locale.GERMAN)
private fun formatTs(ts: Long): String = _fmt.format(Date(ts))
@@ -1,19 +1,25 @@
package com.novasonic.app.ui.component package com.novasonic.app.ui.component
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.PlaylistAdd
import androidx.compose.material.icons.automirrored.filled.QueueMusic import androidx.compose.material.icons.automirrored.filled.QueueMusic
import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.novasonic.app.api.model.Playlist import com.novasonic.app.api.model.Playlist
import com.novasonic.app.api.model.Song import com.novasonic.app.api.model.Song
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
@@ -23,6 +29,7 @@ import com.novasonic.app.ui.theme.*
fun PlaylistPickerSheet( fun PlaylistPickerSheet(
song: Song, song: Song,
loadPlaylists: suspend () -> List<Playlist>, loadPlaylists: suspend () -> List<Playlist>,
coverUrl: (String?) -> String?,
onAdd: (Playlist) -> Unit, onAdd: (Playlist) -> Unit,
onCreate: (String) -> Unit, onCreate: (String) -> Unit,
onDismiss: () -> Unit, onDismiss: () -> Unit,
@@ -65,15 +72,19 @@ fun PlaylistPickerSheet(
OutlinedTextField( OutlinedTextField(
value = newName, value = newName,
onValueChange = { newName = it }, onValueChange = { newName = it },
placeholder = { Text("Neue Playlist…", fontSize = 14.sp) }, placeholder = { Text("Neue Playlist…", color = NsOnSurface2, fontSize = 14.sp) },
leadingIcon = { Icon(Icons.AutoMirrored.Filled.PlaylistAdd, null, tint = NsOnSurface2) },
singleLine = true, singleLine = true,
shape = RoundedCornerShape(12.dp),
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
colors = OutlinedTextFieldDefaults.colors( colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = NsAccent, focusedBorderColor = NsAccent,
unfocusedBorderColor = NsBorder, unfocusedBorderColor = NsOnSurface3,
cursorColor = NsAccent, cursorColor = NsAccent,
focusedTextColor = NsOnSurface, focusedTextColor = NsOnSurface,
unfocusedTextColor = NsOnSurface, unfocusedTextColor = NsOnSurface,
focusedContainerColor = NsSurface2,
unfocusedContainerColor = NsSurface2,
), ),
textStyle = androidx.compose.ui.text.TextStyle( textStyle = androidx.compose.ui.text.TextStyle(
fontFamily = Outfit, fontSize = 14.sp, fontFamily = Outfit, fontSize = 14.sp,
@@ -117,8 +128,22 @@ fun PlaylistPickerSheet(
.padding(horizontal = 20.dp, vertical = 14.dp), .padding(horizontal = 20.dp, vertical = 14.dp),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
val cv = coverUrl(pl.coverArt)
Box(
Modifier.size(40.dp).clip(RoundedCornerShape(6.dp)).background(NsSurface2),
contentAlignment = Alignment.Center,
) {
if (cv != null) {
AsyncImage(
model = cv, contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize(),
)
} else {
Icon(Icons.AutoMirrored.Filled.QueueMusic, null, Icon(Icons.AutoMirrored.Filled.QueueMusic, null,
tint = NsOnSurface2, modifier = Modifier.size(20.dp)) tint = NsOnSurface2, modifier = Modifier.size(20.dp))
}
}
Spacer(Modifier.width(14.dp)) Spacer(Modifier.width(14.dp))
Text( Text(
pl.name, pl.name,
@@ -0,0 +1,92 @@
package com.novasonic.app.ui.component
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Pause
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.novasonic.app.player.PreviewState
import com.novasonic.app.ui.theme.*
/**
* Global 30s-preview control bar. Rendered above the MiniPlayer on every screen while a preview
* clip is active, so the user can pause/stop it after navigating away from the album/artist/Explore
* screen it was started on.
*/
@Composable
fun PreviewBar(
state: PreviewState,
onToggle: () -> Unit,
onClose: () -> Unit,
modifier: Modifier = Modifier,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
.padding(top = 6.dp, bottom = 2.dp)
.shadow(10.dp, RoundedCornerShape(16.dp))
.clip(RoundedCornerShape(16.dp))
.background(NsSurface2)
.padding(horizontal = 12.dp, vertical = 8.dp),
) {
AsyncImage(
model = state.artworkUrl, contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.size(38.dp).clip(RoundedCornerShape(7.dp)).background(NsSurface),
)
Spacer(Modifier.width(11.dp))
Column(Modifier.weight(1f)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = "30s Preview", fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 9.sp, color = NsAccent, letterSpacing = 0.5.sp,
)
}
Text(
text = state.title, fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 13.sp, color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis,
)
if (state.artist.isNotBlank()) {
Text(
text = state.artist, fontFamily = Outfit, fontSize = 11.sp,
color = NsOnSurface2, maxLines = 1, overflow = TextOverflow.Ellipsis,
)
}
}
Box(
Modifier.size(36.dp).clip(CircleShape).background(NsAccent).clickable(onClick = onToggle),
contentAlignment = Alignment.Center,
) {
Icon(
imageVector = if (state.isPlaying) Icons.Default.Pause else Icons.Default.PlayArrow,
contentDescription = if (state.isPlaying) "Pause" else "Abspielen",
tint = Color.White, modifier = Modifier.size(20.dp),
)
}
Spacer(Modifier.width(2.dp))
IconButton(onClick = onClose, modifier = Modifier.size(36.dp)) {
Icon(Icons.Default.Close, contentDescription = "Preview beenden", tint = NsOnSurface2, modifier = Modifier.size(20.dp))
}
}
}
@@ -0,0 +1,174 @@
package com.novasonic.app.ui.component
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import kotlin.math.roundToInt
/**
* Rollbalken zum Ziehen fuer eine [LazyListState] — das Gegenstueck zum verbreiterten Balken im Web.
*
* Compose bringt keinen mit: eine LazyColumn zeigt gar nichts an, egal wie lang sie ist. Bei einer
* Playlist mit 2000 Titeln bleibt so nur Wischen, bis der Daumen glueht.
*
* Gerechnet wird in ITEMS, nicht in Pixeln: die tatsaechliche Gesamthoehe einer LazyColumn ist
* unbekannt, solange nicht alles gebaut wurde, und bei unterschiedlich hohen Zeilen laesst sie sich
* auch nicht ausrechnen. Ueber den Anteil sichtbarer an allen Eintraegen stimmt der Balken bei
* gleich hohen Zeilen — und genau die haben Song- und Albumlisten.
*
* Drei Fallen steckten hier drin, alle beim Ziehen:
*
* 1. **Die Greifflaeche muss breiter sein als der sichtbare Balken.** Sichtbar 6 dp, anfassbar
* [griffBreite]. 6 dp am Bildschirmrand trifft mit dem Finger niemand.
* 2. **Der erste Fingerkontakt muss verbraucht werden**, sonst startet die LazyColumn ihre eigene
* Scrollgeste, sobald die Wischschwelle faellt, und der Balken sieht die Bewegung nie.
* 3. **`pointerInput` darf NICHT auf die Geometrie geschluesselt sein.** Genau das war der Grund,
* warum das Ziehen unbrauchbar blieb: die Daumenposition steht in jedem Bild anders da, ein
* Schluessel darauf setzt die Gestenerkennung also mitten in der Geste neu auf — der Finger
* liegt noch auf dem Schirm, die Erkennung faengt aber wieder bei null an. Der Schluessel ist
* deshalb `Unit`; die wechselnden Werte liest die Geste ueber [rememberUpdatedState] zur
* Laufzeit nach.
*
* Gescrollt wird nicht im Zeigerereignis, sondern in einem eigenen Effekt, der [zielPos] verfolgt.
* Ein `launch` pro Fingerbewegung erzeugte bei 2000 Titeln hunderte konkurrierende Scroll-Aufrufe.
*
* Und eine vierte, die erst nach dem Ausliefern auffiel: **nur der Daumen nimmt Beruehrungen an,
* nicht die ganze Spur.** Compose reicht eine Beruehrung nur an das oberste getroffene Element
* weiter — ein Streifen ueber die volle Hoehe verschluckte damit das ⋮ jeder Songzeile, obwohl er
* die Beruehrung gar nicht wollte. Der aeussere Rahmen hat deshalb KEIN `pointerInput` und ist
* dadurch durchlaessig; nur der Daumen selbst hoert zu, mit etwas Luft nach oben und unten.
*/
@Composable
fun Rollbalken(
state: LazyListState,
modifier: Modifier = Modifier,
breite: Dp = 6.dp,
griffBreite: Dp = 24.dp,
minHoehe: Dp = 44.dp,
farbe: Color = Color.White,
) {
val dichte = LocalDensity.current
var spurPx by remember { mutableFloatStateOf(0f) }
var ziehen by remember { mutableStateOf(false) }
// Beim Ziehen fuehrt diese Kommazahl. Wuerde jeder Zeigerschritt aus firstVisibleItemIndex neu
// rechnen, ginge der Rest unterhalb eines ganzen Eintrags jedes Mal verloren — der Balken
// bliebe bei langsamem Ziehen stehen.
var zielPos by remember { mutableFloatStateOf(0f) }
val info = state.layoutInfo
val gesamt = info.totalItemsCount
val zuSehen = info.visibleItemsInfo.size
if (gesamt == 0 || zuSehen == 0 || gesamt <= zuSehen) return
val aktiv = state.isScrollInProgress || ziehen
val alpha by animateFloatAsState(
targetValue = if (aktiv) 0.9f else 0.3f,
animationSpec = tween(if (aktiv) 120 else 450),
label = "rollbalken-alpha",
)
val maxIndex = (gesamt - zuSehen).coerceAtLeast(1)
val minHoehePx = with(dichte) { minHoehe.toPx() }
val daumenPx = (spurPx * zuSehen / gesamt).coerceIn(minHoehePx.coerceAtMost(spurPx), spurPx)
val frei = (spurPx - daumenPx).coerceAtLeast(0f)
val anteil = if (ziehen) zielPos / maxIndex
else state.firstVisibleItemIndex.toFloat() / maxIndex
val daumenY = frei * anteil.coerceIn(0f, 1f)
val spielPx = with(dichte) { 10.dp.toPx() } // Luft ober- und unterhalb des Daumens
// Was die Geste zur Laufzeit braucht — nicht als pointerInput-Schluessel, siehe oben.
val geo = rememberUpdatedState(Geometrie(maxIndex.toFloat(), frei, daumenY, daumenPx, spielPx))
// Die Liste folgt zielPos in EINER Koroutine statt in einer je Fingerbewegung.
LaunchedEffect(ziehen) {
if (!ziehen) return@LaunchedEffect
snapshotFlow { zielPos.roundToInt() }.collect { state.scrollToItem(it) }
}
Box(
modifier
.width(griffBreite)
.fillMaxHeight()
.onSizeChanged { spurPx = it.height.toFloat() }
) {
val luftDp = with(dichte) { spielPx.toDp() }
Box(
Modifier
.align(Alignment.TopEnd)
// Der Greifbereich beginnt eine Spielbreite ueber dem Daumen und ist entsprechend
// hoeher; der sichtbare Balken sitzt durch das Innenmass wieder genau auf daumenY.
.offset { IntOffset(0, (daumenY - spielPx).roundToInt()) }
.width(griffBreite)
.height(with(dichte) { (daumenPx + 2 * spielPx).toDp() })
.pointerInput(Unit) {
awaitEachGesture {
val start = awaitFirstDown(requireUnconsumed = false)
if (geo.value.frei <= 0f) return@awaitEachGesture
start.consume()
zielPos = state.firstVisibleItemIndex.toFloat()
ziehen = true
try {
while (true) {
val ereignis = awaitPointerEvent()
val punkt = ereignis.changes.firstOrNull { it.id == start.id } ?: break
if (!punkt.pressed) break
val delta = punkt.positionChange().y
punkt.consume()
if (delta != 0f) {
val jetzt = geo.value
if (jetzt.frei > 0f) {
zielPos = (zielPos + delta * jetzt.maxIndex / jetzt.frei)
.coerceIn(0f, jetzt.maxIndex)
}
}
}
} finally {
ziehen = false
}
}
}
.padding(vertical = luftDp, horizontal = 0.dp),
contentAlignment = Alignment.CenterEnd,
) {
Box(
Modifier
.padding(end = 2.dp)
.width(breite)
.fillMaxHeight()
.clip(RoundedCornerShape(50))
.background(farbe.copy(alpha = alpha))
)
}
}
}
/** Nur ein Buendel der Werte, die die Geste zur Laufzeit nachliest. */
private data class Geometrie(
val maxIndex: Float,
val frei: Float,
val daumenY: Float,
val daumenPx: Float,
val spiel: Float,
)
@@ -33,9 +33,14 @@ fun SongContextSheet(
onGoToAlbum: (() -> Unit)? = null, onGoToAlbum: (() -> Unit)? = null,
onShowInfo: (() -> Unit)? = null, onShowInfo: (() -> Unit)? = null,
onDownload: (() -> Unit)? = null, onDownload: (() -> Unit)? = null,
onDelete: (() -> Unit)? = null,
onShare: (() -> Unit)? = null,
) { ) {
ModalBottomSheet( ModalBottomSheet(
onDismissRequest = onDismiss, onDismissRequest = onDismiss,
// Open fully expanded so all options (incl. "Herunterladen" at the bottom) are reachable
// right away — no extra drag-up needed.
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
containerColor = NsSurface, containerColor = NsSurface,
dragHandle = { BottomSheetDefaults.DragHandle(color = NsOnSurface2) }, dragHandle = { BottomSheetDefaults.DragHandle(color = NsOnSurface2) },
) { ) {
@@ -74,6 +79,16 @@ fun SongContextSheet(
onGoToAlbum?.let { CtxItem(Icons.Default.Album, "Zum Album", onClick = { onDismiss(); it() }) } onGoToAlbum?.let { CtxItem(Icons.Default.Album, "Zum Album", onClick = { onDismiss(); it() }) }
onShowInfo?.let { CtxItem(Icons.Default.Info, "Song-Info", onClick = { onDismiss(); it() }) } onShowInfo?.let { CtxItem(Icons.Default.Info, "Song-Info", onClick = { onDismiss(); it() }) }
onDownload?.let { CtxItem(Icons.Default.Download, "Herunterladen", onClick = { onDismiss(); it() }) } onDownload?.let { CtxItem(Icons.Default.Download, "Herunterladen", onClick = { onDismiss(); it() }) }
onShare?.let { CtxItem(Icons.Default.Share, "Teilen", onClick = { onDismiss(); it() }) }
}
// Loeschen steht bewusst unten, abgesetzt und rot: es entfernt die Datei unwiderruflich von
// der Platte. Die Sicherheitsabfrage sitzt beim Aufrufer, wie im Web auch.
onDelete?.let {
HorizontalDivider(color = NsBorder, modifier = Modifier.padding(vertical = 4.dp))
CtxItem(Icons.Default.DeleteForever, "Von Festplatte löschen",
tint = MaterialTheme.colorScheme.error,
onClick = { onDismiss(); it() })
} }
Spacer(Modifier.height(24.dp)) Spacer(Modifier.height(24.dp))
@@ -10,6 +10,8 @@ import androidx.compose.material.icons.filled.FavoriteBorder
import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@@ -34,13 +36,19 @@ fun SongRow(
onStarToggle: (() -> Unit)? = null, onStarToggle: (() -> Unit)? = null,
onMore: (() -> Unit)? = null, onMore: (() -> Unit)? = null,
) { ) {
// Reactive star: reflects an optimistic StarState override the instant it's toggled anywhere.
val starOverrides by com.novasonic.app.data.StarState.overrides.collectAsState()
val effectiveStarred = starOverrides[song.id] ?: starred
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.clickable(onClick = onPlay) .clickable(onClick = onPlay)
.background(if (isPlaying) NsAccent.copy(alpha = 0.08f) else Color.Transparent) .background(if (isPlaying) NsAccent.copy(alpha = 0.08f) else Color.Transparent)
.padding(start = if (isPlaying) 0.dp else 4.dp), // Rechts 24 dp frei halten: genau dort liegt der Rollbalken, und ein ⋮ darunter
// waere nicht mehr zu treffen — Compose gibt eine Beruehrung nur an das oberste
// getroffene Element. Gilt ueberall, damit die Zeilen gleich aussehen.
.padding(start = if (isPlaying) 0.dp else 4.dp, end = 24.dp),
) { ) {
// Accent left bar when playing // Accent left bar when playing
if (isPlaying) { if (isPlaying) {
@@ -113,9 +121,9 @@ fun SongRow(
if (onStarToggle != null) { if (onStarToggle != null) {
IconButton(onClick = onStarToggle, modifier = Modifier.size(38.dp)) { IconButton(onClick = onStarToggle, modifier = Modifier.size(38.dp)) {
Icon( Icon(
if (starred) Icons.Default.Favorite else Icons.Default.FavoriteBorder, if (effectiveStarred) Icons.Default.Favorite else Icons.Default.FavoriteBorder,
contentDescription = null, contentDescription = null,
tint = if (starred) NsAccent else NsOnSurface2.copy(alpha = 0.6f), tint = if (effectiveStarred) NsAccent else NsOnSurface2.copy(alpha = 0.6f),
modifier = Modifier.size(17.dp), modifier = Modifier.size(17.dp),
) )
} }
@@ -0,0 +1,951 @@
package com.novasonic.app.ui.screen
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectVerticalDragGestures
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil.compose.AsyncImage
import com.novasonic.app.api.AbsChapter
import com.novasonic.app.api.AbsClient
import com.novasonic.app.api.AbsLibrary
import com.novasonic.app.api.AbsLibraryItem
import com.novasonic.app.player.AbsPlayState
import com.novasonic.app.player.AbsPlayerController
import com.novasonic.app.ui.theme.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
private fun String.stripHtml(): String =
replace(Regex("<[^>]+>"), " ").replace(Regex("\\s+"), " ").trim()
// ── Library list ─────────────────────────────────────────────────────────────
@Composable
fun AbsScreen(
absClient: AbsClient,
onLibraryClick: (AbsLibrary) -> Unit,
) {
val scope = rememberCoroutineScope()
var libraries by remember { mutableStateOf<List<AbsLibrary>>(emptyList()) }
var isLoading by remember { mutableStateOf(true) }
var error by remember { mutableStateOf<String?>(null) }
LaunchedEffect(Unit) {
scope.launch {
isLoading = true
val result = runCatching { absClient.getLibraries() }
if (result.isSuccess) {
libraries = result.getOrDefault(emptyList())
} else {
error = result.exceptionOrNull()?.message ?: "Fehler"
}
isLoading = false
}
}
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 16.dp, vertical = 16.dp)) {
Text(
"Audiobookshelf",
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 24.sp, color = NsOnSurface,
modifier = Modifier.padding(bottom = 16.dp),
)
when {
isLoading -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent)
}
error != null -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(error ?: "Fehler", fontFamily = Outfit, color = MaterialTheme.colorScheme.error)
}
libraries.isEmpty() -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text("Keine Bibliotheken gefunden", fontFamily = Outfit, color = NsOnSurface2)
}
else -> LazyColumn(verticalArrangement = Arrangement.spacedBy(8.dp)) {
items(libraries) { lib ->
LibraryRow(library = lib, onClick = { onLibraryClick(lib) })
}
}
}
}
}
// ── Combined books screen (skips library list, auto-loads first library) ─────
@Composable
fun AbsBooksScreen(
absClient: AbsClient,
onItemClick: (AbsLibraryItem) -> Unit,
) {
var libraries by remember { mutableStateOf<List<AbsLibrary>>(emptyList()) }
var selectedLibIdx by remember { mutableIntStateOf(0) }
var items by remember { mutableStateOf<List<AbsLibraryItem>>(emptyList()) }
var isLoading by remember { mutableStateOf(true) }
var error by remember { mutableStateOf<String?>(null) }
var query by remember { mutableStateOf("") }
// Initial load: fetch libraries + first library's items
LaunchedEffect(Unit) {
isLoading = true
val libs = runCatching { absClient.getLibraries() }.getOrDefault(emptyList())
libraries = libs
val first = libs.firstOrNull() ?: run { isLoading = false; return@LaunchedEffect }
val r = runCatching { absClient.getLibraryItems(first.id).results }
items = r.getOrDefault(emptyList())
error = r.exceptionOrNull()?.message
isLoading = false
}
// Reload when user switches library tab
LaunchedEffect(selectedLibIdx) {
val lib = libraries.getOrNull(selectedLibIdx) ?: return@LaunchedEffect
query = ""
isLoading = true; error = null
items = runCatching { absClient.getLibraryItems(lib.id).results }.getOrDefault(emptyList())
isLoading = false
}
// Debounced search — 400ms after last keystroke
LaunchedEffect(query) {
val lib = libraries.getOrNull(selectedLibIdx) ?: return@LaunchedEffect
if (query.isBlank()) {
isLoading = true; error = null
items = runCatching { absClient.getLibraryItems(lib.id).results }.getOrDefault(emptyList())
isLoading = false
return@LaunchedEffect
}
delay(400)
isLoading = true; error = null
items = runCatching { absClient.searchLibraryItems(lib.id, query) }.getOrDefault(emptyList())
isLoading = false
}
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 16.dp, vertical = 16.dp)) {
Text(
"Hörbücher",
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 24.sp, color = NsOnSurface,
)
Spacer(Modifier.height(10.dp))
// Search bar
OutlinedTextField(
value = query,
onValueChange = { query = it },
placeholder = { Text("Suchen…", fontFamily = Outfit, color = NsOnSurface3) },
leadingIcon = { Icon(Icons.Default.Search, contentDescription = null, tint = NsOnSurface2) },
trailingIcon = if (query.isNotEmpty()) {{
IconButton(onClick = { query = "" }) {
Icon(Icons.Default.Clear, contentDescription = "Löschen", tint = NsOnSurface2)
}
}} else null,
singleLine = true,
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(12.dp),
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = NsAccent,
unfocusedBorderColor = NsBorder,
focusedTextColor = NsOnSurface,
unfocusedTextColor = NsOnSurface,
cursorColor = NsAccent,
focusedContainerColor = NsSurface,
unfocusedContainerColor = NsSurface,
),
)
// Library switcher — only shown when more than one library exists
if (libraries.size > 1) {
Spacer(Modifier.height(10.dp))
Row(
modifier = Modifier.horizontalScroll(rememberScrollState()),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
libraries.forEachIndexed { idx, lib ->
val sel = idx == selectedLibIdx
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.clip(RoundedCornerShape(20.dp))
.background(if (sel) NsAccent else NsSurface)
.clickable { selectedLibIdx = idx }
.padding(horizontal = 14.dp, vertical = 6.dp),
) {
Text(
lib.name, fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 13.sp, color = if (sel) NsBackground else NsOnSurface2,
)
}
}
}
}
Spacer(Modifier.height(12.dp))
when {
isLoading -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent)
}
error != null -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(error ?: "Fehler", fontFamily = Outfit, color = MaterialTheme.colorScheme.error)
}
items.isEmpty() -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(
if (query.isNotBlank()) "Keine Ergebnisse für \"$query\"" else "Keine Bücher gefunden",
fontFamily = Outfit, color = NsOnSurface2,
)
}
else -> LazyColumn(verticalArrangement = Arrangement.spacedBy(8.dp)) {
items(items) { item ->
AbsItemRow(item = item, absClient = absClient, onClick = { onItemClick(item) })
}
}
}
}
}
@Composable
private fun LibraryRow(library: AbsLibrary, onClick: () -> Unit) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
.background(NsSurface)
.clickable(onClick = onClick)
.padding(horizontal = 14.dp, vertical = 14.dp),
) {
Box(
Modifier.size(44.dp).clip(RoundedCornerShape(10.dp)).background(NsAccent.copy(alpha = 0.15f)),
contentAlignment = Alignment.Center,
) {
Icon(Icons.Default.Book, contentDescription = null, tint = NsAccent, modifier = Modifier.size(24.dp))
}
Spacer(Modifier.width(14.dp))
Column(Modifier.weight(1f)) {
Text(
text = library.name, fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 15.sp, color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis,
)
Text(
text = library.mediaType.replaceFirstChar { it.uppercase() },
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
)
}
}
}
// ── Library items list ────────────────────────────────────────────────────────
@Composable
fun AbsLibraryScreen(
absClient: AbsClient,
library: AbsLibrary,
onItemClick: (AbsLibraryItem) -> Unit,
onBack: () -> Unit,
) {
var items by remember { mutableStateOf<List<AbsLibraryItem>>(emptyList()) }
var isLoading by remember { mutableStateOf(true) }
var error by remember { mutableStateOf<String?>(null) }
LaunchedEffect(library.id) {
isLoading = true
val result = runCatching { absClient.getLibraryItems(library.id).results }
if (result.isSuccess) {
items = result.getOrDefault(emptyList())
} else {
error = result.exceptionOrNull()?.message ?: "Fehler"
}
isLoading = false
}
Column(modifier = Modifier.fillMaxSize()) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(horizontal = 8.dp, vertical = 12.dp),
) {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Zurück", tint = NsOnSurface)
}
Text(
library.name, fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 20.sp, color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f),
)
}
when {
isLoading -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent)
}
error != null -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(error ?: "Fehler", fontFamily = Outfit, color = MaterialTheme.colorScheme.error)
}
items.isEmpty() -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text("Keine Bücher gefunden", fontFamily = Outfit, color = NsOnSurface2)
}
else -> LazyColumn(
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
items(items) { item ->
AbsItemRow(item = item, absClient = absClient, onClick = { onItemClick(item) })
}
}
}
}
}
@Composable
private fun AbsItemRow(item: AbsLibraryItem, absClient: AbsClient, onClick: () -> Unit) {
val meta = item.media.metadata
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
.background(NsSurface)
.clickable(onClick = onClick)
.padding(10.dp),
) {
AsyncImage(
model = absClient.coverUrl(item.id),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.size(56.dp).clip(RoundedCornerShape(8.dp)).background(NsSurface2),
)
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(
text = meta.title ?: item.id,
fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 14.sp, color = NsOnSurface, maxLines = 2, overflow = TextOverflow.Ellipsis,
)
if (!meta.authorName.isNullOrBlank()) {
Text(
text = meta.authorName, fontFamily = Outfit,
fontSize = 12.sp, color = NsOnSurface2, maxLines = 1, overflow = TextOverflow.Ellipsis,
)
}
val durationMin = (item.media.duration / 60).toInt()
if (durationMin > 0) {
Text(
text = "${durationMin / 60}h ${durationMin % 60}m",
fontFamily = Outfit, fontSize = 11.sp, color = NsOnSurface2.copy(alpha = 0.7f),
)
}
}
Icon(
Icons.Default.ChevronRight, contentDescription = null,
tint = NsOnSurface2, modifier = Modifier.size(20.dp),
)
}
}
// ── Book detail ───────────────────────────────────────────────────────────────
@Composable
fun AbsBookDetailScreen(
absClient: AbsClient,
libraryItem: AbsLibraryItem,
absPlayerController: AbsPlayerController,
onPlay: () -> Unit,
onBack: () -> Unit,
) {
val scope = rememberCoroutineScope()
var chapters by remember { mutableStateOf(libraryItem.media.chapters) }
var progress by remember { mutableStateOf<Double?>(null) }
var isLoadingDetail by remember { mutableStateOf(libraryItem.media.chapters.isEmpty()) }
var isStartingPlay by remember { mutableStateOf(false) }
LaunchedEffect(libraryItem.id) {
if (chapters.isEmpty()) {
isLoadingDetail = true
chapters = runCatching { absClient.getItemChapters(libraryItem.id) }.getOrDefault(emptyList())
isLoadingDetail = false
}
progress = runCatching { absClient.getProgress(libraryItem.id)?.currentTime }.getOrNull()
}
val meta = libraryItem.media.metadata
val duration = libraryItem.media.duration
val progressPct = if (duration > 0 && (progress ?: 0.0) > 0) ((progress!! / duration) * 100).toInt() else 0
Column(modifier = Modifier.fillMaxSize()) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(horizontal = 8.dp, vertical = 12.dp),
) {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Zurück", tint = NsOnSurface)
}
Text(
meta.title ?: "Hörbuch", fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 18.sp, color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f),
)
}
LazyColumn(
contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = 24.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
// Header
item(key = "header") {
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
AsyncImage(
model = absClient.coverUrl(libraryItem.id),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.size(120.dp).clip(RoundedCornerShape(12.dp)).background(NsSurface2),
)
Column(Modifier.weight(1f)) {
Text(
text = meta.title ?: "Unbekannt",
fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 16.sp, color = NsOnSurface,
)
if (!meta.authorName.isNullOrBlank()) {
Spacer(Modifier.height(4.dp))
Text(
text = meta.authorName, fontFamily = Outfit,
fontSize = 13.sp, color = NsOnSurface2,
)
}
if (duration > 0) {
Spacer(Modifier.height(4.dp))
val h = (duration / 3600).toInt()
val m = ((duration % 3600) / 60).toInt()
Text(
text = if (h > 0) "${h}h ${m}m" else "${m}m",
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
)
}
if (progressPct in 1..98) {
Spacer(Modifier.height(8.dp))
LinearProgressIndicator(
progress = { progressPct / 100f },
modifier = Modifier.fillMaxWidth().height(4.dp).clip(RoundedCornerShape(2.dp)),
color = NsAccent, trackColor = NsAccent.copy(alpha = 0.2f),
)
Spacer(Modifier.height(2.dp))
Text(
text = "$progressPct% gehört",
fontFamily = Outfit, fontSize = 11.sp, color = NsOnSurface2,
)
}
}
}
}
// Play button
item(key = "play") {
Button(
onClick = {
isStartingPlay = true
scope.launch {
runCatching { absPlayerController.playItem(libraryItem, absClient) }
isStartingPlay = false
onPlay()
}
},
enabled = !isStartingPlay,
modifier = Modifier.fillMaxWidth().height(48.dp),
colors = ButtonDefaults.buttonColors(containerColor = NsAccent, contentColor = NsBackground),
) {
if (isStartingPlay) {
CircularProgressIndicator(modifier = Modifier.size(20.dp), strokeWidth = 2.dp, color = NsBackground)
} else {
Icon(Icons.Default.PlayArrow, contentDescription = null, modifier = Modifier.size(20.dp))
Spacer(Modifier.width(8.dp))
Text(
if (progressPct > 5) "Weiterhören" else "Abspielen",
fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 15.sp,
)
}
}
}
// Description (strip HTML tags from ABS markdown/HTML content)
if (!meta.description.isNullOrBlank()) {
item(key = "desc") {
Text(
text = meta.description.stripHtml(),
fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface2,
lineHeight = 20.sp,
)
}
}
// Chapters
if (chapters.isNotEmpty()) {
item(key = "chHeader") {
Text(
"Kapitel (${chapters.size})",
fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 14.sp, color = NsOnSurface,
)
}
itemsIndexed(chapters, key = { idx, _ -> "ch_$idx" }) { idx, ch ->
ChapterDetailRow(
chapter = ch,
index = idx + 1,
onTap = {
scope.launch {
isStartingPlay = true
runCatching {
absPlayerController.playItem(libraryItem, absClient)
absPlayerController.seekToGlobal(ch.start)
}
isStartingPlay = false
onPlay()
}
},
)
}
} else if (isLoadingDetail) {
item(key = "chLoading") {
Box(Modifier.fillMaxWidth().padding(16.dp), contentAlignment = Alignment.Center) {
CircularProgressIndicator(modifier = Modifier.size(24.dp), color = NsAccent)
}
}
}
}
}
}
@Composable
private fun ChapterDetailRow(chapter: AbsChapter, index: Int, onTap: () -> Unit) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(8.dp))
.background(NsSurface)
.clickable(onClick = onTap)
.padding(horizontal = 12.dp, vertical = 10.dp),
) {
Text(
text = "$index",
fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 12.sp, color = NsAccent,
modifier = Modifier.width(28.dp),
)
Text(
text = chapter.title.ifBlank { "Kapitel $index" },
fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface,
modifier = Modifier.weight(1f),
maxLines = 2, overflow = TextOverflow.Ellipsis,
)
Text(
text = fmtSecs(chapter.start),
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
)
}
}
// ── ABS Now Playing overlay ───────────────────────────────────────────────────
@Composable
fun AbsNowPlayingScreen(
absPlayerController: AbsPlayerController,
absClient: AbsClient,
onDismiss: () -> Unit,
) {
val state by absPlayerController.state.collectAsStateWithLifecycle()
Box(
modifier = Modifier
.fillMaxSize()
.background(NsBackground)
.pointerInput(Unit) {
detectVerticalDragGestures { _, delta -> if (delta > 80f) onDismiss() }
},
) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
// Top bar
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(top = 16.dp),
) {
IconButton(onClick = onDismiss) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Schließen", tint = NsOnSurface)
}
Text(
"Wird abgespielt", fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 14.sp, color = NsOnSurface2,
modifier = Modifier.weight(1f), textAlign = TextAlign.Center,
)
Spacer(Modifier.width(48.dp))
}
Spacer(Modifier.height(20.dp))
// Cover
AsyncImage(
model = state.item?.let { absClient.coverUrl(it.id) },
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.size(220.dp)
.clip(RoundedCornerShape(16.dp))
.background(NsSurface2),
)
Spacer(Modifier.height(20.dp))
// Title / Author / Chapter
val meta = state.item?.media?.metadata
Text(
text = meta?.title ?: "Unbekannt",
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 18.sp, color = NsOnSurface,
maxLines = 2, overflow = TextOverflow.Ellipsis, textAlign = TextAlign.Center,
)
if (!meta?.authorName.isNullOrBlank()) {
Spacer(Modifier.height(4.dp))
Text(
text = meta?.authorName ?: "",
fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface2, textAlign = TextAlign.Center,
)
}
val currentChapter = state.chapters.getOrNull(state.chapterIdx)
if (currentChapter != null && currentChapter.title.isNotBlank()) {
Spacer(Modifier.height(4.dp))
Text(
text = currentChapter.title,
fontFamily = Outfit, fontSize = 12.sp, color = NsAccent, textAlign = TextAlign.Center,
maxLines = 1, overflow = TextOverflow.Ellipsis,
)
}
Spacer(Modifier.height(20.dp))
// Progress bar
val chWin = chapterWindow(state)
val dispCur = if (chWin != null) (state.currentTime - chWin.first).coerceAtLeast(0.0) else state.currentTime
val dispDur = if (chWin != null) chWin.second - chWin.first else state.duration
val progress = if (dispDur > 0) (dispCur / dispDur).coerceIn(0.0, 1.0).toFloat() else 0f
Slider(
value = progress,
onValueChange = { v ->
val globalTarget = if (chWin != null) chWin.first + v * (chWin.second - chWin.first)
else v * state.duration
absPlayerController.seekToGlobal(globalTarget)
},
modifier = Modifier.fillMaxWidth(),
colors = SliderDefaults.colors(
thumbColor = NsAccent, activeTrackColor = NsAccent,
inactiveTrackColor = NsAccent.copy(alpha = 0.2f),
),
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text(fmtSecs(dispCur), fontFamily = Outfit, fontSize = 11.sp, color = NsOnSurface2)
Text("-${fmtSecs(dispDur - dispCur)}", fontFamily = Outfit, fontSize = 11.sp, color = NsOnSurface2)
}
Spacer(Modifier.height(12.dp))
// Controls
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceEvenly,
modifier = Modifier.fillMaxWidth(),
) {
IconButton(onClick = { absPlayerController.prevChapter() }) {
Icon(Icons.Default.SkipPrevious, contentDescription = "Voriges Kapitel", tint = NsOnSurface, modifier = Modifier.size(30.dp))
}
IconButton(onClick = { absPlayerController.skipSecs(-30.0) }) {
Icon(Icons.Default.Replay30, contentDescription = "-30s", tint = NsOnSurface, modifier = Modifier.size(30.dp))
}
Box(
Modifier.size(64.dp).clip(CircleShape).background(NsAccent)
.clickable { absPlayerController.togglePlay() },
contentAlignment = Alignment.Center,
) {
Icon(
if (state.isPlaying) Icons.Default.Pause else Icons.Default.PlayArrow,
contentDescription = null, tint = NsBackground, modifier = Modifier.size(34.dp),
)
}
IconButton(onClick = { absPlayerController.skipSecs(30.0) }) {
Icon(Icons.Default.Forward30, contentDescription = "+30s", tint = NsOnSurface, modifier = Modifier.size(30.dp))
}
IconButton(onClick = { absPlayerController.nextChapter() }) {
Icon(Icons.Default.SkipNext, contentDescription = "Nächstes Kapitel", tint = NsOnSurface, modifier = Modifier.size(30.dp))
}
}
Spacer(Modifier.height(12.dp))
// Speed + Sleep + Chapter track row
AbsBottomControls(state = state, absPlayerController = absPlayerController)
Spacer(Modifier.height(16.dp))
// Chapter list
if (state.chapters.isNotEmpty()) {
AbsChapterList(
state = state,
absPlayerController = absPlayerController,
modifier = Modifier.weight(1f),
)
}
}
// Loading overlay
if (state.isLoading) {
Box(Modifier.fillMaxSize().background(NsBackground.copy(alpha = 0.7f)), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent)
}
}
}
}
@Composable
private fun AbsBottomControls(state: AbsPlayState, absPlayerController: AbsPlayerController) {
var showSpeedPicker by remember { mutableStateOf(false) }
var showSleepPicker by remember { mutableStateOf(false) }
var showCustomSleepDialog by remember { mutableStateOf(false) }
var customMinutesText by remember { mutableStateOf("") }
val speedOptions = listOf(0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 2.0f)
val sleepOptions = listOf(5 to "5 min", 10 to "10 min", 15 to "15 min", 30 to "30 min", 60 to "1 Stunde")
if (showCustomSleepDialog) {
AlertDialog(
onDismissRequest = { showCustomSleepDialog = false },
title = { Text("Sleep Timer", fontFamily = Outfit, fontWeight = FontWeight.Bold) },
text = {
Column {
Text("Minuten eingeben:", fontFamily = Outfit, fontSize = 14.sp, color = NsOnSurface2)
Spacer(Modifier.height(8.dp))
OutlinedTextField(
value = customMinutesText,
onValueChange = { v -> if (v.all { it.isDigit() } && v.length <= 4) customMinutesText = v },
label = { Text("Minuten", fontFamily = Outfit) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
singleLine = true,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = NsAccent, focusedLabelColor = NsAccent, cursorColor = NsAccent,
unfocusedBorderColor = NsOnSurface3, focusedTextColor = NsOnSurface, unfocusedTextColor = NsOnSurface,
),
)
}
},
confirmButton = {
TextButton(onClick = {
val mins = customMinutesText.toIntOrNull()
if (mins != null && mins > 0) absPlayerController.setSleepTimer(mins)
showCustomSleepDialog = false
}) { Text("Starten", color = NsAccent, fontFamily = Outfit) }
},
dismissButton = {
TextButton(onClick = { showCustomSleepDialog = false }) {
Text("Abbrechen", fontFamily = Outfit, color = NsOnSurface2)
}
},
containerColor = NsSurface,
)
}
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth(),
) {
// Speed
Box(Modifier.weight(1f), contentAlignment = Alignment.Center) {
TextButton(onClick = { showSpeedPicker = !showSpeedPicker; showSleepPicker = false }) {
Text(
"${state.speed}×",
fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 14.sp,
color = if (state.speed != 1f) NsAccent else NsOnSurface2,
)
}
DropdownMenu(
expanded = showSpeedPicker,
onDismissRequest = { showSpeedPicker = false },
containerColor = NsSurface2,
) {
speedOptions.forEach { s ->
DropdownMenuItem(
text = { Text("${s}×", fontFamily = Outfit, color = if (s == state.speed) NsAccent else NsOnSurface) },
onClick = { absPlayerController.setSpeed(s); showSpeedPicker = false },
)
}
}
}
// Sleep timer
Box(Modifier.weight(1f), contentAlignment = Alignment.Center) {
val sleepRem = state.sleepRemainingSecs
TextButton(onClick = { showSleepPicker = !showSleepPicker; showSpeedPicker = false }) {
Icon(
Icons.Default.Bedtime, contentDescription = "Sleep Timer",
tint = if (sleepRem != null) NsAccent else NsOnSurface2,
modifier = Modifier.size(18.dp),
)
if (sleepRem != null) {
Spacer(Modifier.width(4.dp))
val m = sleepRem / 60
val s = (sleepRem % 60).toString().padStart(2, '0')
Text("$m:$s", fontFamily = Outfit, fontSize = 13.sp, color = NsAccent)
}
}
DropdownMenu(
expanded = showSleepPicker,
onDismissRequest = { showSleepPicker = false },
containerColor = NsSurface2,
) {
if (state.sleepRemainingSecs != null) {
DropdownMenuItem(
text = { Text("Abbrechen", fontFamily = Outfit, color = MaterialTheme.colorScheme.error) },
onClick = { absPlayerController.cancelSleep(); showSleepPicker = false },
)
}
sleepOptions.forEach { (mins, label) ->
DropdownMenuItem(
text = { Text(label, fontFamily = Outfit, color = NsOnSurface) },
onClick = { absPlayerController.setSleepTimer(mins); showSleepPicker = false },
)
}
DropdownMenuItem(
text = { Text("Benutzerdefiniert…", fontFamily = Outfit, color = NsOnSurface) },
onClick = { showSleepPicker = false; customMinutesText = ""; showCustomSleepDialog = true },
)
}
}
// Chapter track mode toggle
Box(Modifier.weight(1f), contentAlignment = Alignment.Center) {
TextButton(onClick = { absPlayerController.setChapterTrackMode(!state.chapterTrackMode) }) {
Icon(
Icons.Default.Bookmark, contentDescription = "Kapitel-Modus",
tint = if (state.chapterTrackMode) NsAccent else NsOnSurface2,
modifier = Modifier.size(18.dp),
)
Spacer(Modifier.width(4.dp))
Text(
"Kapitel", fontFamily = Outfit, fontSize = 12.sp,
color = if (state.chapterTrackMode) NsAccent else NsOnSurface2,
)
}
}
}
}
@Composable
private fun AbsChapterList(
state: AbsPlayState,
absPlayerController: AbsPlayerController,
modifier: Modifier = Modifier,
) {
val listState = rememberLazyListState()
LaunchedEffect(state.chapterIdx) {
if (state.chapters.isNotEmpty()) {
listState.animateScrollToItem(state.chapterIdx.coerceAtLeast(0))
}
}
Column(modifier = modifier) {
Text(
"Kapitel",
fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 13.sp, color = NsOnSurface2,
modifier = Modifier.padding(bottom = 6.dp),
)
HorizontalDivider(color = NsBorder)
LazyColumn(state = listState, modifier = Modifier.fillMaxSize()) {
itemsIndexed(state.chapters) { idx, ch ->
val isActive = idx == state.chapterIdx
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.background(if (isActive) NsAccent.copy(alpha = 0.08f) else androidx.compose.ui.graphics.Color.Transparent)
.clickable { absPlayerController.seekToChapter(idx) }
.padding(horizontal = 4.dp, vertical = 10.dp),
) {
Text(
"${idx + 1}",
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 11.sp,
color = if (isActive) NsAccent else NsOnSurface2,
modifier = Modifier.width(28.dp),
)
Text(
ch.title.ifBlank { "Kapitel ${idx + 1}" },
fontFamily = Outfit, fontSize = 13.sp,
color = if (isActive) NsAccent else NsOnSurface,
modifier = Modifier.weight(1f),
maxLines = 1, overflow = TextOverflow.Ellipsis,
)
Text(
fmtSecs(ch.start),
fontFamily = Outfit, fontSize = 11.sp, color = NsOnSurface2,
)
}
HorizontalDivider(color = NsBorder.copy(alpha = 0.4f))
}
}
}
}
// ── Helpers ───────────────────────────────────────────────────────────────────
private fun chapterWindow(state: AbsPlayState): Pair<Double, Double>? {
if (!state.chapterTrackMode || state.chapters.isEmpty()) return null
val ch = state.chapters.getOrNull(state.chapterIdx) ?: return null
val next = state.chapters.getOrNull(state.chapterIdx + 1)
val end = next?.start ?: ch.end.takeIf { it > ch.start } ?: state.duration
if (end <= ch.start) return null
return Pair(ch.start, end)
}
internal fun fmtSecs(secs: Double): String {
val s = secs.toLong().coerceAtLeast(0)
val h = s / 3600
val m = (s % 3600) / 60
val sec = s % 60
return if (h > 0) "$h:${m.toString().padStart(2, '0')}:${sec.toString().padStart(2, '0')}"
else "$m:${sec.toString().padStart(2, '0')}"
}
@@ -4,11 +4,17 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Download
import com.novasonic.app.data.StarState
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.FavoriteBorder
import androidx.compose.material.icons.filled.PlayArrow import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.Shuffle import androidx.compose.material.icons.filled.Shuffle
import androidx.compose.material3.* import androidx.compose.material3.*
@@ -32,6 +38,8 @@ import com.novasonic.app.player.PlayerState
import com.novasonic.app.ui.component.SongRow import com.novasonic.app.ui.component.SongRow
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.AlbumViewModel import com.novasonic.app.viewmodel.AlbumViewModel
import com.novasonic.app.ui.component.Rollbalken
import com.novasonic.app.ui.formatGesamtdauer
@Composable @Composable
fun AlbumScreen( fun AlbumScreen(
@@ -45,6 +53,8 @@ fun AlbumScreen(
) { ) {
val vm: AlbumViewModel = viewModel() val vm: AlbumViewModel = viewModel()
val state by vm.state.collectAsStateWithLifecycle() val state by vm.state.collectAsStateWithLifecycle()
val downloadGroup by vm.downloadGroup.collectAsStateWithLifecycle()
val isDownloading by vm.isDownloading.collectAsStateWithLifecycle()
if (state.isLoading) { if (state.isLoading) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
@@ -68,7 +78,9 @@ fun AlbumScreen(
return return
} }
LazyColumn(Modifier.fillMaxSize()) { val listState = rememberLazyListState()
Box(Modifier.fillMaxSize()) {
LazyColumn(Modifier.fillMaxSize(), state = listState) {
item { item {
// ── Hero ───────────────────────────────────────────────────────── // ── Hero ─────────────────────────────────────────────────────────
Box(Modifier.fillMaxWidth()) { Box(Modifier.fillMaxWidth()) {
@@ -137,6 +149,7 @@ fun AlbumScreen(
album.year?.toString(), album.year?.toString(),
album.genre?.takeIf { it.isNotBlank() }, album.genre?.takeIf { it.isNotBlank() },
if (album.songCount > 0) "${album.songCount} Songs" else null, if (album.songCount > 0) "${album.songCount} Songs" else null,
if (album.duration > 0) formatGesamtdauer(album.duration) else null,
).joinToString(" · ") ).joinToString(" · ")
if (meta.isNotBlank()) { if (meta.isNotBlank()) {
Spacer(Modifier.height(3.dp)) Spacer(Modifier.height(3.dp))
@@ -148,7 +161,12 @@ fun AlbumScreen(
} }
} }
// ── Play / Shuffle row ──────────────────────────────────────────── // ── Play / Shuffle / Merken / Download ────────────────────────────
// Gleiche Leiste wie beim Playlist-Detail: vier gleich breite, reine Symbolknoepfe.
// Play und Shuffle trugen hier noch Beschriftungen, waehrend Herz und Download fest
// 46 dp breit waren — die Reihe war dadurch ungleich geteilt und die Schrift wurde auf
// schmalen Geraeten abgeschnitten. Play bleibt gefuellt als Hauptaktion; die uebrigen
// sind umrandet und faerben sich erst accent, wenn sie aktiv sind.
Row( Row(
Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 12.dp), Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp), horizontalArrangement = Arrangement.spacedBy(10.dp),
@@ -158,20 +176,56 @@ fun AlbumScreen(
modifier = Modifier.weight(1f).height(46.dp), modifier = Modifier.weight(1f).height(46.dp),
colors = ButtonDefaults.buttonColors(containerColor = NsAccent, contentColor = Color.White), colors = ButtonDefaults.buttonColors(containerColor = NsAccent, contentColor = Color.White),
shape = RoundedCornerShape(14.dp), shape = RoundedCornerShape(14.dp),
contentPadding = PaddingValues(0.dp),
) { ) {
Icon(Icons.Default.PlayArrow, null, modifier = Modifier.size(20.dp)) Icon(Icons.Default.PlayArrow, "Abspielen", modifier = Modifier.size(22.dp))
Spacer(Modifier.width(6.dp))
Text("Play", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp)
} }
OutlinedButton( OutlinedButton(
onClick = { onPlay(album.song.shuffled(), 0) }, onClick = { onPlay(album.song, -1) }, // -1 = gemischt, der Player mischt
modifier = Modifier.weight(1f).height(46.dp), modifier = Modifier.weight(1f).height(46.dp),
border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(brush = SolidColor(NsAccent.copy(alpha = 0.55f))), border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(brush = SolidColor(NsAccent.copy(alpha = 0.55f))),
shape = RoundedCornerShape(14.dp), shape = RoundedCornerShape(14.dp),
contentPadding = PaddingValues(0.dp),
) { ) {
Icon(Icons.Default.Shuffle, null, modifier = Modifier.size(20.dp), tint = NsAccent) Icon(Icons.Default.Shuffle, "Zufällig abspielen", modifier = Modifier.size(20.dp), tint = NsAccent)
Spacer(Modifier.width(6.dp)) }
Text("Shuffle", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp, color = NsAccent) // Album merken — derselbe Weg wie beim Song: Navidrome behandelt Song-, Album- und
// Kuenstler-IDs beim Markieren gleich.
val overrides by StarState.overrides.collectAsStateWithLifecycle()
val gemerkt = overrides[album.id] ?: (album.starred != null)
OutlinedButton(
onClick = { vm.merkenUmschalten(album.id, album.starred != null) },
modifier = Modifier.weight(1f).height(46.dp),
border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(
brush = SolidColor(if (gemerkt) NsAccent else NsOnSurface3)
),
shape = RoundedCornerShape(14.dp),
contentPadding = PaddingValues(0.dp),
) {
Icon(
if (gemerkt) Icons.Filled.Favorite else Icons.Filled.FavoriteBorder,
if (gemerkt) "Gemerkt" else "Album merken",
Modifier.size(20.dp), tint = if (gemerkt) NsAccent else NsOnSurface2,
)
}
val isFullyDownloaded = downloadGroup != null &&
downloadGroup!!.downloadedTracks >= downloadGroup!!.totalTracks &&
downloadGroup!!.totalTracks > 0
OutlinedButton(
// Tappable unless fully done — resumes / re-downloads any missing songs.
onClick = { if (!isFullyDownloaded) vm.downloadAlbum() },
modifier = Modifier.weight(1f).height(46.dp),
border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(
brush = SolidColor(if (isFullyDownloaded) NsAccent else NsOnSurface3)
),
shape = RoundedCornerShape(14.dp),
contentPadding = PaddingValues(0.dp),
) {
when {
isFullyDownloaded -> Icon(Icons.Default.CheckCircle, "Offline verfügbar", Modifier.size(20.dp), tint = NsAccent)
isDownloading -> CircularProgressIndicator(Modifier.size(18.dp), color = NsAccent, strokeWidth = 2.dp)
else -> Icon(Icons.Default.Download, "Herunterladen", Modifier.size(20.dp), tint = NsOnSurface2)
}
} }
} }
@@ -192,4 +246,10 @@ fun AlbumScreen(
} }
item { Spacer(Modifier.height(16.dp)) } item { Spacer(Modifier.height(16.dp)) }
} }
Rollbalken(
state = listState,
modifier = Modifier.align(Alignment.CenterEnd).padding(vertical = 4.dp),
farbe = NsOnSurface2,
)
}
} }
@@ -10,15 +10,27 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items as gridItems
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material.icons.filled.Event
import com.novasonic.app.data.StarState
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.FavoriteBorder
import androidx.compose.material.icons.filled.PlayArrow import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Shuffle import androidx.compose.material.icons.filled.Shuffle
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@@ -34,12 +46,15 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.novasonic.app.api.model.Song import com.novasonic.app.api.model.Song
import com.novasonic.app.api.model.fmtFanCount
import com.novasonic.app.player.PlayerState import com.novasonic.app.player.PlayerState
import com.novasonic.app.ui.component.AlbumCard import com.novasonic.app.ui.component.AlbumCard
import com.novasonic.app.ui.component.ConcertsSheet
import com.novasonic.app.ui.component.ItunesDownloadSheet import com.novasonic.app.ui.component.ItunesDownloadSheet
import com.novasonic.app.ui.component.SongRow import com.novasonic.app.ui.component.SongRow
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.ArtistViewModel import com.novasonic.app.viewmodel.ArtistViewModel
import kotlinx.coroutines.launch
@Composable @Composable
fun ArtistDetailScreen( fun ArtistDetailScreen(
@@ -49,15 +64,45 @@ fun ArtistDetailScreen(
onAlbumClick: (com.novasonic.app.api.model.Album) -> Unit, onAlbumClick: (com.novasonic.app.api.model.Album) -> Unit,
onStarToggle: (Song) -> Unit, onStarToggle: (Song) -> Unit,
onShowContextMenu: ((Song) -> Unit)? = null, onShowContextMenu: ((Song) -> Unit)? = null,
onArtistClick: ((String) -> Unit)? = null,
onBack: () -> Unit, onBack: () -> Unit,
) { ) {
val vm: ArtistViewModel = viewModel() val vm: ArtistViewModel = viewModel()
val state by vm.state.collectAsStateWithLifecycle() val state by vm.state.collectAsStateWithLifecycle()
val context = LocalContext.current val context = LocalContext.current
val scope = rememberCoroutineScope()
BackHandler(enabled = state.partialAlbum != null) { vm.dismissPartialAlbum() } BackHandler(enabled = state.partialAlbum != null) { vm.dismissPartialAlbum() }
BackHandler(enabled = state.subAlbumItem != null && state.partialAlbum == null) { vm.dismissSubAlbum() } BackHandler(enabled = state.subAlbumItem != null && state.partialAlbum == null) { vm.dismissSubAlbum() }
// Which "all albums" section is expanded (by title), or null. rememberSaveable so it survives
// navigating into an album and back — otherwise back would land on the collapsed artist page.
var openAllAlbums by rememberSaveable { mutableStateOf<String?>(null) }
val showAllAlbums = openAllAlbums != null
BackHandler(enabled = showAllAlbums && state.partialAlbum == null && state.subAlbumItem == null) {
openAllAlbums = null
}
LaunchedEffect(state.pendingShufflePlay) {
state.pendingShufflePlay?.let { songs ->
onPlay(songs, -1) // -1 = gemischt starten, der Player mischt
vm.consumeShufflePlay()
}
}
// Concerts sheet
if (state.showEventsSheet) {
val artist = state.artist
if (artist != null) {
ConcertsSheet(
artistName = artist.name,
events = state.events,
onDismiss = vm::dismissEventsSheet,
eventsError = state.eventsError,
)
}
}
// Download sheet // Download sheet
state.downloadSheetItem?.let { item -> state.downloadSheetItem?.let { item ->
ItunesDownloadSheet( ItunesDownloadSheet(
@@ -72,6 +117,22 @@ fun ArtistDetailScreen(
) )
} }
// Artist-pin picker
if (state.showPinPicker) {
ArtistPinSheet(
artistName = state.artist?.name ?: "",
pinned = state.pin,
searching = state.pinSearching,
candidates = state.pinCandidates,
onPick = vm::pinCandidate,
onPinLink = { link -> vm.pinByLink(link) { ok ->
if (!ok) Toast.makeText(context, "Deezer-Künstler nicht gefunden", Toast.LENGTH_SHORT).show()
} },
onClear = vm::clearPin,
onDismiss = vm::dismissPinPicker,
)
}
if (state.isLoading) { if (state.isLoading) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent) CircularProgressIndicator(color = NsAccent)
@@ -98,6 +159,7 @@ fun ArtistDetailScreen(
onPreview = vm::togglePreview, onPreview = vm::togglePreview,
onDownload = vm::showDownloadSheet, onDownload = vm::showDownloadSheet,
onBack = vm::dismissPartialAlbum, onBack = vm::dismissPartialAlbum,
onShowContextMenu = onShowContextMenu,
) )
return return
} }
@@ -127,7 +189,43 @@ fun ArtistDetailScreen(
// Album categories (computed once iTunes data arrives) // Album categories (computed once iTunes data arrives)
val cats = if (state.iAlbums.isNotEmpty()) categorizeAlbums(artist.album, state.iAlbums) else null val cats = if (state.iAlbums.isNotEmpty()) categorizeAlbums(artist.album, state.iAlbums) else null
LazyColumn(Modifier.fillMaxSize()) { // Rebuild the overlay entries from the (surviving) categorized albums for whichever section is
// open. Derived — not stored — so it's correct after returning from an album.
val allAlbumEntries: List<AllAlbumEntry> = when (openAllAlbums) {
"In Library" -> cats?.downloaded?.map { (nd, _) ->
AllAlbumEntry(name = nd.name, year = nd.year?.toString(), artUrl = coverUrl(nd.coverArt), onClick = { onAlbumClick(nd) })
}.orEmpty()
"Unvollständig" -> cats?.partial?.map { (nd, ia, counts) ->
AllAlbumEntry(
name = nd.name, year = nd.year?.toString(),
artUrl = ia.artworkUrl100?.replace("100x100bb", "300x300bb") ?: coverUrl(nd.coverArt),
badge = "${counts.first}/${counts.second}",
onClick = { vm.loadPartialAlbum(nd, ia) }, onDownload = { vm.showDownloadSheet(ia) },
)
}.orEmpty()
"Nicht heruntergeladen" -> cats?.notDownloaded?.map { ia ->
AllAlbumEntry(
name = ia.collectionName ?: "—", year = ia.releaseDate?.take(4),
artUrl = ia.artworkUrl100?.replace("100x100bb", "300x300bb"), dimmed = true,
onClick = { vm.loadSubAlbum(ia) }, onDownload = { vm.showDownloadSheet(ia) },
)
}.orEmpty()
else -> emptyList()
}
if (showAllAlbums) {
AllAlbumsOverlay(
title = openAllAlbums ?: "",
entries = allAlbumEntries,
onBack = { openAllAlbums = null },
gridState = vm.allAlbumsGrid,
query = vm.allAlbumsQuery.value,
onQueryChange = { vm.allAlbumsQuery.value = it },
)
return
}
LazyColumn(state = vm.pageListState, modifier = Modifier.fillMaxSize()) {
// Back link // Back link
item { item {
Row( Row(
@@ -146,7 +244,10 @@ fun ArtistDetailScreen(
// Hero card // Hero card
item { item {
val imgUrl = state.info?.largeImageUrl?.takeIf { it.isNotBlank() } // A pin's Deezer picture wins over the Last.fm image (fixes same-name artists whose
// Navidrome/Last.fm image is the wrong person).
val imgUrl = state.pinnedImage?.takeIf { it.isNotBlank() }
?: state.info?.largeImageUrl?.takeIf { it.isNotBlank() }
?: coverUrl(artist.coverArt) ?: coverUrl(artist.coverArt)
Box( Box(
Modifier Modifier
@@ -162,6 +263,38 @@ fun ArtistDetailScreen(
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
) )
// Folgen gehoert an den Kuenstler, nicht in die Aktionsleiste darunter: die Leiste
// ist "was ich jetzt tue", Folgen ist ein Zustand. Deshalb als Herz ins Banner,
// direkt neben das Zahnrad — genau wie im Web.
val overrides by StarState.overrides.collectAsStateWithLifecycle()
val folgt = overrides[artist.id] ?: (artist.starred != null)
Surface(
onClick = { vm.folgenUmschalten(artist.id, artist.starred != null) },
shape = RoundedCornerShape(999.dp),
color = Color(0x59000000),
modifier = Modifier.align(Alignment.TopEnd).padding(top = 10.dp, end = 52.dp),
) {
Icon(
if (folgt) Icons.Filled.Favorite else Icons.Filled.FavoriteBorder,
if (folgt) "Du folgst ${artist.name}" else "${artist.name} folgen",
tint = if (folgt) NsAccent else Color.White.copy(0.72f),
modifier = Modifier.padding(7.dp).size(17.dp),
)
}
// "Wrong artist?" pin — minimal icon-only chip, top-right over the hero.
Surface(
onClick = { vm.openPinPicker() },
shape = RoundedCornerShape(999.dp),
color = Color(0x59000000),
modifier = Modifier.align(Alignment.TopEnd).padding(10.dp),
) {
Text(
"⚙",
fontSize = 14.sp,
color = if (state.pin != null) Color(0xFF7EB8FF) else Color.White.copy(0.72f),
modifier = Modifier.padding(horizontal = 8.dp, vertical = 6.dp),
)
}
Box( Box(
Modifier.fillMaxSize().background( Modifier.fillMaxSize().background(
Brush.verticalGradient( Brush.verticalGradient(
@@ -170,39 +303,100 @@ fun ArtistDetailScreen(
) )
) )
) )
Column(modifier = Modifier.align(Alignment.BottomStart).padding(20.dp)) {
Text( Text(
artist.name, artist.name,
fontFamily = Outfit, fontWeight = FontWeight.ExtraBold, fontSize = 30.sp, fontFamily = Outfit, fontWeight = FontWeight.ExtraBold, fontSize = 30.sp,
letterSpacing = (-0.5).sp, color = Color.White, letterSpacing = (-0.5).sp, color = Color.White,
maxLines = 2, overflow = TextOverflow.Ellipsis, maxLines = 2, overflow = TextOverflow.Ellipsis,
modifier = Modifier.align(Alignment.BottomStart).padding(20.dp),
) )
state.fanCount?.takeIf { it > 0 }?.let {
Text(
"${fmtFanCount(it)} Fans",
fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 13.sp,
color = Color.White.copy(0.58f), modifier = Modifier.padding(top = 4.dp),
)
}
}
} }
Spacer(Modifier.height(16.dp)) Spacer(Modifier.height(16.dp))
} }
// Action bar // Action bar
item { item {
Row( LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier modifier = Modifier.padding(bottom = 8.dp),
.padding(horizontal = 16.dp)
.padding(bottom = 8.dp),
) { ) {
item {
ArtistActionPill(Icons.Default.PlayArrow, "Top Songs") { ArtistActionPill(Icons.Default.PlayArrow, "Top Songs") {
if (state.topSongs.isNotEmpty()) onPlay(state.topSongs, 0) if (state.topSongs.isNotEmpty()) onPlay(state.topSongs, 0)
} }
ArtistActionPill(Icons.Default.Shuffle, "Shuffle") { }
if (state.topSongs.isNotEmpty()) onPlay(state.topSongs.shuffled(), 0) item {
ArtistActionPill(
icon = Icons.Default.Shuffle,
label = if (state.isShuffling) "Laden…" else "Shuffle",
onClick = { vm.shuffleAll() },
)
}
item {
val eventCount = state.events.size
val konzertLabel = if (eventCount > 0) "Konzerte ($eventCount)" else "Konzerte"
ArtistActionPill(Icons.Default.Event, konzertLabel) {
vm.openEventsSheet()
}
} }
} }
} }
// Similar artists (exclude the current artist) // Similar artists. When pinned, use Deezer "related" for the pinned artist — Last.fm's list
// is keyed to the (possibly merged/wrong) Navidrome artist, so it goes "weird".
val usePinnedRelated = state.pin != null && state.pinnedRelated.isNotEmpty()
val similarArtists = state.info?.similarArtist val similarArtists = state.info?.similarArtist
?.filter { !it.name.equals(artist.name, ignoreCase = true) } ?.filter { !it.name.equals(artist.name, ignoreCase = true) }
?: emptyList() ?: emptyList()
if (similarArtists.isNotEmpty()) { if (usePinnedRelated) {
item {
SectionLabel("Similar Artists")
LazyRow(
contentPadding = PaddingValues(horizontal = 20.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp),
modifier = Modifier.padding(bottom = 20.dp),
) {
items(state.pinnedRelated, key = { it.artistId ?: 0L }) { rel ->
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.width(70.dp)
// Deezer-related has no Navidrome id → resolve by name on tap; navigate
// if the artist is in the library, else say so.
.clickable {
scope.launch {
val id = vm.libraryArtistId(rel.artistName)
if (id != null && onArtistClick != null) onArtistClick(id)
else Toast.makeText(context, "Nicht in deiner Bibliothek", Toast.LENGTH_SHORT).show()
}
},
) {
AsyncImage(
model = rel.artworkUrl100,
contentDescription = rel.artistName,
contentScale = ContentScale.Crop,
modifier = Modifier.size(60.dp).clip(CircleShape).background(NsSurface2),
)
Spacer(Modifier.height(6.dp))
Text(
rel.artistName ?: "", fontFamily = Outfit, fontSize = 11.sp,
color = NsOnSurface, maxLines = 2, overflow = TextOverflow.Ellipsis,
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
)
}
}
}
}
} else if (similarArtists.isNotEmpty()) {
item { item {
SectionLabel("Similar Artists") SectionLabel("Similar Artists")
LazyRow( LazyRow(
@@ -211,22 +405,30 @@ fun ArtistDetailScreen(
modifier = Modifier.padding(bottom = 20.dp), modifier = Modifier.padding(bottom = 20.dp),
) { ) {
items(similarArtists) { sim -> items(similarArtists) { sim ->
val navigable = onArtistClick != null && sim.id.isNotBlank()
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.width(70.dp), modifier = Modifier
.width(70.dp)
.then(
if (navigable) Modifier.clickable { onArtistClick!!(sim.id) }
else Modifier
),
) { ) {
AsyncImage( AsyncImage(
model = coverUrl(sim.coverArt), model = coverUrl(sim.coverArt),
contentDescription = sim.name, contentDescription = sim.name,
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier.size(60.dp).clip(CircleShape) modifier = Modifier
.size(60.dp)
.clip(CircleShape)
.background(NsSurface2), .background(NsSurface2),
) )
Spacer(Modifier.height(6.dp)) Spacer(Modifier.height(6.dp))
Text( Text(
sim.name, fontFamily = Outfit, fontSize = 11.sp, sim.name, fontFamily = Outfit, fontSize = 11.sp,
color = NsOnSurface2, maxLines = 2, color = if (navigable) NsOnSurface else NsOnSurface2,
overflow = TextOverflow.Ellipsis, maxLines = 2, overflow = TextOverflow.Ellipsis,
textAlign = androidx.compose.ui.text.style.TextAlign.Center, textAlign = androidx.compose.ui.text.style.TextAlign.Center,
) )
} }
@@ -238,7 +440,7 @@ fun ArtistDetailScreen(
// Navidrome top songs // Navidrome top songs
if (state.topSongs.isNotEmpty()) { if (state.topSongs.isNotEmpty()) {
item { SectionLabel("Top Songs") } item { SectionLabel("Top Songs") }
itemsIndexed(state.topSongs, key = { _, s -> "top_${s.id}" }) { idx, song -> itemsIndexed(state.topSongs, key = { idx, s -> "top_${idx}_${s.id}" }) { idx, song ->
SongRow( SongRow(
song = song, song = song,
coverUrl = coverUrl(song.coverArt), coverUrl = coverUrl(song.coverArt),
@@ -255,7 +457,7 @@ fun ArtistDetailScreen(
// ── iTunes: Weltweit populär ────────────────────────────────────────── // ── iTunes: Weltweit populär ──────────────────────────────────────────
if (state.iTracks.isNotEmpty()) { if (state.iTracks.isNotEmpty()) {
item { ArtistSectionHeader("Weltweit populär") } item { ArtistSectionHeader("Weltweit populär") }
itemsIndexed(state.iTracks, key = { _, t -> t.trackId ?: 0L }) { _, track -> itemsIndexed(state.iTracks, key = { idx, t -> "itrack_${idx}_${t.trackId ?: 0L}" }) { _, track ->
ItunesArtistTrackRow( ItunesArtistTrackRow(
track = track, track = track,
isPreviewing = state.previewingId == track.trackId, isPreviewing = state.previewingId == track.trackId,
@@ -273,7 +475,7 @@ fun ArtistDetailScreen(
color = NsAccent, modifier = Modifier.size(16.dp), strokeWidth = 2.dp, color = NsAccent, modifier = Modifier.size(16.dp), strokeWidth = 2.dp,
) )
Spacer(Modifier.width(10.dp)) Spacer(Modifier.width(10.dp))
Text("iTunes Daten werden geladen…", fontFamily = Outfit, Text("Deezer Daten werden geladen…", fontFamily = Outfit,
fontSize = 12.sp, color = NsOnSurface2) fontSize = 12.sp, color = NsOnSurface2)
} }
} }
@@ -282,7 +484,11 @@ fun ArtistDetailScreen(
// ── Album sections (categorized once iTunes data is ready) ──────────── // ── Album sections (categorized once iTunes data is ready) ────────────
if (cats != null) { if (cats != null) {
if (cats.downloaded.isNotEmpty()) { if (cats.downloaded.isNotEmpty()) {
item { ArtistSectionHeader("In Library", cats.downloaded.size) } item {
ArtistSectionHeader("In Library", cats.downloaded.size,
onShowAll = if (cats.downloaded.size > 4) ({ openAllAlbums = "In Library" }) else null
)
}
item { item {
LazyRow( LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp), contentPadding = PaddingValues(horizontal = 16.dp),
@@ -302,7 +508,11 @@ fun ArtistDetailScreen(
} }
if (cats.partial.isNotEmpty()) { if (cats.partial.isNotEmpty()) {
item { ArtistSectionHeader("Unvollständig", cats.partial.size) } item {
ArtistSectionHeader("Unvollständig", cats.partial.size,
onShowAll = if (cats.partial.size > 4) ({ openAllAlbums = "Unvollständig" }) else null
)
}
item { item {
LazyRow( LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp), contentPadding = PaddingValues(horizontal = 16.dp),
@@ -325,7 +535,11 @@ fun ArtistDetailScreen(
} }
if (cats.notDownloaded.isNotEmpty()) { if (cats.notDownloaded.isNotEmpty()) {
item { ArtistSectionHeader("Nicht heruntergeladen", cats.notDownloaded.size) } item {
ArtistSectionHeader("Nicht heruntergeladen", cats.notDownloaded.size,
onShowAll = if (cats.notDownloaded.size > 4) ({ openAllAlbums = "Nicht heruntergeladen" }) else null
)
}
item { item {
LazyRow( LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp), contentPadding = PaddingValues(horizontal = 16.dp),
@@ -418,3 +632,195 @@ private fun SectionLabel(title: String) {
modifier = Modifier.padding(start = 20.dp, top = 4.dp, bottom = 12.dp), modifier = Modifier.padding(start = 20.dp, top = 4.dp, bottom = 12.dp),
) )
} }
internal data class AllAlbumEntry(
val name: String,
val year: String?,
val artUrl: String?,
val badge: String? = null,
val dimmed: Boolean = false,
val onClick: () -> Unit,
val onDownload: (() -> Unit)? = null,
)
@Composable
internal fun AllAlbumsOverlay(
title: String,
entries: List<AllAlbumEntry>,
onBack: () -> Unit,
gridState: androidx.compose.foundation.lazy.grid.LazyGridState = androidx.compose.foundation.lazy.grid.rememberLazyGridState(),
query: String = "",
onQueryChange: (String) -> Unit = {},
) {
val filtered = remember(query, entries) {
if (query.isBlank()) entries
else entries.filter { it.name.contains(query, ignoreCase = true) }
}
Column(
Modifier
.fillMaxSize()
.background(NsBackground),
) {
// Top bar
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 4.dp, end = 12.dp, top = 12.dp, bottom = 4.dp),
) {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, "Zurück", tint = NsOnSurface2)
}
Text(
title,
fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 18.sp, color = NsOnSurface,
modifier = Modifier.weight(1f),
)
Text(
"${filtered.size}",
fontFamily = Outfit, fontSize = 12.sp,
color = NsOnSurface2.copy(0.6f),
)
}
// Search bar
OutlinedTextField(
value = query,
onValueChange = onQueryChange,
placeholder = { Text("Suchen…", color = NsOnSurface2) },
leadingIcon = { Icon(Icons.Default.Search, null, tint = NsOnSurface2) },
trailingIcon = if (query.isNotEmpty()) { {
IconButton(onClick = { onQueryChange("") }) {
Icon(Icons.Default.Clear, null, tint = NsOnSurface2)
}
} } else null,
singleLine = true,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
shape = RoundedCornerShape(12.dp),
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = NsAccent,
unfocusedBorderColor = NsOnSurface3,
cursorColor = NsAccent,
focusedContainerColor = MaterialTheme.colorScheme.surface,
unfocusedContainerColor = MaterialTheme.colorScheme.surface,
),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 6.dp),
)
LazyVerticalGrid(
state = gridState,
columns = GridCells.Fixed(2),
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.fillMaxSize(),
) {
items(filtered.size, key = { idx -> "${idx}_${filtered[idx].name}${filtered[idx].year ?: ""}" }) { idx ->
val entry = filtered[idx]
Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
AlbumThumb(
name = entry.name,
year = entry.year,
artUrl = entry.artUrl,
badge = entry.badge,
dimmed = entry.dimmed,
onClick = entry.onClick,
onDownload = entry.onDownload,
)
}
}
}
}
}
// ─── Artist-pin picker ────────────────────────────────────────────────────────
// Pin a local (Navidrome) artist to a specific Deezer artist, fixing same-name collisions.
// A pasted Deezer link/id is the reliable route when /search/artist can't surface the artist.
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun ArtistPinSheet(
artistName: String,
pinned: com.novasonic.app.api.model.ArtistOverride?,
searching: Boolean,
candidates: List<com.novasonic.app.api.model.ItunesItem>,
onPick: (com.novasonic.app.api.model.ItunesItem) -> Unit,
onPinLink: (String) -> Unit,
onClear: () -> Unit,
onDismiss: () -> Unit,
) {
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
var link by remember { mutableStateOf("") }
ModalBottomSheet(onDismissRequest = onDismiss, sheetState = sheetState, containerColor = NsSurface) {
Column(
Modifier
.fillMaxWidth()
.navigationBarsPadding()
.padding(horizontal = 20.dp)
.padding(bottom = 16.dp),
) {
Text("Richtigen Künstler wählen", fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 18.sp, color = NsOnSurface)
Text("Für „$artistName\"", fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
modifier = Modifier.padding(top = 2.dp, bottom = 14.dp))
if (pinned != null) {
OutlinedButton(
onClick = onClear,
modifier = Modifier.fillMaxWidth().padding(bottom = 12.dp),
) {
Text("Pin entfernen (aktuell: ${pinned.name.ifBlank { "gepinnt" }})",
color = NsError, fontFamily = Outfit, fontWeight = FontWeight.SemiBold)
}
}
// Paste a Deezer link/id → pin directly (reliable when search misses the artist).
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
OutlinedTextField(
value = link, onValueChange = { link = it },
placeholder = { Text("Deezer-Link oder ID", fontFamily = Outfit, fontSize = 13.sp) },
singleLine = true,
textStyle = androidx.compose.ui.text.TextStyle(fontFamily = Outfit, fontSize = 14.sp, color = NsOnSurface),
modifier = Modifier.weight(1f),
)
Spacer(Modifier.width(8.dp))
Button(
onClick = { if (link.isNotBlank()) onPinLink(link) },
shape = RoundedCornerShape(10.dp),
) { Text("Pinnen", fontFamily = Outfit, fontWeight = FontWeight.Bold) }
}
Text("Nicht in der Liste? Künstler auf deezer.com öffnen und Link einfügen.",
fontFamily = Outfit, fontSize = 11.sp, color = NsOnSurface2,
modifier = Modifier.padding(top = 6.dp, bottom = 14.dp))
when {
searching -> Box(Modifier.fillMaxWidth().padding(24.dp), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent, modifier = Modifier.size(28.dp))
}
candidates.isEmpty() -> Text("Keine Deezer-Künstler gefunden.", fontFamily = Outfit,
fontSize = 13.sp, color = NsOnSurface2, modifier = Modifier.padding(vertical = 12.dp))
else -> Column(Modifier.fillMaxWidth()) {
candidates.forEach { c ->
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().clickable { onPick(c) }.padding(vertical = 7.dp),
) {
Box(Modifier.size(48.dp).clip(CircleShape).background(NsSurface2)) {
AsyncImage(model = c.artworkUrl100, contentDescription = null,
contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize())
}
Column(Modifier.weight(1f).padding(horizontal = 12.dp)) {
Text(c.artistName ?: "—", fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 14.sp, color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text(c.fanCount?.let { "${fmtFanCount(it)} Fans" } ?: "Deezer",
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
}
}
}
}
}
}
}
@@ -0,0 +1,352 @@
package com.novasonic.app.ui.screen
import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Download
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
import com.novasonic.app.api.model.ArtistRelease
import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.ArtistNewsViewModel
import com.novasonic.app.viewmodel.NewsReiter
import com.novasonic.app.api.model.ArtistKonzert
import androidx.compose.ui.platform.LocalUriHandler
import java.text.SimpleDateFormat
import java.util.Locale
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.text.style.TextDecoration
/**
* Zeitleiste der jüngsten Veröffentlichungen aller Künstler, denen man folgt. Nach Monat gruppiert,
* neueste zuerst. Was schon in der Bibliothek liegt, ist markiert statt anklickbar.
*/
@Composable
fun ArtistNewsScreen(
onBack: () -> Unit,
onArtistClick: (String) -> Unit,
) {
val vm: ArtistNewsViewModel = viewModel()
val state by vm.state.collectAsStateWithLifecycle()
val ctx = LocalContext.current
Column(Modifier.fillMaxSize()) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.statusBarsPadding().padding(start = 4.dp, top = 4.dp),
) {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, "Zurück",
tint = MaterialTheme.colorScheme.onSurface)
}
val konzerte = state.reiter == NewsReiter.KONZERTE
Text(
if (konzerte) "Konzerte deiner Künstler" else "Neu von deinen Künstlern",
fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 17.sp, color = MaterialTheme.colorScheme.onSurface,
)
}
// Zwei Reiter statt zweier Knoepfe in den Favoriten: Neuheiten und Konzerte sind dasselbe
// Thema. Bewusst NICHT in eine gemeinsame Liste gemischt — Veroeffentlichungen liegen
// hinter, Konzerte vor dem heutigen Tag.
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.padding(start = 16.dp, top = 4.dp),
) {
listOf(
NewsReiter.RELEASES to "Neu erschienen",
NewsReiter.KONZERTE to "Konzerte",
).forEach { (r, label) ->
FilterChip(
selected = state.reiter == r,
onClick = { vm.zeigeReiter(r) },
label = { Text(label, fontSize = 12.sp) },
colors = FilterChipDefaults.filterChipColors(
selectedContainerColor = NsAccent.copy(alpha = 0.2f),
selectedLabelColor = NsAccent,
),
)
}
}
// Das Zeitfenster gilt nur fuer die Veroeffentlichungen. Konzerte sind ohnehin Zukunft,
// dort will man alles Angekuendigte sehen — eine Tagesgrenze schnitte nur willkuerlich ab.
if (state.reiter == NewsReiter.RELEASES) {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.padding(start = 16.dp, top = 8.dp, bottom = 10.dp),
) {
// 90 Tage zuerst, weil es die Vorgabe ist — der aktive Chip steht dann vorn.
listOf(90 to "90 Tage", 30 to "30 Tage", 365 to "1 Jahr").forEach { (tage, label) ->
FilterChip(
selected = state.tage == tage,
onClick = { vm.setzeTage(tage) },
label = { Text(label, fontSize = 12.sp) },
colors = FilterChipDefaults.filterChipColors(
selectedContainerColor = NsAccent.copy(alpha = 0.2f),
selectedLabelColor = NsAccent,
),
)
}
}
} else {
Spacer(Modifier.height(10.dp))
}
HorizontalDivider(color = MaterialTheme.colorScheme.outline)
when {
state.isLoading -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent)
}
state.keinBackend -> Hinweis("🔌", "Kein Backend konfiguriert",
"Neue Veröffentlichungen kommen über das Backend von Deezer.")
state.keineGefolgten -> Hinweis("❤", "Du folgst noch niemandem",
"Auf einer Künstlerseite oben rechts aufs Herz tippen.")
state.error != null -> Hinweis("⚠", "Laden fehlgeschlagen", state.error!!)
state.reiter == NewsReiter.KONZERTE && state.keinSchluessel -> Hinweis("🎟",
"Kein Ticketmaster-Schlüssel hinterlegt", "Im Backend TICKETMASTER_API_KEY setzen.")
state.reiter == NewsReiter.KONZERTE && state.konzerte.isEmpty() -> Hinweis("🎪",
"Keine anstehenden Termine",
"Gesucht wird weltweit über den Künstlernamen.")
state.reiter == NewsReiter.KONZERTE -> LazyColumn(contentPadding = PaddingValues(bottom = 90.dp)) {
var letzterMonat = ""
state.konzerte.forEach { k ->
val monat = monatVon(k.datum)
if (monat != letzterMonat) {
letzterMonat = monat
item(key = "km_$monat") {
Text(monat, fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 13.sp, color = NsOnSurface2,
modifier = Modifier.padding(start = 20.dp, top = 16.dp, bottom = 6.dp))
}
}
item(key = "k_${k.eventId}_${k.artistId}") {
KonzertZeile(k) { onArtistClick(k.artistId) }
}
}
}
state.releases.isEmpty() -> Hinweis("🌙",
"Nichts Neues in den letzten ${state.tage} Tagen", "")
else -> LazyColumn(contentPadding = PaddingValues(bottom = 90.dp)) {
if (state.ohneZuordnung.isNotEmpty()) {
item { ZuordnungsHinweis(state.ohneZuordnung) }
}
var letzterMonat = ""
state.releases.forEach { rel ->
val monat = monatVon(rel.releaseDate)
if (monat != letzterMonat) {
letzterMonat = monat
item(key = "m_$monat") {
Text(monat, fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 13.sp, color = NsOnSurface2,
modifier = Modifier.padding(start = 20.dp, top = 16.dp, bottom = 6.dp))
}
}
item(key = "${rel.artistId}_${rel.albumId}") {
ReleaseZeile(
rel = rel,
schonDa = vm.hatSchon(rel),
onArtist = { onArtistClick(rel.artistId) },
onDownload = {
vm.herunterladen(rel) { _, msg ->
Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show()
}
},
)
}
}
}
}
}
}
@Composable
private fun Hinweis(symbol: String, titel: String, text: String) {
Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(symbol, fontSize = 34.sp)
Spacer(Modifier.height(10.dp))
Text(titel, fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 15.sp,
color = MaterialTheme.colorScheme.onSurface)
if (text.isNotBlank()) {
Spacer(Modifier.height(6.dp))
Text(text, fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
}
}
}
@Composable
private fun ZuordnungsHinweis(namen: List<String>) {
Box(
Modifier.padding(horizontal = 16.dp, vertical = 10.dp)
.clip(RoundedCornerShape(10.dp))
.background(NsAccent.copy(alpha = 0.08f))
.border(1.dp, NsAccent.copy(alpha = 0.28f), RoundedCornerShape(10.dp))
.padding(12.dp),
) {
Text(
"⚠ Für ${namen.size} Künstler wurde kein Deezer-Profil gefunden: " +
namen.take(4).joinToString(", ") + (if (namen.size > 4) " …" else "") +
". Auf der Künstlerseite über ⚙ das richtige Profil festpinnen.",
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2, lineHeight = 17.sp,
)
}
}
private val TYP = mapOf("album" to "Album", "single" to "Single", "ep" to "EP",
"compile" to "Compilation")
@Composable
private fun ReleaseZeile(
rel: ArtistRelease,
schonDa: Boolean,
onArtist: () -> Unit,
onDownload: () -> Unit,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 7.dp),
) {
AsyncImage(
model = rel.cover.takeIf { it.isNotBlank() },
contentDescription = rel.title,
contentScale = ContentScale.Crop,
modifier = Modifier.size(56.dp).clip(RoundedCornerShape(8.dp)).background(NsSurface2),
)
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(rel.title, fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 14.sp,
maxLines = 1, overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colorScheme.onSurface)
Row(verticalAlignment = Alignment.CenterVertically) {
Text(rel.artistName, fontFamily = Outfit, fontSize = 12.sp, color = NsAccent,
maxLines = 1, overflow = TextOverflow.Ellipsis,
modifier = Modifier.clickable(onClick = onArtist))
Text(
" · " + (TYP[rel.recordType] ?: rel.recordType) +
(rel.trackCount?.let { " · $it Titel" } ?: ""),
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
maxLines = 1, overflow = TextOverflow.Ellipsis,
)
}
Text(datumVon(rel.releaseDate), fontFamily = Outfit, fontSize = 11.sp,
color = NsOnSurface3, modifier = Modifier.padding(top = 2.dp))
}
Spacer(Modifier.width(8.dp))
if (schonDa) {
Icon(Icons.Default.CheckCircle, "In deiner Bibliothek",
tint = NsOnSurface3, modifier = Modifier.size(20.dp))
} else {
IconButton(onClick = onDownload) {
Icon(Icons.Default.Download, "Herunterladen", tint = NsAccent,
modifier = Modifier.size(20.dp))
}
}
}
}
// Deezer liefert "JJJJ-MM-TT".
private val EIN = SimpleDateFormat("yyyy-MM-dd", Locale.GERMAN)
private val MONAT = SimpleDateFormat("LLLL yyyy", Locale.GERMAN)
private val DATUM = SimpleDateFormat("dd.MM.yyyy", Locale.GERMAN)
private fun monatVon(s: String) = runCatching { MONAT.format(EIN.parse(s)!!) }.getOrDefault(s)
private fun datumVon(s: String) = runCatching { DATUM.format(EIN.parse(s)!!) }.getOrDefault(s)
// Ticketmaster liefert die ORTSZEIT ohne Zone: "2026-11-04T20:00:00".
private val EIN_ZEIT = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.GERMAN)
private val TAG_KURZ = SimpleDateFormat("d", Locale.GERMAN)
private val MON_KURZ = SimpleDateFormat("MMM", Locale.GERMAN)
private val UHR = SimpleDateFormat("HH:mm", Locale.GERMAN)
private fun zeitVon(s: String) = runCatching { EIN_ZEIT.parse(s) }.getOrNull()
/**
* Eine Konzertzeile. Statt eines Covers steht links ein Kalenderblatt — ein Konzert hat kein Bild,
* aber ein Datum, und danach sucht das Auge in einer Liste, die nach vorn läuft.
*/
@Composable
private fun KonzertZeile(k: ArtistKonzert, onArtist: () -> Unit) {
val uri = LocalUriHandler.current
val d = zeitVon(k.datum)
val ort = listOf(k.ort, k.stadt, k.land).filter { it.isNotBlank() }.joinToString(" · ")
val uhr = d?.let { UHR.format(it) }?.takeIf { it != "00:00" }
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 6.dp),
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier
.size(50.dp)
.clip(RoundedCornerShape(10.dp))
.background(NsSurface)
.border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(10.dp))
.alpha(if (k.abgesagt) 0.45f else 1f),
) {
Text(d?.let { TAG_KURZ.format(it) } ?: "?", fontFamily = Outfit,
fontWeight = FontWeight.Bold, fontSize = 17.sp,
color = MaterialTheme.colorScheme.onSurface)
Text(d?.let { MON_KURZ.format(it) }?.uppercase() ?: "", fontFamily = Outfit,
fontSize = 10.sp, color = NsOnSurface2)
}
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(
k.titel.ifBlank { k.artistName },
fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 14.sp,
color = if (k.abgesagt) NsOnSurface2 else MaterialTheme.colorScheme.onSurface,
maxLines = 1, overflow = TextOverflow.Ellipsis,
textDecoration = if (k.abgesagt) TextDecoration.LineThrough else null,
)
Spacer(Modifier.height(2.dp))
Row(verticalAlignment = Alignment.CenterVertically) {
Text(k.artistName, fontFamily = Outfit, fontSize = 12.sp, color = NsAccent,
maxLines = 1, overflow = TextOverflow.Ellipsis,
modifier = Modifier.clickable(onClick = onArtist))
val rest = listOfNotNull(ort.ifBlank { null }, uhr?.let { "$it Uhr" })
if (rest.isNotEmpty()) {
Text(" · " + rest.joinToString(" · "), fontFamily = Outfit, fontSize = 12.sp,
color = NsOnSurface2, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
}
if (k.abgesagt) {
Text("abgesagt", fontFamily = Outfit, fontSize = 11.sp, color = NsOnSurface2)
} else if (k.url.isNotBlank()) {
TextButton(onClick = { uri.openUri(k.url) }) {
Text("Tickets", fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 12.sp, color = NsAccent)
}
}
}
}
@@ -0,0 +1,403 @@
package com.novasonic.app.ui.screen
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
import com.novasonic.app.api.model.CompareResult
import com.novasonic.app.api.model.SharedArtist
import com.novasonic.app.api.model.SharedTrack
import com.novasonic.app.api.model.UniqueArtist
import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.CompareViewModel
@Composable
fun CompareScreen(
coverUrl: (String?) -> String?,
onBack: () -> Unit,
onArtistClick: (String) -> Unit = {},
onAlbumClick: (String) -> Unit = {},
vm: CompareViewModel = viewModel(),
) {
val state by vm.state.collectAsStateWithLifecycle()
Column(Modifier.fillMaxSize().background(NsBackground)) {
// ── Top bar ──
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(start = 4.dp, top = 8.dp, end = 12.dp),
) {
IconButton(onClick = onBack) {
Icon(Icons.Default.ArrowBack, contentDescription = "Zurück", tint = NsOnSurface)
}
Text(
"Musik-Match",
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 22.sp,
color = NsOnSurface, modifier = Modifier.weight(1f),
)
// Show "wechseln" once a partner is picked so you can go back to the list.
if (state.partner != null) {
Text(
"↺ Wechseln",
fontFamily = Outfit, fontSize = 13.sp, fontWeight = FontWeight.SemiBold,
color = NsOnSurface2,
modifier = Modifier
.clip(RoundedCornerShape(8.dp))
.clickable { vm.clearPartner() }
.padding(horizontal = 8.dp, vertical = 6.dp),
)
}
}
when {
state.loading -> CenterBox { CircularProgressIndicator(color = NsAccent) }
!state.configured -> CenterMsg(
"Kein Scrobble-Dienst konfiguriert.\nTrage die Scrobble-URL in den Einstellungen ein.",
)
state.error != null -> CenterMsg(state.error!!, NsError)
state.partner == null -> PartnerPicker(state.me, state.users, vm::choosePartner)
state.result != null -> CompareContent(state.result!!, coverUrl, onArtistClick, onAlbumClick)
else -> CenterBox { CircularProgressIndicator(color = NsAccent) }
}
}
}
@Composable
private fun PartnerPicker(
me: String,
users: List<com.novasonic.app.api.model.ScrobbleUser>,
onPick: (String) -> Unit,
) {
if (users.isEmpty()) {
CenterMsg("Noch niemand sonst hat Wiedergaben aufgezeichnet.\nSobald eine andere Person NovaSonic nutzt, könnt ihr euch hier vergleichen.")
return
}
Column(
Modifier.fillMaxSize().verticalScroll(rememberScrollState())
.padding(horizontal = 16.dp).padding(bottom = 24.dp),
) {
Text(
"Mit wem willst du dich vergleichen?",
fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface2,
modifier = Modifier.padding(vertical = 6.dp),
)
users.forEach { u ->
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
.padding(vertical = 5.dp)
.clip(RoundedCornerShape(12.dp))
.background(NsSurface2)
.clickable { onPick(u.user) }
.padding(12.dp),
) {
Box(
Modifier.size(40.dp).clip(CircleShape).background(NsAccent),
contentAlignment = Alignment.Center,
) {
Text(
(u.user.firstOrNull()?.uppercase() ?: "?"),
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 18.sp, color = Color.Black,
)
}
Column(Modifier.weight(1f).padding(horizontal = 12.dp)) {
Text(u.user, fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp,
color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text("${u.plays} Plays", fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
Text("›", fontFamily = Outfit, fontSize = 20.sp, color = NsOnSurface2)
}
}
}
}
@Composable
private fun CompareContent(
d: CompareResult,
coverUrl: (String?) -> String?,
onArtistClick: (String) -> Unit,
onAlbumClick: (String) -> Unit,
) {
Column(
Modifier.fillMaxSize().verticalScroll(rememberScrollState())
.padding(horizontal = 16.dp).padding(bottom = 24.dp),
) {
Scoreboard(d)
Spacer(Modifier.height(20.dp))
Totals(d)
Spacer(Modifier.height(22.dp))
SectionHeader("Gemeinsame Künstler")
if (d.sharedArtists.isEmpty()) {
EmptyLine("Keine gemeinsamen Künstler in diesem Zeitraum.")
} else {
val max = (d.sharedArtists.maxOfOrNull { maxOf(it.playsA, it.playsB) } ?: 1).coerceAtLeast(1)
d.sharedArtists.take(15).forEach { a ->
SharedArtistRow(a, max, a.artistId?.let { id -> { onArtistClick(id) } })
}
}
Spacer(Modifier.height(22.dp))
if (d.sharedTracks.isNotEmpty()) {
SectionHeader("Gemeinsame Songs")
d.sharedTracks.take(12).forEach { t ->
SharedTrackRow(t, coverUrl(t.coverArt ?: t.albumId ?: t.songId),
t.albumId?.let { id -> { onAlbumClick(id) } })
}
Spacer(Modifier.height(22.dp))
}
Streitpunkte(d, onArtistClick)
SectionHeader("Nur bei…")
Row(horizontalArrangement = Arrangement.spacedBy(18.dp)) {
UniqueColumn("Nur ${d.userA}", d.onlyA, onArtistClick, Modifier.weight(1f))
UniqueColumn("Nur ${d.userB}", d.onlyB, onArtistClick, Modifier.weight(1f))
}
}
}
@Composable
private fun Streitpunkte(d: CompareResult, onArtistClick: (String) -> Unit) {
// Gemeinsame Kuenstler mit dem groessten Ungleichgewicht — das Gegenstueck zu "Gemeinsame
// Kuenstler", das nach Summe sortiert. Mindestmasse, damit ein einzelner Play gegen null nicht
// als Streit gilt. Identische Schwellen wie im Web, damit beide dasselbe zeigen.
val items = d.sharedArtists
.map { a ->
val summe = a.playsA + a.playsB
Triple(a, summe, if (summe > 0) kotlin.math.abs(a.playsA - a.playsB) / summe.toFloat() else 0f)
}
.filter { (_, summe, unwucht) -> summe >= 4 && unwucht >= 0.5f }
.sortedWith(compareByDescending<Triple<SharedArtist, Int, Float>> { it.third }.thenByDescending { it.second })
.take(8)
SectionHeader("Streitpunkte")
if (items.isEmpty()) {
Text("Ihr hört gemeinsame Künstler erstaunlich ausgewogen.",
fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface2)
return
}
items.forEach { (a, summe, _) ->
val anteilA = a.playsA / summe.toFloat()
Column(
Modifier.fillMaxWidth()
.clickable { a.artistId?.let(onArtistClick) }
.padding(vertical = 6.dp)
) {
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Text("${a.playsA}", fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
fontWeight = FontWeight.Bold)
Text(a.name ?: "—", fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface,
fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis,
textAlign = TextAlign.Center,
modifier = Modifier.weight(1f).padding(horizontal = 8.dp))
Text("${a.playsB}", fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
fontWeight = FontWeight.Bold)
}
Spacer(Modifier.height(4.dp))
Row(Modifier.fillMaxWidth().height(6.dp).clip(RoundedCornerShape(3.dp))) {
Box(Modifier.weight(anteilA.coerceAtLeast(0.001f)).fillMaxHeight().background(NsAccent))
Box(Modifier.weight((1f - anteilA).coerceAtLeast(0.001f)).fillMaxHeight()
.background(NsAccent.copy(alpha = .35f)))
}
}
}
Spacer(Modifier.height(10.dp))
}
@Composable
private fun Scoreboard(d: CompareResult) {
val b = d.battle
if (b == null || b.kategorien.isEmpty()) return
val urteil = when {
b.punkteA == b.punkteB -> "Kopf-an-Kopf — kein Sieger."
b.punkteA > b.punkteB -> "${d.userA} gewinnt ${b.punkteA}:${b.punkteB}."
else -> "${d.userB} gewinnt ${b.punkteB}:${b.punkteA}."
}
Column(Modifier.fillMaxWidth()) {
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
Text(d.userA, fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp,
color = NsOnSurface, maxLines = 1, modifier = Modifier.weight(1f, false))
Text(" ${b.punkteA} : ${b.punkteB} ", fontFamily = Outfit, fontWeight = FontWeight.Black,
fontSize = 30.sp, color = NsOnSurface)
Text(d.userB, fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp,
color = NsOnSurface, maxLines = 1, modifier = Modifier.weight(1f, false))
}
Text(urteil, fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface2,
modifier = Modifier.fillMaxWidth().padding(top = 4.dp, bottom = 12.dp),
textAlign = TextAlign.Center)
// Eine Zeile je Kategorie: Wert · Bezeichnung · Wert. Der Sieger wird farblich
// hervorgehoben, der Verlierer zurueckgenommen — identisch zum Web.
b.kategorien.forEach { k ->
val gewinnA = k.sieger == "A"
val gewinnB = k.sieger == "B"
Row(
Modifier.fillMaxWidth().padding(vertical = 5.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(k.textA, fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp,
color = if (gewinnA) NsAccent else if (gewinnB) NsOnSurface3 else NsOnSurface,
textAlign = TextAlign.End, modifier = Modifier.weight(1f))
Text(k.label.uppercase(), fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 11.sp, color = NsOnSurface2, textAlign = TextAlign.Center,
maxLines = 1, modifier = Modifier.weight(1.3f))
Text(k.textB, fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp,
color = if (gewinnB) NsAccent else if (gewinnA) NsOnSurface3 else NsOnSurface,
modifier = Modifier.weight(1f))
}
}
Spacer(Modifier.height(6.dp))
}
}
@Composable
private fun Totals(d: CompareResult) {
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
TotalCard(d.userA, d.totalsA.plays, d.totalsA.artists, Modifier.weight(1f))
TotalCard(d.userB, d.totalsB.plays, d.totalsB.artists, Modifier.weight(1f))
}
}
@Composable
private fun TotalCard(name: String, plays: Int, artists: Int, modifier: Modifier) {
Column(modifier.clip(RoundedCornerShape(12.dp)).background(NsSurface2).padding(14.dp)) {
Text(name, fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp,
color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis)
Spacer(Modifier.height(6.dp))
Text("$plays Plays · $artists Künstler", fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
}
@Composable
private fun SharedArtistRow(a: SharedArtist, max: Int, onClick: (() -> Unit)?) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
.then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier)
.padding(vertical = 7.dp),
) {
Text("${a.playsA}", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 12.sp,
color = NsOnSurface2, textAlign = TextAlign.End, modifier = Modifier.width(30.dp))
// left (A) bar grows toward the centre
Box(Modifier.weight(1f), contentAlignment = Alignment.CenterEnd) {
Box(Modifier.fillMaxWidth(a.playsA.toFloat() / max).height(6.dp)
.clip(RoundedCornerShape(3.dp)).background(NsAccent))
}
Text(
a.name ?: "—", fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 13.sp,
color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis, textAlign = TextAlign.Center,
modifier = Modifier.weight(1.6f).padding(horizontal = 6.dp),
)
// right (B) bar grows from the centre
Box(Modifier.weight(1f), contentAlignment = Alignment.CenterStart) {
Box(Modifier.fillMaxWidth(a.playsB.toFloat() / max).height(6.dp)
.clip(RoundedCornerShape(3.dp)).background(NsAccent.copy(alpha = 0.55f)))
}
Text("${a.playsB}", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 12.sp,
color = NsOnSurface2, textAlign = TextAlign.Start, modifier = Modifier.width(30.dp))
}
}
@Composable
private fun SharedTrackRow(t: SharedTrack, cover: String?, onClick: (() -> Unit)?) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
.then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier)
.padding(vertical = 5.dp),
) {
Box(Modifier.size(44.dp).clip(RoundedCornerShape(6.dp)).background(NsSurface2)) {
AsyncImage(model = cover, contentDescription = null, contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize())
}
Column(Modifier.weight(1f).padding(horizontal = 12.dp)) {
Text(t.title ?: "—", fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 14.sp,
color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis)
if (!t.artist.isNullOrBlank()) {
Text(t.artist, fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
Text("${t.playsA} · ${t.playsB}", fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 13.sp, color = NsOnSurface2)
}
}
@Composable
private fun UniqueColumn(title: String, items: List<UniqueArtist>, onArtistClick: (String) -> Unit, modifier: Modifier) {
Column(modifier) {
Text(title, fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 12.sp,
color = NsOnSurface2, maxLines = 1, overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(bottom = 6.dp))
if (items.isEmpty()) {
Text("—", fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface2, modifier = Modifier.padding(vertical = 4.dp))
} else {
items.take(6).forEach { a ->
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
.then(if (a.artistId != null) Modifier.clickable { onArtistClick(a.artistId) } else Modifier)
.padding(vertical = 4.dp),
) {
Text(a.name ?: "—", fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface,
maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
Text("${a.plays}", fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 12.sp,
color = NsOnSurface2, modifier = Modifier.padding(start = 6.dp))
}
}
}
}
}
@Composable
private fun SectionHeader(t: String) {
Text(t.uppercase(), fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 12.sp,
letterSpacing = 0.6.sp, color = NsOnSurface2, modifier = Modifier.padding(bottom = 8.dp))
}
@Composable
private fun EmptyLine(msg: String) {
Text(msg, fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface2, modifier = Modifier.padding(vertical = 8.dp))
}
@Composable
private fun CenterBox(content: @Composable BoxScope.() -> Unit) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center, content = content)
}
@Composable
private fun CenterMsg(msg: String, color: Color = NsOnSurface2) {
Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) {
Text(msg, fontFamily = Outfit, fontSize = 14.sp, color = color, textAlign = TextAlign.Center)
}
}
@@ -3,6 +3,8 @@ package com.novasonic.app.ui.screen
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
@@ -48,6 +50,8 @@ fun ExploreScreen(
onSongPlay: (List<com.novasonic.app.api.model.Song>, Int) -> Unit, onSongPlay: (List<com.novasonic.app.api.model.Song>, Int) -> Unit,
onAlbumClick: (com.novasonic.app.api.model.Album) -> Unit, onAlbumClick: (com.novasonic.app.api.model.Album) -> Unit,
onArtistClick: (com.novasonic.app.api.model.Artist) -> Unit, onArtistClick: (com.novasonic.app.api.model.Artist) -> Unit,
onShowContextMenu: ((com.novasonic.app.api.model.Song) -> Unit)? = null,
onOverlayBackChange: ((() -> Unit)?) -> Unit = {},
onOpenImporter: () -> Unit = {}, onOpenImporter: () -> Unit = {},
) { ) {
val vm: ExploreViewModel = viewModel() val vm: ExploreViewModel = viewModel()
@@ -55,6 +59,32 @@ fun ExploreScreen(
val focusManager = LocalFocusManager.current val focusManager = LocalFocusManager.current
val context = LocalContext.current val context = LocalContext.current
// Overlay back is handled at the app root (see AppNavigation.exploreOverlayBack): a BackHandler
// inside this NavHost destination loses back priority to the NavHost, which pops Erkunden → Home.
// Report the current overlay's close action up; clear it when this screen leaves composition
// (e.g. drilling into a real album route) so that screen's own back works normally.
val overlayKind = when {
state.artistDetail != null && state.partialAlbum != null -> 5 // artist → partial album
state.artistDetail != null && state.albumTracks != null -> 4 // artist → iTunes album
state.artistDetail != null && state.artistAllAlbums != null -> 3 // artist → all-albums grid
state.artistDetail != null -> 2 // iTunes artist
state.albumTracks != null -> 1 // album straight from search
else -> 0
}
DisposableEffect(overlayKind) {
onOverlayBackChange(
when (overlayKind) {
5 -> vm::dismissPartialAlbum
4 -> vm::dismissAlbum
3 -> vm::closeArtistAllAlbums
2 -> vm::closeArtistDetail
1 -> vm::dismissAlbum
else -> null
}
)
onDispose { onOverlayBackChange(null) }
}
// Download sheet // Download sheet
state.downloadSheetItem?.let { item -> state.downloadSheetItem?.let { item ->
ItunesDownloadSheet( ItunesDownloadSheet(
@@ -85,6 +115,7 @@ fun ExploreScreen(
onPreview = vm::togglePreview, onPreview = vm::togglePreview,
onDownload = vm::showDownloadSheet, onDownload = vm::showDownloadSheet,
onBack = vm::dismissPartialAlbum, onBack = vm::dismissPartialAlbum,
onShowContextMenu = onShowContextMenu,
) )
} }
albumTracks != null && albumItem != null -> { albumTracks != null && albumItem != null -> {
@@ -95,6 +126,7 @@ fun ExploreScreen(
previewingId = state.previewingId, previewingId = state.previewingId,
onPreview = vm::togglePreview, onPreview = vm::togglePreview,
onDownload = vm::showDownloadSheet, onDownload = vm::showDownloadSheet,
onArtistClick = vm::openArtistOfAlbum,
onBack = vm::dismissAlbum, onBack = vm::dismissAlbum,
) )
} }
@@ -111,28 +143,47 @@ fun ExploreScreen(
onItunesAlbumOpen = vm::loadAlbum, onItunesAlbumOpen = vm::loadAlbum,
onItunesTrackPreview = vm::togglePreview, onItunesTrackPreview = vm::togglePreview,
previewingId = state.previewingId, previewingId = state.previewingId,
allAlbumsOpen = state.artistAllAlbums,
onOpenAllAlbums = vm::openArtistAllAlbums,
onCloseAllAlbums = vm::closeArtistAllAlbums,
allAlbumsGrid = vm.allAlbumsGrid,
allAlbumsQuery = vm.allAlbumsQuery.value,
onAllAlbumsQueryChange = { vm.allAlbumsQuery.value = it },
) )
} }
} }
return return
} }
// Swipe left/right to switch between the Bibliothek and Erkunden sub-tabs, kept in sync with the
// TabRow: a chip tap animates the pager; a settled swipe updates the selected tab.
val pagerState = rememberPagerState(initialPage = state.tab.ordinal) { ExploreTab.values().size }
LaunchedEffect(state.tab) {
if (pagerState.currentPage != state.tab.ordinal) pagerState.animateScrollToPage(state.tab.ordinal)
}
LaunchedEffect(pagerState.settledPage) {
val t = ExploreTab.values()[pagerState.settledPage]
if (t != state.tab) { vm.selectTab(t); vm.stopPreview() }
}
Column(Modifier.fillMaxSize()) { Column(Modifier.fillMaxSize()) {
// ── Tabs ───────────────────────────────────────────────────────────── // ── Tabs ─────────────────────────────────────────────────────────────
// Drive the indicator off the pager's current page so it moves WITH the swipe (at the
// half-way point), not only once the swipe settles — that lag read as "not smooth".
TabRow( TabRow(
selectedTabIndex = state.tab.ordinal, selectedTabIndex = pagerState.currentPage,
containerColor = MaterialTheme.colorScheme.background, containerColor = MaterialTheme.colorScheme.background,
contentColor = NsAccent, contentColor = NsAccent,
) { ) {
Tab( Tab(
selected = state.tab == ExploreTab.LIBRARY, selected = pagerState.currentPage == ExploreTab.LIBRARY.ordinal,
onClick = { vm.selectTab(ExploreTab.LIBRARY); vm.stopPreview() }, onClick = { vm.selectTab(ExploreTab.LIBRARY); vm.stopPreview() },
text = { Text("Bibliothek", maxLines = 1) }, text = { Text("Bibliothek", maxLines = 1) },
selectedContentColor = NsAccent, selectedContentColor = NsAccent,
unselectedContentColor = MaterialTheme.colorScheme.onSurfaceVariant, unselectedContentColor = MaterialTheme.colorScheme.onSurfaceVariant,
) )
Tab( Tab(
selected = state.tab == ExploreTab.GLOBAL, selected = pagerState.currentPage == ExploreTab.GLOBAL.ordinal,
onClick = { vm.selectTab(ExploreTab.GLOBAL); vm.stopPreview() }, onClick = { vm.selectTab(ExploreTab.GLOBAL); vm.stopPreview() },
text = { Text("Erkunden", maxLines = 1) }, text = { Text("Erkunden", maxLines = 1) },
selectedContentColor = NsAccent, selectedContentColor = NsAccent,
@@ -199,17 +250,28 @@ fun ExploreScreen(
} }
} }
// ── Content ────────────────────────────────────────────────────────── // ── Content (swipeable) ────────────────────────────────────────────────
when (state.tab) { HorizontalPager(
ExploreTab.LIBRARY -> LibrarySearchContent( state = pagerState,
// Pre-compose the neighbour page so the swipe doesn't hitch while its (heavy) LazyColumn
// builds on first drag.
beyondViewportPageCount = 1,
modifier = Modifier.weight(1f),
) { page ->
// fillMaxSize so short content (e.g. the Top-Alben charts row) sits at the top, not
// vertically centered in the page.
Box(Modifier.fillMaxSize()) {
when (page) {
ExploreTab.LIBRARY.ordinal -> LibrarySearchContent(
query = state.query, query = state.query,
coverUrl = coverUrl, coverUrl = coverUrl,
playerState = playerState, playerState = playerState,
onSongPlay = onSongPlay, onSongPlay = onSongPlay,
onAlbumClick = onAlbumClick, onAlbumClick = onAlbumClick,
onArtistClick = onArtistClick, onArtistClick = onArtistClick,
onShowContextMenu = onShowContextMenu,
) )
ExploreTab.GLOBAL -> GlobalExploreContent( else -> GlobalExploreContent(
state = state, state = state,
vm = vm, vm = vm,
coverUrl = coverUrl, coverUrl = coverUrl,
@@ -220,6 +282,8 @@ fun ExploreScreen(
) )
} }
} }
}
}
} }
// ── Library (local Navidrome) search ───────────────────────────────────────── // ── Library (local Navidrome) search ─────────────────────────────────────────
@@ -232,6 +296,7 @@ private fun LibrarySearchContent(
onSongPlay: (List<com.novasonic.app.api.model.Song>, Int) -> Unit, onSongPlay: (List<com.novasonic.app.api.model.Song>, Int) -> Unit,
onAlbumClick: (com.novasonic.app.api.model.Album) -> Unit, onAlbumClick: (com.novasonic.app.api.model.Album) -> Unit,
onArtistClick: (com.novasonic.app.api.model.Artist) -> Unit, onArtistClick: (com.novasonic.app.api.model.Artist) -> Unit,
onShowContextMenu: ((com.novasonic.app.api.model.Song) -> Unit)? = null,
) { ) {
// Reuse SearchScreen's ViewModel // Reuse SearchScreen's ViewModel
val vm: com.novasonic.app.viewmodel.SearchViewModel = viewModel() val vm: com.novasonic.app.viewmodel.SearchViewModel = viewModel()
@@ -256,7 +321,7 @@ private fun LibrarySearchContent(
return return
} }
LazyColumn { LazyColumn(state = vm.listState) {
val artists = state.searchResult?.artist ?: emptyList() val artists = state.searchResult?.artist ?: emptyList()
val albums = state.searchResult?.album ?: emptyList() val albums = state.searchResult?.album ?: emptyList()
val songs = state.searchResult?.song ?: emptyList() val songs = state.searchResult?.song ?: emptyList()
@@ -274,12 +339,17 @@ private fun LibrarySearchContent(
item { item {
LazyRow( LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp), contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp), horizontalArrangement = Arrangement.spacedBy(16.dp),
) { ) {
items(artists, key = { it.id }) { a -> items(artists, key = { it.id }) { a ->
SmallArtistChip(a.name) { onArtistClick(a) } // A pin's Deezer picture wins (fixes same-name artists whose Navidrome image
// is the wrong person). Otherwise: search3 usually omits coverArt → fall back
// to the artist id, which Navidrome's getCoverArt resolves to the artist image.
val pinImg = state.overrides[a.id]?.image?.takeIf { it.isNotBlank() }
ArtistCard(name = a.name, imageUrl = pinImg ?: coverUrl(a.coverArt ?: a.id)) { onArtistClick(a) }
} }
} }
Spacer(Modifier.height(8.dp))
} }
} }
if (albums.isNotEmpty()) { if (albums.isNotEmpty()) {
@@ -306,7 +376,10 @@ private fun LibrarySearchContent(
song = song, song = song,
coverUrl = coverUrl(song.coverArt), coverUrl = coverUrl(song.coverArt),
isPlaying = playerState.currentSong?.id == song.id, isPlaying = playerState.currentSong?.id == song.id,
onPlay = { onSongPlay(songs, idx) }, starred = song.starred != null,
// Play only the tapped song; Radio mode (if on) fills the rest.
onPlay = { onSongPlay(listOf(song), 0) },
onMore = onShowContextMenu?.let { cb -> { cb(song) } },
) )
} }
} }
@@ -335,6 +408,7 @@ private fun GlobalExploreContent(
previewingId = state.previewingId, previewingId = state.previewingId,
onPreview = vm::togglePreview, onPreview = vm::togglePreview,
onDownload = onDownload, onDownload = onDownload,
onArtistClick = vm::openArtistOfAlbum,
onBack = vm::dismissAlbum, onBack = vm::dismissAlbum,
) )
return return
@@ -392,7 +466,7 @@ private fun GlobalExploreContent(
return return
} }
LazyColumn { LazyColumn(state = vm.searchListState) {
if (state.error != null) { if (state.error != null) {
item { Text(state.error, color = MaterialTheme.colorScheme.error, item { Text(state.error, color = MaterialTheme.colorScheme.error,
modifier = Modifier.padding(16.dp)) } modifier = Modifier.padding(16.dp)) }
@@ -402,12 +476,17 @@ private fun GlobalExploreContent(
item { item {
LazyRow( LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp), contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp), horizontalArrangement = Arrangement.spacedBy(16.dp),
) { ) {
items(state.artists) { a -> items(state.artists) { a ->
SmallArtistChip(a.artistName ?: "") { vm.openArtistDetail(a) } ArtistCard(
name = a.artistName ?: "",
imageUrl = a.artworkUrl100?.replace("100x100bb", "300x300bb"),
subtitle = a.fanCount?.takeIf { it > 0 }?.let { "${fmtFanCount(it)} Fans" },
) { vm.openArtistDetail(a) }
} }
} }
Spacer(Modifier.height(8.dp))
} }
} }
if (state.albums.isNotEmpty()) { if (state.albums.isNotEmpty()) {
@@ -447,6 +526,7 @@ internal fun ItunesAlbumDetail(
previewingId: Long?, previewingId: Long?,
onPreview: (ItunesItem) -> Unit, onPreview: (ItunesItem) -> Unit,
onDownload: (ItunesItem) -> Unit = {}, onDownload: (ItunesItem) -> Unit = {},
onArtistClick: ((ItunesItem) -> Unit)? = null,
onBack: () -> Unit, onBack: () -> Unit,
) { ) {
Column(Modifier.fillMaxSize()) { Column(Modifier.fillMaxSize()) {
@@ -458,9 +538,25 @@ internal fun ItunesAlbumDetail(
Icon(Icons.AutoMirrored.Filled.ArrowBack, "Zurück", Icon(Icons.AutoMirrored.Filled.ArrowBack, "Zurück",
tint = MaterialTheme.colorScheme.onSurface) tint = MaterialTheme.colorScheme.onSurface)
} }
// Anklickbar nur, wenn Deezer eine Künstler-id mitgeliefert hat — /artist/{id}/albums
// lässt das artist-Objekt weg, dort bleibt der Name einfach Text.
val artistName = albumItem?.artistName
val artistTippbar = onArtistClick != null && albumItem?.artistId != null &&
!artistName.isNullOrBlank()
Column(
Modifier.weight(1f).then(
if (artistTippbar) Modifier.clickable { onArtistClick!!(albumItem!!) } else Modifier
)
) {
Text(title, fontFamily = Outfit, fontWeight = FontWeight.Bold, Text(title, fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = 16.sp, maxLines = 1, overflow = TextOverflow.Ellipsis, fontSize = 16.sp, maxLines = 1, overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colorScheme.onSurface, modifier = Modifier.weight(1f)) color = MaterialTheme.colorScheme.onSurface)
if (!artistName.isNullOrBlank()) {
Text(artistName, fontFamily = Outfit, fontSize = 12.sp,
maxLines = 1, overflow = TextOverflow.Ellipsis,
color = if (artistTippbar) NsAccent else NsOnSurface2)
}
}
if (albumItem != null) { if (albumItem != null) {
IconButton(onClick = { onDownload(albumItem) }) { IconButton(onClick = { onDownload(albumItem) }) {
Icon(Icons.Default.Download, "Album herunterladen", Icon(Icons.Default.Download, "Album herunterladen",
@@ -579,17 +675,47 @@ private fun ItunesTrackRow(
} }
@Composable @Composable
private fun SmallArtistChip(name: String, onClick: () -> Unit) { private fun ArtistCard(name: String, imageUrl: String?, subtitle: String? = null, onClick: () -> Unit) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.width(80.dp)
.clickable(onClick = onClick),
) {
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = Modifier modifier = Modifier
.clip(RoundedCornerShape(20.dp)) .size(72.dp)
.background(NsSurface2) .clip(androidx.compose.foundation.shape.CircleShape)
.clickable(onClick = onClick) .background(NsSurface2),
.padding(horizontal = 14.dp, vertical = 8.dp),
) { ) {
Text(name, fontFamily = Outfit, fontSize = 13.sp, color = NsOnSurface, if (imageUrl != null) {
maxLines = 1, overflow = TextOverflow.Ellipsis) AsyncImage(
model = imageUrl,
contentDescription = name,
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize(),
)
} else {
Icon(
Icons.Default.Person, contentDescription = null,
tint = NsOnSurface2, modifier = Modifier.size(32.dp),
)
}
}
Spacer(Modifier.height(6.dp))
Text(
name, fontFamily = Outfit, fontSize = 12.sp, fontWeight = FontWeight.Medium,
color = NsOnSurface, maxLines = 2, overflow = TextOverflow.Ellipsis,
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
)
if (subtitle != null) {
Text(
subtitle, fontFamily = Outfit, fontSize = 10.sp, fontWeight = FontWeight.Medium,
color = NsOnSurface2, maxLines = 1, overflow = TextOverflow.Ellipsis,
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
)
}
} }
} }
@@ -0,0 +1,96 @@
package com.novasonic.app.ui.screen
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.novasonic.app.api.model.Genre
import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.GenreViewModel
@Composable
fun GenreListScreen(
onGenreClick: (Genre) -> Unit,
onGenrePlay: (Genre) -> Unit,
onBack: () -> Unit,
) {
val vm: GenreViewModel = viewModel()
val state by vm.state.collectAsStateWithLifecycle()
Column(Modifier.fillMaxSize()) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 4.dp, end = 16.dp, top = 8.dp, bottom = 4.dp),
) {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, "Zurück", tint = NsOnSurface2)
}
Text(
"Alle Genres",
fontFamily = Outfit,
fontWeight = FontWeight.Bold,
fontSize = 18.sp,
color = NsOnSurface,
)
}
when {
state.isLoading -> {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent)
}
}
state.error != null -> {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize().padding(32.dp),
) {
Text(state.error!!, color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodyMedium)
Spacer(Modifier.height(12.dp))
Button(onClick = { vm.load() },
colors = ButtonDefaults.buttonColors(containerColor = NsAccent)) {
Text("Retry")
}
}
}
else -> {
LazyColumn(
contentPadding = PaddingValues(bottom = 24.dp),
modifier = Modifier.fillMaxSize(),
) {
val chunked = state.genres.chunked(2)
chunked.forEachIndexed { rowIdx, rowGenres ->
item(key = "row_$rowIdx") {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),
) {
rowGenres.forEachIndexed { colIdx, genre ->
val colorIdx = (rowIdx * 2 + colIdx) % genreColors.size
GenreChip(
genre = genre,
bgColor = genreColors[colorIdx],
onClick = { onGenreClick(genre) },
onPlay = { onGenrePlay(genre) },
modifier = Modifier.weight(1f),
)
}
if (rowGenres.size == 1) Spacer(Modifier.weight(1f))
}
}
}
}
}
}
}
}
@@ -2,6 +2,7 @@
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
@@ -18,6 +19,7 @@ import com.novasonic.app.app
import com.novasonic.app.player.PlayerState import com.novasonic.app.player.PlayerState
import com.novasonic.app.ui.component.SongRow import com.novasonic.app.ui.component.SongRow
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.ui.component.Rollbalken
@Composable @Composable
fun GenreSongsScreen( fun GenreSongsScreen(
@@ -77,7 +79,10 @@ fun GenreSongsScreen(
songs.isEmpty() -> Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) { songs.isEmpty() -> Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) {
Text("Keine Songs gefunden", color = NsOnSurface2) Text("Keine Songs gefunden", color = NsOnSurface2)
} }
else -> LazyColumn { else -> {
val listState = rememberLazyListState()
Box(Modifier.fillMaxSize()) {
LazyColumn(Modifier.fillMaxSize(), state = listState) {
itemsIndexed(songs, key = { _, s -> s.id }) { idx, song -> itemsIndexed(songs, key = { _, s -> s.id }) { idx, song ->
SongRow( SongRow(
song = song, song = song,
@@ -91,6 +96,13 @@ fun GenreSongsScreen(
} }
item { Spacer(Modifier.height(8.dp)) } item { Spacer(Modifier.height(8.dp)) }
} }
Rollbalken(
state = listState,
modifier = Modifier.align(Alignment.CenterEnd).padding(vertical = 4.dp),
farbe = NsOnSurface2,
)
}
}
} }
} }
} }
@@ -1,4 +1,4 @@
package com.novasonic.app.ui.screen package com.novasonic.app.ui.screen
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
@@ -9,6 +9,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@@ -27,12 +28,42 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.novasonic.app.api.model.Album import com.novasonic.app.api.model.Album
import com.novasonic.app.api.model.Genre import com.novasonic.app.api.model.Genre
import com.novasonic.app.data.NotificationStore
import com.novasonic.app.ui.component.AlbumCard import com.novasonic.app.ui.component.AlbumCard
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.HomeViewModel import com.novasonic.app.viewmodel.HomeViewModel
import java.util.Calendar import androidx.compose.ui.res.painterResource
import com.novasonic.app.R
private val genreColors = listOf( private val greetingsWithName = listOf(
"Ready for some beats,",
"What's on the playlist,",
"Good vibes only,",
"Let the music play,",
"Your soundtrack awaits,",
"Turn it up,",
"Time to tune in,",
"Hit play and chill,",
"Music is the answer,",
"Welcome back,",
)
private val greetingsNoName = listOf(
"Ready for some beats?",
"What's on the playlist today?",
"Good vibes only",
"Let the music play",
"Your soundtrack awaits",
"Turn it up",
"Time to tune in",
"Hit play and chill",
"Music is the answer",
"What are we listening to?",
"Time to escape into music",
"Pick something great",
)
internal val genreColors = listOf(
Color(0xFF1a1a3e), Color(0xFF1e2a1a), Color(0xFF2a1a1a), Color(0xFF1a1a3e), Color(0xFF1e2a1a), Color(0xFF2a1a1a),
Color(0xFF1a2a2a), Color(0xFF2a1e1a), Color(0xFF1e1a2a), Color(0xFF1a2a2a), Color(0xFF2a1e1a), Color(0xFF1e1a2a),
Color(0xFF2a2a1a), Color(0xFF1a2a1e), Color(0xFF201520), Color(0xFF2a2a1a), Color(0xFF1a2a1e), Color(0xFF201520),
@@ -46,18 +77,20 @@ fun HomeScreen(
onAlbumPlay: (Album) -> Unit, onAlbumPlay: (Album) -> Unit,
onGenreClick: (Genre) -> Unit, onGenreClick: (Genre) -> Unit,
onGenrePlay: ((Genre) -> Unit)? = null, onGenrePlay: ((Genre) -> Unit)? = null,
onShowAllGenres: (() -> Unit)? = null,
onBellClick: () -> Unit = {},
onSettingsClick: () -> Unit = {},
refreshKey: Int = 0,
) { ) {
val vm: HomeViewModel = viewModel() val vm: HomeViewModel = viewModel()
val state by vm.state.collectAsStateWithLifecycle() val state by vm.state.collectAsStateWithLifecycle()
val notifs by NotificationStore.items.collectAsStateWithLifecycle()
val unreadCount = notifs.count { !it.read }
val greeting = remember { LaunchedEffect(refreshKey) { if (refreshKey > 0) vm.load() }
val hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY)
when { val greeting = remember { greetingsNoName.random() }
hour < 12 -> "Guten Morgen" val greetingWithName = remember { greetingsWithName.random() }
hour < 18 -> "Guten Tag"
else -> "Guten Abend"
}
}
LazyColumn( LazyColumn(
contentPadding = PaddingValues(bottom = 24.dp), contentPadding = PaddingValues(bottom = 24.dp),
@@ -65,14 +98,37 @@ fun HomeScreen(
) { ) {
item { item {
val name = state.username.replaceFirstChar { it.uppercaseChar() } val name = state.username.replaceFirstChar { it.uppercaseChar() }
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 16.dp, end = 8.dp, top = 24.dp, bottom = 20.dp),
) {
Text( Text(
text = if (name.isBlank()) greeting else "$greeting, $name 👋", text = if (name.isBlank()) greeting else "$greetingWithName $name",
fontFamily = Outfit, fontFamily = Outfit,
fontSize = 24.sp, fontSize = 24.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
color = NsOnSurface, color = NsOnSurface,
modifier = Modifier.padding(start = 16.dp, top = 24.dp, bottom = 20.dp), modifier = Modifier.weight(1f),
) )
BadgedBox(
badge = {
if (unreadCount > 0) Badge(containerColor = NsAccent) {
Text(
if (unreadCount > 9) "9+" else "$unreadCount",
fontSize = 9.sp, color = NsBackground,
)
}
}
) {
IconButton(onClick = onBellClick) {
Icon(painterResource(R.drawable.ic_honigtopf_brief), "Benachrichtigungen",
tint = if (unreadCount > 0) NsAccent else NsOnSurface2)
}
}
IconButton(onClick = onSettingsClick) {
Icon(Icons.Default.Settings, "Einstellungen", tint = NsOnSurface2)
}
}
} }
if (state.isLoading) { if (state.isLoading) {
@@ -102,11 +158,12 @@ fun HomeScreen(
return@LazyColumn return@LazyColumn
} }
// Hero card — matches PWA .home-hero (170px height) // Hero card — pool = frequent(5) ∪ recentlyPlayed(5), label from web
state.heroAlbum?.let { hero -> state.heroAlbum?.let { hero ->
item { item {
HeroCard( HeroCard(
album = hero, album = hero,
label = state.heroLabel,
coverUrl = coverUrl(hero), coverUrl = coverUrl(hero),
onPlay = { onAlbumPlay(hero) }, onPlay = { onAlbumPlay(hero) },
onClick = { onAlbumClick(hero) }, onClick = { onAlbumClick(hero) },
@@ -118,8 +175,28 @@ fun HomeScreen(
if (state.genres.isNotEmpty()) { if (state.genres.isNotEmpty()) {
item { SectionHeader("Genres") } item { SectionHeader("Genres") }
item { item {
GenreGrid(genres = state.genres, onGenreClick = onGenreClick, onGenrePlay = onGenrePlay) GenreGrid(genres = state.genres.take(6), onGenreClick = onGenreClick, onGenrePlay = onGenrePlay)
Spacer(Modifier.height(28.dp)) if (onShowAllGenres != null && state.genres.size > 6) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 10.dp)
.clip(RoundedCornerShape(10.dp))
.background(NsSurface)
.clickable(onClick = onShowAllGenres)
.padding(vertical = 12.dp),
) {
Text(
"Alle anzeigen · ${state.genres.size}",
fontFamily = Outfit,
fontWeight = FontWeight.SemiBold,
fontSize = 13.sp,
color = NsAccent,
)
}
}
Spacer(Modifier.height(20.dp))
} }
} }
@@ -130,10 +207,10 @@ fun HomeScreen(
Spacer(Modifier.height(28.dp)) Spacer(Modifier.height(28.dp))
} }
} }
if (state.frequentAlbums.isNotEmpty()) { if (state.recentlyPlayedAlbums.isNotEmpty()) {
item { SectionHeader("Meistgespielt") } item { SectionHeader("Zuletzt gehört") }
item { item {
AlbumRow(albums = state.frequentAlbums, coverUrl = coverUrl, onAlbumClick = onAlbumClick) AlbumRow(albums = state.recentlyPlayedAlbums, coverUrl = coverUrl, onAlbumClick = onAlbumClick)
Spacer(Modifier.height(28.dp)) Spacer(Modifier.height(28.dp))
} }
} }
@@ -141,6 +218,13 @@ fun HomeScreen(
item { SectionHeader("Entdecken") } item { SectionHeader("Entdecken") }
item { item {
AlbumRow(albums = state.randomAlbums, coverUrl = coverUrl, onAlbumClick = onAlbumClick) AlbumRow(albums = state.randomAlbums, coverUrl = coverUrl, onAlbumClick = onAlbumClick)
Spacer(Modifier.height(28.dp))
}
}
if (state.frequentAlbums.isNotEmpty()) {
item { SectionHeader("Meistgespielt") }
item {
AlbumRow(albums = state.frequentAlbums, coverUrl = coverUrl, onAlbumClick = onAlbumClick)
Spacer(Modifier.height(16.dp)) Spacer(Modifier.height(16.dp))
} }
} }
@@ -151,7 +235,7 @@ fun HomeScreen(
// background = blur(8px) brightness(.45) + horizontal gradient overlay // background = blur(8px) brightness(.45) + horizontal gradient overlay
// cover = 100x100, border-radius:9px // cover = 100x100, border-radius:9px
@Composable @Composable
private fun HeroCard(album: Album, coverUrl: String?, onPlay: () -> Unit, onClick: () -> Unit) { private fun HeroCard(album: Album, label: String, coverUrl: String?, onPlay: () -> Unit, onClick: () -> Unit) {
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@@ -160,25 +244,20 @@ private fun HeroCard(album: Album, coverUrl: String?, onPlay: () -> Unit, onClic
.clip(RoundedCornerShape(14.dp)) .clip(RoundedCornerShape(14.dp))
.clickable(onClick = onClick), .clickable(onClick = onClick),
) { ) {
// Blurred background image — matches .home-hero-bg
AsyncImage( AsyncImage(
model = coverUrl, contentDescription = null, model = coverUrl, contentDescription = null,
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize().blur(16.dp), modifier = Modifier.fillMaxSize().blur(16.dp),
) )
// Gradient overlay — matches .home-hero-overlay
// linear-gradient(to right, rgba(7,7,15,.88) 0%, rgba(7,7,15,.3) 100%)
Box( Box(
modifier = Modifier.fillMaxSize().background( modifier = Modifier.fillMaxSize().background(
Brush.horizontalGradient(listOf(Color(0xE107070F), Color(0x4D07070F))) Brush.horizontalGradient(listOf(Color(0xE107070F), Color(0x4D07070F)))
) )
) )
// Content row
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxSize().padding(horizontal = 20.dp, vertical = 16.dp), modifier = Modifier.fillMaxSize().padding(horizontal = 20.dp, vertical = 16.dp),
) { ) {
// Cover art — 100dp, matches .home-hero-cover (100px, border-radius:9px)
AsyncImage( AsyncImage(
model = coverUrl, contentDescription = album.name, model = coverUrl, contentDescription = album.name,
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
@@ -188,10 +267,13 @@ private fun HeroCard(album: Album, coverUrl: String?, onPlay: () -> Unit, onClic
.background(NsSurface2), .background(NsSurface2),
) )
Spacer(Modifier.width(16.dp)) Spacer(Modifier.width(16.dp))
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.weight(1f),
) {
Column(Modifier.weight(1f)) { Column(Modifier.weight(1f)) {
// Label — matches .home-hero-label
Text( Text(
text = "AKTUELL", text = label,
fontFamily = Outfit, fontFamily = Outfit,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
fontSize = 10.sp, fontSize = 10.sp,
@@ -219,8 +301,8 @@ private fun HeroCard(album: Album, coverUrl: String?, onPlay: () -> Unit, onClic
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
} }
Spacer(Modifier.height(12.dp)) }
// Play button — matches .home-hero-play (42px circle, accent bg) Spacer(Modifier.width(12.dp))
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = Modifier modifier = Modifier
@@ -238,7 +320,7 @@ private fun HeroCard(album: Album, coverUrl: String?, onPlay: () -> Unit, onClic
} }
@Composable @Composable
private fun GenreGrid( internal fun GenreGrid(
genres: List<Genre>, genres: List<Genre>,
onGenreClick: (Genre) -> Unit, onGenreClick: (Genre) -> Unit,
onGenrePlay: ((Genre) -> Unit)?, onGenrePlay: ((Genre) -> Unit)?,
@@ -267,7 +349,7 @@ private fun GenreGrid(
} }
@Composable @Composable
private fun GenreChip( internal fun GenreChip(
genre: Genre, genre: Genre,
bgColor: Color, bgColor: Color,
onClick: () -> Unit, onClick: () -> Unit,
@@ -330,7 +412,6 @@ private fun AlbumRow(albums: List<Album>, coverUrl: (Album) -> String?, onAlbumC
} }
} }
// PWA: .section-header { font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:1.5px }
@Composable @Composable
private fun SectionHeader(title: String) { private fun SectionHeader(title: String) {
Text( Text(
@@ -12,6 +12,8 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Download import androidx.compose.material.icons.filled.Download
import androidx.compose.material.icons.filled.PlayCircle
import androidx.compose.material.icons.filled.Stop
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@@ -180,6 +182,38 @@ fun ImporterScreen(onBack: () -> Unit) {
} }
} }
// Playlist aus dem Import anlegen — wie im Web-Importer. Nur ab zwei Titeln sinnvoll;
// ein einzelner Track ergibt keine Playlist.
if (r.tracks.size > 1) {
item {
Column(Modifier.fillMaxWidth().padding(bottom = 10.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox(
checked = state.createPlaylist,
onCheckedChange = vm::setCreatePlaylist,
colors = CheckboxDefaults.colors(checkedColor = brand,
checkmarkColor = Color.Black),
)
Text("Playlist daraus anlegen", fontFamily = Outfit, fontSize = 14.sp,
color = NsOnSurface)
}
if (state.createPlaylist) {
OutlinedTextField(
value = state.playlistName.ifBlank { r.name ?: "" },
onValueChange = vm::setPlaylistName,
label = { Text("Playlist-Name", fontFamily = Outfit) },
singleLine = true,
modifier = Modifier.fillMaxWidth().padding(top = 4.dp),
)
}
state.playlistStatus?.let {
Text(it, fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
modifier = Modifier.padding(top = 6.dp))
}
}
}
}
// Download button / job progress // Download button / job progress
item { item {
if (state.isDownloading || state.jobStatus == "done" || state.jobStatus == "error") { if (state.isDownloading || state.jobStatus == "done" || state.jobStatus == "error") {
@@ -205,7 +239,12 @@ fun ImporterScreen(onBack: () -> Unit) {
} }
itemsIndexed(r.tracks) { idx, track -> itemsIndexed(r.tracks) { idx, track ->
ImportTrackRow(idx + 1, track) ImportTrackRow(
num = idx + 1,
track = track,
isPreviewing = state.previewingId != null && state.previewingId == vm.previewId(track),
onPreview = { vm.togglePreview(track) },
)
} }
} }
} }
@@ -258,7 +297,12 @@ private fun JobProgress(
} }
@Composable @Composable
private fun ImportTrackRow(num: Int, track: ImportTrack) { private fun ImportTrackRow(
num: Int,
track: ImportTrack,
isPreviewing: Boolean,
onPreview: () -> Unit,
) {
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp), modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),
@@ -272,11 +316,22 @@ private fun ImportTrackRow(num: Int, track: ImportTrack) {
Spacer(Modifier.width(12.dp)) Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) { Column(Modifier.weight(1f)) {
Text(track.trackName ?: "—", fontFamily = Outfit, fontWeight = FontWeight.Medium, Text(track.trackName ?: "—", fontFamily = Outfit, fontWeight = FontWeight.Medium,
fontSize = 14.sp, color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis) fontSize = 14.sp, color = if (isPreviewing) NsAccent else NsOnSurface,
maxLines = 1, overflow = TextOverflow.Ellipsis)
if (!track.artistName.isNullOrBlank()) { if (!track.artistName.isNullOrBlank()) {
Text(track.artistName, fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2, Text(track.artistName, fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
maxLines = 1, overflow = TextOverflow.Ellipsis) maxLines = 1, overflow = TextOverflow.Ellipsis)
} }
} }
// 30s preview — only when the source provided a clip
if (track.previewUrl != null) {
IconButton(onClick = onPreview, modifier = Modifier.size(36.dp)) {
Icon(
if (isPreviewing) Icons.Default.Stop else Icons.Default.PlayCircle,
if (isPreviewing) "Stop" else "Preview",
tint = if (isPreviewing) NsAccent else NsOnSurface2,
)
}
}
} }
} }
@@ -7,13 +7,18 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items as gridItems
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.* import androidx.compose.material.icons.filled.*
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.Composable import androidx.compose.runtime.*
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur import androidx.compose.ui.draw.blur
@@ -29,12 +34,15 @@ import coil.compose.AsyncImage
import com.novasonic.app.api.model.Album import com.novasonic.app.api.model.Album
import com.novasonic.app.api.model.ItunesItem import com.novasonic.app.api.model.ItunesItem
import com.novasonic.app.api.model.Song import com.novasonic.app.api.model.Song
import com.novasonic.app.api.model.fmtFanCount
import com.novasonic.app.player.PlayerState import com.novasonic.app.player.PlayerState
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.ItunesArtistState import com.novasonic.app.viewmodel.ItunesArtistState
private fun normAlbum(s: String?): String = private fun normAlbum(s: String?): String =
(s ?: "").lowercase().replace(Regex("[^a-z0-9\\s]"), " ").replace(Regex("\\s+"), " ").trim() // Keep Unicode letters/numbers (\p{L}\p{N}) — stripping to a-z0-9 emptied every Japanese/CJK
// title, so all of an artist's JP singles collapsed into one and "matched" each other.
(s ?: "").lowercase().replace(Regex("[^\\p{L}\\p{N}\\s]"), " ").replace(Regex("\\s+"), " ").trim()
data class ArtistAlbumCategories( data class ArtistAlbumCategories(
val downloaded: List<Pair<Album, ItunesItem?>>, val downloaded: List<Pair<Album, ItunesItem?>>,
@@ -52,6 +60,9 @@ fun categorizeAlbums(ndAlbums: List<Album>, iAlbums: List<ItunesItem>): ArtistAl
for (ia in uniqueIAlbums) { for (ia in uniqueIAlbums) {
val iName = normAlbum(ia.collectionName) val iName = normAlbum(ia.collectionName)
// Deezer's /artist/{id}/albums omits nb_tracks, so trackCount is usually unknown (0) here.
// Only mark "Unvollständig" when we KNOW the album has more tracks than we own — an unknown
// total counts as complete, never a false "1 / 0".
val iCount = ia.trackCount ?: 0 val iCount = ia.trackCount ?: 0
val match = ndAlbums.find { a -> val match = ndAlbums.find { a ->
val n = normAlbum(a.name) val n = normAlbum(a.name)
@@ -59,11 +70,15 @@ fun categorizeAlbums(ndAlbums: List<Album>, iAlbums: List<ItunesItem>): ArtistAl
} }
when { when {
match == null -> notDl.add(ia) match == null -> notDl.add(ia)
iCount > 0 && match.songCount >= iCount -> { // Deezer returns the same album as several variants (single/EP/album/regional); distinctBy
downloaded.add(Pair(match, ia)); usedNdIds.add(match.id) // above only catches identical ids, so also skip an owned album we've already classified —
// otherwise it shows 2-3x ("PIXELATED KISSES").
match.id in usedNdIds -> Unit
iCount > match.songCount -> {
partial.add(Triple(match, ia, Pair(match.songCount, iCount))); usedNdIds.add(match.id)
} }
else -> { else -> {
partial.add(Triple(match, ia, Pair(match.songCount, iCount))); usedNdIds.add(match.id) downloaded.add(Pair(match, ia)); usedNdIds.add(match.id)
} }
} }
} }
@@ -91,12 +106,54 @@ fun ItunesArtistScreen(
onItunesAlbumOpen: (ItunesItem) -> Unit, onItunesAlbumOpen: (ItunesItem) -> Unit,
onItunesTrackPreview: (ItunesItem) -> Unit, onItunesTrackPreview: (ItunesItem) -> Unit,
previewingId: Long?, previewingId: Long?,
allAlbumsOpen: String?,
onOpenAllAlbums: (String) -> Unit,
onCloseAllAlbums: () -> Unit,
allAlbumsGrid: androidx.compose.foundation.lazy.grid.LazyGridState = androidx.compose.foundation.lazy.grid.rememberLazyGridState(),
allAlbumsQuery: String = "",
onAllAlbumsQueryChange: (String) -> Unit = {},
) { ) {
val artist = artistState.artist val artist = artistState.artist
val cats = if (!artistState.isLoading) val cats = if (!artistState.isLoading)
categorizeAlbums(artistState.ndAlbums, artistState.iAlbums) categorizeAlbums(artistState.ndAlbums, artistState.iAlbums)
else null else null
// "All albums" state is hoisted (ExploreViewModel.artistAllAlbums) so it survives an album
// drill-down and back; entries are re-derived from cats for whichever section is open.
val allAlbumEntries: List<AllAlbumEntry> = when (allAlbumsOpen) {
"In Library" -> cats?.downloaded?.map { (nd, _) ->
AllAlbumEntry(name = nd.name, year = nd.year?.toString(), artUrl = coverUrl(nd.coverArt), onClick = { onAlbumClick(nd) })
}.orEmpty()
"Unvollständig" -> cats?.partial?.map { (nd, ia, counts) ->
AllAlbumEntry(
name = nd.name, year = nd.year?.toString(),
artUrl = ia.artworkUrl100?.replace("100x100bb", "300x300bb") ?: coverUrl(nd.coverArt),
badge = "${counts.first}/${counts.second}",
onClick = { onPartialAlbumOpen(nd, ia) }, onDownload = { onDownload(ia) },
)
}.orEmpty()
"Nicht heruntergeladen" -> cats?.notDownloaded?.map { ia ->
AllAlbumEntry(
name = ia.collectionName ?: "—", year = ia.releaseDate?.take(4),
artUrl = ia.artworkUrl100?.replace("100x100bb", "300x300bb"), dimmed = true,
onClick = { onItunesAlbumOpen(ia) }, onDownload = { onDownload(ia) },
)
}.orEmpty()
else -> emptyList()
}
if (allAlbumsOpen != null) {
AllAlbumsOverlay(
title = allAlbumsOpen,
entries = allAlbumEntries,
onBack = onCloseAllAlbums,
gridState = allAlbumsGrid,
query = allAlbumsQuery,
onQueryChange = onAllAlbumsQueryChange,
)
return
}
// Pick backdrop: first Navidrome album cover, else first iTunes album art // Pick backdrop: first Navidrome album cover, else first iTunes album art
val backdropUrl = artistState.ndAlbums.firstOrNull()?.let { coverUrl(it.coverArt) } val backdropUrl = artistState.ndAlbums.firstOrNull()?.let { coverUrl(it.coverArt) }
?: artistState.iAlbums.firstOrNull()?.artworkUrl100?.replace("100x100bb", "300x300bb") ?: artistState.iAlbums.firstOrNull()?.artworkUrl100?.replace("100x100bb", "300x300bb")
@@ -144,6 +201,10 @@ fun ItunesArtistScreen(
Text(artist.primaryGenreName!!, fontFamily = Outfit, Text(artist.primaryGenreName!!, fontFamily = Outfit,
fontSize = 13.sp, color = Color.White.copy(0.6f)) fontSize = 13.sp, color = Color.White.copy(0.6f))
} }
artist.fanCount?.takeIf { it > 0 }?.let {
Text("${fmtFanCount(it)} Fans", fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 12.sp, color = Color.White.copy(0.55f))
}
} }
} }
@@ -164,7 +225,7 @@ fun ItunesArtistScreen(
Text("Top Songs", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 13.sp) Text("Top Songs", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 13.sp)
} }
OutlinedButton( OutlinedButton(
onClick = { onSongPlay(artistState.topSongs.shuffled(), 0) }, onClick = { onSongPlay(artistState.topSongs, -1) },
modifier = Modifier.weight(1f).height(42.dp), modifier = Modifier.weight(1f).height(42.dp),
shape = RoundedCornerShape(12.dp), shape = RoundedCornerShape(12.dp),
border = ButtonDefaults.outlinedButtonBorder(enabled = true) border = ButtonDefaults.outlinedButtonBorder(enabled = true)
@@ -190,7 +251,7 @@ fun ItunesArtistScreen(
// iTunes top tracks // iTunes top tracks
if (artistState.iTracks.isNotEmpty()) { if (artistState.iTracks.isNotEmpty()) {
item { ArtistSectionHeader("Weltweit populär (iTunes)") } item { ArtistSectionHeader("Weltweit populär (Deezer)") }
itemsIndexed(artistState.iTracks, key = { _, t -> t.trackId ?: 0L }) { _, track -> itemsIndexed(artistState.iTracks, key = { _, t -> t.trackId ?: 0L }) { _, track ->
ItunesArtistTrackRow( ItunesArtistTrackRow(
track = track, track = track,
@@ -204,7 +265,11 @@ fun ItunesArtistScreen(
// ── Downloaded albums ───────────────────────────────────────────── // ── Downloaded albums ─────────────────────────────────────────────
cats?.let { c -> cats?.let { c ->
if (c.downloaded.isNotEmpty()) { if (c.downloaded.isNotEmpty()) {
item { ArtistSectionHeader("In Library", c.downloaded.size) } item {
ArtistSectionHeader("In Library", c.downloaded.size,
onShowAll = if (c.downloaded.size > 4) ({ onOpenAllAlbums("In Library") }) else null
)
}
item { item {
LazyRow( LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp), contentPadding = PaddingValues(horizontal = 16.dp),
@@ -225,7 +290,11 @@ fun ItunesArtistScreen(
// ── Partial albums ──────────────────────────────────────────── // ── Partial albums ────────────────────────────────────────────
if (c.partial.isNotEmpty()) { if (c.partial.isNotEmpty()) {
item { ArtistSectionHeader("Unvollständig", c.partial.size) } item {
ArtistSectionHeader("Unvollständig", c.partial.size,
onShowAll = if (c.partial.size > 4) ({ onOpenAllAlbums("Unvollständig") }) else null
)
}
item { item {
LazyRow( LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp), contentPadding = PaddingValues(horizontal = 16.dp),
@@ -248,7 +317,11 @@ fun ItunesArtistScreen(
// ── Not downloaded ──────────────────────────────────────────── // ── Not downloaded ────────────────────────────────────────────
if (c.notDownloaded.isNotEmpty()) { if (c.notDownloaded.isNotEmpty()) {
item { ArtistSectionHeader("Nicht heruntergeladen", c.notDownloaded.size) } item {
ArtistSectionHeader("Nicht heruntergeladen", c.notDownloaded.size,
onShowAll = if (c.notDownloaded.size > 4) ({ onOpenAllAlbums("Nicht heruntergeladen") }) else null
)
}
item { item {
LazyRow( LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp), contentPadding = PaddingValues(horizontal = 16.dp),
@@ -384,7 +457,7 @@ internal fun ItunesArtistTrackRow(
} }
@Composable @Composable
internal fun ArtistSectionHeader(title: String, count: Int? = null) { internal fun ArtistSectionHeader(title: String, count: Int? = null, onShowAll: (() -> Unit)? = null) {
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 20.dp, top = 16.dp, bottom = 10.dp, end = 16.dp), modifier = Modifier.padding(start = 20.dp, top = 16.dp, bottom = 10.dp, end = 16.dp),
@@ -399,5 +472,13 @@ internal fun ArtistSectionHeader(title: String, count: Int? = null) {
.background(NsSurface2) .background(NsSurface2)
.padding(horizontal = 7.dp, vertical = 2.dp)) .padding(horizontal = 7.dp, vertical = 2.dp))
} }
if (onShowAll != null) {
Spacer(Modifier.width(10.dp))
Text(
"Alle anzeigen",
fontFamily = Outfit, fontSize = 12.sp, color = NsAccent,
modifier = Modifier.clickable(onClick = onShowAll),
)
}
} }
} }
@@ -8,16 +8,26 @@ import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
@@ -27,10 +37,20 @@ import coil.compose.AsyncImage
import com.novasonic.app.api.model.Album import com.novasonic.app.api.model.Album
import com.novasonic.app.api.model.Artist import com.novasonic.app.api.model.Artist
import com.novasonic.app.api.model.Playlist import com.novasonic.app.api.model.Playlist
import com.novasonic.app.offline.DownloadGroupEntity
import com.novasonic.app.offline.GroupType
import com.novasonic.app.ui.component.AlbumCard import com.novasonic.app.ui.component.AlbumCard
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.AlbumSort
import com.novasonic.app.viewmodel.LibraryTab import com.novasonic.app.viewmodel.LibraryTab
import com.novasonic.app.viewmodel.LibraryViewModel import com.novasonic.app.viewmodel.LibraryViewModel
import com.novasonic.app.viewmodel.OfflineViewModel
import kotlinx.coroutines.launch
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.DownloadDone
import androidx.compose.material.icons.filled.DownloadForOffline
import androidx.compose.material.icons.filled.PlayArrow
import com.novasonic.app.api.model.Song
@Composable @Composable
fun LibraryScreen( fun LibraryScreen(
@@ -38,19 +58,58 @@ fun LibraryScreen(
onAlbumClick: (Album) -> Unit, onAlbumClick: (Album) -> Unit,
onArtistClick: (Artist) -> Unit, onArtistClick: (Artist) -> Unit,
onPlaylistClick: (Playlist) -> Unit, onPlaylistClick: (Playlist) -> Unit,
onPlay: (List<Song>, Int) -> Unit,
onOpenOffline: (DownloadGroupEntity) -> Unit,
) { ) {
val vm: LibraryViewModel = viewModel() val vm: LibraryViewModel = viewModel()
val state by vm.state.collectAsStateWithLifecycle() val state by vm.state.collectAsStateWithLifecycle()
val offlineVm: OfflineViewModel = viewModel()
// Absicht aus den Favoriten ("Alle anzeigen" bei den gefolgten Künstlern) einmalig einlösen.
LaunchedEffect(Unit) {
if (com.novasonic.app.data.LibraryIntent.oeffneGefolgte) {
com.novasonic.app.data.LibraryIntent.oeffneGefolgte = false
vm.selectTab(LibraryTab.ARTISTS)
vm.nurGefolgteUmschalten(true)
}
}
val offlineGroups by offlineVm.groups.collectAsStateWithLifecycle()
// Fully-downloaded source IDs per type — drives the "downloaded" badge on cards.
val downloadedAlbumIds = remember(offlineGroups) {
offlineGroups.filter { it.type == GroupType.ALBUM && it.totalTracks > 0 && it.downloadedTracks >= it.totalTracks }
.map { it.sourceId }.toSet()
}
val downloadedPlaylistIds = remember(offlineGroups) {
offlineGroups.filter { it.type == GroupType.PLAYLIST && it.totalTracks > 0 && it.downloadedTracks >= it.totalTracks }
.map { it.sourceId }.toSet()
}
var showCreateDialog by remember { mutableStateOf(false) }
var groupToDelete by remember { mutableStateOf<DownloadGroupEntity?>(null) }
// Swipe left/right to switch library tabs, kept in sync with the TabRow (like Erkunden): a chip
// tap animates the pager; a settled swipe updates the selected tab. Indicator is driven off the
// pager's current page so it moves WITH the swipe.
val pagerState = rememberPagerState(initialPage = state.tab.ordinal) { LibraryTab.entries.size }
LaunchedEffect(state.tab) {
if (pagerState.currentPage != state.tab.ordinal) pagerState.animateScrollToPage(state.tab.ordinal)
}
LaunchedEffect(pagerState.settledPage) {
val t = LibraryTab.entries[pagerState.settledPage]
if (t != state.tab) vm.selectTab(t)
}
Box(Modifier.fillMaxSize()) {
Column(Modifier.fillMaxSize()) { Column(Modifier.fillMaxSize()) {
TabRow( TabRow(
selectedTabIndex = state.tab.ordinal, selectedTabIndex = pagerState.currentPage,
containerColor = MaterialTheme.colorScheme.background, containerColor = MaterialTheme.colorScheme.background,
contentColor = NsAccent, contentColor = NsAccent,
) { ) {
LibraryTab.entries.forEach { tab -> LibraryTab.entries.forEach { tab ->
Tab( Tab(
selected = state.tab == tab, selected = pagerState.currentPage == tab.ordinal,
onClick = { vm.selectTab(tab) }, onClick = { vm.selectTab(tab) },
text = { text = {
Text( Text(
@@ -58,6 +117,7 @@ fun LibraryScreen(
LibraryTab.PLAYLISTS -> "Playlists" LibraryTab.PLAYLISTS -> "Playlists"
LibraryTab.ALBUMS -> "Alben" LibraryTab.ALBUMS -> "Alben"
LibraryTab.ARTISTS -> "Künstler" LibraryTab.ARTISTS -> "Künstler"
LibraryTab.OFFLINE -> "Offline"
}, },
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
@@ -69,36 +129,146 @@ fun LibraryScreen(
} }
} }
if (state.isLoading) { HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
val pageTab = LibraryTab.entries[page]
// The Offline tab is fed by the local Room DB (offlineGroups) and must stay usable even while
// the online library is still loading or unreachable — only gate the network-backed tabs.
if (state.isLoading && pageTab != LibraryTab.OFFLINE) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent) CircularProgressIndicator(color = NsAccent)
} }
return@Column } else when (pageTab) {
LibraryTab.ALBUMS -> Column(Modifier.fillMaxSize()) {
// Sort chips
androidx.compose.foundation.lazy.LazyRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
) {
items(AlbumSort.entries) { s ->
FilterChip(
selected = state.albumSort == s,
onClick = { vm.setAlbumSort(s) },
label = {
Text(when (s) {
AlbumSort.NEWEST -> "Neueste"
AlbumSort.OLDEST -> "Älteste"
AlbumSort.AZ -> "A-Z"
}, fontSize = 12.sp)
},
colors = FilterChipDefaults.filterChipColors(
selectedContainerColor = NsAccent.copy(alpha = 0.2f),
selectedLabelColor = NsAccent,
selectedLeadingIconColor = NsAccent,
),
)
} }
}
when (state.tab) { val sortedAlbums = remember(state.albumsByNewest, state.albumsByName, state.albumSort) {
LibraryTab.ALBUMS -> LazyVerticalGrid( when (state.albumSort) {
AlbumSort.NEWEST -> state.albumsByNewest // already ordered by Navidrome add-date
AlbumSort.AZ -> state.albumsByName // already ordered alphabetically
AlbumSort.OLDEST -> state.albumsByName.sortedWith(
compareBy<com.novasonic.app.api.model.Album> { it.year ?: Int.MAX_VALUE }
.thenBy { it.name.lowercase() }
)
}
}
val albumGridState = vm.albumsGridState // hoisted → survives album drill-in/back
// Kein LaunchedEffect(state.albumSort) zum Hochscrollen: der liefe auch beim ersten
// Compose nach dem Zurückkommen und würde die gemerkte Position sofort verwerfen.
// Das Hochscrollen passiert jetzt in vm.setAlbumSort(), also nur bei echtem Wechsel.
LazyVerticalGrid(
state = albumGridState,
columns = GridCells.Adaptive(minSize = 150.dp), columns = GridCells.Adaptive(minSize = 150.dp),
contentPadding = PaddingValues(16.dp), contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = 16.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp), horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalArrangement = Arrangement.spacedBy(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
) { ) {
items(state.albums, key = { it.id }) { album -> items(sortedAlbums, key = { it.id }) { album ->
AlbumCard( AlbumCard(
album = album, album = album,
coverUrl = coverUrl(album.coverArt), coverUrl = coverUrl(album.coverArt),
width = 150.dp, width = 150.dp,
downloaded = album.id in downloadedAlbumIds,
onClick = { onAlbumClick(album) }, onClick = { onAlbumClick(album) },
) )
} }
} }
}
LibraryTab.ARTISTS -> LazyColumn( LibraryTab.ARTISTS -> {
contentPadding = PaddingValues(vertical = 8.dp), val listState = vm.artistsListState // hoisted → survives artist drill-in/back
val scope = rememberCoroutineScope()
// "Gefolgt" filtert die vorhandene Liste — ein eigener Reiter wäre in einer Leiste,
// die schon vier Kacheln trägt, nur Gedränge.
val indizes = remember(state.artistIndexes, state.nurGefolgte, state.gefolgteIds) {
if (!state.nurGefolgte) state.artistIndexes
else state.artistIndexes
.map { idx -> idx.copy(artist = idx.artist.filter { it.id in state.gefolgteIds }) }
.filter { it.artist.isNotEmpty() }
}
val letters = remember(indizes) { indizes.map { it.name } }
// Map letter → flat LazyColumn index of its header item
val letterToIndex = remember(indizes) {
buildMap<String, Int> {
var flat = 0
indizes.forEach { idx ->
put(idx.name, flat)
flat += 1 + idx.artist.size
}
}
}
var activeLetter by remember { mutableStateOf<String?>(null) }
Column(Modifier.fillMaxSize()) {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.padding(start = 16.dp, top = 6.dp, bottom = 6.dp),
) {
FilterChip(
selected = !state.nurGefolgte,
onClick = { vm.nurGefolgteUmschalten(false) },
label = { Text("Alle", fontSize = 12.sp) },
colors = FilterChipDefaults.filterChipColors(
selectedContainerColor = NsAccent.copy(alpha = 0.2f),
selectedLabelColor = NsAccent),
)
FilterChip(
selected = state.nurGefolgte,
onClick = { vm.nurGefolgteUmschalten(true) },
label = {
val n = state.gefolgteIds.size
Text("❤ Gefolgt" + if (state.nurGefolgte && n > 0) " ($n)" else "",
fontSize = 12.sp)
},
colors = FilterChipDefaults.filterChipColors(
selectedContainerColor = NsAccent.copy(alpha = 0.2f),
selectedLabelColor = NsAccent),
)
}
if (state.nurGefolgte && indizes.isEmpty()) {
Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("❤", fontSize = 30.sp)
Spacer(Modifier.height(8.dp))
Text("Du folgst noch niemandem", fontFamily = Outfit,
fontWeight = FontWeight.SemiBold, fontSize = 14.sp,
color = MaterialTheme.colorScheme.onSurface)
Spacer(Modifier.height(4.dp))
Text("Auf einer Künstlerseite oben rechts aufs Herz tippen.",
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
}
return@Column
}
Box(Modifier.fillMaxSize()) {
LazyColumn(
state = listState,
contentPadding = PaddingValues(top = 8.dp, bottom = 8.dp, end = 28.dp),
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
) { ) {
state.artistIndexes.forEach { idx -> indizes.forEach { idx ->
item(key = "header_${idx.name}") { item(key = "header_${idx.name}") {
Text( Text(
text = idx.name, text = idx.name,
@@ -135,28 +305,328 @@ fun LibraryScreen(
} }
} }
LibraryTab.PLAYLISTS -> LazyVerticalGrid( if (letters.isNotEmpty()) {
columns = GridCells.Adaptive(minSize = 150.dp), // Bubble showing active letter while dragging
contentPadding = PaddingValues(16.dp), activeLetter?.let { letter ->
horizontalArrangement = Arrangement.spacedBy(12.dp), Box(
verticalArrangement = Arrangement.spacedBy(16.dp), contentAlignment = Alignment.Center,
modifier = Modifier
.align(Alignment.CenterEnd)
.offset(x = (-44).dp)
.size(52.dp)
.clip(CircleShape)
.background(NsAccent),
) {
Text(
text = letter,
fontSize = 22.sp,
fontWeight = FontWeight.Bold,
color = NsBackground,
)
}
}
// Vertical letter strip
Box(
modifier = Modifier
.align(Alignment.CenterEnd)
.fillMaxHeight()
.width(28.dp)
.pointerInput(letters) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent()
val y = event.changes.firstOrNull()?.position?.y ?: continue
val idx = ((y / size.height) * letters.size)
.toInt().coerceIn(0, letters.lastIndex)
val letter = letters[idx]
when (event.type) {
PointerEventType.Press,
PointerEventType.Move -> {
event.changes.forEach { it.consume() }
if (letter != activeLetter) {
activeLetter = letter
letterToIndex[letter]?.let { pos ->
scope.launch { listState.scrollToItem(pos) }
}
}
}
else -> activeLetter = null
}
}
}
},
) {
Column(
verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
) { ) {
items(state.playlists, key = { it.id }) { pl -> letters.forEach { letter ->
PlaylistCard( Text(
name = pl.name, text = letter,
subtitle = "${pl.songCount} Titel", fontSize = 10.sp,
coverUrl = coverUrl(pl.coverArt), fontWeight = if (letter == activeLetter) FontWeight.Bold else FontWeight.Normal,
onClick = { onPlaylistClick(pl) }, color = if (letter == activeLetter) NsAccent else NsOnSurface3,
textAlign = TextAlign.Center,
) )
} }
} }
} }
} }
}
}
}
LibraryTab.PLAYLISTS -> LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = 150.dp),
contentPadding = PaddingValues(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 80.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.fillMaxSize(),
) {
items(state.playlists, key = { it.id }) { pl ->
// Besitzer nur bei fremden (geteilten) Listen — bei den eigenen waere er Rauschen.
val von = pl.owner?.takeIf { it.isNotBlank() && it != state.currentUser }
PlaylistCard(
name = pl.name,
subtitle = "${pl.songCount} Titel" + (von?.let { " · von $it" } ?: ""),
coverUrl = coverUrl(pl.coverArt),
downloaded = pl.id in downloadedPlaylistIds,
onClick = { onPlaylistClick(pl) },
)
}
}
LibraryTab.OFFLINE -> {
val groups = offlineGroups
val storage by offlineVm.storageBytes.collectAsStateWithLifecycle()
val scope = rememberCoroutineScope()
if (groups.isEmpty()) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Icon(
Icons.Default.DownloadDone,
contentDescription = null,
tint = NsOnSurface3,
modifier = Modifier.size(56.dp),
)
Spacer(Modifier.height(12.dp))
Text(
"Noch nichts heruntergeladen",
fontFamily = Outfit,
fontSize = 15.sp,
color = NsOnSurface2,
)
Spacer(Modifier.height(4.dp))
Text(
"Öffne ein Album und tippe auf ↓",
fontFamily = Outfit,
fontSize = 12.sp,
color = NsOnSurface3,
)
}
}
} else {
LazyColumn(
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 12.dp),
verticalArrangement = Arrangement.spacedBy(1.dp),
modifier = Modifier.fillMaxSize(),
) {
item {
Text(
text = "%.1f MB gespeichert".format(storage / 1_000_000.0),
fontFamily = Outfit,
fontSize = 12.sp,
color = NsOnSurface3,
modifier = Modifier.padding(bottom = 12.dp),
)
}
items(groups, key = { it.groupId }) { group ->
OfflineGroupRow(
group = group,
coverUrl = coverUrl(group.coverArt),
onOpen = { onOpenOffline(group) },
onPlay = {
scope.launch {
val songs = offlineVm.songsForGroup(group.groupId)
if (songs.isNotEmpty()) onPlay(songs, 0)
}
},
onDelete = { groupToDelete = group },
)
}
item { Spacer(Modifier.height(80.dp)) }
}
}
}
}
} // end HorizontalPager
} // end Column
if (pagerState.currentPage == LibraryTab.PLAYLISTS.ordinal) {
FloatingActionButton(
onClick = { showCreateDialog = true },
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp),
containerColor = NsAccent,
) {
Icon(Icons.Default.Add, "Neue Playlist", tint = NsBackground)
}
}
} // end Box
// ── Delete offline group dialog ───────────────────────────────────────────
groupToDelete?.let { group ->
AlertDialog(
onDismissRequest = { groupToDelete = null },
title = { Text("Löschen?", fontFamily = Outfit, fontWeight = FontWeight.Bold) },
text = { Text("\"${group.name}\" aus dem Offline-Speicher entfernen?", fontFamily = Outfit) },
confirmButton = {
TextButton(onClick = {
offlineVm.deleteGroup(group.groupId)
groupToDelete = null
}) {
Text("Löschen", color = MaterialTheme.colorScheme.error, fontFamily = Outfit, fontWeight = FontWeight.Bold)
}
},
dismissButton = {
TextButton(onClick = { groupToDelete = null }) {
Text("Abbrechen", color = NsOnSurface2)
}
},
containerColor = NsSurface,
)
}
// ── Create playlist dialog ────────────────────────────────────────────────
if (showCreateDialog) {
var nameInput by remember { mutableStateOf("") }
AlertDialog(
onDismissRequest = { showCreateDialog = false },
title = { Text("Neue Playlist", fontFamily = Outfit, fontWeight = FontWeight.Bold) },
text = {
OutlinedTextField(
value = nameInput,
onValueChange = { nameInput = it },
label = { Text("Name") },
singleLine = true,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
shape = RoundedCornerShape(12.dp),
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = NsAccent,
unfocusedBorderColor = NsOnSurface3,
cursorColor = NsAccent,
),
modifier = Modifier.fillMaxWidth(),
)
},
confirmButton = {
TextButton(
onClick = {
vm.createPlaylist(nameInput)
showCreateDialog = false
},
enabled = nameInput.isNotBlank(),
) {
Text("Erstellen", color = NsAccent, fontFamily = Outfit, fontWeight = FontWeight.Bold)
}
},
dismissButton = {
TextButton(onClick = { showCreateDialog = false }) {
Text("Abbrechen", color = NsOnSurface2)
}
},
containerColor = NsSurface,
)
}
} }
@Composable @Composable
private fun PlaylistCard(name: String, subtitle: String, coverUrl: String?, onClick: () -> Unit) { private fun OfflineGroupRow(
group: DownloadGroupEntity,
coverUrl: String?,
onOpen: () -> Unit,
onPlay: () -> Unit,
onDelete: () -> Unit,
) {
val isFullyDone = group.totalTracks > 0 && group.downloadedTracks >= group.totalTracks
val subtitle = when {
group.totalTracks == 0 -> "Ausstehend…"
isFullyDone -> "${group.totalTracks} Titel · Vollständig"
else -> "${group.downloadedTracks}/${group.totalTracks} Titel"
}
val typeLabel = when (group.type) {
GroupType.ALBUM -> "Album"
GroupType.PLAYLIST -> "Playlist"
GroupType.SONG -> "Song"
GroupType.FAVORITES -> "Favoriten"
}
Column(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
.background(NsSurface)
.border(1.dp, NsBorder, RoundedCornerShape(12.dp))
.clickable(onClick = onOpen)
.padding(12.dp),
) {
Row(verticalAlignment = Alignment.CenterVertically) {
AsyncImage(
model = coverUrl,
contentDescription = group.name,
contentScale = ContentScale.Crop,
modifier = Modifier
.size(52.dp)
.clip(RoundedCornerShape(8.dp))
.background(NsSurface2),
)
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(
text = group.name,
fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 14.sp,
color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis,
)
Spacer(Modifier.height(2.dp))
Text(
text = "$typeLabel · $subtitle",
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
)
}
IconButton(onClick = onPlay, enabled = isFullyDone) {
Icon(Icons.Default.PlayArrow, "Abspielen",
tint = if (isFullyDone) NsAccent else NsOnSurface3,
modifier = Modifier.size(20.dp))
}
IconButton(onClick = onDelete) {
Icon(Icons.Default.Delete, "Löschen", tint = NsOnSurface3, modifier = Modifier.size(20.dp))
}
}
if (!isFullyDone && group.totalTracks > 0) {
Spacer(Modifier.height(8.dp))
LinearProgressIndicator(
progress = { group.downloadedTracks.toFloat() / group.totalTracks },
modifier = Modifier.fillMaxWidth().height(3.dp).clip(RoundedCornerShape(2.dp)),
color = NsAccent,
trackColor = NsSurface2,
)
}
}
Spacer(Modifier.height(8.dp))
}
@Composable
private fun PlaylistCard(
name: String,
subtitle: String,
coverUrl: String?,
downloaded: Boolean = false,
onClick: () -> Unit,
) {
val shape = RoundedCornerShape(12.dp) val shape = RoundedCornerShape(12.dp)
Column( Column(
modifier = Modifier modifier = Modifier
@@ -165,6 +635,7 @@ private fun PlaylistCard(name: String, subtitle: String, coverUrl: String?, onCl
.border(1.dp, NsBorder, shape) .border(1.dp, NsBorder, shape)
.clickable(onClick = onClick), .clickable(onClick = onClick),
) { ) {
Box {
AsyncImage( AsyncImage(
model = coverUrl, model = coverUrl,
contentDescription = name, contentDescription = name,
@@ -174,6 +645,8 @@ private fun PlaylistCard(name: String, subtitle: String, coverUrl: String?, onCl
.aspectRatio(1f) .aspectRatio(1f)
.background(NsSurface2), .background(NsSurface2),
) )
if (downloaded) DownloadedBadge(Modifier.align(Alignment.BottomEnd).padding(6.dp))
}
Column(Modifier.padding(10.dp)) { Column(Modifier.padding(10.dp)) {
Text( Text(
text = name, text = name,
@@ -189,3 +662,22 @@ private fun PlaylistCard(name: String, subtitle: String, coverUrl: String?, onCl
} }
} }
} }
/** Small "downloaded" pill overlaid on a cover — the down-arrow-in-circle, Spotify-style. */
@Composable
fun DownloadedBadge(modifier: Modifier = Modifier) {
Box(
modifier = modifier
.size(22.dp)
.clip(CircleShape)
.background(Color.Black.copy(alpha = 0.55f)),
contentAlignment = Alignment.Center,
) {
Icon(
Icons.Default.DownloadForOffline,
contentDescription = "Heruntergeladen",
tint = NsAccent,
modifier = Modifier.size(16.dp),
)
}
}
@@ -24,7 +24,8 @@ fun LoginScreen(onLoggedIn: () -> Unit) {
val vm: LoginViewModel = viewModel() val vm: LoginViewModel = viewModel()
val state by vm.state.collectAsStateWithLifecycle() val state by vm.state.collectAsStateWithLifecycle()
var serverUrl by remember { mutableStateOf("") } // Serveradresse vorbelegen, falls im Build hinterlegt — dann bleiben nur Benutzer und Passwort.
var serverUrl by remember { mutableStateOf(com.novasonic.app.BuildConfig.DEFAULT_ND_URL) }
var username by remember { mutableStateOf("") } var username by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") } var password by remember { mutableStateOf("") }
var showPw by remember { mutableStateOf(false) } var showPw by remember { mutableStateOf(false) }
@@ -8,10 +8,14 @@ import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.gestures.detectHorizontalDragGestures import androidx.compose.foundation.gestures.detectHorizontalDragGestures
import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.detectVerticalDragGestures import androidx.compose.foundation.gestures.detectVerticalDragGestures
import androidx.compose.foundation.gestures.animateScrollBy
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@@ -32,7 +36,16 @@ import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import android.graphics.drawable.BitmapDrawable
import androidx.palette.graphics.Palette
import coil.ImageLoader
import coil.request.ImageRequest import coil.request.ImageRequest
import coil.request.SuccessResult
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.rememberScrollState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
@@ -47,9 +60,35 @@ import com.novasonic.app.player.PlayerState
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.LyricsViewModel import com.novasonic.app.viewmodel.LyricsViewModel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.DragHandle
import androidx.compose.ui.input.pointer.positionChange
private enum class NpTab { PLAYER, LYRICS, QUEUE } private enum class NpTab { PLAYER, LYRICS, QUEUE }
// ── Obergrenzen fuer grosse Anzeigen (Fold aufgeklappt, Tablet) ──────────────────────────────
// Bis 1.26 hatte diese Ansicht keine Breitengrenze: das Cover war `fillMaxWidth` mal
// `aspectRatio(1f)`. Auf einem Handy sind das knappe 360 dp und passt; auf dem inneren Display
// eines Fold sind es ueber 800 dp — ein quadratisches Cover dieser Groesse schob Titel,
// Fortschrittsbalken und Knoepfe aus dem Bild, und die ganze Seite wirkte ueberdimensional.
// Die Web-Ansicht deckelt dasselbe seit immer bei 480 px (`.np-inner { max-width: 480px }`).
// Zusaetzlich wird das Cover gegen die HOEHE gedeckelt: bei einem fast quadratischen Display ist
// die Breite kein gutes Mass mehr fuer ein quadratisches Bild.
private val NP_SPALTE_MAX = 480.dp // Player-Seite: Cover, Titel, Fortschritt, Knoepfe
private val NP_LISTE_MAX = 560.dp // Liedtext und Warteschlange — Listen duerfen etwas breiter
private val NP_COVER_MAX = 400.dp
// Was Titel, Album, Kuenstler, Fortschrittsbalken, Zeiten, Knopfreihe und die Abstaende
// dazwischen zusammen brauchen (gemessen an den gesetzten Groessen, mit etwas Luft). Das Cover
// bekommt den Rest — so passt die Seite auch auf kurze Anzeigen, wo bisher die Knopfreihe
// unten abgeschnitten wurde.
private val NP_RESTBEDARF = 260.dp
// Auf kurzen Anzeigen (Flip-Frontdisplay, Querformat) schrumpfen Abstaende und Abspielknopf
// zusaetzlich, der Rest braucht dann weniger — und wenn es trotzdem nicht reicht, laesst sich
// die Seite rollen.
private val NP_RESTBEDARF_KURZ = 200.dp
@Composable @Composable
fun NowPlayingScreen( fun NowPlayingScreen(
state: PlayerState, state: PlayerState,
@@ -59,13 +98,37 @@ fun NowPlayingScreen(
onDismiss: () -> Unit, onDismiss: () -> Unit,
onStarToggle: (() -> Unit)? = null, onStarToggle: (() -> Unit)? = null,
onShowOptions: (() -> Unit)? = null, onShowOptions: (() -> Unit)? = null,
onArtistClick: (() -> Unit)? = null, onArtistClick: ((artistId: String) -> Unit)? = null,
onToggleRadio: (() -> Unit)? = null,
) { ) {
val song = state.currentSong val song = state.currentSong
var tab by remember { mutableStateOf(NpTab.PLAYER) } var tab by remember { mutableStateOf(NpTab.PLAYER) }
// Waagerechtes Wischen: standardmaessig wechselt es den TITEL — das ist die Geste, die man hier
// staendig braucht. Wer lieber zwischen Player, Warteschlange und Text blaettert, stellt es in
// den Einstellungen um; dann uebernimmt wieder der Pager. Die Reiter oben schalten in beiden
// Faellen weiter, es geht also nie eine Ansicht verloren.
val prefsCtx = LocalContext.current
val wischTitel by produceState(initialValue = true, prefsCtx) {
com.novasonic.app.data.PrefsStore(prefsCtx).appSettings.collect { value = it.wischenWechseltTitel }
}
val pagerState = rememberPagerState(initialPage = tab.ordinal) { NpTab.entries.size }
LaunchedEffect(tab) {
if (pagerState.currentPage != tab.ordinal) pagerState.animateScrollToPage(tab.ordinal)
}
LaunchedEffect(pagerState.settledPage) {
val t = NpTab.entries[pagerState.settledPage]
if (t != tab) tab = t
}
// Preload lyrics as soon as NowPlaying opens — so the Lyrics tab shows instantly
val lyricsVm: LyricsViewModel = viewModel()
LaunchedEffect(song?.id) {
if (song != null) lyricsVm.loadForSong(song)
}
val statusBarTop: Dp = with(LocalDensity.current) { WindowInsets.safeDrawing.getTop(this).toDp() } val statusBarTop: Dp = with(LocalDensity.current) { WindowInsets.safeDrawing.getTop(this).toDp() }
val topPad = maxOf(statusBarTop, 36.dp) val topPad = maxOf(statusBarTop + 16.dp, 52.dp)
val navBarBottom: Dp = with(LocalDensity.current) { WindowInsets.safeDrawing.getBottom(this).toDp() } val navBarBottom: Dp = with(LocalDensity.current) { WindowInsets.safeDrawing.getBottom(this).toDp() }
// Apple Music-style: cover scales up while playing // Apple Music-style: cover scales up while playing
@@ -78,26 +141,69 @@ fun NowPlayingScreen(
label = "coverScale", label = "coverScale",
) )
// Extract dominant color from cover art for background tinting
val context = LocalContext.current val context = LocalContext.current
Box(Modifier.fillMaxSize().background(NsBackground)) { var dominantColor by remember(coverUrl) { mutableStateOf<Color?>(null) }
// Blurred album art full-screen background — crossfade prevents transparent flash on song change LaunchedEffect(coverUrl) {
AsyncImage( dominantColor = null
model = ImageRequest.Builder(context).data(coverUrl).crossfade(500).build(), if (coverUrl.isNullOrBlank()) return@LaunchedEffect
contentDescription = null, try {
contentScale = ContentScale.Crop, val loader = ImageLoader(context)
modifier = Modifier.fillMaxSize().blur(72.dp), val req = ImageRequest.Builder(context).data(coverUrl).allowHardware(false).size(80).build()
) val result = loader.execute(req)
Box( if (result is SuccessResult) {
Modifier.fillMaxSize().background( val bitmap = (result.drawable as? BitmapDrawable)?.bitmap ?: return@LaunchedEffect
Brush.verticalGradient(0f to Color(0xCC000000), 1f to Color(0xF2000000)) val palette = withContext(Dispatchers.Default) { Palette.from(bitmap).generate() }
val swatch = palette.vibrantSwatch ?: palette.mutedSwatch ?: palette.dominantSwatch
swatch?.rgb?.let { dominantColor = Color(it) }
}
} catch (_: Exception) {}
}
// Blend vibrant color toward darker for the background without losing the hue
val rawBgColor = dominantColor?.let { c ->
Color(
red = (c.red * 0.55f).coerceIn(0f, 1f),
green = (c.green * 0.55f).coerceIn(0f, 1f),
blue = (c.blue * 0.55f).coerceIn(0f, 1f),
) )
} ?: Color(0xFF0D0D1A)
val animatedBgColor by animateColorAsState(
targetValue = rawBgColor,
animationSpec = tween(600),
label = "npBg",
) )
Box(Modifier.fillMaxSize().background(NsBackground)) {
// Dominant-color gradient — covers top 70% of screen
Box(
Modifier.fillMaxSize().background(
Brush.verticalGradient(
0f to animatedBgColor,
0.65f to animatedBgColor.copy(alpha = 0.5f),
1f to NsBackground,
)
)
)
// Light scrim for readability
Box(Modifier.fillMaxSize().background(Color.Black.copy(alpha = 0.15f)))
BoxWithConstraints(Modifier.fillMaxSize()) {
// Zwei Groessenfragen entscheiden das Layout, nicht ein Geraetename:
// schmal — passt die Kopfzeile mit drei Reitern noch in voller Groesse? (Flip-Deckel)
// kurz — bleibt nach Kopfzeile und Raendern ueberhaupt Platz? (Flip-Deckel, Querformat)
// Die Schwelle liegt bewusst UNTER 360 dp: 360 ist noch ein gewoehnliches Handy und
// soll die Kopfzeile unveraendert behalten. Erfasst werden damit der Deckel eines Fold
// (~352 dp) und — ueber `kurz` — das Frontdisplay eines Flip, das bei aehnlicher Breite
// nur ein Drittel der Hoehe hat und wo drei Reiter in voller Groesse nicht hinpassen.
val schmal = maxWidth < 356.dp || maxHeight < 560.dp
val kurz = maxHeight < 560.dp
val obenPad = if (kurz) maxOf(statusBarTop + 4.dp, 20.dp) else topPad
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.padding(top = topPad, bottom = maxOf(navBarBottom, 20.dp)) .padding(top = obenPad, bottom = maxOf(navBarBottom, if (kurz) 8.dp else 20.dp))
.pointerInput(Unit) { .pointerInput(Unit) {
var dragY = 0f var dragY = 0f
detectVerticalDragGestures( detectVerticalDragGestures(
@@ -111,9 +217,13 @@ fun NowPlayingScreen(
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth() modifier = Modifier
.padding(horizontal = 20.dp) // Ohne Grenze stehen Schliessen-Knopf und Menue auf einem breiten Display
.padding(bottom = 16.dp), // ganz aussen und die Reiter einsam in der Mitte.
.widthIn(max = NP_LISTE_MAX)
.fillMaxWidth()
.padding(horizontal = if (schmal) 8.dp else 20.dp)
.padding(bottom = if (kurz) 10.dp else 28.dp),
) { ) {
NpCircleBtn(onClick = onDismiss) { NpCircleBtn(onClick = onDismiss) {
Icon(Icons.Default.KeyboardArrowDown, "Schließen", Icon(Icons.Default.KeyboardArrowDown, "Schließen",
@@ -128,14 +238,17 @@ fun NowPlayingScreen(
.padding(3.dp), .padding(3.dp),
) { ) {
NpTab.entries.forEach { t -> NpTab.entries.forEach { t ->
val sel = tab == t val sel = pagerState.currentPage == t.ordinal
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = Modifier modifier = Modifier
.clip(RoundedCornerShape(16.dp)) .clip(RoundedCornerShape(16.dp))
.background(if (sel) Color.White.copy(0.18f) else Color.Transparent) .background(if (sel) Color.White.copy(0.18f) else Color.Transparent)
.clickable { tab = t } .clickable { tab = t }
.padding(horizontal = 14.dp, vertical = 6.dp), .padding(
horizontal = if (schmal) 9.dp else 18.dp,
vertical = if (kurz) 6.dp else 9.dp,
),
) { ) {
Text( Text(
when (t) { when (t) {
@@ -143,7 +256,8 @@ fun NowPlayingScreen(
NpTab.LYRICS -> "Lyrics" NpTab.LYRICS -> "Lyrics"
NpTab.QUEUE -> "Queue" NpTab.QUEUE -> "Queue"
}, },
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 11.sp, fontFamily = Outfit, fontWeight = FontWeight.Bold,
fontSize = if (schmal) 11.sp else 13.sp,
color = if (sel) Color.White else Color.White.copy(alpha = 0.4f), color = if (sel) Color.White else Color.White.copy(alpha = 0.4f),
) )
} }
@@ -160,19 +274,83 @@ fun NowPlayingScreen(
} }
} }
// ── Swipeable tab content (Player / Lyrics / Queue) ────────────
HorizontalPager(
state = pagerState,
userScrollEnabled = !wischTitel,
modifier = Modifier.weight(1f).fillMaxWidth(),
) { page ->
// Die ganze Player-Seite nimmt die Wischgeste an, nicht nur das Cover: sonst muesste
// man genau das Bild treffen, und darunter liegt die halbe Seite. Auf Warteschlange
// und Text liegt sie NICHT — dort wuerde sie mit dem Ziehen in der Liste streiten.
var seitenDrag by remember { mutableStateOf(0f) }
val wischbar = wischTitel && NpTab.entries[page] == NpTab.PLAYER
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxSize()
.then(
if (!wischbar) Modifier else Modifier.pointerInput(Unit) {
detectHorizontalDragGestures(
onDragEnd = {
if (seitenDrag < -80) controller.skipNext()
else if (seitenDrag > 80) controller.skipPrev()
seitenDrag = 0f
},
onDragCancel = { seitenDrag = 0f },
onHorizontalDrag = { _, d -> seitenDrag += d },
)
}
),
) {
when (NpTab.entries[page]) {
// ── PLAYER TAB ───────────────────────────────────────────────── // ── PLAYER TAB ─────────────────────────────────────────────────
if (tab == NpTab.PLAYER) { NpTab.PLAYER -> BoxWithConstraints(Modifier.fillMaxSize()) {
var dragX by remember { mutableStateOf(0f) } var dragX by remember { mutableStateOf(0f) }
// Das Cover nimmt das KLEINSTE aus drei Maszen: verfuegbare Breite (minus der
// bisherigen 24 dp Rand je Seite), die Hoehe abzueglich dessen, was der Rest der
// Seite braucht, und eine feste Obergrenze. Auf einem hohen Handy gewinnt die
// Breite — dort bleibt alles wie bisher. Aufgeklappt greifen die anderen beiden.
val coverKante = minOf(
maxWidth - 48.dp,
(maxHeight - if (kurz) NP_RESTBEDARF_KURZ else NP_RESTBEDARF).coerceAtLeast(120.dp),
NP_COVER_MAX,
)
val spalte = minOf(maxWidth, NP_SPALTE_MAX)
// Vor dem Rollbereich festhalten: innerhalb des Box-Lambdas ist `maxHeight` des
// aeusseren Messrahmens nicht mehr erreichbar (Compose sperrt gleich markierte
// Layout-Bereiche gegeneinander ab).
val seitenHoehe = maxHeight
// Greift ueberhaupt eine der neuen Grenzen? Nur dann weicht das Layout von dem
// ab, was ein hohes Handy bisher zeigte. Solange die BREITE das engste Mass ist
// — also auf jedem gewoehnlichen Handy —, bleibt es beim alten Aufbau: oben
// beginnend mit 28 dp Abstand. Erst wenn Hoehe oder Obergrenze beissen (Fold
// aufgeklappt, Tablet, Querformat), wird senkrecht zentriert; oben klebend mit
// einem Loch darunter saehe dort falsch aus.
val gedeckelt = coverKante < maxWidth - 48.dp || kurz
// Cover art — full content width, scale-animates like Apple Music // Passt es, wird es angeordnet wie oben beschrieben; passt es nicht, wird
// gescrollt. Beides mit einem Aufbau: der Inhalt ist mindestens so hoch wie die
// Seite, darf aber darueber hinauswachsen — dann hat der Rollbereich etwas zu
// rollen. Auf dem Frontdisplay eines Flip bleibt sonst nichts uebrig, was ohne
// Abschneiden darstellbar waere. Passt alles, ist der Rollweg null: dann
// verhaelt sich die Seite wie ohne Rollbereich.
// Die Wischgeste zum Schliessen bleibt erhalten: ein Rollbereich ohne Weg
// verbraucht die Geste nicht, sie erreicht also weiter die Seite darunter.
Box(Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = if (gedeckelt) Arrangement.Center else Arrangement.Top,
modifier = Modifier.fillMaxWidth().heightIn(min = seitenHoehe),
) {
if (!gedeckelt) Spacer(Modifier.height(28.dp))
// Cover art — gedeckelt, scale-animates like Apple Music
AsyncImage( AsyncImage(
model = coverUrl, model = coverUrl,
contentDescription = song?.title, contentDescription = song?.title,
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier modifier = Modifier
.padding(horizontal = 24.dp) .size(coverKante)
.fillMaxWidth()
.aspectRatio(1f)
.graphicsLayer { scaleX = coverScale; scaleY = coverScale } .graphicsLayer { scaleX = coverScale; scaleY = coverScale }
.shadow(40.dp, RoundedCornerShape(20.dp)) .shadow(40.dp, RoundedCornerShape(20.dp))
.clip(RoundedCornerShape(20.dp)) .clip(RoundedCornerShape(20.dp))
@@ -190,10 +368,10 @@ fun NowPlayingScreen(
}, },
) )
Spacer(Modifier.height(24.dp)) Spacer(Modifier.height(if (kurz) 12.dp else 24.dp))
// ── Song info ────────────────────────────────────────────── // ── Song info ──────────────────────────────────────────────
Column(Modifier.fillMaxWidth().padding(horizontal = 28.dp)) { Column(Modifier.width(spalte).padding(horizontal = 28.dp)) {
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@@ -206,17 +384,7 @@ fun NowPlayingScreen(
maxLines = 1, overflow = TextOverflow.Ellipsis, maxLines = 1, overflow = TextOverflow.Ellipsis,
) )
Spacer(Modifier.height(3.dp)) Spacer(Modifier.height(3.dp))
if (!song?.artist.isNullOrBlank()) { // Order matches the web player: title → album → artists.
Text(
song!!.artist!!,
fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 15.sp, color = NsAccent,
maxLines = 1, overflow = TextOverflow.Ellipsis,
modifier = if (onArtistClick != null)
Modifier.clickable(onClick = onArtistClick)
else Modifier,
)
}
if (!song?.album.isNullOrBlank()) { if (!song?.album.isNullOrBlank()) {
Text( Text(
song!!.album!!, song!!.album!!,
@@ -224,10 +392,57 @@ fun NowPlayingScreen(
color = Color.White.copy(alpha = 0.45f), color = Color.White.copy(alpha = 0.45f),
maxLines = 1, overflow = TextOverflow.Ellipsis, maxLines = 1, overflow = TextOverflow.Ellipsis,
) )
Spacer(Modifier.height(3.dp))
}
if (song != null && !song.artist.isNullOrBlank()) {
// Prefer OpenSubsonic artists array (has IDs per contributor).
// Fall back to splitting artist string by ';' (same as web app).
val raw: List<com.novasonic.app.api.model.SongArtist> =
if (song.artists.size > 1) song.artists
else song.artist!!.split(";").map { part ->
val n = part.trim()
com.novasonic.app.api.model.SongArtist(
id = if (n.equals(song.artist?.trim(), ignoreCase = true)) song.artistId ?: "" else "",
name = n,
)
}.filter { it.name.isNotBlank() }
val artistList = raw
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.horizontalScroll(rememberScrollState()),
) {
artistList.forEachIndexed { idx, a ->
if (idx > 0) {
Text(
" · ",
fontFamily = Outfit,
fontSize = 14.sp,
color = Color.White.copy(alpha = 0.35f),
)
}
val navigable = onArtistClick != null && a.id.isNotBlank()
Text(
text = a.name,
fontFamily = Outfit,
fontWeight = FontWeight.SemiBold,
fontSize = 14.sp,
maxLines = 1,
color = if (navigable) NsAccent else NsAccent.copy(alpha = 0.55f),
modifier = if (navigable)
Modifier.pointerInput(a.id) {
detectTapGestures { onArtistClick!!(a.id) }
}
else Modifier,
)
}
}
} }
} }
if (onStarToggle != null && song != null) { if (onStarToggle != null && song != null) {
val starred = song.starred != null val starOverrides by com.novasonic.app.data.StarState.overrides.collectAsState()
val starred = starOverrides[song.id] ?: (song.starred != null)
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = Modifier modifier = Modifier
@@ -235,7 +450,7 @@ fun NowPlayingScreen(
.clickable(onClick = onStarToggle), .clickable(onClick = onStarToggle),
) { ) {
Icon( Icon(
if (starred) Icons.Default.Star else Icons.Default.StarBorder, if (starred) Icons.Default.Favorite else Icons.Default.FavoriteBorder,
null, null,
tint = if (starred) NsAccent else Color.White.copy(0.5f), tint = if (starred) NsAccent else Color.White.copy(0.5f),
modifier = Modifier.size(22.dp), modifier = Modifier.size(22.dp),
@@ -245,10 +460,10 @@ fun NowPlayingScreen(
} }
} }
Spacer(Modifier.height(20.dp)) Spacer(Modifier.height(if (kurz) 10.dp else 20.dp))
// ── Seek bar ─────────────────────────────────────────────── // ── Seek bar ───────────────────────────────────────────────
Column(Modifier.fillMaxWidth().padding(horizontal = 24.dp)) { Column(Modifier.width(spalte).padding(horizontal = 24.dp)) {
val progress = if (state.durationMs > 0) val progress = if (state.durationMs > 0)
(state.positionMs.toFloat() / state.durationMs).coerceIn(0f, 1f) else 0f (state.positionMs.toFloat() / state.durationMs).coerceIn(0f, 1f) else 0f
@@ -265,15 +480,15 @@ fun NowPlayingScreen(
} }
} }
Spacer(Modifier.height(12.dp)) Spacer(Modifier.height(if (kurz) 4.dp else 12.dp))
// ── Controls ─────────────────────────────────────────────── // ── Controls ───────────────────────────────────────────────
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceEvenly, horizontalArrangement = Arrangement.SpaceEvenly,
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp), modifier = Modifier.width(spalte).padding(horizontal = 16.dp),
) { ) {
NpCircleBtn(onClick = { controller.toggleShuffle() }) { NpCircleBtn(onClick = { controller.toggleShuffle() }, aktiv = state.shuffled) {
Icon(Icons.Default.Shuffle, null, modifier = Modifier.size(22.dp), Icon(Icons.Default.Shuffle, null, modifier = Modifier.size(22.dp),
tint = if (state.shuffled) NsAccent else Color.White.copy(0.65f)) tint = if (state.shuffled) NsAccent else Color.White.copy(0.65f))
} }
@@ -285,7 +500,7 @@ fun NowPlayingScreen(
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = Modifier modifier = Modifier
.size(68.dp) .size(if (kurz) 56.dp else 68.dp)
.clip(CircleShape) .clip(CircleShape)
.background(Color.White) .background(Color.White)
.clickable { controller.togglePlay() }, .clickable { controller.togglePlay() },
@@ -299,7 +514,8 @@ fun NowPlayingScreen(
NpCircleBtn(onClick = { controller.skipNext() }) { NpCircleBtn(onClick = { controller.skipNext() }) {
Icon(Icons.Default.SkipNext, null, modifier = Modifier.size(34.dp), tint = Color.White) Icon(Icons.Default.SkipNext, null, modifier = Modifier.size(34.dp), tint = Color.White)
} }
NpCircleBtn(onClick = { controller.toggleRepeat() }) { val wiederholt = state.repeatMode != androidx.media3.common.Player.REPEAT_MODE_OFF
NpCircleBtn(onClick = { controller.toggleRepeat() }, aktiv = wiederholt) {
val (icon, tint) = when (state.repeatMode) { val (icon, tint) = when (state.repeatMode) {
androidx.media3.common.Player.REPEAT_MODE_ONE -> Icons.Default.RepeatOne to NsAccent androidx.media3.common.Player.REPEAT_MODE_ONE -> Icons.Default.RepeatOne to NsAccent
androidx.media3.common.Player.REPEAT_MODE_ALL -> Icons.Default.Repeat to NsAccent androidx.media3.common.Player.REPEAT_MODE_ALL -> Icons.Default.Repeat to NsAccent
@@ -308,29 +524,85 @@ fun NowPlayingScreen(
Icon(icon, null, modifier = Modifier.size(22.dp), tint = tint) Icon(icon, null, modifier = Modifier.size(22.dp), tint = tint)
} }
} }
} // end Column (gedeckelte Player-Spalte)
} // end Box (Rollbereich, falls die Seite nicht reicht)
} }
// ── LYRICS TAB ───────────────────────────────────────────────── // ── LYRICS TAB ─────────────────────────────────────────────────
if (tab == NpTab.LYRICS && song != null) { NpTab.LYRICS -> if (song != null) {
val lyricsVm: LyricsViewModel = viewModel()
val lyricsState by lyricsVm.state.collectAsStateWithLifecycle() val lyricsState by lyricsVm.state.collectAsStateWithLifecycle()
val listState = rememberLazyListState() val lyricsListState = rememberLazyListState()
val scope = rememberCoroutineScope() val density = LocalDensity.current
var lyricsViewH by remember { mutableIntStateOf(0) }
LaunchedEffect(song.id) { lyricsVm.loadForSong(song) } // Mitlaufen: Standard AUS. Der Schalter sitzt hier im Reiter, nicht in den
// Einstellungen — man entscheidet beim Lesen, nicht vorher.
val folgtMit by produceState(initialValue = false, prefsCtx) {
com.novasonic.app.data.PrefsStore(prefsCtx).appSettings
.collect { value = it.lyricsFolgenAutomatisch }
}
val folgenScope = rememberCoroutineScope()
// Anchor the active line at 40% from the top — slightly above middle reads more naturally.
val anchorFrac = 0.40f
// 200ms lookahead — same as web app for better sync feel
val activeIdx = if (lyricsState.lines.isNotEmpty()) val activeIdx = if (lyricsState.lines.isNotEmpty())
lyricsState.lines.indexOfLast { it.timeMs <= state.positionMs }.coerceAtLeast(0) lyricsState.lines.indexOfLast { it.timeMs <= state.positionMs + 200L }.coerceAtLeast(0)
else -1 else -1
// Smooth scroll to active line // Center the active line using its *measured* position — no cumulative drift, so
LaunchedEffect(activeIdx) { // wrapped (multi-line) lyrics stay centered. Re-runs once the viewport is measured.
if (activeIdx >= 0 && lyricsState.lines.isNotEmpty()) { LaunchedEffect(activeIdx, lyricsViewH, folgtMit) {
scope.launch { // Ohne Mitlaufen wird nur hervorgehoben, nicht gescrollt — sonst springt der
listState.animateScrollToItem( // Text unter dem Finger weg, sobald die naechste Zeile beginnt.
(activeIdx - 2).coerceAtLeast(0), if (!folgtMit) return@LaunchedEffect
scrollOffset = 0, if (activeIdx < 0 || lyricsState.lines.isEmpty() || lyricsViewH == 0) return@LaunchedEffect
val info = lyricsListState.layoutInfo
val anchor = info.viewportStartOffset +
((info.viewportEndOffset - info.viewportStartOffset) * anchorFrac).toInt()
val item = info.visibleItemsInfo.firstOrNull { it.index == activeIdx }
if (item != null) {
val delta = (item.offset + item.size / 2 - anchor).toFloat()
lyricsListState.animateScrollBy(
delta,
animationSpec = tween(durationMillis = 600, easing = FastOutSlowInEasing),
)
} else {
// Big jump (instrumental gap → chorus): approximate-anchor now, refine next tick
lyricsListState.animateScrollToItem(activeIdx, -anchor)
}
}
if (lyricsState.lines.isNotEmpty()) {
Row(
modifier = Modifier.widthIn(max = NP_LISTE_MAX)
.fillMaxWidth().padding(bottom = 4.dp),
horizontalArrangement = Arrangement.End,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.clip(RoundedCornerShape(16.dp))
.background(
if (folgtMit) NsAccent.copy(0.18f) else Color.White.copy(0.08f)
)
.clickable {
folgenScope.launch {
com.novasonic.app.data.PrefsStore(prefsCtx)
.saveLyricsFolgen(!folgtMit)
}
}
.padding(horizontal = 11.dp, vertical = 6.dp),
) {
Icon(
Icons.Default.KeyboardArrowDown, null,
modifier = Modifier.size(15.dp),
tint = if (folgtMit) NsAccent else Color.White.copy(0.55f),
)
Spacer(Modifier.width(5.dp))
Text(
if (folgtMit) "Folgt" else "Mitlaufen",
fontFamily = Outfit, fontSize = 11.sp, fontWeight = FontWeight.Bold,
color = if (folgtMit) NsAccent else Color.White.copy(0.55f),
) )
} }
} }
@@ -357,48 +629,33 @@ fun NowPlayingScreen(
} }
lyricsState.lines.isNotEmpty() -> LazyColumn( lyricsState.lines.isNotEmpty() -> LazyColumn(
state = listState, state = lyricsListState,
modifier = Modifier.weight(1f).fillMaxWidth(),
contentPadding = PaddingValues(vertical = 40.dp),
verticalArrangement = Arrangement.spacedBy(6.dp),
) {
itemsIndexed(lyricsState.lines) { idx, line ->
val isActive = idx == activeIdx
val isPast = idx < activeIdx
val targetColor = when {
isActive -> Color.White
isPast -> Color.White.copy(alpha = 0.32f)
else -> Color.White.copy(alpha = 0.55f)
}
val animColor by animateColorAsState(
targetValue = targetColor,
animationSpec = tween(350),
label = "lyricColor$idx",
)
val animSize by animateFloatAsState(
targetValue = if (isActive) 20f else 16f,
animationSpec = tween(300),
label = "lyricSize$idx",
)
Text(
text = line.text,
fontFamily = Outfit,
fontWeight = if (isActive) FontWeight.ExtraBold else FontWeight.Normal,
fontSize = animSize.sp,
color = animColor,
textAlign = TextAlign.Center,
modifier = Modifier modifier = Modifier
.weight(1f)
// Gedeckelt: eine Textzeile ueber 800 dp liest sich nicht mehr.
.widthIn(max = NP_LISTE_MAX)
.fillMaxWidth() .fillMaxWidth()
.clickable { controller.seekTo(line.timeMs) } .onSizeChanged { lyricsViewH = it.height },
.padding(horizontal = 12.dp, vertical = 5.dp), // Asymmetric padding so the first/last lines can still reach the anchor point.
contentPadding = if (lyricsViewH > 0) PaddingValues(
top = with(density) { (lyricsViewH * anchorFrac).toDp() },
bottom = with(density) { (lyricsViewH * (1f - anchorFrac)).toDp() },
) else PaddingValues(vertical = 220.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
itemsIndexed(lyricsState.lines, key = { idx, _ -> idx }) { idx, line ->
LyricsLineItem(
text = line.text,
isActive = idx == activeIdx,
isPast = idx < activeIdx,
onSeek = { controller.seekTo(line.timeMs) },
) )
} }
} }
lyricsState.plainText.isNotBlank() -> LazyColumn( lyricsState.plainText.isNotBlank() -> LazyColumn(
modifier = Modifier.weight(1f).fillMaxWidth(), modifier = Modifier.weight(1f)
.widthIn(max = NP_LISTE_MAX).fillMaxWidth(),
contentPadding = PaddingValues(vertical = 24.dp), contentPadding = PaddingValues(vertical = 24.dp),
) { ) {
item { item {
@@ -415,25 +672,94 @@ fun NowPlayingScreen(
} }
// ── QUEUE TAB ────────────────────────────────────────────────── // ── QUEUE TAB ──────────────────────────────────────────────────
if (tab == NpTab.QUEUE) { NpTab.QUEUE -> {
// Radio mode toggle
if (onToggleRadio != null) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.widthIn(max = NP_LISTE_MAX)
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 10.dp)
.clip(RoundedCornerShape(12.dp))
.background(
if (state.radioMode) NsAccent.copy(alpha = 0.18f)
else Color.White.copy(alpha = 0.07f)
)
.clickable(onClick = onToggleRadio)
.padding(horizontal = 16.dp, vertical = 12.dp),
) {
Icon(
Icons.Default.Radio, null,
tint = if (state.radioMode) NsAccent else Color.White.copy(0.55f),
modifier = Modifier.size(18.dp),
)
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(
"Radio-Modus",
fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 14.sp,
color = if (state.radioMode) NsAccent else Color.White.copy(0.85f),
)
Text(
"Lädt ähnliche Songs automatisch nach",
fontFamily = Outfit, fontSize = 11.sp,
color = Color.White.copy(0.4f),
)
}
Switch(
checked = state.radioMode,
onCheckedChange = { onToggleRadio() },
colors = SwitchDefaults.colors(
checkedThumbColor = Color.White,
checkedTrackColor = NsAccent,
uncheckedThumbColor = Color.White.copy(0.6f),
uncheckedTrackColor = Color.White.copy(0.15f),
),
)
}
}
if (state.queue.isEmpty()) { if (state.queue.isEmpty()) {
Box(Modifier.weight(1f).fillMaxWidth(), contentAlignment = Alignment.Center) { Box(Modifier.weight(1f).fillMaxWidth(), contentAlignment = Alignment.Center) {
Text("Warteschlange leer", fontFamily = Outfit, fontSize = 14.sp, Text("Warteschlange leer", fontFamily = Outfit, fontSize = 14.sp,
color = Color.White.copy(0.4f)) color = Color.White.copy(0.4f))
} }
} else { } else {
// ── Warteschlange bearbeiten ────────────────────────────
// Gezogen wird am Griff, nicht an der Zeile: die Liste selbst scrollt, und
// beides an derselben Stelle liesse sich nicht auseinanderhalten.
// Getauscht wird LAUFEND, sobald der Finger eine Zeilenhoehe zurueckgelegt
// hat — dadurch braucht es kein Geisterbild, die Liste zeigt die neue
// Reihenfolge sofort.
val zeilePx = with(LocalDensity.current) { 56.dp.toPx() }
var ziehIdx by remember { mutableIntStateOf(-1) }
var ziehOffset by remember { mutableFloatStateOf(0f) }
val queueLaenge = rememberUpdatedState(state.queue.size)
LazyColumn( LazyColumn(
modifier = Modifier.weight(1f).fillMaxWidth(), modifier = Modifier.weight(1f)
.widthIn(max = NP_LISTE_MAX).fillMaxWidth(),
contentPadding = PaddingValues(vertical = 4.dp), contentPadding = PaddingValues(vertical = 4.dp),
) { ) {
itemsIndexed(state.queue, key = { idx, _ -> idx }) { idx, qSong -> itemsIndexed(state.queue, key = { idx, _ -> idx }) { idx, qSong ->
val active = state.currentIndex == idx val active = state.currentIndex == idx
val wirdGezogen = ziehIdx == idx
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.graphicsLayer {
if (wirdGezogen) { translationY = ziehOffset; shadowElevation = 12f }
}
.clip(RoundedCornerShape(10.dp)) .clip(RoundedCornerShape(10.dp))
.background(if (active) Color.White.copy(0.08f) else Color.Transparent) .background(
when {
wirdGezogen -> Color.White.copy(0.16f)
active -> Color.White.copy(0.08f)
else -> Color.Transparent
}
)
.clickable { controller.seekToItem(idx) } .clickable { controller.seekToItem(idx) }
.padding(horizontal = 16.dp, vertical = 8.dp), .padding(horizontal = 16.dp, vertical = 8.dp),
) { ) {
@@ -461,12 +787,63 @@ fun NowPlayingScreen(
Icon(Icons.AutoMirrored.Filled.VolumeUp, null, Icon(Icons.AutoMirrored.Filled.VolumeUp, null,
tint = NsAccent, modifier = Modifier.size(16.dp)) tint = NsAccent, modifier = Modifier.size(16.dp))
} }
IconButton(
onClick = { controller.entferneAusQueue(idx) },
modifier = Modifier.size(32.dp),
) {
Icon(Icons.Default.Close, "Aus der Warteschlange entfernen",
tint = Color.White.copy(0.45f), modifier = Modifier.size(16.dp))
}
Icon(
Icons.Default.DragHandle, "Zum Verschieben ziehen",
tint = Color.White.copy(if (wirdGezogen) 0.9f else 0.45f),
modifier = Modifier
.size(32.dp)
.padding(6.dp)
.pointerInput(Unit) {
awaitEachGesture {
// Der erste Kontakt wird sofort verbraucht, sonst
// beansprucht die LazyColumn die Geste, sobald die
// Wischschwelle faellt.
val start = awaitFirstDown(requireUnconsumed = false)
start.consume()
var aktuell = idx
var rest = 0f
ziehIdx = aktuell
try {
while (true) {
val ev = awaitPointerEvent()
val p = ev.changes.firstOrNull { it.id == start.id } ?: break
if (!p.pressed) break
rest += p.positionChange().y
p.consume()
while (rest >= zeilePx && aktuell < queueLaenge.value - 1) {
controller.verschiebeInQueue(aktuell, aktuell + 1)
aktuell++; rest -= zeilePx
}
while (rest <= -zeilePx && aktuell > 0) {
controller.verschiebeInQueue(aktuell, aktuell - 1)
aktuell--; rest += zeilePx
}
ziehIdx = aktuell
ziehOffset = rest
}
} finally {
ziehIdx = -1; ziehOffset = 0f
}
}
},
)
} }
} }
} }
} }
} }
} // end when
} // end inner Column
} // end HorizontalPager
} }
} // end BoxWithConstraints (schmal/kurz)
} }
} }
@@ -542,14 +919,74 @@ private fun NpSeekBar(
} }
@Composable @Composable
private fun NpCircleBtn(onClick: () -> Unit, content: @Composable () -> Unit) { private fun NpCircleBtn(
onClick: () -> Unit,
aktiv: Boolean = false,
content: @Composable () -> Unit,
) {
// Ein eingefaerbtes Symbol allein ist als "an" schwer zu erkennen — auf dem dunklen Cover
// sieht Akzentfarbe wie eine Schattierung aus. Ist der Schalter an, liegt deshalb zusaetzlich
// ein getoenter Kreis darunter und ein Punkt darunter, wie in gaengigen Playern.
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = Modifier.size(44.dp).clip(CircleShape).clickable(onClick = onClick), modifier = Modifier
) { content() } .size(44.dp)
.clip(CircleShape)
.background(if (aktiv) NsAccent.copy(alpha = 0.22f) else Color.Transparent)
.clickable(onClick = onClick),
) {
content()
if (aktiv) {
Box(
Modifier
.align(Alignment.BottomCenter)
.padding(bottom = 5.dp)
.size(4.dp)
.clip(CircleShape)
.background(NsAccent)
)
}
}
} }
private fun formatMs(ms: Long): String { private fun formatMs(ms: Long): String {
val s = (ms / 1000).coerceAtLeast(0) val s = (ms / 1000).coerceAtLeast(0)
return "%d:%02d".format(s / 60, s % 60) return "%d:%02d".format(s / 60, s % 60)
} }
@Composable
private fun LyricsLineItem(
text: String,
isActive: Boolean,
isPast: Boolean,
onSeek: () -> Unit,
) {
val animColor by animateColorAsState(
targetValue = when {
isActive -> Color.White
isPast -> Color.White.copy(alpha = 0.45f)
else -> Color.White.copy(alpha = 0.22f)
},
animationSpec = tween(300),
label = "lyricColor",
)
val animScale by animateFloatAsState(
targetValue = if (isActive) 1.04f else 1f,
animationSpec = tween(300),
label = "lyricScale",
)
Text(
text = text,
fontFamily = Outfit,
fontWeight = FontWeight.SemiBold,
fontSize = 18.sp,
lineHeight = 28.sp,
color = animColor,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.graphicsLayer { scaleX = animScale; scaleY = animScale }
.clickable { onSeek() }
.padding(horizontal = 20.dp, vertical = 6.dp),
)
}
@@ -0,0 +1,218 @@
package com.novasonic.app.ui.screen
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.RemoveCircle
import androidx.compose.material.icons.filled.Shuffle
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
import com.novasonic.app.api.model.Song
import com.novasonic.app.offline.DownloadState
import com.novasonic.app.offline.toSong
import com.novasonic.app.player.PlayerState
import com.novasonic.app.ui.component.SongRow
import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.OfflineDetailViewModel
import com.novasonic.app.ui.component.Rollbalken
@Composable
fun OfflineDetailScreen(
coverUrl: (String?) -> String?,
playerState: PlayerState,
onPlay: (List<Song>, Int) -> Unit,
onBack: () -> Unit,
) {
val vm: OfflineDetailViewModel = viewModel()
val group by vm.group.collectAsStateWithLifecycle()
val tracks by vm.tracks.collectAsStateWithLifecycle()
var editMode by remember { mutableStateOf(false) }
// The group flow starts as null before Room emits — don't treat that initial null as "deleted".
var everLoaded by remember { mutableStateOf(false) }
LaunchedEffect(group) { if (group != null) everLoaded = true }
// Only leave once the group was loaded and has since disappeared (last song removed).
LaunchedEffect(everLoaded, group) { if (everLoaded && group == null) onBack() }
val g = group ?: run {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = NsAccent)
}
return
}
val songs = remember(tracks) { tracks.map { it.toSong() } }
// Nur FERTIGE Titel sind offline abspielbar. Die Liste zeigt weiter alle (auch wartende und
// fehlgeschlagene), aber in die Warteschlange dürfen sie nicht: für sie gibt es keine lokale
// Datei, also liefert streamUrl() die Netz-Adresse — und die tut offline genau nichts.
val spielbar = remember(tracks) {
tracks.filter { it.state == DownloadState.DONE }.map { it.toSong() }
}
val ctx = androidx.compose.ui.platform.LocalContext.current
val spieleAb: (List<com.novasonic.app.api.model.Song>, Int) -> Unit = { liste, i ->
val fehlend = songs.size - spielbar.size
if (fehlend > 0) android.widget.Toast.makeText(
ctx, "$fehlend Titel noch nicht heruntergeladen — übersprungen",
android.widget.Toast.LENGTH_SHORT).show()
onPlay(liste, i)
}
val listState = rememberLazyListState()
Box(Modifier.fillMaxSize()) {
LazyColumn(Modifier.fillMaxSize(), state = listState) {
item {
// ── Hero ─────────────────────────────────────────────────────────
Box(Modifier.fillMaxWidth()) {
AsyncImage(
model = coverUrl(g.coverArt),
contentDescription = g.name,
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxWidth().aspectRatio(1f).background(NsSurface2),
)
Box(
Modifier
.fillMaxWidth()
.aspectRatio(1f)
.background(
Brush.verticalGradient(
0.0f to Color.Transparent,
0.40f to NsBackground.copy(alpha = 0.35f),
1.0f to NsBackground,
)
)
)
Box(
Modifier
.statusBarsPadding()
.padding(start = 14.dp, top = 14.dp)
.size(36.dp)
.clip(CircleShape)
.background(Color.Black.copy(alpha = 0.45f))
.clickable(onClick = onBack)
.align(Alignment.TopStart),
contentAlignment = Alignment.Center,
) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, "Zurück",
tint = Color.White, modifier = Modifier.size(18.dp))
}
Column(
Modifier.align(Alignment.BottomStart).padding(horizontal = 20.dp, vertical = 20.dp),
) {
Text(
g.name,
fontFamily = Outfit, fontWeight = FontWeight.ExtraBold,
fontSize = 26.sp, color = Color.White,
maxLines = 2, overflow = TextOverflow.Ellipsis,
)
Spacer(Modifier.height(4.dp))
Text(
"Offline · ${tracks.size} Titel",
fontFamily = Outfit, fontSize = 13.sp,
color = Color.White.copy(alpha = 0.65f),
)
}
}
// ── Play / Shuffle / Edit row ─────────────────────────────────────
Row(
Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp),
) {
Button(
onClick = { if (spielbar.isNotEmpty()) spieleAb(spielbar, 0) },
modifier = Modifier.weight(1f).height(46.dp),
colors = ButtonDefaults.buttonColors(containerColor = NsAccent, contentColor = Color.White),
shape = RoundedCornerShape(14.dp),
) {
Icon(Icons.Default.PlayArrow, null, modifier = Modifier.size(20.dp))
Spacer(Modifier.width(6.dp))
Text("Play", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp)
}
OutlinedButton(
onClick = { if (spielbar.isNotEmpty()) spieleAb(spielbar, -1) },
modifier = Modifier.weight(1f).height(46.dp),
border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(brush = SolidColor(NsAccent.copy(alpha = 0.55f))),
shape = RoundedCornerShape(14.dp),
) {
Icon(Icons.Default.Shuffle, null, modifier = Modifier.size(20.dp), tint = NsAccent)
Spacer(Modifier.width(6.dp))
Text("Shuffle", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp, color = NsAccent)
}
OutlinedButton(
onClick = { editMode = !editMode },
modifier = Modifier.height(46.dp),
border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(
brush = SolidColor(if (editMode) NsAccent else NsOnSurface3)
),
shape = RoundedCornerShape(14.dp),
contentPadding = PaddingValues(horizontal = 14.dp),
) {
Icon(
if (editMode) Icons.Default.Done else Icons.Default.Edit, null,
modifier = Modifier.size(18.dp),
tint = if (editMode) NsAccent else NsOnSurface2,
)
}
}
HorizontalDivider(color = NsBorder)
}
itemsIndexed(songs, key = { _, s -> s.id }) { index, song ->
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Box(Modifier.weight(1f)) {
SongRow(
song = song,
coverUrl = coverUrl(song.coverArt),
isPlaying = playerState.currentSong?.id == song.id,
// Position in der abspielbaren Liste suchen — die Anzeige enthält auch
// Titel, die noch fehlen, die Indizes decken sich also nicht.
onPlay = {
val i = spielbar.indexOfFirst { it.id == song.id }
if (i >= 0) onPlay(spielbar, i)
else android.widget.Toast.makeText(
ctx, "Dieser Titel ist noch nicht heruntergeladen",
android.widget.Toast.LENGTH_SHORT).show()
},
)
}
if (editMode) {
IconButton(onClick = { vm.deleteSong(song.id) }, modifier = Modifier.padding(end = 8.dp)) {
Icon(Icons.Default.RemoveCircle, "Vom Gerät löschen",
tint = MaterialTheme.colorScheme.error, modifier = Modifier.size(22.dp))
}
}
}
}
item { Spacer(Modifier.height(16.dp)) }
}
Rollbalken(
state = listState,
modifier = Modifier.align(Alignment.CenterEnd).padding(vertical = 4.dp),
farbe = NsOnSurface2,
)
}
}
@@ -5,9 +5,12 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.clickable
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Download import androidx.compose.material.icons.filled.Download
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.Shuffle
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@@ -27,7 +30,9 @@ import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.PartialAlbumState import com.novasonic.app.viewmodel.PartialAlbumState
private fun normTrack(s: String?) = private fun normTrack(s: String?) =
(s ?: "").lowercase().replace(Regex("[^a-z0-9]"), "").trim() // Keep Unicode letters/numbers so Japanese track titles aren't all emptied to "" (which made
// every downloaded JP track "match" every missing one in the partial-album split).
(s ?: "").lowercase().replace(Regex("[^\\p{L}\\p{N}]"), "").trim()
@Composable @Composable
fun PartialAlbumScreen( fun PartialAlbumScreen(
@@ -39,6 +44,7 @@ fun PartialAlbumScreen(
onPreview: (ItunesItem) -> Unit, onPreview: (ItunesItem) -> Unit,
onDownload: (ItunesItem) -> Unit, onDownload: (ItunesItem) -> Unit,
onBack: () -> Unit, onBack: () -> Unit,
onShowContextMenu: ((Song) -> Unit)? = null,
) { ) {
val ia = partialAlbum.itunesAlbum val ia = partialAlbum.itunesAlbum
val nd = partialAlbum.ndAlbum val nd = partialAlbum.ndAlbum
@@ -94,6 +100,50 @@ fun PartialAlbumScreen(
.sortedBy { it.trackNumber ?: 999 } .sortedBy { it.trackNumber ?: 999 }
LazyColumn(Modifier.fillMaxSize()) { LazyColumn(Modifier.fillMaxSize()) {
// ── Play / Shuffle the downloaded tracks (you can still enjoy the album even when not
// every track is downloaded yet) ─────────────────────────────────────────────────
if (downloadedSongs.isNotEmpty()) {
item {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp, top = 12.dp, bottom = 4.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.weight(1f)
.clip(RoundedCornerShape(10.dp))
.background(NsAccent)
.clickable { onPlay(downloadedSongs, 0) }
.padding(vertical = 11.dp),
) {
Icon(Icons.Default.PlayArrow, null, tint = NsBackground, modifier = Modifier.size(20.dp))
Spacer(Modifier.width(6.dp))
Text("Abspielen", fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 14.sp, color = NsBackground)
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.weight(1f)
.clip(RoundedCornerShape(10.dp))
.background(NsSurface2)
.clickable { onPlay(downloadedSongs, -1) }
.padding(vertical = 11.dp),
) {
Icon(Icons.Default.Shuffle, null, tint = NsOnSurface, modifier = Modifier.size(18.dp))
Spacer(Modifier.width(6.dp))
Text("Zufall", fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 14.sp, color = NsOnSurface)
}
}
}
}
// ── Downloaded tracks ───────────────────────────────────────────── // ── Downloaded tracks ─────────────────────────────────────────────
if (downloadedSongs.isNotEmpty()) { if (downloadedSongs.isNotEmpty()) {
item { item {
@@ -111,6 +161,7 @@ fun PartialAlbumScreen(
starred = song.starred != null, starred = song.starred != null,
onPlay = { onPlay(downloadedSongs, idx) }, onPlay = { onPlay(downloadedSongs, idx) },
onStarToggle = {}, onStarToggle = {},
onMore = onShowContextMenu?.let { cb -> { cb(song) } },
) )
} }
} }
@@ -1,16 +1,21 @@
package com.novasonic.app.ui.screen package com.novasonic.app.ui.screen
import android.net.Uri
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.PlayArrow import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.filled.Shuffle import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@@ -20,7 +25,9 @@ import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
@@ -28,10 +35,13 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.novasonic.app.api.model.Song import com.novasonic.app.api.model.Song
import com.novasonic.app.offline.DownloadGroupEntity
import com.novasonic.app.player.PlayerState import com.novasonic.app.player.PlayerState
import com.novasonic.app.ui.component.SongRow import com.novasonic.app.ui.component.SongRow
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.PlaylistViewModel import com.novasonic.app.viewmodel.PlaylistViewModel
import com.novasonic.app.ui.component.Rollbalken
import com.novasonic.app.ui.formatGesamtdauer
@Composable @Composable
fun PlaylistDetailScreen( fun PlaylistDetailScreen(
@@ -40,10 +50,27 @@ fun PlaylistDetailScreen(
onPlay: (List<Song>, Int) -> Unit, onPlay: (List<Song>, Int) -> Unit,
onStarToggle: (Song) -> Unit, onStarToggle: (Song) -> Unit,
onShowContextMenu: ((Song) -> Unit)? = null, onShowContextMenu: ((Song) -> Unit)? = null,
onDeleted: () -> Unit = {},
onBack: () -> Unit, onBack: () -> Unit,
) { ) {
val vm: PlaylistViewModel = viewModel() val vm: PlaylistViewModel = viewModel()
val state by vm.state.collectAsStateWithLifecycle() val state by vm.state.collectAsStateWithLifecycle()
val context = LocalContext.current
var editMode by remember { mutableStateOf(false) }
var showRenameDialog by remember { mutableStateOf(false) }
var showDeleteDialog by remember { mutableStateOf(false) }
val downloadGroup by vm.downloadGroup.collectAsStateWithLifecycle()
val isDownloading by vm.isDownloading.collectAsStateWithLifecycle()
val imagePicker = rememberLauncherForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
uri ?: return@rememberLauncherForActivityResult
val mimeType = context.contentResolver.getType(uri) ?: "image/jpeg"
val bytes = context.contentResolver.openInputStream(uri)?.use { it.readBytes() } ?: return@rememberLauncherForActivityResult
vm.uploadCover(bytes, mimeType)
}
LaunchedEffect(state.deleted) { if (state.deleted) onDeleted() }
if (state.isLoading) { if (state.isLoading) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
@@ -67,7 +94,9 @@ fun PlaylistDetailScreen(
return return
} }
LazyColumn(Modifier.fillMaxSize()) { val listState = rememberLazyListState()
Box(Modifier.fillMaxSize()) {
LazyColumn(Modifier.fillMaxSize(), state = listState) {
item { item {
// ── Hero ───────────────────────────────────────────────────────── // ── Hero ─────────────────────────────────────────────────────────
Box(Modifier.fillMaxWidth()) { Box(Modifier.fillMaxWidth()) {
@@ -108,6 +137,37 @@ fun PlaylistDetailScreen(
tint = Color.White, modifier = Modifier.size(18.dp), tint = Color.White, modifier = Modifier.size(18.dp),
) )
} }
// Edit + Delete buttons (top-right)
Row(
Modifier
.statusBarsPadding()
.padding(end = 14.dp, top = 14.dp)
.align(Alignment.TopEnd),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Box(
Modifier
.size(36.dp)
.clip(CircleShape)
.background(Color.Black.copy(alpha = 0.45f))
.clickable { showRenameDialog = true },
contentAlignment = Alignment.Center,
) {
Icon(Icons.Default.Edit, "Bearbeiten",
tint = Color.White, modifier = Modifier.size(18.dp))
}
Box(
Modifier
.size(36.dp)
.clip(CircleShape)
.background(Color.Black.copy(alpha = 0.45f))
.clickable { showDeleteDialog = true },
contentAlignment = Alignment.Center,
) {
Icon(Icons.Default.Delete, "Löschen",
tint = Color.White, modifier = Modifier.size(18.dp))
}
}
Column( Column(
Modifier Modifier
.align(Alignment.BottomStart) .align(Alignment.BottomStart)
@@ -119,9 +179,14 @@ fun PlaylistDetailScreen(
fontSize = 26.sp, color = Color.White, fontSize = 26.sp, color = Color.White,
maxLines = 2, overflow = TextOverflow.Ellipsis, maxLines = 2, overflow = TextOverflow.Ellipsis,
) )
// Der Besitzer stand hier bisher bei JEDER Liste, auch bei den eigenen, und ohne
// Beschriftung — bei einer geteilten Liste ist genau das die interessante Angabe.
val meta = listOfNotNull( val meta = listOfNotNull(
pl.owner?.takeIf { it.isNotBlank() },
if (pl.songCount > 0) "${pl.songCount} Songs" else null, if (pl.songCount > 0) "${pl.songCount} Songs" else null,
// Gesamtdauer: Subsonic liefert sie beim Playlist-Objekt mit, es kostet
// also keinen zusaetzlichen Aufruf.
if (pl.duration > 0) formatGesamtdauer(pl.duration) else null,
pl.owner?.takeIf { it.isNotBlank() && it != state.currentUser }?.let { "von $it" },
).joinToString(" · ") ).joinToString(" · ")
if (meta.isNotBlank()) { if (meta.isNotBlank()) {
Spacer(Modifier.height(4.dp)) Spacer(Modifier.height(4.dp))
@@ -141,7 +206,10 @@ fun PlaylistDetailScreen(
} }
} }
// ── Play / Shuffle row ──────────────────────────────────────────── // ── Play / Shuffle / Edit / Download ──────────────────────────────
// Four buttons in one row left no room for labels (the Play/Shuffle text was being
// clipped away), so all four are equal-width and icon-only. Play stays filled as the
// primary action; the rest are outlined and tint accent when active/done.
Row( Row(
Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 12.dp), Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp), horizontalArrangement = Arrangement.spacedBy(10.dp),
@@ -151,27 +219,61 @@ fun PlaylistDetailScreen(
modifier = Modifier.weight(1f).height(46.dp), modifier = Modifier.weight(1f).height(46.dp),
colors = ButtonDefaults.buttonColors(containerColor = NsAccent, contentColor = Color.White), colors = ButtonDefaults.buttonColors(containerColor = NsAccent, contentColor = Color.White),
shape = RoundedCornerShape(14.dp), shape = RoundedCornerShape(14.dp),
contentPadding = PaddingValues(0.dp),
) { ) {
Icon(Icons.Default.PlayArrow, null, modifier = Modifier.size(20.dp)) Icon(Icons.Default.PlayArrow, "Abspielen", modifier = Modifier.size(22.dp))
Spacer(Modifier.width(6.dp))
Text("Play", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp)
} }
OutlinedButton( OutlinedButton(
onClick = { if (pl.entry.isNotEmpty()) onPlay(pl.entry.shuffled(), 0) }, onClick = { if (pl.entry.isNotEmpty()) onPlay(pl.entry, -1) }, // -1 = gemischt, der Player mischt
modifier = Modifier.weight(1f).height(46.dp), modifier = Modifier.weight(1f).height(46.dp),
border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(brush = SolidColor(NsAccent.copy(alpha = 0.55f))), border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(brush = SolidColor(NsAccent.copy(alpha = 0.55f))),
shape = RoundedCornerShape(14.dp), shape = RoundedCornerShape(14.dp),
contentPadding = PaddingValues(0.dp),
) { ) {
Icon(Icons.Default.Shuffle, null, modifier = Modifier.size(20.dp), tint = NsAccent) Icon(Icons.Default.Shuffle, "Zufällig abspielen", modifier = Modifier.size(20.dp), tint = NsAccent)
Spacer(Modifier.width(6.dp)) }
Text("Shuffle", fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 15.sp, color = NsAccent) // Toggle edit mode for removing songs
OutlinedButton(
onClick = { editMode = !editMode },
modifier = Modifier.weight(1f).height(46.dp),
border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(
brush = SolidColor(if (editMode) NsAccent else NsOnSurface3)
),
shape = RoundedCornerShape(14.dp),
contentPadding = PaddingValues(0.dp),
) {
Icon(
if (editMode) Icons.Default.Done else Icons.Default.Edit,
if (editMode) "Bearbeiten beenden" else "Titel entfernen",
modifier = Modifier.size(20.dp),
tint = if (editMode) NsAccent else NsOnSurface2,
)
}
// Download button — tappable unless fully done; resumes / re-downloads missing songs
val dlDone = downloadGroup?.let { it.downloadedTracks >= it.totalTracks && it.totalTracks > 0 } ?: false
OutlinedButton(
onClick = { if (!dlDone) vm.downloadPlaylist() },
modifier = Modifier.weight(1f).height(46.dp),
border = ButtonDefaults.outlinedButtonBorder(enabled = true).copy(
brush = SolidColor(if (dlDone) NsAccent else NsOnSurface3)
),
shape = RoundedCornerShape(14.dp),
contentPadding = PaddingValues(0.dp),
) {
when {
dlDone -> Icon(Icons.Default.CheckCircle, "Offline verfügbar", modifier = Modifier.size(20.dp), tint = NsAccent)
isDownloading -> CircularProgressIndicator(modifier = Modifier.size(18.dp), strokeWidth = 2.dp, color = NsAccent)
else -> Icon(Icons.Default.Download, "Herunterladen", modifier = Modifier.size(20.dp), tint = NsOnSurface2)
}
} }
} }
HorizontalDivider(color = NsBorder) HorizontalDivider(color = NsBorder)
} }
itemsIndexed(pl.entry, key = { _, s -> s.id }) { idx, song -> itemsIndexed(pl.entry, key = { idx, s -> "${idx}_${s.id}" }) { idx, song ->
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Box(Modifier.weight(1f)) {
SongRow( SongRow(
song = song, song = song,
coverUrl = coverUrl(song.coverArt), coverUrl = coverUrl(song.coverArt),
@@ -179,9 +281,125 @@ fun PlaylistDetailScreen(
starred = song.starred != null, starred = song.starred != null,
onPlay = { onPlay(pl.entry, idx) }, onPlay = { onPlay(pl.entry, idx) },
onStarToggle = { onStarToggle(song) }, onStarToggle = { onStarToggle(song) },
onMore = onShowContextMenu?.let { cb -> { cb(song) } }, onMore = if (!editMode) onShowContextMenu?.let { cb -> { cb(song) } } else null,
) )
} }
if (editMode) {
IconButton(
onClick = { vm.removeSong(idx) },
modifier = Modifier.padding(end = 4.dp),
) {
Icon(
Icons.Default.RemoveCircleOutline,
"Entfernen",
tint = MaterialTheme.colorScheme.error,
modifier = Modifier.size(22.dp),
)
}
}
}
}
item { Spacer(Modifier.height(16.dp)) } item { Spacer(Modifier.height(16.dp)) }
} }
Rollbalken(
state = listState,
modifier = Modifier.align(Alignment.CenterEnd).padding(vertical = 4.dp),
farbe = NsOnSurface2,
)
}
// ── Rename dialog ─────────────────────────────────────────────────────────
if (showRenameDialog) {
var nameInput by remember { mutableStateOf(pl.name) }
var commentInput by remember { mutableStateOf(pl.comment ?: "") }
AlertDialog(
onDismissRequest = { showRenameDialog = false },
title = { Text("Playlist bearbeiten", fontFamily = Outfit, fontWeight = FontWeight.Bold) },
text = {
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
OutlinedTextField(
value = nameInput,
onValueChange = { nameInput = it },
label = { Text("Name") },
singleLine = true,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
shape = RoundedCornerShape(12.dp),
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = NsAccent,
unfocusedBorderColor = NsOnSurface3,
cursorColor = NsAccent,
),
modifier = Modifier.fillMaxWidth(),
)
OutlinedTextField(
value = commentInput,
onValueChange = { commentInput = it },
label = { Text("Beschreibung") },
minLines = 2,
maxLines = 4,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
shape = RoundedCornerShape(12.dp),
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = NsAccent,
unfocusedBorderColor = NsOnSurface3,
cursorColor = NsAccent,
),
modifier = Modifier.fillMaxWidth(),
)
TextButton(
onClick = { showRenameDialog = false; imagePicker.launch("image/*") },
modifier = Modifier.fillMaxWidth(),
) {
Icon(Icons.Default.AddAPhoto, null,
tint = NsAccent, modifier = Modifier.size(16.dp))
Spacer(Modifier.width(6.dp))
Text("Cover hochladen", color = NsAccent, fontSize = 13.sp)
}
}
},
confirmButton = {
TextButton(
onClick = { vm.rename(nameInput, commentInput); showRenameDialog = false },
enabled = nameInput.isNotBlank(),
) {
Text("Speichern", color = NsAccent, fontFamily = Outfit, fontWeight = FontWeight.Bold)
}
},
dismissButton = {
TextButton(onClick = { showRenameDialog = false }) {
Text("Abbrechen", color = NsOnSurface2)
}
},
containerColor = NsSurface,
)
}
// ── Delete confirmation dialog ────────────────────────────────────────────
if (showDeleteDialog) {
AlertDialog(
onDismissRequest = { showDeleteDialog = false },
title = { Text("Playlist löschen?", fontFamily = Outfit, fontWeight = FontWeight.Bold) },
text = {
Text(
"\"${pl.name}\" wird dauerhaft gelöscht.",
fontFamily = Outfit, color = NsOnSurface2,
)
},
confirmButton = {
TextButton(
onClick = { showDeleteDialog = false; vm.delete() },
enabled = !state.isSaving,
) {
Text("Löschen", color = MaterialTheme.colorScheme.error,
fontFamily = Outfit, fontWeight = FontWeight.Bold)
}
},
dismissButton = {
TextButton(onClick = { showDeleteDialog = false }) {
Text("Abbrechen", color = NsOnSurface2)
}
},
containerColor = NsSurface,
)
}
} }
@@ -57,12 +57,12 @@ fun SearchScreen(
if (r.song.isNotEmpty()) { if (r.song.isNotEmpty()) {
item { ResultHeader("Songs") } item { ResultHeader("Songs") }
items(r.song, key = { it.id }) { song -> items(r.song, key = { it.id }) { song ->
val idx = r.song.indexOf(song)
SongRow( SongRow(
song = song, song = song,
coverUrl = coverUrl(song.coverArt), coverUrl = coverUrl(song.coverArt),
isPlaying = playerState.currentSong?.id == song.id, isPlaying = playerState.currentSong?.id == song.id,
onPlay = { onSongPlay(r.song, idx) }, // Play only the tapped song; Radio mode (if on) fills the rest.
onPlay = { onSongPlay(listOf(song), 0) },
) )
} }
} }
@@ -1,4 +1,4 @@
package com.novasonic.app.ui.screen package com.novasonic.app.ui.screen
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.border import androidx.compose.foundation.border
@@ -18,6 +18,7 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.PasswordVisualTransformation
@@ -27,6 +28,7 @@ import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.ConnStatus
import com.novasonic.app.viewmodel.SettingsViewModel import com.novasonic.app.viewmodel.SettingsViewModel
private val SCROBBLE_OPTIONS = listOf( private val SCROBBLE_OPTIONS = listOf(
@@ -39,11 +41,12 @@ private val SCROBBLE_OPTIONS = listOf(
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun SettingsScreen() { fun SettingsScreen(onOpenStats: () -> Unit = {}, onOpenCompare: () -> Unit = {}) {
val vm: SettingsViewModel = viewModel() val vm: SettingsViewModel = viewModel()
val state by vm.state.collectAsStateWithLifecycle() val state by vm.state.collectAsStateWithLifecycle()
var showPassword by remember { mutableStateOf(false) } var showPassword by remember { mutableStateOf(false) }
var showAbsKey by remember { mutableStateOf(false) }
var showLogoutDialog by remember { mutableStateOf(false) } var showLogoutDialog by remember { mutableStateOf(false) }
var scrobbleExpanded by remember { mutableStateOf(false) } var scrobbleExpanded by remember { mutableStateOf(false) }
@@ -58,9 +61,7 @@ fun SettingsScreen() {
} }
}, },
dismissButton = { dismissButton = {
TextButton(onClick = { showLogoutDialog = false }) { TextButton(onClick = { showLogoutDialog = false }) { Text("Abbrechen", fontFamily = Outfit) }
Text("Abbrechen", fontFamily = Outfit)
}
}, },
containerColor = NsSurface, containerColor = NsSurface,
) )
@@ -79,24 +80,226 @@ fun SettingsScreen() {
color = NsOnSurface, color = NsOnSurface,
) )
// ── 📊 Statistics (TOP) ──────────────────────────────────────────────
OutlinedButton(
onClick = onOpenStats,
modifier = Modifier.fillMaxWidth().height(48.dp),
) {
Text("📊 Meine Statistiken", color = NsOnSurface, fontFamily = Outfit, fontWeight = FontWeight.SemiBold)
}
OutlinedButton(
onClick = onOpenCompare,
modifier = Modifier.fillMaxWidth().height(48.dp),
) {
Text("🎧 Musik-Match", color = NsOnSurface, fontFamily = Outfit, fontWeight = FontWeight.SemiBold)
}
// ── Save button (TOP) ────────────────────────────────────────────────
Spacer(Modifier.height(4.dp))
SaveButton(vm, state.isSaving, state.savedOk, state.error)
// ── 🎨 Theme ─────────────────────────────────────────────────────────
SectionHeader("🎨 Theme")
ThemePicker(currentThemeId = state.theme, onSelect = { id -> vm.onTheme(id); applyNsTheme(id) })
Spacer(Modifier.height(4.dp))
// ── 📊 Bibliothek ────────────────────────────────────────────────────
SectionHeader("📊 Bibliothek")
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Column(Modifier.weight(1f)) {
Text("Abspielhäufigkeit anzeigen", fontFamily = Outfit, fontWeight = FontWeight.Medium, fontSize = 14.sp, color = NsOnSurface)
Text("Zeigt Wiedergabezähler in Song-Reihen an", fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
Switch(
checked = state.showPlayCount, onCheckedChange = vm::onShowPlayCount,
colors = SwitchDefaults.colors(
checkedThumbColor = NsBackground, checkedTrackColor = NsAccent,
uncheckedThumbColor = NsOnSurface2,
),
)
}
// ── ▶ Wiedergabe ────────────────────────────────────────────────────
SectionHeader("▶ Wiedergabe")
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Column(Modifier.weight(1f)) {
Text("Wischen wechselt den Titel", fontFamily = Outfit, fontWeight = FontWeight.Medium, fontSize = 14.sp, color = NsOnSurface)
Text(
if (state.wischenWechseltTitel)
"Im Now-Playing: seitwärts wischen springt zum nächsten oder vorherigen Titel"
else
"Im Now-Playing: seitwärts wischen blättert zwischen Player, Warteschlange und Text",
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
)
}
Switch(
checked = state.wischenWechseltTitel,
onCheckedChange = { vm.onWischenWechseltTitel(it) },
colors = SwitchDefaults.colors(
checkedThumbColor = NsBackground, checkedTrackColor = NsAccent,
uncheckedThumbColor = NsOnSurface2,
),
)
}
// ── 📥 Downloads ─────────────────────────────────────────────────────
SectionHeader("📥 Offline-Downloads")
var wlanWarnung by remember { mutableStateOf(false) }
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Column(Modifier.weight(1f)) {
Text("Nur über WLAN herunterladen", fontFamily = Outfit, fontWeight = FontWeight.Medium, fontSize = 14.sp, color = NsOnSurface)
Text("Pausiert unterwegs und macht im WLAN von selbst weiter", fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
Switch(
// Ausschalten nur mit Rueckfrage: eine grosse Playlist sind schnell mehrere Gigabyte,
// und der Downloader arbeitet sich ohne Zutun durch, bis alles da ist.
checked = state.downloadWifiOnly,
onCheckedChange = { an -> if (an) vm.onDownloadWifiOnly(true) else wlanWarnung = true },
colors = SwitchDefaults.colors(
checkedThumbColor = NsBackground, checkedTrackColor = NsAccent,
uncheckedThumbColor = NsOnSurface2,
),
)
}
if (wlanWarnung) {
AlertDialog(
onDismissRequest = { wlanWarnung = false },
title = { Text("Über mobile Daten laden?", fontFamily = Outfit, fontWeight = FontWeight.Bold) },
text = {
Text(
"Downloads laufen dann auch ohne WLAN weiter — und zwar so lange, bis alles " +
"geladen ist. Eine Playlist mit 1000 Titeln sind leicht mehrere Gigabyte.",
fontFamily = Outfit, fontSize = 14.sp,
)
},
confirmButton = {
TextButton(onClick = { vm.onDownloadWifiOnly(false); wlanWarnung = false }) {
Text("Trotzdem erlauben", fontFamily = Outfit, color = MaterialTheme.colorScheme.error)
}
},
dismissButton = {
TextButton(onClick = { wlanWarnung = false }) {
Text("Abbrechen", fontFamily = Outfit, color = NsAccent)
}
},
)
}
Spacer(Modifier.height(4.dp))
ExposedDropdownMenuBox(expanded = scrobbleExpanded, onExpandedChange = { scrobbleExpanded = it }) {
OutlinedTextField(
value = SCROBBLE_OPTIONS.firstOrNull { it.first == state.scrobbleMode }?.second ?: "30 Sekunden",
onValueChange = {}, readOnly = true,
label = { Text("Scrobble senden nach", fontFamily = Outfit) },
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(scrobbleExpanded) },
modifier = Modifier.menuAnchor(MenuAnchorType.PrimaryNotEditable, true).fillMaxWidth(),
colors = fieldColors(),
)
ExposedDropdownMenu(expanded = scrobbleExpanded, onDismissRequest = { scrobbleExpanded = false }, containerColor = NsSurface2) {
SCROBBLE_OPTIONS.forEach { (key, label) ->
DropdownMenuItem(
text = { Text(label, fontFamily = Outfit, color = NsOnSurface) },
onClick = { vm.onScrobbleMode(key); scrobbleExpanded = false },
colors = MenuDefaults.itemColors(textColor = if (key == state.scrobbleMode) NsAccent else NsOnSurface),
)
}
}
}
Spacer(Modifier.height(4.dp))
// ── 📚 Audiobookshelf ────────────────────────────────────────────────
SectionHeader("📚 Audiobookshelf")
NsTextField(
value = state.absUrl, onValueChange = vm::onAbsUrl,
label = "Server URL", placeholder = "https://audiobooks.beispiel.de",
keyboardType = KeyboardType.Uri,
)
NsTextField(
value = state.absApiKey, onValueChange = vm::onAbsApiKey,
label = "API Key",
hint = "Einstellungen → Profil → API Token in Audiobookshelf",
visualTransformation = if (showAbsKey) VisualTransformation.None else PasswordVisualTransformation(),
keyboardType = KeyboardType.Password,
trailingIcon = {
IconButton(onClick = { showAbsKey = !showAbsKey }) {
Icon(
if (showAbsKey) Icons.Default.VisibilityOff else Icons.Default.Visibility,
contentDescription = null, tint = NsOnSurface2,
)
}
},
)
ConnStatusRow(status = state.absStatus, label = "Nicht konfiguriert", onTest = vm::testAbs)
Spacer(Modifier.height(4.dp))
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Column(Modifier.weight(1f)) {
Text("Kapitel-Fortschrittsanzeige", fontFamily = Outfit, fontWeight = FontWeight.Medium, fontSize = 14.sp, color = NsOnSurface)
Text("Fortschrittsbalken zeigt aktuelles Kapitel statt Gesamtlänge", fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
Switch(
checked = state.absChapterTrackMode, onCheckedChange = vm::onAbsChapterTrackMode,
colors = SwitchDefaults.colors(
checkedThumbColor = NsBackground, checkedTrackColor = NsAccent,
uncheckedThumbColor = NsOnSurface2,
),
)
}
Spacer(Modifier.height(4.dp))
// ── 🔑 Discover APIs ─────────────────────────────────────────────────
SectionHeader("🔑 Discover APIs")
NsTextField(
value = state.lastFmKey, onValueChange = vm::onLastFmKey,
label = "Last.fm API Key",
hint = "Kostenlos unter last.fm/api/account/create",
)
// Vorbelegt aus BuildConfig (siehe build.gradle.kts): auf einem frischen Geraet muss nichts
// eingetippt werden. Das Feld bleibt trotzdem bedienbar — zieht der Dienst um, laesst sich
// das hier korrigieren, ohne ein neues APK zu bauen.
NsTextField(
value = state.backendUrl, onValueChange = vm::onBackendUrl,
label = "NovaSonic Backend URL",
hint = "Für Download-to-Server via yt-dlp",
keyboardType = KeyboardType.Uri,
)
ConnStatusRow(status = state.backendStatus, label = "Nicht konfiguriert", onTest = vm::testBackend)
NsTextField(
value = state.scrobbleUrl, onValueChange = vm::onScrobbleUrl,
label = "NovaSonic Scrobble URL",
hint = "Play-Log für Statistiken (Port 3710)",
keyboardType = KeyboardType.Uri,
)
ConnStatusRow(status = state.scrobbleStatus, label = "Nicht konfiguriert", onTest = vm::testScrobble)
Spacer(Modifier.height(4.dp))
// ── 🌐 Navidrome Server ────────────────────────────────────────────── // ── 🌐 Navidrome Server ──────────────────────────────────────────────
SectionHeader("🌐 Navidrome Server") SectionHeader("🌐 Navidrome Server")
NsTextField( NsTextField(
value = state.serverUrl, value = state.serverUrl, onValueChange = vm::onServerUrl,
onValueChange = vm::onServerUrl, label = "Server URL", placeholder = "https://musik.beispiel.de",
label = "Server URL",
placeholder = "https://musik.beispiel.de",
keyboardType = KeyboardType.Uri, keyboardType = KeyboardType.Uri,
) )
NsTextField( NsTextField(
value = state.username, value = state.username, onValueChange = vm::onUsername,
onValueChange = vm::onUsername,
label = "Benutzername", label = "Benutzername",
) )
NsTextField( NsTextField(
value = state.password, value = state.password, onValueChange = vm::onPassword,
onValueChange = vm::onPassword,
label = "Passwort", label = "Passwort",
hint = "(unverändert lassen wenn kein Reset gewünscht)", hint = "(unverändert lassen wenn kein Reset gewünscht)",
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(), visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
@@ -111,124 +314,8 @@ fun SettingsScreen() {
}, },
) )
Spacer(Modifier.height(4.dp))
// ── 📊 Bibliothek ────────────────────────────────────────────────────
SectionHeader("📊 Bibliothek")
// Scrobble-Mode dropdown
ExposedDropdownMenuBox(
expanded = scrobbleExpanded,
onExpandedChange = { scrobbleExpanded = it },
) {
OutlinedTextField(
value = SCROBBLE_OPTIONS.firstOrNull { it.first == state.scrobbleMode }?.second
?: "30 Sekunden",
onValueChange = {},
readOnly = true,
label = { Text("Scrobble senden nach", fontFamily = Outfit) },
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(scrobbleExpanded) },
modifier = Modifier.menuAnchor(MenuAnchorType.PrimaryNotEditable, true).fillMaxWidth(),
colors = fieldColors(),
)
ExposedDropdownMenu(
expanded = scrobbleExpanded,
onDismissRequest = { scrobbleExpanded = false },
containerColor = NsSurface2,
) {
SCROBBLE_OPTIONS.forEach { (key, label) ->
DropdownMenuItem(
text = { Text(label, fontFamily = Outfit, color = NsOnSurface) },
onClick = { vm.onScrobbleMode(key); scrobbleExpanded = false },
colors = MenuDefaults.itemColors(
textColor = if (key == state.scrobbleMode) NsAccent else NsOnSurface
),
)
}
}
}
// Show play count toggle
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),
) {
Column(Modifier.weight(1f)) {
Text("Abspielhäufigkeit anzeigen", fontFamily = Outfit,
fontWeight = FontWeight.Medium, fontSize = 14.sp, color = NsOnSurface)
Text("Zeigt Wiedergabezähler in Song-Reihen an",
fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2)
}
Switch(
checked = state.showPlayCount,
onCheckedChange = vm::onShowPlayCount,
colors = SwitchDefaults.colors(
checkedThumbColor = NsBackground,
checkedTrackColor = NsAccent,
uncheckedThumbColor = NsOnSurface2,
),
)
}
Spacer(Modifier.height(4.dp))
// ── 🎨 Theme ─────────────────────────────────────────────────────────
SectionHeader("🎨 Theme")
ThemePicker(
currentThemeId = state.theme,
onSelect = { id ->
vm.onTheme(id)
applyNsTheme(id)
},
)
Spacer(Modifier.height(4.dp))
// ── 🔑 APIs ──────────────────────────────────────────────────────────
SectionHeader("🔑 APIs")
NsTextField(
value = state.lastFmKey,
onValueChange = vm::onLastFmKey,
label = "Last.fm API Key",
hint = "Kostenlos unter last.fm/api/account/create",
)
NsTextField(
value = state.backendUrl,
onValueChange = vm::onBackendUrl,
label = "NovaSonic Backend URL",
hint = "Für Download-to-Server via yt-dlp",
keyboardType = KeyboardType.Uri,
)
Spacer(Modifier.height(8.dp)) Spacer(Modifier.height(8.dp))
// Status + Save
if (state.error != null) {
Text(state.error!!, color = MaterialTheme.colorScheme.error,
fontFamily = Outfit, fontSize = 13.sp)
}
if (state.savedOk) {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(Icons.Default.Check, null, tint = NsAccent, modifier = Modifier.size(16.dp))
Spacer(Modifier.width(6.dp))
Text("Gespeichert", color = NsAccent, fontFamily = Outfit, fontSize = 13.sp)
}
}
Button(
onClick = vm::save,
enabled = !state.isSaving,
modifier = Modifier.fillMaxWidth().height(48.dp),
colors = ButtonDefaults.buttonColors(containerColor = NsAccent, contentColor = NsBackground),
) {
if (state.isSaving) {
CircularProgressIndicator(modifier = Modifier.size(20.dp), strokeWidth = 2.dp, color = NsBackground)
} else {
Text("Speichern", fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 15.sp)
}
}
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp), color = NsBorder) HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp), color = NsBorder)
OutlinedButton( OutlinedButton(
@@ -238,14 +325,75 @@ fun SettingsScreen() {
brush = androidx.compose.ui.graphics.SolidColor(MaterialTheme.colorScheme.error) brush = androidx.compose.ui.graphics.SolidColor(MaterialTheme.colorScheme.error)
), ),
) { ) {
Text("Abmelden", color = MaterialTheme.colorScheme.error, Text("Abmelden", color = MaterialTheme.colorScheme.error, fontFamily = Outfit, fontWeight = FontWeight.SemiBold)
fontFamily = Outfit, fontWeight = FontWeight.SemiBold)
} }
Spacer(Modifier.height(24.dp)) Spacer(Modifier.height(24.dp))
} }
} }
@Composable
private fun SaveButton(vm: SettingsViewModel, isSaving: Boolean, savedOk: Boolean, error: String?) {
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
if (error != null) {
Text(error, color = MaterialTheme.colorScheme.error, fontFamily = Outfit, fontSize = 13.sp)
}
if (savedOk) {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(Icons.Default.Check, null, tint = NsAccent, modifier = Modifier.size(16.dp))
Spacer(Modifier.width(6.dp))
Text("Gespeichert", color = NsAccent, fontFamily = Outfit, fontSize = 13.sp)
}
}
Button(
onClick = vm::save,
enabled = !isSaving,
modifier = Modifier.fillMaxWidth().height(48.dp),
colors = ButtonDefaults.buttonColors(containerColor = NsAccent, contentColor = NsBackground),
) {
if (isSaving) {
CircularProgressIndicator(modifier = Modifier.size(20.dp), strokeWidth = 2.dp, color = NsBackground)
} else {
Text("Speichern", fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 15.sp)
}
}
}
}
@Composable
private fun ConnStatusRow(status: ConnStatus, label: String, onTest: () -> Unit) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(vertical = 2.dp),
) {
when (status) {
ConnStatus.Idle -> Spacer(Modifier.size(10.dp))
ConnStatus.Checking -> CircularProgressIndicator(modifier = Modifier.size(10.dp), strokeWidth = 1.5.dp, color = NsAccent)
is ConnStatus.Ok -> Box(Modifier.size(10.dp).clip(CircleShape).background(Color(0xFF4CAF50)))
is ConnStatus.Err -> Box(Modifier.size(10.dp).clip(CircleShape).background(Color(0xFFE53935)))
}
Spacer(Modifier.width(8.dp))
Text(
text = when (status) {
ConnStatus.Idle -> label
ConnStatus.Checking -> "Verbinde…"
is ConnStatus.Ok -> status.text
is ConnStatus.Err -> status.text
},
fontFamily = Outfit, fontSize = 12.sp,
color = when (status) {
is ConnStatus.Ok -> Color(0xFF4CAF50)
is ConnStatus.Err -> Color(0xFFE53935)
else -> NsOnSurface2
},
modifier = Modifier.weight(1f),
)
TextButton(onClick = onTest, contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp)) {
Text("Testen", fontFamily = Outfit, fontSize = 12.sp, color = NsAccent)
}
}
}
@Composable @Composable
private fun SectionHeader(title: String) { private fun SectionHeader(title: String) {
Text( Text(
@@ -271,8 +419,7 @@ private fun NsTextField(
) { ) {
Column { Column {
OutlinedTextField( OutlinedTextField(
value = value, value = value, onValueChange = onValueChange,
onValueChange = onValueChange,
label = { Text(label, fontFamily = Outfit) }, label = { Text(label, fontFamily = Outfit) },
placeholder = if (placeholder.isNotBlank()) { { Text(placeholder, color = NsOnSurface2) } } else null, placeholder = if (placeholder.isNotBlank()) { { Text(placeholder, color = NsOnSurface2) } } else null,
singleLine = true, singleLine = true,
@@ -308,29 +455,15 @@ private fun ThemePicker(currentThemeId: String, onSelect: (String) -> Unit) {
.clickable { onSelect(theme.id) } .clickable { onSelect(theme.id) }
.padding(horizontal = 12.dp, vertical = 10.dp), .padding(horizontal = 12.dp, vertical = 10.dp),
) { ) {
// Accent dot Box(Modifier.size(22.dp).clip(CircleShape).background(theme.accent))
Box(
Modifier
.size(22.dp)
.clip(CircleShape)
.background(theme.accent),
)
Spacer(Modifier.width(12.dp)) Spacer(Modifier.width(12.dp))
Text( Text(
text = theme.name, text = theme.name, fontFamily = Outfit,
fontFamily = Outfit,
fontWeight = if (isActive) FontWeight.SemiBold else FontWeight.Normal, fontWeight = if (isActive) FontWeight.SemiBold else FontWeight.Normal,
fontSize = 14.sp, fontSize = 14.sp, color = if (isActive) theme.onSurface else NsOnSurface2,
color = if (isActive) theme.onSurface else NsOnSurface2,
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
) )
if (isActive) { if (isActive) Icon(Icons.Default.Check, null, tint = theme.accent, modifier = Modifier.size(18.dp))
Icon(
Icons.Default.Check, null,
tint = theme.accent,
modifier = Modifier.size(18.dp),
)
}
} }
} }
} }
@@ -338,11 +471,7 @@ private fun ThemePicker(currentThemeId: String, onSelect: (String) -> Unit) {
@Composable @Composable
private fun fieldColors() = OutlinedTextFieldDefaults.colors( private fun fieldColors() = OutlinedTextFieldDefaults.colors(
focusedBorderColor = NsAccent, focusedBorderColor = NsAccent, focusedLabelColor = NsAccent, cursorColor = NsAccent,
focusedLabelColor = NsAccent, unfocusedBorderColor = NsOnSurface3, unfocusedLabelColor = NsOnSurface2,
cursorColor = NsAccent, focusedTextColor = NsOnSurface, unfocusedTextColor = NsOnSurface,
unfocusedBorderColor = NsOnSurface3,
unfocusedLabelColor = NsOnSurface2,
focusedTextColor = NsOnSurface,
unfocusedTextColor = NsOnSurface,
) )
@@ -1,8 +1,19 @@
package com.novasonic.app.ui.screen package com.novasonic.app.ui.screen
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.style.TextOverflow
import coil.compose.AsyncImage
import com.novasonic.app.ui.component.AlbumCard
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@@ -18,9 +29,13 @@ import com.novasonic.app.app
import com.novasonic.app.player.PlayerState import com.novasonic.app.player.PlayerState
import com.novasonic.app.ui.component.SongRow import com.novasonic.app.ui.component.SongRow
import com.novasonic.app.ui.theme.* import com.novasonic.app.ui.theme.*
import com.novasonic.app.ui.component.Rollbalken
enum class StarredSort { NEWEST, OLDEST, AZ, BY_ARTIST } enum class StarredSort { NEWEST, OLDEST, AZ, BY_ARTIST }
/** So viele gefolgte Kuenstler stehen in der Reihe, der Rest hinter "Alle anzeigen". */
private const val GEZEIGT = 10
@Composable @Composable
fun StarredScreen( fun StarredScreen(
coverUrl: (String?) -> String?, coverUrl: (String?) -> String?,
@@ -28,18 +43,29 @@ fun StarredScreen(
onPlay: (List<Song>, Int) -> Unit, onPlay: (List<Song>, Int) -> Unit,
onStarToggle: (Song) -> Unit, onStarToggle: (Song) -> Unit,
onShowContextMenu: ((Song) -> Unit)? = null, onShowContextMenu: ((Song) -> Unit)? = null,
onArtistClick: (String) -> Unit = {},
onAlbumClick: (String) -> Unit = {},
onOpenNews: () -> Unit = {},
onOpenFollowed: () -> Unit = {},
) { ) {
val context = LocalContext.current val context = LocalContext.current
val repo = context.app.repository val repo = context.app.repository
var songs by remember { mutableStateOf<List<Song>>(emptyList()) } var songs by remember { mutableStateOf<List<Song>>(emptyList()) }
// getStarred2 liefert Kuenstler und Alben im SELBEN Paket wie die Songs — die Uebersicht
// "wem folge ich" kostet also keinen zusaetzlichen Aufruf.
var gefolgteKuenstler by remember { mutableStateOf<List<com.novasonic.app.api.model.Artist>>(emptyList()) }
var gemerkteAlben by remember { mutableStateOf<List<com.novasonic.app.api.model.Album>>(emptyList()) }
var loading by remember { mutableStateOf(true) } var loading by remember { mutableStateOf(true) }
var error by remember { mutableStateOf<String?>(null) } var error by remember { mutableStateOf<String?>(null) }
var sort by remember { mutableStateOf(StarredSort.NEWEST) } var sort by remember { mutableStateOf(StarredSort.NEWEST) }
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
try { try {
songs = repo.getStarred().song val markiert = repo.getStarred()
songs = markiert.song
gefolgteKuenstler = markiert.artist.sortedBy { it.name.lowercase() }
gemerkteAlben = markiert.album.sortedByDescending { it.starred ?: "" }
loading = false loading = false
} catch (e: Exception) { } catch (e: Exception) {
error = e.message error = e.message
@@ -57,12 +83,25 @@ fun StarredScreen(
} }
Column(Modifier.fillMaxSize()) { Column(Modifier.fillMaxSize()) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(start = 20.dp, end = 12.dp, top = 24.dp, bottom = 8.dp),
) {
Text( Text(
"Favoriten", "Favoriten",
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 26.sp, fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 26.sp,
color = MaterialTheme.colorScheme.onSurface, color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(start = 20.dp, top = 24.dp, bottom = 8.dp), modifier = Modifier.weight(1f),
) )
// Einstieg in die Zeitleiste: hier stehen die gefolgten Künstler, also liegt die Frage
// "was gibt es Neues von denen" nahe.
if (gefolgteKuenstler.isNotEmpty()) {
TextButton(onClick = onOpenNews) {
Text("✨ Neu", fontFamily = Outfit, fontWeight = FontWeight.SemiBold,
fontSize = 13.sp, color = NsAccent)
}
}
}
// Sort chips // Sort chips
Row( Row(
@@ -100,12 +139,53 @@ fun StarredScreen(
Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) { Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) {
Text(error!!, color = MaterialTheme.colorScheme.error) Text(error!!, color = MaterialTheme.colorScheme.error)
} }
} else if (sorted.isEmpty()) { } else if (sorted.isEmpty() && gefolgteKuenstler.isEmpty() && gemerkteAlben.isEmpty()) {
Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) { Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) {
Text("Noch keine Favoriten", color = NsOnSurface2) Text("Noch keine Favoriten", color = NsOnSurface2)
} }
} else { } else {
LazyColumn { val listState = rememberLazyListState()
Box(Modifier.fillMaxSize()) {
LazyColumn(state = listState) {
if (gefolgteKuenstler.isNotEmpty()) {
item { FavoritenLabel("Künstler, denen du folgst (${gefolgteKuenstler.size})") }
item {
LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
) {
// Die LazyRow baut zwar nur Sichtbares, aber eine endlose Reihe ist
// zum Durchsehen untauglich — der Rest gehoert in die gefilterte
// Kuenstlerliste. GEZEIGT deckt zwei Bildschirmbreiten ab.
items(gefolgteKuenstler.take(GEZEIGT), key = { it.id }) { a ->
GefolgterKuenstler(a.name, coverUrl(a.coverArt), a.albumCount) { onArtistClick(a.id) }
}
if (gefolgteKuenstler.size > GEZEIGT) {
item(key = "alle_kuenstler") {
AlleAnzeigen(gefolgteKuenstler.size - GEZEIGT, onOpenFollowed)
}
}
}
Spacer(Modifier.height(8.dp))
}
}
if (gemerkteAlben.isNotEmpty()) {
item { FavoritenLabel("Gemerkte Alben (${gemerkteAlben.size})") }
item {
LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
) {
items(gemerkteAlben, key = { it.id }) { al ->
AlbumCard(album = al, coverUrl = coverUrl(al.coverArt)) { onAlbumClick(al.id) }
}
}
Spacer(Modifier.height(8.dp))
}
}
if (sorted.isNotEmpty() && (gefolgteKuenstler.isNotEmpty() || gemerkteAlben.isNotEmpty())) {
item { FavoritenLabel("Songs (${sorted.size})") }
}
itemsIndexed(sorted, key = { _, s -> s.id }) { idx, song -> itemsIndexed(sorted, key = { _, s -> s.id }) { idx, song ->
SongRow( SongRow(
song = song, song = song,
@@ -119,6 +199,58 @@ fun StarredScreen(
} }
item { Spacer(Modifier.height(8.dp)) } item { Spacer(Modifier.height(8.dp)) }
} }
Rollbalken(
state = listState,
modifier = Modifier.align(Alignment.CenterEnd).padding(vertical = 4.dp),
farbe = NsOnSurface2,
)
}
} }
} }
} }
@Composable
private fun FavoritenLabel(titel: String) {
Text(
titel,
fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 13.sp,
color = NsOnSurface2,
modifier = Modifier.padding(start = 20.dp, top = 14.dp, bottom = 8.dp),
)
}
@Composable
private fun GefolgterKuenstler(name: String, bild: String?, albumCount: Int, onClick: () -> Unit) {
Column(Modifier.width(110.dp).clickable(onClick = onClick)) {
AsyncImage(
model = bild, contentDescription = name,
contentScale = ContentScale.Crop,
modifier = Modifier.size(110.dp).clip(CircleShape).background(NsSurface2),
)
Spacer(Modifier.height(6.dp))
Text(name, fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 13.sp,
maxLines = 1, overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colorScheme.onSurface)
Text("$albumCount Alben", fontFamily = Outfit, fontSize = 11.sp,
color = NsOnSurface2, maxLines = 1)
}
}
@Composable
private fun AlleAnzeigen(weitere: Int, onClick: () -> Unit) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.width(110.dp).clickable(onClick = onClick),
) {
Box(
Modifier.size(110.dp).clip(CircleShape).background(NsSurface2),
contentAlignment = Alignment.Center,
) {
Text("→", fontSize = 26.sp, color = NsAccent)
}
Spacer(Modifier.height(6.dp))
Text("Alle anzeigen", fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 13.sp,
maxLines = 1, color = MaterialTheme.colorScheme.onSurface)
Text("+$weitere weitere", fontFamily = Outfit, fontSize = 11.sp, color = NsOnSurface2, maxLines = 1)
}
}
@@ -0,0 +1,347 @@
package com.novasonic.app.ui.screen
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
import com.novasonic.app.api.model.ScrobbleStats
import com.novasonic.app.ui.theme.*
import com.novasonic.app.viewmodel.StatsView
import com.novasonic.app.viewmodel.StatsViewModel
private val MONTHS = listOf(
"Januar", "Februar", "März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember",
)
@Composable
fun StatsScreen(
coverUrl: (String?) -> String?,
onBack: () -> Unit,
onArtistClick: (String) -> Unit = {},
onAlbumClick: (String) -> Unit = {},
vm: StatsViewModel = viewModel(),
) {
val state by vm.state.collectAsStateWithLifecycle()
Column(Modifier.fillMaxSize().background(NsBackground)) {
// ── Top bar ──
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(start = 4.dp, top = 8.dp, end = 12.dp),
) {
IconButton(onClick = onBack) {
Icon(Icons.Default.ArrowBack, contentDescription = "Zurück", tint = NsOnSurface)
}
Text(
"Meine Statistiken",
fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 22.sp,
color = NsOnSurface,
)
}
// ── Navigator: scope chips + year/month stepper ──
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(start = 16.dp, end = 12.dp, top = 8.dp, bottom = 8.dp),
) {
listOf(StatsView.ALL to "Alles", StatsView.YEAR to "Jahr", StatsView.MONTH to "Monat").forEach { (v, l) ->
val active = v == state.view
Text(
l,
fontFamily = Outfit, fontSize = 13.sp, fontWeight = FontWeight.SemiBold,
color = if (active) Color.White else NsOnSurface2,
modifier = Modifier
.padding(end = 8.dp)
.clip(RoundedCornerShape(999.dp))
.background(if (active) NsAccent else Color.Transparent)
.clickable { vm.setView(v) }
.padding(horizontal = 14.dp, vertical = 7.dp),
)
}
if (state.view != StatsView.ALL) {
Spacer(Modifier.weight(1f))
StepArrow("‹", enabled = !vm.atStart()) { vm.step(-1) }
Text(
if (state.view == StatsView.YEAR) state.year.toString() else "${MONTHS[state.month]} ${state.year}",
fontFamily = Outfit, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = NsOnSurface,
modifier = Modifier.padding(horizontal = 8.dp),
)
StepArrow("›", enabled = !vm.atCurrent()) { vm.step(1) }
}
}
when {
state.loading -> CenterBox { CircularProgressIndicator(color = NsAccent) }
!state.configured -> CenterMessage(
"Kein Scrobble-Dienst konfiguriert.\nTrage die Scrobble-URL in den Einstellungen ein.",
)
state.error != null -> CenterMessage(state.error!!, NsError)
(state.stats?.totalPlays ?: 0) == 0 -> CenterMessage(
"Noch keine Wiedergaben in diesem Zeitraum.\nSpiel ein paar Songs — sie erscheinen hier automatisch.",
)
else -> StatsContent(state.stats!!, coverUrl, onArtistClick, onAlbumClick)
}
}
}
@Composable
private fun StatsContent(
d: ScrobbleStats,
coverUrl: (String?) -> String?,
onArtistClick: (String) -> Unit,
onAlbumClick: (String) -> Unit,
) {
Column(
Modifier.fillMaxSize().verticalScroll(rememberScrollState())
.padding(horizontal = 16.dp).padding(bottom = 24.dp),
) {
// Tiles
Row(horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.padding(bottom = 18.dp)) {
Tile(d.totalPlays.toString(), "Plays", Modifier.weight(1f))
Tile(fmtTime(d.totalSeconds), "Hörzeit", Modifier.weight(1f))
Tile(if (d.topArtists.size >= 10) "10+" else d.topArtists.size.toString(), "Künstler", Modifier.weight(1f))
}
if (d.series.isNotEmpty()) {
SectionHeader("Verlauf")
SeriesChart(d.series)
Spacer(Modifier.height(20.dp))
}
if (d.topArtists.isNotEmpty()) {
SectionHeader("Top-Künstler")
d.topArtists.forEachIndexed { i, a ->
TopRow(i + 1, coverUrl(a.artistId), a.name ?: "—", null, a.plays, circular = true,
onClick = a.artistId?.let { id -> { onArtistClick(id) } })
}
Spacer(Modifier.height(20.dp))
}
if (d.topTracks.isNotEmpty()) {
SectionHeader("Top-Songs")
d.topTracks.forEachIndexed { i, t ->
TopRow(i + 1, coverUrl(t.coverArt ?: t.albumId ?: t.songId), t.title ?: "—", t.artist, t.plays,
onClick = t.albumId?.let { id -> { onAlbumClick(id) } })
}
Spacer(Modifier.height(20.dp))
}
if (d.topAlbums.isNotEmpty()) {
SectionHeader("Top-Alben")
d.topAlbums.forEachIndexed { i, a ->
TopRow(i + 1, coverUrl(a.coverArt ?: a.albumId), a.name ?: "—", a.artist, a.plays,
onClick = a.albumId?.let { id -> { onAlbumClick(id) } })
}
Spacer(Modifier.height(20.dp))
}
if (d.topGenres.isNotEmpty()) {
SectionHeader("Top-Genres")
d.topGenres.forEachIndexed { i, g -> GenreRow(i + 1, g.name ?: "—", g.plays) }
Spacer(Modifier.height(20.dp))
}
if (d.byHour.any { it.plays > 0 }) {
SectionHeader("Hör-Uhr (Stunde)")
HourClock(d.byHour.map { it.plays })
}
}
}
@Composable
private fun GenreRow(rank: Int, name: String, plays: Int) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp),
) {
Text(
rank.toString(), fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 13.sp,
color = NsOnSurface2, modifier = Modifier.width(22.dp),
)
Text(
name, fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 14.sp,
color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f).padding(horizontal = 12.dp),
)
Text("$plays", fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 13.sp, color = NsOnSurface2)
}
}
@Composable
private fun StepArrow(glyph: String, enabled: Boolean, onClick: () -> Unit) {
Text(
glyph,
fontFamily = Outfit, fontSize = 20.sp, fontWeight = FontWeight.Bold,
color = if (enabled) NsOnSurface else NsOnSurface2.copy(alpha = 0.35f),
modifier = Modifier
.clip(RoundedCornerShape(8.dp))
.then(if (enabled) Modifier.clickable(onClick = onClick) else Modifier)
.padding(horizontal = 8.dp, vertical = 2.dp),
)
}
@Composable
private fun Tile(value: String, label: String, modifier: Modifier = Modifier) {
Column(
modifier
.clip(RoundedCornerShape(12.dp))
.background(NsSurface2)
.padding(14.dp),
) {
Text(value, fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 22.sp, color = NsOnSurface, maxLines = 1)
Text(label, fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2, modifier = Modifier.padding(top = 2.dp))
}
}
@Composable
private fun SectionHeader(t: String) {
Text(
t.uppercase(), fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 12.sp,
letterSpacing = 0.6.sp, color = NsOnSurface2, modifier = Modifier.padding(bottom = 8.dp),
)
}
@Composable
private fun TopRow(
rank: Int, cover: String?, title: String, subtitle: String?, plays: Int, circular: Boolean = false,
onClick: (() -> Unit)? = null,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
.then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier)
.padding(vertical = 5.dp),
) {
Text(
rank.toString(), fontFamily = Outfit, fontWeight = FontWeight.Bold, fontSize = 13.sp,
color = NsOnSurface2, modifier = Modifier.width(22.dp),
)
Box(
Modifier
.size(44.dp)
.clip(if (circular) CircleShape else RoundedCornerShape(6.dp))
.background(NsSurface2),
) {
AsyncImage(
model = cover, contentDescription = null, contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize(),
)
}
Column(Modifier.weight(1f).padding(horizontal = 12.dp)) {
Text(title, fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 14.sp,
color = NsOnSurface, maxLines = 1, overflow = TextOverflow.Ellipsis)
if (!subtitle.isNullOrBlank()) {
Text(subtitle, fontFamily = Outfit, fontSize = 12.sp, color = NsOnSurface2,
maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
Text("$plays", fontFamily = Outfit, fontWeight = FontWeight.SemiBold, fontSize = 13.sp, color = NsOnSurface2)
}
}
@Composable
private fun SeriesChart(series: List<com.novasonic.app.api.model.StatBucket>) {
val max = (series.maxOfOrNull { it.plays } ?: 1).coerceAtLeast(1)
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.Bottom,
modifier = Modifier.fillMaxWidth().height(110.dp).horizontalScroll(rememberScrollState()),
) {
series.forEach { s ->
Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.width(30.dp)) {
Box(
Modifier
.width(20.dp)
.height((6 + (84 * s.plays / max)).dp)
.clip(RoundedCornerShape(topStart = 4.dp, topEnd = 4.dp))
.background(NsAccent),
)
Text(
seriesLabel(s.bucket), fontFamily = Outfit, fontSize = 9.sp, color = NsOnSurface2,
maxLines = 1, modifier = Modifier.padding(top = 4.dp),
)
}
}
}
}
@Composable
private fun HourClock(hours: List<Int>) {
val max = (hours.maxOrNull() ?: 1).coerceAtLeast(1)
Row(
horizontalArrangement = Arrangement.spacedBy(2.dp),
verticalAlignment = Alignment.Bottom,
modifier = Modifier.fillMaxWidth().height(72.dp),
) {
hours.forEachIndexed { h, plays ->
Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.weight(1f)) {
Box(
Modifier
.fillMaxWidth()
.height((2 + (48 * plays / max)).dp)
.clip(RoundedCornerShape(topStart = 3.dp, topEnd = 3.dp))
.background(if (plays > 0) NsAccent else NsSurface2),
)
Text(
if (h % 6 == 0) h.toString() else "",
fontFamily = Outfit, fontSize = 9.sp, color = NsOnSurface2,
modifier = Modifier.padding(top = 3.dp),
)
}
}
}
}
@Composable
private fun CenterBox(content: @Composable BoxScope.() -> Unit) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center, content = content)
}
@Composable
private fun CenterMessage(msg: String, color: Color = NsOnSurface2) {
Box(Modifier.fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) {
Text(msg, fontFamily = Outfit, fontSize = 14.sp, color = color)
}
}
// "3h 12m" / "12m" / "45s"
private fun fmtTime(sec: Long): String {
val h = sec / 3600
val m = (sec % 3600) / 60
return when {
h > 0 -> "${h}h ${m}m"
m > 0 -> "${m}m"
else -> "${sec}s"
}
}
// "2025-08" -> "08.25", "2025-08-03" -> "03.08", "2025" -> "2025"
private fun seriesLabel(b: String): String = when {
b.length == 7 -> b.substring(5) + "." + b.substring(2, 4)
b.length == 10 -> b.substring(8) + "." + b.substring(5, 7)
else -> b
}
@@ -7,6 +7,7 @@ import androidx.compose.ui.graphics.Color
// ── Dynamic theme state — Compose tracks reads automatically ───────────────── // ── Dynamic theme state — Compose tracks reads automatically ─────────────────
object NsColors { object NsColors {
var themeId by mutableStateOf("dark-ocean") // currently applied theme id (readable)
var accent by mutableStateOf(Color(0xFF4F8EF7)) var accent by mutableStateOf(Color(0xFF4F8EF7))
var accentDim by mutableStateOf(Color(0xFF2A6CD6)) var accentDim by mutableStateOf(Color(0xFF2A6CD6))
var bg by mutableStateOf(Color(0xFF070D14)) var bg by mutableStateOf(Color(0xFF070D14))
@@ -84,10 +85,25 @@ val NS_THEMES = listOf(
Color(0xFF162A21), Color(0xFF1E3A2D), Color(0xFF162A21), Color(0xFF1E3A2D),
Color(0xFFE8FFF1), Color(0xFF8FBFA4), Color(0xFF557A63), Color(0xFFE8FFF1), Color(0xFF8FBFA4), Color(0xFF557A63),
), ),
NsTheme(
"violet", "Violet",
Color(0xFFA78BFA), Color(0xFF7C5CF0),
Color(0xFF0D0916), Color(0xFF140E20),
Color(0xFF221835), Color(0xFF2D2145),
Color(0xFFF2EDFF), Color(0xFF9B8BBD), Color(0xFF655780),
),
NsTheme(
"crimson", "Crimson",
Color(0xFFE05263), Color(0xFFB03445),
Color(0xFF120708), Color(0xFF1A0B0D),
Color(0xFF2B1316), Color(0xFF3A1A1E),
Color(0xFFFFEEF0), Color(0xFFBF8D94), Color(0xFF7D545C),
),
) )
fun applyNsTheme(themeId: String) { fun applyNsTheme(themeId: String) {
val t = NS_THEMES.find { it.id == themeId } ?: NS_THEMES.first() val t = NS_THEMES.find { it.id == themeId } ?: NS_THEMES.first()
NsColors.themeId = t.id
NsColors.accent = t.accent NsColors.accent = t.accent
NsColors.accentDim = t.accentDim NsColors.accentDim = t.accentDim
NsColors.bg = t.bg NsColors.bg = t.bg
@@ -6,8 +6,10 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.model.Album import com.novasonic.app.api.model.Album
import com.novasonic.app.app import com.novasonic.app.app
import kotlinx.coroutines.flow.MutableStateFlow import com.novasonic.app.offline.DownloadGroupEntity
import kotlinx.coroutines.flow.StateFlow import com.novasonic.app.offline.DownloadState
import com.novasonic.app.offline.GroupType
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
data class AlbumUiState( data class AlbumUiState(
@@ -19,11 +21,25 @@ data class AlbumUiState(
class AlbumViewModel(app: Application, savedState: SavedStateHandle) : AndroidViewModel(app) { class AlbumViewModel(app: Application, savedState: SavedStateHandle) : AndroidViewModel(app) {
private val repo = app.app.repository private val repo = app.app.repository
/** Album merken — optimistisch ueber StarState, faellt bei einem Fehlschlag zurueck. */
fun merkenUmschalten(albumId: String, aktuellMarkiert: Boolean) =
com.novasonic.app.data.StarState.toggle(repo, viewModelScope, albumId, aktuellMarkiert)
private val offlineRepo = app.app.offlineRepository
private val albumId: String? = savedState["albumId"] private val albumId: String? = savedState["albumId"]
private val _state = MutableStateFlow(AlbumUiState()) private val _state = MutableStateFlow(AlbumUiState())
val state: StateFlow<AlbumUiState> = _state val state: StateFlow<AlbumUiState> = _state
val downloadGroup: StateFlow<DownloadGroupEntity?> = offlineRepo.allGroupsFlow
.map { groups -> groups.find { it.groupId == "album:$albumId" } }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null)
/** True while any track in this album's group is queued or actively downloading. */
val isDownloading: StateFlow<Boolean> = offlineRepo.tracksForGroupFlow("album:$albumId")
.map { tracks -> tracks.any { it.state == DownloadState.QUEUED || it.state == DownloadState.DOWNLOADING } }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)
init { init {
val id = albumId val id = albumId
if (id.isNullOrBlank()) { if (id.isNullOrBlank()) {
@@ -39,4 +55,19 @@ class AlbumViewModel(app: Application, savedState: SavedStateHandle) : AndroidVi
} }
} }
} }
fun downloadAlbum() {
val album = _state.value.album ?: return
viewModelScope.launch {
runCatching {
offlineRepo.enqueueGroup(
type = GroupType.ALBUM,
sourceId = album.id,
name = album.name,
coverArt = album.coverArt,
songs = album.song,
)
}.onFailure { android.util.Log.e("AlbumViewModel", "enqueueGroup failed", it) }
}
}
} }
@@ -0,0 +1,169 @@
package com.novasonic.app.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.ImporterClient
import com.novasonic.app.api.ReleasesClient
import com.novasonic.app.api.model.ArtistRef
import com.novasonic.app.api.model.ArtistKonzert
import com.novasonic.app.api.model.ArtistRelease
import com.novasonic.app.api.model.DownloadRequest
import com.novasonic.app.app
import com.novasonic.app.data.NotificationStore
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
/** Welcher Reiter gezeigt wird. Getrennte Listen, weil die Zeit in verschiedene Richtungen läuft. */
enum class NewsReiter { RELEASES, KONZERTE }
data class ArtistNewsUiState(
val reiter: NewsReiter = NewsReiter.RELEASES,
val releases: List<ArtistRelease> = emptyList(),
val konzerte: List<ArtistKonzert> = emptyList(),
val keinSchluessel: Boolean = false,
/** Schlüssel (Künstler + Album, normalisiert) alles dessen, was schon in der Bibliothek liegt. */
val vorhanden: Set<String> = emptySet(),
val ohneZuordnung: List<String> = emptyList(),
val tage: Int = 90,
val isLoading: Boolean = true,
val keineGefolgten: Boolean = false,
val keinBackend: Boolean = false,
val error: String? = null,
)
/**
* "Neu von deinen Künstlern". Gefolgt = Navidromes Stern, die Künstlerliste kommt also aus
* getStarred2. Die Deezer-Auflösung macht das Backend — dort liegen die Pins und der gemeinsame
* Cache, sonst würde jedes Gerät bei jedem Öffnen dieselben Abfragen wiederholen.
*/
class ArtistNewsViewModel(app: Application) : AndroidViewModel(app) {
private val repo = app.app.repository
private val _state = MutableStateFlow(ArtistNewsUiState())
val state: StateFlow<ArtistNewsUiState> = _state
init { laden(90) }
/** Reiter wechseln und, falls noch nichts geladen ist, nachladen. */
fun zeigeReiter(r: NewsReiter) {
_state.value = _state.value.copy(reiter = r)
if (r == NewsReiter.KONZERTE && _state.value.konzerte.isEmpty()) ladeKonzerte()
}
/** Zeitfenster setzen — gibt es nur bei den Veroeffentlichungen. */
fun setzeTage(tage: Int) = laden(tage)
// Kein Zeitfenster: Ticketmaster liefert ohnehin nur Anstehendes, und dort will man alles
// Angekuendigte sehen — eine Tagesgrenze schnitte nur willkuerlich ab.
fun ladeKonzerte() = viewModelScope.launch {
_state.value = _state.value.copy(isLoading = true, error = null,
keineGefolgten = false, keinBackend = false, keinSchluessel = false)
try {
val backendUrl = runCatching { repo.getBackendUrl() }.getOrDefault("")
if (backendUrl.isBlank()) {
_state.value = _state.value.copy(isLoading = false, keinBackend = true)
return@launch
}
val kuenstler = repo.getStarred().artist.map { ArtistRef(it.id, it.name) }
if (kuenstler.isEmpty()) {
_state.value = _state.value.copy(isLoading = false, keineGefolgten = true)
return@launch
}
val antwort = ReleasesClient.konzerte(backendUrl, kuenstler)
_state.value = _state.value.copy(
konzerte = antwort.konzerte,
keinSchluessel = antwort.keinSchluessel,
isLoading = false,
)
} catch (e: Exception) {
_state.value = _state.value.copy(isLoading = false, error = e.message)
}
}
fun laden(tage: Int = _state.value.tage) = viewModelScope.launch {
_state.value = _state.value.copy(isLoading = true, tage = tage, error = null,
reiter = NewsReiter.RELEASES, keineGefolgten = false, keinBackend = false)
try {
val backendUrl = runCatching { repo.getBackendUrl() }.getOrDefault("")
if (backendUrl.isBlank()) {
_state.value = _state.value.copy(isLoading = false, keinBackend = true)
return@launch
}
val markiert = repo.getStarred()
val kuenstler = markiert.artist.map { ArtistRef(it.id, it.name) }
if (kuenstler.isEmpty()) {
_state.value = _state.value.copy(isLoading = false, keineGefolgten = true)
return@launch
}
val antwort = ReleasesClient.fetch(backendUrl, kuenstler, tage)
// Was liegt schon in der Bibliothek? Verglichen wird über Künstler + Albumname —
// Deezers Album-Id hat mit Navidromes nichts zu tun.
val vorhanden = withContext(Dispatchers.IO) {
val ausFavoriten = markiert.album.map { schluessel(it.artist ?: "", it.name) }
val ausBibliothek = kuenstler.chunked(6).flatMap { haeppchen ->
haeppchen.map { k ->
async {
runCatching { repo.getArtist(k.id).album.map { schluessel(k.name, it.name) } }
.getOrDefault(emptyList())
}
}.awaitAll().flatten()
}
(ausFavoriten + ausBibliothek).toSet()
}
_state.value = _state.value.copy(
releases = antwort.releases,
ohneZuordnung = antwort.ohneZuordnung,
vorhanden = vorhanden,
isLoading = false,
)
} catch (e: Exception) {
_state.value = _state.value.copy(isLoading = false, error = e.message)
}
}
fun hatSchon(rel: ArtistRelease): Boolean =
schluessel(rel.artistName, rel.title) in _state.value.vorhanden
fun herunterladen(rel: ArtistRelease, onDone: (Boolean, String) -> Unit) {
viewModelScope.launch {
val backendUrl = runCatching { repo.getBackendUrl() }.getOrDefault("")
if (backendUrl.isBlank()) { onDone(false, "Kein Backend konfiguriert"); return@launch }
val request = DownloadRequest(
jobId = "job_${System.currentTimeMillis()}",
type = "album",
title = rel.title,
artist = rel.artistName,
artworkUrl = rel.cover.takeIf { it.isNotBlank() },
collectionId = rel.albumId.toLongOrNull(),
itunesId = rel.albumId.toLongOrNull(),
)
val client = ImporterClient(backendUrl)
runCatching { client.download(request) }
.onSuccess {
NotificationStore.startPoll(
backendUrl, request.jobId, request.title, request.artist ?: "",
navType = "album", navAlbum = rel.title, navArtist = rel.artistName,
)
onDone(true, "✓ Download gestartet")
}
.onFailure { onDone(false, "Backend nicht erreichbar: ${it.message}") }
client.close()
}
}
private companion object {
fun norm(s: String) = s.lowercase()
.replace(Regex("[^a-z0-9]"), "")
fun schluessel(kuenstler: String, album: String) = "${norm(kuenstler)}~~${norm(album)}"
}
}
@@ -1,18 +1,21 @@
package com.novasonic.app.viewmodel package com.novasonic.app.viewmodel
import android.app.Application import android.app.Application
import android.media.MediaPlayer
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.EventsClient
import com.novasonic.app.api.ImporterClient import com.novasonic.app.api.ImporterClient
import com.novasonic.app.api.ItunesClient import com.novasonic.app.api.ItunesClient
import com.novasonic.app.api.model.Artist import com.novasonic.app.api.model.Artist
import com.novasonic.app.api.model.ArtistOverride
import com.novasonic.app.api.model.ConcertEvent
import com.novasonic.app.api.model.ArtistInfo import com.novasonic.app.api.model.ArtistInfo
import com.novasonic.app.api.model.DownloadRequest import com.novasonic.app.api.model.DownloadRequest
import com.novasonic.app.api.model.ItunesItem import com.novasonic.app.api.model.ItunesItem
import com.novasonic.app.api.model.Song import com.novasonic.app.api.model.Song
import com.novasonic.app.app import com.novasonic.app.app
import com.novasonic.app.data.NotificationStore
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@@ -27,26 +30,57 @@ data class ArtistUiState(
val iAlbums: List<ItunesItem> = emptyList(), val iAlbums: List<ItunesItem> = emptyList(),
val iTracks: List<ItunesItem> = emptyList(), val iTracks: List<ItunesItem> = emptyList(),
val itunesLoading: Boolean = false, val itunesLoading: Boolean = false,
// Shuffle all
val isShuffling: Boolean = false,
val pendingShufflePlay: List<Song>? = null,
// Sub-album detail (tapped not-downloaded album) // Sub-album detail (tapped not-downloaded album)
val subAlbumItem: ItunesItem? = null, val subAlbumItem: ItunesItem? = null,
val subAlbumTracks: List<ItunesItem>? = null, val subAlbumTracks: List<ItunesItem>? = null,
val subAlbumTitle: String = "", val subAlbumTitle: String = "",
// Partial album detail (tapped incomplete album — shows downloaded + missing tracks) // Partial album detail (tapped incomplete album — shows downloaded + missing tracks)
val partialAlbum: PartialAlbumState? = null, val partialAlbum: PartialAlbumState? = null,
// Concerts
val events: List<ConcertEvent> = emptyList(),
val eventsError: String? = null, // non-null → the fetch failed (vs. genuinely no concerts)
val showEventsSheet: Boolean = false,
// Deezer fan count of the matched artist (shown under the name), null if unknown
val fanCount: Long? = null,
// Preview + download // Preview + download
val previewingId: Long? = null, val previewingId: Long? = null,
val downloadSheetItem: ItunesItem? = null, val downloadSheetItem: ItunesItem? = null,
// Artist pin (same-name disambiguation): the active pin, the image it overrides the hero with,
// and the picker state (link/id paste + Deezer search candidates).
val pin: ArtistOverride? = null,
val pinnedImage: String? = null,
// When pinned, the Similar-Artists row uses Deezer "related" (correct for the pinned artist)
// instead of Last.fm's list (keyed to the wrong/merged Navidrome artist).
val pinnedRelated: List<ItunesItem> = emptyList(),
val showPinPicker: Boolean = false,
val pinSearching: Boolean = false,
val pinCandidates: List<ItunesItem> = emptyList(),
) )
class ArtistViewModel(app: Application, savedState: SavedStateHandle) : AndroidViewModel(app) { class ArtistViewModel(app: Application, savedState: SavedStateHandle) : AndroidViewModel(app) {
private val repo = app.app.repository private val repo = app.app.repository
/** Folgen = Navidromes Stern auf dem Kuenstler. Laeuft ueber StarState, damit der Zustand
* sofort umspringt und bei einem Fehlschlag von selbst zurueckfaellt. */
fun folgenUmschalten(artistId: String, aktuellMarkiert: Boolean) =
com.novasonic.app.data.StarState.toggle(repo, viewModelScope, artistId, aktuellMarkiert)
private val player = app.app.playerController
private val preview = app.app.previewController
private val artistId: String? = savedState["artistId"] private val artistId: String? = savedState["artistId"]
private val _state = MutableStateFlow(ArtistUiState()) private val _state = MutableStateFlow(ArtistUiState())
val state: StateFlow<ArtistUiState> = _state val state: StateFlow<ArtistUiState> = _state
private var mediaPlayer: MediaPlayer? = null // Scroll of the artist page + the "alle anzeigen" overlay, hoisted so tapping an album/artist and
// coming back returns you to the same spot (the artist route entry, hence this VM, is retained).
val pageListState = androidx.compose.foundation.lazy.LazyListState()
val allAlbumsGrid = androidx.compose.foundation.lazy.grid.LazyGridState()
val allAlbumsQuery = androidx.compose.runtime.mutableStateOf("")
init { init {
if (artistId.isNullOrBlank()) { if (artistId.isNullOrBlank()) {
@@ -54,6 +88,12 @@ class ArtistViewModel(app: Application, savedState: SavedStateHandle) : AndroidV
} else { } else {
load() load()
} }
// Mirror the app-level preview so track rows show which clip plays (bar lives in AppNavigation).
viewModelScope.launch {
preview.state.collect { ps ->
_state.value = _state.value.copy(previewingId = if (ps.isPlaying) ps.trackId else null)
}
}
} }
fun load() { fun load() {
@@ -67,34 +107,81 @@ class ArtistViewModel(app: Application, savedState: SavedStateHandle) : AndroidV
val artist = artistDef.await() val artist = artistDef.await()
val info = infoDef.await() val info = infoDef.await()
val topDef = async { runCatching { repo.getTopSongs(artist.name) }.getOrDefault(emptyList()) } val topDef = async { runCatching { repo.getTopSongs(artist.name, artist.id) }.getOrDefault(emptyList()) }
val top = topDef.await() // A manual pin (shared, server-side) fixes same-name collisions — resolve it up front
// so the Deezer enrichment below uses the pinned artist, not a name-guess.
val pinDef = async { runCatching { repo.getArtistOverride(artist.id) }.getOrNull() }
// Navidrome can hold the same track twice (single + album track) → duplicate top-song
// rows ("PIXELATED KISSES" x2). Collapse by title+album (keeps the highest play count).
val top = topDef.await().distinctBy { "${it.title}|${it.album}".lowercase() }
val pin = pinDef.await()
_state.value = ArtistUiState( _state.value = ArtistUiState(
artist = artist, info = info, topSongs = top, artist = artist, info = info, topSongs = top,
isLoading = false, itunesLoading = true, isLoading = false, itunesLoading = true,
pin = pin, pinnedImage = pin?.image?.takeIf { it.isNotBlank() },
) )
// Fetch iTunes data without blocking the main screen // Fetch iTunes + events in parallel without blocking the main screen
launch { loadItunesData(artist.name) } launch { loadItunesData(artist.name, pin) }
launch {
val backendUrl = repo.getBackendUrl()
runCatching { EventsClient.fetchEvents(backendUrl, artist.name) }
.onSuccess { _state.value = _state.value.copy(events = it, eventsError = null) }
.onFailure { e ->
android.util.Log.w("NovaSonic", "Konzert-Fetch fehlgeschlagen für ${artist.name}", e)
_state.value = _state.value.copy(events = emptyList(), eventsError = e.message ?: e.toString())
}
}
} catch (e: Exception) { } catch (e: Exception) {
_state.value = ArtistUiState(isLoading = false, itunesLoading = false, error = e.message ?: e.toString()) _state.value = ArtistUiState(isLoading = false, itunesLoading = false, error = e.message ?: e.toString())
} }
} }
} }
private suspend fun loadItunesData(artistName: String) { private suspend fun loadItunesData(artistName: String, pin: ArtistOverride? = null) {
// Pinned: skip the name-guess entirely and enrich straight from the pinned Deezer artist id.
val pinnedId = pin?.deezerArtistId?.toLongOrNull()
if (pinnedId != null) {
_state.value = _state.value.copy(
fanCount = pin.fanCount ?: _state.value.fanCount,
pinnedImage = pin.image.takeIf { it.isNotBlank() } ?: _state.value.pinnedImage,
)
coroutineScope {
val iAlbumsD = async { runCatching { ItunesClient.lookupArtistAlbums(pinnedId) }.getOrDefault(emptyList()) }
val iTracksD = async { runCatching { ItunesClient.lookupArtistTopTracks(pinnedId, 10) }.getOrDefault(emptyList()) }
val relatedD = async { runCatching { ItunesClient.lookupRelatedArtists(pinnedId, 12) }.getOrDefault(emptyList()) }
_state.value = _state.value.copy(
iAlbums = iAlbumsD.await(), iTracks = iTracksD.await(),
pinnedRelated = relatedD.await(), itunesLoading = false,
)
}
enrichPartialCounts()
return
}
// Not pinned → clear any stale pinned-related from a previous pin.
_state.value = _state.value.copy(pinnedRelated = emptyList())
val searchResp = runCatching { val searchResp = runCatching {
ItunesClient.search(artistName, entity = "musicArtist", limit = 5) ItunesClient.search(artistName, entity = "musicArtist", limit = 5)
}.getOrNull() }.getOrNull()
val iArtistId = searchResp?.results val artists = searchResp?.results?.filter { it.wrapperType == "artist" } ?: emptyList()
?.filter { it.wrapperType == "artist" } // artists are fan-sorted (ItunesClient), so firstOrNull gives the most popular match.
?.find { // Prefer an EXACT normalized-name match: "Flay!" must not resolve to the far more popular
it.artistName?.equals(artistName, ignoreCase = true) == true || // "K.FLAY" (its name merely contains "flay"). Only fall back to a loose contains-match.
it.artistName?.contains(artistName, ignoreCase = true) == true fun norm(s: String?) = (s ?: "").lowercase().replace(Regex("[^\\p{L}\\p{N}]"), "")
val q = norm(artistName)
val iArtist = (
artists.firstOrNull { norm(it.artistName) == q }
?: artists.firstOrNull {
val n = it.artistName ?: return@firstOrNull false
n.contains(artistName, ignoreCase = true) || artistName.contains(n, ignoreCase = true)
} }
?.artistId ?: artists.firstOrNull()
)
val iArtistId = iArtist?.artistId
if (iArtist?.fanCount != null) _state.value = _state.value.copy(fanCount = iArtist.fanCount)
if (iArtistId != null) { if (iArtistId != null) {
coroutineScope { coroutineScope {
@@ -106,11 +193,41 @@ class ArtistViewModel(app: Application, savedState: SavedStateHandle) : AndroidV
itunesLoading = false, itunesLoading = false,
) )
} }
enrichPartialCounts()
} else { } else {
_state.value = _state.value.copy(itunesLoading = false) _state.value = _state.value.copy(itunesLoading = false)
} }
} }
/**
* Deezer's /artist/{id}/albums omits nb_tracks, so an owned album's real total is unknown and it
* never got flagged "Unvollständig" (iCount stayed 0). Mirror the web: for MATCHED (owned) albums
* whose Deezer trackCount is unknown, fetch the album's track list once to learn the real total,
* then update state so categorizeAlbums can detect partials. Only matched albums are enriched —
* a couple of calls, not the whole discography.
*/
private suspend fun enrichPartialCounts() {
val ndAlbums = _state.value.artist?.album ?: return
val iAlbums = _state.value.iAlbums
if (ndAlbums.isEmpty() || iAlbums.isEmpty()) return
fun norm(s: String?) = (s ?: "").lowercase().replace(Regex("[^\\p{L}\\p{N}]"), "")
val enriched = coroutineScope {
iAlbums.map { ia ->
val cid = ia.collectionId
val known = (ia.trackCount ?: 0) > 0
val matched = ndAlbums.any { a ->
val n = norm(a.name); val i = norm(ia.collectionName)
n == i || (n.length > 3 && i.startsWith(n)) || (i.length > 3 && n.startsWith(i))
}
if (!known && matched && cid != null) async {
val n = runCatching { ItunesClient.lookupAlbum(cid).size }.getOrDefault(0)
if (n > 0) ia.copy(trackCount = n) else ia
} else async { ia }
}.map { it.await() }
}
_state.value = _state.value.copy(iAlbums = enriched)
}
// ── Sub-album (not-downloaded iTunes album) ────────────────────────────── // ── Sub-album (not-downloaded iTunes album) ──────────────────────────────
fun loadSubAlbum(album: ItunesItem) { fun loadSubAlbum(album: ItunesItem) {
@@ -163,6 +280,28 @@ class ArtistViewModel(app: Application, savedState: SavedStateHandle) : AndroidV
// ── Download sheet ─────────────────────────────────────────────────────── // ── Download sheet ───────────────────────────────────────────────────────
fun shuffleAll() {
val artist = _state.value.artist ?: return
if (_state.value.isShuffling) return
viewModelScope.launch {
_state.value = _state.value.copy(isShuffling = true)
val allSongs = artist.album.flatMap { album ->
runCatching { repo.getAlbum(album.id).song }.getOrDefault(emptyList())
}
_state.value = _state.value.copy(
isShuffling = false,
pendingShufflePlay = allSongs.ifEmpty { null }, // gemischt wird im Player
)
}
}
fun consumeShufflePlay() {
_state.value = _state.value.copy(pendingShufflePlay = null)
}
fun openEventsSheet() { _state.value = _state.value.copy(showEventsSheet = true) }
fun dismissEventsSheet() { _state.value = _state.value.copy(showEventsSheet = false) }
fun showDownloadSheet(item: ItunesItem) { fun showDownloadSheet(item: ItunesItem) {
_state.value = _state.value.copy(downloadSheetItem = item) _state.value = _state.value.copy(downloadSheetItem = item)
} }
@@ -201,46 +340,111 @@ class ArtistViewModel(app: Application, savedState: SavedStateHandle) : AndroidV
} }
val client = ImporterClient(backendUrl) val client = ImporterClient(backendUrl)
runCatching { client.download(request) } runCatching { client.download(request) }
.onSuccess { onDone(true, "✓ Download gestartet") } .onSuccess {
NotificationStore.startPoll(backendUrl, request.jobId, request.title, request.artist ?: "")
onDone(true, "✓ Download gestartet")
}
.onFailure { onDone(false, "Backend nicht erreichbar: ${it.message}") } .onFailure { onDone(false, "Backend nicht erreichbar: ${it.message}") }
client.close() client.close()
} }
} }
// ── iTunes 30s preview ─────────────────────────────────────────────────── // ── 30s preview (app-level PreviewController → global control bar, survives navigation) ──
fun togglePreview(track: ItunesItem) { fun togglePreview(track: ItunesItem) {
val url = track.previewUrl ?: return val url = track.previewUrl ?: return
val id = track.trackId ?: return val id = track.trackId ?: return
if (_state.value.previewingId == id) stopPreview() else startPreview(url, id) player.pause()
preview.toggle(id, url, track.trackName ?: "", track.artistName ?: "", track.artworkUrl100)
} }
private fun startPreview(url: String, id: Long) { fun stopPreview() = preview.stop()
stopPreview()
_state.value = _state.value.copy(previewingId = id) // ── Artist pin (same-name disambiguation) ────────────────────────────────
viewModelScope.launch(Dispatchers.IO) {
try { fun openPinPicker() {
val mp = MediaPlayer().apply { _state.value = _state.value.copy(showPinPicker = true, pinCandidates = emptyList(), pinSearching = true)
setDataSource(url) val name = _state.value.artist?.name ?: return
prepare() viewModelScope.launch {
start() val res = runCatching { ItunesClient.search(name, entity = "musicArtist", limit = 8) }.getOrNull()
setOnCompletionListener { _state.value = _state.value.copy(previewingId = null) } val cands = res?.results?.filter { it.wrapperType == "artist" } ?: emptyList()
} _state.value = _state.value.copy(pinCandidates = cands, pinSearching = false)
mediaPlayer = mp
} catch (e: Exception) {
_state.value = _state.value.copy(previewingId = null)
}
} }
} }
fun stopPreview() { fun dismissPinPicker() { _state.value = _state.value.copy(showPinPicker = false) }
mediaPlayer?.runCatching { stop(); release() }
mediaPlayer = null /** Pin one of the searched candidates. */
_state.value = _state.value.copy(previewingId = null) fun pinCandidate(item: ItunesItem) {
val dzId = item.artistId ?: return
applyPin(ArtistOverride(
deezerArtistId = dzId.toString(),
name = item.artistName ?: _state.value.artist?.name ?: "",
image = item.artworkUrl100 ?: "",
fanCount = item.fanCount,
))
} }
override fun onCleared() { /** Pin by a pasted Deezer link or bare id (the reliable route when search can't surface it). */
super.onCleared() fun pinByLink(raw: String, onResult: (Boolean) -> Unit) {
stopPreview() val id = parseDeezerArtistId(raw)?.toLongOrNull()
if (id == null) { onResult(false); return }
viewModelScope.launch {
val a = runCatching { ItunesClient.lookupArtist(id) }.getOrNull()
if (a?.artistId == null) { onResult(false); return@launch }
applyPin(ArtistOverride(
deezerArtistId = a.artistId.toString(),
name = a.artistName ?: _state.value.artist?.name ?: "",
image = a.artworkUrl100 ?: "",
fanCount = a.fanCount,
))
onResult(true)
} }
}
/**
* Resolve a (Deezer-related) artist name to a Navidrome library artist id, so a pinned artist's
* "Similar" chips are tappable when that artist is actually in the library. Exact name match only
* (case-insensitive) to avoid navigating to the wrong artist; null if not in the library.
*/
suspend fun libraryArtistId(name: String?): String? {
val n = name?.trim()?.lowercase() ?: return null
if (n.isEmpty()) return null
val res = runCatching { repo.search(n) }.getOrNull() ?: return null
return res.artist.firstOrNull { it.name.trim().lowercase() == n }?.id
}
fun clearPin() {
val id = artistId ?: return
viewModelScope.launch {
runCatching { repo.removeArtistOverride(id) }
_state.value = _state.value.copy(pin = null, pinnedImage = null, showPinPicker = false, itunesLoading = true)
loadItunesData(_state.value.artist?.name ?: "", null)
}
}
private fun applyPin(ov: ArtistOverride) {
val id = artistId ?: return
viewModelScope.launch {
runCatching { repo.setArtistOverride(id, ov) }
_state.value = _state.value.copy(
pin = ov,
pinnedImage = ov.image.takeIf { it.isNotBlank() },
showPinPicker = false,
itunesLoading = true,
)
loadItunesData(_state.value.artist?.name ?: "", ov)
}
}
// Pull a Deezer artist id out of a pasted URL (deezer.com/.../artist/12345) or a bare id.
private fun parseDeezerArtistId(raw: String): String? {
val s = raw.trim()
if (s.isEmpty()) return null
Regex("artist/(\\d+)").find(s)?.let { return it.groupValues[1] }
return if (s.matches(Regex("\\d+"))) s else null
}
// No onCleared stopPreview — the preview is app-level so it keeps playing (controllable via the
// global bar) after leaving this screen.
} }
@@ -0,0 +1,68 @@
package com.novasonic.app.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.model.CompareResult
import com.novasonic.app.api.model.ScrobbleUser
import com.novasonic.app.app
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
data class CompareUiState(
val loading: Boolean = true,
val configured: Boolean = true,
val error: String? = null,
val me: String = "",
val users: List<ScrobbleUser> = emptyList(), // candidates (excludes me)
val partner: String? = null, // chosen userB; null → show picker
val result: CompareResult? = null,
)
/** Head-to-Head "Musik-Match": pick a partner from the play-log, then compare. */
class CompareViewModel(app: Application) : AndroidViewModel(app) {
private val repo = app.app.repository
private val _state = MutableStateFlow(CompareUiState())
val state: StateFlow<CompareUiState> = _state
init { loadUsers() }
fun loadUsers() {
viewModelScope.launch {
_state.value = CompareUiState(loading = true)
val settings = repo.appSettingsFlow().first()
if (settings.scrobbleUrl.isBlank()) {
_state.value = _state.value.copy(loading = false, configured = false)
return@launch
}
val resp = repo.fetchScrobbleUsers()
_state.value = if (resp == null)
_state.value.copy(loading = false, error = "Scrobble-Dienst nicht erreichbar")
else
_state.value.copy(
loading = false, configured = true, error = null,
me = resp.me,
users = resp.users.filter { it.user != resp.me },
)
}
}
/** Back to the partner picker. */
fun clearPartner() {
_state.value = _state.value.copy(partner = null, result = null, error = null)
}
fun choosePartner(name: String) {
_state.value = _state.value.copy(partner = name, loading = true, error = null, result = null)
viewModelScope.launch {
val res = repo.fetchScrobbleCompare(name)
_state.value = if (res == null)
_state.value.copy(loading = false, error = "Scrobble-Dienst nicht erreichbar")
else
_state.value.copy(loading = false, result = res, error = null)
}
}
}
@@ -1,7 +1,6 @@
package com.novasonic.app.viewmodel package com.novasonic.app.viewmodel
import android.app.Application import android.app.Application
import android.media.MediaPlayer
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.ImporterClient import com.novasonic.app.api.ImporterClient
@@ -11,8 +10,10 @@ import com.novasonic.app.api.model.DownloadRequest
import com.novasonic.app.api.model.ItunesItem import com.novasonic.app.api.model.ItunesItem
import com.novasonic.app.api.model.ItunesRssEntry import com.novasonic.app.api.model.ItunesRssEntry
import com.novasonic.app.api.model.Song import com.novasonic.app.api.model.Song
import androidx.compose.foundation.lazy.LazyListState
import com.novasonic.app.api.model.artworkHd import com.novasonic.app.api.model.artworkHd
import com.novasonic.app.app import com.novasonic.app.app
import com.novasonic.app.data.NotificationStore
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@@ -50,6 +51,9 @@ data class ExploreUiState(
val albumItem: ItunesItem? = null, val albumItem: ItunesItem? = null,
// Artist detail (iTunes) // Artist detail (iTunes)
val artistDetail: ItunesArtistState? = null, val artistDetail: ItunesArtistState? = null,
// Which "all albums" section is expanded inside the iTunes artist overlay (by title), or null.
// Hoisted here so it survives drilling into an album (nav route OR overlay) and coming back.
val artistAllAlbums: String? = null,
// Partial album detail (opened from artist's "Unvollständig" section) // Partial album detail (opened from artist's "Unvollständig" section)
val partialAlbum: PartialAlbumState? = null, val partialAlbum: PartialAlbumState? = null,
// Download sheet // Download sheet
@@ -67,14 +71,30 @@ data class ExploreUiState(
class ExploreViewModel(app: Application) : AndroidViewModel(app) { class ExploreViewModel(app: Application) : AndroidViewModel(app) {
private val repo = app.app.repository private val repo = app.app.repository
private val player = app.app.playerController
private val preview = app.app.previewController
private val _state = MutableStateFlow(ExploreUiState(chartsLoading = true)) private val _state = MutableStateFlow(ExploreUiState(chartsLoading = true))
val state: StateFlow<ExploreUiState> = _state val state: StateFlow<ExploreUiState> = _state
private var searchJob: Job? = null // Global-search results scroll — hoisted so it survives an album/artist drill-in and back.
private var mediaPlayer: MediaPlayer? = null val searchListState = LazyListState()
// "Alle anzeigen" overlay (Deezer artist albums): scroll + search query, hoisted so an album
// drill-in and back keeps both (the overlay itself leaves composition on drill-in).
val allAlbumsGrid = androidx.compose.foundation.lazy.grid.LazyGridState()
val allAlbumsQuery = androidx.compose.runtime.mutableStateOf("")
init { loadCharts() } private var searchJob: Job? = null
init {
loadCharts()
// Mirror the app-level preview state so the track rows still show which clip is playing.
viewModelScope.launch {
preview.state.collect { ps ->
_state.value = _state.value.copy(previewingId = if (ps.isPlaying) ps.trackId else null)
}
}
}
fun selectTab(tab: ExploreTab) { fun selectTab(tab: ExploreTab) {
_state.value = _state.value.copy(tab = tab, albumTracks = null) _state.value = _state.value.copy(tab = tab, albumTracks = null)
@@ -94,23 +114,54 @@ class ExploreViewModel(app: Application) : AndroidViewModel(app) {
} }
private fun search(q: String) { private fun search(q: String) {
// Strip leading aesthetic punctuation (".diedlonely", "†…") so iTunes actually surfaces the
// artist instead of nothing. Falls back to the raw query if it was only symbols.
val term = q.trimStart { !it.isLetterOrDigit() }.trim().ifBlank { q }
viewModelScope.launch { viewModelScope.launch {
_state.value = _state.value.copy(isSearching = true, error = null) _state.value = _state.value.copy(isSearching = true, error = null)
try { try {
val resp = ItunesClient.search(q) val resp = ItunesClient.search(term)
val results = resp.results val results = resp.results
val artists = results.filter { it.wrapperType == "artist" }
_state.value = _state.value.copy( _state.value = _state.value.copy(
artists = results.filter { it.wrapperType == "artist" }, artists = artists,
albums = results.filter { it.wrapperType == "collection" }, albums = results.filter { it.wrapperType == "collection" },
tracks = results.filter { it.wrapperType == "track" && it.kind == "song" }, tracks = results.filter { it.wrapperType == "track" && it.kind == "song" },
isSearching = false, isSearching = false,
) )
enrichArtistArt(artists)
} catch (e: Exception) { } catch (e: Exception) {
_state.value = _state.value.copy(isSearching = false, error = e.message) _state.value = _state.value.copy(isSearching = false, error = e.message)
} }
} }
} }
/**
* iTunes artist entities carry no artwork, so search results render as grey circles. Mirror the
* web PWA: fetch one album per artist and borrow its cover. Runs after the main results are shown
* (list appears instantly) and only applies if the user is still viewing the same artist set.
*/
private fun enrichArtistArt(artists: List<ItunesItem>) {
if (artists.none { it.artworkUrl100.isNullOrBlank() && it.artistName != null }) return
viewModelScope.launch {
val enriched = artists.map { a ->
async {
if (!a.artworkUrl100.isNullOrBlank()) return@async a
val name = a.artistName ?: return@async a
val art = runCatching {
ItunesClient.search(name, entity = "album", limit = 1).results
.firstOrNull { it.wrapperType == "collection" }?.artworkUrl100
}.getOrNull()
if (art != null) a.copy(artworkUrl100 = art) else a
}
}.awaitAll()
val cur = _state.value.artists
if (cur.map { it.artistId } == artists.map { it.artistId }) {
_state.value = _state.value.copy(artists = enriched)
}
}
}
fun loadAlbum(album: ItunesItem) { fun loadAlbum(album: ItunesItem) {
val id = album.collectionId ?: return val id = album.collectionId ?: return
viewModelScope.launch { viewModelScope.launch {
@@ -129,34 +180,92 @@ class ExploreViewModel(app: Application) : AndroidViewModel(app) {
_state.value = _state.value.copy(albumTracks = null, albumItem = null) _state.value = _state.value.copy(albumTracks = null, albumItem = null)
} }
/** Vom geöffneten Album zu dessen Künstler springen. Deezer legt das artist-Objekt samt id
* jedem Albumtreffer bei, der Sprung kostet also keinen zusätzlichen Suchaufruf. Die
* Albumansicht wird geschlossen, sonst läge sie weiter über der Künstlerseite. */
fun openArtistOfAlbum(album: ItunesItem) {
val id = album.artistId ?: return
val name = album.artistName ?: return
_state.value = _state.value.copy(albumTracks = null, albumItem = null, partialAlbum = null)
openArtistDetail(ItunesItem(wrapperType = "artist", artistId = id, artistName = name))
}
fun openArtistAllAlbums(title: String) { _state.value = _state.value.copy(artistAllAlbums = title) }
fun closeArtistAllAlbums() { _state.value = _state.value.copy(artistAllAlbums = null) }
fun openArtistDetail(artist: ItunesItem) { fun openArtistDetail(artist: ItunesItem) {
_state.value = _state.value.copy( _state.value = _state.value.copy(
artistDetail = ItunesArtistState(artist = artist, isLoading = true), artistDetail = ItunesArtistState(artist = artist, isLoading = true),
artistAllAlbums = null,
) )
viewModelScope.launch { viewModelScope.launch {
val artistId = artist.artistId val artistId = artist.artistId
val artistName = artist.artistName ?: return@launch val artistName = artist.artistName ?: return@launch
val ndAlbumsD: Deferred<List<Album>> = async { runCatching { repo.getNdAlbumsForArtist(artistName) }.getOrDefault(emptyList()) } val ndAlbumsD: Deferred<List<Album>> = async { runCatching { repo.getNdAlbumsForArtist(artistName) }.getOrDefault(emptyList()) }
// Bewusst ohne id: artistId ist hier DEEZERS Kuenstler-ID, nicht Navidromes. Sie hier
// mitzugeben wuerde Navidrome eine fremde ID unterschieben.
val topSongsD: Deferred<List<Song>> = async { runCatching { repo.getTopSongs(artistName) }.getOrDefault(emptyList()) } val topSongsD: Deferred<List<Song>> = async { runCatching { repo.getTopSongs(artistName) }.getOrDefault(emptyList()) }
val iAlbumsD: Deferred<List<ItunesItem>> = async { if (artistId != null) runCatching { ItunesClient.lookupArtistAlbums(artistId) }.getOrDefault(emptyList()) else emptyList() } val iAlbumsD: Deferred<List<ItunesItem>> = async { if (artistId != null) runCatching { ItunesClient.lookupArtistAlbums(artistId) }.getOrDefault(emptyList()) else emptyList() }
val iTracksD: Deferred<List<ItunesItem>> = async { if (artistId != null) runCatching { ItunesClient.lookupArtistTopTracks(artistId, 10) }.getOrDefault(emptyList()) else emptyList() } val iTracksD: Deferred<List<ItunesItem>> = async { if (artistId != null) runCatching { ItunesClient.lookupArtistTopTracks(artistId, 10) }.getOrDefault(emptyList()) else emptyList() }
val ndAlbums = ndAlbumsD.await()
val iAlbums = iAlbumsD.await()
// Aus einem Album konstruierte Künstler tragen weder Bild noch Fanzahl — einmal
// nachschlagen, damit die Kopfzeile genauso aussieht wie aus der Künstlersuche.
val voll = if (artistId != null && artist.artworkUrl100 == null && artist.fanCount == null)
runCatching { ItunesClient.lookupArtist(artistId) }.getOrNull() ?: artist
else artist
_state.value = _state.value.copy( _state.value = _state.value.copy(
artistDetail = ItunesArtistState( artistDetail = ItunesArtistState(
artist = artist, artist = voll,
isLoading = false, isLoading = false,
ndAlbums = ndAlbumsD.await(), ndAlbums = ndAlbums,
iAlbums = iAlbumsD.await(), iAlbums = iAlbums,
iTracks = iTracksD.await(), iTracks = iTracksD.await(),
topSongs = topSongsD.await(), topSongs = topSongsD.await(),
), ),
) )
// Deezer's artist-albums list omits nb_tracks, so owned albums never show "Unvollständig".
// Resolve the real total for matched albums (like web) so partials are detected.
val enriched = enrichPartialCounts(ndAlbums, iAlbums)
if (enriched !== iAlbums) {
_state.value.artistDetail?.let { d ->
if (d.artist.artistId == artist.artistId) {
_state.value = _state.value.copy(artistDetail = d.copy(iAlbums = enriched))
}
}
}
} }
} }
/** For MATCHED (owned) albums whose Deezer trackCount is unknown, fetch the album's track list
* once to learn the real total. Only owned albums are enriched (a couple of calls). */
private suspend fun enrichPartialCounts(
ndAlbums: List<Album>, iAlbums: List<ItunesItem>,
): List<ItunesItem> {
if (ndAlbums.isEmpty() || iAlbums.isEmpty()) return iAlbums
fun norm(s: String?) = (s ?: "").lowercase().replace(Regex("[^\\p{L}\\p{N}]"), "")
var changed = false
val out = coroutineScope {
iAlbums.map { ia ->
val cid = ia.collectionId
val known = (ia.trackCount ?: 0) > 0
val matched = ndAlbums.any { a ->
val n = norm(a.name); val i = norm(ia.collectionName)
n == i || (n.length > 3 && i.startsWith(n)) || (i.length > 3 && n.startsWith(i))
}
if (!known && matched && cid != null) async {
val n = runCatching { ItunesClient.lookupAlbum(cid).size }.getOrDefault(0)
if (n > 0) { changed = true; ia.copy(trackCount = n) } else ia
} else async { ia }
}.map { it.await() }
}
return if (changed) out else iAlbums
}
fun closeArtistDetail() { fun closeArtistDetail() {
_state.value = _state.value.copy(artistDetail = null, partialAlbum = null) _state.value = _state.value.copy(artistDetail = null, partialAlbum = null, artistAllAlbums = null)
} }
fun loadPartialAlbum(nd: Album, ia: ItunesItem) { fun loadPartialAlbum(nd: Album, ia: ItunesItem) {
@@ -232,7 +341,15 @@ class ExploreViewModel(app: Application) : AndroidViewModel(app) {
} }
val client = ImporterClient(backendUrl) val client = ImporterClient(backendUrl)
runCatching { client.download(request) } runCatching { client.download(request) }
.onSuccess { onDone(true, "✓ Download gestartet") } .onSuccess {
// App-lifetime poll → success/failure notification even after leaving the screen
// (previously only the artist page + importer notified; search/Bibliothek was silent).
NotificationStore.startPoll(
backendUrl, request.jobId, request.title, request.artist ?: "",
navType = type, navAlbum = item.collectionName ?: "", navArtist = item.artistName ?: "",
)
onDone(true, "✓ Download gestartet")
}
.onFailure { onDone(false, "Backend nicht erreichbar: ${it.message}") } .onFailure { onDone(false, "Backend nicht erreichbar: ${it.message}") }
client.close() client.close()
} }
@@ -254,40 +371,12 @@ class ExploreViewModel(app: Application) : AndroidViewModel(app) {
fun togglePreview(track: ItunesItem) { fun togglePreview(track: ItunesItem) {
val url = track.previewUrl ?: return val url = track.previewUrl ?: return
val id = track.trackId ?: return val id = track.trackId ?: return
val cur = _state.value.previewingId player.pause() // don't overlap the 30s clip with library playback
if (cur == id) { preview.toggle(id, url, track.trackName ?: "", track.artistName ?: "", track.artworkUrl100)
stopPreview()
} else {
startPreview(url, id)
}
} }
private fun startPreview(url: String, id: Long) { fun stopPreview() = preview.stop()
stopPreview()
_state.value = _state.value.copy(previewingId = id)
viewModelScope.launch(Dispatchers.IO) {
try {
val mp = MediaPlayer().apply {
setDataSource(url)
prepare()
start()
setOnCompletionListener { _state.value = _state.value.copy(previewingId = null) }
}
mediaPlayer = mp
} catch (e: Exception) {
_state.value = _state.value.copy(previewingId = null)
}
}
}
fun stopPreview() { // NOTE: no onCleared stopPreview — the preview is app-level on purpose, so leaving the Explore
mediaPlayer?.runCatching { stop(); release() } // tab keeps it playing with the global control bar (see AppNavigation).
mediaPlayer = null
_state.value = _state.value.copy(previewingId = null)
}
override fun onCleared() {
super.onCleared()
stopPreview()
}
} }
@@ -0,0 +1,33 @@
package com.novasonic.app.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.model.Genre
import com.novasonic.app.app
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
data class GenreUiState(
val genres: List<Genre> = emptyList(),
val isLoading: Boolean = true,
val error: String? = null,
)
class GenreViewModel(app: Application) : AndroidViewModel(app) {
private val repo = app.app.repository
private val _state = MutableStateFlow(GenreUiState())
val state: StateFlow<GenreUiState> = _state
init { load() }
fun load() {
viewModelScope.launch {
_state.value = GenreUiState(isLoading = true)
runCatching { repo.getGenres().filter { it.songCount > 0 }.sortedByDescending { it.songCount } }
.onSuccess { _state.value = GenreUiState(genres = it, isLoading = false) }
.onFailure { _state.value = GenreUiState(error = it.message, isLoading = false) }
}
}
}
@@ -13,7 +13,9 @@ import kotlinx.coroutines.launch
data class HomeUiState( data class HomeUiState(
val heroAlbum: Album? = null, val heroAlbum: Album? = null,
val heroLabel: String = "",
val recentAlbums: List<Album> = emptyList(), val recentAlbums: List<Album> = emptyList(),
val recentlyPlayedAlbums: List<Album> = emptyList(),
val frequentAlbums: List<Album> = emptyList(), val frequentAlbums: List<Album> = emptyList(),
val randomAlbums: List<Album> = emptyList(), val randomAlbums: List<Album> = emptyList(),
val genres: List<Genre> = emptyList(), val genres: List<Genre> = emptyList(),
@@ -42,26 +44,45 @@ class HomeViewModel(app: Application) : AndroidViewModel(app) {
viewModelScope.launch { viewModelScope.launch {
_state.value = _state.value.copy(isLoading = true, error = null) _state.value = _state.value.copy(isLoading = true, error = null)
try { try {
val recentDef = async { repo.getRecentAlbums(20) } val recentDef = async { runCatching { repo.getRecentAlbums(20) } }
val frequentDef = async { repo.getFrequentAlbums(20) } val recentlyPlayedDef = async { runCatching { repo.getRecentlyPlayedAlbums(5) } }
val randomDef = async { repo.getRandomAlbums(20) } val frequentDef = async { runCatching { repo.getFrequentAlbums(20) } }
val genresDef = async { runCatching { repo.getGenres() }.getOrDefault(emptyList()) } val randomDef = async { runCatching { repo.getRandomAlbums(20) } }
val genresDef = async { runCatching { repo.getGenres() } }
val recent = recentDef.await() val recentResult = recentDef.await()
val frequent = frequentDef.await() val recentlyPlayedResult = recentlyPlayedDef.await()
val random = randomDef.await() val frequentResult = frequentDef.await()
val genres = genresDef.await() val randomResult = randomDef.await()
val genresResult = genresDef.await()
// Hero rotates between first recent and first frequent album if (recentResult.isFailure) {
val hero = if (System.currentTimeMillis() % 2 == 0L) recent.firstOrNull() _state.value = HomeUiState(error = recentResult.exceptionOrNull()?.message)
else frequent.firstOrNull() ?: recent.firstOrNull() return@launch
}
val recent = recentResult.getOrDefault(emptyList())
val recentlyPlayed = recentlyPlayedResult.getOrDefault(emptyList())
val frequent = frequentResult.getOrDefault(emptyList())
val random = randomResult.getOrDefault(emptyList())
val genres = genresResult.getOrDefault(emptyList())
// Hero pool = frequent.take(5) ∪ recentlyPlayed.take(5), deduped — matches web
val frequentIds = frequent.take(5).map { it.id }.toSet()
val seen = mutableSetOf<String>()
val pool = (frequent.take(5) + recentlyPlayed.take(5))
.filter { it.id.isNotBlank() && seen.add(it.id) }
val hero = pool.randomOrNull()
val heroLabel = if (hero != null && frequentIds.contains(hero.id)) "MEISTGESPIELT" else "ZULETZT GEHÖRT"
_state.value = _state.value.copy( _state.value = _state.value.copy(
heroAlbum = hero, heroAlbum = hero,
heroLabel = heroLabel,
recentAlbums = recent, recentAlbums = recent,
recentlyPlayedAlbums = recentlyPlayed,
frequentAlbums = frequent, frequentAlbums = frequent,
randomAlbums = random, randomAlbums = random,
genres = genres.filter { it.songCount > 0 }.take(12), genres = genres.filter { it.songCount > 0 }.sortedByDescending { it.songCount },
isLoading = false, isLoading = false,
error = null, error = null,
) )
@@ -6,7 +6,9 @@ import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.ImporterClient import com.novasonic.app.api.ImporterClient
import com.novasonic.app.api.model.DownloadRequest import com.novasonic.app.api.model.DownloadRequest
import com.novasonic.app.api.model.ImportResolveResponse import com.novasonic.app.api.model.ImportResolveResponse
import com.novasonic.app.api.model.ImportTrack
import com.novasonic.app.app import com.novasonic.app.app
import com.novasonic.app.data.NotificationStore
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@@ -25,11 +27,20 @@ data class ImporterUiState(
val jobMessage: String? = null, val jobMessage: String? = null,
val jobCompleted: Int = 0, val jobCompleted: Int = 0,
val jobTotal: Int = 0, val jobTotal: Int = 0,
// 30s preview — synthetic id (previewUrl hash) of the clip currently playing, or null
val previewingId: Long? = null,
// Playlist aus dem Import anlegen (wie im Web-Importer). Nur sinnvoll ab zwei Titeln.
val createPlaylist: Boolean = true,
val playlistName: String = "",
val playlistStatus: String? = null,
) )
class ImporterViewModel(app: Application) : AndroidViewModel(app) { class ImporterViewModel(app: Application) : AndroidViewModel(app) {
private val repo = app.app.repository private val repo = app.app.repository
private val player = app.app.playerController
private val preview = app.app.previewController
private val _state = MutableStateFlow(ImporterUiState()) private val _state = MutableStateFlow(ImporterUiState())
val state: StateFlow<ImporterUiState> = _state val state: StateFlow<ImporterUiState> = _state
@@ -40,7 +51,31 @@ class ImporterViewModel(app: Application) : AndroidViewModel(app) {
_state.value = _state.value.copy(backendUrl = s.backendUrl) _state.value = _state.value.copy(backendUrl = s.backendUrl)
} }
} }
// Mirror the app-level preview so the track rows show which clip is playing.
viewModelScope.launch {
preview.state.collect { ps ->
_state.value = _state.value.copy(previewingId = if (ps.isPlaying) ps.trackId else null)
} }
}
}
// ── 30s preview ─────────────────────────────────────────────────────────
// Import tracks have no numeric id, so key the app-level preview by the previewUrl's hash.
fun previewId(track: ImportTrack): Long = track.previewUrl?.hashCode()?.toLong() ?: 0L
fun togglePreview(track: ImportTrack) {
val url = track.previewUrl ?: return
player.pause() // don't overlap the 30s clip with library playback
preview.toggle(
previewId(track), url,
track.trackName ?: "", track.artistName ?: "", track.artworkUrl100,
)
}
fun stopPreview() = preview.stop()
fun setCreatePlaylist(v: Boolean) { _state.value = _state.value.copy(createPlaylist = v) }
fun setPlaylistName(v: String) { _state.value = _state.value.copy(playlistName = v) }
fun onLink(v: String) { fun onLink(v: String) {
_state.value = _state.value.copy( _state.value = _state.value.copy(
@@ -108,6 +143,17 @@ class ImporterViewModel(app: Application) : AndroidViewModel(app) {
tracks = resolved.tracks, tracks = resolved.tracks,
) )
) )
// App-lifetime poll → notification delivered even if user navigates away
NotificationStore.startPoll(
backendUrl = s.backendUrl,
jobId = jobId,
title = resolved.name ?: "Import",
artist = resolved.artist ?: "",
navType = resolved.type ?: "",
navAlbum = resolved.name ?: "",
navArtist = resolved.artist ?: "",
)
// In-screen progress poll (cancelled on navigation — only for UI)
pollJob(client, jobId) pollJob(client, jobId)
} catch (e: Exception) { } catch (e: Exception) {
_state.value = _state.value.copy( _state.value = _state.value.copy(
@@ -120,6 +166,9 @@ class ImporterViewModel(app: Application) : AndroidViewModel(app) {
} }
private suspend fun pollJob(client: ImporterClient, jobId: String) { private suspend fun pollJob(client: ImporterClient, jobId: String) {
val s = _state.value
val title = s.resolved?.name ?: "Import"
val artist = s.resolved?.artist ?: ""
try { try {
repeat(600) { // up to ~20 min at 2s interval repeat(600) { // up to ~20 min at 2s interval
delay(2000) delay(2000)
@@ -132,6 +181,11 @@ class ImporterViewModel(app: Application) : AndroidViewModel(app) {
) )
if (st.status == "done" || st.status == "error") { if (st.status == "done" || st.status == "error") {
_state.value = _state.value.copy(isDownloading = false) _state.value = _state.value.copy(isDownloading = false)
val cur = _state.value
if (st.status == "done" && cur.createPlaylist && cur.resolved!!.tracks.size > 1) {
buildPlaylist(cur.playlistName.ifBlank { cur.resolved.name ?: "Import" },
cur.resolved.tracks)
}
return return
} }
} }
@@ -141,6 +195,47 @@ class ImporterViewModel(app: Application) : AndroidViewModel(app) {
} }
} }
/**
* Legt nach dem Import eine Navidrome-Playlist aus den importierten Titeln an — dieselbe Abfolge
* wie im Web: Scan anstossen, kurz warten, jeden Titel suchen, gefundene IDs in eine neue
* Playlist. Titel, die Navidrome (noch) nicht kennt, werden gezaehlt statt zu scheitern.
*/
private suspend fun buildPlaylist(name: String, tracks: List<ImportTrack>) {
_state.value = _state.value.copy(playlistStatus = "Navidrome scannt…")
runCatching { repo.startScan() }
delay(4000)
val norm = { s: String -> s.lowercase().replace(Regex("[^\\p{L}\\p{N}]+"), "") }
val ids = mutableListOf<String>()
var fehlend = 0
for (t in tracks) {
val titel = t.trackName ?: continue
val treffer = runCatching {
val q = listOfNotNull(t.artistName, titel).joinToString(" ")
val gefunden = repo.search(q).song
gefunden.firstOrNull { norm(it.title) == norm(titel) }
?: repo.search(titel).song.firstOrNull { norm(it.title) == norm(titel) }
}.getOrNull()
if (treffer != null) ids += treffer.id else fehlend++
_state.value = _state.value.copy(
playlistStatus = "Playlist: ${ids.size}/${tracks.size} gefunden…")
}
if (ids.isEmpty()) {
_state.value = _state.value.copy(
playlistStatus = "Keine Titel in Navidrome gefunden — Playlist nicht angelegt.")
return
}
val res = runCatching { repo.createPlaylist(name, ids) }
_state.value = _state.value.copy(
playlistStatus = res.fold(
{ "Playlist \"$name\" angelegt: ${ids.size}/${tracks.size} Titel" +
if (fehlend > 0) " ($fehlend nicht gefunden)" else "" },
{ "Playlist fehlgeschlagen: ${it.message}" },
),
)
}
private fun mapError(code: String): String = when (code) { private fun mapError(code: String): String = when (code) {
"EDITORIAL_PLAYLIST" -> "EDITORIAL_PLAYLIST" ->
"Editorial Playlist: Spotify sperrt eigene kuratierte Playlists. Kopiere sie in eine eigene Playlist und importiere diese." "Editorial Playlist: Spotify sperrt eigene kuratierte Playlists. Kopiere sie in eine eigene Playlist und importiere diese."
@@ -1,23 +1,36 @@
package com.novasonic.app.viewmodel package com.novasonic.app.viewmodel
import android.app.Application import android.app.Application
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.model.Album import com.novasonic.app.api.model.Album
import com.novasonic.app.api.model.ArtistIndex import com.novasonic.app.api.model.ArtistIndex
import com.novasonic.app.api.model.Playlist import com.novasonic.app.api.model.Playlist
import com.novasonic.app.app import com.novasonic.app.app
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
enum class LibraryTab { PLAYLISTS, ALBUMS, ARTISTS } enum class LibraryTab { PLAYLISTS, OFFLINE, ALBUMS, ARTISTS }
enum class AlbumSort { NEWEST, OLDEST, AZ }
data class LibraryUiState( data class LibraryUiState(
val tab: LibraryTab = LibraryTab.PLAYLISTS, val tab: LibraryTab = LibraryTab.PLAYLISTS,
val albums: List<Album> = emptyList(), // Two pre-fetched lists — avoids re-fetch when switching sort
val albumsByNewest: List<Album> = emptyList(), // type=newest (Navidrome add-date)
val albumsByName: List<Album> = emptyList(), // type=alphabeticalByName (for AZ + Oldest)
val albumSort: AlbumSort = AlbumSort.NEWEST,
val artistIndexes: List<ArtistIndex> = emptyList(), val artistIndexes: List<ArtistIndex> = emptyList(),
/** IDs der markierten ("gefolgten") Künstler — getArtists liefert kein `starred` mit. */
val gefolgteIds: Set<String> = emptySet(),
val nurGefolgte: Boolean = false,
val playlists: List<Playlist> = emptyList(), val playlists: List<Playlist> = emptyList(),
/** Angemeldeter Nutzer — der Besitzer wird nur bei FREMDEN Playlists angezeigt. */
val currentUser: String = "",
val isLoading: Boolean = false, val isLoading: Boolean = false,
val error: String? = null, val error: String? = null,
) )
@@ -29,27 +42,72 @@ class LibraryViewModel(app: Application) : AndroidViewModel(app) {
private val _state = MutableStateFlow(LibraryUiState(isLoading = true)) private val _state = MutableStateFlow(LibraryUiState(isLoading = true))
val state: StateFlow<LibraryUiState> = _state val state: StateFlow<LibraryUiState> = _state
init { loadPlaylists() } // Scroll positions live in the VM so they survive drilling into an album/artist and back (the
// Library back-stack entry, hence this VM, is retained). A full teardown of the tab → fresh VM
// → back at the top, as expected.
val albumsGridState = LazyGridState()
val artistsListState = LazyListState()
init {
loadPlaylists()
viewModelScope.launch {
val u = runCatching { repo.credentialsFlow().first().username }.getOrDefault("")
_state.value = _state.value.copy(currentUser = u)
}
}
fun setAlbumSort(sort: AlbumSort) {
if (sort == _state.value.albumSort) return
_state.value = _state.value.copy(albumSort = sort)
// Eine andere Sortierung heißt eine andere Liste — dort oben anfangen. Bewusst hier und
// nicht als LaunchedEffect im Screen: der feuert auch bei jedem Neu-Composen (z. B. nach
// dem Zurück aus einem Album) und hätte die gemerkte Scrollposition jedes Mal verworfen.
viewModelScope.launch { albumsGridState.scrollToItem(0) }
}
fun selectTab(tab: LibraryTab) { fun selectTab(tab: LibraryTab) {
_state.value = _state.value.copy(tab = tab) _state.value = _state.value.copy(tab = tab)
when (tab) { when (tab) {
LibraryTab.ALBUMS -> if (_state.value.albums.isEmpty()) loadAlbums() LibraryTab.ALBUMS -> if (_state.value.albumsByNewest.isEmpty() && _state.value.albumsByName.isEmpty()) loadAlbums()
LibraryTab.ARTISTS -> if (_state.value.artistIndexes.isEmpty()) loadArtists() LibraryTab.ARTISTS -> if (_state.value.artistIndexes.isEmpty()) loadArtists()
LibraryTab.PLAYLISTS -> if (_state.value.playlists.isEmpty()) loadPlaylists() LibraryTab.PLAYLISTS -> if (_state.value.playlists.isEmpty()) loadPlaylists()
LibraryTab.OFFLINE -> Unit
} }
} }
private fun loadAlbums() = viewModelScope.launch { private fun loadAlbums() = viewModelScope.launch {
_state.value = _state.value.copy(isLoading = true, error = null) _state.value = _state.value.copy(isLoading = true, error = null)
try { try {
val albums = repo.getAlphaAlbums(200) val newestDef = async { runCatching { repo.getRecentAlbums(500) } }
_state.value = _state.value.copy(albums = albums, isLoading = false) val azDef = async { runCatching { repo.getAlphaAlbums(500) } }
val newestResult = newestDef.await()
val azResult = azDef.await()
if (newestResult.isFailure) {
_state.value = _state.value.copy(error = newestResult.exceptionOrNull()?.message, isLoading = false)
return@launch
}
_state.value = _state.value.copy(
albumsByNewest = newestResult.getOrDefault(emptyList()),
albumsByName = azResult.getOrDefault(emptyList()),
isLoading = false,
)
} catch (e: Exception) { } catch (e: Exception) {
_state.value = _state.value.copy(error = e.message, isLoading = false) _state.value = _state.value.copy(error = e.message, isLoading = false)
} }
} }
fun nurGefolgteUmschalten(an: Boolean) {
_state.value = _state.value.copy(nurGefolgte = an)
if (an) ladeGefolgte()
}
/** Markierte Künstler nachladen. Frisch bei jedem Einschalten, damit ein eben entfolgter
* Künstler nicht noch in der Liste steht. */
private fun ladeGefolgte() = viewModelScope.launch {
runCatching { repo.getStarred().artist.map { it.id }.toSet() }
.onSuccess { _state.value = _state.value.copy(gefolgteIds = it) }
}
private fun loadArtists() = viewModelScope.launch { private fun loadArtists() = viewModelScope.launch {
_state.value = _state.value.copy(isLoading = true, error = null) _state.value = _state.value.copy(isLoading = true, error = null)
try { try {
@@ -69,4 +127,21 @@ class LibraryViewModel(app: Application) : AndroidViewModel(app) {
_state.value = _state.value.copy(error = e.message, isLoading = false) _state.value = _state.value.copy(error = e.message, isLoading = false)
} }
} }
fun createPlaylist(name: String, onSuccess: (String) -> Unit = {}) {
val trimmed = name.trim()
if (trimmed.isBlank()) return
viewModelScope.launch {
try {
val newPl = repo.createPlaylist(trimmed, emptyList())
val pls = runCatching { repo.getPlaylists() }.getOrDefault(_state.value.playlists)
_state.value = _state.value.copy(playlists = pls)
onSuccess(newPl.id)
} catch (e: Exception) {
_state.value = _state.value.copy(error = e.message)
}
}
}
fun reloadPlaylists() = loadPlaylists()
} }
@@ -1,4 +1,4 @@
package com.novasonic.app.viewmodel package com.novasonic.app.viewmodel
import android.app.Application import android.app.Application
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
@@ -7,7 +7,6 @@ import com.novasonic.app.api.LrcLibClient
import com.novasonic.app.api.LrcLine import com.novasonic.app.api.LrcLine
import com.novasonic.app.api.parseLrc import com.novasonic.app.api.parseLrc
import com.novasonic.app.api.model.Song import com.novasonic.app.api.model.Song
import com.novasonic.app.app
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -17,7 +16,7 @@ data class LyricsUiState(
val plainText: String = "", // fallback plain lyrics val plainText: String = "", // fallback plain lyrics
val isLoading: Boolean = false, val isLoading: Boolean = false,
val notFound: Boolean = false, val notFound: Boolean = false,
val songId: String = "", // which song these are for val songId: String = "",
) )
class LyricsViewModel(app: Application) : AndroidViewModel(app) { class LyricsViewModel(app: Application) : AndroidViewModel(app) {
@@ -29,24 +28,18 @@ class LyricsViewModel(app: Application) : AndroidViewModel(app) {
if (_state.value.songId == song.id && !_state.value.isLoading) return if (_state.value.songId == song.id && !_state.value.isLoading) return
_state.value = LyricsUiState(isLoading = true, songId = song.id) _state.value = LyricsUiState(isLoading = true, songId = song.id)
viewModelScope.launch { viewModelScope.launch {
val artist = song.artist ?: "" val result = LrcLibClient.getLyrics(
val title = song.title artist = song.artist ?: "",
val album = song.album title = song.title,
val durSecs = song.duration album = song.album,
durationSecs = song.duration,
val result = LrcLibClient.getLyrics(artist, title, album, durSecs) )
_state.value = when {
when { result == null -> LyricsUiState(notFound = true, songId = song.id)
result == null -> _state.value = LyricsUiState( result.instrumental -> LyricsUiState(plainText = "🎵 Instrumentalstück", songId = song.id)
notFound = true, songId = song.id) !result.syncedLyrics.isNullOrBlank() -> LyricsUiState(lines = parseLrc(result.syncedLyrics), songId = song.id)
result.instrumental -> _state.value = LyricsUiState( !result.plainLyrics.isNullOrBlank() -> LyricsUiState(plainText = result.plainLyrics, songId = song.id)
plainText = "🎵 Instrumentalstück", songId = song.id) else -> LyricsUiState(notFound = true, songId = song.id)
!result.syncedLyrics.isNullOrBlank() -> _state.value = LyricsUiState(
lines = parseLrc(result.syncedLyrics), songId = song.id)
!result.plainLyrics.isNullOrBlank() -> _state.value = LyricsUiState(
plainText = result.plainLyrics, songId = song.id)
else -> _state.value = LyricsUiState(
notFound = true, songId = song.id)
} }
} }
} }
@@ -0,0 +1,33 @@
package com.novasonic.app.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.model.Song
import com.novasonic.app.app
import com.novasonic.app.offline.DownloadGroupEntity
import com.novasonic.app.offline.DownloadedTrackEntity
import com.novasonic.app.offline.toSong
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
class OfflineDetailViewModel(app: Application, savedState: SavedStateHandle) : AndroidViewModel(app) {
private val offlineRepo = app.app.offlineRepository
// groupId is passed URL-encoded in the route; Navigation decodes it back to "album:xyz".
private val groupId: String = savedState["groupId"] ?: ""
val group: StateFlow<DownloadGroupEntity?> = offlineRepo.allGroupsFlow
.map { groups -> groups.find { it.groupId == groupId } }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null)
val tracks: StateFlow<List<DownloadedTrackEntity>> = offlineRepo.tracksForGroupFlow(groupId)
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
fun songs(): List<Song> = tracks.value.map { it.toSong() }
fun deleteSong(songId: String) {
viewModelScope.launch { offlineRepo.removeSongFromGroup(groupId, songId) }
}
}
@@ -0,0 +1,38 @@
package com.novasonic.app.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.model.Song
import com.novasonic.app.app
import com.novasonic.app.offline.DownloadGroupEntity
import com.novasonic.app.offline.DownloadState
import com.novasonic.app.offline.toSong
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class OfflineViewModel(app: Application) : AndroidViewModel(app) {
private val offlineRepo = app.app.offlineRepository
val groups: StateFlow<List<DownloadGroupEntity>> = offlineRepo.allGroupsFlow
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
val storageBytes: StateFlow<Long> = groups
.map { withContext(Dispatchers.IO) { offlineRepo.storageUsedBytes() } }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), 0L)
fun deleteGroup(groupId: String) {
viewModelScope.launch { offlineRepo.deleteGroup(groupId) }
}
/** Nur FERTIGE Titel: wartende oder fehlgeschlagene haben keine lokale Datei und wuerden aus
* dem Netz gezogen — offline schlaegt die Wiedergabe dann fehl, bei grossen Playlists
* gleich beim ersten Titel. */
suspend fun songsForGroup(groupId: String): List<Song> =
offlineRepo.tracksForGroup(groupId)
.filter { it.state == DownloadState.DONE }
.map { it.toSong() }
}
@@ -6,30 +6,61 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.model.PlaylistWithSongs import com.novasonic.app.api.model.PlaylistWithSongs
import com.novasonic.app.app import com.novasonic.app.app
import com.novasonic.app.offline.DownloadGroupEntity
import com.novasonic.app.offline.DownloadState
import com.novasonic.app.offline.GroupType
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
data class PlaylistUiState( data class PlaylistUiState(
val playlist: PlaylistWithSongs? = null, val playlist: PlaylistWithSongs? = null,
val isLoading: Boolean = true, val isLoading: Boolean = true,
val isSaving: Boolean = false,
val deleted: Boolean = false,
val error: String? = null, val error: String? = null,
/** Angemeldeter Nutzer — der Besitzer wird nur bei FREMDEN Playlists angezeigt. */
val currentUser: String = "",
) )
class PlaylistViewModel(app: Application, savedState: SavedStateHandle) : AndroidViewModel(app) { class PlaylistViewModel(app: Application, savedState: SavedStateHandle) : AndroidViewModel(app) {
private val repo = app.app.repository private val repo = app.app.repository
private val offlineRepo = app.app.offlineRepository
private val playlistId: String? = savedState["playlistId"] private val playlistId: String? = savedState["playlistId"]
private val _state = MutableStateFlow(PlaylistUiState()) private val _state = MutableStateFlow(PlaylistUiState())
val state: StateFlow<PlaylistUiState> = _state val state: StateFlow<PlaylistUiState> = _state
val downloadGroup: StateFlow<DownloadGroupEntity?> = offlineRepo.allGroupsFlow
.map { groups -> groups.find { it.groupId == "playlist:$playlistId" } }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null)
/** True while any track in this playlist's group is queued or actively downloading. */
val isDownloading: StateFlow<Boolean> = offlineRepo.tracksForGroupFlow("playlist:$playlistId")
.map { tracks -> tracks.any { it.state == DownloadState.QUEUED || it.state == DownloadState.DOWNLOADING } }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)
init { init {
load()
viewModelScope.launch {
val u = runCatching { repo.credentialsFlow().first().username }.getOrDefault("")
_state.value = _state.value.copy(currentUser = u)
}
}
fun load() {
val id = playlistId val id = playlistId
if (id.isNullOrBlank()) { if (id.isNullOrBlank()) {
_state.value = PlaylistUiState(isLoading = false, error = "Keine Playlist-ID übergeben") _state.value = PlaylistUiState(isLoading = false, error = "Keine Playlist-ID übergeben")
} else { return
}
viewModelScope.launch { viewModelScope.launch {
_state.value = _state.value.copy(isLoading = true, error = null)
try { try {
val pl = repo.getPlaylist(id) val pl = repo.getPlaylist(id)
_state.value = PlaylistUiState(playlist = pl, isLoading = false) _state.value = PlaylistUiState(playlist = pl, isLoading = false)
@@ -38,5 +69,101 @@ class PlaylistViewModel(app: Application, savedState: SavedStateHandle) : Androi
} }
} }
} }
fun rename(newName: String, newComment: String? = null) {
val id = playlistId ?: return
val pl = _state.value.playlist ?: return
val trimmed = newName.trim()
if (trimmed.isBlank()) return
val comment = newComment?.trim() ?: pl.comment
viewModelScope.launch {
_state.value = _state.value.copy(isSaving = true)
try {
repo.updatePlaylistMeta(id, trimmed, comment)
_state.value = _state.value.copy(
playlist = pl.copy(name = trimmed, comment = comment),
isSaving = false,
)
} catch (e: Exception) {
_state.value = _state.value.copy(isSaving = false, error = e.message)
}
}
}
fun delete() {
val id = playlistId ?: return
viewModelScope.launch {
_state.value = _state.value.copy(isSaving = true)
try {
repo.deletePlaylist(id)
_state.value = _state.value.copy(deleted = true, isSaving = false)
} catch (e: Exception) {
_state.value = _state.value.copy(isSaving = false, error = e.message)
}
}
}
fun uploadCover(imageBytes: ByteArray, mimeType: String) {
val id = playlistId ?: return
viewModelScope.launch {
_state.value = _state.value.copy(isSaving = true)
try {
repo.uploadPlaylistCover(id, imageBytes, mimeType)
// Reload to get the updated coverArt ID from Navidrome
val pl = repo.getPlaylist(id)
_state.value = _state.value.copy(playlist = pl, isSaving = false)
} catch (e: Exception) {
_state.value = _state.value.copy(isSaving = false, error = e.message)
}
}
}
fun removeCover() {
val id = playlistId ?: return
val pl = _state.value.playlist ?: return
viewModelScope.launch {
_state.value = _state.value.copy(isSaving = true)
try {
repo.removePlaylistCover(id)
_state.value = _state.value.copy(
playlist = pl.copy(coverArt = null),
isSaving = false,
)
} catch (e: Exception) {
_state.value = _state.value.copy(isSaving = false, error = e.message)
}
}
}
fun downloadPlaylist() {
val pl = _state.value.playlist ?: return
viewModelScope.launch {
runCatching {
offlineRepo.enqueueGroup(
type = GroupType.PLAYLIST,
sourceId = pl.id,
name = pl.name,
coverArt = pl.coverArt,
songs = pl.entry,
)
}.onFailure { android.util.Log.e("PlaylistViewModel", "downloadPlaylist failed", it) }
}
}
fun removeSong(index: Int) {
val id = playlistId ?: return
val pl = _state.value.playlist ?: return
if (index < 0 || index >= pl.entry.size) return
viewModelScope.launch {
try {
repo.removeSongsFromPlaylist(id, listOf(index))
val newSongs = pl.entry.toMutableList().also { it.removeAt(index) }
_state.value = _state.value.copy(
playlist = pl.copy(entry = newSongs, songCount = newSongs.size)
)
} catch (e: Exception) {
_state.value = _state.value.copy(error = e.message)
}
}
} }
} }
@@ -1,8 +1,10 @@
package com.novasonic.app.viewmodel package com.novasonic.app.viewmodel
import android.app.Application import android.app.Application
import androidx.compose.foundation.lazy.LazyListState
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.model.ArtistOverride
import com.novasonic.app.api.model.SearchResult3 import com.novasonic.app.api.model.SearchResult3
import com.novasonic.app.app import com.novasonic.app.app
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@@ -16,6 +18,8 @@ data class SearchUiState(
val searchResult: SearchResult3? = null, val searchResult: SearchResult3? = null,
val isLoading: Boolean = false, val isLoading: Boolean = false,
val error: String? = null, val error: String? = null,
// Artist pins (by Navidrome artist id) so a pinned artist shows the correct picture in results.
val overrides: Map<String, ArtistOverride> = emptyMap(),
) )
class SearchViewModel(app: Application) : AndroidViewModel(app) { class SearchViewModel(app: Application) : AndroidViewModel(app) {
@@ -25,8 +29,18 @@ class SearchViewModel(app: Application) : AndroidViewModel(app) {
private val _state = MutableStateFlow(SearchUiState()) private val _state = MutableStateFlow(SearchUiState())
val state: StateFlow<SearchUiState> = _state val state: StateFlow<SearchUiState> = _state
// Results scroll — hoisted so it survives a drill-in/back within the search.
val listState = LazyListState()
private var searchJob: Job? = null private var searchJob: Job? = null
init {
viewModelScope.launch {
val ov = runCatching { repo.artistOverrides() }.getOrDefault(emptyMap())
if (ov.isNotEmpty()) _state.value = _state.value.copy(overrides = ov)
}
}
fun onQueryChange(q: String) = onSearch(q) fun onQueryChange(q: String) = onSearch(q)
fun onSearch(q: String) { fun onSearch(q: String) {
@@ -1,33 +1,58 @@
package com.novasonic.app.viewmodel package com.novasonic.app.viewmodel
import android.app.Application import android.app.Application
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.AbsClient
import com.novasonic.app.app import com.novasonic.app.app
import com.novasonic.app.data.PrefsStore import com.novasonic.app.data.PrefsStore
import com.novasonic.app.ui.theme.NsColors
import io.ktor.client.HttpClient
import io.ktor.client.engine.android.Android
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.request.get
import io.ktor.http.HttpStatusCode
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
sealed class ConnStatus {
object Idle : ConnStatus()
object Checking : ConnStatus()
data class Ok(val text: String) : ConnStatus()
data class Err(val text: String) : ConnStatus()
}
data class SettingsUiState( data class SettingsUiState(
val serverUrl: String = "", val serverUrl: String = "",
val username: String = "", val username: String = "",
val password: String = "", val password: String = "",
val lastFmKey: String = "", val lastFmKey: String = "",
val backendUrl: String = "", val backendUrl: String = "",
val scrobbleUrl: String = "",
val scrobbleMode: String = "30s", val scrobbleMode: String = "30s",
val showPlayCount: Boolean = false, val showPlayCount: Boolean = false,
val theme: String = "dark-ocean", val theme: String = "dark-ocean",
val absUrl: String = "",
val absApiKey: String = "",
val absChapterTrackMode: Boolean = false,
val downloadWifiOnly: Boolean = true,
val wischenWechseltTitel: Boolean = true,
val isSaving: Boolean = false, val isSaving: Boolean = false,
val savedOk: Boolean = false, val savedOk: Boolean = false,
val error: String? = null, val error: String? = null,
val absStatus: ConnStatus = ConnStatus.Idle,
val backendStatus: ConnStatus = ConnStatus.Idle,
val scrobbleStatus: ConnStatus = ConnStatus.Idle,
) )
class SettingsViewModel(app: Application) : AndroidViewModel(app) { class SettingsViewModel(app: Application) : AndroidViewModel(app) {
private val repo = app.app.repository private val repo = app.app.repository
private val offlineRepo = app.app.offlineRepository
private val _state = MutableStateFlow(SettingsUiState()) // Seed the theme with the already-applied one so the picker doesn't jump before DataStore emits.
private val _state = MutableStateFlow(SettingsUiState(theme = NsColors.themeId))
val state: StateFlow<SettingsUiState> = _state val state: StateFlow<SettingsUiState> = _state
init { init {
@@ -39,9 +64,15 @@ class SettingsViewModel(app: Application) : AndroidViewModel(app) {
password = s.password, password = s.password,
lastFmKey = s.lastFmKey, lastFmKey = s.lastFmKey,
backendUrl = s.backendUrl, backendUrl = s.backendUrl,
scrobbleUrl = s.scrobbleUrl,
scrobbleMode = s.scrobbleMode, scrobbleMode = s.scrobbleMode,
showPlayCount = s.showPlayCount, showPlayCount = s.showPlayCount,
theme = s.theme, theme = s.theme,
absUrl = s.absUrl,
absApiKey = s.absApiKey,
absChapterTrackMode = s.absChapterTrackMode,
downloadWifiOnly = s.downloadWifiOnly,
wischenWechseltTitel = s.wischenWechseltTitel,
) )
} }
} }
@@ -51,15 +82,86 @@ class SettingsViewModel(app: Application) : AndroidViewModel(app) {
fun onUsername(v: String) = update { it.copy(username = v, savedOk = false) } fun onUsername(v: String) = update { it.copy(username = v, savedOk = false) }
fun onPassword(v: String) = update { it.copy(password = v, savedOk = false) } fun onPassword(v: String) = update { it.copy(password = v, savedOk = false) }
fun onLastFmKey(v: String) = update { it.copy(lastFmKey = v, savedOk = false) } fun onLastFmKey(v: String) = update { it.copy(lastFmKey = v, savedOk = false) }
fun onBackendUrl(v: String) = update { it.copy(backendUrl = v, savedOk = false) } fun onBackendUrl(v: String) = update { it.copy(backendUrl = v, savedOk = false, backendStatus = ConnStatus.Idle) }
fun onScrobbleUrl(v: String) = update { it.copy(scrobbleUrl = v, savedOk = false, scrobbleStatus = ConnStatus.Idle) }
fun onScrobbleMode(v: String) = update { it.copy(scrobbleMode = v, savedOk = false) } fun onScrobbleMode(v: String) = update { it.copy(scrobbleMode = v, savedOk = false) }
fun onShowPlayCount(v: Boolean) = update { it.copy(showPlayCount = v, savedOk = false) } fun onShowPlayCount(v: Boolean) = update { it.copy(showPlayCount = v, savedOk = false) }
fun onAbsUrl(v: String) = update { it.copy(absUrl = v, savedOk = false, absStatus = ConnStatus.Idle) }
fun onAbsApiKey(v: String) = update { it.copy(absApiKey = v, savedOk = false, absStatus = ConnStatus.Idle) }
fun onAbsChapterTrackMode(v: Boolean) = update { it.copy(absChapterTrackMode = v, savedOk = false) }
fun onDownloadWifiOnly(v: Boolean) = update { it.copy(downloadWifiOnly = v, savedOk = false) }
fun onWischenWechseltTitel(v: Boolean) = update { it.copy(wischenWechseltTitel = v, savedOk = false) }
fun onTheme(id: String) { fun onTheme(id: String) {
update { it.copy(theme = id) } update { it.copy(theme = id) }
viewModelScope.launch { repo.saveTheme(id) } viewModelScope.launch { repo.saveTheme(id) }
} }
fun testAbs() {
val url = _state.value.absUrl.trim().trimEnd('/')
val key = _state.value.absApiKey.trim()
if (url.isBlank() || key.isBlank()) {
update { it.copy(absStatus = ConnStatus.Err("URL und API Key eingeben")) }
return
}
update { it.copy(absStatus = ConnStatus.Checking) }
viewModelScope.launch {
val backend = _state.value.backendUrl.trim().trimEnd('/')
val ok = runCatching { AbsClient(url, key, backend).ping() }.getOrDefault(false)
update { it.copy(absStatus = if (ok) ConnStatus.Ok("Verbunden · $url") else ConnStatus.Err("Nicht erreichbar")) }
}
}
fun testBackend() {
val url = _state.value.backendUrl.trim().trimEnd('/')
if (url.isBlank()) {
update { it.copy(backendStatus = ConnStatus.Err("Backend URL eingeben")) }
return
}
update { it.copy(backendStatus = ConnStatus.Checking) }
viewModelScope.launch {
try {
val http = HttpClient(Android) {
install(HttpTimeout) { requestTimeoutMillis = 5_000; connectTimeoutMillis = 4_000 }
}
val resp = http.get("$url/api/health")
http.close()
if (resp.status == HttpStatusCode.OK) {
update { it.copy(backendStatus = ConnStatus.Ok("Verbunden · $url")) }
} else {
update { it.copy(backendStatus = ConnStatus.Err("HTTP ${resp.status.value}")) }
}
} catch (e: Exception) {
update { it.copy(backendStatus = ConnStatus.Err("Nicht erreichbar")) }
}
}
}
fun testScrobble() {
val url = _state.value.scrobbleUrl.trim().trimEnd('/')
if (url.isBlank()) {
update { it.copy(scrobbleStatus = ConnStatus.Err("Scrobble URL eingeben")) }
return
}
update { it.copy(scrobbleStatus = ConnStatus.Checking) }
viewModelScope.launch {
try {
val http = HttpClient(Android) {
install(HttpTimeout) { requestTimeoutMillis = 5_000; connectTimeoutMillis = 4_000 }
}
val resp = http.get("$url/scrobble/health")
http.close()
if (resp.status == HttpStatusCode.OK) {
update { it.copy(scrobbleStatus = ConnStatus.Ok("Verbunden · $url")) }
} else {
update { it.copy(scrobbleStatus = ConnStatus.Err("HTTP ${resp.status.value}")) }
}
} catch (e: Exception) {
update { it.copy(scrobbleStatus = ConnStatus.Err("Nicht erreichbar")) }
}
}
}
fun save() { fun save() {
val s = _state.value val s = _state.value
if (s.serverUrl.isBlank() || s.username.isBlank() || s.password.isBlank()) { if (s.serverUrl.isBlank() || s.username.isBlank() || s.password.isBlank()) {
@@ -75,10 +177,19 @@ class SettingsViewModel(app: Application) : AndroidViewModel(app) {
password = s.password, password = s.password,
lastFmKey = s.lastFmKey.trim(), lastFmKey = s.lastFmKey.trim(),
backendUrl = s.backendUrl.trimEnd('/'), backendUrl = s.backendUrl.trimEnd('/'),
scrobbleUrl = s.scrobbleUrl.trimEnd('/'),
scrobbleMode = s.scrobbleMode, scrobbleMode = s.scrobbleMode,
showPlayCount = s.showPlayCount, showPlayCount = s.showPlayCount,
theme = s.theme, theme = s.theme,
absUrl = s.absUrl.trimEnd('/'),
absApiKey = s.absApiKey.trim(),
absChapterTrackMode = s.absChapterTrackMode,
downloadWifiOnly = s.downloadWifiOnly,
wischenWechseltTitel = s.wischenWechseltTitel,
)) ))
// Die Netzbedingung steckt in der bereits eingereihten Arbeit — ohne Neueinreihen
// wuerde der WLAN-Schalter erst beim naechsten App-Start greifen.
offlineRepo.netzbedingungAktualisieren()
_state.value = _state.value.copy(isSaving = false, savedOk = true) _state.value = _state.value.copy(isSaving = false, savedOk = true)
} catch (e: Exception) { } catch (e: Exception) {
_state.value = _state.value.copy(isSaving = false, error = e.message) _state.value = _state.value.copy(isSaving = false, error = e.message)
@@ -0,0 +1,124 @@
package com.novasonic.app.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.novasonic.app.api.model.ScrobbleStats
import com.novasonic.app.app
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import java.util.Calendar
import java.util.TimeZone
enum class StatsView { ALL, YEAR, MONTH }
data class StatsUiState(
val loading: Boolean = true,
val configured: Boolean = true,
val error: String? = null,
val view: StatsView = StatsView.ALL,
val year: Int = Calendar.getInstance().get(Calendar.YEAR),
val month: Int = Calendar.getInstance().get(Calendar.MONTH), // 0-11
val firstPlayedAt: Long? = null, // earliest logged play → navigator lower bound
val stats: ScrobbleStats? = null,
)
class StatsViewModel(app: Application) : AndroidViewModel(app) {
private val repo = app.app.repository
private val _state = MutableStateFlow(StatsUiState())
val state: StateFlow<StatsUiState> = _state
init { load() }
fun setView(v: StatsView) {
if (v == _state.value.view) return
_state.value = _state.value.copy(view = v)
load()
}
/** Step the current year/month window by ±1 (no-op in ALL). */
fun step(dir: Int) {
val s = _state.value
when (s.view) {
StatsView.YEAR -> _state.value = s.copy(year = s.year + dir)
StatsView.MONTH -> {
var m = s.month + dir
var y = s.year
if (m < 0) { m = 11; y-- }
if (m > 11) { m = 0; y++ }
_state.value = s.copy(year = y, month = m)
}
else -> return
}
load()
}
/** True when the shown window is the current one — used to disable stepping into the future. */
fun atCurrent(): Boolean {
val s = _state.value
val now = Calendar.getInstance()
return when (s.view) {
StatsView.YEAR -> s.year >= now.get(Calendar.YEAR)
StatsView.MONTH -> s.year > now.get(Calendar.YEAR) ||
(s.year == now.get(Calendar.YEAR) && s.month >= now.get(Calendar.MONTH))
else -> true
}
}
/** True when the shown window is at/before the first logged play — caps stepping backwards. */
fun atStart(): Boolean {
val s = _state.value
val first = s.firstPlayedAt ?: return false
val c = Calendar.getInstance().apply { timeInMillis = first * 1000 }
val fy = c.get(Calendar.YEAR)
val fm = c.get(Calendar.MONTH)
return when (s.view) {
StatsView.YEAR -> s.year <= fy
StatsView.MONTH -> s.year < fy || (s.year == fy && s.month <= fm)
else -> false
}
}
private fun startOf(year: Int, month: Int, day: Int): Long {
val c = Calendar.getInstance().apply {
clear()
set(year, month, day, 0, 0, 0)
}
return c.timeInMillis / 1000
}
private fun range(): Triple<Long, Long, String> {
val s = _state.value
val nowSec = System.currentTimeMillis() / 1000
return when (s.view) {
StatsView.ALL -> Triple(0L, nowSec + 1, "month")
StatsView.YEAR -> Triple(startOf(s.year, 0, 1), startOf(s.year + 1, 0, 1), "month")
StatsView.MONTH -> Triple(startOf(s.year, s.month, 1), startOf(s.year, s.month + 1, 1), "day")
}
}
private fun load() {
viewModelScope.launch {
_state.value = _state.value.copy(loading = true, error = null)
val settings = repo.appSettingsFlow().first()
if (settings.scrobbleUrl.isBlank()) {
_state.value = _state.value.copy(loading = false, configured = false)
return@launch
}
val (from, to, bucket) = range()
val tz = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000
val stats = repo.fetchScrobbleStats(from, to, tz, bucket, 10)
_state.value = if (stats == null)
_state.value.copy(loading = false, error = "Scrobble-Dienst nicht erreichbar")
else
_state.value.copy(
loading = false, configured = true, stats = stats,
// Keep the earliest-play bound once known (a windowed query may return null for it).
firstPlayedAt = stats.firstPlayedAt ?: _state.value.firstPlayedAt,
)
}
}
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:pivotX="12"
android:scaleX="-1">
<path
android:fillColor="#FFFFFF"
android:pathData="M12,5L12,1L7,6L12,11L12,7C15.31,7 18,9.69 18,13C18,16.31 15.31,19 12,19C8.69,19 6,16.31 6,13L4,13C4,17.42 7.58,21 12,21C16.42,21 20,17.42 20,13C20,8.58 16.42,5 12,5Z"/>
</group>
</vector>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#FFFFFF" android:pathData="M6,19h4L10,5H6v14zM14,5v14h4L18,5h-4z"/>
</vector>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#FFFFFF" android:pathData="M8,5.14v14l11,-7z"/>
</vector>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M12,5L12,1L7,6L12,11L12,7C15.31,7 18,9.69 18,13C18,16.31 15.31,19 12,19C8.69,19 6,16.31 6,13L4,13C4,17.42 7.58,21 12,21C16.42,21 20,17.42 20,13C20,8.58 16.42,5 12,5Z"/>
</vector>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M6,6 L14.5,12 L6,18 Z M16,6 L18,6 L18,18 L16,18 Z"/>
</vector>
Loaded 100 of 179 files, more files were not shown because too many files have changed in this diff. Show more