Split the shared code into a core module

The Yandex Music client, the player, the app state and the stores move from the
TV app to :core (it.panov.musyx.*), so a phone app can build on them. The TV app
becomes :tv with the same application id. CoverHues, SessionPlayer and the
strings the state layer shows move with them; LRCLIB's user agent is set by
each app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yuriy PanovandClaude Opus 5.5 committed 2026-10-23 10:07:21 +06:00
1 parent 90ac73facc
commit 4c978efa80
121 files changed
+464 -397

No files matched your search

+10 -6
View File
@@ -46,16 +46,16 @@ writes it) or `ANDROID_HOME`. The Gradle wrapper fetches everything else.
./gradlew assembleDebug ./gradlew assembleDebug
``` ```
The APK lands in `app/build/outputs/apk/debug/app-debug.apk`. `./gradlew testDebugUnitTest` The APK lands in `tv/build/outputs/apk/debug/tv-debug.apk`. `./gradlew testDebugUnitTest`
runs the JVM tests (the queue and player rules, API parsing and request signing, lyrics, runs the JVM tests (the queue and player rules, API parsing and request signing, lyrics,
decryption and theme parity, mostly ported from the desktop tests), and `./gradlew lint` runs Android decryption and theme parity, mostly ported from the desktop tests), and `./gradlew lint` runs Android
Lint, with the report in `app/build/reports/lint-results-debug.html`. Lint, with a report in each module's `build/reports/lint-results-debug.html`.
To run it, start an Android TV or Google TV emulator (Device Manager in Android Studio, TV To run it, start an Android TV or Google TV emulator (Device Manager in Android Studio, TV
category) or connect a TV with ADB debugging on, then: category) or connect a TV with ADB debugging on, then:
```bash ```bash
./gradlew installDebug ./gradlew :tv:installDebug
``` ```
```bash ```bash
@@ -67,7 +67,7 @@ tablets, since neither Leanback nor a touchscreen is required.
### Generated resources ### Generated resources
The icons, banner and fonts in `app/src/main/res` come from `assets/`. Regenerate them after The icons, banner and fonts in `tv/src/main/res` come from `assets/`. Regenerate them after
changing the sources: changing the sources:
- `python3 tool/svg_to_vector.py` turns `assets/icons/*.svg` into `res/drawable/ic_<name>.xml`. - `python3 tool/svg_to_vector.py` turns `assets/icons/*.svg` into `res/drawable/ic_<name>.xml`.
@@ -79,15 +79,19 @@ changing the sources:
## Layout ## Layout
- `app/`: the Android TV app (`it.panov.musyx.tv`), under `app/src/main/java/it/panov/musyx/tv`: - `core/`: what the apps share (`it.panov.musyx`), under `core/src/main/java/it/panov/musyx`:
- `api/`: the Yandex Music client, ported from `reference/ym-api` with the `yamuse` wire - `api/`: the Yandex Music client, ported from `reference/ym-api` with the `yamuse` wire
details inlined (`Transport.kt` headers and errors, `Auth.kt` device flow, `Signing.kt`). details inlined (`Transport.kt` headers and errors, `Auth.kt` device flow, `Signing.kt`).
- `player/`: `PlayerCore` (queue, repeat, waves, reports; a pure port of the desktop - `player/`: `PlayerCore` (queue, repeat, waves, reports; a pure port of the desktop
player), `ExoEngine` (one ExoPlayer, with `AesCtrDataSource` for encrypted FLAC), player), `ExoEngine` (one ExoPlayer, with `AesCtrDataSource` for encrypted FLAC),
`PlaybackController` (runs the core's effects) and `PlaybackService` (the media session). `PlaybackController` (runs the core's effects) and `SessionPlayer` (the player the media
session wraps).
- `state/`: `AppState`, the port of the desktop `app.rs` and `app/edit.rs`, plus search, - `state/`: `AppState`, the port of the desktop `app.rs` and `app/edit.rs`, plus search,
sign-in and navigation state. sign-in and navigation state.
- `data/`: settings and the Keystore-encrypted credentials. - `data/`: settings and the Keystore-encrypted credentials.
- `res/`: the strings the state layer shows (toasts, sign-in errors, quality names).
- `tv/`: the Android TV app (`it.panov.musyx.tv`), under `tv/src/main/java/it/panov/musyx/tv`:
- `player/PlaybackService.kt`: the media session.
- `ui/`: the shell (drawer, mini player, dialogs, toasts), `screens/` and `components/`. - `ui/`: the shell (drawer, mini player, dialogs, toasts), `screens/` and `components/`.
The theme is `ui/theme/Theme.kt`, a 1:1 port of `DESIGN.md`. The theme is `ui/theme/Theme.kt`, a 1:1 port of `DESIGN.md`.
- `gradle/libs.versions.toml`: dependency versions. - `gradle/libs.versions.toml`: dependency versions.
+1
View File
@@ -1,5 +1,6 @@
plugins { plugins {
alias(libs.plugins.android.application) apply false alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.compose) apply false alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.kotlin.serialization) apply false alias(libs.plugins.kotlin.serialization) apply false
} }
+36
View File
@@ -0,0 +1,36 @@
// What the TV and phone apps share: the Yandex Music client, the player, the app state and
// the stores. No UI beyond Compose runtime state.
plugins {
alias(libs.plugins.android.library)
// For stability inference on the models and state the UIs read.
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
}
android {
namespace = "it.panov.musyx"
compileSdk = 37
defaultConfig {
minSdk = 23
consumerProguardFiles("consumer-rules.pro")
}
testOptions {
// PlayerCore logs through android.util.Log; JVM tests get no-op stubs.
unitTests.isReturnDefaultValues = true
}
}
dependencies {
implementation(libs.androidx.core.ktx)
api(platform(libs.compose.bom))
api(libs.compose.runtime)
api(libs.media3.exoplayer)
api(libs.media3.session)
implementation(libs.okhttp)
implementation(libs.kotlinx.serialization.json)
testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.test)
}
+1
View File
@@ -0,0 +1 @@
# R8 rules for apps that use core. The libraries in use ship their own consumer rules.
@@ -1,7 +1,7 @@
// Yandex OAuth device flow: show a code, the user confirms it on Yandex's page (or scans // Yandex OAuth device flow: show a code, the user confirms it on Yandex's page (or scans
// the QR), poll until a token arrives. Uses the official Android app's public client id, // the QR), poll until a token arrives. Uses the official Android app's public client id,
// because third parties can't register an app for the music API. // because third parties can't register an app for the music API.
package it.panov.musyx.tv.api package it.panov.musyx.api
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@@ -0,0 +1,19 @@
// Placeholder art seeds: every item without a cover gets two stable hues, as on the desktop.
package it.panov.musyx.api
/** Two stable hues for placeholder art; equal seeds give equal art. Port of ym-api `hues_for`. */
fun huesFor(seed: ULong): Pair<Float, Float> =
(seed * 47uL % 360uL).toFloat() to ((seed * 131uL + 90uL) % 360uL).toFloat()
/** Seeds per item kind, as in ym-api, so an item gets the same art as on the desktop. */
object CoverHues {
fun album(id: Long) = huesFor(id.toULong())
fun artist(id: Long) = huesFor(id.toULong() xor 0x5bd1_e995uL)
fun playlist(owner: Long, kind: Long) = huesFor(owner.toULong() * 1_000_003uL xor kind.toULong())
fun clip(id: Long) = huesFor(id.toULong() xor 0x2c1b_3c6duL)
/** A track borrows its album's art, or hashes its own (string) id. */
fun track(id: String, albumId: Long?): Pair<Float, Float> = huesFor(
albumId?.toULong() ?: id.encodeToByteArray().fold(7uL) { h, b -> h * 31uL + b.toUByte().toULong() },
)
}
@@ -1,5 +1,5 @@
// What the credential store keeps. `toString` never prints the tokens. // What the credential store keeps. `toString` never prints the tokens.
package it.panov.musyx.tv.api package it.panov.musyx.api
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.JsonPrimitive
@@ -1,6 +1,6 @@
// Tolerant readers over kotlinx JSON trees. The API sends ids as numbers or strings and // Tolerant readers over kotlinx JSON trees. The API sends ids as numbers or strings and
// drops fields freely, so every model is read field by field instead of through a schema. // drops fields freely, so every model is read field by field instead of through a schema.
package it.panov.musyx.tv.api package it.panov.musyx.api
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonArray
@@ -1,8 +1,7 @@
// LRCLIB (lrclib.net): an open lyrics database, asked when Yandex has no lyrics for a track. // LRCLIB (lrclib.net): an open lyrics database, asked when Yandex has no lyrics for a track.
// No key; it asks clients to name themselves in the User-Agent. // No key; it asks clients to name themselves in the User-Agent.
package it.panov.musyx.tv.api package it.panov.musyx.api
import it.panov.musyx.tv.BuildConfig
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@@ -14,9 +13,11 @@ import kotlin.math.abs
import kotlin.math.roundToLong import kotlin.math.roundToLong
private const val LRCLIB_BASE = "https://lrclib.net/api" private const val LRCLIB_BASE = "https://lrclib.net/api"
private val LRCLIB_AGENT = "Musyx-TV/${BuildConfig.VERSION_NAME} (https://git.panov.it/panov/musyz-mobile)"
object Lrclib { object Lrclib {
/** How this app names itself to LRCLIB; each app sets its own name and version at startup. */
var agent = "Musyx (https://git.panov.it/panov/musyz-mobile)"
/** How far a search result's length may be from the track's and still be the same recording. */ /** How far a search result's length may be from the track's and still be the same recording. */
internal const val DURATION_SLACK_S = 3.0 internal const val DURATION_SLACK_S = 3.0
@@ -90,7 +91,7 @@ object Lrclib {
val url = (LRCLIB_BASE + path).toHttpUrl().newBuilder().apply { val url = (LRCLIB_BASE + path).toHttpUrl().newBuilder().apply {
params.pairs.forEach { (k, v) -> addQueryParameter(k, v) } params.pairs.forEach { (k, v) -> addQueryParameter(k, v) }
}.build() }.build()
val request = Request.Builder().url(url).header("User-Agent", LRCLIB_AGENT).get().build() val request = Request.Builder().url(url).header("User-Agent", agent).get().build()
var attempt = 0 var attempt = 0
while (true) { while (true) {
val (status, retryAfter, body) = withContext(Dispatchers.IO) { val (status, retryAfter, body) = withContext(Dispatchers.IO) {
@@ -1,5 +1,5 @@
// Lyrics: synced (LRC) or plain text. Port of ym-api edit.rs. // Lyrics: synced (LRC) or plain text. Port of ym-api edit.rs.
package it.panov.musyx.tv.api package it.panov.musyx.api
/** One line of lyrics; synced lyrics carry the moment it's sung. */ /** One line of lyrics; synced lyrics carry the moment it's sung. */
data class LyricLine(val atMs: Long?, val text: String) data class LyricLine(val atMs: Long?, val text: String)
@@ -1,8 +1,7 @@
// The app-facing shapes of API objects, keeping only what the UI uses and resolving every // The app-facing shapes of API objects, keeping only what the UI uses and resolving every
// missing field once, here. Port of ym-api's models.rs, library.rs, discover.rs and clips.rs. // missing field once, here. Port of ym-api's models.rs, library.rs, discover.rs and clips.rs.
package it.panov.musyx.tv.api package it.panov.musyx.api
import it.panov.musyx.tv.ui.theme.CoverHues
import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonElement
/** Absolute URL for a `%%`-templated image uri at `size`×`size` pixels. */ /** Absolute URL for a `%%`-templated image uri at `size`×`size` pixels. */
@@ -1,5 +1,5 @@
// Request signatures the API checks: the MP3 link, `/get-file-info` and lyrics. // Request signatures the API checks: the MP3 link, `/get-file-info` and lyrics.
package it.panov.musyx.tv.api package it.panov.musyx.api
import java.security.MessageDigest import java.security.MessageDigest
import javax.crypto.Mac import javax.crypto.Mac
@@ -1,5 +1,5 @@
// The HTTP layer: identity headers, the `result` envelope, error mapping and retries. // The HTTP layer: identity headers, the `result` envelope, error mapping and retries.
package it.panov.musyx.tv.api package it.panov.musyx.api
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@@ -1,5 +1,5 @@
// My Wave and other radio stations ("rotor"), plus listening reports. Port of ym-api wave.rs. // My Wave and other radio stations ("rotor"), plus listening reports. Port of ym-api wave.rs.
package it.panov.musyx.tv.api package it.panov.musyx.api
import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
@@ -1,6 +1,6 @@
// An authenticated Yandex Music client. Port of ym-api's client.rs, with yamuse's wire // An authenticated Yandex Music client. Port of ym-api's client.rs, with yamuse's wire
// behaviour inlined. // behaviour inlined.
package it.panov.musyx.tv.api package it.panov.musyx.api
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.coroutineScope
@@ -1,5 +1,5 @@
// Errors the app can act on. Messages are for logs, not for display. // Errors the app can act on. Messages are for logs, not for display.
package it.panov.musyx.tv.api package it.panov.musyx.api
sealed class YmError(message: String) : Exception(message) { sealed class YmError(message: String) : Exception(message) {
/** The token is missing, revoked or expired. Sign in again. */ /** The token is missing, revoked or expired. Sign in again. */
@@ -1,13 +1,13 @@
// Keeping the user signed in: credentials are encrypted with a key that lives in the Android // Keeping the user signed in: credentials are encrypted with a key that lives in the Android
// Keystore and never leaves it, and the ciphertext sits in private preferences. // Keystore and never leaves it, and the ciphertext sits in private preferences.
package it.panov.musyx.tv.data package it.panov.musyx.data
import android.content.Context import android.content.Context
import android.security.keystore.KeyGenParameterSpec import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties import android.security.keystore.KeyProperties
import android.util.Base64 import android.util.Base64
import androidx.core.content.edit import androidx.core.content.edit
import it.panov.musyx.tv.api.Credentials import it.panov.musyx.api.Credentials
import java.security.KeyStore import java.security.KeyStore
import javax.crypto.Cipher import javax.crypto.Cipher
import javax.crypto.KeyGenerator import javax.crypto.KeyGenerator
@@ -1,5 +1,5 @@
// Preferences kept between launches. Port of the desktop store.rs. // Preferences kept between launches. Port of the desktop store.rs.
package it.panov.musyx.tv.data package it.panov.musyx.data
import android.content.Context import android.content.Context
import androidx.core.content.edit import androidx.core.content.edit
@@ -1,7 +1,7 @@
// Decrypts `encraw` lossless files as ExoPlayer reads them. AES-CTR is a stream cipher // Decrypts `encraw` lossless files as ExoPlayer reads them. AES-CTR is a stream cipher
// over a 128-bit big-endian block counter starting at zero, so any byte offset can be // over a 128-bit big-endian block counter starting at zero, so any byte offset can be
// decrypted on its own and seeking keeps working. // decrypted on its own and seeking keeps working.
package it.panov.musyx.tv.player package it.panov.musyx.player
import android.net.Uri import android.net.Uri
import androidx.media3.common.C import androidx.media3.common.C
@@ -1,7 +1,7 @@
// The audio engine: one ExoPlayer that plays one track at a time. The queue lives in // The audio engine: one ExoPlayer that plays one track at a time. The queue lives in
// PlayerCore; this only loads what it's told and reports back, tagged with the generation // PlayerCore; this only loads what it's told and reports back, tagged with the generation
// of the load so late events from a previous track are ignored. // of the load so late events from a previous track are ignored.
package it.panov.musyx.tv.player package it.panov.musyx.player
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
@@ -19,10 +19,10 @@ import androidx.media3.datasource.DefaultHttpDataSource
import androidx.media3.datasource.ResolvingDataSource import androidx.media3.datasource.ResolvingDataSource
import androidx.media3.exoplayer.ExoPlayer import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import it.panov.musyx.tv.api.CLIENT_HEADER import it.panov.musyx.api.CLIENT_HEADER
import it.panov.musyx.tv.api.Stream import it.panov.musyx.api.Stream
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.api.isYandexHost import it.panov.musyx.api.isYandexHost
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
interface EngineEvents { interface EngineEvents {
@@ -1,6 +1,6 @@
// Runs PlayerCore on the main thread: forwards engine events and user commands to it, // Runs PlayerCore on the main thread: forwards engine events and user commands to it,
// carries out the effects it asks for against the API, and publishes what the UI shows. // carries out the effects it asks for against the API, and publishes what the UI shows.
package it.panov.musyx.tv.player package it.panov.musyx.player
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
@@ -11,12 +11,12 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.annotation.OptIn import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi import androidx.media3.common.util.UnstableApi
import it.panov.musyx.tv.api.MY_WAVE import it.panov.musyx.api.MY_WAVE
import it.panov.musyx.tv.api.Stream import it.panov.musyx.api.Stream
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.api.WaveSettings import it.panov.musyx.api.WaveSettings
import it.panov.musyx.tv.api.YmClient import it.panov.musyx.api.YmClient
import it.panov.musyx.tv.data.Quality import it.panov.musyx.data.Quality
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -1,14 +1,14 @@
// Playback state: the queue, what's loaded, and the rules for moving between tracks. // Playback state: the queue, what's loaded, and the rules for moving between tracks.
// Network work is described as [Effect]s for the app to run, so this class stays free of // Network work is described as [Effect]s for the app to run, so this class stays free of
// the API client and can be tested on its own. Port of the desktop `player/mod.rs`. // the API client and can be tested on its own. Port of the desktop `player/mod.rs`.
package it.panov.musyx.tv.player package it.panov.musyx.player
import it.panov.musyx.tv.api.PlayReport import it.panov.musyx.api.PlayReport
import it.panov.musyx.tv.api.Stream import it.panov.musyx.api.Stream
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.api.WaveBatch import it.panov.musyx.api.WaveBatch
import it.panov.musyx.tv.api.WaveEvent import it.panov.musyx.api.WaveEvent
import it.panov.musyx.tv.api.YmError import it.panov.musyx.api.YmError
import kotlin.random.Random import kotlin.random.Random
/** Give up after this many unplayable tracks in a row instead of skipping forever. */ /** Give up after this many unplayable tracks in a row instead of skipping forever. */
@@ -1,6 +1,6 @@
// Play order over a fixed list of items: shuffle, repeat, next/previous. Port of the // Play order over a fixed list of items: shuffle, repeat, next/previous. Port of the
// desktop `player/queue.rs`; generic so the rules can be tested with plain numbers. // desktop `player/queue.rs`; generic so the rules can be tested with plain numbers.
package it.panov.musyx.tv.player package it.panov.musyx.player
import kotlin.random.Random import kotlin.random.Random
@@ -1,50 +1,12 @@
// Background audio and remote control: the media session that the TV's Now Playing card, // The player that each app's media session wraps.
// the remote's media keys and Google Assistant talk to. package it.panov.musyx.player
package it.panov.musyx.tv.player
import android.app.PendingIntent
import android.content.Intent
import androidx.media3.common.Player
import androidx.annotation.OptIn import androidx.annotation.OptIn
import androidx.media3.common.ForwardingSimpleBasePlayer
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi import androidx.media3.common.util.UnstableApi
import androidx.media3.session.MediaSession
import androidx.media3.session.MediaSessionService
import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.ListenableFuture
import it.panov.musyx.tv.MainActivity
import it.panov.musyx.tv.Musyx
@OptIn(UnstableApi::class)
class PlaybackService : MediaSessionService() {
private var session: MediaSession? = null
override fun onCreate() {
super.onCreate()
val open = PendingIntent.getActivity(
this,
0,
Intent(this, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
)
session = MediaSession.Builder(this, Musyx.graph(this).state.playback.sessionPlayer)
.setSessionActivity(open)
.build()
}
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaSession? = session
override fun onTaskRemoved(rootIntent: Intent?) {
val player = session?.player
if (player == null || !player.playWhenReady || player.mediaItemCount == 0) stopSelf()
}
override fun onDestroy() {
// The player belongs to the app and outlives the service.
session?.release()
session = null
super.onDestroy()
}
}
/** /**
* The ExoPlayer as the media session sees it. ExoPlayer only ever holds the current * The ExoPlayer as the media session sees it. ExoPlayer only ever holds the current
@@ -53,7 +15,7 @@ class PlaybackService : MediaSessionService() {
*/ */
@OptIn(UnstableApi::class) @OptIn(UnstableApi::class)
class SessionPlayer(player: Player, private val controller: PlaybackController) : class SessionPlayer(player: Player, private val controller: PlaybackController) :
androidx.media3.common.ForwardingSimpleBasePlayer(player) { ForwardingSimpleBasePlayer(player) {
override fun getState(): State { override fun getState(): State {
val state = super.getState() val state = super.getState()
@@ -1,7 +1,7 @@
// Application state and everything that changes it. Port of the desktop app.rs and // Application state and everything that changes it. Port of the desktop app.rs and
// app/edit.rs: screens read these fields and call these methods; all of it runs on the // app/edit.rs: screens read these fields and call these methods; all of it runs on the
// main thread, with network calls in coroutines that write their results back. // main thread, with network calls in coroutines that write their results back.
package it.panov.musyx.tv.state package it.panov.musyx.state
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
@@ -9,39 +9,39 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import it.panov.musyx.tv.R import it.panov.musyx.R
import it.panov.musyx.tv.api.Account import it.panov.musyx.api.Account
import it.panov.musyx.tv.api.AlbumPage import it.panov.musyx.api.AlbumPage
import it.panov.musyx.tv.api.AlbumSummary import it.panov.musyx.api.AlbumSummary
import it.panov.musyx.tv.api.ArtistPage import it.panov.musyx.api.ArtistPage
import it.panov.musyx.tv.api.ArtistSummary import it.panov.musyx.api.ArtistSummary
import it.panov.musyx.tv.api.Auth import it.panov.musyx.api.Auth
import it.panov.musyx.tv.api.Clip import it.panov.musyx.api.Clip
import it.panov.musyx.tv.api.ContentLanguage import it.panov.musyx.api.ContentLanguage
import it.panov.musyx.tv.api.Credentials import it.panov.musyx.api.Credentials
import it.panov.musyx.tv.api.Genre import it.panov.musyx.api.Genre
import it.panov.musyx.tv.api.Home import it.panov.musyx.api.Home
import it.panov.musyx.tv.api.LibraryPlaylists import it.panov.musyx.api.LibraryPlaylists
import it.panov.musyx.tv.api.LikedIds import it.panov.musyx.api.LikedIds
import it.panov.musyx.tv.api.Lrclib import it.panov.musyx.api.Lrclib
import it.panov.musyx.tv.api.Lyrics import it.panov.musyx.api.Lyrics
import it.panov.musyx.tv.api.MY_WAVE import it.panov.musyx.api.MY_WAVE
import it.panov.musyx.tv.api.PlaylistId import it.panov.musyx.api.PlaylistId
import it.panov.musyx.tv.api.PlaylistPage import it.panov.musyx.api.PlaylistPage
import it.panov.musyx.tv.api.PlaylistSummary import it.panov.musyx.api.PlaylistSummary
import it.panov.musyx.tv.api.Station import it.panov.musyx.api.Station
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.api.WaveSettings import it.panov.musyx.api.WaveSettings
import it.panov.musyx.tv.api.YmClient import it.panov.musyx.api.YmClient
import it.panov.musyx.tv.api.YmError import it.panov.musyx.api.YmError
import it.panov.musyx.tv.data.Appearance import it.panov.musyx.data.Appearance
import it.panov.musyx.tv.data.FontSize import it.panov.musyx.data.FontSize
import it.panov.musyx.tv.data.CredentialStore import it.panov.musyx.data.CredentialStore
import it.panov.musyx.tv.data.Locale import it.panov.musyx.data.Locale
import it.panov.musyx.tv.data.Quality import it.panov.musyx.data.Quality
import it.panov.musyx.tv.data.Settings import it.panov.musyx.data.Settings
import it.panov.musyx.tv.data.SettingsStore import it.panov.musyx.data.SettingsStore
import it.panov.musyx.tv.player.PlaybackController import it.panov.musyx.player.PlaybackController
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -1,12 +1,12 @@
// Small state types shared by every screen. // Small state types shared by every screen.
package it.panov.musyx.tv.state package it.panov.musyx.state
import androidx.annotation.PluralsRes import androidx.annotation.PluralsRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import it.panov.musyx.tv.api.PlaylistId import it.panov.musyx.api.PlaylistId
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.api.YmError import it.panov.musyx.api.YmError
/** Something fetched from the API: not asked for yet, on its way, here, or failed. */ /** Something fetched from the API: not asked for yet, on its way, here, or failed. */
sealed interface Loadable<out T> { sealed interface Loadable<out T> {
@@ -1,10 +1,10 @@
// Every place the content area can show, and the back stack between them. // Every place the content area can show, and the back stack between them.
package it.panov.musyx.tv.state package it.panov.musyx.state
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import it.panov.musyx.tv.api.PlaylistId import it.panov.musyx.api.PlaylistId
sealed interface Route { sealed interface Route {
data object Home : Route data object Home : Route
@@ -1,13 +1,13 @@
// Search: suggestions while typing, results by kind, more pages on request. // Search: suggestions while typing, results by kind, more pages on request.
package it.panov.musyx.tv.state package it.panov.musyx.state
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import it.panov.musyx.tv.api.SearchKind import it.panov.musyx.api.SearchKind
import it.panov.musyx.tv.api.SearchResults import it.panov.musyx.api.SearchResults
import it.panov.musyx.tv.api.YmClient import it.panov.musyx.api.YmClient
import it.panov.musyx.tv.api.YmError import it.panov.musyx.api.YmError
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@@ -1,17 +1,17 @@
// Device-code sign-in: get a code, the user confirms it on Yandex's page (or scans the // Device-code sign-in: get a code, the user confirms it on Yandex's page (or scans the
// QR with their phone), we poll until a token arrives. A pasted token is the fallback. // QR with their phone), we poll until a token arrives. A pasted token is the fallback.
package it.panov.musyx.tv.state package it.panov.musyx.state
import android.os.SystemClock import android.os.SystemClock
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import it.panov.musyx.tv.R import it.panov.musyx.R
import it.panov.musyx.tv.api.Auth import it.panov.musyx.api.Auth
import it.panov.musyx.tv.api.Credentials import it.panov.musyx.api.Credentials
import it.panov.musyx.tv.api.DeviceCode import it.panov.musyx.api.DeviceCode
import it.panov.musyx.tv.api.Poll import it.panov.musyx.api.Poll
import it.panov.musyx.tv.api.YmError import it.panov.musyx.api.YmError
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
+61
View File
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Strings the shared state layer shows: toasts, sign-in errors, quality names. -->
<resources>
<string name="signin_token_rejected">Яндекс не принял этот токен. Проверьте его и вставьте ещё раз.</string>
<string name="signin_error_expired">Срок действия кода истёк до подтверждения. Получите новый код и попробуйте снова.</string>
<string name="signin_error_denied">Доступ отклонён на странице Яндекса. Если это ошибка, получите новый код.</string>
<string name="signin_error_network">Яндекс недоступен. Проверьте подключение и попробуйте ещё раз.</string>
<string name="signin_error_unauthorized">Яндекс не принял вход. Получите новый код и попробуйте снова.</string>
<string name="signin_error_unexpected">Яндекс прислал неожиданный ответ. Попробуйте чуть позже.</string>
<string name="quality_lossless">Без потерь</string>
<string name="quality_best">Лучшее</string>
<string name="quality_balanced">Оптимальное</string>
<string name="quality_data_saver">Экономия трафика</string>
<string name="toast_already_playing">«%1$s» уже играет</string>
<string name="toast_plays_next">«%1$s» зазвучит следующим</string>
<string name="toast_added_to_queue">«%1$s» добавлен в очередь</string>
<string name="toast_finding_similar">Ищем треки в духе «%1$s»…</string>
<string name="toast_no_similar">У Яндекса нет похожих треков для «%1$s»</string>
<string name="toast_similar_failed">Не удалось найти похожие треки. Попробуйте ещё раз.</string>
<string name="toast_liked">Добавлено в «Мне нравится»</string>
<string name="toast_unliked">Убрано из «Мне нравится»</string>
<string name="toast_like_failed">Не удалось изменить отметку. Попробуйте ещё раз.</string>
<string name="toast_disliked">Этот трек больше не будет попадаться в рекомендациях</string>
<string name="toast_undisliked">Трек снова может попадаться в рекомендациях</string>
<string name="toast_change_failed">Не удалось это изменить. Попробуйте ещё раз.</string>
<string name="toast_album_liked">Альбом добавлен в коллекцию</string>
<string name="toast_album_unliked">Альбом убран из коллекции</string>
<string name="toast_artist_liked">Исполнитель добавлен в коллекцию</string>
<string name="toast_artist_unliked">Исполнитель убран из коллекции</string>
<string name="toast_playlist_liked">Плейлист добавлен в коллекцию</string>
<string name="toast_playlist_unliked">Плейлист убран из коллекции</string>
<string name="toast_clip_liked">Клип добавлен в коллекцию</string>
<string name="toast_clip_unliked">Клип убран из коллекции</string>
<string name="toast_added_to">Добавлено в «%1$s»</string>
<string name="toast_added_to_playlist">Добавлено в плейлист</string>
<string name="toast_add_failed">Не удалось добавить в «%1$s». Попробуйте ещё раз.</string>
<string name="toast_add_failed_playlist">Не удалось добавить в плейлист. Попробуйте ещё раз.</string>
<string name="toast_created">Плейлист «%1$s» создан</string>
<string name="toast_created_with_track">Плейлист «%1$s» создан, трек добавлен</string>
<string name="toast_create_failed">Не удалось создать плейлист. Попробуйте ещё раз.</string>
<string name="toast_renamed">Плейлист переименован в «%1$s»</string>
<string name="toast_rename_failed">Не удалось переименовать плейлист. Попробуйте ещё раз.</string>
<string name="toast_now_public">Теперь плейлист видят все, у кого есть ссылка</string>
<string name="toast_now_private">Теперь плейлист видите только вы</string>
<string name="toast_visibility_failed">Не удалось изменить доступ. Попробуйте ещё раз.</string>
<string name="toast_deleted">Плейлист «%1$s» удалён</string>
<string name="toast_delete_failed">Не удалось удалить «%1$s». Попробуйте ещё раз.</string>
<string name="toast_removed">Удалено из плейлиста</string>
<string name="toast_remove_failed">Не удалось удалить трек. Попробуйте ещё раз.</string>
<string name="toast_moved">Перемещено</string>
<string name="toast_move_failed">Не удалось переместить трек. Попробуйте ещё раз.</string>
<string name="toast_quality">Качество звука: %1$s. Применится со следующего трека.</string>
<string name="toast_covers_cleared">Кеш обложек очищен</string>
<string name="toast_covers_failed">Не удалось очистить кеш обложек.</string>
<plurals name="toast_playing_similar">
<item quantity="one">Играем %1$d трек в духе «%2$s»</item>
<item quantity="few">Играем %1$d трека в духе «%2$s»</item>
<item quantity="many">Играем %1$d треков в духе «%2$s»</item>
<item quantity="other">Играем %1$d трека в духе «%2$s»</item>
</plurals>
</resources>
+59
View File
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Strings the shared state layer shows: toasts, sign-in errors, quality names. -->
<resources>
<string name="signin_token_rejected">Yandex didn\'t accept that token. Check it and paste it again.</string>
<string name="signin_error_expired">The code expired before it was confirmed. Get a new code to try again.</string>
<string name="signin_error_denied">Access was declined on Yandex\'s page. Get a new code if that was a mistake.</string>
<string name="signin_error_network">Can\'t reach Yandex. Check your connection and try again.</string>
<string name="signin_error_unauthorized">Yandex didn\'t accept the sign-in. Get a new code to try again.</string>
<string name="signin_error_unexpected">Yandex sent an unexpected answer. Try again in a moment.</string>
<string name="quality_lossless">Lossless</string>
<string name="quality_best">Best</string>
<string name="quality_balanced">Balanced</string>
<string name="quality_data_saver">Data saver</string>
<string name="toast_already_playing">“%1$s” is already playing</string>
<string name="toast_plays_next">“%1$s” plays next</string>
<string name="toast_added_to_queue">Added “%1$s” to the queue</string>
<string name="toast_finding_similar">Finding tracks like “%1$s”…</string>
<string name="toast_no_similar">Yandex has no similar tracks for “%1$s”</string>
<string name="toast_similar_failed">Couldn\'t find similar tracks. Try again.</string>
<string name="toast_liked">Added to Liked tracks</string>
<string name="toast_unliked">Removed from Liked tracks</string>
<string name="toast_like_failed">Couldn\'t change the like. Try again.</string>
<string name="toast_disliked">You won\'t be recommended this track</string>
<string name="toast_undisliked">Recommendations for this track restored</string>
<string name="toast_change_failed">Couldn\'t change that. Try again.</string>
<string name="toast_album_liked">Album added to your collection</string>
<string name="toast_album_unliked">Album removed from your collection</string>
<string name="toast_artist_liked">Artist added to your collection</string>
<string name="toast_artist_unliked">Artist removed from your collection</string>
<string name="toast_playlist_liked">Playlist added to your collection</string>
<string name="toast_playlist_unliked">Playlist removed from your collection</string>
<string name="toast_clip_liked">Clip added to your collection</string>
<string name="toast_clip_unliked">Clip removed from your collection</string>
<string name="toast_added_to">Added to “%1$s”</string>
<string name="toast_added_to_playlist">Added to the playlist</string>
<string name="toast_add_failed">Couldn\'t add to “%1$s”. Try again.</string>
<string name="toast_add_failed_playlist">Couldn\'t add to the playlist. Try again.</string>
<string name="toast_created">Created “%1$s”</string>
<string name="toast_created_with_track">Created “%1$s” with the track</string>
<string name="toast_create_failed">Couldn\'t create the playlist. Try again.</string>
<string name="toast_renamed">Renamed to “%1$s”</string>
<string name="toast_rename_failed">Couldn\'t rename the playlist. Try again.</string>
<string name="toast_now_public">Anyone with the link can now see this playlist</string>
<string name="toast_now_private">Only you can see this playlist now</string>
<string name="toast_visibility_failed">Couldn\'t change who can see it. Try again.</string>
<string name="toast_deleted">Deleted “%1$s”</string>
<string name="toast_delete_failed">Couldn\'t delete “%1$s”. Try again.</string>
<string name="toast_removed">Removed from the playlist</string>
<string name="toast_remove_failed">Couldn\'t remove the track. Try again.</string>
<string name="toast_moved">Moved</string>
<string name="toast_move_failed">Couldn\'t move the track. Try again.</string>
<string name="toast_quality">Streaming quality: %1$s. Applies from the next track.</string>
<string name="toast_covers_cleared">Cover cache cleared</string>
<string name="toast_covers_failed">Couldn\'t clear the cover cache.</string>
<plurals name="toast_playing_similar">
<item quantity="one">Playing %1$d track like “%2$s”</item>
<item quantity="other">Playing %1$d tracks like “%2$s”</item>
</plurals>
</resources>
@@ -1,7 +1,7 @@
package it.panov.musyx.tv.api package it.panov.musyx.api
import it.panov.musyx.tv.player.ctrCipher import it.panov.musyx.player.ctrCipher
import it.panov.musyx.tv.player.hexKey import it.panov.musyx.player.hexKey
import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.JsonPrimitive
import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
@@ -0,0 +1,18 @@
package it.panov.musyx.api
import org.junit.Assert.assertEquals
import org.junit.Test
/** Parity with the desktop's placeholder hues. */
class CoverHuesTest {
// Expected values come from ym-api's `hues_for` and its per-kind seeds (u64 wrapping maths).
@Test
fun huesMatchTheDesktop() {
assertEquals(47f to 221f, CoverHues.album(1))
assertEquals(329f to 335f, CoverHues.album(-1))
assertEquals(233f to 119f, CoverHues.artist(42))
assertEquals(2f to 356f, CoverHues.playlist(owner = 503_646_255, kind = 3))
assertEquals(295f to 85f, CoverHues.track("12345:678", albumId = null))
assertEquals(CoverHues.album(7), CoverHues.track("12345:678", albumId = 7))
}
}
@@ -1,10 +1,10 @@
package it.panov.musyx.tv.player package it.panov.musyx.player
import it.panov.musyx.tv.api.Stream import it.panov.musyx.api.Stream
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.api.WaveBatch import it.panov.musyx.api.WaveBatch
import it.panov.musyx.tv.api.WaveEvent import it.panov.musyx.api.WaveEvent
import it.panov.musyx.tv.api.YmError import it.panov.musyx.api.YmError
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
@@ -1,4 +1,4 @@
package it.panov.musyx.tv.player package it.panov.musyx.player
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
@@ -1,7 +1,7 @@
package it.panov.musyx.tv.state package it.panov.musyx.state
import it.panov.musyx.tv.api.PlaylistId import it.panov.musyx.api.PlaylistId
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
import org.junit.Assert.assertSame import org.junit.Assert.assertSame
+2
View File
@@ -24,6 +24,7 @@ compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" } compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
compose-foundation = { module = "androidx.compose.foundation:foundation" } compose-foundation = { module = "androidx.compose.foundation:foundation" }
compose-runtime = { module = "androidx.compose.runtime:runtime" }
tv-material = { module = "androidx.tv:tv-material", version.ref = "tv-material" } tv-material = { module = "androidx.tv:tv-material", version.ref = "tv-material" }
media3-exoplayer = { module = "androidx.media3:media3-exoplayer", version.ref = "media3" } media3-exoplayer = { module = "androidx.media3:media3-exoplayer", version.ref = "media3" }
media3-session = { module = "androidx.media3:media3-session", version.ref = "media3" } media3-session = { module = "androidx.media3:media3-session", version.ref = "media3" }
@@ -38,5 +39,6 @@ androidx-lifecycle-process = { module = "androidx.lifecycle:lifecycle-process",
[plugins] [plugins]
android-application = { id = "com.android.application", version.ref = "agp" } android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
+1 -1
View File
@@ -21,4 +21,4 @@ dependencyResolutionManagement {
} }
rootProject.name = "musyx-mobile" rootProject.name = "musyx-mobile"
include(":app") include(":core", ":tv")
+2 -2
View File
@@ -7,7 +7,7 @@
(run tool/make_icon.py first if it changes). (run tool/make_icon.py first if it changes).
Needs Pillow (pip install Pillow), unlike make_icon.py, because it sets type. Needs Pillow (pip install Pillow), unlike make_icon.py, because it sets type.
Usage: python3 tool/make_tv_assets.py [app/src/main/res] Usage: python3 tool/make_tv_assets.py [tv/src/main/res]
""" """
import sys import sys
from pathlib import Path from pathlib import Path
@@ -87,4 +87,4 @@ def main(res):
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1] if len(sys.argv) > 1 else ROOT / "app/src/main/res") main(sys.argv[1] if len(sys.argv) > 1 else ROOT / "tv/src/main/res")
+2 -2
View File
@@ -5,7 +5,7 @@ Lucide draws everything in `currentColor`. The drawables keep that idea: every s
is plain white, which Compose's `Icon(tint = ...)` replaces with a theme token, so no design is plain white, which Compose's `Icon(tint = ...)` replaces with a theme token, so no design
colour is baked in. Path data is re-tokenised so arc flags and packed numbers are unambiguous. colour is baked in. Path data is re-tokenised so arc flags and packed numbers are unambiguous.
Usage: python3 tool/svg_to_vector.py [assets/icons] [app/src/main/res/drawable] Usage: python3 tool/svg_to_vector.py [assets/icons] [tv/src/main/res/drawable]
""" """
import re import re
import sys import sys
@@ -130,5 +130,5 @@ def main(src, dst):
if __name__ == "__main__": if __name__ == "__main__":
main( main(
sys.argv[1] if len(sys.argv) > 1 else ROOT / "assets/icons", sys.argv[1] if len(sys.argv) > 1 else ROOT / "assets/icons",
sys.argv[2] if len(sys.argv) > 2 else ROOT / "app/src/main/res/drawable", sys.argv[2] if len(sys.argv) > 2 else ROOT / "tv/src/main/res/drawable",
) )
+2 -8
View File
@@ -3,7 +3,6 @@ import java.util.Properties
plugins { plugins {
alias(libs.plugins.android.application) alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.compose) alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
} }
android { android {
@@ -48,14 +47,11 @@ android {
compose = true compose = true
buildConfig = true buildConfig = true
} }
testOptions {
// PlayerCore logs through android.util.Log; JVM tests get no-op stubs.
unitTests.isReturnDefaultValues = true
}
} }
dependencies { dependencies {
implementation(project(":core"))
implementation(libs.androidx.core.ktx) implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.compose) implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.runtime.compose) implementation(libs.androidx.lifecycle.runtime.compose)
@@ -70,8 +66,6 @@ dependencies {
implementation(libs.media3.exoplayer) implementation(libs.media3.exoplayer)
implementation(libs.media3.session) implementation(libs.media3.session)
implementation(libs.okhttp)
implementation(libs.kotlinx.serialization.json)
implementation(libs.coil.compose) implementation(libs.coil.compose)
implementation(libs.coil.network.okhttp) implementation(libs.coil.network.okhttp)
implementation(libs.zxing.core) implementation(libs.zxing.core)
View File
File renamed without changes.
View File
File renamed without changes.
File renamed without changes.
@@ -14,10 +14,10 @@ import androidx.compose.runtime.snapshotFlow
import androidx.media3.session.MediaController import androidx.media3.session.MediaController
import androidx.media3.session.SessionToken import androidx.media3.session.SessionToken
import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.ListenableFuture
import it.panov.musyx.tv.data.Appearance import it.panov.musyx.data.Appearance
import it.panov.musyx.tv.data.SettingsStore import it.panov.musyx.data.SettingsStore
import it.panov.musyx.tv.player.PlaybackService import it.panov.musyx.tv.player.PlaybackService
import it.panov.musyx.tv.player.Status import it.panov.musyx.player.Status
import it.panov.musyx.tv.ui.MusyxApp import it.panov.musyx.tv.ui.MusyxApp
import it.panov.musyx.tv.ui.screens.ScreenSaverState import it.panov.musyx.tv.ui.screens.ScreenSaverState
import it.panov.musyx.tv.ui.theme.MusyxTheme import it.panov.musyx.tv.ui.theme.MusyxTheme
@@ -13,9 +13,10 @@ import coil3.disk.directory
import coil3.memory.MemoryCache import coil3.memory.MemoryCache
import coil3.network.okhttp.OkHttpNetworkFetcherFactory import coil3.network.okhttp.OkHttpNetworkFetcherFactory
import coil3.request.crossfade import coil3.request.crossfade
import it.panov.musyx.tv.data.CredentialStore import it.panov.musyx.api.Lrclib
import it.panov.musyx.tv.data.SettingsStore import it.panov.musyx.data.CredentialStore
import it.panov.musyx.tv.state.AppState import it.panov.musyx.data.SettingsStore
import it.panov.musyx.state.AppState
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
@@ -25,6 +26,11 @@ class Musyx : Application(), SingletonImageLoader.Factory {
/** Lives as long as the process; everything in it runs on the main thread. */ /** Lives as long as the process; everything in it runs on the main thread. */
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate) val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
override fun onCreate() {
super.onCreate()
Lrclib.agent = "Musyx-TV/${BuildConfig.VERSION_NAME} (https://git.panov.it/panov/musyz-mobile)"
}
val state: AppState by lazy { val state: AppState by lazy {
AppState( AppState(
context = this, context = this,
@@ -0,0 +1,44 @@
// Background audio and remote control: the media session that the TV's Now Playing card,
// the remote's media keys and Google Assistant talk to.
package it.panov.musyx.tv.player
import android.app.PendingIntent
import android.content.Intent
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import androidx.media3.session.MediaSession
import androidx.media3.session.MediaSessionService
import it.panov.musyx.tv.MainActivity
import it.panov.musyx.tv.Musyx
@OptIn(UnstableApi::class)
class PlaybackService : MediaSessionService() {
private var session: MediaSession? = null
override fun onCreate() {
super.onCreate()
val open = PendingIntent.getActivity(
this,
0,
Intent(this, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
)
session = MediaSession.Builder(this, Musyx.graph(this).state.playback.sessionPlayer)
.setSessionActivity(open)
.build()
}
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaSession? = session
override fun onTaskRemoved(rootIntent: Intent?) {
val player = session?.player
if (player == null || !player.playWhenReady || player.mediaItemCount == 0) stopSelf()
}
override fun onDestroy() {
// The player belongs to the app and outlives the service.
session?.release()
session = null
super.onDestroy()
}
}
@@ -7,12 +7,12 @@ import androidx.compose.ui.platform.LocalResources
import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.api.AlbumKind import it.panov.musyx.api.AlbumKind
import it.panov.musyx.tv.api.AlbumSummary import it.panov.musyx.api.AlbumSummary
import it.panov.musyx.tv.api.Clip import it.panov.musyx.api.Clip
import it.panov.musyx.tv.api.PlaylistSummary import it.panov.musyx.api.PlaylistSummary
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.state.UiText import it.panov.musyx.state.UiText
@Composable @Composable
fun text(ui: UiText): String { fun text(ui: UiText): String {
@@ -55,9 +55,9 @@ import androidx.tv.material3.LocalContentColor
import androidx.tv.material3.NavigationDrawerItemDefaults import androidx.tv.material3.NavigationDrawerItemDefaults
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.Route import it.panov.musyx.state.Route
import it.panov.musyx.tv.state.Session import it.panov.musyx.state.Session
import it.panov.musyx.tv.ui.components.onInk import it.panov.musyx.tv.ui.components.onInk
import it.panov.musyx.tv.ui.components.FocusEntry import it.panov.musyx.tv.ui.components.FocusEntry
import it.panov.musyx.tv.ui.components.Focusable import it.panov.musyx.tv.ui.components.Focusable
@@ -11,7 +11,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.api.YmError import it.panov.musyx.api.YmError
import it.panov.musyx.tv.ui.theme.MusyxTheme import it.panov.musyx.tv.ui.theme.MusyxTheme
/** Muted running text inside the safe margin. */ /** Muted running text inside the safe margin. */
@@ -27,11 +27,11 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.api.PlaylistId import it.panov.musyx.api.PlaylistId
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.PlaylistSlot import it.panov.musyx.state.PlaylistSlot
import it.panov.musyx.tv.state.Sheet import it.panov.musyx.state.Sheet
import it.panov.musyx.tv.ui.artistsOrUnknown import it.panov.musyx.tv.ui.artistsOrUnknown
import it.panov.musyx.tv.ui.clock import it.panov.musyx.tv.ui.clock
import it.panov.musyx.tv.ui.theme.MusyxTheme import it.panov.musyx.tv.ui.theme.MusyxTheme
@@ -44,17 +44,17 @@ import androidx.compose.ui.unit.dp
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.api.AlbumSummary import it.panov.musyx.api.AlbumSummary
import it.panov.musyx.tv.api.ArtistSummary import it.panov.musyx.api.ArtistSummary
import it.panov.musyx.tv.api.Clip import it.panov.musyx.api.Clip
import it.panov.musyx.tv.api.Genre import it.panov.musyx.api.Genre
import it.panov.musyx.tv.api.PlaylistSummary import it.panov.musyx.api.PlaylistSummary
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.Loadable import it.panov.musyx.state.Loadable
import it.panov.musyx.tv.state.Route import it.panov.musyx.state.Route
import it.panov.musyx.tv.state.Sheet import it.panov.musyx.state.Sheet
import it.panov.musyx.tv.state.UiText import it.panov.musyx.state.UiText
import it.panov.musyx.tv.ui.artistsOrUnknown import it.panov.musyx.tv.ui.artistsOrUnknown
import it.panov.musyx.tv.ui.clock import it.panov.musyx.tv.ui.clock
import it.panov.musyx.tv.ui.components.COVER_LARGE import it.panov.musyx.tv.ui.components.COVER_LARGE
@@ -19,16 +19,16 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.api.AlbumPage import it.panov.musyx.api.AlbumPage
import it.panov.musyx.tv.api.ArtistPage import it.panov.musyx.api.ArtistPage
import it.panov.musyx.tv.api.PlaylistPage import it.panov.musyx.api.PlaylistPage
import it.panov.musyx.tv.api.PlaylistSummary import it.panov.musyx.api.PlaylistSummary
import it.panov.musyx.tv.api.YmError import it.panov.musyx.api.YmError
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.Loadable import it.panov.musyx.state.Loadable
import it.panov.musyx.tv.state.Page import it.panov.musyx.state.Page
import it.panov.musyx.tv.state.Route import it.panov.musyx.state.Route
import it.panov.musyx.tv.state.Sheet import it.panov.musyx.state.Sheet
import it.panov.musyx.tv.ui.components.COVER_LARGE import it.panov.musyx.tv.ui.components.COVER_LARGE
import it.panov.musyx.tv.ui.components.Columns import it.panov.musyx.tv.ui.components.Columns
import it.panov.musyx.tv.ui.components.Cover import it.panov.musyx.tv.ui.components.Cover
@@ -36,15 +36,15 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.api.Character import it.panov.musyx.api.Character
import it.panov.musyx.tv.api.Language import it.panov.musyx.api.Language
import it.panov.musyx.tv.api.MY_WAVE import it.panov.musyx.api.MY_WAVE
import it.panov.musyx.tv.api.Mood import it.panov.musyx.api.Mood
import it.panov.musyx.tv.api.Station import it.panov.musyx.api.Station
import it.panov.musyx.tv.api.WaveSettings import it.panov.musyx.api.WaveSettings
import it.panov.musyx.tv.player.Status import it.panov.musyx.player.Status
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.Route import it.panov.musyx.state.Route
import it.panov.musyx.tv.ui.components.CardWidth import it.panov.musyx.tv.ui.components.CardWidth
import it.panov.musyx.tv.ui.components.Chip import it.panov.musyx.tv.ui.components.Chip
import it.panov.musyx.tv.ui.components.PlayingBadge import it.panov.musyx.tv.ui.components.PlayingBadge
@@ -12,11 +12,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.CollectionTab import it.panov.musyx.state.CollectionTab
import it.panov.musyx.tv.state.Liked import it.panov.musyx.state.Liked
import it.panov.musyx.tv.state.Loadable import it.panov.musyx.state.Loadable
import it.panov.musyx.tv.state.Route import it.panov.musyx.state.Route
import it.panov.musyx.tv.ui.components.CardGrid import it.panov.musyx.tv.ui.components.CardGrid
import it.panov.musyx.tv.ui.components.Chip import it.panov.musyx.tv.ui.components.Chip
import it.panov.musyx.tv.ui.components.Failure import it.panov.musyx.tv.ui.components.Failure
@@ -119,7 +119,7 @@ fun CollectionScreen(state: AppState, entry: FocusEntry) {
) { p -> ) { p ->
item(key = "new") { item(key = "new") {
Box(Modifier.padding(horizontal = space.safeX)) { Box(Modifier.padding(horizontal = space.safeX)) {
Chip(stringResource(R.string.action_new_playlist), false, { state.openSheet(it.panov.musyx.tv.state.Sheet.NewPlaylist(null)) }) Chip(stringResource(R.string.action_new_playlist), false, { state.openSheet(it.panov.musyx.state.Sheet.NewPlaylist(null)) })
} }
} }
if (p.own.isEmpty() && p.liked.isEmpty()) { if (p.own.isEmpty() && p.liked.isEmpty()) {
@@ -70,17 +70,17 @@ import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.MainActivity import it.panov.musyx.tv.MainActivity
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.api.Lyrics import it.panov.musyx.api.Lyrics
import it.panov.musyx.tv.api.LyricsSource import it.panov.musyx.api.LyricsSource
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.player.Notice import it.panov.musyx.player.Notice
import it.panov.musyx.tv.player.PlaybackState import it.panov.musyx.player.PlaybackState
import it.panov.musyx.tv.player.Repeat import it.panov.musyx.player.Repeat
import it.panov.musyx.tv.player.Status import it.panov.musyx.player.Status
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.Loadable import it.panov.musyx.state.Loadable
import it.panov.musyx.tv.state.Route import it.panov.musyx.state.Route
import it.panov.musyx.tv.state.Sheet import it.panov.musyx.state.Sheet
import it.panov.musyx.tv.ui.artistsOrUnknown import it.panov.musyx.tv.ui.artistsOrUnknown
import it.panov.musyx.tv.ui.clock import it.panov.musyx.tv.ui.clock
import it.panov.musyx.tv.ui.components.subtle import it.panov.musyx.tv.ui.components.subtle
@@ -55,11 +55,11 @@ import androidx.tv.material3.Text
import coil3.SingletonImageLoader import coil3.SingletonImageLoader
import coil3.compose.AsyncImage import coil3.compose.AsyncImage
import coil3.request.ImageRequest import coil3.request.ImageRequest
import it.panov.musyx.tv.api.Lyrics import it.panov.musyx.api.Lyrics
import it.panov.musyx.tv.api.Track import it.panov.musyx.api.Track
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.Loadable import it.panov.musyx.state.Loadable
import it.panov.musyx.tv.player.Status import it.panov.musyx.player.Status
import it.panov.musyx.tv.ui.artistsOrUnknown import it.panov.musyx.tv.ui.artistsOrUnknown
import it.panov.musyx.tv.ui.theme.CoverPlaceholder import it.panov.musyx.tv.ui.theme.CoverPlaceholder
import it.panov.musyx.tv.ui.theme.MusyxTheme import it.panov.musyx.tv.ui.theme.MusyxTheme
@@ -20,11 +20,11 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.api.BestMatch import it.panov.musyx.api.BestMatch
import it.panov.musyx.tv.api.SearchKind import it.panov.musyx.api.SearchKind
import it.panov.musyx.tv.state.ALL_TAB_TRACKS import it.panov.musyx.state.ALL_TAB_TRACKS
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.Route import it.panov.musyx.state.Route
import it.panov.musyx.tv.ui.artistsOrUnknown import it.panov.musyx.tv.ui.artistsOrUnknown
import it.panov.musyx.tv.ui.compact import it.panov.musyx.tv.ui.compact
import it.panov.musyx.tv.ui.components.subtle import it.panov.musyx.tv.ui.components.subtle
@@ -67,8 +67,8 @@ import com.google.zxing.BarcodeFormat
import com.google.zxing.EncodeHintType import com.google.zxing.EncodeHintType
import com.google.zxing.qrcode.QRCodeWriter import com.google.zxing.qrcode.QRCodeWriter
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.SignInState import it.panov.musyx.state.SignInState
import it.panov.musyx.tv.ui.Wordmark import it.panov.musyx.tv.ui.Wordmark
import it.panov.musyx.tv.ui.components.Focusable import it.panov.musyx.tv.ui.components.Focusable
import it.panov.musyx.tv.ui.components.GhostButton import it.panov.musyx.tv.ui.components.GhostButton
@@ -20,12 +20,12 @@ import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.BuildConfig import it.panov.musyx.tv.BuildConfig
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.data.Appearance import it.panov.musyx.data.Appearance
import it.panov.musyx.tv.data.FontSize import it.panov.musyx.data.FontSize
import it.panov.musyx.tv.data.Locale import it.panov.musyx.data.Locale
import it.panov.musyx.tv.data.Quality import it.panov.musyx.data.Quality
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.qualityLabel import it.panov.musyx.state.qualityLabel
import it.panov.musyx.tv.ui.components.Chip import it.panov.musyx.tv.ui.components.Chip
import it.panov.musyx.tv.ui.components.ChoiceRow import it.panov.musyx.tv.ui.components.ChoiceRow
import it.panov.musyx.tv.ui.components.FocusEntry import it.panov.musyx.tv.ui.components.FocusEntry
@@ -34,9 +34,9 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.Dialog
import androidx.tv.material3.Text import androidx.tv.material3.Text
import it.panov.musyx.tv.R import it.panov.musyx.tv.R
import it.panov.musyx.tv.state.AppState import it.panov.musyx.state.AppState
import it.panov.musyx.tv.state.Route import it.panov.musyx.state.Route
import it.panov.musyx.tv.state.Sheet import it.panov.musyx.state.Sheet
import it.panov.musyx.tv.ui.artistsOrUnknown import it.panov.musyx.tv.ui.artistsOrUnknown
import it.panov.musyx.tv.ui.components.subtle import it.panov.musyx.tv.ui.components.subtle
import it.panov.musyx.tv.ui.components.Divider import it.panov.musyx.tv.ui.components.Divider
@@ -162,7 +162,7 @@ private fun TrackMenu(state: AppState, sheet: Sheet.TrackMenu) {
track.album?.takeIf { here != Route.Album(it.id) }?.let { album -> track.album?.takeIf { here != Route.Album(it.id) }?.let { album ->
item { Item(R.drawable.ic_disc_3, stringResource(R.string.menu_go_to_album)) { state.navigate(Route.Album(album.id)) } } item { Item(R.drawable.ic_disc_3, stringResource(R.string.menu_go_to_album)) { state.navigate(Route.Album(album.id)) } }
} }
track.artists.filter { it.id != null && here != Route.Artist(it.id) }.take(3).forEach { artist -> track.artists.filter { a -> a.id?.let { here != Route.Artist(it) } == true }.take(3).forEach { artist ->
item { item {
Item(R.drawable.ic_mic_vocal, stringResource(R.string.menu_go_to_artist_named, artist.name)) { Item(R.drawable.ic_mic_vocal, stringResource(R.string.menu_go_to_artist_named, artist.name)) {
state.navigate(Route.Artist(artist.id!!)) state.navigate(Route.Artist(artist.id!!))
@@ -276,23 +276,6 @@ private fun MusyxRadius.toShapes() = Shapes(
// ---- Cover placeholder ---- // ---- Cover placeholder ----
/** Two stable hues for placeholder art; equal seeds give equal art. Port of ym-api `hues_for`. */
fun huesFor(seed: ULong): Pair<Float, Float> =
(seed * 47uL % 360uL).toFloat() to ((seed * 131uL + 90uL) % 360uL).toFloat()
/** Seeds per item kind, as in ym-api, so an item gets the same art as on the desktop. */
object CoverHues {
fun album(id: Long) = huesFor(id.toULong())
fun artist(id: Long) = huesFor(id.toULong() xor 0x5bd1_e995uL)
fun playlist(owner: Long, kind: Long) = huesFor(owner.toULong() * 1_000_003uL xor kind.toULong())
fun clip(id: Long) = huesFor(id.toULong() xor 0x2c1b_3c6duL)
/** A track borrows its album's art, or hashes its own (string) id. */
fun track(id: String, albumId: Long?): Pair<Float, Float> = huesFor(
albumId?.toULong() ?: id.encodeToByteArray().fold(7uL) { h, b -> h * 31uL + b.toUByte().toULong() },
)
}
/** Placeholder art for an item without a cover yet: two hues on a 135° diagonal. */ /** Placeholder art for an item without a cover yet: two hues on a 135° diagonal. */
fun coverBrush(h1: Float, h2: Float): Brush = Brush.linearGradient( fun coverBrush(h1: Float, h2: Float): Brush = Brush.linearGradient(
0f to hsl(h1, 0.70f, 0.60f), 0f to hsl(h1, 0.70f, 0.60f),
File renamed without changes.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 121 files, more files were not shown because too many files have changed in this diff. Show more