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:
@@ -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,72 +292,98 @@ 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,
|
||||||
itemsIndexed(
|
)
|
||||||
items = chunks,
|
mostPlayedSection(sections.mostPlayedTracks, onMostPlayedTap)
|
||||||
key = { index, chunk -> "recent-$index-${chunk.first().id}" },
|
lastPlayedSection(sections.lastPlayedArtists, onArtistClick)
|
||||||
) { 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.",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
item { Spacer(Modifier.height(BOTTOM_PADDING_FOR_MINIPLAYER_DP.dp)) }
|
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
|
@Composable
|
||||||
private fun EmptySection(title: String, body: String) {
|
private fun EmptySection(title: String, body: String) {
|
||||||
Column(
|
Column(
|
||||||
|
|||||||
Reference in New Issue
Block a user