The first public release of Fabled Minstrel #158
+15
-1
@@ -67,6 +67,9 @@ import com.fabledsword.minstrel.cache.db.entities.SyncMetadataEntity
|
||||
CachedNotificationEntity::class,
|
||||
CachedNotificationSettingsEntity::class,
|
||||
],
|
||||
// v13: + cached_playlists.coverAlbumIds and createdAt, the albums Home's
|
||||
// shelves draw each playlist tile's picture from and when a mix was
|
||||
// rebuilt. MIGRATION_12_13 adds both empty; the next list refresh fills them.
|
||||
// v12: + auth_session.backgroundDelivery and notifiedUpTo, the device's
|
||||
// background-delivery choice and its shade high-water mark.
|
||||
// v11: + cached_notifications and cached_notification_settings, the
|
||||
@@ -87,7 +90,7 @@ import com.fabledsword.minstrel.cache.db.entities.SyncMetadataEntity
|
||||
// on auth_session. Versions before v8 rebuild destructively, which is
|
||||
// right for them: the next sync refills every row with the new
|
||||
// columns populated, so there is nothing to migrate by hand.
|
||||
version = 12,
|
||||
version = 13,
|
||||
exportSchema = true,
|
||||
)
|
||||
@TypeConverters(MinstrelTypeConverters::class)
|
||||
@@ -162,3 +165,14 @@ val MIGRATION_11_12: Migration = object : Migration(11, 12) {
|
||||
db.execSQL("ALTER TABLE auth_session ADD COLUMN notifiedUpTo INTEGER")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* v12 → v13: a playlist's cover albums and creation time. Both start empty;
|
||||
* Home refreshes the playlist list on open, which fills them.
|
||||
*/
|
||||
val MIGRATION_12_13: Migration = object : Migration(12, 13) {
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE cached_playlists ADD COLUMN coverAlbumIds TEXT NOT NULL DEFAULT ''")
|
||||
db.execSQL("ALTER TABLE cached_playlists ADD COLUMN createdAt TEXT NOT NULL DEFAULT ''")
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ object DatabaseModule {
|
||||
// and rebuilds. The sync controller refills the cache from the
|
||||
// server on first launch, so a rebuild loses only the unsynced
|
||||
// mutation queue.
|
||||
.addMigrations(MIGRATION_8_9, MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12)
|
||||
.addMigrations(MIGRATION_8_9, MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13)
|
||||
.fallbackToDestructiveMigration(dropAllTables = true)
|
||||
.build()
|
||||
|
||||
|
||||
Vendored
+10
@@ -1,5 +1,6 @@
|
||||
package com.fabledsword.minstrel.cache.db.entities
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import kotlinx.datetime.Clock
|
||||
@@ -25,4 +26,13 @@ data class CachedPlaylistEntity(
|
||||
val durationSec: Int = 0,
|
||||
val systemVariant: String? = null,
|
||||
val fetchedAt: Instant = Clock.System.now(),
|
||||
/**
|
||||
* The playlist's cover albums, comma-joined (album ids are UUIDs and
|
||||
* carry no commas). Empty until the list is next refreshed.
|
||||
*/
|
||||
@ColumnInfo(defaultValue = "''")
|
||||
val coverAlbumIds: String = "",
|
||||
/** ISO-8601 creation time; for a system mix, when it was last rebuilt. */
|
||||
@ColumnInfo(defaultValue = "''")
|
||||
val createdAt: String = "",
|
||||
)
|
||||
|
||||
@@ -80,11 +80,16 @@ import com.fabledsword.minstrel.nav.AlbumDetail
|
||||
import com.fabledsword.minstrel.nav.ArtistDetail
|
||||
import com.fabledsword.minstrel.nav.Home
|
||||
import com.fabledsword.minstrel.nav.PlaylistDetail
|
||||
import com.fabledsword.minstrel.playlists.assignShelfCovers
|
||||
import com.fabledsword.minstrel.playlists.data.PlaylistsRepository
|
||||
import com.fabledsword.minstrel.playlists.data.playPlaylistShuffled
|
||||
import com.fabledsword.minstrel.playlists.shelfMeta
|
||||
import com.fabledsword.minstrel.playlists.widgets.OfflinePoolCard
|
||||
import com.fabledsword.minstrel.playlists.widgets.PlaylistCard
|
||||
import com.fabledsword.minstrel.playlists.widgets.GenreBandCard
|
||||
import com.fabledsword.minstrel.playlists.widgets.PlaceholderShape
|
||||
import com.fabledsword.minstrel.playlists.widgets.PlaylistPlaceholderCard
|
||||
import com.fabledsword.minstrel.playlists.widgets.SongsLikeCard
|
||||
import com.fabledsword.minstrel.playlists.widgets.WidePlaylistCard
|
||||
import com.fabledsword.minstrel.shared.UiState
|
||||
import com.fabledsword.minstrel.shared.UpdateVeilController
|
||||
import com.fabledsword.minstrel.shared.VeilOutcome
|
||||
@@ -763,6 +768,7 @@ private fun HomeSuccessContent(
|
||||
// pool cards lead the row. Songs-like has its own row below.
|
||||
PlaylistsRow(
|
||||
title = "Playlists",
|
||||
shape = ShelfShape.WIDE,
|
||||
rowItems = buildPlaylistsRow(sections.playlists, systemStatus, offline),
|
||||
offline = offline,
|
||||
onPlaylistClick = onPlaylistClick,
|
||||
@@ -831,6 +837,7 @@ private fun LazyListScope.songsLikeSection(
|
||||
item {
|
||||
PlaylistsRow(
|
||||
title = "Songs like…",
|
||||
shape = ShelfShape.ROUND,
|
||||
rowItems = rowItems,
|
||||
offline = offline,
|
||||
onPlaylistClick = onPlaylistClick,
|
||||
@@ -856,6 +863,7 @@ private fun LazyListScope.genreMixSection(
|
||||
item {
|
||||
PlaylistsRow(
|
||||
title = "Your genres",
|
||||
shape = ShelfShape.BAND,
|
||||
rowItems = rowItems,
|
||||
offline = offline,
|
||||
onPlaylistClick = onPlaylistClick,
|
||||
@@ -1132,16 +1140,27 @@ private fun AlbumsRow(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A shelf of playlist tiles in one [shape]. Each tile gets cover albums no
|
||||
* tile before it already shows (assignShelfCovers), and the size and refresh
|
||||
* time the shelf's mixes share go beside the title once (shelfMeta).
|
||||
*/
|
||||
@Composable
|
||||
private fun PlaylistsRow(
|
||||
title: String,
|
||||
shape: ShelfShape,
|
||||
rowItems: List<PlaylistRowItem>,
|
||||
offline: Boolean,
|
||||
onPlaylistClick: (String) -> Unit,
|
||||
onPlayPool: (OfflinePoolKind) -> Unit,
|
||||
onPlayPlaylist: suspend (PlaylistRef) -> Unit,
|
||||
) {
|
||||
HorizontalScrollRow(title = title) {
|
||||
val reals = rowItems.filterIsInstance<PlaylistRowItem.Real>().map { it.playlist }
|
||||
val covers = remember(reals, shape) {
|
||||
reals.map { it.id }.zip(assignShelfCovers(reals, shape.coversPerTile)).toMap()
|
||||
}
|
||||
val meta = remember(reals) { shelfMeta(reals) }
|
||||
HorizontalScrollRow(title = title, meta = meta) {
|
||||
itemsIndexed(items = rowItems) { _, item ->
|
||||
when (item) {
|
||||
is PlaylistRowItem.OfflinePool -> OfflinePoolCard(
|
||||
@@ -1149,28 +1168,58 @@ private fun PlaylistsRow(
|
||||
icon = iconForPool(item.kind),
|
||||
onClick = { onPlayPool(item.kind) },
|
||||
)
|
||||
is PlaylistRowItem.Real -> {
|
||||
is PlaylistRowItem.Real -> ShelfTile(
|
||||
shape = shape,
|
||||
playlist = item.playlist,
|
||||
covers = covers[item.playlist.id].orEmpty(),
|
||||
// Greyed offline when the tile needs the live server or
|
||||
// isn't fully cached — dimmed but still tappable into the
|
||||
// detail to shuffle whatever subset is cached.
|
||||
val greyed = offline && item.playlist.unavailableOffline
|
||||
PlaylistCard(
|
||||
playlist = item.playlist,
|
||||
onClick = { onPlaylistClick(item.playlist.id) },
|
||||
onPlay = { onPlayPlaylist(item.playlist) },
|
||||
playEnabled = item.playlist.trackCount > 0 && !greyed,
|
||||
greyed = greyed,
|
||||
)
|
||||
}
|
||||
greyed = offline && item.playlist.unavailableOffline,
|
||||
onClick = { onPlaylistClick(item.playlist.id) },
|
||||
onPlay = { onPlayPlaylist(item.playlist) },
|
||||
)
|
||||
is PlaylistRowItem.Placeholder -> PlaylistPlaceholderCard(
|
||||
label = item.label,
|
||||
variant = item.variant,
|
||||
shape = shape.placeholder,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** One playlist tile in its shelf's shape. */
|
||||
@Composable
|
||||
private fun ShelfTile(
|
||||
shape: ShelfShape,
|
||||
playlist: PlaylistRef,
|
||||
covers: List<String>,
|
||||
greyed: Boolean,
|
||||
onClick: () -> Unit,
|
||||
onPlay: suspend () -> Unit,
|
||||
) {
|
||||
val playEnabled = playlist.trackCount > 0
|
||||
when (shape) {
|
||||
ShelfShape.WIDE -> WidePlaylistCard(playlist, covers, onClick, onPlay, playEnabled, greyed)
|
||||
ShelfShape.ROUND -> SongsLikeCard(playlist, covers, onClick, onPlay, playEnabled, greyed)
|
||||
ShelfShape.BAND -> GenreBandCard(playlist, covers, onClick, onPlay, playEnabled, greyed)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The tile shape a Home playlist shelf uses, so shelves read apart at a
|
||||
* glance: wide cards for the main mixes and playlists, circles for Songs
|
||||
* like (the shape artists have everywhere), colour bands with a fan of
|
||||
* covers for genres. [coversPerTile] is how many distinct covers a tile
|
||||
* shows; [placeholder] is the shape a not-yet-built mix takes on the shelf.
|
||||
*/
|
||||
internal enum class ShelfShape(val coversPerTile: Int, val placeholder: PlaceholderShape) {
|
||||
WIDE(coversPerTile = 1, placeholder = PlaceholderShape.WIDE),
|
||||
ROUND(coversPerTile = 1, placeholder = PlaceholderShape.ROUND),
|
||||
BAND(coversPerTile = 3, placeholder = PlaceholderShape.SQUARE),
|
||||
}
|
||||
|
||||
private fun iconForPool(kind: OfflinePoolKind) = when (kind) {
|
||||
OfflinePoolKind.RECENTLY_PLAYED -> Lucide.History
|
||||
OfflinePoolKind.LIKED -> Lucide.Heart
|
||||
|
||||
@@ -21,6 +21,13 @@ data class PlaylistRef(
|
||||
val ownerUsername: String = "",
|
||||
/** All member tracks resident in the audio cache — playable fully offline. */
|
||||
val fullyCached: Boolean = false,
|
||||
/**
|
||||
* Albums whose covers can stand for this playlist, in playlist order. Home
|
||||
* gives each tile one the tiles before it do not already show.
|
||||
*/
|
||||
val coverAlbumIds: List<String> = emptyList(),
|
||||
/** ISO-8601. A system mix is rebuilt in place, so this is when it was last refreshed. */
|
||||
val createdAt: String = "",
|
||||
) {
|
||||
val isSystem: Boolean get() = systemVariant != null
|
||||
|
||||
|
||||
@@ -23,6 +23,11 @@ data class PlaylistWire(
|
||||
@SerialName("owner_username") val ownerUsername: String = "",
|
||||
@SerialName("created_at") val createdAt: String = "",
|
||||
@SerialName("updated_at") val updatedAt: String = "",
|
||||
/**
|
||||
* Up to six distinct albums with art, in the order they first appear in
|
||||
* the playlist. Home's shelves pick each tile's picture from these.
|
||||
*/
|
||||
@SerialName("cover_album_ids") val coverAlbumIds: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -79,5 +84,7 @@ data class PlaylistDetailWire(
|
||||
@SerialName("track_count") val trackCount: Int = 0,
|
||||
@SerialName("cover_url") val coverUrl: String = "",
|
||||
@SerialName("owner_username") val ownerUsername: String = "",
|
||||
@SerialName("created_at") val createdAt: String = "",
|
||||
@SerialName("cover_album_ids") val coverAlbumIds: List<String> = emptyList(),
|
||||
val tracks: List<PlaylistTrackWire> = emptyList(),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.fabledsword.minstrel.playlists
|
||||
|
||||
import com.fabledsword.minstrel.models.PlaylistRef
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.util.Locale
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
// What a Home shelf of playlist tiles shows: which album covers each tile
|
||||
// gets, the one line of facts the shelf's tiles share, and the colour a
|
||||
// wide card or genre band is washed in. Mirrors the web client's
|
||||
// lib/playlists/shelf.ts so both Homes read the same.
|
||||
|
||||
/**
|
||||
* Each tile takes the first of its playlist's cover albums that no tile
|
||||
* before it on the shelf already shows, so a shelf never repeats a cover
|
||||
* while a tile still has an unused one. A tile whose albums are all taken
|
||||
* reuses its own first albums rather than showing nothing. [perTile] is
|
||||
* how many covers a tile shows (one for a card, three for a genre band).
|
||||
*/
|
||||
fun assignShelfCovers(playlists: List<PlaylistRef>, perTile: Int): List<List<String>> {
|
||||
val used = mutableSetOf<String>()
|
||||
return playlists.map { p ->
|
||||
val fresh = p.coverAlbumIds.filter { it !in used }.take(perTile)
|
||||
val picked = fresh.ifEmpty { p.coverAlbumIds.take(perTile) }
|
||||
used += picked
|
||||
picked
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* System playlists are rebuilt in place, so created_at is when the mix was
|
||||
* last refreshed. Worded for a person ("Refreshed today"), not as "3h ago".
|
||||
* Empty when [iso] does not parse.
|
||||
*/
|
||||
fun refreshedLabel(
|
||||
iso: String,
|
||||
now: Instant = Instant.now(),
|
||||
zone: ZoneId = ZoneId.systemDefault(),
|
||||
): String {
|
||||
val t = runCatching { Instant.parse(iso) }.getOrNull() ?: return ""
|
||||
val days = ChronoUnit.DAYS.between(t.atZone(zone).toLocalDate(), now.atZone(zone).toLocalDate())
|
||||
return when {
|
||||
ChronoUnit.MINUTES.between(t, now) < JUST_NOW_MINUTES -> "Refreshed just now"
|
||||
days <= 0 -> "Refreshed today"
|
||||
days == 1L -> "Refreshed yesterday"
|
||||
days < WEEK_DAYS -> "Refreshed $days days ago"
|
||||
else -> "Refreshed " + t.atZone(zone).format(DateTimeFormatter.ofPattern("MMM d", Locale.getDefault()))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The facts every system mix on a shelf has in common, said once beside the
|
||||
* shelf's title instead of under each tile: their size when it is about the
|
||||
* same, and when they were refreshed when that is the same. Empty when the
|
||||
* mixes share nothing worth saying. User playlists are left out: their sizes
|
||||
* and ages are their own.
|
||||
*/
|
||||
fun shelfMeta(
|
||||
playlists: List<PlaylistRef>,
|
||||
now: Instant = Instant.now(),
|
||||
zone: ZoneId = ZoneId.systemDefault(),
|
||||
): String {
|
||||
val mixes = playlists.filter { it.isSystem }
|
||||
if (mixes.isEmpty()) return ""
|
||||
val parts = mutableListOf<String>()
|
||||
|
||||
val counts = mixes.map { it.trackCount }.sorted()
|
||||
val lo = counts.first()
|
||||
val hi = counts.last()
|
||||
if (lo == hi) {
|
||||
parts += "${plural(lo, "song", "songs")} each"
|
||||
} else if (hi - lo <= hi * SAME_SIZE_TOLERANCE) {
|
||||
// Close enough to read as one size: round the middle to a friendly 5.
|
||||
val mid = counts[counts.size / 2]
|
||||
val rounded = max(ROUND_TO, (mid.toDouble() / ROUND_TO).roundToInt() * ROUND_TO)
|
||||
parts += "about ${plural(rounded, "song", "songs")} each"
|
||||
}
|
||||
|
||||
val labels = mixes.map { refreshedLabel(it.createdAt, now, zone) }.toSet()
|
||||
val label = labels.singleOrNull()
|
||||
if (!label.isNullOrEmpty()) parts += label.lowercase(Locale.getDefault())
|
||||
|
||||
return parts.joinToString(" · ").replaceFirstChar { it.uppercase() }
|
||||
}
|
||||
|
||||
/**
|
||||
* "Songs like Low Tide Choir" → "Low Tide Choir": a Songs like tile labels
|
||||
* the artist under its circle, so the prefix would only repeat the shelf.
|
||||
*/
|
||||
fun songsLikeArtist(p: PlaylistRef): String = p.name.replace(SONGS_LIKE_PREFIX, "")
|
||||
|
||||
/** "{n} song" / "{n} songs". */
|
||||
fun plural(n: Int, one: String, many: String): String = "$n ${if (n == 1) one else many}"
|
||||
|
||||
/** An sRGB colour as 0–255 channels; kept free of Compose so it unit-tests. */
|
||||
data class Rgb(val r: Int, val g: Int, val b: Int)
|
||||
|
||||
/**
|
||||
* The colour a wide card or genre band is washed in, from its lead cover's
|
||||
* main colour. A light or loud cover would wash the card too light for the
|
||||
* light text on it, so the tone keeps the cover's hue but caps its
|
||||
* lightness and saturation. The card's gradient then darkens it further,
|
||||
* and its text clears 4.5:1 on any cover (ShelfTest checks it).
|
||||
*/
|
||||
fun washTone(c: Rgb): Rgb {
|
||||
val (h, s, l) = toHsl(c.r / CHANNEL_MAX, c.g / CHANNEL_MAX, c.b / CHANNEL_MAX)
|
||||
return fromHsl(h, min(s, MAX_WASH_SATURATION), min(l, MAX_WASH_LIGHTNESS))
|
||||
}
|
||||
|
||||
private fun toHsl(r: Double, g: Double, b: Double): Triple<Double, Double, Double> {
|
||||
val mx = maxOf(r, g, b)
|
||||
val mn = minOf(r, g, b)
|
||||
val l = (mx + mn) / 2
|
||||
if (mx == mn) return Triple(0.0, 0.0, l)
|
||||
val d = mx - mn
|
||||
val s = if (l > HALF) d / (2 - mx - mn) else d / (mx + mn)
|
||||
val h = when (mx) {
|
||||
r -> (g - b) / d + (if (g < b) HUE_SECTORS else 0.0)
|
||||
g -> (b - r) / d + 2
|
||||
else -> (r - g) / d + 4
|
||||
}
|
||||
return Triple(h / HUE_SECTORS, s, l)
|
||||
}
|
||||
|
||||
private fun fromHsl(h: Double, s: Double, l: Double): Rgb {
|
||||
val q = if (l < HALF) l * (1 + s) else l + s - l * s
|
||||
val p = 2 * l - q
|
||||
fun channel(t0: Double): Double {
|
||||
var t = t0
|
||||
if (t < 0) t += 1
|
||||
if (t > 1) t -= 1
|
||||
return when {
|
||||
t < 1.0 / HUE_SECTORS -> p + (q - p) * HUE_SECTORS * t
|
||||
t < HALF -> q
|
||||
t < 2.0 / 3 -> p + (q - p) * (2.0 / 3 - t) * HUE_SECTORS
|
||||
else -> p
|
||||
}
|
||||
}
|
||||
return Rgb(
|
||||
r = (channel(h + 1.0 / 3) * CHANNEL_MAX).roundToInt(),
|
||||
g = (channel(h) * CHANNEL_MAX).roundToInt(),
|
||||
b = (channel(h - 1.0 / 3) * CHANNEL_MAX).roundToInt(),
|
||||
)
|
||||
}
|
||||
|
||||
private val SONGS_LIKE_PREFIX = Regex("^Songs like\\s+", RegexOption.IGNORE_CASE)
|
||||
private const val JUST_NOW_MINUTES = 5
|
||||
private const val WEEK_DAYS = 7
|
||||
private const val SAME_SIZE_TOLERANCE = 0.1
|
||||
private const val ROUND_TO = 5
|
||||
private const val CHANNEL_MAX = 255.0
|
||||
private const val HUE_SECTORS = 6.0
|
||||
private const val HALF = 0.5
|
||||
private const val MAX_WASH_SATURATION = 0.6
|
||||
private const val MAX_WASH_LIGHTNESS = 0.3
|
||||
+8
@@ -263,6 +263,8 @@ private fun CachedPlaylistEntity.toDomain(): PlaylistRef =
|
||||
isPublic = isPublic,
|
||||
systemVariant = systemVariant,
|
||||
trackCount = trackCount,
|
||||
coverAlbumIds = coverAlbumIds.split(',').filter { it.isNotEmpty() },
|
||||
createdAt = createdAt,
|
||||
// Server returns a relative cover path like "/api/playlists/<id>/cover";
|
||||
// wrap through the placeholder host so BaseUrlInterceptor + the shared
|
||||
// Coil/OkHttpClient resolve it against the live server. Without this
|
||||
@@ -280,6 +282,8 @@ private fun PlaylistWire.toEntity(): CachedPlaylistEntity =
|
||||
coverPath = coverUrl.ifEmpty { null },
|
||||
trackCount = trackCount,
|
||||
systemVariant = systemVariant,
|
||||
coverAlbumIds = coverAlbumIds.joinToString(","),
|
||||
createdAt = createdAt,
|
||||
)
|
||||
|
||||
private fun PlaylistDetailWire.toPlaylistEntity(): CachedPlaylistEntity =
|
||||
@@ -292,6 +296,8 @@ private fun PlaylistDetailWire.toPlaylistEntity(): CachedPlaylistEntity =
|
||||
coverPath = coverUrl.ifEmpty { null },
|
||||
trackCount = trackCount,
|
||||
systemVariant = systemVariant,
|
||||
coverAlbumIds = coverAlbumIds.joinToString(","),
|
||||
createdAt = createdAt,
|
||||
)
|
||||
|
||||
private fun PlaylistDetailWire.toPlaylistRef(): PlaylistRef =
|
||||
@@ -308,6 +314,8 @@ private fun PlaylistDetailWire.toPlaylistRef(): PlaylistRef =
|
||||
// host for BaseUrlInterceptor to rewrite to the live server.
|
||||
coverUrl = resolveServerUrl(coverUrl) ?: "",
|
||||
ownerUsername = ownerUsername,
|
||||
coverAlbumIds = coverAlbumIds,
|
||||
createdAt = createdAt,
|
||||
)
|
||||
|
||||
private fun PlaylistTrackWire.toDomain(): PlaylistTrackRef =
|
||||
|
||||
+82
-27
@@ -3,12 +3,13 @@ package com.fabledsword.minstrel.playlists.widgets
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -18,6 +19,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.composables.icons.lucide.ListMusic
|
||||
@@ -38,17 +40,29 @@ import com.fabledsword.minstrel.theme.FabledSwordFlatTokens
|
||||
* - seed-needed → songs-like slot with no seed artist liked yet
|
||||
* - pending → never built / waiting for the next scheduled run
|
||||
*/
|
||||
/** Which shelf a placeholder stands in for; it takes that shelf's tile shape. */
|
||||
enum class PlaceholderShape { SQUARE, WIDE, ROUND }
|
||||
|
||||
@Composable
|
||||
fun PlaylistPlaceholderCard(
|
||||
label: String,
|
||||
variant: String,
|
||||
modifier: Modifier = Modifier,
|
||||
shape: PlaceholderShape = PlaceholderShape.SQUARE,
|
||||
) {
|
||||
Column(modifier = modifier.width(176.dp).padding(horizontal = 8.dp)) {
|
||||
if (shape == PlaceholderShape.WIDE) {
|
||||
WidePlaceholder(label = label, variant = variant, modifier = modifier)
|
||||
return
|
||||
}
|
||||
val round = shape == PlaceholderShape.ROUND
|
||||
Column(
|
||||
modifier = modifier.width(if (round) 136.dp else 176.dp).padding(horizontal = 8.dp),
|
||||
horizontalAlignment = if (round) Alignment.CenterHorizontally else Alignment.Start,
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(144.dp)
|
||||
.clip(RoundedCornerShape(FabledSwordFlatTokens.radiusSm))
|
||||
.size(if (round) 120.dp else 144.dp)
|
||||
.clip(if (round) CircleShape else RoundedCornerShape(FabledSwordFlatTokens.radiusSm))
|
||||
.background(MaterialTheme.colorScheme.surfaceVariant),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
@@ -58,39 +72,80 @@ fun PlaylistPlaceholderCard(
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.size(40.dp),
|
||||
)
|
||||
Surface(
|
||||
StatusPill(
|
||||
variant = variant,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomStart)
|
||||
.align(if (round) Alignment.BottomCenter else Alignment.BottomStart)
|
||||
.padding(6.dp),
|
||||
shape = RoundedCornerShape(FabledSwordFlatTokens.radiusSm),
|
||||
color = MaterialTheme.colorScheme.surface.copy(alpha = STATUS_BG_ALPHA),
|
||||
) {
|
||||
Text(
|
||||
text = statusLabelFor(variant),
|
||||
modifier = Modifier.padding(horizontal = 8.dp, vertical = 2.dp),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(8.dp))
|
||||
PlaceholderText(label = label, variant = variant, centered = round)
|
||||
}
|
||||
}
|
||||
|
||||
/** The wide placeholder, the same size as Home's wide playlist card. */
|
||||
@Composable
|
||||
private fun WidePlaceholder(label: String, variant: String, modifier: Modifier) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.width(296.dp)
|
||||
.height(125.dp)
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(MaterialTheme.colorScheme.surfaceVariant),
|
||||
) {
|
||||
Box(modifier = Modifier.size(125.dp), contentAlignment = Alignment.Center) {
|
||||
Icon(
|
||||
imageVector = iconFor(variant),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.size(40.dp),
|
||||
)
|
||||
StatusPill(variant = variant, modifier = Modifier.align(Alignment.BottomStart).padding(6.dp))
|
||||
}
|
||||
Column(modifier = Modifier.padding(12.dp)) {
|
||||
PlaceholderText(label = label, variant = variant, centered = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StatusPill(variant: String, modifier: Modifier) {
|
||||
Surface(
|
||||
modifier = modifier,
|
||||
shape = RoundedCornerShape(FabledSwordFlatTokens.radiusSm),
|
||||
color = MaterialTheme.colorScheme.surface.copy(alpha = STATUS_BG_ALPHA),
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
text = statusLabelFor(variant),
|
||||
modifier = Modifier.padding(horizontal = 8.dp, vertical = 2.dp),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
Text(
|
||||
text = subtitleFor(variant),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PlaceholderText(label: String, variant: String, centered: Boolean) {
|
||||
val align = if (centered) TextAlign.Center else TextAlign.Start
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
textAlign = align,
|
||||
)
|
||||
Text(
|
||||
text = subtitleFor(variant),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
textAlign = align,
|
||||
)
|
||||
}
|
||||
|
||||
private const val STATUS_BG_ALPHA = 0.85f
|
||||
|
||||
private fun iconFor(variant: String) = when (variant) {
|
||||
|
||||
+365
@@ -0,0 +1,365 @@
|
||||
package com.fabledsword.minstrel.playlists.widgets
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shadow
|
||||
import androidx.compose.ui.graphics.lerp
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
import com.composables.icons.lucide.ListMusic
|
||||
import com.composables.icons.lucide.Lucide
|
||||
import com.fabledsword.minstrel.models.PlaylistRef
|
||||
import com.fabledsword.minstrel.models.albumCoverPath
|
||||
import com.fabledsword.minstrel.nav.LocalDetailSeedCache
|
||||
import com.fabledsword.minstrel.player.ui.rememberDominantColor
|
||||
import com.fabledsword.minstrel.playlists.Rgb
|
||||
import com.fabledsword.minstrel.playlists.plural
|
||||
import com.fabledsword.minstrel.playlists.songsLikeArtist
|
||||
import com.fabledsword.minstrel.playlists.washTone
|
||||
import com.fabledsword.minstrel.shared.widgets.CoverTile
|
||||
import com.fabledsword.minstrel.shared.widgets.PlayCircleButton
|
||||
import com.fabledsword.minstrel.shared.widgets.ServerImage
|
||||
import com.fabledsword.minstrel.theme.FabledSwordDarkTokens
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
// Home's three playlist tile shapes, one per kind of shelf, so the shelves
|
||||
// can be told apart at a glance (the web Home's PlaylistCard has the same
|
||||
// three):
|
||||
// - WidePlaylistCard: a main mix or playlist. Its lead cover on the left,
|
||||
// the name and what it is built from on a wash of the cover's colour.
|
||||
// - SongsLikeCard: a circle, the shape artists have everywhere else.
|
||||
// - GenreBandCard: a colour field with a fan of three covers.
|
||||
// `covers` are the album ids the shelf assigned this tile
|
||||
// (assignShelfCovers), so neighbouring tiles show different pictures. The
|
||||
// size and refresh time the tiles share are said once in the shelf heading
|
||||
// (shelfMeta), so no tile repeats them.
|
||||
|
||||
/**
|
||||
* A main mix or user playlist on Home. [greyed] dims it (not playable
|
||||
* offline) while keeping it tappable, as [PlaylistCard] does.
|
||||
*/
|
||||
@Composable
|
||||
fun WidePlaylistCard(
|
||||
playlist: PlaylistRef,
|
||||
covers: List<String>,
|
||||
onClick: () -> Unit,
|
||||
onPlay: suspend () -> Unit,
|
||||
playEnabled: Boolean,
|
||||
greyed: Boolean,
|
||||
) {
|
||||
val lead = leadCoverUrl(playlist, covers)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.width(WIDE_WIDTH)
|
||||
.height(WIDE_HEIGHT)
|
||||
.alpha(if (greyed) GREYED_ALPHA else 1f)
|
||||
.clip(RoundedCornerShape(CARD_RADIUS))
|
||||
.background(washBrush(rememberWash(lead)))
|
||||
.stashingClick(playlist, onClick),
|
||||
) {
|
||||
Row(modifier = Modifier.fillMaxSize()) {
|
||||
LeadArt(url = lead, modifier = Modifier.size(WIDE_HEIGHT))
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(start = 12.dp, top = 12.dp, end = 52.dp, bottom = 12.dp),
|
||||
) {
|
||||
Text(
|
||||
text = playlist.name,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
color = OnWash,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text(
|
||||
text = sublineFor(playlist),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = OnWash.copy(alpha = ON_WASH_2),
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
PlayCircleButton(
|
||||
onPlay = onPlay,
|
||||
enabled = playEnabled && !greyed,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomEnd)
|
||||
.padding(8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** A "Songs like {artist}" mix: a circle labelled with the seed artist. */
|
||||
@Composable
|
||||
fun SongsLikeCard(
|
||||
playlist: PlaylistRef,
|
||||
covers: List<String>,
|
||||
onClick: () -> Unit,
|
||||
onPlay: suspend () -> Unit,
|
||||
playEnabled: Boolean,
|
||||
greyed: Boolean,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.width(ROUND_WIDTH)
|
||||
.alpha(if (greyed) GREYED_ALPHA else 1f)
|
||||
.stashingClick(playlist, onClick)
|
||||
.padding(horizontal = 8.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
CoverTile(
|
||||
url = leadCoverUrl(playlist, covers),
|
||||
contentDescription = playlist.name,
|
||||
size = ROUND_SIZE,
|
||||
shape = CircleShape,
|
||||
background = MaterialTheme.colorScheme.surfaceVariant,
|
||||
fallback = { NoArtIcon() },
|
||||
overlay = {
|
||||
PlayCircleButton(
|
||||
onPlay = onPlay,
|
||||
enabled = playEnabled && !greyed,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomEnd)
|
||||
.padding(4.dp),
|
||||
)
|
||||
},
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
text = "SONGS LIKE",
|
||||
style = MaterialTheme.typography.labelSmall.copy(letterSpacing = MICRO_LABEL_TRACKING),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Text(
|
||||
text = songsLikeArtist(playlist),
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A genre mix: a field of its lead cover's colour, the genre in large type,
|
||||
* and a fan of up to three covers across most of its width. The leftmost
|
||||
* cover sits on top and each one to its right tucks under it.
|
||||
*/
|
||||
@Composable
|
||||
fun GenreBandCard(
|
||||
playlist: PlaylistRef,
|
||||
covers: List<String>,
|
||||
onClick: () -> Unit,
|
||||
onPlay: suspend () -> Unit,
|
||||
playEnabled: Boolean,
|
||||
greyed: Boolean,
|
||||
) {
|
||||
val fan = covers.map(::albumCoverPath).ifEmpty { listOfNotNull(playlist.coverUrl.ifEmpty { null }) }
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.width(BAND_WIDTH)
|
||||
.height(BAND_HEIGHT)
|
||||
.alpha(if (greyed) GREYED_ALPHA else 1f)
|
||||
.clip(RoundedCornerShape(CARD_RADIUS))
|
||||
.background(washBrush(rememberWash(fan.firstOrNull())))
|
||||
.stashingClick(playlist, onClick),
|
||||
) {
|
||||
CoverFan(urls = fan, modifier = Modifier.align(Alignment.CenterEnd).padding(end = 12.dp))
|
||||
Text(
|
||||
text = playlist.name.replace(MIX_SUFFIX, ""),
|
||||
style = MaterialTheme.typography.headlineSmall.copy(
|
||||
shadow = Shadow(color = Color.Black.copy(alpha = NAME_SHADOW_ALPHA), blurRadius = 4f),
|
||||
),
|
||||
color = OnWash,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomStart)
|
||||
.padding(start = 8.dp, bottom = 10.dp)
|
||||
.widthIn(max = BAND_WIDTH * NAME_MAX_FRACTION)
|
||||
.zIndex(FAN_LAYERS)
|
||||
.clip(RoundedCornerShape(6.dp))
|
||||
.background(NameBacking)
|
||||
.padding(horizontal = 8.dp, vertical = 2.dp),
|
||||
)
|
||||
PlayCircleButton(
|
||||
onPlay = onPlay,
|
||||
enabled = playEnabled && !greyed,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomEnd)
|
||||
.zIndex(FAN_LAYERS + 1)
|
||||
.padding(8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Up to three covers spanning [FAN_SPAN] of the band's width, as tall as the
|
||||
* band allows and overlapping to fit, tilted -8° / 0° / +8°.
|
||||
*/
|
||||
@Composable
|
||||
private fun CoverFan(urls: List<String>, modifier: Modifier = Modifier) {
|
||||
val n = urls.size.coerceAtMost(FAN_MAX)
|
||||
if (n == 0) return
|
||||
val span = BAND_WIDTH * FAN_SPAN
|
||||
val step: Dp = if (n > 1) (span - FAN_COVER) / (n - 1) else 0.dp
|
||||
Box(modifier = modifier.width(if (n > 1) span else FAN_COVER).height(BAND_HEIGHT)) {
|
||||
urls.take(n).forEachIndexed { i, url ->
|
||||
val tilt = if (n > 1) FAN_TILT_DEG * (2f * i / (n - 1) - 1f) else 0f
|
||||
ServerImage(
|
||||
url = url,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterStart)
|
||||
.offset(x = step * i, y = if (tilt == 0f) (-4).dp else 4.dp)
|
||||
.zIndex((n - i).toFloat())
|
||||
.rotate(tilt)
|
||||
.shadow(elevation = 6.dp, shape = RoundedCornerShape(6.dp))
|
||||
.size(FAN_COVER)
|
||||
.clip(RoundedCornerShape(6.dp)),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LeadArt(url: String?, modifier: Modifier) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxHeight()
|
||||
.background(MaterialTheme.colorScheme.surfaceVariant),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
ServerImage(
|
||||
url = url,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
fallback = { NoArtIcon() },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NoArtIcon() {
|
||||
Icon(
|
||||
imageVector = Lucide.ListMusic,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.size(40.dp),
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Modifier.stashingClick(playlist: PlaylistRef, onClick: () -> Unit): Modifier {
|
||||
val seedCache = LocalDetailSeedCache.current
|
||||
return clickable {
|
||||
seedCache.stashPlaylist(playlist)
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The wash colour for a tile whose lead cover is [url]: the cover's main
|
||||
* colour, toned by [washTone] so light text reads on it. A neutral slate
|
||||
* until the colour is known, or when there is no cover.
|
||||
*/
|
||||
@Composable
|
||||
private fun rememberWash(url: String?): Color {
|
||||
val dominant = rememberDominantColor(url)
|
||||
if (dominant == Color.Transparent) return NeutralWash
|
||||
val toned = washTone(
|
||||
Rgb(r = channel(dominant.red), g = channel(dominant.green), b = channel(dominant.blue)),
|
||||
)
|
||||
return Color(red = toned.r, green = toned.g, blue = toned.b)
|
||||
}
|
||||
|
||||
/**
|
||||
* The tile background: the wash darkened toward near-black, 62% wash at the
|
||||
* art end fading to 30%. With [washTone]'s caps this keeps [OnWash] text at
|
||||
* 4.5:1 or better on any cover (ShelfTest checks the numbers).
|
||||
*/
|
||||
private fun washBrush(wash: Color): Brush = Brush.horizontalGradient(
|
||||
listOf(lerp(WashBase, wash, WASH_NEAR), lerp(WashBase, wash, WASH_FAR)),
|
||||
)
|
||||
|
||||
private fun channel(v: Float): Int = (v * CHANNEL_MAX).roundToInt()
|
||||
|
||||
private fun leadCoverUrl(playlist: PlaylistRef, covers: List<String>): String? =
|
||||
covers.firstOrNull()?.let(::albumCoverPath) ?: playlist.coverUrl.ifEmpty { null }
|
||||
|
||||
/** A system mix says what it is built from; anything else says its size and owner. */
|
||||
private fun sublineFor(p: PlaylistRef): String =
|
||||
if (p.isSystem && p.description.isNotEmpty()) {
|
||||
p.description
|
||||
} else {
|
||||
plural(p.trackCount, "track", "tracks") +
|
||||
if (p.ownerUsername.isNotEmpty()) " · by ${p.ownerUsername}" else ""
|
||||
}
|
||||
|
||||
// The wash is dark in both themes, so its text is the dark theme's light
|
||||
// parchment in both themes too; the theme-switching tokens would turn it
|
||||
// dark in light mode and lose the contrast.
|
||||
private val OnWash = FabledSwordDarkTokens.parchment
|
||||
private val WashBase = Color(red = 14, green = 16, blue = 19)
|
||||
private val NeutralWash = Color(red = 44, green = 49, blue = 58)
|
||||
|
||||
// 70% near-black behind a genre name keeps it above 4.5:1 even where the
|
||||
// fan's covers run under it and one of them is white.
|
||||
private val NameBacking = Color(red = 14, green = 16, blue = 19, alpha = 179)
|
||||
private val MIX_SUFFIX = Regex("\\s+mix$", RegexOption.IGNORE_CASE)
|
||||
|
||||
// Wide card 64:27 and band 16:7, the web Home's proportions.
|
||||
private val WIDE_WIDTH = 296.dp
|
||||
private val WIDE_HEIGHT = 125.dp
|
||||
private val BAND_WIDTH = 280.dp
|
||||
private val BAND_HEIGHT = 122.dp
|
||||
private val ROUND_WIDTH = 136.dp
|
||||
private val ROUND_SIZE = 120.dp
|
||||
private val CARD_RADIUS = 12.dp
|
||||
private val FAN_COVER = 95.dp
|
||||
private val MICRO_LABEL_TRACKING = 0.9.sp
|
||||
|
||||
private const val FAN_SPAN = 0.8f
|
||||
private const val FAN_MAX = 3
|
||||
private const val FAN_LAYERS = 4f
|
||||
private const val FAN_TILT_DEG = 8f
|
||||
private const val NAME_MAX_FRACTION = 0.85f
|
||||
private const val NAME_SHADOW_ALPHA = 0.6f
|
||||
private const val WASH_NEAR = 0.62f
|
||||
private const val WASH_FAR = 0.30f
|
||||
private const val ON_WASH_2 = 0.9f
|
||||
private const val GREYED_ALPHA = 0.45f
|
||||
private const val CHANNEL_MAX = 255f
|
||||
+27
-5
@@ -3,6 +3,7 @@ package com.fabledsword.minstrel.shared.widgets
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
@@ -11,6 +12,7 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
/**
|
||||
@@ -22,21 +24,41 @@ import androidx.compose.ui.unit.dp
|
||||
*
|
||||
* The `content` lambda receives a `LazyListScope` so callers use
|
||||
* `items(list, key = ...) { ... }` — preserves lazy item rendering.
|
||||
*
|
||||
* [meta] is a short line beside the title for facts every tile in the row
|
||||
* shares ("25 songs each · refreshed today"), said once instead of under
|
||||
* each tile. Empty shows nothing.
|
||||
*/
|
||||
@Composable
|
||||
fun HorizontalScrollRow(
|
||||
title: String,
|
||||
modifier: Modifier = Modifier,
|
||||
meta: String = "",
|
||||
content: LazyListScope.() -> Unit,
|
||||
) {
|
||||
Column(modifier = modifier.fillMaxWidth()) {
|
||||
if (title.isNotEmpty()) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
)
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
modifier = Modifier.alignByBaseline(),
|
||||
)
|
||||
if (meta.isNotEmpty()) {
|
||||
Text(
|
||||
text = meta,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.alignByBaseline(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
LazyRow(
|
||||
contentPadding = PaddingValues(horizontal = 16.dp),
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.fabledsword.minstrel.playlists
|
||||
|
||||
import com.fabledsword.minstrel.models.PlaylistRef
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
import java.time.Instant
|
||||
import java.time.ZoneOffset
|
||||
import kotlin.math.pow
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class ShelfTest {
|
||||
|
||||
private val utc = ZoneOffset.UTC
|
||||
private val now = Instant.parse("2026-11-23T15:00:00Z")
|
||||
|
||||
private fun mix(
|
||||
covers: List<String> = emptyList(),
|
||||
tracks: Int = 100,
|
||||
createdAt: String = "2026-11-23T08:00:00Z",
|
||||
variant: String? = "for_you",
|
||||
name: String = "Mix",
|
||||
) = PlaylistRef(
|
||||
id = name,
|
||||
userId = "u",
|
||||
name = name,
|
||||
systemVariant = variant,
|
||||
trackCount = tracks,
|
||||
coverAlbumIds = covers,
|
||||
createdAt = createdAt,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `each tile takes the first album no earlier tile shows`() {
|
||||
val got = assignShelfCovers(
|
||||
listOf(mix(listOf("a", "b", "c")), mix(listOf("a", "d")), mix(listOf("a", "d", "e"))),
|
||||
perTile = 1,
|
||||
)
|
||||
assertEquals(listOf(listOf("a"), listOf("d"), listOf("e")), got)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a band takes three unused albums`() {
|
||||
val got = assignShelfCovers(
|
||||
listOf(mix(listOf("a", "b", "c", "d")), mix(listOf("b", "c", "e", "f", "g"))),
|
||||
perTile = 3,
|
||||
)
|
||||
assertEquals(listOf(listOf("a", "b", "c"), listOf("e", "f", "g")), got)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a tile whose albums are all taken reuses its own rather than showing nothing`() {
|
||||
val got = assignShelfCovers(listOf(mix(listOf("a")), mix(listOf("a"))), perTile = 1)
|
||||
assertEquals(listOf(listOf("a"), listOf("a")), got)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `equal sizes and the same refresh read as one line`() {
|
||||
assertEquals("25 songs each · refreshed today", shelfMeta(listOf(mix(tracks = 25), mix(tracks = 25)), now, utc))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sizes within a tenth of each other read as about`() {
|
||||
val mixes = listOf(95, 97, 99, 100).map { mix(tracks = it) }
|
||||
assertEquals("About 100 songs each · refreshed today", shelfMeta(mixes, now, utc))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sizes that differ widely are left to the tiles`() {
|
||||
assertEquals("Refreshed today", shelfMeta(listOf(mix(tracks = 20), mix(tracks = 100)), now, utc))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `user playlists do not count, and a shelf of only them says nothing`() {
|
||||
val mine = mix(tracks = 3, variant = null, createdAt = "2025-01-01T00:00:00Z")
|
||||
assertEquals("", shelfMeta(listOf(mine), now, utc))
|
||||
assertEquals("50 songs each · refreshed today", shelfMeta(listOf(mix(tracks = 50), mine), now, utc))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `different refresh days are not summarised`() {
|
||||
val mixes = listOf(mix(), mix(createdAt = "2026-11-20T08:00:00Z"))
|
||||
assertEquals("100 songs each", shelfMeta(mixes, now, utc))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `refreshed label counts calendar days`() {
|
||||
val noon = Instant.parse("2026-11-23T12:00:00Z")
|
||||
assertEquals("Refreshed yesterday", refreshedLabel("2026-11-22T12:00:00Z", noon, utc))
|
||||
assertEquals("Refreshed 3 days ago", refreshedLabel("2026-11-20T12:00:00Z", noon, utc))
|
||||
assertEquals("", refreshedLabel("not a date", noon, utc))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `songs like tiles drop the shelf-wide prefix`() {
|
||||
assertEquals("Low Tide Choir", songsLikeArtist(mix(name = "Songs like Low Tide Choir")))
|
||||
assertEquals("Something else", songsLikeArtist(mix(name = "Something else")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a dark cover keeps its own colour`() {
|
||||
assertEquals(Rgb(30, 60, 90), washTone(Rgb(30, 60, 90)))
|
||||
}
|
||||
|
||||
// A tile's gradient is the tone mixed 62% toward #0e1013 at its lightest
|
||||
// end. Its text is parchment at 90% or more; this checks 80%, a margin
|
||||
// the web client's tiles also hold to.
|
||||
@ParameterizedTest(name = "{0} cover")
|
||||
@MethodSource("lightCovers")
|
||||
fun `a light or loud cover still leaves the faintest text at 4_5 to 1`(name: String, cover: Rgb) {
|
||||
val ground = blend(washTone(cover).toD(), 0.62, Triple(14.0, 16.0, 19.0))
|
||||
val text = blend(Triple(232.0, 228.0, 216.0), 0.8, ground)
|
||||
val ratio = (lum(text) + 0.05) / (lum(ground) + 0.05)
|
||||
assertTrue(ratio >= 4.5, "$name: $ratio")
|
||||
}
|
||||
|
||||
private fun Rgb.toD() = Triple(r.toDouble(), g.toDouble(), b.toDouble())
|
||||
|
||||
private fun blend(a: Triple<Double, Double, Double>, t: Double, b: Triple<Double, Double, Double>) = Triple(
|
||||
a.first * t + b.first * (1 - t),
|
||||
a.second * t + b.second * (1 - t),
|
||||
a.third * t + b.third * (1 - t),
|
||||
)
|
||||
|
||||
private fun lum(c: Triple<Double, Double, Double>): Double {
|
||||
fun ch(v: Double): Double {
|
||||
val s = v / 255
|
||||
return if (s <= 0.03928) s / 12.92 else ((s + 0.055) / 1.055).pow(2.4)
|
||||
}
|
||||
return 0.2126 * ch(c.first) + 0.7152 * ch(c.second) + 0.0722 * ch(c.third)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun lightCovers() = listOf(
|
||||
arrayOf("beige", Rgb(200, 190, 160)),
|
||||
arrayOf("near white", Rgb(245, 245, 245)),
|
||||
arrayOf("acid yellow", Rgb(240, 240, 20)),
|
||||
arrayOf("light grey", Rgb(170, 175, 180)),
|
||||
)
|
||||
}
|
||||
}
|
||||
+14
@@ -61,4 +61,18 @@ class PlaylistsRepositoryCacheMergeTest {
|
||||
assertEquals(true, byId.getValue("full").fullyCached)
|
||||
assertEquals(false, byId.getValue("partial").fullyCached)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cover albums and creation time come back from the cached row`() {
|
||||
val row = playlist("p", trackCount = 3).copy(coverAlbumIds = "a1,a2", createdAt = "2026-11-23T08:00:00Z")
|
||||
val out = mergePlaylistsWithCache(rows = listOf(row), counts = emptyList()).single()
|
||||
assertEquals(listOf("a1", "a2"), out.coverAlbumIds)
|
||||
assertEquals("2026-11-23T08:00:00Z", out.createdAt)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a row cached before cover albums existed has none`() {
|
||||
val out = mergePlaylistsWithCache(rows = listOf(playlist("p", trackCount = 3)), counts = emptyList())
|
||||
assertEquals(emptyList(), out.single().coverAlbumIds)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user