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.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
@@ -291,12 +292,36 @@ private fun HomeSuccessContent(
if (sections.playlists.isNotEmpty()) { if (sections.playlists.isNotEmpty()) {
item { PlaylistsRow(sections.playlists, onPlaylistClick) } item { PlaylistsRow(sections.playlists, onPlaylistClick) }
} }
if (sections.recentlyAddedAlbums.isNotEmpty()) { recentlyAddedSection(sections.recentlyAddedAlbums, onAlbumClick)
// Chunk into stacked carousels of 25 so a large library rediscoverSection(
// reads as multiple rows instead of one unwieldy LazyRow. albums = sections.rediscoverAlbums,
// Only the first chunk carries the section title; the rest artists = sections.rediscoverArtists,
// are untitled continuation rows (matches Flutter). onAlbumClick = onAlbumClick,
val chunks = sections.recentlyAddedAlbums.chunked(RECENTLY_ADDED_CHUNK) 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( itemsIndexed(
items = chunks, items = chunks,
key = { index, chunk -> "recent-$index-${chunk.first().id}" }, key = { index, chunk -> "recent-$index-${chunk.first().id}" },
@@ -307,35 +332,33 @@ private fun HomeSuccessContent(
onAlbumClick = onAlbumClick, onAlbumClick = onAlbumClick,
) )
} }
} else {
item {
EmptySection(
title = "Recently added",
body = "Albums you add to the library will show up here first.",
)
} }
}
item { private fun LazyListScope.rediscoverSection(
if (sections.rediscoverAlbums.isNotEmpty() || albums: List<AlbumRef>,
sections.rediscoverArtists.isNotEmpty() artists: List<ArtistRef>,
onAlbumClick: (String) -> Unit,
onArtistClick: (String) -> Unit,
) { ) {
RediscoverBlock( item {
albums = sections.rediscoverAlbums, if (albums.isNotEmpty() || artists.isNotEmpty()) {
artists = sections.rediscoverArtists, RediscoverBlock(albums, artists, onAlbumClick, onArtistClick)
onAlbumClick = onAlbumClick,
onArtistClick = onArtistClick,
)
} else { } else {
EmptySection( EmptySection(
title = "Rediscover", title = "Rediscover",
body = "No forgotten favourites yet. Like albums or " + body = "No forgotten favourites yet. Like albums or artists to fill this in.",
"artists to fill this in.",
) )
} }
} }
}
private fun LazyListScope.mostPlayedSection(
tracks: List<TrackRef>,
onMostPlayedTap: (List<TrackRef>, Int) -> Unit,
) {
item { item {
if (sections.mostPlayedTracks.isNotEmpty()) { if (tracks.isNotEmpty()) {
MostPlayedRow(sections.mostPlayedTracks, onMostPlayedTap) MostPlayedRow(tracks, onMostPlayedTap)
} else { } else {
EmptySection( EmptySection(
title = "Most played", title = "Most played",
@@ -343,9 +366,15 @@ private fun HomeSuccessContent(
) )
} }
} }
}
private fun LazyListScope.lastPlayedSection(
artists: List<ArtistRef>,
onArtistClick: (String) -> Unit,
) {
item { item {
if (sections.lastPlayedArtists.isNotEmpty()) { if (artists.isNotEmpty()) {
ArtistsRow("Last played", sections.lastPlayedArtists, onArtistClick) ArtistsRow("Last played", artists, onArtistClick)
} else { } else {
EmptySection( EmptySection(
title = "Last played", title = "Last played",
@@ -353,8 +382,6 @@ private fun HomeSuccessContent(
) )
} }
} }
item { Spacer(Modifier.height(BOTTOM_PADDING_FOR_MINIPLAYER_DP.dp)) }
}
} }
@Composable @Composable