diff --git a/AGENTS.md b/AGENTS.md index 3978a18..c6ad0c1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -200,6 +200,28 @@ server in this repo. `StateFlow` that starts at null and is filled in by a background resolver for exactly this reason. The same caution applies to any future flow that needs the network to produce its first value. +- **Caching covers was never the missing piece; knowing their file name was.** The image loader has + had a 96 MB disk cache since the first commit (`CoilApplication.newImageLoader`), so a cover that + has been fetched once renders with the box switched off. What favourites lacked was a + `coverFile` to build a URL from: only an album favourite ever recorded one, and only if that + album's cover had already been resolved by the album grid. Everything else — the player's star, + every folder and track row in the library — saved `null` and nothing backfilled it, so the tab + was a wall of placeholder icons and the cache was never asked for anything. Two halves fix it, + and both are needed: the player passes `player.currentCoverFile()` when it saves, and + `ResolveFavoriteCoverUseCase` fills in the rest from `LibraryRepository.coverFileFor`. +- **A folder's cover is its first track's, and that costs up to three RPCs.** Nothing in the + protocol returns cover art for a folder, so `coverFileFor` resolves one track inside it: from the + Room cache when that level has been browsed, otherwise via `get_folder_content` first, and one + level deeper when the folder holds nothing but subfolders (an artist above its albums). It stops + there — a cover is not worth walking a tree for. This is why the lookup is driven by what is on + screen (`FavoritesViewModel.ensureCover`), capped by the same two-permit semaphore as the album + grid, tried once per favourite per session, and never run as a sweep over the table. The result + is persisted, so a favourite costs it once ever. +- **A cover lookup that failed because the box was off must be allowed to happen again.** + `FavoritesViewModel` keeps its "already asked" set in memory and clears it whenever the active box + or the connection changes; without that, opening the tab while offline would spend every + favourite's one attempt on an unreachable box and leave the covers missing until the app + restarted. - **There is no `core` RPC package.** `core.version`, `core.started_at` and `core.git_state` are *published topics*; asking for `core.version` over RPC answers with an error. Use `player.ctrl.playerstatus` as a reachability ping — it returns the poller's cached dict without @@ -377,9 +399,18 @@ Three levels, and the distinction matters: activity exists, and `RuntimeEnvironment.setQualifiers` inside a test body is too late (the same trap as the locale). Note this simulates the *window*, not the device: there are no system bars, no rounded corners and no notch in a golden. -- **Cover art never reaches the network.** The image loader is replaced with a fake engine that - answers every URL with a flat colour, instantly; the box's HTTP cover cache is not reachable - from CI, and an image arriving a frame late would make the golden depend on timing. +- **Cover art never reaches the network, and it is not a flat colour either.** The image loader + is replaced with a fake engine answering instantly from `FakeCoverArt` — the box's HTTP cover + cache is not reachable from CI, and an image arriving a frame late would make the golden + depend on timing. It used to answer every URL with one flat green rectangle, which meant the + goldens could not fail on a cropped, stretched, letterboxed, unclipped or swapped cover: all + of those look identical when the picture is one colour. `FakeCoverArt` draws a **3:2 + landscape** source (so `ContentScale.Crop` has to be doing something — `Fit` would letterbox), + with a **circle** inside the middle third (round when scaled right, an ellipse when stretched), + an asymmetric **wedge** and a full-width **base stripe** (so a mirrored or vertically offset + draw is not a picture that happens to match), and a **colour derived from the URL** (so two + covers are two colours). Everything is a pure function of the URL — `String.hashCode` is + specified by the JLS — because a golden cannot afford a picture that varies by host or run. - **Roborazzi captures the window, not the node**, whichever node it is handed — so a component golden shortens the window instead, via `@Config(qualifiers = "+h200dp")` on the class, rather than being a 40 dp chip above a screenful of background. @@ -390,11 +421,30 @@ Three levels, and the distinction matters: - **Roborazzi is pinned at 1.60.0** because 1.61.0 and later carry Kotlin 2.3 metadata that Kotlin 2.0.21 cannot read. Upgrading it means upgrading Kotlin and the Compose compiler too. -Covered so far: the whole app on three devices (player light and dark, library, favourites, -settings top and lower half, box management, one box's page, offline, onboarding), the player -screen (playing, paused, idle, web radio, sleep timer, light and dark), the library screen +Covered so far: the whole app on three devices (player light and dark, library, favourites in both +layouts, settings top and lower half, box management, one box's page, offline, onboarding), the +player screen (playing, paused, idle, web radio, sleep timer, light and dark), the library screen (folders, tracks, albums, search, no results, empty, light and dark) and the chrome components. +The favourites goldens carry **two entries with a `coverFile` and one without**, because both halves +matter: a cover has to render, and a favourite the box has no artwork for has to stay recognisable +by its placeholder icon. `favourites_compact_*` reaches the list layout by *clicking* the top bar +action rather than presetting the stored preference, so a toggle that stopped switching fails the +test instead of quietly capturing the same picture twice. `Fixtures.albums` does the same for the +album grid, four of six with artwork. + +`StoreFixtures.favorites` carries covers on three of four for a reason worth keeping: without them +that listing image is four empty tiles above a mini player that *does* show a cover, which reads as +artwork failing to load rather than as a design — and it contradicts what the app now does, since +a played folder gets its cover. The fourth keeps its placeholder, because a box genuinely does have +folders it has no artwork for. + +**Two fixtures can land on the same palette slot.** `FakeCoverArt` picks from five colours by URL +hash, so a grid meant to show that covers differ can end up with two identical tiles next to each +other — `cover-fairy-tales.jpg` and `cover-bedtime.jpg` collide, which is why the store fixture +spells it `cover-fairytales.jpg`. Check a new fixture's slot rather than assume: +`Math.floorMod(("http:///cover-cache/" + fileName).hashCode(), 5)`. + Box management is captured with **two** boxes configured (`app/boxes_*`, `app/box_detail_*`), since one box is the case where those screens have least to say — and the box page golden is the *non-active* box, which is the state the old settings screen could not reach at all. @@ -713,6 +763,17 @@ still needs doing, in rough order of importance: `core-data/.../db/Migrations.kt` — no destructive fallback, favourites are the one thing here that cannot be rebuilt from the box), a `track` variant of the `coil://play` deep link, and settings backup **format version 2**. +- **The favourites tab has two layouts, and the switch is in the top bar.** `FavoritesLayout` in + `AppSettings` chooses between the cover grid (the default — §7.2's point is a target a child can + aim at without reading) and a compact row list for a collection that has outgrown a screenful of + tiles. Consequences worth keeping: the preference is owned by `AppViewModel` and passed *into* + `FavoritesScreen`, because the control lives in the shell's top bar and one preference should have + one owner; the top bar's `actions` slot is per destination, so anything added there must stay + conditional on the route the way this is; and both layouts share one `LazyVerticalGrid` — + `GridCells.Fixed(1)` is the list — plus one `FavoriteEntry`, so neither shape can quietly lose an + action the other has. It also rides in the settings backup, which did **not** bump + `FORMAT_VERSION`: an older build that drops the field loses a layout preference, not the ability + to play anything. Same for the `coverFile` now exported per favourite. - **Long press in the library opens a context menu, it does not toggle a favourite.** The plan (§14, phase 2) has long press as the way to favourite something, which is undiscoverable and was the only way to do it. Every library row and album cell now carries a ⋮ button, and both it and a long diff --git a/CHANGELOG.md b/CHANGELOG.md index 24331be..b62b369 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,20 @@ automatically from the `## [x.y.z]` heading matching `versionName` in `app/build ## [Unreleased] +### Added +- **Favourites can be shown as a compact list**, switched with the new button in the top bar of that + tab. Covers stay the default — they are what makes a favourite something a child can aim at + without reading — but a collection that has outgrown a screenful of tiles is easier to scan as + rows. The choice is remembered + +### Fixed +- **Favourites now show cover art.** They almost never did: a favourite recorded a cover only when + it was saved from an album whose artwork happened to be loaded already, so the star on the player + and every folder and track in the library saved one with no cover at all — and nothing ever filled + it in later. A favourite saved while something is playing now keeps that cover, and any favourite + without one has it looked up when it comes on screen, once, and stored. Fetched artwork already + survived the box being switched off, in the image cache; there was simply nothing to fetch + ## [0.9.0] - 2026-08-05 ### Added diff --git a/app/src/main/kotlin/app/coilforphoniebox/ui/AppViewModel.kt b/app/src/main/kotlin/app/coilforphoniebox/ui/AppViewModel.kt index e213d11..9cca2a9 100644 --- a/app/src/main/kotlin/app/coilforphoniebox/ui/AppViewModel.kt +++ b/app/src/main/kotlin/app/coilforphoniebox/ui/AppViewModel.kt @@ -6,6 +6,7 @@ import app.coilforphoniebox.domain.model.AppSettings import app.coilforphoniebox.domain.model.Box import app.coilforphoniebox.domain.model.ConnectionState import app.coilforphoniebox.domain.model.ConnectionTestResult +import app.coilforphoniebox.domain.model.FavoritesLayout import app.coilforphoniebox.domain.model.PlayerStatus import app.coilforphoniebox.domain.repository.BoxRepository import app.coilforphoniebox.domain.repository.LibraryRepository @@ -35,7 +36,7 @@ class AppViewModel @Inject constructor( private val boxes: BoxRepository, private val player: PlayerRepository, private val library: LibraryRepository, - settings: SettingsRepository, + private val settings: SettingsRepository, ) : ViewModel() { data class State( @@ -118,4 +119,19 @@ class AppViewModel @Inject constructor( fun togglePlayback() { viewModelScope.launch { player.toggle() } } + + /** + * Switches the favourites tab between covers and rows. + * + * Lives here rather than in `FavoritesViewModel` because the control is in the top bar, + * which the shell owns — and it is a stored preference, so the tab comes back the way it + * was left. + */ + fun toggleFavoritesLayout() { + val next = when (state.value.settings.favoritesLayout) { + FavoritesLayout.GRID -> FavoritesLayout.LIST + FavoritesLayout.LIST -> FavoritesLayout.GRID + } + viewModelScope.launch { settings.setFavoritesLayout(next) } + } } diff --git a/app/src/main/kotlin/app/coilforphoniebox/ui/CoilApp.kt b/app/src/main/kotlin/app/coilforphoniebox/ui/CoilApp.kt index 11d840c..c4b9e66 100644 --- a/app/src/main/kotlin/app/coilforphoniebox/ui/CoilApp.kt +++ b/app/src/main/kotlin/app/coilforphoniebox/ui/CoilApp.kt @@ -6,6 +6,8 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.rounded.ArrowBack +import androidx.compose.material.icons.automirrored.rounded.ViewList +import androidx.compose.material.icons.rounded.GridView import androidx.compose.material.icons.rounded.LibraryMusic import androidx.compose.material.icons.rounded.PlayCircle import androidx.compose.material.icons.rounded.Settings @@ -40,6 +42,7 @@ import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import app.coilforphoniebox.R +import app.coilforphoniebox.domain.model.FavoritesLayout import app.coilforphoniebox.ui.boxes.AddBoxScreen import app.coilforphoniebox.ui.boxes.AddBoxViewModel import app.coilforphoniebox.ui.boxes.BoxDetailScreen @@ -140,6 +143,26 @@ fun CoilApp(appViewModel: AppViewModel) { } } }, + // Only the favourites tab has anything to put here. The action shows what a + // tap would switch *to*, so the icon and its label describe the same thing. + actions = { + if (currentRoute == Destination.FAVOURITES.route) { + val list = state.settings.favoritesLayout == FavoritesLayout.LIST + IconButton(onClick = appViewModel::toggleFavoritesLayout) { + Icon( + imageVector = if (list) { + Icons.Rounded.GridView + } else { + Icons.AutoMirrored.Rounded.ViewList + }, + contentDescription = stringResource( + if (list) R.string.action_favourites_show_grid + else R.string.action_favourites_show_list, + ), + ) + } + } + }, ) }, bottomBar = { @@ -188,7 +211,7 @@ fun CoilApp(appViewModel: AppViewModel) { composable(Destination.FAVOURITES.route) { val viewModel = hiltViewModel() SnackbarMessages(viewModel.messages, snackbarHostState) - FavoritesScreen(viewModel) + FavoritesScreen(viewModel, layout = state.settings.favoritesLayout) } composable(Destination.SETTINGS.route) { diff --git a/app/src/main/kotlin/app/coilforphoniebox/ui/favorites/FavoritesScreen.kt b/app/src/main/kotlin/app/coilforphoniebox/ui/favorites/FavoritesScreen.kt index 52720a5..6518a98 100644 --- a/app/src/main/kotlin/app/coilforphoniebox/ui/favorites/FavoritesScreen.kt +++ b/app/src/main/kotlin/app/coilforphoniebox/ui/favorites/FavoritesScreen.kt @@ -1,16 +1,16 @@ package app.coilforphoniebox.ui.favorites -import android.content.Context -import android.content.Intent import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid @@ -28,12 +28,14 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource @@ -45,13 +47,21 @@ import app.coilforphoniebox.R import app.coilforphoniebox.domain.model.Box as PhonieBox import app.coilforphoniebox.domain.model.Favorite import app.coilforphoniebox.domain.model.FavoriteType +import app.coilforphoniebox.domain.model.FavoritesLayout import app.coilforphoniebox.ui.components.CoverArt import app.coilforphoniebox.ui.components.EmptyState import app.coilforphoniebox.ui.components.shareLink +/** + * The favourites tab, in one of two layouts (§7.2). + * + * [layout] comes from settings via the shell rather than from this screen's own view model, + * because the control that changes it lives in the top bar — one preference, one owner. + */ @Composable fun FavoritesScreen( viewModel: FavoritesViewModel, + layout: FavoritesLayout, modifier: Modifier = Modifier, ) { val state by viewModel.state.collectAsStateWithLifecycle() @@ -66,17 +76,26 @@ fun FavoritesScreen( return } + // A single column of a grid is a list, so both layouts share one lazy container and one + // item block — which keeps the two from drifting apart in what they can do. + val compact = layout == FavoritesLayout.LIST + LazyVerticalGrid( - columns = GridCells.Adaptive(minSize = 148.dp), - contentPadding = PaddingValues(12.dp), + columns = if (compact) GridCells.Fixed(1) else GridCells.Adaptive(minSize = 148.dp), + contentPadding = if (compact) PaddingValues(vertical = 8.dp) else PaddingValues(12.dp), horizontalArrangement = Arrangement.spacedBy(12.dp), - verticalArrangement = Arrangement.spacedBy(12.dp), + verticalArrangement = Arrangement.spacedBy(if (compact) 2.dp else 12.dp), modifier = modifier, ) { items(state.favorites, key = { it.id }) { favorite -> - FavoriteCell( + // Cover art is fetched for the entries that are actually on screen, never for + // the whole table at once — see FavoritesViewModel.ensureCover. + LaunchedEffect(favorite.id, favorite.coverFile) { viewModel.ensureCover(favorite) } + + FavoriteEntry( favorite = favorite, box = state.activeBox, + compact = compact, link = viewModel.linkFor(favorite), onPlay = { viewModel.play(favorite) }, onRemove = { viewModel.remove(favorite) }, @@ -88,10 +107,17 @@ fun FavoritesScreen( } } +/** + * One favourite, as a cover tile or as a row. + * + * Everything that is not layout lives here — the cover URL, the menu and what it offers — + * so the two shapes differ in appearance only and neither can quietly lose an action. + */ @Composable -private fun FavoriteCell( +private fun FavoriteEntry( favorite: Favorite, box: PhonieBox?, + compact: Boolean, /** `coil://play` link for this favourite; null for a row that cannot be played. */ link: String?, onPlay: () -> Unit, @@ -104,9 +130,44 @@ private fun FavoriteCell( val coverUrl = remember(favorite.coverFile, box?.host) { favorite.coverFile?.let { file -> box?.coverUrl(file) } } - val clipboard = LocalClipboardManager.current - val context = LocalContext.current + val menuButton: @Composable () -> Unit = { + Box { + IconButton(onClick = { menuOpen = true }) { + Icon( + imageVector = Icons.Rounded.MoreVert, + contentDescription = stringResource(R.string.action_more), + ) + } + + FavoriteMenu( + expanded = menuOpen, + onDismiss = { menuOpen = false }, + label = favorite.label, + link = link, + onPin = { onPin(coverUrl) }, + onMove = onMove, + onRemove = onRemove, + onLinkCopied = onLinkCopied, + ) + } + } + + if (compact) { + FavoriteRow(favorite, coverUrl, onPlay, menuButton) + } else { + FavoriteCell(favorite, coverUrl, onPlay, menuButton) + } +} + +/** The big-cover tile: what favourites are for, and what a child aims at without reading. */ +@Composable +private fun FavoriteCell( + favorite: Favorite, + coverUrl: String?, + onPlay: () -> Unit, + menuButton: @Composable () -> Unit, +) { Column { Box { CoverArt( @@ -117,76 +178,10 @@ private fun FavoriteCell( .aspectRatio(1f) .clickable(onClick = onPlay), cornerRadius = 14.dp, - // Folders and single tracks have no artwork, so the placeholder is what - // tells a saved folder apart from a saved track at a glance. - placeholderIcon = when (favorite.type) { - FavoriteType.FOLDER -> Icons.Rounded.Folder - FavoriteType.ALBUM -> Icons.Rounded.Album - FavoriteType.TRACK -> Icons.Rounded.MusicNote - }, + placeholderIcon = favorite.placeholderIcon, ) - IconButton( - onClick = { menuOpen = true }, - modifier = Modifier.align(Alignment.TopEnd), - ) { - Icon( - imageVector = Icons.Rounded.MoreVert, - contentDescription = stringResource(R.string.action_more), - ) - } - - DropdownMenu(expanded = menuOpen, onDismissRequest = { menuOpen = false }) { - DropdownMenuItem( - text = { Text(stringResource(R.string.action_add_to_home_screen)) }, - onClick = { - menuOpen = false - onPin(coverUrl) - }, - ) - // The link is what a home screen shortcut points at. Handing it out lets an - // automation app, an NFC tag or a link in a note start this favourite on its - // own box — and it is the only way to see it, since the box id in it is a - // UUID shown nowhere else. - if (link != null) { - DropdownMenuItem( - text = { Text(stringResource(R.string.action_copy_link)) }, - onClick = { - menuOpen = false - clipboard.setText(AnnotatedString(link)) - onLinkCopied() - }, - ) - DropdownMenuItem( - text = { Text(stringResource(R.string.action_share_link)) }, - onClick = { - menuOpen = false - context.shareLink(link, favorite.label) - }, - ) - } - DropdownMenuItem( - text = { Text(stringResource(R.string.action_move_up)) }, - onClick = { - menuOpen = false - onMove(true) - }, - ) - DropdownMenuItem( - text = { Text(stringResource(R.string.action_move_down)) }, - onClick = { - menuOpen = false - onMove(false) - }, - ) - DropdownMenuItem( - text = { Text(stringResource(R.string.action_remove)) }, - onClick = { - menuOpen = false - onRemove() - }, - ) - } + Box(Modifier.align(Alignment.TopEnd)) { menuButton() } } Spacer(Modifier.height(6.dp)) @@ -199,3 +194,122 @@ private fun FavoriteCell( Spacer(Modifier.size(4.dp)) } } + +/** + * The compact row, for a collection that has outgrown a screenful of tiles: the same cover + * at thumbnail size, and the label on one line so four times as many fit. + */ +@Composable +private fun FavoriteRow( + favorite: Favorite, + coverUrl: String?, + onPlay: () -> Unit, + menuButton: @Composable () -> Unit, +) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .clickable(onClick = onPlay) + .padding(start = 16.dp, end = 4.dp, top = 4.dp, bottom = 4.dp), + ) { + CoverArt( + url = coverUrl, + contentDescription = null, + modifier = Modifier.size(48.dp), + cornerRadius = 8.dp, + placeholderIconSize = 24.dp, + placeholderIcon = favorite.placeholderIcon, + ) + + Text( + text = favorite.label, + style = MaterialTheme.typography.bodyLarge, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier + .weight(1f) + .padding(horizontal = 16.dp), + ) + + menuButton() + } +} + +@Composable +private fun FavoriteMenu( + expanded: Boolean, + onDismiss: () -> Unit, + label: String, + link: String?, + onPin: () -> Unit, + onMove: (Boolean) -> Unit, + onRemove: () -> Unit, + onLinkCopied: () -> Unit, +) { + val clipboard = LocalClipboardManager.current + val context = LocalContext.current + + DropdownMenu(expanded = expanded, onDismissRequest = onDismiss) { + DropdownMenuItem( + text = { Text(stringResource(R.string.action_add_to_home_screen)) }, + onClick = { + onDismiss() + onPin() + }, + ) + // The link is what a home screen shortcut points at. Handing it out lets an + // automation app, an NFC tag or a link in a note start this favourite on its + // own box — and it is the only way to see it, since the box id in it is a + // UUID shown nowhere else. + if (link != null) { + DropdownMenuItem( + text = { Text(stringResource(R.string.action_copy_link)) }, + onClick = { + onDismiss() + clipboard.setText(AnnotatedString(link)) + onLinkCopied() + }, + ) + DropdownMenuItem( + text = { Text(stringResource(R.string.action_share_link)) }, + onClick = { + onDismiss() + context.shareLink(link, label) + }, + ) + } + DropdownMenuItem( + text = { Text(stringResource(R.string.action_move_up)) }, + onClick = { + onDismiss() + onMove(true) + }, + ) + DropdownMenuItem( + text = { Text(stringResource(R.string.action_move_down)) }, + onClick = { + onDismiss() + onMove(false) + }, + ) + DropdownMenuItem( + text = { Text(stringResource(R.string.action_remove)) }, + onClick = { + onDismiss() + onRemove() + }, + ) + } +} + +/** + * What stands in for artwork the box has none of. A folder and a single track usually have + * no cover of their own, so the placeholder is what tells the two apart at a glance. + */ +private val Favorite.placeholderIcon: ImageVector + get() = when (type) { + FavoriteType.FOLDER -> Icons.Rounded.Folder + FavoriteType.ALBUM -> Icons.Rounded.Album + FavoriteType.TRACK -> Icons.Rounded.MusicNote + } diff --git a/app/src/main/kotlin/app/coilforphoniebox/ui/favorites/FavoritesViewModel.kt b/app/src/main/kotlin/app/coilforphoniebox/ui/favorites/FavoritesViewModel.kt index 07826ff..5c043ae 100644 --- a/app/src/main/kotlin/app/coilforphoniebox/ui/favorites/FavoritesViewModel.kt +++ b/app/src/main/kotlin/app/coilforphoniebox/ui/favorites/FavoritesViewModel.kt @@ -5,10 +5,13 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import app.coilforphoniebox.R import app.coilforphoniebox.domain.model.Box +import app.coilforphoniebox.domain.model.ConnectionState import app.coilforphoniebox.domain.model.Favorite import app.coilforphoniebox.domain.repository.BoxRepository import app.coilforphoniebox.domain.repository.FavoriteRepository +import app.coilforphoniebox.domain.repository.PlayerRepository import app.coilforphoniebox.domain.usecase.PlayFavoriteUseCase +import app.coilforphoniebox.domain.usecase.ResolveFavoriteCoverUseCase import app.coilforphoniebox.shortcuts.PlayDeepLink import app.coilforphoniebox.shortcuts.ShortcutPublisher import app.coilforphoniebox.ui.UiMessage @@ -33,13 +36,16 @@ import javax.inject.Inject class FavoritesViewModel @Inject constructor( private val favorites: FavoriteRepository, private val boxes: BoxRepository, + private val player: PlayerRepository, private val playFavorite: PlayFavoriteUseCase, + private val resolveCover: ResolveFavoriteCoverUseCase, private val shortcuts: ShortcutPublisher, ) : ViewModel() { data class State( val favorites: List = emptyList(), val activeBox: Box? = null, + val connection: ConnectionState = ConnectionState.DISCONNECTED, ) private val messageChannel = MutableSharedFlow( @@ -53,8 +59,46 @@ class FavoritesViewModel @Inject constructor( boxes.activeBox.map { it?.id }.distinctUntilChanged().flatMapLatest { boxId -> if (boxId == null) flowOf(emptyList()) else favorites.favorites(boxId) }, - ) { box, list -> State(favorites = list, activeBox = box) } - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), State()) + player.connectionState, + ) { box, list, connection -> + State(favorites = list, activeBox = box, connection = connection) + }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), State()) + + /** + * Favourites this session has already asked the box about, so a scroll back up the grid + * does not ask again for the ones that genuinely have no artwork. + * + * Deliberately not persisted, and cleared whenever the box or the connection changes: + * a lookup that came back empty because the box was unreachable must be allowed a second + * chance once it is back, or a missing cover would stay missing until the app restarts. + */ + private val coverAttempts = mutableSetOf() + + init { + viewModelScope.launch { + combine( + boxes.activeBox.map { it?.id }, + player.connectionState.map { it.isUsable }, + ) { boxId, usable -> boxId to usable } + .distinctUntilChanged() + .collect { coverAttempts.clear() } + } + } + + /** + * Resolves the cover art for a favourite that was saved without one, once it is on + * screen. Called from the entry itself rather than for the whole list, because each + * lookup is at least one RPC on the socket the box shares with its card reader (§6) — + * and the answer is stored, so it happens once per favourite rather than per visit. + */ + fun ensureCover(favorite: Favorite) { + if (favorite.coverFile != null) return + // Asking an unreachable box only burns the one attempt this favourite gets. + if (!state.value.connection.isUsable) return + if (!coverAttempts.add(favorite.id)) return + + viewModelScope.launch { resolveCover(favorite) } + } fun play(favorite: Favorite) { viewModelScope.launch { diff --git a/app/src/main/kotlin/app/coilforphoniebox/ui/player/PlayerViewModel.kt b/app/src/main/kotlin/app/coilforphoniebox/ui/player/PlayerViewModel.kt index 6f11ab9..6332999 100644 --- a/app/src/main/kotlin/app/coilforphoniebox/ui/player/PlayerViewModel.kt +++ b/app/src/main/kotlin/app/coilforphoniebox/ui/player/PlayerViewModel.kt @@ -269,6 +269,10 @@ class PlayerViewModel @Inject constructor( * * The label is the folder's own name — content from the box, so it is used exactly as * it comes (§12.4). + * + * The playing song's cover is stored with it: it is already resolved, it is a picture of + * what is in that folder, and saving it here is what spares the favourites tab a lookup + * of its own later. */ fun toggleFolderFavorite() { val current = state.value @@ -283,7 +287,14 @@ class PlayerViewModel @Inject constructor( return@launch } - favorites.add(Favorite.of(boxId, folderLabelFor(folder), PlayTarget.Folder(folder))) + favorites.add( + Favorite.of( + boxId = boxId, + label = folderLabelFor(folder), + target = PlayTarget.Folder(folder), + coverFile = player.currentCoverFile(), + ), + ) messageChannel.emit(UiMessage(R.string.favourites_added)) } } @@ -303,7 +314,14 @@ class PlayerViewModel @Inject constructor( return@launch } - favorites.add(Favorite.of(boxId, label, PlayTarget.Track(file))) + favorites.add( + Favorite.of( + boxId = boxId, + label = label, + target = PlayTarget.Track(file), + coverFile = player.currentCoverFile(), + ), + ) messageChannel.emit(UiMessage(R.string.favourites_added)) } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index f09ca3a..ab20dd5 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -71,6 +71,8 @@ Nach oben Nach unten Dieser Launcher unterstützt keine Verknüpfungen auf dem Startbildschirm. + Als Liste anzeigen + Als Cover anzeigen Boxen Box wechseln diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index a9c0ef8..6262f24 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -71,6 +71,8 @@ Mover arriba Mover abajo Este lanzador no admite accesos directos en la pantalla de inicio. + Ver como lista + Ver las portadas Cajas Cambiar de caja diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 259b47b..cc2550e 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -75,6 +75,8 @@ Déplacer vers le haut Déplacer vers le bas Ce lanceur ne prend pas en charge les raccourcis sur l\'écran d\'accueil. + Afficher en liste + Afficher les pochettes Box Changer de box diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index b2d1dd4..4a47d43 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -71,6 +71,8 @@ Omhoog Omlaag Deze launcher ondersteunt geen snelkoppelingen op het startscherm. + Als lijst weergeven + Als hoezen weergeven Boxen Andere box kiezen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e2dc01c..66fed66 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -136,6 +136,10 @@ Move up Move down This launcher does not support home screen shortcuts. + + Show as list + Show as covers Boxes diff --git a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/AppScreenshotTest.kt b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/AppScreenshotTest.kt index cf2e1b4..87505f5 100644 --- a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/AppScreenshotTest.kt +++ b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/AppScreenshotTest.kt @@ -1,5 +1,6 @@ package app.coilforphoniebox.screenshot +import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollTo @@ -87,6 +88,20 @@ abstract class AppScreenshotTest : ScreenshotTest() { captureRoot("app/favourites_$device") } + /** + * The same favourites as rows, reached the way a user reaches them: the top bar action on + * that tab. Clicking it rather than presetting the stored layout keeps the control itself + * in the picture — a toggle that stopped switching would fail here. + */ + @Test + fun favourites_compact() { + showApp() + navigateTo(R.string.nav_favourites) + compose.onNodeWithContentDescription(string(R.string.action_favourites_show_list)).performClick() + compose.waitForIdle() + captureRoot("app/favourites_compact_$device") + } + @Test fun settings() { showApp() diff --git a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/FakeCoverArt.kt b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/FakeCoverArt.kt new file mode 100644 index 0000000..3c5a5fe --- /dev/null +++ b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/FakeCoverArt.kt @@ -0,0 +1,104 @@ +package app.coilforphoniebox.screenshot + +import android.content.res.Resources +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.Path +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable + +/** + * Synthetic album art for the screenshot tests. + * + * A flat colour used to stand in for every cover, which made the goldens blind to most of the + * ways cover display actually goes wrong: a stretched image, a `Fit` where `Crop` was meant, a + * missing rounded-corner clip, or the wrong cover against the wrong title all look identical + * when the picture is one rectangle of one colour. Each of those now shows up: + * + * - **The source is 3:2 landscape, not square.** Every cover in the app is drawn into a square + * or fixed box with `ContentScale.Crop`, so a non-square source is what proves the crop is + * happening at all — `Fit` would letterbox and leave background showing. + * - **A circle is the aspect detector.** Scaled correctly it stays round; stretched to fill a + * square it becomes a visible ellipse. It sits inside the middle third so a centre crop keeps + * it whole. + * - **The wedge and the base stripe are asymmetric**, so a mirrored, rotated or vertically + * offset draw is not a picture that happens to look the same. + * - **The colour comes from the URL**, so two covers are two colours and a cover shown against + * the wrong title is visible rather than plausible. + * + * Everything here is a pure function of the URL — `String.hashCode` is specified by the JLS, so + * the same URL is the same picture on every host and every run, which is the one property a + * golden cannot do without. + */ +object FakeCoverArt { + + /** 3:2, deliberately — see the note above about proving the crop. */ + private const val WIDTH = 360 + private const val HEIGHT = 240 + + /** + * Muted and brand-adjacent rather than loud: these reach the Play Store screenshots through + * the same harness, where a page of primary colours would read as test scaffolding. + * + * Five slots means two fixtures can land on the same colour, which matters only where they + * end up side by side — a grid of covers that is meant to show they differ. When adding a + * fixture cover, check its slot rather than assume: + * + * ``` + * Math.floorMod(("http:///cover-cache/" + fileName).hashCode(), 5) + * ``` + */ + private val BASE_COLORS = intArrayOf( + 0xFF3B5A46.toInt(), // deep green — the colour every cover used to be + 0xFF4A5570.toInt(), // slate blue + 0xFF6B4A3C.toInt(), // warm brown + 0xFF4F4A63.toInt(), // muted violet + 0xFF3F5860.toInt(), // teal + ) + + fun drawable(resources: Resources, url: String): Drawable = + BitmapDrawable(resources, bitmap(url)) + + private fun bitmap(url: String): Bitmap { + val bitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val base = BASE_COLORS[(url.hashCode().mod(BASE_COLORS.size))] + val paint = Paint().apply { isAntiAlias = true } + + canvas.drawColor(base) + + // A wedge out of the bottom-left corner: orientation, and something for a wrong crop + // anchor to move. + paint.color = shift(base, 1.35f) + canvas.drawPath( + Path().apply { + moveTo(0f, HEIGHT.toFloat()) + lineTo(WIDTH * 0.55f, HEIGHT.toFloat()) + lineTo(0f, HEIGHT * 0.25f) + close() + }, + paint, + ) + + // Inside the middle third, so a centre crop keeps it whole and its roundness is the + // thing a stretched image loses. + paint.color = shift(base, 1.85f) + canvas.drawCircle(WIDTH * 0.52f, HEIGHT * 0.42f, HEIGHT * 0.24f, paint) + + // Full-width stripe along the bottom: survives the crop, so a vertical offset shows as + // a stripe that is too thick, too thin or gone. + paint.color = shift(base, 0.6f) + canvas.drawRect(0f, HEIGHT * 0.88f, WIDTH.toFloat(), HEIGHT.toFloat(), paint) + + return bitmap + } + + /** Lightens ([factor] above 1) or darkens the channels of [color], staying in range. */ + private fun shift(color: Int, factor: Float): Int { + fun channel(shift: Int): Int = + (((color shr shift) and 0xFF) * factor).toInt().coerceIn(0, 0xFF) + + return (0xFF shl 24) or (channel(16) shl 16) or (channel(8) shl 8) or channel(0) + } +} diff --git a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/FakeRepositories.kt b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/FakeRepositories.kt index f25b4ab..f7bfd56 100644 --- a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/FakeRepositories.kt +++ b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/FakeRepositories.kt @@ -5,6 +5,7 @@ import app.coilforphoniebox.domain.model.Box import app.coilforphoniebox.domain.model.ConnectionState import app.coilforphoniebox.domain.model.ConnectionTestResult import app.coilforphoniebox.domain.model.Favorite +import app.coilforphoniebox.domain.model.FavoritesLayout import app.coilforphoniebox.domain.model.FolderContent import app.coilforphoniebox.domain.model.LibraryAlbum import app.coilforphoniebox.domain.model.LibraryIndexResult @@ -47,6 +48,7 @@ class FakePlayerRepository( coverUrl: String? = null, sleepTimer: SleepTimerStatus = SleepTimerStatus.Off, boxVersion: String? = "future3/main", + private val coverFile: String? = null, ) : PlayerRepository { override val status = MutableStateFlow(status) override val volume = MutableStateFlow(volume) @@ -55,6 +57,8 @@ class FakePlayerRepository( override val coverUrl = MutableStateFlow(coverUrl) override val sleepTimer = MutableStateFlow(sleepTimer) + override fun currentCoverFile(): String? = coverFile + override suspend fun play(): Result = Result.success(Unit) override suspend fun pause(): Result = Result.success(Unit) override suspend fun toggle(): Result = Result.success(Unit) @@ -145,6 +149,10 @@ class FakeFavoriteRepository(favorites: List = emptyList()) : Favorite override suspend fun reorder(ids: List) = Unit override suspend fun recordLaunch(id: Long) = Unit override suspend fun setPinned(id: Long, pinned: Boolean) = Unit + + override suspend fun setCover(id: Long, coverFile: String) { + all.value = all.value.map { if (it.id == id) it.copy(coverFile = coverFile) else it } + } } /** @@ -181,6 +189,13 @@ class FakeLibraryRepository( override suspend fun ensureAlbumCover(boxId: String, albumArtist: String, album: String) = Unit + /** + * Null, deliberately: a golden has to be the same picture every run, and a cover that + * appeared as the result of a lookup would depend on when the lookup finished. A + * favourite that is meant to show artwork carries its `coverFile` from the start. + */ + override suspend fun coverFileFor(boxId: String, target: PlayTarget): String? = null + override suspend fun rescanBoxLibrary(boxId: String): Result = Result.success(Unit) override suspend fun refreshIfStaleAndIdle(boxId: String) = Unit @@ -216,6 +231,10 @@ class FakeSettingsRepository(settings: AppSettings = AppSettings()) : SettingsRe state.value = state.value.copy(sessionMode = mode) } + override suspend fun setFavoritesLayout(layout: FavoritesLayout) { + state.value = state.value.copy(favoritesLayout = layout) + } + override suspend fun setOnboardingComplete(complete: Boolean) { state.value = state.value.copy(onboardingComplete = complete) } diff --git a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/Fixtures.kt b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/Fixtures.kt index 29e2ed9..d5b5865 100644 --- a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/Fixtures.kt +++ b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/Fixtures.kt @@ -136,19 +136,25 @@ object Fixtures { durationSeconds = seconds, ) - private fun album(artist: String, name: String) = LibraryAlbum( + private fun album(artist: String, name: String, cover: String? = null) = LibraryAlbum( boxId = livingRoom.id, albumArtist = artist, album = name, + coverFile = cover, cachedAt = NOW, ) + /** + * Four with artwork and two without, so the album grid is a picture of both cases — a + * resolved cover next to an album the box has no art for. The names are a stand-in; what + * they produce is [FakeCoverArt], one distinct cover per URL. + */ val albums = listOf( - album("Bärenstark", "Ein Bär räumt auf"), - album("Detective Stories", "The Missing Key"), - album("Detective Stories", "The Silent Lighthouse"), + album("Bärenstark", "Ein Bär räumt auf", "cover-baer.jpg"), + album("Detective Stories", "The Missing Key", "cover-missing-key.jpg"), + album("Detective Stories", "The Silent Lighthouse", "cover-lighthouse.jpg"), album("Nursery Rhymes", "Ten in the Bed"), - album("Nursery Rhymes", "Wheels on the Bus"), + album("Nursery Rhymes", "Wheels on the Bus", "cover-wheels.jpg"), album("Sing-Along", "Songs for the Long Drive Home"), ) @@ -165,6 +171,13 @@ object Fixtures { // --------------------------------------------------------------- favourites + /** + * Two with artwork and one without, which is the mix worth a golden: a cover has to + * render *and* a favourite the box has no artwork for has to stay recognisable by its + * placeholder. The file names are a stand-in, but not an inert one — [FakeCoverArt] + * derives a different picture from each, so a cover shown against the wrong title is + * something the golden can fail on. + */ val favorites = listOf( Favorite( id = 1, @@ -172,6 +185,7 @@ object Fixtures { label = "Bedtime Stories", type = FavoriteType.FOLDER, folder = "Bedtime Stories", + coverFile = "cover-bedtime.jpg", sortIndex = 0, launchCount = 31, ), @@ -182,6 +196,7 @@ object Fixtures { type = FavoriteType.ALBUM, albumArtist = "Detective Stories", album = "The Missing Key", + coverFile = "cover-missing-key.jpg", sortIndex = 1, launchCount = 12, ), diff --git a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/ScreenshotTest.kt b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/ScreenshotTest.kt index b52c0d1..e1770de 100644 --- a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/ScreenshotTest.kt +++ b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/ScreenshotTest.kt @@ -1,6 +1,5 @@ package app.coilforphoniebox.screenshot -import android.graphics.drawable.ColorDrawable import android.os.Looper import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -18,6 +17,8 @@ import app.coilforphoniebox.HiltTestActivity import app.coilforphoniebox.ui.theme.CoilTheme import coil.Coil import coil.ImageLoader +import coil.decode.DataSource +import coil.request.SuccessResult import coil.test.FakeImageLoaderEngine import com.github.takahirom.roborazzi.captureRoboImage import dagger.hilt.android.testing.HiltAndroidRule @@ -58,12 +59,28 @@ abstract class ScreenshotTest { /** * Cover art must never be a real request. The box's HTTP cover cache is not reachable from * CI, and an image that arrives a frame late would make the golden depend on timing rather - * than on the layout — so every URL resolves to the same flat colour, instantly. + * than on the layout — so every URL resolves instantly, from [FakeCoverArt]. + * + * It answers with synthetic artwork rather than a flat colour on purpose: one rectangle of + * one colour looks the same whether it was cropped, stretched, letterboxed, left unclipped + * or swapped with a different cover, which left these goldens unable to fail on any of it. + * See [FakeCoverArt] for what each part of the picture is there to catch. + * + * The interceptor is added rather than set as the default because only that path receives + * the engine's transformed request, which is the one with the crossfade removed — an image + * that fades in would put timing back into the golden. */ @Before fun installFakeImageLoader() { + val resources = RuntimeEnvironment.getApplication().resources val engine = FakeImageLoaderEngine.Builder() - .default(ColorDrawable(FAKE_COVER_COLOR)) + .addInterceptor { chain -> + SuccessResult( + drawable = FakeCoverArt.drawable(resources, chain.request.data.toString()), + request = chain.request, + dataSource = DataSource.MEMORY, + ) + } .build() Coil.setImageLoader( ImageLoader.Builder(RuntimeEnvironment.getApplication()) @@ -194,8 +211,5 @@ abstract class ScreenshotTest { /** How far the clock steps between checks in [awaitText]. */ const val POLL_MILLIS = 250L - - /** A muted green, close enough to real artwork to show how the layout carries it. */ - const val FAKE_COVER_COLOR = 0xFF3B5A46.toInt() } } diff --git a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/StoreFixtures.kt b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/StoreFixtures.kt index f54518f..d32c05f 100644 --- a/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/StoreFixtures.kt +++ b/app/src/testDebug/kotlin/app/coilforphoniebox/screenshot/StoreFixtures.kt @@ -85,6 +85,15 @@ object StoreFixtures { ), ) + /** + * Three with artwork and one without, which is what a used favourites tab looks like: a + * folder that has been played carries the cover Coil resolved for it, and one whose tracks + * have no embedded art keeps its placeholder. + * + * The covers are not decoration on a listing image — without them this shot is four empty + * tiles above a mini player that *does* show a cover, which reads as artwork failing to + * load rather than as a design. + */ val favorites = listOf( Favorite( id = 1, @@ -92,6 +101,7 @@ object StoreFixtures { label = "Bedtime Stories", type = FavoriteType.FOLDER, folder = "Bedtime Stories", + coverFile = "cover-bedtime.jpg", sortIndex = 0, launchCount = 31, ), @@ -102,6 +112,7 @@ object StoreFixtures { type = FavoriteType.ALBUM, albumArtist = "Detective Stories", album = "The Missing Key", + coverFile = "cover-missing-key.jpg", sortIndex = 1, launchCount = 12, ), @@ -111,6 +122,10 @@ object StoreFixtures { label = "Fairy Tales", type = FavoriteType.FOLDER, folder = "Fairy Tales", + // Not "cover-fairy-tales.jpg": that lands in the same palette slot as the + // bedtime cover, and two adjacent tiles of one colour is what this shot is + // meant to disprove. See FakeCoverArt on picking a fixture's file name. + coverFile = "cover-fairytales.jpg", sortIndex = 2, launchCount = 9, ), diff --git a/app/src/testDebug/screenshots/app/box_detail_phone.png b/app/src/testDebug/screenshots/app/box_detail_phone.png index 06141f6..1722f74 100644 Binary files a/app/src/testDebug/screenshots/app/box_detail_phone.png and b/app/src/testDebug/screenshots/app/box_detail_phone.png differ diff --git a/app/src/testDebug/screenshots/app/box_detail_small.png b/app/src/testDebug/screenshots/app/box_detail_small.png index d93e253..32e9384 100644 Binary files a/app/src/testDebug/screenshots/app/box_detail_small.png and b/app/src/testDebug/screenshots/app/box_detail_small.png differ diff --git a/app/src/testDebug/screenshots/app/box_detail_tablet.png b/app/src/testDebug/screenshots/app/box_detail_tablet.png index 497cbd0..7a8565e 100644 Binary files a/app/src/testDebug/screenshots/app/box_detail_tablet.png and b/app/src/testDebug/screenshots/app/box_detail_tablet.png differ diff --git a/app/src/testDebug/screenshots/app/boxes_phone.png b/app/src/testDebug/screenshots/app/boxes_phone.png index aeea0ee..8daba0d 100644 Binary files a/app/src/testDebug/screenshots/app/boxes_phone.png and b/app/src/testDebug/screenshots/app/boxes_phone.png differ diff --git a/app/src/testDebug/screenshots/app/boxes_small.png b/app/src/testDebug/screenshots/app/boxes_small.png index 87b2acd..9794564 100644 Binary files a/app/src/testDebug/screenshots/app/boxes_small.png and b/app/src/testDebug/screenshots/app/boxes_small.png differ diff --git a/app/src/testDebug/screenshots/app/boxes_tablet.png b/app/src/testDebug/screenshots/app/boxes_tablet.png index dace543..e26b621 100644 Binary files a/app/src/testDebug/screenshots/app/boxes_tablet.png and b/app/src/testDebug/screenshots/app/boxes_tablet.png differ diff --git a/app/src/testDebug/screenshots/app/favourites_compact_phone.png b/app/src/testDebug/screenshots/app/favourites_compact_phone.png new file mode 100644 index 0000000..fbeafce Binary files /dev/null and b/app/src/testDebug/screenshots/app/favourites_compact_phone.png differ diff --git a/app/src/testDebug/screenshots/app/favourites_compact_small.png b/app/src/testDebug/screenshots/app/favourites_compact_small.png new file mode 100644 index 0000000..6535437 Binary files /dev/null and b/app/src/testDebug/screenshots/app/favourites_compact_small.png differ diff --git a/app/src/testDebug/screenshots/app/favourites_compact_tablet.png b/app/src/testDebug/screenshots/app/favourites_compact_tablet.png new file mode 100644 index 0000000..63d4bc1 Binary files /dev/null and b/app/src/testDebug/screenshots/app/favourites_compact_tablet.png differ diff --git a/app/src/testDebug/screenshots/app/favourites_phone.png b/app/src/testDebug/screenshots/app/favourites_phone.png index c7265a6..2599953 100644 Binary files a/app/src/testDebug/screenshots/app/favourites_phone.png and b/app/src/testDebug/screenshots/app/favourites_phone.png differ diff --git a/app/src/testDebug/screenshots/app/favourites_small.png b/app/src/testDebug/screenshots/app/favourites_small.png index a312883..7219b81 100644 Binary files a/app/src/testDebug/screenshots/app/favourites_small.png and b/app/src/testDebug/screenshots/app/favourites_small.png differ diff --git a/app/src/testDebug/screenshots/app/favourites_tablet.png b/app/src/testDebug/screenshots/app/favourites_tablet.png index 32ce5af..1319a19 100644 Binary files a/app/src/testDebug/screenshots/app/favourites_tablet.png and b/app/src/testDebug/screenshots/app/favourites_tablet.png differ diff --git a/app/src/testDebug/screenshots/app/library_phone.png b/app/src/testDebug/screenshots/app/library_phone.png index 44c0716..787c761 100644 Binary files a/app/src/testDebug/screenshots/app/library_phone.png and b/app/src/testDebug/screenshots/app/library_phone.png differ diff --git a/app/src/testDebug/screenshots/app/library_small.png b/app/src/testDebug/screenshots/app/library_small.png index 87bc323..074225c 100644 Binary files a/app/src/testDebug/screenshots/app/library_small.png and b/app/src/testDebug/screenshots/app/library_small.png differ diff --git a/app/src/testDebug/screenshots/app/library_tablet.png b/app/src/testDebug/screenshots/app/library_tablet.png index 090f64c..371c537 100644 Binary files a/app/src/testDebug/screenshots/app/library_tablet.png and b/app/src/testDebug/screenshots/app/library_tablet.png differ diff --git a/app/src/testDebug/screenshots/app/offline_phone.png b/app/src/testDebug/screenshots/app/offline_phone.png index 2e55a04..955a548 100644 Binary files a/app/src/testDebug/screenshots/app/offline_phone.png and b/app/src/testDebug/screenshots/app/offline_phone.png differ diff --git a/app/src/testDebug/screenshots/app/offline_small.png b/app/src/testDebug/screenshots/app/offline_small.png index 890055a..e0adb36 100644 Binary files a/app/src/testDebug/screenshots/app/offline_small.png and b/app/src/testDebug/screenshots/app/offline_small.png differ diff --git a/app/src/testDebug/screenshots/app/offline_tablet.png b/app/src/testDebug/screenshots/app/offline_tablet.png index fc521a0..9517f81 100644 Binary files a/app/src/testDebug/screenshots/app/offline_tablet.png and b/app/src/testDebug/screenshots/app/offline_tablet.png differ diff --git a/app/src/testDebug/screenshots/app/player_dark_phone.png b/app/src/testDebug/screenshots/app/player_dark_phone.png index 352b1b7..8b51b8e 100644 Binary files a/app/src/testDebug/screenshots/app/player_dark_phone.png and b/app/src/testDebug/screenshots/app/player_dark_phone.png differ diff --git a/app/src/testDebug/screenshots/app/player_dark_small.png b/app/src/testDebug/screenshots/app/player_dark_small.png index e7415d5..e77ede7 100644 Binary files a/app/src/testDebug/screenshots/app/player_dark_small.png and b/app/src/testDebug/screenshots/app/player_dark_small.png differ diff --git a/app/src/testDebug/screenshots/app/player_dark_tablet.png b/app/src/testDebug/screenshots/app/player_dark_tablet.png index 198206d..56eb960 100644 Binary files a/app/src/testDebug/screenshots/app/player_dark_tablet.png and b/app/src/testDebug/screenshots/app/player_dark_tablet.png differ diff --git a/app/src/testDebug/screenshots/app/player_phone.png b/app/src/testDebug/screenshots/app/player_phone.png index 3243097..cc15176 100644 Binary files a/app/src/testDebug/screenshots/app/player_phone.png and b/app/src/testDebug/screenshots/app/player_phone.png differ diff --git a/app/src/testDebug/screenshots/app/player_small.png b/app/src/testDebug/screenshots/app/player_small.png index 11d9870..05e2bea 100644 Binary files a/app/src/testDebug/screenshots/app/player_small.png and b/app/src/testDebug/screenshots/app/player_small.png differ diff --git a/app/src/testDebug/screenshots/app/player_tablet.png b/app/src/testDebug/screenshots/app/player_tablet.png index 347deed..e325fb6 100644 Binary files a/app/src/testDebug/screenshots/app/player_tablet.png and b/app/src/testDebug/screenshots/app/player_tablet.png differ diff --git a/app/src/testDebug/screenshots/app/settings_lower_phone.png b/app/src/testDebug/screenshots/app/settings_lower_phone.png index c44dea8..0b81e74 100644 Binary files a/app/src/testDebug/screenshots/app/settings_lower_phone.png and b/app/src/testDebug/screenshots/app/settings_lower_phone.png differ diff --git a/app/src/testDebug/screenshots/app/settings_lower_small.png b/app/src/testDebug/screenshots/app/settings_lower_small.png index ece1690..a018059 100644 Binary files a/app/src/testDebug/screenshots/app/settings_lower_small.png and b/app/src/testDebug/screenshots/app/settings_lower_small.png differ diff --git a/app/src/testDebug/screenshots/app/settings_lower_tablet.png b/app/src/testDebug/screenshots/app/settings_lower_tablet.png index c24e500..9021533 100644 Binary files a/app/src/testDebug/screenshots/app/settings_lower_tablet.png and b/app/src/testDebug/screenshots/app/settings_lower_tablet.png differ diff --git a/app/src/testDebug/screenshots/app/settings_phone.png b/app/src/testDebug/screenshots/app/settings_phone.png index e242ef9..e91c125 100644 Binary files a/app/src/testDebug/screenshots/app/settings_phone.png and b/app/src/testDebug/screenshots/app/settings_phone.png differ diff --git a/app/src/testDebug/screenshots/app/settings_small.png b/app/src/testDebug/screenshots/app/settings_small.png index 3158e94..6f7abc1 100644 Binary files a/app/src/testDebug/screenshots/app/settings_small.png and b/app/src/testDebug/screenshots/app/settings_small.png differ diff --git a/app/src/testDebug/screenshots/app/settings_tablet.png b/app/src/testDebug/screenshots/app/settings_tablet.png index c4b62dc..2e7ac0c 100644 Binary files a/app/src/testDebug/screenshots/app/settings_tablet.png and b/app/src/testDebug/screenshots/app/settings_tablet.png differ diff --git a/app/src/testDebug/screenshots/chrome/mini_player_playing.png b/app/src/testDebug/screenshots/chrome/mini_player_playing.png index 3673e3f..3970c67 100644 Binary files a/app/src/testDebug/screenshots/chrome/mini_player_playing.png and b/app/src/testDebug/screenshots/chrome/mini_player_playing.png differ diff --git a/app/src/testDebug/screenshots/library/albums_light.png b/app/src/testDebug/screenshots/library/albums_light.png index a2dc268..94e44ea 100644 Binary files a/app/src/testDebug/screenshots/library/albums_light.png and b/app/src/testDebug/screenshots/library/albums_light.png differ diff --git a/app/src/testDebug/screenshots/player/paused_light.png b/app/src/testDebug/screenshots/player/paused_light.png index 5dd53d8..89a4929 100644 Binary files a/app/src/testDebug/screenshots/player/paused_light.png and b/app/src/testDebug/screenshots/player/paused_light.png differ diff --git a/app/src/testDebug/screenshots/player/playing_dark.png b/app/src/testDebug/screenshots/player/playing_dark.png index f878b70..261258d 100644 Binary files a/app/src/testDebug/screenshots/player/playing_dark.png and b/app/src/testDebug/screenshots/player/playing_dark.png differ diff --git a/app/src/testDebug/screenshots/player/playing_landscape.png b/app/src/testDebug/screenshots/player/playing_landscape.png index b3a26cd..5149dd7 100644 Binary files a/app/src/testDebug/screenshots/player/playing_landscape.png and b/app/src/testDebug/screenshots/player/playing_landscape.png differ diff --git a/app/src/testDebug/screenshots/player/playing_light.png b/app/src/testDebug/screenshots/player/playing_light.png index 6836528..32e6e62 100644 Binary files a/app/src/testDebug/screenshots/player/playing_light.png and b/app/src/testDebug/screenshots/player/playing_light.png differ diff --git a/app/src/testDebug/screenshots/player/sleep_timer_light.png b/app/src/testDebug/screenshots/player/sleep_timer_light.png index 32cde5e..18f2104 100644 Binary files a/app/src/testDebug/screenshots/player/sleep_timer_light.png and b/app/src/testDebug/screenshots/player/sleep_timer_light.png differ diff --git a/core-data/src/main/kotlin/app/coilforphoniebox/data/db/FavoriteDao.kt b/core-data/src/main/kotlin/app/coilforphoniebox/data/db/FavoriteDao.kt index e828d16..d065c87 100644 --- a/core-data/src/main/kotlin/app/coilforphoniebox/data/db/FavoriteDao.kt +++ b/core-data/src/main/kotlin/app/coilforphoniebox/data/db/FavoriteDao.kt @@ -54,6 +54,9 @@ interface FavoriteDao { @Query("UPDATE favorites SET shortcutPinned = :pinned WHERE id = :id") suspend fun setPinned(id: Long, pinned: Boolean) + @Query("UPDATE favorites SET coverFile = :coverFile WHERE id = :id") + suspend fun setCover(id: Long, coverFile: String) + @Query("SELECT COALESCE(MAX(sortIndex), -1) FROM favorites WHERE boxId = :boxId") suspend fun maxSortIndex(boxId: String): Int diff --git a/core-data/src/main/kotlin/app/coilforphoniebox/data/db/LibraryDao.kt b/core-data/src/main/kotlin/app/coilforphoniebox/data/db/LibraryDao.kt index def44b4..62451ec 100644 --- a/core-data/src/main/kotlin/app/coilforphoniebox/data/db/LibraryDao.kt +++ b/core-data/src/main/kotlin/app/coilforphoniebox/data/db/LibraryDao.kt @@ -27,6 +27,26 @@ interface LibraryDao { @Query("SELECT contentCachedAt FROM library_folders WHERE boxId = :boxId AND path = :path") fun observeContentCachedAt(boxId: String, path: String): Flow + /** + * First track of a level, in the order the browser shows it. Nothing in the protocol + * returns a folder's cover art, so this is what stands in for one. + */ + @Query( + "SELECT * FROM library_tracks WHERE boxId = :boxId AND parentPath = :parentPath " + + "ORDER BY trackNo IS NULL, trackNo ASC, title COLLATE NOCASE ASC LIMIT 1", + ) + suspend fun firstTrackIn(boxId: String, parentPath: String): LibraryTrackEntity? + + /** + * First subfolder of a level, for a folder that holds no tracks of its own. A listing + * carries the level itself as well, which is why it is excluded here. + */ + @Query( + "SELECT * FROM library_folders WHERE boxId = :boxId AND parentPath = :parentPath " + + "AND path != :parentPath ORDER BY displayName COLLATE NOCASE ASC LIMIT 1", + ) + suspend fun firstFolderIn(boxId: String, parentPath: String): LibraryFolderEntity? + @Query( "SELECT * FROM library_albums WHERE boxId = :boxId " + "ORDER BY albumArtist COLLATE NOCASE ASC, album COLLATE NOCASE ASC", diff --git a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/BackupRepositoryImpl.kt b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/BackupRepositoryImpl.kt index 662fb10..f5837ea 100644 --- a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/BackupRepositoryImpl.kt +++ b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/BackupRepositoryImpl.kt @@ -8,6 +8,7 @@ import app.coilforphoniebox.data.settings.SettingsStore import app.coilforphoniebox.domain.model.Box import app.coilforphoniebox.domain.model.Favorite import app.coilforphoniebox.domain.model.FavoriteType +import app.coilforphoniebox.domain.model.FavoritesLayout import app.coilforphoniebox.domain.model.SessionMode import app.coilforphoniebox.domain.model.ThemeMode import app.coilforphoniebox.domain.repository.BackupRepository @@ -64,6 +65,12 @@ class BackupRepositoryImpl @Inject constructor( /** Added with format version 2, together with `TRACK` favourites. */ val trackUrl: String? = null, val sortIndex: Int = 0, + /** + * Saves the box a round of cover lookups after a reinstall. The name is a hash in + * the box's own cover cache, so it stays valid for the same box and means nothing + * on another one — which is fine, since favourites are matched to a box by address. + */ + val coverFile: String? = null, ) @Serializable @@ -71,6 +78,7 @@ class BackupRepositoryImpl @Inject constructor( val themeMode: String = ThemeMode.SYSTEM.name, val dynamicColor: Boolean = false, val sessionMode: String = SessionMode.APP_ONLY.name, + val favoritesLayout: String = FavoritesLayout.GRID.name, ) override suspend fun export(): String { @@ -96,6 +104,7 @@ class BackupRepositoryImpl @Inject constructor( album = favorite.album, trackUrl = favorite.trackUrl, sortIndex = favorite.sortIndex, + coverFile = favorite.coverFile, ) }, ) @@ -104,6 +113,7 @@ class BackupRepositoryImpl @Inject constructor( themeMode = current.themeMode.name, dynamicColor = current.dynamicColor, sessionMode = current.sessionMode.name, + favoritesLayout = current.favoritesLayout.name, ), ) return codec.encodeToString(file) @@ -156,6 +166,7 @@ class BackupRepositoryImpl @Inject constructor( album = favorite.album, trackUrl = favorite.trackUrl, sortIndex = favorite.sortIndex, + coverFile = favorite.coverFile, ).toEntity(), ) } @@ -169,6 +180,10 @@ class BackupRepositoryImpl @Inject constructor( SessionMode.entries.firstOrNull { it.name == file.settings.sessionMode } ?: SessionMode.APP_ONLY, ) + settings.setFavoritesLayout( + FavoritesLayout.entries.firstOrNull { it.name == file.settings.favoritesLayout } + ?: FavoritesLayout.GRID, + ) } private val codec = Json { @@ -181,6 +196,10 @@ class BackupRepositoryImpl @Inject constructor( * 2 added `trackUrl`. The bump is deliberate even though the field is optional: * an older build would import a `TRACK` row without its URL, which is a * favourite that cannot play. Refusing the file says so instead. + * + * `coverFile` and `favoritesLayout` arrived later and deliberately did *not* bump + * it: an older build that drops them loses a cover it can resolve again from the + * box and a layout preference, not the ability to play anything. */ const val FORMAT_VERSION = 2 } diff --git a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/FavoriteRepositoryImpl.kt b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/FavoriteRepositoryImpl.kt index 9029089..401a197 100644 --- a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/FavoriteRepositoryImpl.kt +++ b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/FavoriteRepositoryImpl.kt @@ -44,4 +44,6 @@ class FavoriteRepositoryImpl @Inject constructor( override suspend fun recordLaunch(id: Long) = dao.incrementLaunchCount(id) override suspend fun setPinned(id: Long, pinned: Boolean) = dao.setPinned(id, pinned) + + override suspend fun setCover(id: Long, coverFile: String) = dao.setCover(id, coverFile) } diff --git a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/LibraryRepositoryImpl.kt b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/LibraryRepositoryImpl.kt index 055fee4..36619c7 100644 --- a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/LibraryRepositoryImpl.kt +++ b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/LibraryRepositoryImpl.kt @@ -10,11 +10,13 @@ import app.coilforphoniebox.domain.model.LibraryAlbum import app.coilforphoniebox.domain.model.LibraryIndexResult import app.coilforphoniebox.domain.model.LibraryIndexState import app.coilforphoniebox.domain.model.LibrarySearchResults +import app.coilforphoniebox.domain.model.PlayTarget import app.coilforphoniebox.domain.model.PlaybackState import app.coilforphoniebox.domain.repository.LibraryRepository import app.coilforphoniebox.transport.Commands import app.coilforphoniebox.transport.ConnectionManager import app.coilforphoniebox.transport.LibraryParser +import app.coilforphoniebox.transport.PhonieboxCommand import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow @@ -93,28 +95,70 @@ class LibraryRepositoryImpl @Inject constructor( coverPermits.withPermit { // Another caller may have resolved it while this one waited for a permit. if (dao.findAlbum(boxId, albumArtist, album)?.coverFile != null) return + val coverFile = resolveCover(Commands.albumCoverArt(albumArtist, album)) ?: return + dao.setAlbumCover(boxId, albumArtist, album, coverFile) + } + } - // The box answers the first request with CACHE_PENDING and extracts the artwork - // on a worker thread, so asking once never yields a file name. - repeat(COVER_ATTEMPTS) { attempt -> - if (attempt > 0) delay(COVER_RETRY_MILLIS) + override suspend fun coverFileFor(boxId: String, target: PlayTarget): String? = when (target) { + is PlayTarget.Album -> + dao.findAlbum(boxId, target.albumArtist, target.album)?.coverFile + ?: coverPermits.withPermit { + resolveCover(Commands.albumCoverArt(target.albumArtist, target.album)) + // The album grid asks the same question, so answer it here too. A + // missing row makes this a no-op rather than an error. + ?.also { dao.setAlbumCover(boxId, target.albumArtist, target.album, it) } + } - val payload = transport.call(Commands.albumCoverArt(albumArtist, album)) - .getOrNull() ?: return + is PlayTarget.Track -> coverPermits.withPermit { resolveCover(Commands.singleCoverArt(target.url)) } - when (val art = LibraryParser.coverArt(payload)) { - is LibraryParser.CoverArt.Available -> { - dao.setAlbumCover(boxId, albumArtist, album, art.fileName) - return - } + is PlayTarget.Folder -> firstTrackUrlIn(boxId, target.path, descend = true) + ?.let { url -> coverPermits.withPermit { resolveCover(Commands.singleCoverArt(url)) } } + } + + /** + * URL of the track whose artwork stands in for a folder's. + * + * There is no folder cover in the protocol, so a track inside it has to do. The cache + * answers for a level that has been browsed; one that has not costs a + * `get_folder_content`. A folder holding nothing but subfolders — an artist above its + * albums, which is a common layout — is followed one level down and no further, because + * each level is another call on the socket the box shares with its card reader (§6). + */ + private suspend fun firstTrackUrlIn(boxId: String, path: String, descend: Boolean): String? { + if (dao.findFolder(boxId, path)?.contentCachedAt == null) { + refreshFolder(boxId, path).getOrElse { return null } + } + dao.firstTrackIn(boxId, path)?.let { return it.url } + if (!descend) return null + val child = dao.firstFolderIn(boxId, path) ?: return null + return firstTrackUrlIn(boxId, child.path, descend = false) + } + + /** + * Asks the box for one cover and waits out its extraction. + * + * The first request for a song or album the box has not cached yet answers + * `CACHE_PENDING` and queues the work on a worker thread, so asking once never yields a + * file name. Null means there is no artwork — or that it did not arrive in the time this + * is prepared to wait, which the caller must not record as "none". + */ + private suspend fun resolveCover(command: PhonieboxCommand): String? { + repeat(COVER_ATTEMPTS) { attempt -> + if (attempt > 0) delay(COVER_RETRY_MILLIS) - // Nothing to show, and nothing to gain from asking again. - LibraryParser.CoverArt.Missing -> return + val payload = transport.call(command).getOrNull() ?: return null - LibraryParser.CoverArt.Pending -> Unit - } + when (val art = LibraryParser.coverArt(payload)) { + is LibraryParser.CoverArt.Available -> return art.fileName + + // Nothing to show, and nothing to gain from asking again. + LibraryParser.CoverArt.Missing -> return null + + LibraryParser.CoverArt.Pending -> Unit } } + return null } override suspend fun rescanBoxLibrary(boxId: String): Result = diff --git a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/PlayerRepositoryImpl.kt b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/PlayerRepositoryImpl.kt index 46189a5..da0af20 100644 --- a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/PlayerRepositoryImpl.kt +++ b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/PlayerRepositoryImpl.kt @@ -57,6 +57,15 @@ class PlayerRepositoryImpl @Inject constructor( private val _coverUrl = MutableStateFlow(null) + /** + * The same cover as [_coverUrl], as the bare file name. + * + * Kept beside the URL rather than derived from it: a favourite stores the file name, and + * picking it back out of a URL would make [Box.coverUrl] a format two places have to + * agree on. + */ + private val _coverFile = MutableStateFlow(null) + /** * Deliberately a [StateFlow] with a value from the start, resolved in the background, * rather than a flow that maps the current song to an RPC. @@ -70,6 +79,8 @@ class PlayerRepositoryImpl @Inject constructor( */ override val coverUrl: StateFlow = _coverUrl.asStateFlow() + override fun currentCoverFile(): String? = _coverFile.value + init { scope.launch { resolveCoversForCurrentSong() } } @@ -86,11 +97,14 @@ class PlayerRepositoryImpl @Inject constructor( val key = cacheKey(file, box) if (key != lastKey) { // Showing the previous song's artwork would be worse than showing none. + _coverFile.value = null _coverUrl.value = null lastKey = key } if (file != null && box != null) { - _coverUrl.value = resolveCover(file, box) + val coverFile = resolveCoverFile(file, box) + _coverFile.value = coverFile + _coverUrl.value = coverFile?.let { box.coverUrl(it) } } } } @@ -100,10 +114,10 @@ class PlayerRepositoryImpl @Inject constructor( * artwork on a worker thread, so a single request never returns a usable name. This * asks again a few times before giving up. */ - private suspend fun resolveCover(file: String, box: Box): String? { + private suspend fun resolveCoverFile(file: String, box: Box): String? { val key = "${box.id}|$file" if (key in songsWithoutArt) return null - resolvedCovers[key]?.let { return box.coverUrl(it) } + resolvedCovers[key]?.let { return it } repeat(COVER_ATTEMPTS) { attempt -> if (attempt > 0) delay(COVER_RETRY_MILLIS) @@ -112,7 +126,7 @@ class PlayerRepositoryImpl @Inject constructor( when (val art = LibraryParser.coverArt(payload)) { is LibraryParser.CoverArt.Available -> { resolvedCovers[key] = art.fileName - return box.coverUrl(art.fileName) + return art.fileName } LibraryParser.CoverArt.Missing -> { diff --git a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/SettingsRepositoryImpl.kt b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/SettingsRepositoryImpl.kt index 037f5e2..820e05a 100644 --- a/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/SettingsRepositoryImpl.kt +++ b/core-data/src/main/kotlin/app/coilforphoniebox/data/repository/SettingsRepositoryImpl.kt @@ -2,6 +2,7 @@ package app.coilforphoniebox.data.repository import app.coilforphoniebox.data.settings.SettingsStore import app.coilforphoniebox.domain.model.AppSettings +import app.coilforphoniebox.domain.model.FavoritesLayout import app.coilforphoniebox.domain.model.SessionMode import app.coilforphoniebox.domain.model.ThemeMode import app.coilforphoniebox.domain.repository.SettingsRepository @@ -24,6 +25,9 @@ class SettingsRepositoryImpl @Inject constructor( override suspend fun setSessionMode(mode: SessionMode) = store.setSessionMode(mode) + override suspend fun setFavoritesLayout(layout: FavoritesLayout) = + store.setFavoritesLayout(layout) + override suspend fun setOnboardingComplete(complete: Boolean) = store.setOnboardingComplete(complete) } diff --git a/core-data/src/main/kotlin/app/coilforphoniebox/data/settings/SettingsStore.kt b/core-data/src/main/kotlin/app/coilforphoniebox/data/settings/SettingsStore.kt index e008efb..e65ab63 100644 --- a/core-data/src/main/kotlin/app/coilforphoniebox/data/settings/SettingsStore.kt +++ b/core-data/src/main/kotlin/app/coilforphoniebox/data/settings/SettingsStore.kt @@ -6,6 +6,7 @@ import androidx.datastore.preferences.core.booleanPreferencesKey import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.stringPreferencesKey import app.coilforphoniebox.domain.model.AppSettings +import app.coilforphoniebox.domain.model.FavoritesLayout import app.coilforphoniebox.domain.model.SessionMode import app.coilforphoniebox.domain.model.ThemeMode import kotlinx.coroutines.flow.Flow @@ -27,6 +28,7 @@ class SettingsStore @Inject constructor( themeMode = prefs[THEME_MODE].toThemeMode(), dynamicColor = prefs[DYNAMIC_COLOR] ?: false, sessionMode = prefs[SESSION_MODE].toSessionMode(), + favoritesLayout = prefs[FAVORITES_LAYOUT].toFavoritesLayout(), activeBoxId = prefs[ACTIVE_BOX_ID], onboardingComplete = prefs[ONBOARDING_COMPLETE] ?: false, ) @@ -40,6 +42,8 @@ class SettingsStore @Inject constructor( suspend fun setSessionMode(mode: SessionMode) = put(SESSION_MODE, mode.name) + suspend fun setFavoritesLayout(layout: FavoritesLayout) = put(FAVORITES_LAYOUT, layout.name) + suspend fun setActiveBoxId(boxId: String?) { dataStore.edit { prefs -> if (boxId == null) prefs.remove(ACTIVE_BOX_ID) else prefs[ACTIVE_BOX_ID] = boxId @@ -59,10 +63,14 @@ class SettingsStore @Inject constructor( private fun String?.toSessionMode(): SessionMode = this?.let { name -> SessionMode.entries.firstOrNull { it.name == name } } ?: SessionMode.APP_ONLY + private fun String?.toFavoritesLayout(): FavoritesLayout = + this?.let { name -> FavoritesLayout.entries.firstOrNull { it.name == name } } ?: FavoritesLayout.GRID + private companion object { val THEME_MODE = stringPreferencesKey("theme_mode") val DYNAMIC_COLOR = booleanPreferencesKey("dynamic_color") val SESSION_MODE = stringPreferencesKey("session_mode") + val FAVORITES_LAYOUT = stringPreferencesKey("favorites_layout") val ACTIVE_BOX_ID = stringPreferencesKey("active_box_id") val ONBOARDING_COMPLETE = booleanPreferencesKey("onboarding_complete") } diff --git a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/model/AppSettings.kt b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/model/AppSettings.kt index 827c2ff..6b0143b 100644 --- a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/model/AppSettings.kt +++ b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/model/AppSettings.kt @@ -13,12 +13,22 @@ enum class ThemeMode { SYSTEM, LIGHT, DARK } */ enum class SessionMode { OFF, APP_ONLY, AUTOMATIC } +/** + * How the favourites tab lays its entries out. + * + * [GRID] is the default and what favourites are for — a wall of covers a child can aim at + * without reading. [LIST] trades that reach for density: one row each, so a collection that + * has outgrown a screenful of tiles can be scanned by name instead of scrolled through. + */ +enum class FavoritesLayout { GRID, LIST } + /** Global settings. Everything box-specific lives on [Box] instead (§7.2). */ data class AppSettings( val themeMode: ThemeMode = ThemeMode.SYSTEM, /** Material You would displace the brand colour, so it is off by default (§10.9). */ val dynamicColor: Boolean = false, val sessionMode: SessionMode = SessionMode.APP_ONLY, + val favoritesLayout: FavoritesLayout = FavoritesLayout.GRID, val activeBoxId: String? = null, val onboardingComplete: Boolean = false, ) diff --git a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/FavoriteRepository.kt b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/FavoriteRepository.kt index 1c3fe03..bf0deac 100644 --- a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/FavoriteRepository.kt +++ b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/FavoriteRepository.kt @@ -25,5 +25,13 @@ interface FavoriteRepository { suspend fun recordLaunch(id: Long) + /** + * Records the cover art file name for a favourite that was saved without one. + * + * A favourite is the one thing here that cannot be rebuilt from the box, so its cover + * is stored beside it rather than being looked up again every time the tab opens. + */ + suspend fun setCover(id: Long, coverFile: String) + suspend fun setPinned(id: Long, pinned: Boolean) } diff --git a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/LibraryRepository.kt b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/LibraryRepository.kt index 7db3476..368bcf6 100644 --- a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/LibraryRepository.kt +++ b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/LibraryRepository.kt @@ -5,6 +5,7 @@ import app.coilforphoniebox.domain.model.LibraryAlbum import app.coilforphoniebox.domain.model.LibraryIndexResult import app.coilforphoniebox.domain.model.LibraryIndexState import app.coilforphoniebox.domain.model.LibrarySearchResults +import app.coilforphoniebox.domain.model.PlayTarget import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow @@ -34,6 +35,17 @@ interface LibraryRepository { */ suspend fun ensureAlbumCover(boxId: String, albumArtist: String, album: String) + /** + * Cover file name for [target], from the cache if it is there and from the box if not. + * Null when the box has no artwork for it, or when it could not be asked. + * + * Only a folder needs more than one call: nothing in the protocol returns a folder's + * cover, so its first track stands in for it — taken from the cache when that level has + * been browsed, and fetched with `get_folder_content` when it has not. Costly enough + * that only an explicit, on-screen need should ask (§6). + */ + suspend fun coverFileFor(boxId: String, target: PlayTarget): String? + /** Fires `player.ctrl.update` so the box rescans its own MPD database. */ suspend fun rescanBoxLibrary(boxId: String): Result diff --git a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/PlayerRepository.kt b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/PlayerRepository.kt index 041ae71..d73ea3c 100644 --- a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/PlayerRepository.kt +++ b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/PlayerRepository.kt @@ -28,6 +28,16 @@ interface PlayerRepository { /** Absolute HTTP URL of the current song's cover, or null when there is none. */ val coverUrl: Flow + /** + * Cover file name of the playing song, if one has already been resolved. + * + * The same name [coverUrl] is built from, handed over unwrapped so that saving a + * favourite can store it. Read once at the moment of the tap rather than exposed as a + * flow: nothing on screen shows this, and a favourite records the cover it was saved + * with, not whatever is playing later. + */ + fun currentCoverFile(): String? + /** * The box's stop-player timer. Its shutdown timers are deliberately not represented * here at all — Coil never sends a command that switches the box off (§16). diff --git a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/SettingsRepository.kt b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/SettingsRepository.kt index 9461b67..8ca8dff 100644 --- a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/SettingsRepository.kt +++ b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/repository/SettingsRepository.kt @@ -1,6 +1,7 @@ package app.coilforphoniebox.domain.repository import app.coilforphoniebox.domain.model.AppSettings +import app.coilforphoniebox.domain.model.FavoritesLayout import app.coilforphoniebox.domain.model.SessionMode import app.coilforphoniebox.domain.model.ThemeMode import kotlinx.coroutines.flow.Flow @@ -16,5 +17,7 @@ interface SettingsRepository { suspend fun setSessionMode(mode: SessionMode) + suspend fun setFavoritesLayout(layout: FavoritesLayout) + suspend fun setOnboardingComplete(complete: Boolean) } diff --git a/core-domain/src/main/kotlin/app/coilforphoniebox/domain/usecase/ResolveFavoriteCoverUseCase.kt b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/usecase/ResolveFavoriteCoverUseCase.kt new file mode 100644 index 0000000..e86617c --- /dev/null +++ b/core-domain/src/main/kotlin/app/coilforphoniebox/domain/usecase/ResolveFavoriteCoverUseCase.kt @@ -0,0 +1,32 @@ +package app.coilforphoniebox.domain.usecase + +import app.coilforphoniebox.domain.model.Favorite +import app.coilforphoniebox.domain.repository.FavoriteRepository +import app.coilforphoniebox.domain.repository.LibraryRepository +import javax.inject.Inject + +/** + * Fills in the cover art a favourite was saved without, and stores it. + * + * Favourites are saved from wherever the user happens to be, and most of those places do + * not know a cover: the player's star knows the playing song's, an album row knows its + * own, and a folder or track row in the library knows none at all. Without a backfill the + * favourites tab is a wall of placeholder icons — which is what it was. + * + * Deliberately one favourite at a time and driven by what is on screen, never by a sweep + * over the table: every resolution is at least one RPC on the socket the box shares with + * its card reader (§6). The file name is persisted, so a favourite costs this once ever and + * its cover then renders from the image loader's disk cache with the box switched off. + */ +class ResolveFavoriteCoverUseCase @Inject constructor( + private val favorites: FavoriteRepository, + private val library: LibraryRepository, +) { + /** No-op for a favourite that already has a cover, or has no target to resolve one from. */ + suspend operator fun invoke(favorite: Favorite) { + if (favorite.coverFile != null) return + val target = favorite.toPlayTarget() ?: return + val coverFile = library.coverFileFor(favorite.boxId, target) ?: return + favorites.setCover(favorite.id, coverFile) + } +} diff --git a/docs/pages/assets/screenshots/01_player.png b/docs/pages/assets/screenshots/01_player.png index 8d7a56a..f91dc66 100644 Binary files a/docs/pages/assets/screenshots/01_player.png and b/docs/pages/assets/screenshots/01_player.png differ diff --git a/docs/pages/assets/screenshots/02_library.png b/docs/pages/assets/screenshots/02_library.png index 9dedeb3..9e7cd84 100644 Binary files a/docs/pages/assets/screenshots/02_library.png and b/docs/pages/assets/screenshots/02_library.png differ diff --git a/docs/pages/assets/screenshots/03_favourites.png b/docs/pages/assets/screenshots/03_favourites.png index 10bca17..8c8bd6e 100644 Binary files a/docs/pages/assets/screenshots/03_favourites.png and b/docs/pages/assets/screenshots/03_favourites.png differ diff --git a/docs/pages/assets/screenshots/04_search.png b/docs/pages/assets/screenshots/04_search.png index 256c5bf..c9a389a 100644 Binary files a/docs/pages/assets/screenshots/04_search.png and b/docs/pages/assets/screenshots/04_search.png differ diff --git a/docs/pages/assets/screenshots/05_sleep_timer.png b/docs/pages/assets/screenshots/05_sleep_timer.png index 3c3cd65..a6b28e2 100644 Binary files a/docs/pages/assets/screenshots/05_sleep_timer.png and b/docs/pages/assets/screenshots/05_sleep_timer.png differ diff --git a/docs/pages/assets/screenshots/tablet10/01_player.png b/docs/pages/assets/screenshots/tablet10/01_player.png index 6e1ec9a..ddcbd9a 100644 Binary files a/docs/pages/assets/screenshots/tablet10/01_player.png and b/docs/pages/assets/screenshots/tablet10/01_player.png differ diff --git a/docs/pages/assets/screenshots/tablet10/02_library.png b/docs/pages/assets/screenshots/tablet10/02_library.png index 586adea..7674a78 100644 Binary files a/docs/pages/assets/screenshots/tablet10/02_library.png and b/docs/pages/assets/screenshots/tablet10/02_library.png differ diff --git a/docs/pages/assets/screenshots/tablet10/03_favourites.png b/docs/pages/assets/screenshots/tablet10/03_favourites.png index ac428ea..1b86998 100644 Binary files a/docs/pages/assets/screenshots/tablet10/03_favourites.png and b/docs/pages/assets/screenshots/tablet10/03_favourites.png differ diff --git a/docs/pages/assets/screenshots/tablet10/04_search.png b/docs/pages/assets/screenshots/tablet10/04_search.png index a58d95a..ee831e9 100644 Binary files a/docs/pages/assets/screenshots/tablet10/04_search.png and b/docs/pages/assets/screenshots/tablet10/04_search.png differ diff --git a/docs/pages/assets/screenshots/tablet10/05_sleep_timer.png b/docs/pages/assets/screenshots/tablet10/05_sleep_timer.png index 3886cb4..a93ea0a 100644 Binary files a/docs/pages/assets/screenshots/tablet10/05_sleep_timer.png and b/docs/pages/assets/screenshots/tablet10/05_sleep_timer.png differ diff --git a/docs/pages/assets/screenshots/tablet7/01_player.png b/docs/pages/assets/screenshots/tablet7/01_player.png index a40cf10..c2b85a1 100644 Binary files a/docs/pages/assets/screenshots/tablet7/01_player.png and b/docs/pages/assets/screenshots/tablet7/01_player.png differ diff --git a/docs/pages/assets/screenshots/tablet7/02_library.png b/docs/pages/assets/screenshots/tablet7/02_library.png index 302a4b4..ae18525 100644 Binary files a/docs/pages/assets/screenshots/tablet7/02_library.png and b/docs/pages/assets/screenshots/tablet7/02_library.png differ diff --git a/docs/pages/assets/screenshots/tablet7/03_favourites.png b/docs/pages/assets/screenshots/tablet7/03_favourites.png index 1ae51c4..7352df9 100644 Binary files a/docs/pages/assets/screenshots/tablet7/03_favourites.png and b/docs/pages/assets/screenshots/tablet7/03_favourites.png differ diff --git a/docs/pages/assets/screenshots/tablet7/04_search.png b/docs/pages/assets/screenshots/tablet7/04_search.png index 5d05520..5104d30 100644 Binary files a/docs/pages/assets/screenshots/tablet7/04_search.png and b/docs/pages/assets/screenshots/tablet7/04_search.png differ diff --git a/docs/pages/assets/screenshots/tablet7/05_sleep_timer.png b/docs/pages/assets/screenshots/tablet7/05_sleep_timer.png index b161f97..dfc318d 100644 Binary files a/docs/pages/assets/screenshots/tablet7/05_sleep_timer.png and b/docs/pages/assets/screenshots/tablet7/05_sleep_timer.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/01_player.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/01_player.png index 8d7a56a..f91dc66 100644 Binary files a/fastlane/metadata/android/en-US/images/phoneScreenshots/01_player.png and b/fastlane/metadata/android/en-US/images/phoneScreenshots/01_player.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/02_library.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/02_library.png index 9dedeb3..9e7cd84 100644 Binary files a/fastlane/metadata/android/en-US/images/phoneScreenshots/02_library.png and b/fastlane/metadata/android/en-US/images/phoneScreenshots/02_library.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/03_favourites.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/03_favourites.png index 10bca17..8c8bd6e 100644 Binary files a/fastlane/metadata/android/en-US/images/phoneScreenshots/03_favourites.png and b/fastlane/metadata/android/en-US/images/phoneScreenshots/03_favourites.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/04_search.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/04_search.png index 256c5bf..c9a389a 100644 Binary files a/fastlane/metadata/android/en-US/images/phoneScreenshots/04_search.png and b/fastlane/metadata/android/en-US/images/phoneScreenshots/04_search.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/05_sleep_timer.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/05_sleep_timer.png index 3c3cd65..a6b28e2 100644 Binary files a/fastlane/metadata/android/en-US/images/phoneScreenshots/05_sleep_timer.png and b/fastlane/metadata/android/en-US/images/phoneScreenshots/05_sleep_timer.png differ diff --git a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/01_player.png b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/01_player.png index a40cf10..c2b85a1 100644 Binary files a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/01_player.png and b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/01_player.png differ diff --git a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/02_library.png b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/02_library.png index 302a4b4..ae18525 100644 Binary files a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/02_library.png and b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/02_library.png differ diff --git a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/03_favourites.png b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/03_favourites.png index 1ae51c4..7352df9 100644 Binary files a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/03_favourites.png and b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/03_favourites.png differ diff --git a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/04_search.png b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/04_search.png index 5d05520..5104d30 100644 Binary files a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/04_search.png and b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/04_search.png differ diff --git a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/05_sleep_timer.png b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/05_sleep_timer.png index b161f97..dfc318d 100644 Binary files a/fastlane/metadata/android/en-US/images/sevenInchScreenshots/05_sleep_timer.png and b/fastlane/metadata/android/en-US/images/sevenInchScreenshots/05_sleep_timer.png differ diff --git a/fastlane/metadata/android/en-US/images/tenInchScreenshots/01_player.png b/fastlane/metadata/android/en-US/images/tenInchScreenshots/01_player.png index 6e1ec9a..ddcbd9a 100644 Binary files a/fastlane/metadata/android/en-US/images/tenInchScreenshots/01_player.png and b/fastlane/metadata/android/en-US/images/tenInchScreenshots/01_player.png differ diff --git a/fastlane/metadata/android/en-US/images/tenInchScreenshots/02_library.png b/fastlane/metadata/android/en-US/images/tenInchScreenshots/02_library.png index 586adea..7674a78 100644 Binary files a/fastlane/metadata/android/en-US/images/tenInchScreenshots/02_library.png and b/fastlane/metadata/android/en-US/images/tenInchScreenshots/02_library.png differ diff --git a/fastlane/metadata/android/en-US/images/tenInchScreenshots/03_favourites.png b/fastlane/metadata/android/en-US/images/tenInchScreenshots/03_favourites.png index ac428ea..1b86998 100644 Binary files a/fastlane/metadata/android/en-US/images/tenInchScreenshots/03_favourites.png and b/fastlane/metadata/android/en-US/images/tenInchScreenshots/03_favourites.png differ diff --git a/fastlane/metadata/android/en-US/images/tenInchScreenshots/04_search.png b/fastlane/metadata/android/en-US/images/tenInchScreenshots/04_search.png index a58d95a..ee831e9 100644 Binary files a/fastlane/metadata/android/en-US/images/tenInchScreenshots/04_search.png and b/fastlane/metadata/android/en-US/images/tenInchScreenshots/04_search.png differ diff --git a/fastlane/metadata/android/en-US/images/tenInchScreenshots/05_sleep_timer.png b/fastlane/metadata/android/en-US/images/tenInchScreenshots/05_sleep_timer.png index 3886cb4..a93ea0a 100644 Binary files a/fastlane/metadata/android/en-US/images/tenInchScreenshots/05_sleep_timer.png and b/fastlane/metadata/android/en-US/images/tenInchScreenshots/05_sleep_timer.png differ