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) <noreply@anthropic.com>
This commit is contained in:
2026-05-28 01:01:43 -04:00
parent 7f6aa9482a
commit 6a473661ba
@@ -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<AlbumRef>,
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<AlbumRef>,
artists: List<ArtistRef>,
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<TrackRef>,
onMostPlayedTap: (List<TrackRef>, 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<ArtistRef>,
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(