Skip to content

Commit

Permalink
Fix: don't fetch cover art urls twice
Browse files Browse the repository at this point in the history
  • Loading branch information
prabalsingh24 committed May 29, 2023
1 parent 42aefbc commit f87767a
Showing 1 changed file with 5 additions and 7 deletions.
Expand Up @@ -13,7 +13,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.FloatingActionButton
Expand Down Expand Up @@ -47,7 +47,6 @@ import org.listenbrainz.android.ui.components.ListenCard
import org.listenbrainz.android.ui.components.LoadingAnimation
import org.listenbrainz.android.ui.screens.profile.UserData
import org.listenbrainz.android.util.Constants
import org.listenbrainz.android.util.Utils
import org.listenbrainz.android.viewmodel.ListensViewModel

@Composable
Expand All @@ -57,6 +56,7 @@ fun ListensScreen(
shouldScrollToTop: MutableState<Boolean>,
context: Context = LocalContext.current
) {

DisposableEffect(Unit) {
viewModel.connect(spotifyClientId = spotifyClientId)
onDispose {
Expand Down Expand Up @@ -89,6 +89,7 @@ fun ListensScreen(
val youtubeApiKey = stringResource(id = R.string.youtubeApiKey)
// Listens list
val listens = viewModel.listensFlow.collectAsState().value
val coverArtUrls = viewModel.coverArtFlow.collectAsState().value

Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {

Expand All @@ -110,13 +111,10 @@ fun ListensScreen(
}
}

items(listens) { listen ->
itemsIndexed(listens) { index, listen ->
ListenCard(
listen,
coverArtUrl = Utils.getCoverArtUrl(
caaReleaseMbid = listen.track_metadata.mbid_mapping?.caa_release_mbid,
caaId = listen.track_metadata.mbid_mapping?.caa_id
)
coverArtUrls[index]
)
{
if (it.track_metadata.additional_info?.spotify_id != null) {
Expand Down

0 comments on commit f87767a

Please sign in to comment.