From 6a473661ba609ec37f50cf3f373eabd9a2fc8f10 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 28 May 2026 01:01:43 -0400 Subject: [PATCH] fix(android) detekt: extract Home section helpers from HomeSuccessContent The 25-row chunking + per-section empty messages pushed HomeSuccessContent to 69 lines (cap 60). Extracted each section into a LazyListScope extension (recentlyAddedSection / rediscoverSection / mostPlayedSection / lastPlayedSection) so the main composable is just the LazyColumn skeleton calling them. File already carries @file:Suppress(TooManyFunctions) for the Compose helper density. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../minstrel/home/ui/HomeScreen.kt | 151 +++++++++++------- 1 file changed, 89 insertions(+), 62 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/minstrel/home/ui/HomeScreen.kt b/android/app/src/main/java/com/fabledsword/minstrel/home/ui/HomeScreen.kt index 15c3bfda..5b323735 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/home/ui/HomeScreen.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/home/ui/HomeScreen.kt @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.itemsIndexed @@ -291,72 +292,98 @@ private fun HomeSuccessContent( if (sections.playlists.isNotEmpty()) { item { PlaylistsRow(sections.playlists, onPlaylistClick) } } - if (sections.recentlyAddedAlbums.isNotEmpty()) { - // Chunk into stacked carousels of 25 so a large library - // reads as multiple rows instead of one unwieldy LazyRow. - // Only the first chunk carries the section title; the rest - // are untitled continuation rows (matches Flutter). - val chunks = sections.recentlyAddedAlbums.chunked(RECENTLY_ADDED_CHUNK) - itemsIndexed( - items = chunks, - key = { index, chunk -> "recent-$index-${chunk.first().id}" }, - ) { index, chunk -> - AlbumsRow( - title = if (index == 0) "Recently added" else "", - albums = chunk, - onAlbumClick = onAlbumClick, - ) - } - } else { - item { - EmptySection( - title = "Recently added", - body = "Albums you add to the library will show up here first.", - ) - } - } - item { - if (sections.rediscoverAlbums.isNotEmpty() || - sections.rediscoverArtists.isNotEmpty() - ) { - RediscoverBlock( - albums = sections.rediscoverAlbums, - artists = sections.rediscoverArtists, - onAlbumClick = onAlbumClick, - onArtistClick = onArtistClick, - ) - } else { - EmptySection( - title = "Rediscover", - body = "No forgotten favourites yet. Like albums or " + - "artists to fill this in.", - ) - } - } - item { - if (sections.mostPlayedTracks.isNotEmpty()) { - MostPlayedRow(sections.mostPlayedTracks, onMostPlayedTap) - } else { - EmptySection( - title = "Most played", - body = "Play some music — your most-listened tracks will appear here.", - ) - } - } - item { - if (sections.lastPlayedArtists.isNotEmpty()) { - ArtistsRow("Last played", sections.lastPlayedArtists, onArtistClick) - } else { - EmptySection( - title = "Last played", - body = "Recently played artists will show up here.", - ) - } - } + recentlyAddedSection(sections.recentlyAddedAlbums, onAlbumClick) + rediscoverSection( + albums = sections.rediscoverAlbums, + artists = sections.rediscoverArtists, + onAlbumClick = onAlbumClick, + onArtistClick = onArtistClick, + ) + mostPlayedSection(sections.mostPlayedTracks, onMostPlayedTap) + lastPlayedSection(sections.lastPlayedArtists, onArtistClick) item { Spacer(Modifier.height(BOTTOM_PADDING_FOR_MINIPLAYER_DP.dp)) } } } +private fun LazyListScope.recentlyAddedSection( + albums: List, + onAlbumClick: (String) -> Unit, +) { + if (albums.isEmpty()) { + item { + EmptySection( + title = "Recently added", + body = "Albums you add to the library will show up here first.", + ) + } + return + } + // Chunk into stacked carousels of 25 so a large library reads as + // multiple rows instead of one unwieldy LazyRow. Only the first + // chunk carries the section title; the rest are continuation rows. + val chunks = albums.chunked(RECENTLY_ADDED_CHUNK) + itemsIndexed( + items = chunks, + key = { index, chunk -> "recent-$index-${chunk.first().id}" }, + ) { index, chunk -> + AlbumsRow( + title = if (index == 0) "Recently added" else "", + albums = chunk, + onAlbumClick = onAlbumClick, + ) + } +} + +private fun LazyListScope.rediscoverSection( + albums: List, + artists: List, + onAlbumClick: (String) -> Unit, + onArtistClick: (String) -> Unit, +) { + item { + if (albums.isNotEmpty() || artists.isNotEmpty()) { + RediscoverBlock(albums, artists, onAlbumClick, onArtistClick) + } else { + EmptySection( + title = "Rediscover", + body = "No forgotten favourites yet. Like albums or artists to fill this in.", + ) + } + } +} + +private fun LazyListScope.mostPlayedSection( + tracks: List, + onMostPlayedTap: (List, Int) -> Unit, +) { + item { + if (tracks.isNotEmpty()) { + MostPlayedRow(tracks, onMostPlayedTap) + } else { + EmptySection( + title = "Most played", + body = "Play some music — your most-listened tracks will appear here.", + ) + } + } +} + +private fun LazyListScope.lastPlayedSection( + artists: List, + onArtistClick: (String) -> Unit, +) { + item { + if (artists.isNotEmpty()) { + ArtistsRow("Last played", artists, onArtistClick) + } else { + EmptySection( + title = "Last played", + body = "Recently played artists will show up here.", + ) + } + } +} + @Composable private fun EmptySection(title: String, body: String) { Column(