Compare commits
17
Commits
@@ -1,6 +1,6 @@
|
|||||||
# Playtube für Android
|
# Playtube für Android
|
||||||
|
|
||||||
Android-Version von [Playtube](https://git.fojadrachi.de/Fojadrachi/Playtube) – **nur YouTube Music**,
|
Android-Version von [Playtube](https://github.com/fojadrachi/Playtube) – **nur YouTube Music**,
|
||||||
mit Hintergrundwiedergabe und Discord Rich Presence. Ohne YouTube-Tab und ohne Stream-Dock-Fernsteuerung.
|
mit Hintergrundwiedergabe und Discord Rich Presence. Ohne YouTube-Tab und ohne Stream-Dock-Fernsteuerung.
|
||||||
|
|
||||||
- **YouTube Music in der App** (`music.youtube.com` in einer WebView), Anmeldung mit deinem
|
- **YouTube Music in der App** (`music.youtube.com` in einer WebView), Anmeldung mit deinem
|
||||||
@@ -15,6 +15,29 @@ mit Hintergrundwiedergabe und Discord Rich Presence. Ohne YouTube-Tab und ohne S
|
|||||||
Fortschritt, solange Musik läuft (nicht bei Pause). Nutzt das offizielle Discord Social SDK und
|
Fortschritt, solange Musik läuft (nicht bei Pause). Nutzt das offizielle Discord Social SDK und
|
||||||
braucht die installierte Discord-App auf demselben Handy; es wird nichts angemeldet, und es
|
braucht die installierte Discord-App auf demselben Handy; es wird nichts angemeldet, und es
|
||||||
werden keine Konto-Daten an Playtube gegeben.
|
werden keine Konto-Daten an Playtube gegeben.
|
||||||
|
- **PC steuern** (wie Spotify Connect): Playtube auf dem PC im selben WLAN fernbedienen – Titel,
|
||||||
|
Cover, Play/Pause, Vor/Zurück, Zufall/Wiederholen, Spulen, Lautstärke, Like, Wechsel zwischen
|
||||||
|
YouTube und YouTube Music, dazu **Warteschlange** und **Playlists** (Titel antippen = abspielen;
|
||||||
|
ab Playtube 2.1.0 am PC). Der Bildschirm ist im Spotify-Stil gehalten (Akzent: Playtube-Lila/Pink),
|
||||||
|
die Verbindung bleibt auch im Hintergrund bestehen (Benachrichtigung „Steuert …“ mit Trennen). Erreichbar über den runden Knopf am rechten Rand oder durch langes Drücken aufs
|
||||||
|
App-Icon („PC steuern“). Am PC einmalig in Playtube unter *Einstellungen › Steuerung vom Handy*
|
||||||
|
einschalten und mit dem 6-stelligen Code koppeln (siehe unten).
|
||||||
|
- **Playtube Jam** (wie Spotify Jam): gemeinsam hören, jeder synchron auf dem eigenen Gerät.
|
||||||
|
Über den zweiten runden Knopf am rechten Rand einen Jam starten (der gerade laufende Song wird der
|
||||||
|
erste) oder per Code beitreten; einladen über „Link teilen“. Einladungslinks
|
||||||
|
`https://jam.fojadrachi.de/<CODE>` und `playtube://jam/<CODE>` öffnen direkt die App; YouTube-Links
|
||||||
|
aus anderen Apps über „Teilen › Jam“ hinzufügen – auch ganze Playlists und Alben (Playlist-Link);
|
||||||
|
mehrere Songs laufen automatisch nacheinander. Gespielt wird in der YouTube-Music-Ansicht der App,
|
||||||
|
die sich mit dem Jam abgleicht ([JamSync.kt](app/src/main/java/de/fojadrachi/playtube/JamSync.kt),
|
||||||
|
[JamHub.kt](app/src/main/java/de/fojadrachi/playtube/JamHub.kt)). Mitspielen können Playtube am PC
|
||||||
|
(ab 2.2.0) und Freunde im Browser; der Dienst liegt im Projekt `playtube-jam`.
|
||||||
|
- **Diagnosedaten** (standardmäßig an, abschaltbar über das Zahnrad am rechten Rand; beim ersten
|
||||||
|
Start erscheint ein Hinweis): Abstürze und Verbindungsfehler landen in einem kleinen eigenen Log
|
||||||
|
(`files/diag.log`), das die App kurz nach dem Start höchstens alle 6 Stunden gefiltert an den
|
||||||
|
Playtube-Dienst schickt (`/api/diag` im Projekt `playtube-jam`, 30 Tage gespeichert). Ohne Cookies,
|
||||||
|
Anmeldedaten, Suchanfragen, Songtitel oder Video-IDs
|
||||||
|
([DiagReport.kt](app/src/main/java/de/fojadrachi/playtube/DiagReport.kt),
|
||||||
|
[Diagnostics.kt](app/src/main/java/de/fojadrachi/playtube/Diagnostics.kt)).
|
||||||
- **Links** zu `music.youtube.com` öffnen sich in Playtube.
|
- **Links** zu `music.youtube.com` öffnen sich in Playtube.
|
||||||
- **Updates** aus den eigenen Releases (Tag `vX.Y.Z-android`), kein GitHub, kein Play Store.
|
- **Updates** aus den eigenen Releases (Tag `vX.Y.Z-android`), kein GitHub, kein Play Store.
|
||||||
|
|
||||||
@@ -28,6 +51,23 @@ Voraussetzungen: Android 8.0 (API 26) oder neuer, aktuelles „Android System We
|
|||||||
(„Unbekannte Apps installieren") – erlauben.
|
(„Unbekannte Apps installieren") – erlauben.
|
||||||
3. Beim ersten Start Benachrichtigungen erlauben (für die Steuerung auf dem Sperrbildschirm).
|
3. Beim ersten Start Benachrichtigungen erlauben (für die Steuerung auf dem Sperrbildschirm).
|
||||||
|
|
||||||
|
### PC steuern einrichten
|
||||||
|
|
||||||
|
1. Am PC in Playtube (ab Version 2.0.0) *Einstellungen › Steuerung vom Handy* einschalten und
|
||||||
|
speichern. Windows fragt einmalig nach der Firewall – für **private Netzwerke** erlauben.
|
||||||
|
2. Am Handy auf den runden Knopf am rechten Rand tippen. Die App sucht Playtube-PCs im WLAN
|
||||||
|
(UDP-Broadcast an Port 47812); wird keiner gefunden, die am PC angezeigte IP-Adresse eingeben.
|
||||||
|
3. Am PC „Handy koppeln“ wählen und den 6-stelligen Code am Handy eingeben. Danach verbindet sich
|
||||||
|
die App mit diesem PC ohne Code.
|
||||||
|
|
||||||
|
Die Verbindung hält ein Vordergrunddienst (`PcRemoteService`): Sie bleibt, wenn du den Bildschirm
|
||||||
|
verlässt, fragt dann nur alle 4 s den Stand ab und verbindet sich nach einem Abbruch bis zu 5-mal neu.
|
||||||
|
Beendet wird sie über „Trennen“ (App oder Benachrichtigung). Die Wiedergabe auf dem Handy bleibt unberührt.
|
||||||
|
|
||||||
|
Verbindung: TCP-Port 47811 im lokalen Netz, unverschlüsselt (wie im Heimnetz üblich); der PC nimmt
|
||||||
|
nur Geräte aus privaten Netzen an und nur nach Kopplung. Das Gegenstück am PC ist
|
||||||
|
`playtube/lan_remote.py`.
|
||||||
|
|
||||||
Bei Akku-Optimierung des Herstellers (Xiaomi, Samsung, …) Playtube dort von der Optimierung
|
Bei Akku-Optimierung des Herstellers (Xiaomi, Samsung, …) Playtube dort von der Optimierung
|
||||||
ausnehmen, sonst beendet Android die Hintergrundwiedergabe manchmal.
|
ausnehmen, sonst beendet Android die Hintergrundwiedergabe manchmal.
|
||||||
|
|
||||||
@@ -89,7 +129,9 @@ von Playtube fragen ein anderes Repo ab und sehen sie nie.
|
|||||||
| `NowPlaying.kt` | Datensatz „läuft gerade" |
|
| `NowPlaying.kt` | Datensatz „läuft gerade" |
|
||||||
| `UpdateChecker.kt` | Update-Prüfung über die Gitea-Releases |
|
| `UpdateChecker.kt` | Update-Prüfung über die Gitea-Releases |
|
||||||
| `DiscordPresence.kt`, `PresencePlan.kt`, `cpp/` | Discord Rich Presence: was angezeigt wird, und die Brücke zum SDK |
|
| `DiscordPresence.kt`, `PresencePlan.kt`, `cpp/` | Discord Rich Presence: was angezeigt wird, und die Brücke zum SDK |
|
||||||
|
| `Diagnostics.kt`, `DiagReport.kt` | Diagnose-Log, Absturz-Handler, Filter und Versand an `/api/diag` |
|
||||||
| `UserAgent.kt` | macht die WebView-Kennung zu einer normalen Chrome-Kennung (Google-Anmeldung) |
|
| `UserAgent.kt` | macht die WebView-Kennung zu einer normalen Chrome-Kennung (Google-Anmeldung) |
|
||||||
|
| `PcRemote.kt`, `PcSession.kt`, `PcRemoteService.kt`, `PcRemoteActivity.kt`, `ImageCache.kt` | „PC steuern“: Protokoll, dauerhafte Verbindung (Vordergrunddienst), Fernbedienung, Cover-Cache |
|
||||||
|
|
||||||
## Bekannte Grenzen
|
## Bekannte Grenzen
|
||||||
|
|
||||||
@@ -104,3 +146,13 @@ von Playtube fragen ein anderes Repo ab und sehen sie nie.
|
|||||||
App-Aktivität).
|
App-Aktivität).
|
||||||
- Kein Like-/Wiederholen-/Zufalls-Knopf in der Benachrichtigung; die Bedienung der Seite selbst
|
- Kein Like-/Wiederholen-/Zufalls-Knopf in der Benachrichtigung; die Bedienung der Seite selbst
|
||||||
funktioniert normal.
|
funktioniert normal.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## English
|
||||||
|
|
||||||
|
**Diagnostics** (on by default, can be turned off via the gear button on the right edge; a notice is
|
||||||
|
shown on first start): crashes and connection errors are written to a small app log
|
||||||
|
(`files/diag.log`) that the app sends, filtered, to the Playtube service (`/api/diag` in the
|
||||||
|
`playtube-jam` project) shortly after start and at most every 6 hours. Reports are kept for 30 days.
|
||||||
|
No cookies, sign-in data, searches, song titles or video IDs are sent.
|
||||||
|
|||||||
@@ -19,12 +19,14 @@ android {
|
|||||||
applicationId = "de.fojadrachi.playtube"
|
applicationId = "de.fojadrachi.playtube"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 2
|
versionCode = 12
|
||||||
versionName = "1.1.0"
|
versionName = "1.7.0"
|
||||||
|
|
||||||
// Update-Quelle: eigener Gitea-Server (kein GitHub/Google Play).
|
// Update-Quelle: eigener Gitea-Server (kein GitHub/Google Play).
|
||||||
buildConfigField("String", "UPDATE_SERVER", "\"https://git.fojadrachi.de\"")
|
buildConfigField("String", "UPDATE_SERVER", "\"https://git.fojadrachi.de\"")
|
||||||
buildConfigField("String", "REPO_SLUG", "\"Fojadrachi/Playtube-Android\"")
|
buildConfigField("String", "REPO_SLUG", "\"Fojadrachi/Playtube-Android\"")
|
||||||
|
// Playtube Jam: eigener Dienst (Ordner playtube-jam, Cloudflare Worker).
|
||||||
|
buildConfigField("String", "JAM_SERVER", "\"https://jam.fojadrachi.de\"")
|
||||||
// Discord-Anwendung von Playtube (gleiche wie in der Desktop-Version; die ID ist oeffentlich).
|
// Discord-Anwendung von Playtube (gleiche wie in der Desktop-Version; die ID ist oeffentlich).
|
||||||
buildConfigField("long", "DISCORD_APPLICATION_ID", "1548023494976086127L")
|
buildConfigField("long", "DISCORD_APPLICATION_ID", "1548023494976086127L")
|
||||||
|
|
||||||
@@ -78,6 +80,9 @@ dependencies {
|
|||||||
implementation("androidx.appcompat:appcompat:1.7.0")
|
implementation("androidx.appcompat:appcompat:1.7.0")
|
||||||
implementation("androidx.webkit:webkit:1.12.1")
|
implementation("androidx.webkit:webkit:1.12.1")
|
||||||
implementation("androidx.media:media:1.7.0")
|
implementation("androidx.media:media:1.7.0")
|
||||||
|
implementation("androidx.palette:palette:1.0.0")
|
||||||
|
// Playtube Jam: WebSocket zum Jam-Server.
|
||||||
|
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||||
// Discord Social SDK (Rich Presence): nicht im Repo, siehe README "Discord-SDK".
|
// Discord Social SDK (Rich Presence): nicht im Repo, siehe README "Discord-SDK".
|
||||||
implementation(files("../libs/discord_partner_sdk.aar"))
|
implementation(files("../libs/discord_partner_sdk.aar"))
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
<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" />
|
||||||
|
<!-- "PC steuern" bleibt im Hintergrund verbunden (PcRemoteService). -->
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||||
|
|
||||||
<!-- Das Discord-SDK bringt Sprach-Berechtigungen und eine Login-Activity mit; Playtube nutzt
|
<!-- Das Discord-SDK bringt Sprach-Berechtigungen und eine Login-Activity mit; Playtube nutzt
|
||||||
nur die Rich Presence und braucht davon nichts. -->
|
nur die Rich Presence und braucht davon nichts. -->
|
||||||
@@ -35,6 +38,10 @@
|
|||||||
<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>
|
||||||
|
<!-- Langes Druecken aufs App-Icon: "PC steuern". -->
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.shortcuts"
|
||||||
|
android:resource="@xml/shortcuts" />
|
||||||
<!-- Geteilte/angetippte YouTube-Music-Links oeffnen sich in Playtube. -->
|
<!-- Geteilte/angetippte YouTube-Music-Links oeffnen sich in Playtube. -->
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
@@ -44,6 +51,48 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<!-- Playtube auf dem PC im selben WLAN steuern (PcRemote.kt). -->
|
||||||
|
<activity
|
||||||
|
android:name=".PcRemoteActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/pc_title"
|
||||||
|
android:launchMode="singleTop"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboardHidden|keyboard|uiMode"
|
||||||
|
android:windowSoftInputMode="adjustResize" />
|
||||||
|
|
||||||
|
<!-- Playtube Jam: Einladungslinks (App-Link jam.fojadrachi.de, playtube://jam/<CODE>) und
|
||||||
|
"Teilen" von YouTube-Links aus anderen Apps (fuegt sie zum laufenden Jam hinzu). -->
|
||||||
|
<activity
|
||||||
|
android:name=".JamActivity"
|
||||||
|
android:exported="true"
|
||||||
|
android:label="@string/jam_title"
|
||||||
|
android:launchMode="singleTop"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboardHidden|keyboard|uiMode"
|
||||||
|
android:windowSoftInputMode="adjustResize">
|
||||||
|
<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="jam.fojadrachi.de" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<data android:scheme="playtube" android:host="jam" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter android:label="@string/jam_title">
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name=".PcRemoteService"
|
||||||
|
android:exported="false"
|
||||||
|
android:foregroundServiceType="connectedDevice" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".PlaybackService"
|
android:name=".PlaybackService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ Java_de_fojadrachi_playtube_DiscordPresence_nativeUpdate(JNIEnv* env, jobject, j
|
|||||||
|
|
||||||
discordpp::Activity activity;
|
discordpp::Activity activity;
|
||||||
activity.SetType(discordpp::ActivityTypes::Listening);
|
activity.SetType(discordpp::ActivityTypes::Listening);
|
||||||
|
// Statuszeile "Hoert <Titel> zu" statt des Namens der Discord-Anwendung.
|
||||||
|
activity.SetStatusDisplayType(discordpp::StatusDisplayTypes::Details);
|
||||||
activity.SetDetails(textOrNone(toString(env, details)));
|
activity.SetDetails(textOrNone(toString(env, details)));
|
||||||
activity.SetState(textOrNone(toString(env, state)));
|
activity.SetState(textOrNone(toString(env, state)));
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import org.json.JSONArray
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reine Logik fuer Diagnoseberichte (ohne Android, mit Unit-Tests): Logzeilen filtern und
|
||||||
|
* den Bericht fuer `POST /api/diag` (playtube-jam) bauen. Versand und Log-Datei: [Diagnostics].
|
||||||
|
*
|
||||||
|
* Nicht gesendet werden Cookies, Tokens, Anmeldedaten, Suchanfragen, Songtitel, Video-IDs,
|
||||||
|
* E-Mail-Adressen und URL-Parameter.
|
||||||
|
*/
|
||||||
|
object DiagReport {
|
||||||
|
const val MAX_LINES = 300
|
||||||
|
const val MAX_LINE_CHARS = 480
|
||||||
|
|
||||||
|
private val COOKIE = Regex("(?i)\\b(cookie|set-cookie|authorization)\\b.*")
|
||||||
|
private val BEARER = Regex("(?i)\\bbearer\\s+\\S+")
|
||||||
|
private val SECRET = Regex("(?i)\\b(\\w*token|\\w*key|secret|password|passwort|sapisid)(\\s*[\"']?\\s*[:=]\\s*[\"']?)[^\\s\"'&,;]+")
|
||||||
|
private val EMAIL = Regex("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}")
|
||||||
|
private val URL_QUERY = Regex("(?i)(https?://[^\\s?#\"']+)[?#][^\\s\"']*")
|
||||||
|
private val WORD = Regex("[A-Za-z0-9_-]+")
|
||||||
|
private val JSON_PRIVATE = Regex("(?i)(\"(?:title|artist|author|album|name|query|q|search)\"\\s*:\\s*)\"(?:[^\"\\\\]|\\\\.)*\"")
|
||||||
|
private val CAMEL = Regex("^([A-Z][a-z]+)+$")
|
||||||
|
private val CONTROL = Regex("[\\u0000-\\u0008\\u000b-\\u001f\\u007f\\u202a-\\u202e\\u2066-\\u2069]")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* YouTube-Video-ID: 11 Zeichen aus `[A-Za-z0-9_-]`, entweder Buchstaben plus Ziffer/`_`/`-` oder
|
||||||
|
* mindestens zwei Grossbuchstaben ohne normale Schreibweise (nicht "Verbindunge", "ServerError").
|
||||||
|
*/
|
||||||
|
fun looksLikeVideoId(word: String): Boolean {
|
||||||
|
if (word.length != 11 || !word.all { it in 'A'..'Z' || it in 'a'..'z' || it in '0'..'9' || it == '_' || it == '-' }) return false
|
||||||
|
val letters = word.any { it.isLetter() }
|
||||||
|
if (word.any { it.isDigit() || it == '_' || it == '-' }) return letters
|
||||||
|
return word.count { it in 'A'..'Z' } >= 2 && word.any { it in 'a'..'z' } && !CAMEL.matches(word)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun looksLikeSecret(word: String): Boolean =
|
||||||
|
word.length >= 20 && word.any { it.isDigit() } && word.any { it.isLetter() }
|
||||||
|
|
||||||
|
fun sanitize(line: String): String {
|
||||||
|
var text = CONTROL.replace(line, " ")
|
||||||
|
text = COOKIE.replace(text) { "${it.groupValues[1].lowercase()} [entfernt]" }
|
||||||
|
text = BEARER.replace(text, "Bearer [entfernt]")
|
||||||
|
text = SECRET.replace(text) { "${it.groupValues[1]}${it.groupValues[2]}[entfernt]" }
|
||||||
|
text = EMAIL.replace(text, "[e-mail]")
|
||||||
|
text = URL_QUERY.replace(text) { "${it.groupValues[1]}?[…]" }
|
||||||
|
text = JSON_PRIVATE.replace(text) { "${it.groupValues[1]}\"[entfernt]\"" }
|
||||||
|
text = WORD.replace(text) {
|
||||||
|
when {
|
||||||
|
looksLikeVideoId(it.value) -> "[video]"
|
||||||
|
looksLikeSecret(it.value) -> "[id]"
|
||||||
|
else -> it.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return text.trim().take(MAX_LINE_CHARS)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Collected(val lines: List<String>, val latest: Long)
|
||||||
|
|
||||||
|
/** Zeilen `[secs] text` nach `since` (Unix-Sekunden), gefiltert, hoechstens [MAX_LINES] neueste. */
|
||||||
|
fun collect(logText: String, since: Long): Collected {
|
||||||
|
var latest = since
|
||||||
|
val lines = ArrayList<String>()
|
||||||
|
for (raw in logText.lineSequence()) {
|
||||||
|
if (!raw.startsWith("[")) continue
|
||||||
|
val end = raw.indexOf("] ")
|
||||||
|
if (end < 0) continue
|
||||||
|
val secs = raw.substring(1, end).toLongOrNull() ?: continue
|
||||||
|
if (secs <= since) continue
|
||||||
|
latest = maxOf(latest, secs)
|
||||||
|
lines += "[$secs] ${sanitize(raw.substring(end + 2))}"
|
||||||
|
}
|
||||||
|
return Collected(lines.takeLast(MAX_LINES), latest)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isError(line: String): Boolean {
|
||||||
|
val lower = line.lowercase()
|
||||||
|
return listOf("absturz", "exception", "error", "fehler", "fehlgeschlagen", "failed").any { it in lower }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Vermerk zum Bericht: manuell gesendet (ggf. ohne neue Einträge) oder leer. */
|
||||||
|
fun note(manual: Boolean, noNewLines: Boolean): String = when {
|
||||||
|
manual && noNewLines -> "manuell gesendet (keine neuen Einträge)"
|
||||||
|
manual -> "manuell gesendet"
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun build(installId: String, version: String, androidVersion: String, device: String, lines: List<String>, note: String = ""): JSONObject =
|
||||||
|
JSONObject()
|
||||||
|
.put("app", "android")
|
||||||
|
.put("version", version)
|
||||||
|
.put("platform", "android-$androidVersion")
|
||||||
|
.put("os", device)
|
||||||
|
.put("installId", installId)
|
||||||
|
.put("lines", JSONArray(lines))
|
||||||
|
.put("errors", JSONArray(lines.filter(::isError)))
|
||||||
|
.put("note", note)
|
||||||
|
.put("includesTitles", false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import java.io.File
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
import java.net.URL
|
||||||
|
import java.security.SecureRandom
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diagnosedaten: kleines eigenes Log (Abstuerze, Verbindungsfehler) in `files/diag.log`, das
|
||||||
|
* Playtube kurz nach dem Start und hoechstens alle 6 Stunden an den Playtube-Server schickt
|
||||||
|
* (`POST /api/diag`). Standardmaessig an, abschaltbar im Einstellungsdialog.
|
||||||
|
*/
|
||||||
|
object Diagnostics {
|
||||||
|
private const val PREFS = "playtube"
|
||||||
|
private const val KEY_ENABLED = "diag_enabled"
|
||||||
|
private const val KEY_INSTALL_ID = "diag_install_id"
|
||||||
|
private const val KEY_LAST_SENT = "diag_last_sent"
|
||||||
|
private const val KEY_LAST_TRY = "diag_last_try"
|
||||||
|
private const val KEY_NOTICE = "diag_notice_shown"
|
||||||
|
private const val MAX_LOG_BYTES = 256 * 1024
|
||||||
|
private const val INTERVAL_MS = 6 * 3600 * 1000L
|
||||||
|
private const val TIMEOUT_MS = 10_000
|
||||||
|
|
||||||
|
private var appContext: Context? = null
|
||||||
|
private val main = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
|
fun init(context: Context) {
|
||||||
|
if (appContext != null) return
|
||||||
|
appContext = context.applicationContext
|
||||||
|
val previous = Thread.getDefaultUncaughtExceptionHandler()
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler { thread, error ->
|
||||||
|
// Absturz sofort ins Log - gesendet wird beim naechsten Start.
|
||||||
|
line("Absturz in ${thread.name}: ${error.stackTraceToString().take(3000)}")
|
||||||
|
previous?.uncaughtException(thread, error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun prefs(context: Context) = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
fun isEnabled(context: Context): Boolean = prefs(context).getBoolean(KEY_ENABLED, true)
|
||||||
|
|
||||||
|
fun setEnabled(context: Context, enabled: Boolean) {
|
||||||
|
prefs(context).edit().putBoolean(KEY_ENABLED, enabled).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Einmaliger Hinweis, dass Diagnosedaten gesendet werden (Opt-out). */
|
||||||
|
fun needsNotice(context: Context): Boolean = !prefs(context).getBoolean(KEY_NOTICE, false)
|
||||||
|
|
||||||
|
fun noticeShown(context: Context) {
|
||||||
|
prefs(context).edit().putBoolean(KEY_NOTICE, true).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun installId(context: Context): String {
|
||||||
|
val prefs = prefs(context)
|
||||||
|
prefs.getString(KEY_INSTALL_ID, null)?.takeIf { it.isNotBlank() }?.let { return it }
|
||||||
|
val bytes = ByteArray(12).also { SecureRandom().nextBytes(it) }
|
||||||
|
val id = bytes.joinToString("") { "%02x".format(it) }
|
||||||
|
prefs.edit().putString(KEY_INSTALL_ID, id).apply()
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun logFile(context: Context) = File(context.filesDir, "diag.log")
|
||||||
|
|
||||||
|
/** Zeile ins Diagnose-Log schreiben (thread-sicher, auch ohne Versand-Erlaubnis lokal). */
|
||||||
|
@Synchronized
|
||||||
|
fun line(text: String) {
|
||||||
|
val context = appContext ?: return
|
||||||
|
runCatching {
|
||||||
|
val file = logFile(context)
|
||||||
|
if (file.length() > MAX_LOG_BYTES) {
|
||||||
|
// Aeltere Haelfte verwerfen.
|
||||||
|
val keep = file.readText().takeLast(MAX_LOG_BYTES / 2)
|
||||||
|
file.writeText(keep.substring(keep.indexOf('\n') + 1))
|
||||||
|
}
|
||||||
|
file.appendText("[${System.currentTimeMillis() / 1000}] ${text.replace('\n', ' ')}\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Automatisch senden (Start): nur wenn an, neue Zeilen da und der letzte Versuch >= 6 h her ist. */
|
||||||
|
fun sendIfDue(context: Context) {
|
||||||
|
if (!isEnabled(context)) return
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
if (now - prefs(context).getLong(KEY_LAST_TRY, 0) < INTERVAL_MS) return
|
||||||
|
send(context, manual = false) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Senden; [done] bekommt (null = nichts Neues, true/false = Erfolg) auf dem Hauptthread.
|
||||||
|
* [manual] ("Jetzt senden"): geht auch ohne neue Logzeilen raus, dann mit dem Vermerk
|
||||||
|
* "manuell gesendet" (Version, Gerät und Kennung reichen zum Prüfen).
|
||||||
|
*/
|
||||||
|
fun send(context: Context, manual: Boolean, done: (Boolean?) -> Unit) {
|
||||||
|
val ctx = context.applicationContext
|
||||||
|
Thread {
|
||||||
|
val prefs = prefs(ctx)
|
||||||
|
val text = runCatching { logFile(ctx).readText() }.getOrDefault("")
|
||||||
|
val collected = DiagReport.collect(text, prefs.getLong(KEY_LAST_SENT, 0))
|
||||||
|
if (collected.lines.isEmpty() && !manual) {
|
||||||
|
main.post { done(null) }
|
||||||
|
return@Thread
|
||||||
|
}
|
||||||
|
prefs.edit().putLong(KEY_LAST_TRY, System.currentTimeMillis()).apply()
|
||||||
|
val body = DiagReport.build(
|
||||||
|
installId(ctx),
|
||||||
|
BuildConfig.VERSION_NAME,
|
||||||
|
Build.VERSION.RELEASE ?: "?",
|
||||||
|
"${Build.MANUFACTURER} ${Build.MODEL}".take(80),
|
||||||
|
collected.lines,
|
||||||
|
DiagReport.note(manual, collected.lines.isEmpty()),
|
||||||
|
)
|
||||||
|
val ok = post("${BuildConfig.JAM_SERVER}/api/diag", body.toString())
|
||||||
|
if (ok) prefs.edit().putLong(KEY_LAST_SENT, collected.latest).apply()
|
||||||
|
main.post { done(ok) }
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun post(url: String, json: String): Boolean =
|
||||||
|
try {
|
||||||
|
val connection = URL(url).openConnection() as HttpURLConnection
|
||||||
|
connection.connectTimeout = TIMEOUT_MS
|
||||||
|
connection.readTimeout = TIMEOUT_MS
|
||||||
|
connection.requestMethod = "POST"
|
||||||
|
connection.doOutput = true
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json")
|
||||||
|
connection.setRequestProperty("User-Agent", "Playtube-Android/${BuildConfig.VERSION_NAME}")
|
||||||
|
try {
|
||||||
|
connection.outputStream.use { it.write(json.toByteArray()) }
|
||||||
|
connection.responseCode == HttpURLConnection.HTTP_OK
|
||||||
|
} finally {
|
||||||
|
connection.disconnect()
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.util.LruCache
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
import java.net.URL
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
|
/** Laedt Cover im Hintergrund und haelt die letzten in einem kleinen Speicher-Cache (~12 MB). */
|
||||||
|
object ImageCache {
|
||||||
|
private const val MAX_BYTES = 4 * 1024 * 1024 * 3
|
||||||
|
private const val MAX_DOWNLOAD = 4 * 1024 * 1024
|
||||||
|
|
||||||
|
private val cache = object : LruCache<String, Bitmap>(MAX_BYTES) {
|
||||||
|
override fun sizeOf(key: String, value: Bitmap) = value.byteCount
|
||||||
|
}
|
||||||
|
private val executor = Executors.newFixedThreadPool(3)
|
||||||
|
private val main = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
|
fun cached(url: String, maxPx: Int): Bitmap? = cache.get(key(url, maxPx))
|
||||||
|
|
||||||
|
/** Ruft [done] auf dem Hauptthread auf (mit null, wenn das Bild nicht geladen werden konnte). */
|
||||||
|
fun load(url: String, maxPx: Int, done: (Bitmap?) -> Unit) {
|
||||||
|
if (!url.startsWith("https://")) {
|
||||||
|
done(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cached(url, maxPx)?.let {
|
||||||
|
done(it)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
executor.execute {
|
||||||
|
val bitmap = download(url, maxPx)
|
||||||
|
if (bitmap != null) cache.put(key(url, maxPx), bitmap)
|
||||||
|
main.post { done(bitmap) }
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
done(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun key(url: String, maxPx: Int) = "$maxPx|$url"
|
||||||
|
|
||||||
|
private fun download(url: String, maxPx: Int): Bitmap? =
|
||||||
|
try {
|
||||||
|
val connection = URL(url).openConnection() as HttpURLConnection
|
||||||
|
connection.connectTimeout = 8_000
|
||||||
|
connection.readTimeout = 8_000
|
||||||
|
val bytes = try {
|
||||||
|
connection.inputStream.use { it.readNBytesLimited(MAX_DOWNLOAD) }
|
||||||
|
} finally {
|
||||||
|
connection.disconnect()
|
||||||
|
}
|
||||||
|
val bounds = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
||||||
|
BitmapFactory.decodeByteArray(bytes, 0, bytes.size, bounds)
|
||||||
|
val options = BitmapFactory.Options().apply { inSampleSize = sampleSize(bounds.outWidth, bounds.outHeight, maxPx) }
|
||||||
|
BitmapFactory.decodeByteArray(bytes, 0, bytes.size, options)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun java.io.InputStream.readNBytesLimited(limit: Int): ByteArray {
|
||||||
|
val out = java.io.ByteArrayOutputStream()
|
||||||
|
val buffer = ByteArray(16 * 1024)
|
||||||
|
while (true) {
|
||||||
|
val read = read(buffer)
|
||||||
|
if (read < 0) break
|
||||||
|
out.write(buffer, 0, read)
|
||||||
|
if (out.size() > limit) throw java.io.IOException("Bild zu gross")
|
||||||
|
}
|
||||||
|
return out.toByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Groesster Faktor (Zweierpotenz), bei dem die Seiten noch mindestens [maxPx] Pixel haben. */
|
||||||
|
fun sampleSize(width: Int, height: Int, maxPx: Int): Int {
|
||||||
|
var sample = 1
|
||||||
|
val side = minOf(width, height)
|
||||||
|
while (maxPx > 0 && side / (sample * 2) >= maxPx) sample *= 2
|
||||||
|
return sample
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,411 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import android.content.ClipData
|
||||||
|
import android.content.ClipboardManager
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.inputmethod.EditorInfo
|
||||||
|
import android.widget.Button
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.ImageButton
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.SeekBar
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.widget.SwitchCompat
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Playtube Jam: starten, beitreten (auch ueber Einladungslinks), Warteschlange, Teilnehmer.
|
||||||
|
* Abgespielt wird in der WebView von [MainActivity]; Verbindung und Zustand haelt [JamHub].
|
||||||
|
*/
|
||||||
|
class JamActivity : AppCompatActivity() {
|
||||||
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
private lateinit var status: TextView
|
||||||
|
private lateinit var setup: View
|
||||||
|
private lateinit var panel: View
|
||||||
|
private lateinit var leave: Button
|
||||||
|
private lateinit var nameInput: EditText
|
||||||
|
private lateinit var codeInput: EditText
|
||||||
|
private lateinit var addInput: EditText
|
||||||
|
private lateinit var addButton: Button
|
||||||
|
private lateinit var seek: SeekBar
|
||||||
|
private lateinit var allControl: SwitchCompat
|
||||||
|
private var seeking = false
|
||||||
|
/** Per "Teilen" empfangenes Video, solange noch kein Jam laeuft. */
|
||||||
|
private var pendingVideoId: String? = null
|
||||||
|
private var results: List<JamHub.SearchResult> = emptyList()
|
||||||
|
|
||||||
|
private val listener: () -> Unit = { render() }
|
||||||
|
private val ticker = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
renderProgress()
|
||||||
|
handler.postDelayed(this, 500)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
JamHub.init(this)
|
||||||
|
setContentView(R.layout.activity_jam)
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.jamRoot)) { view, insets ->
|
||||||
|
val space = insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime())
|
||||||
|
view.setPadding(space.left, space.top, space.right, space.bottom)
|
||||||
|
WindowInsetsCompat.CONSUMED
|
||||||
|
}
|
||||||
|
status = findViewById(R.id.jamStatus)
|
||||||
|
setup = findViewById(R.id.jamSetup)
|
||||||
|
panel = findViewById(R.id.jamPanel)
|
||||||
|
leave = findViewById(R.id.jamLeave)
|
||||||
|
nameInput = findViewById(R.id.jamName)
|
||||||
|
codeInput = findViewById(R.id.jamCode)
|
||||||
|
addInput = findViewById(R.id.jamAddInput)
|
||||||
|
addButton = findViewById(R.id.jamAddButton)
|
||||||
|
seek = findViewById(R.id.jamSeek)
|
||||||
|
allControl = findViewById(R.id.jamAllControl)
|
||||||
|
|
||||||
|
nameInput.setText(JamHub.savedName())
|
||||||
|
findViewById<View>(R.id.jamBack).setOnClickListener { finish() }
|
||||||
|
findViewById<View>(R.id.jamStart).setOnClickListener { startJam() }
|
||||||
|
findViewById<View>(R.id.jamJoin).setOnClickListener { joinJam(codeInput.text.toString()) }
|
||||||
|
codeInput.setOnEditorActionListener { _, _, _ -> joinJam(codeInput.text.toString()); true }
|
||||||
|
leave.setOnClickListener { JamHub.leave() }
|
||||||
|
findViewById<View>(R.id.jamPlayPause).setOnClickListener { JamHub.playPause() }
|
||||||
|
findViewById<View>(R.id.jamNext).setOnClickListener { JamHub.send("skip") }
|
||||||
|
findViewById<View>(R.id.jamPrevious).setOnClickListener { JamHub.send("previous") }
|
||||||
|
addButton.setOnClickListener { add() }
|
||||||
|
addInput.setOnEditorActionListener { _, actionId, event ->
|
||||||
|
if (actionId == EditorInfo.IME_ACTION_GO || event?.keyCode == KeyEvent.KEYCODE_ENTER) { add(); true } else false
|
||||||
|
}
|
||||||
|
findViewById<View>(R.id.jamShare).setOnClickListener { share() }
|
||||||
|
findViewById<View>(R.id.jamCopy).setOnClickListener { copy() }
|
||||||
|
findViewById<View>(R.id.jamEnd).setOnClickListener {
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setMessage(R.string.jam_end_confirm)
|
||||||
|
.setPositiveButton(R.string.jam_end) { _, _ -> JamHub.send("end") }
|
||||||
|
.setNegativeButton(R.string.pc_cancel, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
allControl.setOnCheckedChangeListener { button, checked ->
|
||||||
|
if (button.isPressed) JamHub.send("settings", "allControl" to checked)
|
||||||
|
}
|
||||||
|
seek.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||||
|
override fun onProgressChanged(bar: SeekBar, progress: Int, fromUser: Boolean) {}
|
||||||
|
override fun onStartTrackingTouch(bar: SeekBar) { seeking = true }
|
||||||
|
override fun onStopTrackingTouch(bar: SeekBar) {
|
||||||
|
seeking = false
|
||||||
|
JamHub.seekFraction(bar.progress / 1000.0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
handleIntent(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
setIntent(intent)
|
||||||
|
handleIntent(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
JamHub.listeners.add(listener)
|
||||||
|
handler.post(ticker)
|
||||||
|
render()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
JamHub.listeners.remove(listener)
|
||||||
|
handler.removeCallbacks(ticker)
|
||||||
|
super.onStop()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Einladungen und Teilen
|
||||||
|
|
||||||
|
private fun handleIntent(intent: Intent?) {
|
||||||
|
when (intent?.action) {
|
||||||
|
Intent.ACTION_VIEW -> JamSync.normalizeCode(intent.data?.toString())?.let { code ->
|
||||||
|
codeInput.setText(code)
|
||||||
|
if (nameInput.text.isNotBlank()) joinJam(code) else nameInput.requestFocus()
|
||||||
|
}
|
||||||
|
Intent.ACTION_SEND -> {
|
||||||
|
val shared = intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||||
|
val playlistId = JamSync.playlistIdFromSharedText(shared)
|
||||||
|
if (playlistId != null && JamHub.active) {
|
||||||
|
JamHub.addPlaylist(playlistId)
|
||||||
|
Toast.makeText(this, R.string.jam_playlist_adding, Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val videoId = JamSync.videoIdFromSharedText(shared) ?: run {
|
||||||
|
if (playlistId != null) status.setText(R.string.jam_share_no_jam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (JamHub.active) {
|
||||||
|
JamHub.addVideo(videoId)
|
||||||
|
Toast.makeText(this, R.string.jam_added_shared, Toast.LENGTH_SHORT).show()
|
||||||
|
} else {
|
||||||
|
pendingVideoId = videoId
|
||||||
|
status.setText(R.string.jam_share_no_jam)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun takeName(): String? {
|
||||||
|
val name = nameInput.text.toString().trim()
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
status.setText(R.string.jam_status_need_name)
|
||||||
|
nameInput.requestFocus()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startJam() {
|
||||||
|
val name = takeName() ?: return
|
||||||
|
// Erster Song: per "Teilen" empfangen oder das, was gerade in Playtube laeuft.
|
||||||
|
val first = pendingVideoId?.let { JSONObject().put("t", "add").put("videoId", it) }
|
||||||
|
?: JamHub.pageVideo?.let { page ->
|
||||||
|
JSONObject().put("t", "add").put("videoId", page.videoId).put("title", page.title).put("artist", page.artist)
|
||||||
|
}
|
||||||
|
pendingVideoId = null
|
||||||
|
JamHub.start(name, first)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun joinJam(raw: String) {
|
||||||
|
val name = takeName() ?: return
|
||||||
|
JamHub.join(raw, name)
|
||||||
|
pendingVideoId?.let { id -> handler.postDelayed({ if (JamHub.active) JamHub.addVideo(id) }, 2500) }
|
||||||
|
pendingVideoId = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Bedienung
|
||||||
|
|
||||||
|
private fun add() {
|
||||||
|
val text = addInput.text.toString().trim()
|
||||||
|
if (text.isEmpty()) return
|
||||||
|
val videoId = JamSync.parseVideoId(text)
|
||||||
|
val playlistId = if (videoId == null) JamSync.parsePlaylistId(text) else null
|
||||||
|
if (playlistId != null) {
|
||||||
|
JamHub.addPlaylist(playlistId)
|
||||||
|
addInput.setText("")
|
||||||
|
status.setText(R.string.jam_playlist_adding)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (videoId != null) {
|
||||||
|
JamHub.addVideo(videoId)
|
||||||
|
addInput.setText("")
|
||||||
|
status.text = getString(R.string.jam_added, videoId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (JamHub.state?.search != true) {
|
||||||
|
status.setText(R.string.jam_error_bad_video)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
JamHub.search(text) { found ->
|
||||||
|
if (found == null) {
|
||||||
|
status.setText(R.string.jam_error_search)
|
||||||
|
} else {
|
||||||
|
results = found
|
||||||
|
renderResults()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun inviteLink(): String? = JamHub.code?.let { "${JamHub.server}/$it" }
|
||||||
|
|
||||||
|
private fun share() {
|
||||||
|
val link = inviteLink() ?: return
|
||||||
|
val send = Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, getString(R.string.jam_share_text, link))
|
||||||
|
startActivity(Intent.createChooser(send, getString(R.string.jam_invite)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun copy() {
|
||||||
|
val link = inviteLink() ?: return
|
||||||
|
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
|
clipboard.setPrimaryClip(ClipData.newPlainText("Playtube Jam", link))
|
||||||
|
Toast.makeText(this, R.string.jam_copied, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Anzeige
|
||||||
|
|
||||||
|
private fun render() {
|
||||||
|
status.text = JamHub.status
|
||||||
|
val active = JamHub.active
|
||||||
|
setup.visibility = if (active) View.GONE else View.VISIBLE
|
||||||
|
panel.visibility = if (active) View.VISIBLE else View.GONE
|
||||||
|
leave.visibility = if (active) View.VISIBLE else View.GONE
|
||||||
|
if (!active) return
|
||||||
|
val code = JamHub.code ?: return
|
||||||
|
findViewById<TextView>(R.id.jamInviteCode).text = JamSync.prettyCode(code)
|
||||||
|
findViewById<TextView>(R.id.jamInviteLink).text = inviteLink()
|
||||||
|
val state = JamHub.state ?: return
|
||||||
|
|
||||||
|
val item = state.current
|
||||||
|
findViewById<TextView>(R.id.jamNowTitle).text = item?.title ?: getString(R.string.jam_nothing)
|
||||||
|
findViewById<TextView>(R.id.jamNowArtist).text = item?.let { subtitle(it) } ?: ""
|
||||||
|
val cover = findViewById<ImageView>(R.id.jamCover)
|
||||||
|
cover.setImageDrawable(null)
|
||||||
|
item?.thumb?.takeIf { it.startsWith("https://") }?.let { url ->
|
||||||
|
ImageCache.load(url, (96 * resources.displayMetrics.density).toInt()) { bitmap ->
|
||||||
|
if (JamHub.state?.current?.thumb == url) cover.setImageBitmap(bitmap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
findViewById<View>(R.id.jamCantPlay).visibility = if (JamHub.isUnplayable(item?.id)) View.VISIBLE else View.GONE
|
||||||
|
findViewById<ImageButton>(R.id.jamPlayPause).setImageResource(if (state.playback.paused) R.drawable.ic_play else R.drawable.ic_pause)
|
||||||
|
for (id in listOf(R.id.jamPlayPause, R.id.jamNext, R.id.jamPrevious)) {
|
||||||
|
findViewById<View>(id).apply {
|
||||||
|
isEnabled = state.canControl
|
||||||
|
alpha = if (state.canControl) 1f else 0.4f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seek.isEnabled = state.canControl && item != null
|
||||||
|
findViewById<View>(R.id.jamHostBox).visibility = if (state.isHost) View.VISIBLE else View.GONE
|
||||||
|
allControl.isChecked = state.allControl
|
||||||
|
addInput.setHint(if (state.search) R.string.jam_search_hint else R.string.jam_add_hint)
|
||||||
|
addButton.setText(if (state.search) R.string.jam_search else R.string.jam_add)
|
||||||
|
|
||||||
|
val queue = findViewById<LinearLayout>(R.id.jamQueue)
|
||||||
|
queue.removeAllViews()
|
||||||
|
if (state.queue.isEmpty()) queue.addView(emptyText(R.string.jam_queue_empty))
|
||||||
|
for (q in state.queue) {
|
||||||
|
queue.addView(
|
||||||
|
row(
|
||||||
|
q.title, subtitle(q), image = q.thumb, initial = null,
|
||||||
|
action1 = if (state.canControl) R.drawable.ic_play to { JamHub.send("jump", "itemId" to q.id) } else null,
|
||||||
|
action2 = if (state.canControl || q.by == state.you) R.drawable.ic_close to { JamHub.send("remove", "itemId" to q.id) } else null,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val members = findViewById<LinearLayout>(R.id.jamMembers)
|
||||||
|
members.removeAllViews()
|
||||||
|
for (m in state.members) {
|
||||||
|
val info = buildList {
|
||||||
|
if (m.host) add(getString(R.string.jam_host))
|
||||||
|
add(getString(when (m.client) { "pc" -> R.string.jam_client_pc; "android" -> R.string.jam_client_android; else -> R.string.jam_client_web }))
|
||||||
|
if (!m.online) add(getString(R.string.jam_offline))
|
||||||
|
if (m.cantPlay) add(getString(R.string.jam_cant_play))
|
||||||
|
}.joinToString(" · ")
|
||||||
|
val name = if (m.id == state.you) getString(R.string.jam_you, m.name) else m.name
|
||||||
|
val kick = if (state.isHost && m.id != state.you) {
|
||||||
|
R.drawable.ic_close to {
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setMessage(getString(R.string.jam_kick_confirm, m.name))
|
||||||
|
.setPositiveButton(R.string.jam_kick) { _, _ -> JamHub.send("kick", "memberId" to m.id) }
|
||||||
|
.setNegativeButton(R.string.pc_cancel, null)
|
||||||
|
.show()
|
||||||
|
Unit
|
||||||
|
}
|
||||||
|
} else null
|
||||||
|
// Host-Rolle abgeben (nur an jemanden, der gerade verbunden ist).
|
||||||
|
val makeHost = if (state.isHost && m.id != state.you && m.online) {
|
||||||
|
R.drawable.ic_crown to {
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setMessage(getString(R.string.jam_make_host_confirm, m.name))
|
||||||
|
.setPositiveButton(R.string.jam_make_host) { _, _ -> JamHub.send("transfer", "memberId" to m.id) }
|
||||||
|
.setNegativeButton(R.string.pc_cancel, null)
|
||||||
|
.show()
|
||||||
|
Unit
|
||||||
|
}
|
||||||
|
} else null
|
||||||
|
members.addView(row(name, info, image = null, initial = m.name.take(1).uppercase(), action1 = makeHost, action2 = kick).apply {
|
||||||
|
alpha = if (m.online) 1f else 0.5f
|
||||||
|
})
|
||||||
|
}
|
||||||
|
renderProgress()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun renderResults() {
|
||||||
|
val box = findViewById<LinearLayout>(R.id.jamResults)
|
||||||
|
box.removeAllViews()
|
||||||
|
for (r in results) {
|
||||||
|
box.addView(
|
||||||
|
row(
|
||||||
|
r.title, r.artist, image = r.thumb, initial = null,
|
||||||
|
action1 = R.drawable.ic_queue_music to {
|
||||||
|
JamHub.addVideo(r.videoId, r.title, r.artist, r.thumb, next = true)
|
||||||
|
status.text = getString(R.string.jam_added, r.title)
|
||||||
|
},
|
||||||
|
action2 = R.drawable.ic_add to {
|
||||||
|
JamHub.addVideo(r.videoId, r.title, r.artist, r.thumb)
|
||||||
|
status.text = getString(R.string.jam_added, r.title)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun renderProgress() {
|
||||||
|
val state = JamHub.state ?: return
|
||||||
|
val want = JamSync.target(state, JamHub.clock.serverNow(System.currentTimeMillis().toDouble()))
|
||||||
|
val dur = want?.dur ?: JamHub.lastDuration
|
||||||
|
val pos = (want?.pos ?: 0.0).coerceAtLeast(0.0).let { if (dur > 0) it.coerceAtMost(dur) else it }
|
||||||
|
findViewById<TextView>(R.id.jamTime).text = JamSync.formatTime(pos)
|
||||||
|
findViewById<TextView>(R.id.jamDuration).text = JamSync.formatTime(dur)
|
||||||
|
if (!seeking) seek.progress = if (dur > 0) (pos / dur * 1000).toInt() else 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun subtitle(item: JamSync.Item): String {
|
||||||
|
val by = getString(R.string.jam_by, item.byName)
|
||||||
|
return if (item.artist.isBlank()) by else "${item.artist} · $by"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun emptyText(text: Int) = TextView(this).apply {
|
||||||
|
setText(text)
|
||||||
|
setTextColor(getColor(R.color.text_muted))
|
||||||
|
setPadding(0, 12, 0, 12)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun row(
|
||||||
|
title: String,
|
||||||
|
subtitle: String,
|
||||||
|
image: String?,
|
||||||
|
initial: String?,
|
||||||
|
action1: Pair<Int, () -> Unit>?,
|
||||||
|
action2: Pair<Int, () -> Unit>?,
|
||||||
|
): View {
|
||||||
|
val view = LayoutInflater.from(this).inflate(R.layout.item_jam_row, null, false)
|
||||||
|
view.findViewById<TextView>(R.id.jamRowTitle).text = title
|
||||||
|
view.findViewById<TextView>(R.id.jamRowSubtitle).text = subtitle
|
||||||
|
val imageView = view.findViewById<ImageView>(R.id.jamRowImage)
|
||||||
|
val avatar = view.findViewById<TextView>(R.id.jamRowAvatar)
|
||||||
|
if (initial != null) {
|
||||||
|
imageView.visibility = View.GONE
|
||||||
|
avatar.visibility = View.VISIBLE
|
||||||
|
avatar.text = initial
|
||||||
|
} else if (image != null && image.startsWith("https://")) {
|
||||||
|
ImageCache.load(image, (64 * resources.displayMetrics.density).toInt()) { bitmap -> imageView.setImageBitmap(bitmap) }
|
||||||
|
}
|
||||||
|
for ((id, action) in listOf(R.id.jamRowAction1 to action1, R.id.jamRowAction2 to action2)) {
|
||||||
|
val button = view.findViewById<ImageButton>(id)
|
||||||
|
if (action != null) {
|
||||||
|
button.visibility = View.VISIBLE
|
||||||
|
button.setImageResource(action.first)
|
||||||
|
button.setOnClickListener { action.second() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun start(context: Context) {
|
||||||
|
context.startActivity(Intent(context, JamActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun open(context: Context, uri: Uri) {
|
||||||
|
context.startActivity(Intent(Intent.ACTION_VIEW, uri, context, JamActivity::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,491 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.os.SystemClock
|
||||||
|
import okhttp3.Call
|
||||||
|
import okhttp3.Callback
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
import okhttp3.Response
|
||||||
|
import okhttp3.WebSocket
|
||||||
|
import okhttp3.WebSocketListener
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.io.IOException
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Playtube Jam: Verbindung zum Jam-Server und gemeinsamer Zustand fuer [JamActivity] (Anzeige)
|
||||||
|
* und [MainActivity] (spielt in ihrer YouTube-Music-WebView ab). Alles auf dem Hauptthread.
|
||||||
|
*/
|
||||||
|
object JamHub {
|
||||||
|
private const val PREFS = "playtube"
|
||||||
|
private const val KEY_NAME = "jam_name"
|
||||||
|
private const val KEY_CODE = "jam_last_code"
|
||||||
|
private const val KEY_TOKEN = "jam_last_token"
|
||||||
|
/** Spielt ein Titel so lange nicht an, gilt er hier als nicht abspielbar. */
|
||||||
|
private const val STUCK_LIMIT_MS = 15_000L
|
||||||
|
|
||||||
|
val server: String get() = BuildConfig.JAM_SERVER
|
||||||
|
|
||||||
|
private val main = Handler(Looper.getMainLooper())
|
||||||
|
private val http = OkHttpClient.Builder()
|
||||||
|
.connectTimeout(10, TimeUnit.SECONDS)
|
||||||
|
.readTimeout(0, TimeUnit.SECONDS)
|
||||||
|
.pingInterval(20, TimeUnit.SECONDS)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
private var appContext: Context? = null
|
||||||
|
private var socket: WebSocket? = null
|
||||||
|
private var reconnectDelay = 1000L
|
||||||
|
private var pings = 0
|
||||||
|
private var name = ""
|
||||||
|
private var token: String? = null
|
||||||
|
|
||||||
|
var code: String? = null
|
||||||
|
private set
|
||||||
|
var state: JamSync.State? = null
|
||||||
|
private set
|
||||||
|
var status: String = ""
|
||||||
|
private set
|
||||||
|
val clock = JamSync.Clock()
|
||||||
|
|
||||||
|
/** Anzeige (JamActivity) - wird bei jeder Aenderung aufgerufen. */
|
||||||
|
val listeners = LinkedHashSet<() -> Unit>()
|
||||||
|
|
||||||
|
val active: Boolean get() = code != null
|
||||||
|
|
||||||
|
/** Was gerade in Playtube laeuft (von MainActivity) - wird beim Starten der erste Song. */
|
||||||
|
data class PageVideo(val videoId: String, val title: String, val artist: String)
|
||||||
|
var pageVideo: PageVideo? = null
|
||||||
|
|
||||||
|
// Abgleich-Zustand des eigenen Players
|
||||||
|
private val unplayable = HashSet<String>()
|
||||||
|
private val reported = HashSet<String>()
|
||||||
|
private var expectUntil = 0L
|
||||||
|
private var pendingLoad: Pair<String, Long>? = null
|
||||||
|
private var stuckSince: Pair<String, Long>? = null
|
||||||
|
private var diverge = 0
|
||||||
|
/** Song beim Beitreten ("" = keiner) - zaehlt nicht als Wunsch; beim Starten null = noch offen. */
|
||||||
|
private var baseline: String? = null
|
||||||
|
private val picked = HashSet<String>()
|
||||||
|
var lastDuration = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun init(context: Context) {
|
||||||
|
appContext = context.applicationContext
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun prefs() = appContext!!.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
fun savedName(): String = prefs().getString(KEY_NAME, "") ?: ""
|
||||||
|
|
||||||
|
private fun notifyListeners() = listeners.toList().forEach { it() }
|
||||||
|
|
||||||
|
private fun setStatus(text: String) {
|
||||||
|
status = text
|
||||||
|
notifyListeners()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun str(id: Int, vararg args: Any): String = appContext!!.getString(id, *args)
|
||||||
|
|
||||||
|
fun isUnplayable(itemId: String?): Boolean = itemId != null && itemId in unplayable
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Starten, Beitreten, Verlassen
|
||||||
|
|
||||||
|
fun start(displayName: String, firstSong: JSONObject?) {
|
||||||
|
if (active) return
|
||||||
|
rememberName(displayName)
|
||||||
|
setStatus(str(R.string.jam_status_creating))
|
||||||
|
val body = JSONObject().put("name", displayName).put("client", "android").toString()
|
||||||
|
val request = Request.Builder().url("$server/api/jam").post(body.toRequestBody("application/json".toMediaType())).build()
|
||||||
|
http.newCall(request).enqueue(object : Callback {
|
||||||
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
|
Diagnostics.line("jam: Anlegen fehlgeschlagen: $e")
|
||||||
|
main.post { setStatus(str(R.string.jam_status_failed)) }
|
||||||
|
}
|
||||||
|
override fun onResponse(call: Call, response: Response) {
|
||||||
|
val text = response.use {
|
||||||
|
if (!it.isSuccessful) Diagnostics.line("jam: Anlegen fehlgeschlagen: HTTP ${it.code}")
|
||||||
|
if (it.isSuccessful) it.body?.string() else null
|
||||||
|
}
|
||||||
|
main.post {
|
||||||
|
val json = text?.let { runCatching { JSONObject(it) }.getOrNull() }
|
||||||
|
if (json == null) {
|
||||||
|
setStatus(str(R.string.jam_status_failed))
|
||||||
|
} else {
|
||||||
|
connect(json.getString("code"), json.getString("token"))
|
||||||
|
firstSong?.let { send(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun join(rawCode: String, displayName: String) {
|
||||||
|
val joinCode = JamSync.normalizeCode(rawCode)
|
||||||
|
if (joinCode == null) {
|
||||||
|
setStatus(str(R.string.jam_status_bad_code))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (active) {
|
||||||
|
if (code != joinCode) setStatus(str(R.string.jam_status_in_other))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rememberName(displayName)
|
||||||
|
setStatus(str(R.string.jam_status_joining))
|
||||||
|
val request = Request.Builder().url("$server/api/jam/$joinCode").build()
|
||||||
|
http.newCall(request).enqueue(object : Callback {
|
||||||
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
|
Diagnostics.line("jam: Beitreten fehlgeschlagen: $e")
|
||||||
|
main.post { setStatus(str(R.string.jam_status_failed)) }
|
||||||
|
}
|
||||||
|
override fun onResponse(call: Call, response: Response) {
|
||||||
|
val status = response.use { it.code }
|
||||||
|
if (status != 200 && status != 404) Diagnostics.line("jam: Beitreten fehlgeschlagen: HTTP $status")
|
||||||
|
main.post {
|
||||||
|
when (status) {
|
||||||
|
200 -> {
|
||||||
|
val prefs = prefs()
|
||||||
|
val saved = if (prefs.getString(KEY_CODE, null) == joinCode) prefs.getString(KEY_TOKEN, null) else null
|
||||||
|
connect(joinCode, saved)
|
||||||
|
}
|
||||||
|
404 -> setStatus(str(R.string.jam_status_not_found))
|
||||||
|
else -> setStatus(str(R.string.jam_status_failed))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun rememberName(displayName: String) {
|
||||||
|
name = displayName
|
||||||
|
prefs().edit().putString(KEY_NAME, displayName).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun connect(joinCode: String, savedToken: String?) {
|
||||||
|
code = joinCode
|
||||||
|
token = savedToken
|
||||||
|
state = null
|
||||||
|
unplayable.clear()
|
||||||
|
reported.clear()
|
||||||
|
picked.clear()
|
||||||
|
baseline = null
|
||||||
|
pendingLoad = null
|
||||||
|
stuckSince = null
|
||||||
|
prefs().edit().putString(KEY_CODE, joinCode).putString(KEY_TOKEN, savedToken ?: "").apply()
|
||||||
|
openSocket()
|
||||||
|
notifyListeners()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun openSocket() {
|
||||||
|
val joinCode = code ?: return
|
||||||
|
val wsUrl = server.replaceFirst("https://", "wss://").replaceFirst("http://", "ws://") + "/api/jam/$joinCode/ws"
|
||||||
|
socket = http.newWebSocket(Request.Builder().url(wsUrl).build(), object : WebSocketListener() {
|
||||||
|
override fun onOpen(webSocket: WebSocket, response: Response) {
|
||||||
|
main.post {
|
||||||
|
if (socket !== webSocket) return@post
|
||||||
|
reconnectDelay = 1000L
|
||||||
|
val hello = JSONObject().put("t", "hello").put("name", name).put("client", "android")
|
||||||
|
token?.let { hello.put("token", it) }
|
||||||
|
webSocket.send(hello.toString())
|
||||||
|
pings = 0
|
||||||
|
ping()
|
||||||
|
setStatus(str(R.string.jam_status_connected))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMessage(webSocket: WebSocket, text: String) {
|
||||||
|
val receivedAt = System.currentTimeMillis().toDouble()
|
||||||
|
main.post { if (socket === webSocket) handle(text, receivedAt) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
||||||
|
Diagnostics.line("jam: Verbindung fehlgeschlagen: $t")
|
||||||
|
main.post { if (socket === webSocket) lost() }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
|
||||||
|
main.post { if (socket === webSocket) lost() }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private val pingTask = Runnable { ping() }
|
||||||
|
|
||||||
|
private fun ping() {
|
||||||
|
main.removeCallbacks(pingTask)
|
||||||
|
val ws = socket ?: return
|
||||||
|
ws.send(JSONObject().put("t", "ping").put("c", System.currentTimeMillis().toDouble()).toString())
|
||||||
|
pings++
|
||||||
|
main.postDelayed(pingTask, if (pings < 6) 800L else 15_000L)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun lost() {
|
||||||
|
socket = null
|
||||||
|
main.removeCallbacks(pingTask)
|
||||||
|
if (!active) return
|
||||||
|
setStatus(str(R.string.jam_status_reconnecting))
|
||||||
|
main.postDelayed({ if (active && socket == null) openSocket() }, reconnectDelay)
|
||||||
|
reconnectDelay = (reconnectDelay * 2).coerceAtMost(20_000L)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handle(text: String, receivedAt: Double) {
|
||||||
|
val msg = runCatching { JSONObject(text) }.getOrNull() ?: return
|
||||||
|
when (msg.optString("t")) {
|
||||||
|
"pong" -> clock.add(msg.optDouble("c"), msg.optDouble("s"), receivedAt)
|
||||||
|
"welcome" -> {
|
||||||
|
token = msg.optString("token")
|
||||||
|
prefs().edit().putString(KEY_TOKEN, token).apply()
|
||||||
|
}
|
||||||
|
"state" -> {
|
||||||
|
val parsed = JamSync.parseState(msg)
|
||||||
|
clock.hint(parsed.serverNow, System.currentTimeMillis().toDouble())
|
||||||
|
state = parsed
|
||||||
|
notifyListeners()
|
||||||
|
}
|
||||||
|
"ended" -> close(endedText(msg.optString("reason")), forget = true)
|
||||||
|
"error" -> when (val error = msg.optString("error")) {
|
||||||
|
"not_found", "kicked", "full" -> close(endedText(error), forget = true)
|
||||||
|
else -> {
|
||||||
|
Diagnostics.line("jam: Server meldet Fehler $error")
|
||||||
|
setStatus(errorText(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun endedText(reason: String): String = str(
|
||||||
|
when (reason) {
|
||||||
|
"host_ended" -> R.string.jam_ended_host
|
||||||
|
"expired" -> R.string.jam_ended_expired
|
||||||
|
"kicked" -> R.string.jam_ended_kicked
|
||||||
|
"left" -> R.string.jam_ended_left
|
||||||
|
"full" -> R.string.jam_ended_full
|
||||||
|
"not_found" -> R.string.jam_status_not_found
|
||||||
|
else -> R.string.jam_ended_over
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
fun errorText(error: String): String = when (error) {
|
||||||
|
"not_allowed" -> str(R.string.jam_error_not_allowed)
|
||||||
|
"queue_full" -> str(R.string.jam_error_queue_full)
|
||||||
|
"bad_video" -> str(R.string.jam_error_bad_video)
|
||||||
|
"offline" -> str(R.string.jam_error_offline)
|
||||||
|
"playlist_not_found" -> str(R.string.jam_error_playlist)
|
||||||
|
"rate_limited" -> str(R.string.jam_error_rate_limited)
|
||||||
|
else -> str(R.string.jam_error_other, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Jam lokal beenden. */
|
||||||
|
private fun close(message: String, forget: Boolean) {
|
||||||
|
val ws = socket
|
||||||
|
socket = null
|
||||||
|
code = null
|
||||||
|
state = null
|
||||||
|
main.removeCallbacks(pingTask)
|
||||||
|
ws?.close(1000, null)
|
||||||
|
if (forget) prefs().edit().remove(KEY_CODE).remove(KEY_TOKEN).apply()
|
||||||
|
// Den letzten Jam-Titel nicht einfach weiterlaufen lassen.
|
||||||
|
PlaybackHub.send(PlayerCommand.Pause)
|
||||||
|
setStatus(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun leave() {
|
||||||
|
if (!active) return
|
||||||
|
send(JSONObject().put("t", "leave"))
|
||||||
|
main.postDelayed({ if (active) close(str(R.string.jam_ended_left), forget = true) }, 800)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun send(msg: JSONObject) {
|
||||||
|
socket?.send(msg.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun send(type: String, vararg pairs: Pair<String, Any?>) {
|
||||||
|
val msg = JSONObject().put("t", type)
|
||||||
|
for ((k, v) in pairs) msg.put(k, v ?: JSONObject.NULL)
|
||||||
|
send(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun playPause() {
|
||||||
|
val s = state ?: return
|
||||||
|
send(if (s.playback.paused) "play" else "pause")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun seekFraction(fraction: Double) {
|
||||||
|
val dur = state?.current?.dur ?: lastDuration.takeIf { it > 0 } ?: return
|
||||||
|
send("seek", "pos" to Math.round(fraction.coerceIn(0.0, 1.0) * dur).toDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addVideo(videoId: String, title: String? = null, artist: String? = null, thumb: String? = null, next: Boolean = false) {
|
||||||
|
val msg = JSONObject().put("t", "add").put("videoId", videoId).put("next", next)
|
||||||
|
title?.let { msg.put("title", it) }
|
||||||
|
artist?.let { msg.put("artist", it) }
|
||||||
|
thumb?.let { msg.put("thumb", it) }
|
||||||
|
send(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ganze Playlist / ganzes Album: der Jam-Server holt die Songs. */
|
||||||
|
fun addPlaylist(playlistId: String) {
|
||||||
|
send(JSONObject().put("t", "addPlaylist").put("playlistId", playlistId))
|
||||||
|
}
|
||||||
|
|
||||||
|
data class SearchResult(val videoId: String, val title: String, val artist: String, val thumb: String)
|
||||||
|
|
||||||
|
fun search(query: String, done: (List<SearchResult>?) -> Unit) {
|
||||||
|
val url = "$server/api/search".toHttpUrl().newBuilder().addQueryParameter("q", query).build()
|
||||||
|
http.newCall(Request.Builder().url(url).build()).enqueue(object : Callback {
|
||||||
|
override fun onFailure(call: Call, e: IOException) { main.post { done(null) } }
|
||||||
|
override fun onResponse(call: Call, response: Response) {
|
||||||
|
val text = response.use { if (it.isSuccessful) it.body?.string() else null }
|
||||||
|
val results = text?.let {
|
||||||
|
runCatching {
|
||||||
|
val array = JSONObject(it).getJSONArray("results")
|
||||||
|
(0 until array.length()).map { i ->
|
||||||
|
val o = array.getJSONObject(i)
|
||||||
|
SearchResult(o.optString("videoId"), o.optString("title"), o.optString("artist"), o.optString("thumb"))
|
||||||
|
}
|
||||||
|
}.getOrNull()
|
||||||
|
}
|
||||||
|
main.post { done(results) }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wiedergabe-Befehle (Benachrichtigung, Kopfhoerer, "PC steuern" nicht) an den Jam umleiten.
|
||||||
|
* true = erledigt.
|
||||||
|
*/
|
||||||
|
fun intercept(command: PlayerCommand): Boolean {
|
||||||
|
val s = state ?: return false
|
||||||
|
if (!s.canControl) return true
|
||||||
|
when (command) {
|
||||||
|
PlayerCommand.PlayPause -> playPause()
|
||||||
|
PlayerCommand.Play -> send("play")
|
||||||
|
PlayerCommand.Pause -> send("pause")
|
||||||
|
PlayerCommand.Next -> send("skip")
|
||||||
|
PlayerCommand.Previous -> send("previous")
|
||||||
|
is PlayerCommand.SeekTo -> send("seek", "pos" to command.positionMs / 1000.0)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Abgleich des Players
|
||||||
|
|
||||||
|
/** Was die WebView tun soll: neue URL laden und/oder Skripte ausfuehren. */
|
||||||
|
data class Actions(val loadUrl: String?, val scripts: List<String>)
|
||||||
|
|
||||||
|
/** Wertet das Ergebnis von [JamSync.PROBE] aus (MainActivity ruft das alle 700 ms). */
|
||||||
|
fun syncPlayer(probe: JSONObject): Actions {
|
||||||
|
val s = state ?: return Actions(null, emptyList())
|
||||||
|
val now = SystemClock.elapsedRealtime()
|
||||||
|
// Soll-Position zum Zeitpunkt der Messung in der Seite (nicht erst nach der Antwort).
|
||||||
|
val wall = System.currentTimeMillis().toDouble()
|
||||||
|
val sampled = probe.optDouble("now", wall).takeIf { it.isFinite() && abs(it - wall) < 5000 } ?: wall
|
||||||
|
val want = JamSync.target(s, clock.serverNow(sampled))
|
||||||
|
val local = JamSync.Local(
|
||||||
|
videoId = probe.optString("id").takeIf { it.isNotEmpty() && it != "null" && !probe.isNull("id") },
|
||||||
|
pos = probe.optDouble("t", 0.0),
|
||||||
|
paused = probe.optBoolean("paused", true),
|
||||||
|
rate = probe.optDouble("rate", 1.0).takeIf { it.isFinite() && it > 0 } ?: 1.0,
|
||||||
|
)
|
||||||
|
val duration = probe.optDouble("d", 0.0)
|
||||||
|
val scripts = ArrayList<String>()
|
||||||
|
var load: String? = null
|
||||||
|
val pause = JamSync.playScript(false)
|
||||||
|
val matches = want != null && local.videoId == want.videoId
|
||||||
|
// In YouTube Music selbst einen Song gestartet: ab in den Jam (wie bei Spotify Jam).
|
||||||
|
if (baseline == null) baseline = local.videoId ?: ""
|
||||||
|
if (!probe.optBoolean("ad")) {
|
||||||
|
JamSync.userPick(s, want, local, baseline)?.let { id ->
|
||||||
|
if (picked.add(id)) {
|
||||||
|
val title = probe.optString("title").takeIf { it.isNotEmpty() && !probe.isNull("title") }
|
||||||
|
val artist = probe.optString("artist").takeIf { it.isNotEmpty() && !probe.isNull("artist") }
|
||||||
|
addVideo(id, title, artist)
|
||||||
|
setStatus(str(R.string.jam_added, title ?: id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (matches) {
|
||||||
|
pendingLoad = null
|
||||||
|
if (duration > 0) lastDuration = duration
|
||||||
|
}
|
||||||
|
if (want == null) {
|
||||||
|
if (JamSync.decide(null, local).isNotEmpty()) scripts.add(pause)
|
||||||
|
return Actions(null, scripts)
|
||||||
|
}
|
||||||
|
if (want.itemId in unplayable) {
|
||||||
|
if (!local.paused) scripts.add(pause)
|
||||||
|
return Actions(null, scripts)
|
||||||
|
}
|
||||||
|
if (probe.optBoolean("ad")) return Actions(null, scripts)
|
||||||
|
if (matches) {
|
||||||
|
if (duration > 0 && want.dur == null && reported.add("d" + want.itemId)) {
|
||||||
|
send("duration", "itemId" to want.itemId, "dur" to Math.round(duration).toDouble())
|
||||||
|
}
|
||||||
|
if (want.pos > 5 && JamSync.reachedEnd(local, duration, probe.optBoolean("ended")) && reported.add("e" + want.itemId)) {
|
||||||
|
send("ended", "itemId" to want.itemId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Mit Steuerrecht selbst in der Seite pausiert/fortgesetzt: fuer alle uebernehmen.
|
||||||
|
if (s.canControl && matches && now > expectUntil && want.pos >= 1 && duration > 0 && local.pos < duration - 2) {
|
||||||
|
diverge = if (local.paused != want.paused) diverge + 1 else 0
|
||||||
|
if (diverge >= 2) {
|
||||||
|
diverge = 0
|
||||||
|
expectUntil = now + 3000
|
||||||
|
send(if (local.paused) "pause" else "play")
|
||||||
|
return Actions(null, scripts)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
diverge = 0
|
||||||
|
}
|
||||||
|
// Spielt der Titel hier nicht an (gesperrt, Region, privat): ueberspringen.
|
||||||
|
val error = probe.optBoolean("error")
|
||||||
|
if (!want.paused && want.pos >= 1 && (!matches || local.paused || error)) {
|
||||||
|
val since = stuckSince
|
||||||
|
if (since == null || since.first != want.itemId) {
|
||||||
|
stuckSince = want.itemId to now
|
||||||
|
} else if (now - since.second > if (error) 3000 else STUCK_LIMIT_MS) {
|
||||||
|
unplayable.add(want.itemId)
|
||||||
|
send("unplayable", "itemId" to want.itemId)
|
||||||
|
scripts.add(pause)
|
||||||
|
notifyListeners()
|
||||||
|
return Actions(null, scripts)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stuckSince = null
|
||||||
|
}
|
||||||
|
for (step in JamSync.decide(want, local)) {
|
||||||
|
when (step) {
|
||||||
|
is JamSync.Step.Load -> {
|
||||||
|
val pending = pendingLoad
|
||||||
|
if (pending == null || pending.first != step.videoId || now - pending.second > 12_000) {
|
||||||
|
pendingLoad = step.videoId to now
|
||||||
|
expectUntil = now + 8000
|
||||||
|
load = JamSync.watchUrl(step.videoId)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
is JamSync.Step.Seek -> {
|
||||||
|
expectUntil = now + 3000
|
||||||
|
scripts.add(JamSync.seekScript(step.pos))
|
||||||
|
}
|
||||||
|
JamSync.Step.Play -> {
|
||||||
|
expectUntil = now + 3000
|
||||||
|
scripts.add(JamSync.playScript(true))
|
||||||
|
}
|
||||||
|
JamSync.Step.Pause -> {
|
||||||
|
expectUntil = now + 3000
|
||||||
|
scripts.add(pause)
|
||||||
|
}
|
||||||
|
is JamSync.Step.Rate -> scripts.add(JamSync.rateScript(step.rate))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Actions(load, scripts)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,346 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import org.json.JSONArray
|
||||||
|
import org.json.JSONObject
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Playtube Jam: Protokoll und reine Sync-Logik (ohne Android-Klassen, mit JUnit getestet).
|
||||||
|
* Dieselben Regeln gelten in Playtube am PC (src/jam.rs) und im Web-Client (public/sync.js).
|
||||||
|
*
|
||||||
|
* Wiedergabe-Modell des Servers: playback = { paused, position, ref }. Position zur Serverzeit T:
|
||||||
|
* paused ? position : position + (T - ref) / 1000. Negativ heisst "startet gleich".
|
||||||
|
*/
|
||||||
|
object JamSync {
|
||||||
|
const val TOLERANCE_S = 1.0
|
||||||
|
|
||||||
|
/** Beim Spulen etwas vorhalten: bis das Video an der neuen Stelle spielt, vergeht Zeit. */
|
||||||
|
const val SEEK_LEAD_S = 0.2
|
||||||
|
private const val NUDGE_START_S = 0.08
|
||||||
|
private const val NUDGE_STOP_S = 0.03
|
||||||
|
private const val NUDGE_GAIN = 0.25
|
||||||
|
private const val NUDGE_MAX = 0.08
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wiedergabetempo, das eine kleine Abweichung [drift] (eigene minus Jam-Position, s) ausgleicht -
|
||||||
|
* unhoerbar, die Tonhoehe bleibt. Einmal angefangen ([current] != 1) bis fast 0 ausgleichen.
|
||||||
|
*/
|
||||||
|
fun nudgeRate(drift: Double, current: Double): Double {
|
||||||
|
val threshold = if (abs(current - 1.0) > 0.001) NUDGE_STOP_S else NUDGE_START_S
|
||||||
|
if (!drift.isFinite() || abs(drift) < threshold) return 1.0
|
||||||
|
val rate = (1.0 - NUDGE_GAIN * drift).coerceIn(1.0 - NUDGE_MAX, 1.0 + NUDGE_MAX)
|
||||||
|
return Math.round(rate * 1000.0) / 1000.0
|
||||||
|
}
|
||||||
|
private const val CODE_ALPHABET = "ABCDEFGHJKMNPQRSTUVWXYZ23456789"
|
||||||
|
private val VIDEO_ID = Regex("^[A-Za-z0-9_-]{11}$")
|
||||||
|
|
||||||
|
data class Item(
|
||||||
|
val id: String,
|
||||||
|
val videoId: String,
|
||||||
|
val title: String,
|
||||||
|
val artist: String,
|
||||||
|
val thumb: String,
|
||||||
|
val dur: Double?,
|
||||||
|
val by: String,
|
||||||
|
val byName: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Member(
|
||||||
|
val id: String,
|
||||||
|
val name: String,
|
||||||
|
val client: String,
|
||||||
|
val online: Boolean,
|
||||||
|
val host: Boolean,
|
||||||
|
val cantPlay: Boolean,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Playback(val paused: Boolean, val position: Double, val ref: Double)
|
||||||
|
|
||||||
|
data class State(
|
||||||
|
val code: String,
|
||||||
|
val you: String,
|
||||||
|
val hostId: String,
|
||||||
|
val allControl: Boolean,
|
||||||
|
val canControl: Boolean,
|
||||||
|
val search: Boolean,
|
||||||
|
val members: List<Member>,
|
||||||
|
val current: Item?,
|
||||||
|
val queue: List<Item>,
|
||||||
|
val history: List<Item>,
|
||||||
|
val playback: Playback,
|
||||||
|
val serverNow: Double,
|
||||||
|
) {
|
||||||
|
val isHost: Boolean get() = you == hostId
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Codes und Links
|
||||||
|
|
||||||
|
/** "abc-234", "ABC 234" oder Einladungslink -> "ABC234", sonst null. */
|
||||||
|
fun normalizeCode(input: String?): String? {
|
||||||
|
if (input == null) return null
|
||||||
|
var text = input.trim().substringBefore('?').substringBefore('#').trimEnd('/')
|
||||||
|
if (text.contains('/')) text = text.substringAfterLast('/')
|
||||||
|
val code = text.filter { !it.isWhitespace() && it != '-' }.uppercase()
|
||||||
|
return if (code.length == 6 && code.all { it in CODE_ALPHABET }) code else null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Video-ID aus ID oder YouTube-/YouTube-Music-Link. */
|
||||||
|
fun parseVideoId(input: String?): String? {
|
||||||
|
val text = input?.trim() ?: return null
|
||||||
|
if (VIDEO_ID.matches(text)) return text
|
||||||
|
val rest = text.substringAfter("://", text)
|
||||||
|
val host = rest.substringBefore('/').lowercase().removePrefix("www.").removePrefix("m.").removePrefix("music.")
|
||||||
|
val path = rest.substringAfter('/', "").substringBefore('#')
|
||||||
|
val pathOnly = path.substringBefore('?')
|
||||||
|
val query = path.substringAfter('?', "")
|
||||||
|
val id = when (host) {
|
||||||
|
"youtu.be" -> pathOnly.substringBefore('/')
|
||||||
|
"youtube.com", "youtube-nocookie.com" ->
|
||||||
|
query.split('&').firstOrNull { it.startsWith("v=") }?.removePrefix("v=")
|
||||||
|
?: pathOnly.split('/').let { parts ->
|
||||||
|
if (parts.size >= 2 && parts[0] in setOf("shorts", "embed", "live", "v")) parts[1] else null
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
return id?.takeIf { VIDEO_ID.matches(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private val PLAYLIST_ID = Regex("^(PL|OLAK5uy_|RD|LL|UU|FL|OL|LM)[A-Za-z0-9_-]{0,80}$")
|
||||||
|
|
||||||
|
/** Playlist-/Album-ID aus einer ID oder einem Link mit `list=`, sonst null. */
|
||||||
|
fun parsePlaylistId(input: String?): String? {
|
||||||
|
val text = input?.trim() ?: return null
|
||||||
|
val raw = if (text.contains("youtube.com") || text.contains("youtu.be") || text.contains("://")) {
|
||||||
|
val rest = text.substringAfter("://", text)
|
||||||
|
val host = rest.substringBefore('/').lowercase().removePrefix("www.").removePrefix("m.").removePrefix("music.")
|
||||||
|
if (host != "youtube.com" && host != "youtu.be") return null
|
||||||
|
rest.substringAfter('?', "").substringBefore('#').split('&')
|
||||||
|
.firstOrNull { it.startsWith("list=") }?.removePrefix("list=") ?: return null
|
||||||
|
} else text
|
||||||
|
val id = raw.removePrefix("VL")
|
||||||
|
return id.takeIf { PLAYLIST_ID.matches(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Playlist-Link (ohne einzelnes Video) aus einem geteilten Text. */
|
||||||
|
fun playlistIdFromSharedText(text: String?): String? =
|
||||||
|
text?.split(Regex("\\s+"))?.firstNotNullOfOrNull { word ->
|
||||||
|
if (parseVideoId(word) == null) parsePlaylistId(word) else null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sucht in einem geteilten Text (z. B. aus der YouTube-App) den ersten YouTube-Link. */
|
||||||
|
fun videoIdFromSharedText(text: String?): String? =
|
||||||
|
text?.split(Regex("\\s+"))?.firstNotNullOfOrNull { parseVideoId(it) }
|
||||||
|
|
||||||
|
fun prettyCode(code: String): String = if (code.length == 6) code.substring(0, 3) + " " + code.substring(3) else code
|
||||||
|
|
||||||
|
fun formatTime(seconds: Double): String {
|
||||||
|
val total = if (seconds.isFinite() && seconds > 0) seconds.toLong() else 0L
|
||||||
|
val h = total / 3600
|
||||||
|
val m = (total / 60) % 60
|
||||||
|
val s = total % 60
|
||||||
|
return if (h > 0) String.format("%d:%02d:%02d", h, m, s) else String.format("%d:%02d", m, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Zustand lesen
|
||||||
|
|
||||||
|
fun parseState(json: JSONObject): State {
|
||||||
|
fun item(o: JSONObject?): Item? = o?.let {
|
||||||
|
Item(
|
||||||
|
id = it.optString("id"),
|
||||||
|
videoId = it.optString("videoId"),
|
||||||
|
title = it.optString("title"),
|
||||||
|
artist = it.optString("artist"),
|
||||||
|
thumb = it.optString("thumb"),
|
||||||
|
dur = if (it.isNull("dur") || !it.has("dur")) null else it.optDouble("dur").takeIf { d -> d.isFinite() },
|
||||||
|
by = it.optString("by"),
|
||||||
|
byName = it.optString("byName"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
fun items(a: JSONArray?): List<Item> =
|
||||||
|
if (a == null) emptyList() else (0 until a.length()).mapNotNull { item(a.optJSONObject(it)) }
|
||||||
|
val members = json.optJSONArray("members")?.let { a ->
|
||||||
|
(0 until a.length()).mapNotNull { a.optJSONObject(it) }.map {
|
||||||
|
Member(
|
||||||
|
id = it.optString("id"),
|
||||||
|
name = it.optString("name"),
|
||||||
|
client = it.optString("client"),
|
||||||
|
online = it.optBoolean("online"),
|
||||||
|
host = it.optBoolean("host"),
|
||||||
|
cantPlay = it.optBoolean("cantPlay"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} ?: emptyList()
|
||||||
|
val pb = json.optJSONObject("playback")
|
||||||
|
return State(
|
||||||
|
code = json.optString("code"),
|
||||||
|
you = json.optString("you"),
|
||||||
|
hostId = json.optString("hostId"),
|
||||||
|
allControl = json.optBoolean("allControl"),
|
||||||
|
canControl = json.optBoolean("canControl"),
|
||||||
|
search = json.optJSONObject("features")?.optBoolean("search") ?: false,
|
||||||
|
members = members,
|
||||||
|
current = item(json.optJSONObject("current")),
|
||||||
|
queue = items(json.optJSONArray("queue")),
|
||||||
|
history = items(json.optJSONArray("history")),
|
||||||
|
playback = Playback(
|
||||||
|
paused = pb?.optBoolean("paused", true) ?: true,
|
||||||
|
position = pb?.optDouble("position", 0.0) ?: 0.0,
|
||||||
|
ref = pb?.optDouble("ref", 0.0) ?: 0.0,
|
||||||
|
),
|
||||||
|
serverNow = json.optDouble("serverNow", 0.0),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Zeit und Abgleich
|
||||||
|
|
||||||
|
/** Zeitabgleich ueber ping/pong: die Messung mit der kuerzesten Laufzeit zaehlt. */
|
||||||
|
class Clock {
|
||||||
|
private val samples = ArrayList<Pair<Double, Double>>()
|
||||||
|
var offset = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun add(c: Double, s: Double, r: Double) {
|
||||||
|
val rtt = r - c
|
||||||
|
if (rtt < 0 || rtt > 30_000) return
|
||||||
|
samples.add(rtt to s - (c + rtt / 2))
|
||||||
|
if (samples.size > 10) samples.removeAt(0)
|
||||||
|
offset = samples.minByOrNull { it.first }!!.second
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hint(serverNow: Double, localNow: Double) {
|
||||||
|
if (samples.isEmpty()) offset = serverNow - localNow
|
||||||
|
}
|
||||||
|
|
||||||
|
fun serverNow(localNow: Double): Double = localNow + offset
|
||||||
|
}
|
||||||
|
|
||||||
|
fun positionAt(playback: Playback, serverNow: Double): Double =
|
||||||
|
if (playback.paused) playback.position else playback.position + (serverNow - playback.ref) / 1000.0
|
||||||
|
|
||||||
|
data class Target(val videoId: String, val itemId: String, val pos: Double, val paused: Boolean, val dur: Double?)
|
||||||
|
|
||||||
|
fun target(state: State?, serverNow: Double): Target? {
|
||||||
|
val item = state?.current ?: return null
|
||||||
|
return Target(item.videoId, item.id, positionAt(state.playback, serverNow), state.playback.paused, item.dur)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Local(val videoId: String?, val pos: Double, val paused: Boolean, val rate: Double = 1.0)
|
||||||
|
|
||||||
|
sealed class Step {
|
||||||
|
data class Load(val videoId: String, val pos: Double) : Step()
|
||||||
|
data class Seek(val pos: Double) : Step()
|
||||||
|
data object Play : Step()
|
||||||
|
data object Pause : Step()
|
||||||
|
data class Rate(val rate: Double) : Step()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Was der eigene Player tun soll, damit er zum Jam passt. */
|
||||||
|
fun decide(want: Target?, local: Local, tolerance: Double = TOLERANCE_S): List<Step> {
|
||||||
|
if (want == null) return if (local.videoId != null && !local.paused) listOf(Step.Pause) else emptyList()
|
||||||
|
val nearEnd = want.dur != null && want.pos > want.dur - 3
|
||||||
|
if (local.videoId != want.videoId) {
|
||||||
|
// Am Titelende springt YouTube Music von selbst weiter - nicht den alten Titel neu laden.
|
||||||
|
if (nearEnd) return if (local.paused) emptyList() else listOf(Step.Pause)
|
||||||
|
val steps = mutableListOf<Step>(Step.Load(want.videoId, max(0.0, want.pos)))
|
||||||
|
if (want.paused || want.pos < 0) steps.add(Step.Pause)
|
||||||
|
return steps
|
||||||
|
}
|
||||||
|
val steps = mutableListOf<Step>()
|
||||||
|
if (want.pos < 0) {
|
||||||
|
if (!local.paused) steps.add(Step.Pause)
|
||||||
|
if (local.pos > 0.5) steps.add(Step.Seek(0.0))
|
||||||
|
return steps
|
||||||
|
}
|
||||||
|
val drift = local.pos - want.pos
|
||||||
|
val seek = abs(drift) > tolerance && !(nearEnd && local.pos > want.pos)
|
||||||
|
if (seek) steps.add(Step.Seek(if (want.paused) want.pos else want.pos + SEEK_LEAD_S))
|
||||||
|
if (want.paused && !local.paused) steps.add(Step.Pause)
|
||||||
|
if (!want.paused && local.paused) steps.add(Step.Play)
|
||||||
|
// Feinabgleich ueber das Tempo, solange beide normal laufen.
|
||||||
|
val desired = if (!seek && !want.paused && !local.paused && !nearEnd) nudgeRate(drift, local.rate) else 1.0
|
||||||
|
if (abs(desired - local.rate) > 0.004) steps.add(Step.Rate(desired))
|
||||||
|
return steps
|
||||||
|
}
|
||||||
|
|
||||||
|
fun reachedEnd(local: Local, duration: Double, ended: Boolean): Boolean =
|
||||||
|
ended || (duration > 0 && local.pos >= duration - 0.6)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaScript: Stand des Players auf music.youtube.com (wie jam_probe.js am PC). Video-ID, Zeit und
|
||||||
|
* Laenge kommen von der Player-API - so darf man in YouTube Music weiter stoebern, und von
|
||||||
|
* mehreren <video>-Elementen wird nicht das falsche gelesen.
|
||||||
|
*/
|
||||||
|
const val PROBE = """
|
||||||
|
(function () {
|
||||||
|
var player = document.getElementById('movie_player');
|
||||||
|
function api(fn) { return player && typeof player[fn] === 'function'; }
|
||||||
|
var video = (player && player.querySelector('video')) || document.querySelector('video');
|
||||||
|
var id = null;
|
||||||
|
try { var data = api('getVideoData') ? player.getVideoData() : null; id = data && data.video_id ? data.video_id : null; } catch (e) { id = null; }
|
||||||
|
if (!id) { try { if (location.pathname === '/watch') { id = new URL(location.href).searchParams.get('v'); } } catch (e) { id = null; } }
|
||||||
|
var state = api('getPlayerState') ? player.getPlayerState() : null;
|
||||||
|
var session = navigator.mediaSession ? navigator.mediaSession.playbackState : 'none';
|
||||||
|
var paused;
|
||||||
|
if (state === 1 || state === 3) { paused = false; }
|
||||||
|
else if (state === 2) { paused = true; }
|
||||||
|
else if (session === 'playing' || session === 'paused') { paused = session === 'paused'; }
|
||||||
|
else { paused = video ? video.paused : true; }
|
||||||
|
var meta = navigator.mediaSession ? navigator.mediaSession.metadata : null;
|
||||||
|
var ad = !!document.querySelector('.ad-showing, .ad-interrupting');
|
||||||
|
var error = !!document.querySelector('.ytp-error, yt-playability-error-supported-renderers:not([hidden]) .reason');
|
||||||
|
return JSON.stringify({
|
||||||
|
id: id,
|
||||||
|
t: api('getCurrentTime') ? player.getCurrentTime() : (video ? video.currentTime : 0),
|
||||||
|
d: api('getDuration') && player.getDuration() > 0 ? player.getDuration() : ((video && isFinite(video.duration)) ? video.duration : 0),
|
||||||
|
paused: paused,
|
||||||
|
ended: state === 0 || (video ? video.ended : false),
|
||||||
|
rate: video && video.playbackRate > 0 ? video.playbackRate : 1,
|
||||||
|
now: Date.now(),
|
||||||
|
ad: ad,
|
||||||
|
error: error,
|
||||||
|
title: meta && meta.title ? meta.title : null,
|
||||||
|
artist: meta && meta.artist ? meta.artist : null
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
"""
|
||||||
|
|
||||||
|
/** Abspielen/Pausieren/Spulen ueber die Player-API (Rueckfall: das <video> des Players). */
|
||||||
|
fun playScript(play: Boolean): String {
|
||||||
|
val method = if (play) "playVideo" else "pauseVideo"
|
||||||
|
val prop = if (play) "play" else "pause"
|
||||||
|
return "(function(){var p=document.getElementById('movie_player');" +
|
||||||
|
"if(p&&typeof p.$method==='function'){p.$method();return;}" +
|
||||||
|
"var v=p&&p.querySelector('video')||document.querySelector('video');if(v){v.$prop();}})();"
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wiedergabetempo des Players (Feinabgleich, Tonhoehe bleibt). */
|
||||||
|
fun rateScript(rate: Double): String {
|
||||||
|
val r = if (rate.isFinite()) rate.coerceIn(0.5, 2.0) else 1.0
|
||||||
|
return "(function(){var p=document.getElementById('movie_player');" +
|
||||||
|
"var v=p&&p.querySelector('video')||document.querySelector('video');" +
|
||||||
|
"if(v){v.preservesPitch=true;v.playbackRate=$r;}})();"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun seekScript(seconds: Double): String {
|
||||||
|
val s = if (seconds.isFinite()) max(0.0, seconds) else 0.0
|
||||||
|
return "(function(){var p=document.getElementById('movie_player');var s=$s;" +
|
||||||
|
"if(p&&typeof p.seekTo==='function'){p.seekTo(s,true);return;}" +
|
||||||
|
"var v=p&&p.querySelector('video')||document.querySelector('video');if(v){v.currentTime=s;}})();"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hat man in YouTube Music selbst einen anderen Song gestartet? Dann kommt er wie bei Spotify Jam
|
||||||
|
* in den Jam. Nicht dazu zaehlen: der Song beim Beitreten ([baseline]), Autoplay am Titelende,
|
||||||
|
* der Start-Vorlauf und Songs, die der Jam schon kennt.
|
||||||
|
*/
|
||||||
|
fun userPick(state: State, want: Target?, local: Local, baseline: String?): String? {
|
||||||
|
val id = local.videoId ?: return null
|
||||||
|
if (local.paused || id == baseline || !VIDEO_ID.matches(id)) return null
|
||||||
|
if (want != null && (want.videoId == id || want.pos < 0 || (want.dur != null && want.pos > want.dur - 3))) return null
|
||||||
|
val known = (listOfNotNull(state.current) + state.queue + state.history).any { it.videoId == id }
|
||||||
|
return if (known) null else id
|
||||||
|
}
|
||||||
|
|
||||||
|
fun watchUrl(videoId: String): String = "https://music.youtube.com/watch?v=$videoId"
|
||||||
|
}
|
||||||
@@ -11,6 +11,10 @@ import android.os.Bundle
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.CheckBox
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import android.webkit.PermissionRequest
|
import android.webkit.PermissionRequest
|
||||||
import android.webkit.WebChromeClient
|
import android.webkit.WebChromeClient
|
||||||
@@ -23,9 +27,14 @@ import androidx.activity.result.contract.ActivityResultContracts
|
|||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.webkit.WebSettingsCompat
|
import androidx.webkit.WebSettingsCompat
|
||||||
import androidx.webkit.WebViewCompat
|
import androidx.webkit.WebViewCompat
|
||||||
import androidx.webkit.WebViewFeature
|
import androidx.webkit.WebViewFeature
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.json.JSONTokener
|
||||||
|
|
||||||
/** Playtube fuer Android: YouTube Music in einer WebView, mit Hintergrundwiedergabe. */
|
/** Playtube fuer Android: YouTube Music in einer WebView, mit Hintergrundwiedergabe. */
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
@@ -40,14 +49,28 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Playtube Jam: eigenen Player alle 700 ms mit dem Jam abgleichen (JamHub).
|
||||||
|
private val jamLoop = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
syncJam()
|
||||||
|
handler.postDelayed(this, JAM_INTERVAL_MS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val notificationPermission =
|
private val notificationPermission =
|
||||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { /* ohne Erlaubnis: nur keine Benachrichtigung */ }
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) { /* ohne Erlaubnis: nur keine Benachrichtigung */ }
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
Diagnostics.init(this)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
webView = findViewById(R.id.webView)
|
webView = findViewById(R.id.webView)
|
||||||
progress = findViewById(R.id.progress)
|
progress = findViewById(R.id.progress)
|
||||||
|
keepContentBetweenSystemBars()
|
||||||
|
findViewById<View>(R.id.pcRemoteButton).setOnClickListener { PcRemoteActivity.start(this) }
|
||||||
|
findViewById<View>(R.id.jamButton).setOnClickListener { JamActivity.start(this) }
|
||||||
|
findViewById<View>(R.id.settingsButton).setOnClickListener { showSettings() }
|
||||||
|
JamHub.init(this)
|
||||||
|
|
||||||
configureWebView()
|
configureWebView()
|
||||||
onBackPressedDispatcher.addCallback(
|
onBackPressedDispatcher.addCallback(
|
||||||
@@ -61,7 +84,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
PlaybackHub.commandHandler = { command ->
|
PlaybackHub.commandHandler = { command ->
|
||||||
runOnUiThread { webView.evaluateJavascript(MediaScripts.forCommand(command), null) }
|
runOnUiThread {
|
||||||
|
// Im Jam gehen Play/Pause/Weiter/Zurueck an den Jam statt an den Player.
|
||||||
|
if (!JamHub.intercept(command)) webView.evaluateJavascript(MediaScripts.forCommand(command), null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
requestNotificationPermission()
|
requestNotificationPermission()
|
||||||
DiscordPresence.init(this)
|
DiscordPresence.init(this)
|
||||||
@@ -69,7 +95,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
webView.loadUrl(startUrl(intent))
|
webView.loadUrl(startUrl(intent))
|
||||||
handler.post(probeLoop)
|
handler.post(probeLoop)
|
||||||
|
handler.post(jamLoop)
|
||||||
checkForUpdate()
|
checkForUpdate()
|
||||||
|
showDiagnosticsNotice()
|
||||||
|
// Kurz nach dem Start: Absturz vom letzten Mal o. ä. senden (höchstens alle 6 Stunden).
|
||||||
|
handler.postDelayed({ Diagnostics.sendIfDue(this) }, DIAG_DELAY_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
@@ -84,6 +114,21 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onPause()
|
super.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ab Android 15 zeichnet jede App unter Status- und Navigationsleiste. Die Seite bekommt deshalb
|
||||||
|
* Abstand oben/unten (und fuer die Tastatur); dahinter bleiben schwarze Balken stehen.
|
||||||
|
*/
|
||||||
|
private fun keepContentBetweenSystemBars() {
|
||||||
|
val insetsController = WindowCompat.getInsetsController(window, window.decorView)
|
||||||
|
insetsController.isAppearanceLightStatusBars = false
|
||||||
|
insetsController.isAppearanceLightNavigationBars = false
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.root)) { view, insets ->
|
||||||
|
val space = insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime())
|
||||||
|
view.setPadding(space.left, space.top, space.right, space.bottom)
|
||||||
|
WindowInsetsCompat.CONSUMED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
handler.removeCallbacksAndMessages(null)
|
handler.removeCallbacksAndMessages(null)
|
||||||
PlaybackHub.commandHandler = null
|
PlaybackHub.commandHandler = null
|
||||||
@@ -146,7 +191,23 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun probe() {
|
private fun probe() {
|
||||||
webView.evaluateJavascript(MediaScripts.PROBE) { raw ->
|
webView.evaluateJavascript(MediaScripts.PROBE) { raw ->
|
||||||
NowPlaying.parse(raw)?.let(PlaybackHub::publish)
|
NowPlaying.parse(raw)?.let { info ->
|
||||||
|
PlaybackHub.publish(info)
|
||||||
|
// Fuer "Jam starten": der gerade laufende Song wird der erste im Jam.
|
||||||
|
val videoId = JamSync.parseVideoId(webView.url)
|
||||||
|
JamHub.pageVideo = if (videoId != null && info.hasTrack) JamHub.PageVideo(videoId, info.title, info.artist) else null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun syncJam() {
|
||||||
|
if (JamHub.state == null) return
|
||||||
|
webView.evaluateJavascript(JamSync.PROBE) { raw ->
|
||||||
|
val text = runCatching { JSONTokener(raw).nextValue() as? String }.getOrNull() ?: return@evaluateJavascript
|
||||||
|
val probe = runCatching { JSONObject(text) }.getOrNull() ?: return@evaluateJavascript
|
||||||
|
val actions = JamHub.syncPlayer(probe)
|
||||||
|
actions.loadUrl?.let { webView.loadUrl(it) }
|
||||||
|
for (script in actions.scripts) webView.evaluateJavascript(script, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +236,58 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Einstellungen / Diagnose
|
||||||
|
|
||||||
|
/** Einmaliger Hinweis: Diagnosedaten sind an (Opt-out) und lassen sich hier abschalten. */
|
||||||
|
private fun showDiagnosticsNotice() {
|
||||||
|
if (!Diagnostics.needsNotice(this)) return
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.diag_notice_title)
|
||||||
|
.setMessage(R.string.diag_notice_message)
|
||||||
|
.setPositiveButton(R.string.diag_notice_ok) { _, _ -> Diagnostics.noticeShown(this) }
|
||||||
|
.setNegativeButton(R.string.diag_notice_off) { _, _ ->
|
||||||
|
Diagnostics.setEnabled(this, false)
|
||||||
|
Diagnostics.noticeShown(this)
|
||||||
|
}
|
||||||
|
.setOnCancelListener { Diagnostics.noticeShown(this) }
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showSettings() {
|
||||||
|
val pad = (20 * resources.displayMetrics.density).toInt()
|
||||||
|
val box = CheckBox(this).apply {
|
||||||
|
setText(R.string.diag_enabled)
|
||||||
|
isChecked = Diagnostics.isEnabled(this@MainActivity)
|
||||||
|
setOnCheckedChangeListener { _, checked -> Diagnostics.setEnabled(this@MainActivity, checked) }
|
||||||
|
}
|
||||||
|
val hint = TextView(this).apply {
|
||||||
|
text = getString(R.string.diag_hint) + "\n\n" + getString(R.string.diag_install_id, Diagnostics.installId(this@MainActivity))
|
||||||
|
setTextIsSelectable(true)
|
||||||
|
alpha = 0.75f
|
||||||
|
}
|
||||||
|
val content = LinearLayout(this).apply {
|
||||||
|
orientation = LinearLayout.VERTICAL
|
||||||
|
setPadding(pad, pad / 2, pad, 0)
|
||||||
|
addView(box)
|
||||||
|
addView(hint)
|
||||||
|
}
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.settings_title)
|
||||||
|
.setView(content)
|
||||||
|
.setPositiveButton(R.string.diag_done, null)
|
||||||
|
.setNeutralButton(R.string.diag_send_now) { _, _ ->
|
||||||
|
Diagnostics.send(this, manual = true) { ok ->
|
||||||
|
val text = when (ok) {
|
||||||
|
null -> R.string.diag_nothing
|
||||||
|
true -> R.string.diag_sent
|
||||||
|
false -> R.string.diag_failed
|
||||||
|
}
|
||||||
|
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
private fun showUpdateDialog(release: UpdateChecker.Release) {
|
private fun showUpdateDialog(release: UpdateChecker.Release) {
|
||||||
val prefs = getSharedPreferences(PREFS, MODE_PRIVATE)
|
val prefs = getSharedPreferences(PREFS, MODE_PRIVATE)
|
||||||
if (prefs.getString(KEY_DISMISSED_UPDATE, null) == release.tag) return
|
if (prefs.getString(KEY_DISMISSED_UPDATE, null) == release.tag) return
|
||||||
@@ -198,6 +311,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private const val MUSIC_ORIGIN = "https://music.youtube.com"
|
private const val MUSIC_ORIGIN = "https://music.youtube.com"
|
||||||
private const val HOME_URL = "https://music.youtube.com/"
|
private const val HOME_URL = "https://music.youtube.com/"
|
||||||
private const val PROBE_INTERVAL_MS = 1500L
|
private const val PROBE_INTERVAL_MS = 1500L
|
||||||
|
private const val JAM_INTERVAL_MS = 700L
|
||||||
|
private const val DIAG_DELAY_MS = 30_000L
|
||||||
private const val PREFS = "playtube"
|
private const val PREFS = "playtube"
|
||||||
private const val KEY_DISMISSED_UPDATE = "dismissed_update"
|
private const val KEY_DISMISSED_UPDATE = "dismissed_update"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,237 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.io.BufferedReader
|
||||||
|
import java.io.BufferedWriter
|
||||||
|
import java.io.Closeable
|
||||||
|
import java.io.IOException
|
||||||
|
import java.net.DatagramPacket
|
||||||
|
import java.net.DatagramSocket
|
||||||
|
import java.net.InetAddress
|
||||||
|
import java.net.InetSocketAddress
|
||||||
|
import java.net.Socket
|
||||||
|
import java.net.SocketTimeoutException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Steuerung von Playtube auf dem PC im selben WLAN (wie "Spotify Connect"). Gegenstueck am PC:
|
||||||
|
* playtube/lan_remote.py. Protokoll: eine JSON-Nachricht pro Zeile ueber TCP (Port 47811); den PC
|
||||||
|
* findet die App per UDP-Broadcast "PLAYTUBE_DISCOVER" an Port 47812.
|
||||||
|
*/
|
||||||
|
data class PcDevice(val name: String, val host: String, val port: Int = PcRemote.DEFAULT_PORT)
|
||||||
|
|
||||||
|
/** Was auf dem PC gerade laeuft (aus der "status"-Antwort, Zeiten in Sekunden). */
|
||||||
|
/** Ein Titel der Warteschlange am PC. */
|
||||||
|
data class QueueItem(val title: String, val subtitle: String, val thumbnail: String, val current: Boolean)
|
||||||
|
|
||||||
|
/** Eine Playlist der YouTube-Music-Bibliothek am PC. */
|
||||||
|
data class PcPlaylist(val id: String, val title: String)
|
||||||
|
|
||||||
|
data class PcState(
|
||||||
|
val activeTab: String,
|
||||||
|
val visibleTab: String,
|
||||||
|
val title: String,
|
||||||
|
val subtitle: String,
|
||||||
|
val thumbnail: String,
|
||||||
|
val playing: Boolean,
|
||||||
|
val position: Double,
|
||||||
|
val duration: Double,
|
||||||
|
val volume: Int,
|
||||||
|
val liked: Boolean,
|
||||||
|
/** "NONE", "ALL" oder "ONE" (leer = unbekannt). */
|
||||||
|
val repeatMode: String = "",
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
val EMPTY = PcState("music", "music", "", "", "", false, 0.0, 0.0, 100, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object PcRemote {
|
||||||
|
const val DEFAULT_PORT = 47811
|
||||||
|
const val DISCOVERY_PORT = 47812
|
||||||
|
private const val DISCOVERY_REQUEST = "PLAYTUBE_DISCOVER"
|
||||||
|
private const val CONNECT_TIMEOUT_MS = 4_000
|
||||||
|
private const val READ_TIMEOUT_MS = 6_000
|
||||||
|
|
||||||
|
/** Antwort eines PCs auf die Suche -> Geraet, oder null wenn es kein Playtube ist. */
|
||||||
|
fun parseDiscoveryReply(text: String, host: String): PcDevice? {
|
||||||
|
val json = try {
|
||||||
|
JSONObject(text)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (json.optString("service") != "playtube") return null
|
||||||
|
val port = json.optInt("port", DEFAULT_PORT).takeIf { it in 1..65535 } ?: return null
|
||||||
|
val name = json.optString("name").trim().take(60).ifBlank { host }
|
||||||
|
return PcDevice(name, host, port)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "status"-Antwort -> [PcState]; null, wenn die Antwort keinen Stand enthaelt. */
|
||||||
|
fun parseState(reply: JSONObject): PcState? {
|
||||||
|
val state = reply.optJSONObject("state") ?: return null
|
||||||
|
val activeTab = state.optString("activeTab", "music")
|
||||||
|
val tab = state.optJSONObject("tabs")?.optJSONObject(activeTab)
|
||||||
|
return PcState(
|
||||||
|
activeTab = activeTab,
|
||||||
|
visibleTab = state.optString("visibleTab", activeTab),
|
||||||
|
title = tab.text("title"),
|
||||||
|
subtitle = tab.text("subtitle"),
|
||||||
|
thumbnail = largeCover(tab.text("thumbnail").takeIf { it.startsWith("https://") }.orEmpty()),
|
||||||
|
playing = tab?.optBoolean("playing") ?: false,
|
||||||
|
position = tab?.optDouble("currentTime")?.takeIf { it.isFinite() } ?: 0.0,
|
||||||
|
duration = tab?.optDouble("duration")?.takeIf { it.isFinite() } ?: 0.0,
|
||||||
|
volume = (tab?.optDouble("volume")?.takeIf { it.isFinite() } ?: 100.0).toInt().coerceIn(0, 100),
|
||||||
|
liked = tab?.optString("likeStatus").equals("LIKE", ignoreCase = true),
|
||||||
|
repeatMode = tab.text("repeatMode").uppercase(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "queue"-Antwort -> Titel (Cover in Listengroesse); Eintraege ohne JSON-Objekt werden uebersprungen. */
|
||||||
|
fun parseQueue(reply: JSONObject): List<QueueItem> {
|
||||||
|
val array = reply.optJSONArray("queue") ?: return emptyList()
|
||||||
|
val items = ArrayList<QueueItem>()
|
||||||
|
for (i in 0 until array.length()) {
|
||||||
|
val item = array.optJSONObject(i) ?: continue
|
||||||
|
// Nichts weglassen: der Index muss zur Reihenfolge am PC passen (play_queue_item).
|
||||||
|
items += QueueItem(
|
||||||
|
title = item.text("title").trim(),
|
||||||
|
subtitle = item.text("subtitle").trim(),
|
||||||
|
thumbnail = sizedCover(item.text("thumbnail").takeIf { it.startsWith("https://") }.orEmpty(), 226),
|
||||||
|
current = item.optBoolean("current"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "list_playlists"-Antwort -> Playlists. */
|
||||||
|
fun parsePlaylists(reply: JSONObject): List<PcPlaylist> {
|
||||||
|
val array = reply.optJSONArray("playlists") ?: return emptyList()
|
||||||
|
val items = ArrayList<PcPlaylist>()
|
||||||
|
for (i in 0 until array.length()) {
|
||||||
|
val item = array.optJSONObject(i) ?: continue
|
||||||
|
val id = item.text("id").trim()
|
||||||
|
if (id.isEmpty()) continue
|
||||||
|
items += PcPlaylist(id, item.text("title").trim().ifEmpty { id })
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ein PC mit Playtube 2.0.x kennt "queue" noch nicht und antwortet mit "unbekannter Befehl". */
|
||||||
|
fun isUnknownCommand(message: String?): Boolean =
|
||||||
|
message != null && (message.contains("unbekannter Befehl", ignoreCase = true) ||
|
||||||
|
message.contains("unknown command", ignoreCase = true))
|
||||||
|
|
||||||
|
private val GOOGLE_IMAGE_SIZE = Regex("=(w\\d+-h\\d+|s\\d+)[^/=]*$")
|
||||||
|
private val YTIMG_SMALL = Regex("/(default|mqdefault)\\.jpg$")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Das Cover aus der YouTube-Music-Player-Leiste ist nur 60x60 Pixel gross ("=w60-h60-l90-rj") -
|
||||||
|
* fuer die Fernbedienung in 544x544 anfordern; kleine YouTube-Vorschaubilder durch hqdefault ersetzen.
|
||||||
|
*/
|
||||||
|
fun largeCover(url: String): String = sizedCover(url, 544)
|
||||||
|
|
||||||
|
/** Wie [largeCover], aber in [size] x [size] Pixeln (fuer kleine Listenbilder). */
|
||||||
|
fun sizedCover(url: String, size: Int): String = when {
|
||||||
|
url.contains("googleusercontent.com") || url.contains("ggpht.com") ->
|
||||||
|
url.replace(GOOGLE_IMAGE_SIZE, "=w$size-h$size-l90-rj")
|
||||||
|
url.contains("ytimg.com") -> url.replace(YTIMG_SMALL, "/hqdefault.jpg")
|
||||||
|
else -> url
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Textfeld ohne JSON-null ("null" als Text waere sonst sichtbar). */
|
||||||
|
private fun JSONObject?.text(key: String): String =
|
||||||
|
if (this == null || isNull(key)) "" else optString(key)
|
||||||
|
|
||||||
|
/** Sekunden -> "m:ss" bzw. "h:mm:ss". */
|
||||||
|
fun formatTime(seconds: Double): String {
|
||||||
|
val total = seconds.coerceAtLeast(0.0).toLong()
|
||||||
|
val h = total / 3600
|
||||||
|
val m = (total % 3600) / 60
|
||||||
|
val s = total % 60
|
||||||
|
return if (h > 0) "%d:%02d:%02d".format(h, m, s) else "%d:%02d".format(m, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sucht Playtube-PCs im WLAN (blockiert bis [timeoutMs] - nicht auf dem Hauptthread aufrufen).
|
||||||
|
* Mehrere Antworten desselben PCs werden zusammengefasst.
|
||||||
|
*/
|
||||||
|
fun discover(timeoutMs: Int = 1500): List<PcDevice> {
|
||||||
|
val found = LinkedHashMap<String, PcDevice>()
|
||||||
|
try {
|
||||||
|
DatagramSocket().use { socket ->
|
||||||
|
socket.broadcast = true
|
||||||
|
socket.soTimeout = 300
|
||||||
|
val request = DISCOVERY_REQUEST.toByteArray()
|
||||||
|
val broadcast = InetAddress.getByName("255.255.255.255")
|
||||||
|
socket.send(DatagramPacket(request, request.size, broadcast, DISCOVERY_PORT))
|
||||||
|
val deadline = System.currentTimeMillis() + timeoutMs
|
||||||
|
val buffer = ByteArray(1024)
|
||||||
|
while (System.currentTimeMillis() < deadline) {
|
||||||
|
val packet = DatagramPacket(buffer, buffer.size)
|
||||||
|
try {
|
||||||
|
socket.receive(packet)
|
||||||
|
} catch (_: SocketTimeoutException) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val host = packet.address.hostAddress ?: continue
|
||||||
|
val text = String(packet.data, 0, packet.length, Charsets.UTF_8)
|
||||||
|
parseDiscoveryReply(text, host)?.let { found["${it.host}:${it.port}"] = it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: IOException) {
|
||||||
|
// Kein WLAN o.ae. -> leere Liste; die IP-Adresse laesst sich von Hand eingeben.
|
||||||
|
}
|
||||||
|
return found.values.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fehlermeldung des PCs (z.B. "Falscher Code"). */
|
||||||
|
class RemoteException(message: String) : IOException(message)
|
||||||
|
|
||||||
|
/** Eine offene Verbindung zum PC. Alle Aufrufe blockieren - nur auf einem Hintergrundthread nutzen. */
|
||||||
|
class Connection private constructor(private val socket: Socket) : Closeable {
|
||||||
|
private val reader: BufferedReader = socket.getInputStream().bufferedReader(Charsets.UTF_8)
|
||||||
|
private val writer: BufferedWriter = socket.getOutputStream().bufferedWriter(Charsets.UTF_8)
|
||||||
|
private var nextId = 1
|
||||||
|
|
||||||
|
/** Schickt eine Anfrage und wartet auf die Antwort mit derselben id. */
|
||||||
|
fun request(command: String, fill: JSONObject.() -> Unit = {}): JSONObject {
|
||||||
|
val id = nextId++
|
||||||
|
val message = JSONObject().put("id", id).put("cmd", command).apply(fill)
|
||||||
|
writer.write(message.toString())
|
||||||
|
writer.write("\n")
|
||||||
|
writer.flush()
|
||||||
|
while (true) {
|
||||||
|
val line = reader.readLine() ?: throw IOException("Verbindung getrennt")
|
||||||
|
val reply = try {
|
||||||
|
JSONObject(line)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (reply.optInt("id", -1) != id) continue
|
||||||
|
if (!reply.optBoolean("ok")) throw RemoteException(reply.optString("error", "Fehler"))
|
||||||
|
return reply
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
try {
|
||||||
|
socket.close()
|
||||||
|
} catch (_: IOException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun open(device: PcDevice): Connection {
|
||||||
|
val socket = Socket()
|
||||||
|
try {
|
||||||
|
socket.connect(InetSocketAddress(device.host, device.port), CONNECT_TIMEOUT_MS)
|
||||||
|
socket.soTimeout = READ_TIMEOUT_MS
|
||||||
|
socket.tcpNoDelay = true
|
||||||
|
} catch (e: IOException) {
|
||||||
|
socket.close()
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
return Connection(socket)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,610 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.animation.ValueAnimator
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Outline
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.text.InputFilter
|
||||||
|
import android.text.InputType
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.ViewOutlineProvider
|
||||||
|
import android.widget.BaseAdapter
|
||||||
|
import android.widget.Button
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.ImageButton
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.ListView
|
||||||
|
import android.widget.SeekBar
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.graphics.ColorUtils
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.palette.graphics.Palette
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "PC steuern": findet Playtube auf dem PC im selben WLAN und steuert es wie eine Fernbedienung
|
||||||
|
* (Titel, Cover, Play/Pause, Spulen, Lautstaerke, Like, Warteschlange, Playlists). Die Verbindung
|
||||||
|
* haelt [PcSession] mit dem Vordergrunddienst [PcRemoteService] - sie bleibt bestehen, wenn man diesen
|
||||||
|
* Bildschirm verlaesst. Protokoll siehe [PcRemote].
|
||||||
|
*/
|
||||||
|
class PcRemoteActivity : AppCompatActivity(), PcSession.Listener {
|
||||||
|
private val main = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
|
private var draggingPosition = false
|
||||||
|
private var draggingVolume = false
|
||||||
|
private var coverUrl = ""
|
||||||
|
private var gradientColor = BACKGROUND
|
||||||
|
private var gradientAnimator: ValueAnimator? = null
|
||||||
|
private var lastPhase = PcSession.Phase.IDLE
|
||||||
|
private var pendingTarget: PcDevice? = null
|
||||||
|
|
||||||
|
/** Meldung (Fehler / Verbindung verloren), die die Suche nicht ueberschreiben soll. */
|
||||||
|
private var note: String? = null
|
||||||
|
private var listMode: ListMode? = null
|
||||||
|
private var queueItems = listOf<QueueItem>()
|
||||||
|
private var playlistItems = listOf<PcPlaylist>()
|
||||||
|
private val devices = mutableListOf<PcDevice>()
|
||||||
|
|
||||||
|
private lateinit var status: TextView
|
||||||
|
private lateinit var devicePanel: View
|
||||||
|
private lateinit var playerPanel: View
|
||||||
|
private lateinit var listPanel: View
|
||||||
|
private lateinit var gradient: View
|
||||||
|
private lateinit var cover: ImageView
|
||||||
|
private lateinit var deviceName: TextView
|
||||||
|
private lateinit var trackTitle: TextView
|
||||||
|
private lateinit var trackSubtitle: TextView
|
||||||
|
private lateinit var positionBar: SeekBar
|
||||||
|
private lateinit var positionText: TextView
|
||||||
|
private lateinit var durationText: TextView
|
||||||
|
private lateinit var playPause: ImageButton
|
||||||
|
private lateinit var like: ImageButton
|
||||||
|
private lateinit var repeat: ImageButton
|
||||||
|
private lateinit var volumeBar: SeekBar
|
||||||
|
private lateinit var tabYoutube: Button
|
||||||
|
private lateinit var tabMusic: Button
|
||||||
|
private lateinit var deviceAdapter: RowAdapter
|
||||||
|
private lateinit var itemAdapter: RowAdapter
|
||||||
|
private lateinit var listTitle: TextView
|
||||||
|
private lateinit var listMessage: TextView
|
||||||
|
private lateinit var itemList: ListView
|
||||||
|
|
||||||
|
private enum class ListMode { QUEUE, PLAYLISTS }
|
||||||
|
|
||||||
|
private val notificationPermission =
|
||||||
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) { /* ohne Erlaubnis: nur keine Benachrichtigung */ }
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_pc_remote)
|
||||||
|
keepContentBetweenSystemBars()
|
||||||
|
|
||||||
|
status = findViewById(R.id.remoteStatus)
|
||||||
|
devicePanel = findViewById(R.id.devicePanel)
|
||||||
|
playerPanel = findViewById(R.id.playerPanel)
|
||||||
|
listPanel = findViewById(R.id.listPanel)
|
||||||
|
gradient = findViewById(R.id.gradient)
|
||||||
|
cover = findViewById(R.id.cover)
|
||||||
|
deviceName = findViewById(R.id.deviceName)
|
||||||
|
trackTitle = findViewById(R.id.trackTitle)
|
||||||
|
trackSubtitle = findViewById(R.id.trackSubtitle)
|
||||||
|
positionBar = findViewById(R.id.positionBar)
|
||||||
|
positionText = findViewById(R.id.positionText)
|
||||||
|
durationText = findViewById(R.id.durationText)
|
||||||
|
playPause = findViewById(R.id.playPauseButton)
|
||||||
|
like = findViewById(R.id.likeButton)
|
||||||
|
repeat = findViewById(R.id.repeatButton)
|
||||||
|
volumeBar = findViewById(R.id.volumeBar)
|
||||||
|
tabYoutube = findViewById(R.id.tabYoutube)
|
||||||
|
tabMusic = findViewById(R.id.tabMusic)
|
||||||
|
listTitle = findViewById(R.id.listTitle)
|
||||||
|
listMessage = findViewById(R.id.listMessage)
|
||||||
|
itemList = findViewById(R.id.itemList)
|
||||||
|
|
||||||
|
setupRoundCover()
|
||||||
|
applyGradient(BACKGROUND)
|
||||||
|
|
||||||
|
deviceAdapter = RowAdapter(this)
|
||||||
|
findViewById<ListView>(R.id.deviceList).apply {
|
||||||
|
adapter = deviceAdapter
|
||||||
|
setOnItemClickListener { _, _, position, _ -> devices.getOrNull(position)?.let(::connectTo) }
|
||||||
|
}
|
||||||
|
itemAdapter = RowAdapter(this)
|
||||||
|
itemList.apply {
|
||||||
|
adapter = itemAdapter
|
||||||
|
setOnItemClickListener { _, _, position, _ -> onListItemClicked(position) }
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById<Button>(R.id.searchButton).setOnClickListener {
|
||||||
|
note = null
|
||||||
|
search()
|
||||||
|
}
|
||||||
|
findViewById<Button>(R.id.manualButton).setOnClickListener { askForAddress() }
|
||||||
|
findViewById<Button>(R.id.disconnectButton).setOnClickListener { PcSession.disconnect() }
|
||||||
|
findViewById<ImageButton>(R.id.deviceBack).setOnClickListener { showPlayer() }
|
||||||
|
findViewById<ImageButton>(R.id.closeButton).setOnClickListener { finish() }
|
||||||
|
findViewById<ImageButton>(R.id.devicesButton).setOnClickListener { showDevices() }
|
||||||
|
findViewById<ImageButton>(R.id.listBack).setOnClickListener { closeList() }
|
||||||
|
findViewById<Button>(R.id.queueButton).setOnClickListener { openList(ListMode.QUEUE) }
|
||||||
|
findViewById<Button>(R.id.playlistsButton).setOnClickListener { openList(ListMode.PLAYLISTS) }
|
||||||
|
|
||||||
|
findViewById<ImageButton>(R.id.previousButton).setOnClickListener { PcSession.send("previous") }
|
||||||
|
findViewById<ImageButton>(R.id.nextButton).setOnClickListener { PcSession.send("next") }
|
||||||
|
findViewById<ImageButton>(R.id.shuffleButton).setOnClickListener { PcSession.send("shuffle") }
|
||||||
|
repeat.setOnClickListener { PcSession.send("repeat") }
|
||||||
|
playPause.setOnClickListener {
|
||||||
|
PcSession.send("play_pause") // der naechste Status (1 s) bestaetigt; die Taste schaltet sofort um
|
||||||
|
renderPlayPause(!PcSession.state.playing)
|
||||||
|
}
|
||||||
|
like.setOnClickListener { PcSession.send("like") }
|
||||||
|
tabYoutube.setOnClickListener { PcSession.send("switch_tab", target = "youtube") }
|
||||||
|
tabMusic.setOnClickListener { PcSession.send("switch_tab", target = "music") }
|
||||||
|
|
||||||
|
positionBar.setOnSeekBarChangeListener(object : SeekBarListener() {
|
||||||
|
override fun onStartTrackingTouch(bar: SeekBar) {
|
||||||
|
draggingPosition = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onProgressChanged(bar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||||
|
if (fromUser) positionText.text = PcRemote.formatTime(progress.toDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStopTrackingTouch(bar: SeekBar) {
|
||||||
|
draggingPosition = false
|
||||||
|
// Der PC spult relativ ("seek" = Sekunden vor/zurueck).
|
||||||
|
val delta = (bar.progress - PcSession.state.position).coerceIn(-3600.0, 3600.0)
|
||||||
|
PcSession.send("seek", value = delta)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
volumeBar.setOnSeekBarChangeListener(object : SeekBarListener() {
|
||||||
|
override fun onStartTrackingTouch(bar: SeekBar) {
|
||||||
|
draggingVolume = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStopTrackingTouch(bar: SeekBar) {
|
||||||
|
draggingVolume = false
|
||||||
|
PcSession.send("set_volume", value = bar.progress.toDouble())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
when {
|
||||||
|
listMode != null -> closeList()
|
||||||
|
PcSession.isActive && devicePanel.visibility == View.VISIBLE -> showPlayer()
|
||||||
|
else -> {
|
||||||
|
isEnabled = false
|
||||||
|
onBackPressedDispatcher.onBackPressed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= 33 &&
|
||||||
|
ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
notificationPermission.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PcSession.isActive) {
|
||||||
|
lastPhase = PcSession.phase
|
||||||
|
showPlayer()
|
||||||
|
} else {
|
||||||
|
showDevices()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
PcSession.addListener(this)
|
||||||
|
onUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
PcSession.removeListener(this)
|
||||||
|
super.onStop()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
main.removeCallbacksAndMessages(null)
|
||||||
|
gradientAnimator?.cancel()
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun keepContentBetweenSystemBars() {
|
||||||
|
val root = findViewById<View>(R.id.remoteRoot)
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(root) { view, insets ->
|
||||||
|
val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime())
|
||||||
|
view.setPadding(bars.left, bars.top, bars.right, bars.bottom)
|
||||||
|
WindowInsetsCompat.CONSUMED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Quadratisches Cover mit runden Ecken, so gross wie der freie Platz erlaubt. */
|
||||||
|
private fun setupRoundCover() {
|
||||||
|
val corner = 12 * resources.displayMetrics.density
|
||||||
|
cover.clipToOutline = true
|
||||||
|
cover.outlineProvider = object : ViewOutlineProvider() {
|
||||||
|
override fun getOutline(view: View, outline: Outline) {
|
||||||
|
outline.setRoundRect(0, 0, view.width, view.height, corner)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
findViewById<View>(R.id.coverBox).addOnLayoutChangeListener { box, left, top, right, bottom, _, _, _, _ ->
|
||||||
|
val side = minOf(right - left, bottom - top).coerceAtLeast(0)
|
||||||
|
if (cover.layoutParams.width != side || cover.layoutParams.height != side) {
|
||||||
|
cover.layoutParams = cover.layoutParams.apply {
|
||||||
|
width = side
|
||||||
|
height = side
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Bereiche umschalten
|
||||||
|
|
||||||
|
private fun showPlayer() {
|
||||||
|
devicePanel.visibility = View.GONE
|
||||||
|
playerPanel.visibility = View.VISIBLE
|
||||||
|
render()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showDevices() {
|
||||||
|
closeList()
|
||||||
|
val connected = PcSession.isActive
|
||||||
|
playerPanel.visibility = View.GONE
|
||||||
|
devicePanel.visibility = View.VISIBLE
|
||||||
|
findViewById<View>(R.id.deviceBack).visibility = if (connected) View.VISIBLE else View.GONE
|
||||||
|
findViewById<View>(R.id.disconnectButton).visibility = if (connected) View.VISIBLE else View.GONE
|
||||||
|
applyGradient(BACKGROUND)
|
||||||
|
search()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ PC-Sitzung (Listener)
|
||||||
|
|
||||||
|
override fun onUpdate() {
|
||||||
|
val phase = PcSession.phase
|
||||||
|
val previous = lastPhase
|
||||||
|
lastPhase = phase
|
||||||
|
when (phase) {
|
||||||
|
PcSession.Phase.IDLE -> {
|
||||||
|
if (previous != PcSession.Phase.IDLE) showDevices()
|
||||||
|
}
|
||||||
|
PcSession.Phase.CONNECTING -> status.text = getString(R.string.pc_connecting, PcSession.device?.name.orEmpty())
|
||||||
|
PcSession.Phase.CONNECTED, PcSession.Phase.RECONNECTING -> {
|
||||||
|
if (previous == PcSession.Phase.CONNECTING) showPlayer()
|
||||||
|
if (playerPanel.visibility == View.VISIBLE) render()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onProblem(problem: PcSession.Problem, message: String) {
|
||||||
|
when (problem) {
|
||||||
|
PcSession.Problem.PAIRING_REQUIRED -> pendingTarget?.let(::askForCode)
|
||||||
|
PcSession.Problem.FAILED -> {
|
||||||
|
note = getString(R.string.pc_error, message)
|
||||||
|
status.text = note
|
||||||
|
if (playerPanel.visibility == View.VISIBLE) showDevices()
|
||||||
|
}
|
||||||
|
PcSession.Problem.LOST -> {
|
||||||
|
note = getString(R.string.pc_lost, message)
|
||||||
|
status.text = note
|
||||||
|
showDevices()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ PCs finden
|
||||||
|
|
||||||
|
private fun search() {
|
||||||
|
if (note == null) status.setText(R.string.pc_searching) else status.text = note
|
||||||
|
Thread {
|
||||||
|
val found = PcRemote.discover()
|
||||||
|
main.post {
|
||||||
|
if (isFinishing || isDestroyed) return@post
|
||||||
|
devices.clear()
|
||||||
|
devices.addAll(found)
|
||||||
|
val connectedHost = PcSession.device?.takeIf { PcSession.isActive }?.host
|
||||||
|
deviceAdapter.setRows(
|
||||||
|
found.map {
|
||||||
|
Row(
|
||||||
|
title = it.name,
|
||||||
|
subtitle = if (it.host == connectedHost) getString(R.string.pc_this_pc) else it.host,
|
||||||
|
iconRes = R.drawable.ic_computer,
|
||||||
|
highlighted = it.host == connectedHost,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if (PcSession.phase != PcSession.Phase.CONNECTING) {
|
||||||
|
note?.let { status.text = it } ?: status.setText(if (found.isEmpty()) R.string.pc_none_found else R.string.pc_found)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun askForAddress() {
|
||||||
|
val input = EditText(this).apply {
|
||||||
|
hint = getString(R.string.pc_manual_hint)
|
||||||
|
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI
|
||||||
|
setText(PcSession.prefs(this@PcRemoteActivity).getString(PcSession.KEY_LAST_HOST, ""))
|
||||||
|
}
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.pc_manual)
|
||||||
|
.setView(padded(input))
|
||||||
|
.setPositiveButton(R.string.pc_connect) { _, _ ->
|
||||||
|
val host = input.text.toString().trim()
|
||||||
|
if (host.isNotEmpty()) {
|
||||||
|
val name = PcSession.prefs(this).getString(PcSession.KEY_NAME_FOR + host, null) ?: host
|
||||||
|
connectTo(PcDevice(name, host))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.pc_cancel, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Verbinden / Koppeln
|
||||||
|
|
||||||
|
private fun connectTo(target: PcDevice) {
|
||||||
|
note = null
|
||||||
|
pendingTarget = target
|
||||||
|
val token = PcSession.prefs(this).getString(PcSession.KEY_TOKEN_FOR + target.name, null)
|
||||||
|
if (token == null) {
|
||||||
|
askForCode(target)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PcSession.connect(this, target, token, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun askForCode(target: PcDevice) {
|
||||||
|
val input = EditText(this).apply {
|
||||||
|
hint = getString(R.string.pc_pair_hint)
|
||||||
|
inputType = InputType.TYPE_CLASS_NUMBER
|
||||||
|
filters = arrayOf(InputFilter.LengthFilter(6))
|
||||||
|
}
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(getString(R.string.pc_pair_title, target.name))
|
||||||
|
.setMessage(R.string.pc_pair_message)
|
||||||
|
.setView(padded(input))
|
||||||
|
.setPositiveButton(R.string.pc_pair) { _, _ ->
|
||||||
|
PcSession.connect(this, target, null, input.text.toString().trim())
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.pc_cancel, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Anzeige
|
||||||
|
|
||||||
|
private fun render() {
|
||||||
|
val state = PcSession.state
|
||||||
|
deviceName.text = PcSession.device?.name.orEmpty()
|
||||||
|
trackTitle.text = state.title.ifBlank { getString(R.string.pc_nothing_playing) }
|
||||||
|
trackSubtitle.text = if (PcSession.phase == PcSession.Phase.RECONNECTING) getString(R.string.pc_reconnecting) else state.subtitle
|
||||||
|
renderPlayPause(state.playing)
|
||||||
|
|
||||||
|
val duration = state.duration.toInt().coerceAtLeast(0)
|
||||||
|
positionBar.max = duration
|
||||||
|
positionBar.isEnabled = duration > 0
|
||||||
|
durationText.text = PcRemote.formatTime(state.duration)
|
||||||
|
if (!draggingPosition) {
|
||||||
|
positionBar.progress = state.position.toInt().coerceIn(0, duration)
|
||||||
|
positionText.text = PcRemote.formatTime(state.position)
|
||||||
|
}
|
||||||
|
if (!draggingVolume) volumeBar.progress = state.volume
|
||||||
|
|
||||||
|
like.setImageResource(if (state.liked) R.drawable.ic_favorite else R.drawable.ic_favorite_border)
|
||||||
|
like.imageTintList = tint(if (state.liked) R.color.brand_to else R.color.text)
|
||||||
|
repeat.setImageResource(if (state.repeatMode == "ONE") R.drawable.ic_repeat_one else R.drawable.ic_repeat)
|
||||||
|
repeat.imageTintList = tint(if (state.repeatMode == "ALL" || state.repeatMode == "ONE") R.color.brand_to else R.color.text_muted)
|
||||||
|
findViewById<ImageButton>(R.id.shuffleButton).imageTintList = tint(R.color.text_muted)
|
||||||
|
tabYoutube.alpha = if (state.visibleTab == "youtube") 1f else 0.45f
|
||||||
|
tabMusic.alpha = if (state.visibleTab == "music") 1f else 0.45f
|
||||||
|
|
||||||
|
if (state.thumbnail != coverUrl) loadCover(state.thumbnail)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun renderPlayPause(playing: Boolean) {
|
||||||
|
playPause.setImageResource(if (playing) R.drawable.ic_pause else R.drawable.ic_play)
|
||||||
|
playPause.contentDescription = getString(if (playing) R.string.action_pause else R.string.action_play)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun tint(colorRes: Int) = android.content.res.ColorStateList.valueOf(ContextCompat.getColor(this, colorRes))
|
||||||
|
|
||||||
|
private fun loadCover(url: String) {
|
||||||
|
coverUrl = url
|
||||||
|
if (url.isEmpty()) {
|
||||||
|
cover.setImageDrawable(null)
|
||||||
|
applyGradient(BACKGROUND)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ImageCache.load(url, 544) { bitmap ->
|
||||||
|
if (coverUrl != url || isDestroyed) return@load
|
||||||
|
cover.setImageBitmap(bitmap)
|
||||||
|
if (bitmap != null) {
|
||||||
|
Palette.from(bitmap).maximumColorCount(12).generate { palette ->
|
||||||
|
if (coverUrl != url || palette == null || isDestroyed) return@generate
|
||||||
|
val base = palette.getDarkMutedColor(palette.getMutedColor(palette.getDominantColor(BACKGROUND)))
|
||||||
|
animateGradient(ColorUtils.blendARGB(base, BACKGROUND, 0.2f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun animateGradient(target: Int) {
|
||||||
|
gradientAnimator?.cancel()
|
||||||
|
gradientAnimator = ValueAnimator.ofArgb(gradientColor, target).apply {
|
||||||
|
duration = 500
|
||||||
|
addUpdateListener { applyGradient(it.animatedValue as Int) }
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun applyGradient(color: Int) {
|
||||||
|
gradientColor = color
|
||||||
|
gradient.background = GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(color, BACKGROUND, BACKGROUND))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Warteschlange / Playlists
|
||||||
|
|
||||||
|
private fun openList(mode: ListMode) {
|
||||||
|
listMode = mode
|
||||||
|
listPanel.visibility = View.VISIBLE
|
||||||
|
listTitle.setText(if (mode == ListMode.QUEUE) R.string.pc_queue else R.string.pc_playlists)
|
||||||
|
itemAdapter.setRows(emptyList())
|
||||||
|
showListMessage(getString(R.string.pc_loading))
|
||||||
|
loadList(mode, scrollToCurrent = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun closeList() {
|
||||||
|
listMode = null
|
||||||
|
listPanel.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadList(mode: ListMode, scrollToCurrent: Boolean) {
|
||||||
|
val command = if (mode == ListMode.QUEUE) "queue" else "list_playlists"
|
||||||
|
PcSession.request(command, { if (mode == ListMode.QUEUE) put("target", PcSession.state.activeTab) }) { result ->
|
||||||
|
if (listMode != mode || isDestroyed) return@request
|
||||||
|
result.onSuccess { reply ->
|
||||||
|
if (mode == ListMode.QUEUE) {
|
||||||
|
queueItems = PcRemote.parseQueue(reply)
|
||||||
|
itemAdapter.setRows(
|
||||||
|
queueItems.map {
|
||||||
|
Row(it.title.ifBlank { "–" }, it.subtitle, it.thumbnail, R.drawable.ic_queue_music, it.current)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
showListMessage(if (queueItems.isEmpty()) getString(R.string.pc_queue_empty) else null)
|
||||||
|
if (scrollToCurrent) queueItems.indexOfFirst { it.current }.takeIf { it > 0 }?.let { itemList.setSelection(it) }
|
||||||
|
} else {
|
||||||
|
playlistItems = PcRemote.parsePlaylists(reply)
|
||||||
|
itemAdapter.setRows(playlistItems.map { Row(it.title, "", "", R.drawable.ic_library_music, false) })
|
||||||
|
showListMessage(if (playlistItems.isEmpty()) getString(R.string.pc_playlists_empty) else null)
|
||||||
|
}
|
||||||
|
}.onFailure { error ->
|
||||||
|
val text = if (PcRemote.isUnknownCommand(error.message)) {
|
||||||
|
getString(R.string.pc_update_pc)
|
||||||
|
} else {
|
||||||
|
getString(R.string.pc_list_error, error.message ?: error.javaClass.simpleName)
|
||||||
|
}
|
||||||
|
showListMessage(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showListMessage(text: String?) {
|
||||||
|
listMessage.text = text.orEmpty()
|
||||||
|
listMessage.visibility = if (text == null) View.GONE else View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onListItemClicked(position: Int) {
|
||||||
|
when (listMode) {
|
||||||
|
ListMode.QUEUE -> {
|
||||||
|
if (position !in queueItems.indices) return
|
||||||
|
PcSession.send("play_queue_item", target = PcSession.state.activeTab, value = position.toDouble())
|
||||||
|
// Sofort markieren; kurz darauf ist die Liste vom PC neu geladen.
|
||||||
|
itemAdapter.setHighlight(position)
|
||||||
|
main.postDelayed({ if (listMode == ListMode.QUEUE) loadList(ListMode.QUEUE, scrollToCurrent = false) }, 1500)
|
||||||
|
}
|
||||||
|
ListMode.PLAYLISTS -> {
|
||||||
|
val playlist = playlistItems.getOrNull(position) ?: return
|
||||||
|
PcSession.request("play_playlist", { put("playlist", playlist.id) })
|
||||||
|
closeList()
|
||||||
|
}
|
||||||
|
null -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Hilfen
|
||||||
|
|
||||||
|
private fun padded(view: View): View =
|
||||||
|
LinearLayout(this).apply {
|
||||||
|
val pad = (20 * resources.displayMetrics.density).toInt()
|
||||||
|
setPadding(pad, pad / 2, pad, 0)
|
||||||
|
addView(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** SeekBar-Listener mit leeren Standardmethoden. */
|
||||||
|
private open class SeekBarListener : SeekBar.OnSeekBarChangeListener {
|
||||||
|
override fun onProgressChanged(bar: SeekBar, progress: Int, fromUser: Boolean) {}
|
||||||
|
override fun onStartTrackingTouch(bar: SeekBar) {}
|
||||||
|
override fun onStopTrackingTouch(bar: SeekBar) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Eine Zeile in Geraete-, Warteschlangen- und Playlist-Listen. */
|
||||||
|
private data class Row(
|
||||||
|
val title: String,
|
||||||
|
val subtitle: String,
|
||||||
|
val imageUrl: String = "",
|
||||||
|
val iconRes: Int = 0,
|
||||||
|
val highlighted: Boolean = false,
|
||||||
|
)
|
||||||
|
|
||||||
|
private class RowAdapter(private val context: Context) : BaseAdapter() {
|
||||||
|
private var rows = listOf<Row>()
|
||||||
|
private val pink = ContextCompat.getColor(context, R.color.brand_to)
|
||||||
|
private val white = ContextCompat.getColor(context, R.color.text)
|
||||||
|
private val density = context.resources.displayMetrics.density
|
||||||
|
|
||||||
|
fun setRows(new: List<Row>) {
|
||||||
|
rows = new
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setHighlight(position: Int) {
|
||||||
|
rows = rows.mapIndexed { i, row -> row.copy(highlighted = i == position) }
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCount() = rows.size
|
||||||
|
override fun getItem(position: Int) = rows[position]
|
||||||
|
override fun getItemId(position: Int) = position.toLong()
|
||||||
|
|
||||||
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
|
val view = convertView ?: LayoutInflater.from(context).inflate(R.layout.item_row, parent, false)
|
||||||
|
val row = rows[position]
|
||||||
|
val title = view.findViewById<TextView>(R.id.rowTitle)
|
||||||
|
val subtitle = view.findViewById<TextView>(R.id.rowSubtitle)
|
||||||
|
val image = view.findViewById<ImageView>(R.id.rowImage)
|
||||||
|
title.text = row.title
|
||||||
|
title.setTextColor(if (row.highlighted) pink else white)
|
||||||
|
subtitle.text = row.subtitle
|
||||||
|
subtitle.visibility = if (row.subtitle.isEmpty()) View.GONE else View.VISIBLE
|
||||||
|
|
||||||
|
image.tag = row.imageUrl
|
||||||
|
image.scaleType = ImageView.ScaleType.CENTER
|
||||||
|
image.setImageResource(row.iconRes)
|
||||||
|
image.imageTintList = android.content.res.ColorStateList.valueOf(ContextCompat.getColor(context, R.color.text_muted))
|
||||||
|
if (row.imageUrl.isNotEmpty()) {
|
||||||
|
ImageCache.load(row.imageUrl, (48 * density).toInt()) { bitmap ->
|
||||||
|
if (bitmap != null && image.tag == row.imageUrl) {
|
||||||
|
image.imageTintList = null
|
||||||
|
image.scaleType = ImageView.ScaleType.CENTER_CROP
|
||||||
|
image.setImageBitmap(bitmap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val BACKGROUND = Color.parseColor("#121212")
|
||||||
|
|
||||||
|
fun start(context: Context) {
|
||||||
|
context.startActivity(Intent(context, PcRemoteActivity::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.ServiceInfo
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.IBinder
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.media.app.NotificationCompat.MediaStyle
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Haelt die Verbindung zum PC ("Steuert <PC>"): Vordergrunddienst mit Benachrichtigung (Cover, Titel,
|
||||||
|
* Zurueck / Play-Pause / Vor, Trennen). Beruehrt die Wiedergabe auf dem Handy nicht - es gibt hier
|
||||||
|
* keine Media-Session und keinen Audiofokus. Die eigentliche Arbeit macht [PcSession].
|
||||||
|
*/
|
||||||
|
class PcRemoteService : Service(), PcSession.Listener {
|
||||||
|
private var cover: Bitmap? = null
|
||||||
|
private var coverUrl = ""
|
||||||
|
private var shownKey = ""
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
val manager = getSystemService(NotificationManager::class.java)
|
||||||
|
manager.createNotificationChannel(
|
||||||
|
NotificationChannel(CHANNEL_ID, getString(R.string.channel_pc_remote), NotificationManager.IMPORTANCE_LOW),
|
||||||
|
)
|
||||||
|
PcSession.addListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
when (intent?.action) {
|
||||||
|
ACTION_DISCONNECT -> {
|
||||||
|
PcSession.disconnect()
|
||||||
|
stopSelf()
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
ACTION_PREVIOUS -> PcSession.send("previous")
|
||||||
|
ACTION_PLAY_PAUSE -> PcSession.send("play_pause")
|
||||||
|
ACTION_NEXT -> PcSession.send("next")
|
||||||
|
}
|
||||||
|
if (PcSession.phase == PcSession.Phase.IDLE && intent?.action != null) {
|
||||||
|
stopSelf()
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
startInForeground(buildNotification())
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startInForeground(notification: Notification) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 29) {
|
||||||
|
startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE)
|
||||||
|
} else {
|
||||||
|
startForeground(NOTIFICATION_ID, notification)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
PcSession.removeListener(this)
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Listener
|
||||||
|
|
||||||
|
override fun onUpdate() {
|
||||||
|
if (PcSession.phase == PcSession.Phase.IDLE) {
|
||||||
|
stopSelf()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val state = PcSession.state
|
||||||
|
if (state.thumbnail != coverUrl) {
|
||||||
|
coverUrl = state.thumbnail
|
||||||
|
cover = null
|
||||||
|
if (coverUrl.isNotEmpty()) {
|
||||||
|
val url = coverUrl
|
||||||
|
ImageCache.load(url, COVER_PX) { bitmap ->
|
||||||
|
if (coverUrl == url && bitmap != null) {
|
||||||
|
cover = bitmap
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onProblem(problem: PcSession.Problem, message: String) {}
|
||||||
|
|
||||||
|
/** Nur neu zeichnen, wenn sich etwas Sichtbares geaendert hat (jede Sekunde ein Status kommt an). */
|
||||||
|
private fun refresh() {
|
||||||
|
val state = PcSession.state
|
||||||
|
val key = "${PcSession.phase}|${PcSession.device?.name}|${state.title}|${state.subtitle}|${state.playing}|${cover != null}"
|
||||||
|
if (key == shownKey) return
|
||||||
|
shownKey = key
|
||||||
|
getSystemService(NotificationManager::class.java).notify(NOTIFICATION_ID, buildNotification())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildNotification(): Notification {
|
||||||
|
val name = PcSession.device?.name.orEmpty()
|
||||||
|
val state = PcSession.state
|
||||||
|
val reconnecting = PcSession.phase == PcSession.Phase.RECONNECTING
|
||||||
|
val text = when {
|
||||||
|
reconnecting -> getString(R.string.pc_reconnecting)
|
||||||
|
state.title.isBlank() -> getString(R.string.pc_nothing_playing)
|
||||||
|
state.subtitle.isBlank() -> state.title
|
||||||
|
else -> "${state.title} – ${state.subtitle}"
|
||||||
|
}
|
||||||
|
val open = PendingIntent.getActivity(
|
||||||
|
this, 0, Intent(this, PcRemoteActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
|
||||||
|
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
|
||||||
|
)
|
||||||
|
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
|
||||||
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
|
.setContentTitle(getString(R.string.pc_controlling, name))
|
||||||
|
.setContentText(text)
|
||||||
|
.setLargeIcon(cover)
|
||||||
|
.setContentIntent(open)
|
||||||
|
.setOnlyAlertOnce(true)
|
||||||
|
.setOngoing(true)
|
||||||
|
.setShowWhen(false)
|
||||||
|
.setCategory(NotificationCompat.CATEGORY_TRANSPORT)
|
||||||
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
|
.addAction(R.drawable.ic_skip_previous, getString(R.string.action_previous), action(ACTION_PREVIOUS, 1))
|
||||||
|
.addAction(
|
||||||
|
if (state.playing) R.drawable.ic_pause else R.drawable.ic_play,
|
||||||
|
getString(if (state.playing) R.string.action_pause else R.string.action_play),
|
||||||
|
action(ACTION_PLAY_PAUSE, 2),
|
||||||
|
)
|
||||||
|
.addAction(R.drawable.ic_skip_next, getString(R.string.action_next), action(ACTION_NEXT, 3))
|
||||||
|
.addAction(0, getString(R.string.pc_disconnect), action(ACTION_DISCONNECT, 4))
|
||||||
|
.setStyle(MediaStyle().setShowActionsInCompactView(0, 1, 2))
|
||||||
|
return builder.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun action(action: String, requestCode: Int): PendingIntent =
|
||||||
|
PendingIntent.getService(
|
||||||
|
this, requestCode, Intent(this, PcRemoteService::class.java).setAction(action),
|
||||||
|
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
|
||||||
|
)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val CHANNEL_ID = "pc_remote"
|
||||||
|
private const val NOTIFICATION_ID = 2
|
||||||
|
private const val COVER_PX = 256
|
||||||
|
private const val ACTION_PREVIOUS = "de.fojadrachi.playtube.PC_PREVIOUS"
|
||||||
|
private const val ACTION_PLAY_PAUSE = "de.fojadrachi.playtube.PC_PLAY_PAUSE"
|
||||||
|
private const val ACTION_NEXT = "de.fojadrachi.playtube.PC_NEXT"
|
||||||
|
private const val ACTION_DISCONNECT = "de.fojadrachi.playtube.PC_DISCONNECT"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,319 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.io.IOException
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
import java.util.concurrent.RejectedExecutionException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Verbindung zum PC ueberlebt den Steuerungsbildschirm (wie Spotify Connect): sie lebt hier im
|
||||||
|
* Prozess, gehalten von [PcRemoteService] (Vordergrunddienst + Benachrichtigung). Verbindung, Status-
|
||||||
|
* Abfrage und Befehle laufen auf einem eigenen Thread; Aufrufer und Listener sind immer der Hauptthread.
|
||||||
|
*/
|
||||||
|
object PcSession {
|
||||||
|
enum class Phase { IDLE, CONNECTING, CONNECTED, RECONNECTING }
|
||||||
|
enum class Problem { PAIRING_REQUIRED, FAILED, LOST }
|
||||||
|
|
||||||
|
interface Listener {
|
||||||
|
fun onUpdate()
|
||||||
|
fun onProblem(problem: Problem, message: String)
|
||||||
|
}
|
||||||
|
|
||||||
|
const val PREFS = "pc_remote"
|
||||||
|
const val KEY_TOKEN_FOR = "token:"
|
||||||
|
const val KEY_NAME_FOR = "name:"
|
||||||
|
const val KEY_LAST_HOST = "last_host"
|
||||||
|
|
||||||
|
private const val POLL_VISIBLE_MS = 1_000L
|
||||||
|
private const val POLL_BACKGROUND_MS = 4_000L
|
||||||
|
private const val RECONNECT_ATTEMPTS = 5
|
||||||
|
|
||||||
|
private val main = Handler(Looper.getMainLooper())
|
||||||
|
private val worker: ExecutorService = Executors.newSingleThreadExecutor()
|
||||||
|
private val listeners = mutableListOf<Listener>()
|
||||||
|
|
||||||
|
/** Nur auf [worker] benutzen. */
|
||||||
|
private var connection: PcRemote.Connection? = null
|
||||||
|
private var statusPending = false
|
||||||
|
private var generation = 0
|
||||||
|
private var reconnectAttempt = 0
|
||||||
|
private lateinit var appContext: Context
|
||||||
|
|
||||||
|
var phase = Phase.IDLE
|
||||||
|
private set
|
||||||
|
var device: PcDevice? = null
|
||||||
|
private set
|
||||||
|
var state: PcState = PcState.EMPTY
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** Verbunden oder gerade dabei (Player soll angezeigt werden). */
|
||||||
|
val isActive: Boolean get() = phase == Phase.CONNECTED || phase == Phase.RECONNECTING
|
||||||
|
|
||||||
|
fun prefs(context: Context): SharedPreferences = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Listener / Polling
|
||||||
|
|
||||||
|
fun addListener(listener: Listener) {
|
||||||
|
listeners += listener
|
||||||
|
if (listeners.size == 1 && phase == Phase.CONNECTED) {
|
||||||
|
main.removeCallbacks(poll)
|
||||||
|
main.post(poll) // sofort frischen Stand holen, danach im 1-s-Takt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeListener(listener: Listener) {
|
||||||
|
listeners -= listener
|
||||||
|
}
|
||||||
|
|
||||||
|
private val poll = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
if (phase != Phase.CONNECTED) return
|
||||||
|
requestStatus()
|
||||||
|
main.postDelayed(this, if (listeners.isEmpty()) POLL_BACKGROUND_MS else POLL_VISIBLE_MS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun notifyUpdate() = listeners.toList().forEach { it.onUpdate() }
|
||||||
|
|
||||||
|
private fun notifyProblem(problem: Problem, message: String) =
|
||||||
|
listeners.toList().forEach { it.onProblem(problem, message) }
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Verbinden / Trennen
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verbindet mit [target]: mit [code] wird neu gekoppelt, sonst mit dem gespeicherten [token].
|
||||||
|
* Startet dabei den Vordergrunddienst, der die Verbindung haelt.
|
||||||
|
*/
|
||||||
|
fun connect(context: Context, target: PcDevice, token: String?, code: String?) {
|
||||||
|
appContext = context.applicationContext
|
||||||
|
val gen = ++generation
|
||||||
|
main.removeCallbacks(poll)
|
||||||
|
phase = Phase.CONNECTING
|
||||||
|
device = target
|
||||||
|
state = PcState.EMPTY
|
||||||
|
reconnectAttempt = 0
|
||||||
|
notifyUpdate()
|
||||||
|
ContextCompat.startForegroundService(appContext, Intent(appContext, PcRemoteService::class.java))
|
||||||
|
onWorker {
|
||||||
|
closeConnection()
|
||||||
|
try {
|
||||||
|
val conn = PcRemote.Connection.open(target)
|
||||||
|
val reply = try {
|
||||||
|
if (code != null) {
|
||||||
|
conn.request("pair") {
|
||||||
|
put("code", code)
|
||||||
|
put("device", Build.MODEL ?: "Android")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
conn.request("hello") { put("token", token.orEmpty()) }
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
conn.close()
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
connection = conn
|
||||||
|
main.post { if (gen == generation) onConnected(target, reply, code != null) else onWorker { conn.close() } }
|
||||||
|
} catch (e: PcRemote.RemoteException) {
|
||||||
|
main.post {
|
||||||
|
if (gen != generation) return@post
|
||||||
|
if (code == null) {
|
||||||
|
prefs(appContext).edit().remove(KEY_TOKEN_FOR + target.name).apply()
|
||||||
|
reset()
|
||||||
|
notifyProblem(Problem.PAIRING_REQUIRED, e.message.orEmpty())
|
||||||
|
} else {
|
||||||
|
reset()
|
||||||
|
notifyProblem(Problem.FAILED, e.message ?: "Fehler")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
Diagnostics.line("pc: Verbinden fehlgeschlagen: $e")
|
||||||
|
main.post {
|
||||||
|
if (gen != generation) return@post
|
||||||
|
reset()
|
||||||
|
notifyProblem(Problem.FAILED, e.message ?: e.javaClass.simpleName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onConnected(target: PcDevice, reply: JSONObject, paired: Boolean) {
|
||||||
|
// Der PC meldet seinen Namen - unter dem merken wir uns Token und Adresse.
|
||||||
|
val name = reply.optString("name").ifBlank { target.name }
|
||||||
|
val token = if (paired) reply.optString("token") else prefs(appContext).getString(KEY_TOKEN_FOR + target.name, null)
|
||||||
|
prefs(appContext).edit().apply {
|
||||||
|
if (!token.isNullOrEmpty()) {
|
||||||
|
putString(KEY_TOKEN_FOR + target.name, token)
|
||||||
|
putString(KEY_TOKEN_FOR + name, token)
|
||||||
|
}
|
||||||
|
putString(KEY_NAME_FOR + target.host, name)
|
||||||
|
putString(KEY_LAST_HOST, target.host)
|
||||||
|
}.apply()
|
||||||
|
device = target.copy(name = name)
|
||||||
|
phase = Phase.CONNECTED
|
||||||
|
notifyUpdate()
|
||||||
|
main.removeCallbacks(poll)
|
||||||
|
main.post(poll)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Trennt bewusst (Knopf "Trennen") und beendet den Dienst. */
|
||||||
|
fun disconnect() {
|
||||||
|
reset()
|
||||||
|
notifyUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun reset() {
|
||||||
|
generation++
|
||||||
|
main.removeCallbacks(poll)
|
||||||
|
main.removeCallbacks(reconnectRunnable)
|
||||||
|
phase = Phase.IDLE
|
||||||
|
device = null
|
||||||
|
state = PcState.EMPTY
|
||||||
|
statusPending = false
|
||||||
|
onWorker { closeConnection() }
|
||||||
|
if (::appContext.isInitialized) appContext.stopService(Intent(appContext, PcRemoteService::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Verbindungsverlust
|
||||||
|
|
||||||
|
private fun onConnectionLost() {
|
||||||
|
if (phase != Phase.CONNECTED) return
|
||||||
|
phase = Phase.RECONNECTING
|
||||||
|
reconnectAttempt = 0
|
||||||
|
main.removeCallbacks(poll)
|
||||||
|
notifyUpdate()
|
||||||
|
scheduleReconnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val reconnectRunnable = Runnable { reconnect() }
|
||||||
|
|
||||||
|
private fun scheduleReconnect() {
|
||||||
|
main.postDelayed(reconnectRunnable, 2_000L * (reconnectAttempt + 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun reconnect() {
|
||||||
|
val target = device ?: return
|
||||||
|
if (phase != Phase.RECONNECTING) return
|
||||||
|
val token = prefs(appContext).getString(KEY_TOKEN_FOR + target.name, null)
|
||||||
|
val gen = generation
|
||||||
|
reconnectAttempt++
|
||||||
|
onWorker {
|
||||||
|
closeConnection()
|
||||||
|
try {
|
||||||
|
val conn = PcRemote.Connection.open(target)
|
||||||
|
try {
|
||||||
|
conn.request("hello") { put("token", token.orEmpty()) }
|
||||||
|
} catch (e: IOException) {
|
||||||
|
conn.close()
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
connection = conn
|
||||||
|
main.post {
|
||||||
|
if (gen != generation || phase != Phase.RECONNECTING) return@post
|
||||||
|
phase = Phase.CONNECTED
|
||||||
|
notifyUpdate()
|
||||||
|
main.removeCallbacks(poll)
|
||||||
|
main.post(poll)
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
main.post {
|
||||||
|
if (gen != generation || phase != Phase.RECONNECTING) return@post
|
||||||
|
if (e is PcRemote.RemoteException || reconnectAttempt >= RECONNECT_ATTEMPTS) {
|
||||||
|
val name = device?.name.orEmpty()
|
||||||
|
reset()
|
||||||
|
notifyUpdate()
|
||||||
|
notifyProblem(Problem.LOST, name)
|
||||||
|
} else {
|
||||||
|
scheduleReconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ Befehle und Stand
|
||||||
|
|
||||||
|
private fun requestStatus() {
|
||||||
|
// Bei langsamem WLAN nicht eine Abfrage pro Sekunde aufstauen.
|
||||||
|
if (statusPending) return
|
||||||
|
statusPending = true
|
||||||
|
val gen = generation
|
||||||
|
onWorker {
|
||||||
|
try {
|
||||||
|
val conn = connection
|
||||||
|
if (conn == null) {
|
||||||
|
main.post { statusPending = false }
|
||||||
|
return@onWorker
|
||||||
|
}
|
||||||
|
val next = PcRemote.parseState(conn.request("status"))
|
||||||
|
main.post {
|
||||||
|
statusPending = false
|
||||||
|
if (gen != generation || phase != Phase.CONNECTED) return@post
|
||||||
|
if (next != null) {
|
||||||
|
state = next
|
||||||
|
notifyUpdate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: IOException) {
|
||||||
|
closeConnection()
|
||||||
|
main.post {
|
||||||
|
statusPending = false
|
||||||
|
if (gen == generation) onConnectionLost()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Befehl ohne Antwort; danach wird der Stand neu abgefragt. */
|
||||||
|
fun send(command: String, target: String = "auto", value: Double? = null) {
|
||||||
|
request(command, {
|
||||||
|
put("target", target)
|
||||||
|
if (value != null) put("value", value)
|
||||||
|
}) { requestStatus() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Anfrage mit Antwort; [done] kommt auf dem Hauptthread (Fehler: RemoteException vom PC oder IOException). */
|
||||||
|
fun request(command: String, fill: JSONObject.() -> Unit = {}, done: (Result<JSONObject>) -> Unit = {}) {
|
||||||
|
val gen = generation
|
||||||
|
onWorker {
|
||||||
|
val conn = connection
|
||||||
|
if (conn == null) {
|
||||||
|
main.post { done(Result.failure(IOException("Nicht verbunden"))) }
|
||||||
|
return@onWorker
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
val reply = conn.request(command, fill)
|
||||||
|
main.post { done(Result.success(reply)) }
|
||||||
|
} catch (e: PcRemote.RemoteException) {
|
||||||
|
main.post { done(Result.failure(e)) } // Befehl abgelehnt - Verbindung bleibt
|
||||||
|
} catch (e: IOException) {
|
||||||
|
Diagnostics.line("pc: Verbindung verloren: $e")
|
||||||
|
closeConnection()
|
||||||
|
main.post {
|
||||||
|
if (gen == generation) onConnectionLost()
|
||||||
|
done(Result.failure(e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onWorker(block: () -> Unit) {
|
||||||
|
try {
|
||||||
|
worker.execute(block)
|
||||||
|
} catch (_: RejectedExecutionException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nur auf [worker] aufrufen. */
|
||||||
|
private fun closeConnection() {
|
||||||
|
connection?.close()
|
||||||
|
connection = null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,9 @@ data class PresencePlan(
|
|||||||
/** Schwankung des Startzeitpunkts durch die 1,5-s-Abfrage, die noch kein Spulen ist. */
|
/** Schwankung des Startzeitpunkts durch die 1,5-s-Abfrage, die noch kein Spulen ist. */
|
||||||
const val SEEK_TOLERANCE_MS = 4_000L
|
const val SEEK_TOLERANCE_MS = 4_000L
|
||||||
|
|
||||||
|
/** Discord akzeptiert Bildadressen nur bis 300 Zeichen. */
|
||||||
|
const val MAX_IMAGE_URL_LENGTH = 300
|
||||||
|
|
||||||
/** null = nichts anzeigen (nichts laeuft oder Pause). */
|
/** null = nichts anzeigen (nichts laeuft oder Pause). */
|
||||||
fun from(info: NowPlaying, nowMs: Long): PresencePlan? {
|
fun from(info: NowPlaying, nowMs: Long): PresencePlan? {
|
||||||
if (!info.hasTrack || !info.playing) return null
|
if (!info.hasTrack || !info.playing) return null
|
||||||
@@ -28,7 +31,7 @@ data class PresencePlan(
|
|||||||
return PresencePlan(
|
return PresencePlan(
|
||||||
details = info.title,
|
details = info.title,
|
||||||
state = info.artist,
|
state = info.artist,
|
||||||
artworkUrl = info.artworkUrl,
|
artworkUrl = info.artworkUrl?.takeIf { it.length <= MAX_IMAGE_URL_LENGTH },
|
||||||
startMs = start,
|
startMs = start,
|
||||||
endMs = if (info.durationMs > 0) start + info.durationMs else 0L,
|
endMs = if (info.durationMs > 0) start + info.durationMs else 0L,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<gradient android:angle="0" android:startColor="@color/brand_from" android:endColor="@color/brand_to" />
|
||||||
|
<corners android:radius="10dp" />
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="#17171D" />
|
||||||
|
<stroke android:width="1dp" android:color="#2A2A34" />
|
||||||
|
<corners android:radius="14dp" />
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="#1F1F27" />
|
||||||
|
<stroke android:width="1dp" android:color="#2A2A34" />
|
||||||
|
<corners android:radius="10dp" />
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="#33FFFFFF" />
|
||||||
|
<corners android:radius="22dp" />
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<gradient
|
||||||
|
android:angle="135"
|
||||||
|
android:endColor="@color/brand_to"
|
||||||
|
android:startColor="@color/brand_from" />
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<solid android:color="#FFFFFF" />
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="#2A2A2A" />
|
||||||
|
<corners android:radius="6dp" />
|
||||||
|
</shape>
|
||||||
@@ -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="#FFFFFFFF"
|
||||||
|
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
|
||||||
|
</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="#FFAAAAAA"
|
||||||
|
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M20,18c1.1,0 1.99,-0.9 1.99,-2L22,6c0,-1.1 -0.9,-2 -2,-2H4c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2H0v2h24v-2h-4zM4,6h16v10H4V6z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Krone: "Zum Host machen" in der Teilnehmerliste des Jams -->
|
||||||
|
<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="#FFAAAAAA"
|
||||||
|
android:pathData="M5,16L3,5l5.5,5L12,4l3.5,6L21,5l-2,11H5zM19,19c0,0.6 -0.4,1 -1,1H6c-0.6,0 -1,-0.4 -1,-1v-1h14v1z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M16.5,3c-1.74,0 -3.41,0.81 -4.5,2.09C10.91,3.81 9.24,3 7.5,3 4.42,3 2,5.42 2,8.5c0,3.78 3.4,6.86 8.55,11.54L12,21.35l1.45,-1.32C18.6,15.36 22,12.28 22,8.5 22,5.42 19.58,3 16.5,3zm-4.4,15.55l-0.1,0.1 -0.1,-0.1C7.14,14.24 4,11.39 4,8.5 4,6.5 5.5,5 7.5,5c1.54,0 3.04,0.99 3.57,2.36h1.87C13.46,5.99 14.96,5 16.5,5c2,0 3.5,1.5 3.5,3.5 0,2.89 -3.14,5.74 -7.9,10.05z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Playtube Jam: zwei Personen mit Note (Material "group") -->
|
||||||
|
<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="#FFFFFFFF"
|
||||||
|
android:pathData="M16,11c1.66,0 2.99,-1.34 2.99,-3S17.66,5 16,5c-1.66,0 -3,1.34 -3,3s1.34,3 3,3zM8,11c1.66,0 2.99,-1.34 2.99,-3S9.66,5 8,5C6.34,5 5,6.34 5,8s1.34,3 3,3zM8,13c-2.33,0 -7,1.17 -7,3.5V19h14v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5zM16,13c-0.29,0 -0.62,0.02 -0.97,0.05 1.16,0.84 1.97,1.97 1.97,3.45V19h6v-2.5c0,-2.33 -4.67,-3.5 -7,-3.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="#FFFFFFFF"
|
||||||
|
android:pathData="M7.41,8.59L12,13.17l4.59,-4.58L18,10l-6,6 -6,-6 1.41,-1.41z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M20,2H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2zm-2,5h-3v5.5c0,1.38 -1.12,2.5 -2.5,2.5S10,13.88 10,12.5s1.12,-2.5 2.5,-2.5c0.57,0 1.08,0.19 1.5,0.51V5h4v2zM4,6H2v14c0,1.1 0.9,2 2,2h14v-2H4V6z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Daumen hoch (Material "thumb_up"). Farbe setzt PcRemoteActivity je nach Like-Status. -->
|
||||||
|
<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="#FFFFFFFF"
|
||||||
|
android:pathData="M1,21h4L5,9L1,9v12zM23,10c0,-1.1 -0.9,-2 -2,-2h-6.31l0.95,-4.57 0.03,-0.32c0,-0.41 -0.17,-0.79 -0.44,-1.06L14.17,1 7.59,7.59C7.22,7.95 7,8.45 7,9v10c0,1.1 0.9,2 2,2h9c0.83,0 1.54,-0.5 1.84,-1.22l3.02,-7.05c0.09,-0.23 0.14,-0.47 0.14,-0.73v-2z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M6,19h4V5H6v14zm8,-14v14h4V5h-4z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Bildschirm mit Wellen (Material "cast"): "Auf dem PC steuern". -->
|
||||||
|
<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="#FFFFFFFF"
|
||||||
|
android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v3h2L3,5h18v14h-7v2h7c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM1,18v3h3c0,-1.66 -1.34,-3 -3,-3zM1,14v2c2.76,0 5,2.24 5,5h2c0,-3.87 -3.13,-7 -7,-7zM1,10v2c4.97,0 9,4.03 9,9h2c0,-6.08 -4.93,-11 -11,-11z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M8,5v14l11,-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="#FFFFFFFF"
|
||||||
|
android:pathData="M15,6H3v2h12V6zm0,4H3v2h12v-2zM3,16h8v-2H3v2zM17,6v8.18c-0.31,-0.11 -0.65,-0.18 -1,-0.18 -1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3V8h3V6h-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="#FFFFFFFF"
|
||||||
|
android:pathData="M7,7h10v3l4,-4 -4,-4v3H5v6h2V7zm10,10H7v-3l-4,4 4,4v-3h12v-6h-2v4z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M7,7h10v3l4,-4 -4,-4v3H5v6h2V7zm10,10H7v-3l-4,4 4,4v-3h12v-6h-2v4zm-4,-2V9h-1l-2,1v1h1.5v4H13z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Einstellungen (Material "settings") -->
|
||||||
|
<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="#FFFFFFFF"
|
||||||
|
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Icon der Verknuepfung "PC steuern": weisses Symbol auf dem Playtube-Verlauf. -->
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:drawable="@drawable/bg_play_button" />
|
||||||
|
<item
|
||||||
|
android:bottom="12dp"
|
||||||
|
android:drawable="@drawable/ic_pc_remote"
|
||||||
|
android:left="12dp"
|
||||||
|
android:right="12dp"
|
||||||
|
android:top="12dp" />
|
||||||
|
</layer-list>
|
||||||
@@ -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="#FFFFFFFF"
|
||||||
|
android:pathData="M10.59,9.17L5.41,4 4,5.41l5.17,5.17 1.42,-1.41zM14.5,4l2.04,2.04L4,18.59 5.41,20 17.96,7.46 20,9.5V4h-5.5zm0.33,9.41l-1.41,1.41 3.13,3.13L14.5,20H20v-5.5l-2.04,2.04 -3.13,-3.13z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M6,18l8.5,-6L6,6v12zM16,6v12h2V6h-2z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M6,6h2v12H6zm3.5,6l8.5,6V6z" />
|
||||||
|
</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="#FFFFFFFF"
|
||||||
|
android:pathData="M3,9v6h4l5,5V4L7,9H3zm13.5,3c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14,3.23v2.06c2.89,0.86 5,3.54 5,6.71s-2.11,5.85 -5,6.71v2.06c4.01,-0.91 7,-4.49 7,-8.77s-2.99,-7.86 -7,-8.77z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,495 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Playtube Jam (JamActivity): dunkel, Lila/Pink wie "PC steuern". -->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/jamRoot"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/remote_background"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingEnd="16dp">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/jamBack"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/pc_back_to_player"
|
||||||
|
android:src="@drawable/ic_keyboard_arrow_down" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/jam_title"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/jamLeave"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/jam_leave"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:fillViewport="true">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingBottom="24dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamStatus"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<!-- Noch in keinem Jam -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/jamSetup"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/bg_card"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/jam_intro"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/jamName"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:background="@drawable/bg_input"
|
||||||
|
android:hint="@string/jam_name_hint"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="textPersonName|textCapWords"
|
||||||
|
android:maxLength="32"
|
||||||
|
android:paddingStart="12dp"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textColorHint="@color/text_muted" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/jamStart"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:background="@drawable/bg_brand_button"
|
||||||
|
android:text="@string/jam_start"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:text="@string/jam_start_hint"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/jamCode"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_input"
|
||||||
|
android:hint="@string/jam_code_hint"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="textCapCharacters|textNoSuggestions"
|
||||||
|
android:maxLength="60"
|
||||||
|
android:paddingStart="12dp"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textColorHint="@color/text_muted" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/jamJoin"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:background="@drawable/bg_brand_button"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:text="@string/jam_join"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Im Jam -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/jamPanel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<!-- Läuft gerade -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/bg_card"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/jamCover"
|
||||||
|
android:layout_width="96dp"
|
||||||
|
android:layout_height="54dp"
|
||||||
|
android:background="@drawable/bg_tile"
|
||||||
|
android:contentDescription="@string/pc_cover"
|
||||||
|
android:scaleType="centerCrop" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamNowTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamNowArtist"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamCantPlay"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="@string/jam_cant_play_here"
|
||||||
|
android:textColor="#FCA5A5"
|
||||||
|
android:textSize="13sp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/jamSeek"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:max="1000"
|
||||||
|
android:progressTint="@color/brand_to"
|
||||||
|
android:thumbTint="@color/text" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamTime"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamDuration"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/jamPrevious"
|
||||||
|
android:layout_width="56dp"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/jam_previous"
|
||||||
|
android:src="@drawable/ic_skip_previous" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/jamPlayPause"
|
||||||
|
android:layout_width="64dp"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:background="@drawable/bg_play_button"
|
||||||
|
android:contentDescription="@string/jam_play_pause"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:src="@drawable/ic_play" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/jamNext"
|
||||||
|
android:layout_width="56dp"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/jam_next"
|
||||||
|
android:src="@drawable/ic_skip_next" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Hinzufügen und Warteschlange -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:background="@drawable/bg_card"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/jamAddInput"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_input"
|
||||||
|
android:hint="@string/jam_add_hint"
|
||||||
|
android:imeOptions="actionGo"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="text"
|
||||||
|
android:maxLength="200"
|
||||||
|
android:paddingStart="12dp"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textColorHint="@color/text_muted" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/jamAddButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:background="@drawable/bg_brand_button"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:text="@string/jam_add"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:text="@string/jam_add_hint_share"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/jamResults"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:text="@string/jam_queue"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/jamQueue"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Einladen -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:background="@drawable/bg_card"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/jam_invite"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamInviteCode"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:letterSpacing="0.1"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="28sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamInviteLink"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
android:textSize="13sp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/jamShare"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_brand_button"
|
||||||
|
android:text="@string/jam_share"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/text" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/jamCopy"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_input"
|
||||||
|
android:text="@string/jam_copy"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/text" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Nur für den Host -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/jamHostBox"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:background="@drawable/bg_card"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
android:id="@+id/jamAllControl"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/jam_all_control"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/jamEnd"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:text="@string/jam_end"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="#F87171" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Teilnehmer -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:background="@drawable/bg_card"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/jam_members"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/jamMembers"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:text="@string/jam_play_hint"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
</LinearLayout>
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/root"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/background">
|
android:background="@color/system_bars">
|
||||||
|
|
||||||
<WebView
|
<WebView
|
||||||
android:id="@+id/webView"
|
android:id="@+id/webView"
|
||||||
@@ -18,4 +19,49 @@
|
|||||||
android:max="100"
|
android:max="100"
|
||||||
android:progressTint="@color/brand_to"
|
android:progressTint="@color/brand_to"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<!-- "PC steuern" (PcRemoteActivity). Am rechten Rand mittig: dort liegen bei YouTube Music
|
||||||
|
keine festen Bedienelemente (oben Kopfzeile, unten Player und Navigation). -->
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/pcRemoteButton"
|
||||||
|
android:layout_width="44dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_gravity="end|center_vertical"
|
||||||
|
android:layout_marginEnd="6dp"
|
||||||
|
android:alpha="0.85"
|
||||||
|
android:background="@drawable/bg_play_button"
|
||||||
|
android:contentDescription="@string/pc_open"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:src="@drawable/ic_pc_remote" />
|
||||||
|
|
||||||
|
<!-- Playtube Jam (JamActivity): direkt unter "PC steuern". -->
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/jamButton"
|
||||||
|
android:layout_width="44dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_gravity="end|center_vertical"
|
||||||
|
android:layout_marginTop="56dp"
|
||||||
|
android:layout_marginEnd="6dp"
|
||||||
|
android:alpha="0.85"
|
||||||
|
android:background="@drawable/bg_play_button"
|
||||||
|
android:contentDescription="@string/jam_open"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:src="@drawable/ic_jam" />
|
||||||
|
|
||||||
|
<!-- Einstellungen (Diagnosedaten): unter dem Jam-Knopf, etwas kleiner. -->
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/settingsButton"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_gravity="end|center_vertical"
|
||||||
|
android:layout_marginTop="108dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:alpha="0.7"
|
||||||
|
android:background="@drawable/bg_play_button"
|
||||||
|
android:contentDescription="@string/settings_open"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:src="@drawable/ic_settings" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|||||||
@@ -0,0 +1,461 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/remoteRoot"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/remote_background">
|
||||||
|
|
||||||
|
<!-- Farbverlauf aus der Cover-Farbe -->
|
||||||
|
<View
|
||||||
|
android:id="@+id/gradient"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
<!-- Geraeteliste: PCs im WLAN -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/devicePanel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/deviceBack"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/pc_back_to_player"
|
||||||
|
android:src="@drawable/ic_keyboard_arrow_down"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/remoteHeading"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/pc_title"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/remoteStatus"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/deviceList"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:divider="@null"
|
||||||
|
android:dividerHeight="0dp"
|
||||||
|
android:scrollbars="none" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="@string/pc_hint"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="13sp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/searchButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/pc_search" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/manualButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/pc_manual" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/disconnectButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:text="@string/pc_disconnect"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Player im Stil einer Streaming-Fernbedienung -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/playerPanel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="24dp"
|
||||||
|
android:paddingEnd="24dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/closeButton"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/pc_close"
|
||||||
|
android:src="@drawable/ic_keyboard_arrow_down" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pc_playing_on"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="11sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/deviceName"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/devicesButton"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/pc_devices"
|
||||||
|
android:src="@drawable/ic_computer" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/tabYoutube"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="YouTube"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="13sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/tabMusic"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="YouTube Music"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="13sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/coverBox"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/cover"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="200dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/bg_tile"
|
||||||
|
android:contentDescription="@string/pc_cover"
|
||||||
|
android:scaleType="centerCrop" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/trackTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="22sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/trackSubtitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/likeButton"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/pc_like"
|
||||||
|
android:src="@drawable/ic_favorite_border" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/positionBar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="-16dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="-16dp"
|
||||||
|
android:progressBackgroundTint="#55FFFFFF"
|
||||||
|
android:progressTint="@color/text"
|
||||||
|
android:thumbTint="@color/text" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/positionText"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/durationText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/shuffleButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/pc_shuffle"
|
||||||
|
android:src="@drawable/ic_shuffle" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/previousButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/action_previous"
|
||||||
|
android:scaleType="center"
|
||||||
|
android:src="@drawable/ic_skip_previous" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/playPauseButton"
|
||||||
|
android:layout_width="72dp"
|
||||||
|
android:layout_height="72dp"
|
||||||
|
android:background="@drawable/bg_play_white"
|
||||||
|
android:contentDescription="@string/action_play"
|
||||||
|
android:src="@drawable/ic_play"
|
||||||
|
android:tint="#000000" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/nextButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/action_next"
|
||||||
|
android:scaleType="center"
|
||||||
|
android:src="@drawable/ic_skip_next" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/repeatButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/pc_repeat"
|
||||||
|
android:src="@drawable/ic_repeat" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:contentDescription="@string/pc_volume"
|
||||||
|
android:src="@drawable/ic_volume_up"
|
||||||
|
android:tint="@color/text_muted" />
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/volumeBar"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:max="100"
|
||||||
|
android:progressBackgroundTint="#55FFFFFF"
|
||||||
|
android:progressTint="@color/text"
|
||||||
|
android:thumbTint="@color/text" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/queueButton"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_pill"
|
||||||
|
android:drawableStart="@drawable/ic_queue_music"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:drawableTint="@color/text"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:text="@string/pc_queue"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/playlistsButton"
|
||||||
|
style="?android:attr/borderlessButtonStyle"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_pill"
|
||||||
|
android:drawableStart="@drawable/ic_library_music"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:drawableTint="@color/text"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:text="@string/pc_playlists"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Vollbild-Liste: Warteschlange oder Playlists -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/listPanel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/remote_background"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingEnd="16dp">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/listBack"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/pc_back_to_player"
|
||||||
|
android:src="@drawable/ic_keyboard_arrow_down" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/listTitle"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/listMessage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/itemList"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:divider="@null"
|
||||||
|
android:dividerHeight="0dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Zeile im Jam: Titel (Vorschaubild) oder Teilnehmer (Anfangsbuchstabe), dazu bis zu zwei Knöpfe. -->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:minHeight="56dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingTop="6dp"
|
||||||
|
android:paddingBottom="6dp">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/jamRowImage"
|
||||||
|
android:layout_width="64dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:background="@drawable/bg_tile"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
android:scaleType="centerCrop" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamRowAvatar"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:background="@drawable/bg_play_button"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamRowTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/jamRowSubtitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/jamRowAction1"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/jamRowAction2"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</LinearLayout>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:minHeight="64dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/rowImage"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:background="@drawable/bg_tile"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
android:padding="0dp"
|
||||||
|
android:scaleType="centerCrop" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="14dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/rowTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/rowSubtitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/text_muted"
|
||||||
|
android:textSize="13sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
@@ -13,15 +13,155 @@
|
|||||||
<string name="update_download">Herunterladen</string>
|
<string name="update_download">Herunterladen</string>
|
||||||
<string name="update_later">Später</string>
|
<string name="update_later">Später</string>
|
||||||
|
|
||||||
|
<!-- PC steuern (PcRemoteActivity) -->
|
||||||
|
<string name="pc_title">PC steuern</string>
|
||||||
|
<string name="pc_shortcut">PC steuern</string>
|
||||||
|
<string name="pc_open">Playtube auf dem PC steuern</string>
|
||||||
|
<string name="pc_searching">Suche Playtube-PCs im WLAN …</string>
|
||||||
|
<string name="pc_found">Tippe auf einen PC, um ihn zu steuern.</string>
|
||||||
|
<string name="pc_none_found">Kein PC gefunden.</string>
|
||||||
|
<string name="pc_hint">Am PC in Playtube unter Einstellungen › „Steuerung vom Handy“ einschalten. Handy und PC müssen im selben WLAN sein.</string>
|
||||||
|
<string name="pc_search">Erneut suchen</string>
|
||||||
|
<string name="pc_manual">IP-Adresse eingeben</string>
|
||||||
|
<string name="pc_manual_hint">z. B. 192.168.178.20</string>
|
||||||
|
<string name="pc_connect">Verbinden</string>
|
||||||
|
<string name="pc_cancel">Abbrechen</string>
|
||||||
|
<string name="pc_pair_title">Mit %1$s koppeln</string>
|
||||||
|
<string name="pc_pair_message">Am PC in Playtube unter Einstellungen › „Steuerung vom Handy“ auf „Handy koppeln“ tippen und den 6-stelligen Code hier eingeben.</string>
|
||||||
|
<string name="pc_pair_hint">Code</string>
|
||||||
|
<string name="pc_pair">Koppeln</string>
|
||||||
|
<string name="pc_connecting">Verbinde mit %1$s …</string>
|
||||||
|
<string name="pc_connected">Verbunden mit %1$s</string>
|
||||||
|
<string name="pc_error">Verbindung fehlgeschlagen: %1$s</string>
|
||||||
|
<string name="pc_lost">Verbindung zu %1$s verloren.</string>
|
||||||
|
<string name="pc_nothing_playing">Gerade läuft nichts</string>
|
||||||
|
<string name="pc_disconnect">Trennen</string>
|
||||||
|
<string name="pc_cover">Cover</string>
|
||||||
|
<string name="pc_like">Gefällt mir</string>
|
||||||
|
<string name="pc_volume">Lautstärke</string>
|
||||||
|
|
||||||
|
<string name="channel_pc_remote">PC steuern</string>
|
||||||
|
<string name="pc_controlling">Steuert %1$s</string>
|
||||||
|
<string name="pc_reconnecting">Verbinde neu …</string>
|
||||||
|
<string name="pc_back_to_player">Zurück zum Player</string>
|
||||||
|
<string name="pc_close">Schließen</string>
|
||||||
|
<string name="pc_playing_on">Spielt auf</string>
|
||||||
|
<string name="pc_devices">Geräte</string>
|
||||||
|
<string name="pc_shuffle">Zufällige Wiedergabe</string>
|
||||||
|
<string name="pc_repeat">Wiederholen</string>
|
||||||
|
<string name="pc_queue">Warteschlange</string>
|
||||||
|
<string name="pc_playlists">Playlists</string>
|
||||||
|
<string name="pc_loading">Lade …</string>
|
||||||
|
<string name="pc_queue_empty">Die Warteschlange ist leer.</string>
|
||||||
|
<string name="pc_playlists_empty">Keine Playlists gefunden. Bist du in YouTube Music am PC angemeldet?</string>
|
||||||
|
<string name="pc_update_pc">Am PC Playtube auf 2.1.0 aktualisieren, um die Warteschlange zu sehen.</string>
|
||||||
|
<string name="pc_list_error">Das hat nicht geklappt: %1$s</string>
|
||||||
|
<string name="pc_this_pc">Verbunden</string>
|
||||||
|
|
||||||
|
<!-- Playtube Jam (JamActivity, JamHub) -->
|
||||||
|
<string name="jam_title">Jam</string>
|
||||||
|
<string name="jam_open">Playtube Jam: gemeinsam hören</string>
|
||||||
|
<string name="jam_intro">Hört gemeinsam wie bei Spotify Jam: jeder auf seinem eigenen Gerät, synchron, und alle wünschen sich Songs. Freunde ohne Playtube machen über den Link im Browser mit.</string>
|
||||||
|
<string name="jam_name_hint">Dein Name</string>
|
||||||
|
<string name="jam_start">Jam starten</string>
|
||||||
|
<string name="jam_start_hint">Läuft gerade ein Song, wird er der erste im Jam.</string>
|
||||||
|
<string name="jam_code_hint">Code oder Einladungslink</string>
|
||||||
|
<string name="jam_join">Beitreten</string>
|
||||||
|
<string name="jam_invite">Freunde einladen</string>
|
||||||
|
<string name="jam_share">Link teilen</string>
|
||||||
|
<string name="jam_copy">Kopieren</string>
|
||||||
|
<string name="jam_copied">Link kopiert.</string>
|
||||||
|
<string name="jam_share_text">Hör mit mir in Playtube Jam: %1$s</string>
|
||||||
|
<string name="jam_all_control">Alle dürfen steuern</string>
|
||||||
|
<string name="jam_end">Jam beenden</string>
|
||||||
|
<string name="jam_end_confirm">Jam für alle beenden?</string>
|
||||||
|
<string name="jam_leave">Verlassen</string>
|
||||||
|
<string name="jam_members">Dabei</string>
|
||||||
|
<string name="jam_queue">Als Nächstes</string>
|
||||||
|
<string name="jam_queue_empty">Die Warteschlange ist leer.</string>
|
||||||
|
<string name="jam_add">Hinzufügen</string>
|
||||||
|
<string name="jam_search">Suchen</string>
|
||||||
|
<string name="jam_add_hint">YouTube-Link oder Video-ID</string>
|
||||||
|
<string name="jam_search_hint">Song suchen oder Link einfügen</string>
|
||||||
|
<string name="jam_add_hint_share">Tipp: In der YouTube-App „Teilen“ › Playtube wählen.</string>
|
||||||
|
<string name="jam_nothing">Noch läuft nichts – füge den ersten Song hinzu.</string>
|
||||||
|
<string name="jam_cant_play_here">Dieser Titel lässt sich hier nicht abspielen (z. B. Region) – er läuft bei den anderen weiter.</string>
|
||||||
|
<string name="jam_by">von %1$s</string>
|
||||||
|
<string name="jam_host">Host</string>
|
||||||
|
<string name="jam_you">%1$s (du)</string>
|
||||||
|
<string name="jam_offline">offline</string>
|
||||||
|
<string name="jam_cant_play">kann diesen Titel nicht abspielen</string>
|
||||||
|
<string name="jam_client_pc">Playtube PC</string>
|
||||||
|
<string name="jam_client_android">Android</string>
|
||||||
|
<string name="jam_client_web">Browser</string>
|
||||||
|
<string name="jam_kick">Entfernen</string>
|
||||||
|
<string name="jam_kick_confirm">%1$s aus dem Jam entfernen?</string>
|
||||||
|
<string name="jam_make_host">Zum Host machen</string>
|
||||||
|
<string name="jam_make_host_confirm">%1$s zum Host machen? Du gibst damit die Host-Rechte ab.</string>
|
||||||
|
<string name="jam_error_offline">Diese Person ist gerade nicht verbunden.</string>
|
||||||
|
<string name="jam_play_now">Jetzt spielen</string>
|
||||||
|
<string name="jam_remove">Entfernen</string>
|
||||||
|
<string name="jam_added">Hinzugefügt: %1$s</string>
|
||||||
|
<string name="jam_added_shared">Zum Jam hinzugefügt.</string>
|
||||||
|
<string name="jam_playlist_adding">Playlist wird hinzugefügt …</string>
|
||||||
|
<string name="jam_error_playlist">Diese Playlist ist nicht öffentlich oder existiert nicht.</string>
|
||||||
|
<string name="jam_share_no_jam">Du bist gerade in keinem Jam. Starte einen oder tritt einem bei.</string>
|
||||||
|
<string name="jam_play_hint">Die Musik läuft im Player von Playtube. Du kannst dort weiter in YouTube Music stöbern: Tippst du einen Song an, landet er wie bei Spotify im Jam. Mit Steuerrecht wirken Play/Pause und Weiter dort und in der Benachrichtigung für alle.</string>
|
||||||
|
<string name="jam_status_creating">Jam wird gestartet …</string>
|
||||||
|
<string name="jam_status_joining">Verbinde …</string>
|
||||||
|
<string name="jam_status_connected">Verbunden.</string>
|
||||||
|
<string name="jam_status_reconnecting">Verbindung unterbrochen – verbinde neu …</string>
|
||||||
|
<string name="jam_status_bad_code">Das ist kein gültiger Code (6 Zeichen).</string>
|
||||||
|
<string name="jam_status_not_found">Diesen Jam gibt es nicht (mehr).</string>
|
||||||
|
<string name="jam_status_failed">Keine Verbindung zum Jam-Server.</string>
|
||||||
|
<string name="jam_status_need_name">Bitte gib zuerst deinen Namen ein.</string>
|
||||||
|
<string name="jam_status_in_other">Du bist schon in einem Jam – verlasse ihn zuerst.</string>
|
||||||
|
<string name="jam_ended_host">Der Host hat den Jam beendet.</string>
|
||||||
|
<string name="jam_ended_over">Der Jam ist zu Ende.</string>
|
||||||
|
<string name="jam_ended_expired">Der Jam ist abgelaufen.</string>
|
||||||
|
<string name="jam_ended_kicked">Du wurdest aus dem Jam entfernt.</string>
|
||||||
|
<string name="jam_ended_left">Du hast den Jam verlassen.</string>
|
||||||
|
<string name="jam_ended_full">Der Jam ist voll.</string>
|
||||||
|
<string name="jam_error_not_allowed">Das darf nur der Host.</string>
|
||||||
|
<string name="jam_error_queue_full">Die Warteschlange ist voll.</string>
|
||||||
|
<string name="jam_error_bad_video">Das ist kein YouTube-Link.</string>
|
||||||
|
<string name="jam_error_rate_limited">Langsam – zu viele Aktionen auf einmal.</string>
|
||||||
|
<string name="jam_error_search">Die Suche geht gerade nicht.</string>
|
||||||
|
<string name="jam_error_other">Fehler: %1$s</string>
|
||||||
|
<string name="jam_previous">Zurück</string>
|
||||||
|
<string name="jam_next">Weiter</string>
|
||||||
|
<string name="jam_play_pause">Wiedergabe umschalten</string>
|
||||||
|
|
||||||
|
<color name="remote_background">#121212</color>
|
||||||
<color name="background">#0F0F0F</color>
|
<color name="background">#0F0F0F</color>
|
||||||
|
<color name="surface">#1F1F1F</color>
|
||||||
|
<color name="text">#FFFFFF</color>
|
||||||
|
<color name="text_muted">#AAAAAA</color>
|
||||||
|
<color name="system_bars">#000000</color>
|
||||||
<color name="brand_from">#7C3AED</color>
|
<color name="brand_from">#7C3AED</color>
|
||||||
<color name="brand_to">#EC4899</color>
|
<color name="brand_to">#EC4899</color>
|
||||||
|
|
||||||
<style name="Theme.Playtube" parent="Theme.AppCompat.NoActionBar">
|
<style name="Theme.Playtube" parent="Theme.AppCompat.NoActionBar">
|
||||||
<item name="android:windowBackground">@color/background</item>
|
<item name="android:windowBackground">@color/background</item>
|
||||||
<item name="android:statusBarColor">@color/background</item>
|
<item name="android:statusBarColor">@color/system_bars</item>
|
||||||
<item name="android:navigationBarColor">@color/background</item>
|
<item name="android:navigationBarColor">@color/system_bars</item>
|
||||||
<item name="colorPrimary">@color/brand_from</item>
|
<item name="colorPrimary">@color/brand_from</item>
|
||||||
<item name="colorAccent">@color/brand_to</item>
|
<item name="colorAccent">@color/brand_to</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- Einstellungen / Diagnose -->
|
||||||
|
<string name="settings_open">Einstellungen</string>
|
||||||
|
<string name="settings_title">Playtube-Einstellungen</string>
|
||||||
|
<string name="diag_enabled">Diagnosedaten senden (hilft, Fehler zu finden)</string>
|
||||||
|
<string name="diag_hint">Gesendet werden Fehlermeldungen und Abstürze aus dem Playtube-Log, App- und Android-Version sowie das Gerätemodell mit einer zufälligen Kennung – keine Cookies, Anmeldedaten, Suchanfragen, Songtitel oder Video-IDs. Gespeichert 30 Tage. Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag</string>
|
||||||
|
<string name="diag_install_id">Kennung dieser Installation: %1$s</string>
|
||||||
|
<string name="diag_send_now">Jetzt senden</string>
|
||||||
|
<string name="diag_done">Fertig</string>
|
||||||
|
<string name="diag_sent">Diagnosedaten gesendet.</string>
|
||||||
|
<string name="diag_nothing">Keine neuen Einträge seit dem letzten Bericht.</string>
|
||||||
|
<string name="diag_failed">Senden fehlgeschlagen.</string>
|
||||||
|
<string name="diag_notice_title">Diagnosedaten</string>
|
||||||
|
<string name="diag_notice_message">Damit Fehler schneller behoben werden, sendet Playtube Fehlermeldungen und Abstürze (ohne Cookies, Anmeldedaten, Suchanfragen oder Songtitel) an den Playtube-Server. Du kannst das jederzeit über das Zahnrad abschalten.</string>
|
||||||
|
<string name="diag_notice_ok">OK</string>
|
||||||
|
<string name="diag_notice_off">Abschalten</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<shortcut
|
||||||
|
android:enabled="true"
|
||||||
|
android:icon="@drawable/ic_shortcut_pc_remote"
|
||||||
|
android:shortcutId="pc_remote"
|
||||||
|
android:shortcutShortLabel="@string/pc_shortcut">
|
||||||
|
<intent
|
||||||
|
android:action="android.intent.action.VIEW"
|
||||||
|
android:targetClass="de.fojadrachi.playtube.PcRemoteActivity"
|
||||||
|
android:targetPackage="de.fojadrachi.playtube" />
|
||||||
|
</shortcut>
|
||||||
|
</shortcuts>
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class DiagReportTest {
|
||||||
|
@Test
|
||||||
|
fun removesPrivateData() {
|
||||||
|
val cases = mapOf(
|
||||||
|
"Cookie: SAPISID=abc; HSID=def" to "cookie [entfernt]",
|
||||||
|
"jam: lade dQw4w9WgXcQ" to "jam: lade [video]",
|
||||||
|
"GET https://music.youtube.com/search?q=lieblingssong ok" to "GET https://music.youtube.com/search?[…] ok",
|
||||||
|
"token=abcdef123 weiter" to "token=[entfernt] weiter",
|
||||||
|
"{\"last_token\":\"xyz\"}" to "{\"last_token\":\"[entfernt]\"}",
|
||||||
|
"Mail [email protected]" to "Mail [e-mail]",
|
||||||
|
"Playlist PLabcdefghij1234567890XYZ" to "Playlist [id]",
|
||||||
|
"Sende Bearer eyJhbGciOiJIUzI1NiJ9" to "Sende Bearer [entfernt]",
|
||||||
|
)
|
||||||
|
for ((input, expected) in cases) assertEquals(input, expected, DiagReport.sanitize(input))
|
||||||
|
assertEquals("Jam: Verbindung fehlgeschlagen", DiagReport.sanitize("Jam: Verbindung fehlgeschlagen"))
|
||||||
|
assertEquals("a b", DiagReport.sanitize("a\u0000b"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun removesIdsWithoutDigitsAndJsonTitles() {
|
||||||
|
assertEquals("jam: lade [video]", DiagReport.sanitize("jam: lade JZYXtUJcTws"))
|
||||||
|
assertEquals(
|
||||||
|
"Player: {\"artist\":\"[entfernt]\",\"id\":\"[video]\",\"title\":\"[entfernt]\",\"paused\":true}",
|
||||||
|
DiagReport.sanitize("Player: {\"artist\":\"Band\",\"id\":\"Rlg9P5i1bkQ\",\"title\":\"Mein Song\",\"paused\":true}"),
|
||||||
|
)
|
||||||
|
assertEquals("Verbindunge ServerError PlaytubeApp", DiagReport.sanitize("Verbindunge ServerError PlaytubeApp"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun recognizesVideoIds() {
|
||||||
|
assertTrue(DiagReport.looksLikeVideoId("dQw4w9WgXcQ"))
|
||||||
|
assertFalse(DiagReport.looksLikeVideoId("Verbindunge"))
|
||||||
|
assertFalse(DiagReport.looksLikeVideoId("12345678901"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun collectsOnlyNewLines() {
|
||||||
|
val log = "[100] alt\n[200] Jam: Verbindung fehlgeschlagen\nkaputt\n[202] neu\n"
|
||||||
|
val collected = DiagReport.collect(log, 100)
|
||||||
|
assertEquals(listOf("[200] Jam: Verbindung fehlgeschlagen", "[202] neu"), collected.lines)
|
||||||
|
assertEquals(202L, collected.latest)
|
||||||
|
assertTrue(DiagReport.collect(log, 202).lines.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun keepsTheNewestLines() {
|
||||||
|
val log = (1..1000).joinToString("\n") { "[$it] Zeile $it" }
|
||||||
|
val lines = DiagReport.collect(log, 0).lines
|
||||||
|
assertEquals(DiagReport.MAX_LINES, lines.size)
|
||||||
|
assertEquals("[701] Zeile 701", lines.first())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun manualReportWithoutLinesHasNote() {
|
||||||
|
assertEquals("manuell gesendet (keine neuen Einträge)", DiagReport.note(manual = true, noNewLines = true))
|
||||||
|
assertEquals("manuell gesendet", DiagReport.note(manual = true, noNewLines = false))
|
||||||
|
assertEquals("", DiagReport.note(manual = false, noNewLines = true))
|
||||||
|
val report = DiagReport.build("abc123abc123", "1.6.1", "15", "Google Pixel 9", emptyList(), DiagReport.note(true, true))
|
||||||
|
assertEquals(0, report.getJSONArray("lines").length())
|
||||||
|
assertTrue(report.getString("note").isNotEmpty()) // sonst lehnt der Server den Bericht als leer ab
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun buildsReport() {
|
||||||
|
val lines = listOf("[1] Absturz in main: java.lang.IllegalStateException", "[2] ok")
|
||||||
|
val report = DiagReport.build("abc123abc123", "1.6.0", "15", "Google Pixel 9", lines)
|
||||||
|
assertEquals("android", report.getString("app"))
|
||||||
|
assertEquals("android-15", report.getString("platform"))
|
||||||
|
assertEquals(1, report.getJSONArray("errors").length())
|
||||||
|
assertFalse(report.getBoolean("includesTitles"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import de.fojadrachi.playtube.JamSync.Local
|
||||||
|
import de.fojadrachi.playtube.JamSync.Step
|
||||||
|
import de.fojadrachi.playtube.JamSync.Target
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class JamSyncTest {
|
||||||
|
@Test
|
||||||
|
fun `liest Codes und Einladungslinks`() {
|
||||||
|
assertEquals("ABC234", JamSync.normalizeCode("abc-234"))
|
||||||
|
assertEquals("ABC234", JamSync.normalizeCode(" ABC 234 "))
|
||||||
|
assertEquals("ABC234", JamSync.normalizeCode("https://jam.fojadrachi.de/abc234"))
|
||||||
|
assertEquals("ABC234", JamSync.normalizeCode("https://jam.fojadrachi.de/ABC234/?x=1"))
|
||||||
|
assertEquals("ABC234", JamSync.normalizeCode("playtube://jam/ABC234"))
|
||||||
|
assertNull(JamSync.normalizeCode("ABC10O"))
|
||||||
|
assertNull(JamSync.normalizeCode("ABC23"))
|
||||||
|
assertNull(JamSync.normalizeCode(null))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `liest Video-IDs aus Links und geteiltem Text`() {
|
||||||
|
val id = "dQw4w9WgXcQ"
|
||||||
|
for (input in listOf(
|
||||||
|
id,
|
||||||
|
"https://www.youtube.com/watch?v=$id&list=RD",
|
||||||
|
"https://music.youtube.com/watch?v=$id",
|
||||||
|
"https://youtu.be/$id?si=abc",
|
||||||
|
"youtube.com/shorts/$id",
|
||||||
|
"https://m.youtube.com/watch?feature=share&v=$id",
|
||||||
|
)) {
|
||||||
|
assertEquals(input, id, JamSync.parseVideoId(input))
|
||||||
|
}
|
||||||
|
assertNull(JamSync.parseVideoId("https://evil.example/watch?v=$id"))
|
||||||
|
assertNull(JamSync.parseVideoId("kurz"))
|
||||||
|
assertEquals(id, JamSync.videoIdFromSharedText("Hör dir das an: https://youtu.be/$id?si=x"))
|
||||||
|
assertNull(JamSync.videoIdFromSharedText("kein Link hier"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `gleicht kleine Abweichungen ueber das Tempo aus`() {
|
||||||
|
val want = JamSync.Target("aaaaaaaaaaa", "i", 30.0, false, 200.0)
|
||||||
|
fun local(pos: Double, rate: Double = 1.0, paused: Boolean = false) = JamSync.Local("aaaaaaaaaaa", pos, paused, rate)
|
||||||
|
assertEquals(listOf(JamSync.Step.Rate(0.92)), JamSync.decide(want, local(30.4)))
|
||||||
|
assertEquals(listOf(JamSync.Step.Rate(1.05)), JamSync.decide(want, local(29.8)))
|
||||||
|
assertEquals(listOf(JamSync.Step.Rate(1.0)), JamSync.decide(want, local(30.01, rate = 1.05)))
|
||||||
|
assertEquals(emptyList<JamSync.Step>(), JamSync.decide(want, local(30.05)))
|
||||||
|
assertEquals(
|
||||||
|
listOf(JamSync.Step.Seek(30.0 + JamSync.SEEK_LEAD_S), JamSync.Step.Rate(1.0)),
|
||||||
|
JamSync.decide(want, local(34.0, rate = 1.08)),
|
||||||
|
)
|
||||||
|
assertEquals(0.988, JamSync.nudgeRate(0.05, 1.02), 1e-9)
|
||||||
|
assertEquals(1.0, JamSync.nudgeRate(0.05, 1.0), 1e-9)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `liest Playlist-Links`() {
|
||||||
|
assertEquals("PLabc_1", JamSync.parsePlaylistId("https://music.youtube.com/playlist?list=PLabc_1"))
|
||||||
|
assertEquals("RDxyz", JamSync.parsePlaylistId("https://www.youtube.com/watch?v=dQw4w9WgXcQ&list=RDxyz"))
|
||||||
|
assertEquals("OLAK5uy_abc", JamSync.parsePlaylistId("OLAK5uy_abc"))
|
||||||
|
assertEquals("PLabc", JamSync.parsePlaylistId("VLPLabc"))
|
||||||
|
assertNull(JamSync.parsePlaylistId("https://evil.example/playlist?list=PLabc"))
|
||||||
|
assertNull(JamSync.parsePlaylistId("queen"))
|
||||||
|
assertEquals("PLabc", JamSync.playlistIdFromSharedText("Hör mal: https://music.youtube.com/playlist?list=PLabc"))
|
||||||
|
assertNull(JamSync.playlistIdFromSharedText("https://youtu.be/dQw4w9WgXcQ?list=PLabc"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `liest den Zustand des Servers`() {
|
||||||
|
val state = JamSync.parseState(
|
||||||
|
JSONObject(
|
||||||
|
"""{"t":"state","code":"ABC234","you":"m2","hostId":"m1","allControl":false,"canControl":false,
|
||||||
|
"features":{"search":true},
|
||||||
|
"members":[{"id":"m1","name":"Chris","client":"pc","online":true,"host":true,"cantPlay":false}],
|
||||||
|
"current":{"id":"i1","videoId":"dQw4w9WgXcQ","title":"T","artist":"A","thumb":"x","dur":212,"by":"m1","byName":"Chris"},
|
||||||
|
"queue":[{"id":"i2","videoId":"aaaaaaaaaaa","title":"U","dur":null}],"history":[],
|
||||||
|
"playback":{"paused":false,"position":10,"ref":1000},"serverNow":6000}""",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assertFalse(state.isHost)
|
||||||
|
assertTrue(state.search)
|
||||||
|
assertEquals(212.0, state.current!!.dur!!, 0.0)
|
||||||
|
assertNull(state.queue[0].dur)
|
||||||
|
assertEquals("Chris", state.members[0].name)
|
||||||
|
val want = JamSync.target(state, 6000.0)!!
|
||||||
|
assertEquals(15.0, want.pos, 1e-9)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Zeitabgleich nimmt die schnellste Messung`() {
|
||||||
|
val clock = JamSync.Clock()
|
||||||
|
clock.hint(9000.0, 1000.0)
|
||||||
|
assertEquals(8000.0, clock.offset, 0.0)
|
||||||
|
clock.add(1000.0, 6050.0, 1100.0)
|
||||||
|
clock.add(2000.0, 7900.0, 2800.0)
|
||||||
|
clock.add(3000.0, 8010.0, 3020.0)
|
||||||
|
assertEquals(5000.0, clock.offset, 0.0)
|
||||||
|
clock.add(5000.0, 0.0, 4000.0)
|
||||||
|
assertEquals(5000.0, clock.offset, 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun want(pos: Double, paused: Boolean = false) = Target("aaaaaaaaaaa", "i", pos, paused, 200.0)
|
||||||
|
private fun local(id: String?, pos: Double, paused: Boolean) = Local(id, pos, paused)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Nachzuegler laden an der richtigen Stelle`() {
|
||||||
|
assertEquals(listOf(Step.Load("aaaaaaaaaaa", 42.5)), JamSync.decide(want(42.5), local("bbbbbbbbbbb", 3.0, false)))
|
||||||
|
assertEquals(listOf(Step.Load("aaaaaaaaaaa", 0.0), Step.Pause), JamSync.decide(want(-1.0), local(null, 0.0, true)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `warten am Start, Pause und Play uebernehmen`() {
|
||||||
|
val id = "aaaaaaaaaaa"
|
||||||
|
assertEquals(listOf(Step.Pause, Step.Seek(0.0)), JamSync.decide(want(-1.0), local(id, 2.0, false)))
|
||||||
|
assertEquals(listOf(Step.Pause), JamSync.decide(want(30.0, paused = true), local(id, 30.2, false)))
|
||||||
|
assertEquals(listOf(Step.Play), JamSync.decide(want(30.0), local(id, 30.2, true)))
|
||||||
|
assertEquals(listOf(Step.Pause), JamSync.decide(null, local(id, 3.0, false)))
|
||||||
|
assertTrue(JamSync.decide(null, local(null, 0.0, true)).isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `spult erst ab der Toleranz`() {
|
||||||
|
val id = "aaaaaaaaaaa"
|
||||||
|
assertTrue(JamSync.decide(want(30.0), local(id, 30.05, false)).isEmpty())
|
||||||
|
assertEquals(listOf(Step.Seek(30.0 + JamSync.SEEK_LEAD_S)), JamSync.decide(want(30.0), local(id, 34.0, false)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `laedt am Titelende nicht den alten Titel neu`() {
|
||||||
|
assertEquals(listOf(Step.Pause), JamSync.decide(want(198.5), local("zzzzzzzzzzz", 1.0, false)))
|
||||||
|
assertTrue(JamSync.decide(want(198.0), local("aaaaaaaaaaa", 199.9, false)).isEmpty())
|
||||||
|
assertTrue(JamSync.reachedEnd(local("a", 199.5, false), 200.0, false))
|
||||||
|
assertFalse(JamSync.reachedEnd(local("a", 150.0, false), 200.0, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `in YouTube Music gestartete Songs kommen in den Jam`() {
|
||||||
|
val item = { id: String, video: String -> JamSync.Item(id, video, "", "", "", 200.0, "", "") }
|
||||||
|
val state = JamSync.State(
|
||||||
|
"ABC234", "m1", "m1", false, true, false, emptyList(),
|
||||||
|
current = item("i1", "aaaaaaaaaaa"), queue = emptyList(), history = listOf(item("i0", "hhhhhhhhhhh")),
|
||||||
|
playback = JamSync.Playback(false, 30.0, 0.0), serverNow = 0.0,
|
||||||
|
)
|
||||||
|
val w = want(30.0)
|
||||||
|
assertEquals("bbbbbbbbbbb", JamSync.userPick(state, w, local("bbbbbbbbbbb", 1.0, false), ""))
|
||||||
|
assertNull(JamSync.userPick(state, w, local("aaaaaaaaaaa", 30.0, false), ""))
|
||||||
|
assertNull(JamSync.userPick(state, w, local("hhhhhhhhhhh", 1.0, false), ""))
|
||||||
|
assertNull(JamSync.userPick(state, w, local("bbbbbbbbbbb", 1.0, true), ""))
|
||||||
|
assertNull(JamSync.userPick(state, w, local("bbbbbbbbbbb", 1.0, false), "bbbbbbbbbbb"))
|
||||||
|
assertNull(JamSync.userPick(state, want(198.5), local("zzzzzzzzzzz", 1.0, false), ""))
|
||||||
|
val empty = state.copy(current = null, history = emptyList())
|
||||||
|
assertEquals("bbbbbbbbbbb", JamSync.userPick(empty, null, local("bbbbbbbbbbb", 1.0, false), ""))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Steuerskripte nutzen die Player-API`() {
|
||||||
|
assertTrue(JamSync.playScript(true).contains("p.playVideo()"))
|
||||||
|
assertTrue(JamSync.playScript(false).contains("p.pauseVideo()"))
|
||||||
|
assertTrue(JamSync.seekScript(12.5).contains("var s=12.5;"))
|
||||||
|
assertTrue(JamSync.seekScript(-4.0).contains("var s=0.0;"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `formatiert Zeit und Code`() {
|
||||||
|
assertEquals("0:00", JamSync.formatTime(0.0))
|
||||||
|
assertEquals("1:05", JamSync.formatTime(65.9))
|
||||||
|
assertEquals("1:02:05", JamSync.formatTime(3725.0))
|
||||||
|
assertEquals("ABC 234", JamSync.prettyCode("ABC234"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package de.fojadrachi.playtube
|
||||||
|
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class PcRemoteTest {
|
||||||
|
@Test
|
||||||
|
fun parsesDiscoveryReply() {
|
||||||
|
val device = PcRemote.parseDiscoveryReply(
|
||||||
|
"""{"service": "playtube", "protocol": 1, "name": "MEIN-PC", "port": 47811}""",
|
||||||
|
"192.168.1.20",
|
||||||
|
)
|
||||||
|
assertEquals(PcDevice("MEIN-PC", "192.168.1.20", 47811), device)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ignoresForeignOrBrokenDiscoveryReplies() {
|
||||||
|
assertNull(PcRemote.parseDiscoveryReply("""{"service": "other", "port": 1}""", "1.2.3.4"))
|
||||||
|
assertNull(PcRemote.parseDiscoveryReply("""{"service": "playtube", "port": 70000}""", "1.2.3.4"))
|
||||||
|
assertNull(PcRemote.parseDiscoveryReply("kein json", "1.2.3.4"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun usesHostWhenNameIsMissing() {
|
||||||
|
val device = PcRemote.parseDiscoveryReply("""{"service": "playtube"}""", "10.0.0.2")
|
||||||
|
assertEquals(PcDevice("10.0.0.2", "10.0.0.2", PcRemote.DEFAULT_PORT), device)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun parsesStateOfTheActiveTab() {
|
||||||
|
val reply = JSONObject(
|
||||||
|
"""
|
||||||
|
{"id": 3, "ok": true, "state": {
|
||||||
|
"protocol": 1, "visibleTab": "youtube", "activeTab": "music",
|
||||||
|
"tabs": {
|
||||||
|
"youtube": null,
|
||||||
|
"music": {"title": "Song", "subtitle": "Artist", "thumbnail": "https://i.ytimg.com/x.jpg",
|
||||||
|
"playing": true, "currentTime": 61.5, "duration": 200, "volume": 42,
|
||||||
|
"likeStatus": "LIKE"}
|
||||||
|
}}}
|
||||||
|
""".trimIndent(),
|
||||||
|
)
|
||||||
|
val state = PcRemote.parseState(reply)!!
|
||||||
|
assertEquals("music", state.activeTab)
|
||||||
|
assertEquals("youtube", state.visibleTab)
|
||||||
|
assertEquals("Song", state.title)
|
||||||
|
assertEquals("Artist", state.subtitle)
|
||||||
|
assertEquals("https://i.ytimg.com/x.jpg", state.thumbnail)
|
||||||
|
assertTrue(state.playing)
|
||||||
|
assertEquals(61.5, state.position, 0.001)
|
||||||
|
assertEquals(200.0, state.duration, 0.001)
|
||||||
|
assertEquals(42, state.volume)
|
||||||
|
assertTrue(state.liked)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun handlesEmptyTabsAndNulls() {
|
||||||
|
val reply = JSONObject(
|
||||||
|
"""{"ok": true, "state": {"activeTab": "youtube", "tabs": {"youtube": {"title": null,
|
||||||
|
"thumbnail": "http://unsicher", "currentTime": null}, "music": null}}}""",
|
||||||
|
)
|
||||||
|
val state = PcRemote.parseState(reply)!!
|
||||||
|
assertEquals("", state.title)
|
||||||
|
assertEquals("", state.thumbnail)
|
||||||
|
assertEquals(0.0, state.position, 0.001)
|
||||||
|
assertFalse(state.playing)
|
||||||
|
assertNull(PcRemote.parseState(JSONObject("""{"ok": true}""")))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun requestsLargeCovers() {
|
||||||
|
assertEquals(
|
||||||
|
"https://lh3.googleusercontent.com/abc=w544-h544-l90-rj",
|
||||||
|
PcRemote.largeCover("https://lh3.googleusercontent.com/abc=w60-h60-l90-rj"),
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"https://yt3.ggpht.com/xyz=w544-h544-l90-rj",
|
||||||
|
PcRemote.largeCover("https://yt3.ggpht.com/xyz=s88-c-k-c0x00ffffff-no-rj"),
|
||||||
|
)
|
||||||
|
assertEquals("https://i.ytimg.com/vi/id/hqdefault.jpg", PcRemote.largeCover("https://i.ytimg.com/vi/id/default.jpg"))
|
||||||
|
assertEquals("https://i.ytimg.com/vi/id/hqdefault.jpg", PcRemote.largeCover("https://i.ytimg.com/vi/id/hqdefault.jpg"))
|
||||||
|
assertEquals("https://example.com/a.png", PcRemote.largeCover("https://example.com/a.png"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun formatsTimes() {
|
||||||
|
assertEquals("0:00", PcRemote.formatTime(-5.0))
|
||||||
|
assertEquals("1:05", PcRemote.formatTime(65.9))
|
||||||
|
assertEquals("1:01:01", PcRemote.formatTime(3661.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun parsesQueueAndKeepsOrder() {
|
||||||
|
val reply = JSONObject(
|
||||||
|
"""{"ok": true, "queue": [
|
||||||
|
{"title": "A", "subtitle": "X", "thumbnail": "https://lh3.googleusercontent.com/a=w60-h60-l90-rj", "current": true},
|
||||||
|
{"title": "", "subtitle": "leer"},
|
||||||
|
{"title": "B", "thumbnail": "http://unsicher", "current": false}
|
||||||
|
]}""",
|
||||||
|
)
|
||||||
|
val queue = PcRemote.parseQueue(reply)
|
||||||
|
assertEquals(3, queue.size)
|
||||||
|
assertEquals(QueueItem("A", "X", "https://lh3.googleusercontent.com/a=w226-h226-l90-rj", true), queue[0])
|
||||||
|
assertEquals(QueueItem("", "leer", "", false), queue[1])
|
||||||
|
assertEquals(QueueItem("B", "", "", false), queue[2])
|
||||||
|
assertTrue(PcRemote.parseQueue(JSONObject("""{"ok": true}""")).isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun parsesPlaylists() {
|
||||||
|
val reply = JSONObject("""{"ok": true, "playlists": [{"id": "LM", "title": "Mag ich"}, {"id": "PL1"}, {"title": "x"}]}""")
|
||||||
|
assertEquals(listOf(PcPlaylist("LM", "Mag ich"), PcPlaylist("PL1", "PL1")), PcRemote.parsePlaylists(reply))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun recognisesOldPcsWithoutQueue() {
|
||||||
|
assertTrue(PcRemote.isUnknownCommand("unbekannter Befehl: queue"))
|
||||||
|
assertFalse(PcRemote.isUnknownCommand("Falscher Code"))
|
||||||
|
assertFalse(PcRemote.isUnknownCommand(null))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun readsRepeatMode() {
|
||||||
|
val reply = JSONObject("""{"ok": true, "state": {"activeTab": "music", "tabs": {"music": {"repeatMode": "one"}}}}""")
|
||||||
|
assertEquals("ONE", PcRemote.parseState(reply)!!.repeatMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,12 +24,18 @@ $ErrorActionPreference = "Stop"
|
|||||||
|
|
||||||
$token = $env:GITEA_TOKEN
|
$token = $env:GITEA_TOKEN
|
||||||
if (-not $token) {
|
if (-not $token) {
|
||||||
# Alternativ aus einer lokalen Datei (nur fuer deinen Benutzer): %USERPROFILE%\.gitea-token
|
# Alternativ aus einer lokalen Datei (nur fuer deinen Benutzer):
|
||||||
$tokenFile = Join-Path $env:USERPROFILE ".gitea-token"
|
# %USERPROFILE%\.secrets\gitea-token.txt (Vorlage, Anleitung in gitea-token.example.txt)
|
||||||
if (Test-Path $tokenFile) { $token = (Get-Content -Raw $tokenFile).Trim() }
|
# %USERPROFILE%\.gitea-token (aelterer Ort)
|
||||||
|
foreach ($tokenFile in @((Join-Path $env:USERPROFILE ".secrets\gitea-token.txt"), (Join-Path $env:USERPROFILE ".gitea-token"))) {
|
||||||
|
if (-not (Test-Path $tokenFile)) { continue }
|
||||||
|
$candidate = (Get-Content -Raw $tokenFile).Trim()
|
||||||
|
# Platzhalter der Vorlage zaehlt nicht als Token.
|
||||||
|
if ($candidate -and $candidate -notmatch "EINFUEGEN") { $token = $candidate; break }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (-not $token) {
|
if (-not $token) {
|
||||||
throw "Kein Token: GITEA_TOKEN setzen oder ihn in %USERPROFILE%\.gitea-token ablegen (Zugriffstoken aus Gitea > Einstellungen > Anwendungen)."
|
throw "Kein Token: in %USERPROFILE%\.secrets\gitea-token.txt den Platzhalter durch den Token ersetzen oder GITEA_TOKEN setzen (Zugriffstoken aus Gitea > Einstellungen > Anwendungen)."
|
||||||
}
|
}
|
||||||
if (-not $Title) { $Title = $Tag }
|
if (-not $Title) { $Title = $Tag }
|
||||||
foreach ($file in $Files) {
|
foreach ($file in $Files) {
|
||||||
|
|||||||
+13
-14
@@ -1,18 +1,17 @@
|
|||||||
## Playtube für Android – YouTube Music mit Hintergrundwiedergabe und Discord
|
## Playtube für Android 1.7.0
|
||||||
|
|
||||||
Die Android-Version von Playtube: **nur YouTube Music**, ohne YouTube-Tab und Stream-Dock-Fernsteuerung.
|
- **Host abgeben:** Als Host kannst du die Rolle im Jam an jemand anderen übergeben – in der Liste „Dabei“ auf die
|
||||||
|
Krone neben dem Namen tippen und bestätigen.
|
||||||
|
- **„Freunde einladen“:** Code und Link stehen jetzt mittig.
|
||||||
|
|
||||||
- **Neu: Discord Rich Presence** – Discord zeigt „Hört Playtube" mit Titel, Interpret, Cover und
|
Alles Weitere wie in 1.6.1. Voraussetzung: Android 8.0 oder neuer.
|
||||||
Fortschritt (offizielles Discord Social SDK, braucht die Discord-App auf dem Handy, keine Anmeldung).
|
|
||||||
- Musik läuft im Hintergrund und bei ausgeschaltetem Bildschirm weiter.
|
|
||||||
- Medien-Benachrichtigung und Sperrbildschirm-Steuerung mit Titel, Interpret und Cover.
|
|
||||||
- **Eigene, hochgeladene Songs** lassen sich abspielen.
|
|
||||||
- Updates über diese Releases (Tag `…-android`), kein GitHub, kein Play Store.
|
|
||||||
|
|
||||||
### Installieren
|
---
|
||||||
1. `Playtube-Android-vX.Y.Z.apk` herunterladen und öffnen (eine vorhandene 1.0.0 wird aktualisiert).
|
|
||||||
2. Einmalig „Unbekannte Apps installieren" für den Browser/Dateimanager erlauben.
|
|
||||||
3. Beim ersten Start Benachrichtigungen erlauben.
|
|
||||||
|
|
||||||
Voraussetzung: Android 8.0 oder neuer (ARM 32/64 Bit). Bei Akku-Optimierung des Herstellers Playtube
|
## Playtube for Android 1.7.0
|
||||||
ausnehmen, sonst kann Android die Hintergrundwiedergabe beenden.
|
|
||||||
|
- **Hand over host:** as host you can pass the role in a jam to someone else – tap the crown next to their name in
|
||||||
|
the "Listening" list and confirm.
|
||||||
|
- **"Invite friends":** the code and link are now centered.
|
||||||
|
|
||||||
|
Everything else as in 1.6.1. Requires Android 8.0 or newer.
|
||||||
|
|||||||
Reference in New Issue
Block a user