Use LazyColumn in PlaylistOrAlbumScreen

This commit is contained in:
vfsfitvnm
2022-06-12 19:54:48 +02:00
parent ec052c7636
commit 6737a7b003

View File

@@ -3,8 +3,13 @@ package it.vfsfitvnm.vimusic.ui.screens
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.* import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.BasicText import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.* import androidx.compose.runtime.*
@@ -51,7 +56,7 @@ import kotlinx.coroutines.withContext
fun PlaylistOrAlbumScreen( fun PlaylistOrAlbumScreen(
browseId: String, browseId: String,
) { ) {
val scrollState = rememberScrollState() val lazyListState = rememberLazyListState()
var playlistOrAlbum by remember { var playlistOrAlbum by remember {
mutableStateOf<Outcome<YouTube.PlaylistOrAlbum>>(Outcome.Loading) mutableStateOf<Outcome<YouTube.PlaylistOrAlbum>>(Outcome.Loading)
@@ -101,13 +106,14 @@ fun PlaylistOrAlbumScreen(
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
Column( LazyColumn(
state = lazyListState,
contentPadding = PaddingValues(bottom = 72.dp),
modifier = Modifier modifier = Modifier
.background(colorPalette.background) .background(colorPalette.background)
.fillMaxSize() .fillMaxSize()
.verticalScroll(scrollState)
.padding(bottom = 72.dp)
) { ) {
item {
TopAppBar( TopAppBar(
modifier = Modifier modifier = Modifier
.height(52.dp) .height(52.dp)
@@ -215,7 +221,9 @@ fun PlaylistOrAlbumScreen(
.size(24.dp) .size(24.dp)
) )
} }
}
item {
OutcomeItem( OutcomeItem(
outcome = playlistOrAlbum, outcome = playlistOrAlbum,
onRetry = onLoad, onRetry = onLoad,
@@ -324,17 +332,22 @@ fun PlaylistOrAlbumScreen(
} }
} }
} }
}
}
playlistOrAlbum.items?.forEachIndexed { index, song -> itemsIndexed(
items = playlistOrAlbum.valueOrNull?.items ?: emptyList(),
contentType = { _, song -> song }
) { index, song ->
SongItem( SongItem(
title = song.info.name, title = song.info.name,
authors = (song.authors ?: playlistOrAlbum.authors)?.joinToString("") { it.name }, authors = (song.authors ?: playlistOrAlbum.valueOrNull?.authors)?.joinToString("") { it.name },
durationText = song.durationText, durationText = song.durationText,
onClick = { onClick = {
player?.mediaController?.let { player?.mediaController?.let {
it.sendCustomCommand(StopRadioCommand, Bundle.EMPTY) it.sendCustomCommand(StopRadioCommand, Bundle.EMPTY)
playlistOrAlbum.items?.mapNotNull { song -> playlistOrAlbum.valueOrNull?.items?.mapNotNull { song ->
song.toMediaItem(browseId, playlistOrAlbum) song.toMediaItem(browseId, playlistOrAlbum.valueOrNull!!)
}?.let { mediaItems -> }?.let { mediaItems ->
it.forcePlayAtIndex(mediaItems, index) it.forcePlayAtIndex(mediaItems, index)
} }
@@ -363,7 +376,7 @@ fun PlaylistOrAlbumScreen(
}, },
menuContent = { menuContent = {
NonQueuedMediaItemMenu( NonQueuedMediaItemMenu(
mediaItem = song.toMediaItem(browseId, playlistOrAlbum) mediaItem = song.toMediaItem(browseId, playlistOrAlbum.valueOrNull!!)
?: return@SongItem, ?: return@SongItem,
onDismiss = menuState::hide, onDismiss = menuState::hide,
) )
@@ -374,7 +387,6 @@ fun PlaylistOrAlbumScreen(
} }
} }
} }
}
@Composable @Composable
private fun Loading() { private fun Loading() {