package com.example.musicapp.Interface import TopBar import…
- User
package com.example.musicapp.Interface
import TopBar import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import com.example.musicapp.Data.Song import com.example.musicapp.ViewModel.AlbumDetailsViewModel import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.* import androidx.compose.runtime.collectAsState import androidx.compose.ui.Alignment import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.navigation.NavController import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import coil.compose.rememberImagePainter import coil.transform.CircleCropTransformation import com.example.musicapp.ViewModel.PlayerViewModel import com.example.musicapp.R import androidx.compose.runtime.remember import androidx.lifecycle.ViewModelStoreOwner import com.example.musicapp.Data.Repository.DeezerRepository
@Composable fun AlbumDetailScreen(albumId: Int, navController: NavController, localViewModelStoreOwner: ViewModelStoreOwner ) { val context = LocalContext.current val deezerRepository = remember { DeezerRepository() } // memoize to avoid re-initialization val albumDetailsViewModel: AlbumDetailsViewModel = viewModel()
code// Replace the previous playerViewModel assignment with this code: val playerViewModel = remember { PlayerViewModel(context) } albumDetailsViewModel.fetchAlbumDetails(albumId) val albumDetails = albumDetailsViewModel.albumDetails.collectAsState().value albumDetails?.let { details -> Scaffold( topBar = { TopBar(title = details.title) }, content = { padding -> Column( modifier = Modifier.padding(padding) ) { LazyColumn { itemsIndexed(details.songs) { _, song -> // Use itemsIndexed instead of items AlbumDetailItem(song, navController, playerViewModel) } } } } ) } - Assistant