Skip to content

Commit

Permalink
Wrap calculations in remember
Browse files Browse the repository at this point in the history
  • Loading branch information
07jasjeet committed Feb 5, 2025
1 parent e4be5bc commit 9a126a2
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,28 @@ import org.listenbrainz.android.ui.components.ListenCardSmall
import org.listenbrainz.android.ui.theme.ListenBrainzTheme
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.remember

@Composable
fun AlbumsOverViewScreen(
albums: List<Album>,
onPlayIconClick: (Album) -> Unit
) {
val albumsStarting: MutableMap<Char, MutableList<Album>> = mutableMapOf()
val albumsStarting = remember(albums) {
val albumsStarting = mutableMapOf<Char, MutableList<Album>>()

for (i in 0..25) {
albumsStarting['A' + i] = mutableListOf()
}
albumsStarting['#'] = mutableListOf()
for (i in 0..25) {
albumsStarting['A' + i] = mutableListOf()
}
albumsStarting['#'] = mutableListOf()

for (album in albums) {
val title = album.title.trim()
val startingLetter = title.firstOrNull()?.uppercaseChar()?.takeIf { it.isLetter() } ?: '#'
albumsStarting[startingLetter]?.add(album)
}

for (album in albums) {
val title = album.title.trim()
val startingLetter = title.firstOrNull()?.uppercaseChar()?.takeIf { it.isLetter() } ?: '#'
albumsStarting[startingLetter]?.add(album)
albumsStarting as Map<Char, List<Album>>
}

LazyColumn(
Expand Down

0 comments on commit 9a126a2

Please sign in to comment.