feat: Your genres leads with the genres you play most, not A to Z
release / web (push) Successful in 1m8s
release / go (push) Successful in 1m40s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m43s
release / android (push) Successful in 4m21s
release / Build signed APK (push) Successful in 4m55s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 22s
release / Verify release artifacts (tag releases only) (push) Skipped

The genre mix builder already ranks genres by how much you listen to
them (taste profile, then plays and likes, then library size), but the
rank was lost when the mixes were stored and both apps sorted the shelf
by name. Each playlist now has a shelf_rank (migration 0107), which the
genre builder fills 1..n in that listening order, even where it picked a
narrower genre before a broader one. The list and detail endpoints carry
it, and the web and Android Home sort the genre shelf by it, unranked
playlists after by name. Android's playlist cache gains the column
(Room v14).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 18:10:08 -05:00
co-authored by Claude Opus 5.5
parent 7cc14da1a7
commit 104f9fd141
25 changed files with 220 additions and 41 deletions
@@ -67,6 +67,8 @@ import com.fabledsword.minstrel.cache.db.entities.SyncMetadataEntity
CachedNotificationEntity::class,
CachedNotificationSettingsEntity::class,
],
// v14: + cached_playlists.shelfRank, a system mix's place on its Home
// shelf. MIGRATION_13_14 adds it as 0; the next list refresh fills it.
// 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.
@@ -90,7 +92,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 = 13,
version = 14,
exportSchema = true,
)
@TypeConverters(MinstrelTypeConverters::class)
@@ -176,3 +178,13 @@ val MIGRATION_12_13: Migration = object : Migration(12, 13) {
db.execSQL("ALTER TABLE cached_playlists ADD COLUMN createdAt TEXT NOT NULL DEFAULT ''")
}
}
/**
* v13 → v14: a playlist's place on its Home shelf. Starts at 0 (unranked);
* Home refreshes the playlist list on open, which fills it.
*/
val MIGRATION_13_14: Migration = object : Migration(13, 14) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE cached_playlists ADD COLUMN shelfRank INTEGER NOT NULL DEFAULT 0")
}
}
@@ -37,7 +37,14 @@ 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, MIGRATION_12_13)
.addMigrations(
MIGRATION_8_9,
MIGRATION_9_10,
MIGRATION_10_11,
MIGRATION_11_12,
MIGRATION_12_13,
MIGRATION_13_14,
)
.fallbackToDestructiveMigration(dropAllTables = true)
.build()
@@ -35,4 +35,7 @@ data class CachedPlaylistEntity(
/** ISO-8601 creation time; for a system mix, when it was last rebuilt. */
@ColumnInfo(defaultValue = "''")
val createdAt: String = "",
/** Place on its Home shelf, 1 first; 0 when unranked. */
@ColumnInfo(defaultValue = "0")
val shelfRank: Int = 0,
)
@@ -83,6 +83,7 @@ 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.byShelfRank
import com.fabledsword.minstrel.playlists.data.PlaylistsRepository
import com.fabledsword.minstrel.playlists.data.playPlaylistShuffled
import com.fabledsword.minstrel.playlists.shelfMeta
@@ -1340,10 +1341,10 @@ internal fun buildSongsLikeRow(
}
/**
* Builds the "Your genres" row: every genre mix, in name order so the
* shelf reads like a stable channel list. No placeholders — a genre mix
* needs listening history or a genre-tagged library, so none built means
* nothing to show. Offline, fully-cached mixes come first and the rest are
* Builds the "Your genres" row: every genre mix, the genres the listener
* plays most first ([byShelfRank], the server's shelf_rank). No
* placeholders — a genre mix needs listening history or a genre-tagged
* library, so none built means nothing to show. Offline, fully-cached mixes come first and the rest are
* greyed. Mirrors the web Home's genreMixPlaylists.
*/
internal fun buildGenreMixRow(
@@ -1352,7 +1353,7 @@ internal fun buildGenreMixRow(
): List<PlaylistRowItem> {
val mixes = owned
.filter { it.systemVariant == "genre_mix" }
.sortedBy { it.name.lowercase() }
.sortedWith(byShelfRank)
if (!offline) return mixes.map { PlaylistRowItem.Real(it) }
val (available, greyed) = mixes.partition { !it.unavailableOffline }
return (available + greyed).map { PlaylistRowItem.Real(it) }
@@ -28,6 +28,8 @@ data class PlaylistRef(
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 = "",
/** Place on its Home shelf, 1 first; 0 when the app orders it itself. See playlists/Shelf.kt byShelfRank. */
val shelfRank: Int = 0,
) {
val isSystem: Boolean get() = systemVariant != null
@@ -28,6 +28,11 @@ data class PlaylistWire(
* the playlist. Home's shelves pick each tile's picture from these.
*/
@SerialName("cover_album_ids") val coverAlbumIds: List<String> = emptyList(),
/**
* A system mix's place on its Home shelf, 1 first: genre mixes are
* numbered by how much the listener plays each genre. 0 when unranked.
*/
@SerialName("shelf_rank") val shelfRank: Int = 0,
)
/**
@@ -86,5 +91,6 @@ data class PlaylistDetailWire(
@SerialName("owner_username") val ownerUsername: String = "",
@SerialName("created_at") val createdAt: String = "",
@SerialName("cover_album_ids") val coverAlbumIds: List<String> = emptyList(),
@SerialName("shelf_rank") val shelfRank: Int = 0,
val tracks: List<PlaylistTrackWire> = emptyList(),
)
@@ -88,6 +88,15 @@ fun shelfMeta(
return parts.joinToString(" · ").replaceFirstChar { it.uppercase() }
}
/**
* Orders a shelf by the rank the server gave each mix (1 first; genre mixes
* lead with the genres the listener plays most). Unranked playlists follow in
* name order, as do ranked ones should two share a rank.
*/
val byShelfRank: Comparator<PlaylistRef> =
compareBy<PlaylistRef> { if (it.shelfRank > 0) it.shelfRank else Int.MAX_VALUE }
.thenBy { it.name.lowercase(Locale.getDefault()) }
/**
* "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.
@@ -265,6 +265,7 @@ private fun CachedPlaylistEntity.toDomain(): PlaylistRef =
trackCount = trackCount,
coverAlbumIds = coverAlbumIds.split(',').filter { it.isNotEmpty() },
createdAt = createdAt,
shelfRank = shelfRank,
// 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
@@ -284,6 +285,7 @@ private fun PlaylistWire.toEntity(): CachedPlaylistEntity =
systemVariant = systemVariant,
coverAlbumIds = coverAlbumIds.joinToString(","),
createdAt = createdAt,
shelfRank = shelfRank,
)
private fun PlaylistDetailWire.toPlaylistEntity(): CachedPlaylistEntity =
@@ -298,6 +300,7 @@ private fun PlaylistDetailWire.toPlaylistEntity(): CachedPlaylistEntity =
systemVariant = systemVariant,
coverAlbumIds = coverAlbumIds.joinToString(","),
createdAt = createdAt,
shelfRank = shelfRank,
)
private fun PlaylistDetailWire.toPlaylistRef(): PlaylistRef =
@@ -316,6 +319,7 @@ private fun PlaylistDetailWire.toPlaylistRef(): PlaylistRef =
ownerUsername = ownerUsername,
coverAlbumIds = coverAlbumIds,
createdAt = createdAt,
shelfRank = shelfRank,
)
private fun PlaylistTrackWire.toDomain(): PlaylistTrackRef =
@@ -105,13 +105,14 @@ class BuildPlaylistsRowTest {
assertTrue(buildSongsLikeRow(emptyList(), SystemPlaylistsStatus(), offline = true).isEmpty())
}
private fun genreMix(name: String, cached: Boolean) = PlaylistRef(
private fun genreMix(name: String, cached: Boolean, rank: Int = 0) = PlaylistRef(
id = name,
userId = "u",
name = name,
systemVariant = "genre_mix",
trackCount = 50,
fullyCached = cached,
shelfRank = rank,
)
@Test
@@ -131,6 +132,20 @@ class BuildPlaylistsRowTest {
assertEquals(listOf("u1"), carousel)
}
@Test
fun `ranked genre mixes lead with the genre played most, the unranked follow by name`() {
val owned = listOf(
genreMix("Ambient mix", cached = true, rank = 3),
genreMix("Zydeco mix", cached = true),
genreMix("Pop mix", cached = true, rank = 1),
genreMix("Blues mix", cached = true),
genreMix("Jazz mix", cached = true, rank = 2),
)
val names = buildGenreMixRow(owned, offline = false)
.filterIsInstance<PlaylistRowItem.Real>().map { it.playlist.name }
assertEquals(listOf("Pop mix", "Jazz mix", "Ambient mix", "Blues mix", "Zydeco mix"), names)
}
@Test
fun `genre mixes are not refreshable, so a cached one plays offline`() {
assertFalse(genreMix("Jazz mix", cached = true).refreshable)
@@ -70,6 +70,12 @@ class PlaylistsRepositoryCacheMergeTest {
assertEquals("2026-11-23T08:00:00Z", out.createdAt)
}
@Test
fun `a genre mix keeps its shelf rank through the cache`() {
val row = playlist("p", trackCount = 3).copy(shelfRank = 2)
assertEquals(2, mergePlaylistsWithCache(rows = listOf(row), counts = emptyList()).single().shelfRank)
}
@Test
fun `a row cached before cover albums existed has none`() {
val out = mergePlaylistsWithCache(rows = listOf(playlist("p", trackCount = 3)), counts = emptyList())