[feat] Smart playlist status sync
This commit is contained in:
@@ -11,11 +11,13 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -28,25 +30,36 @@ import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@Composable
|
||||
fun PlaylistPanel(modifier: Modifier, videoPlayerViewModel: VideoPlayerViewModel)
|
||||
{
|
||||
fun PlaylistPanel(modifier: Modifier, videoPlayerViewModel: VideoPlayerViewModel) {
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
val name by videoPlayerViewModel.currentName
|
||||
val id by videoPlayerViewModel.currentId
|
||||
|
||||
val listState = rememberLazyListState()
|
||||
val videos = videoPlayerViewModel.videos
|
||||
|
||||
LaunchedEffect(id, videos) {
|
||||
val targetIndex = videos.indexOfFirst { it.id == id }
|
||||
if (targetIndex >= 0) {
|
||||
listState.scrollToItem(targetIndex)
|
||||
}
|
||||
}
|
||||
|
||||
LazyRow(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.height(80.dp),
|
||||
state = listState,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
contentPadding = PaddingValues(horizontal = 24.dp)
|
||||
) {
|
||||
items(videoPlayerViewModel.videos) { it ->
|
||||
// SingleImageItem(img = it, videoPlayerViewModel.imageLoader!!)
|
||||
items(videos) { it ->
|
||||
Card(
|
||||
modifier = Modifier.fillMaxHeight().width(140.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.width(140.dp),
|
||||
onClick = {
|
||||
if(name == it.video.name)
|
||||
if (name == it.video.name)
|
||||
return@Card
|
||||
|
||||
videoPlayerViewModel.viewModelScope.launch {
|
||||
@@ -58,11 +71,20 @@ fun PlaylistPanel(modifier: Modifier, videoPlayerViewModel: VideoPlayerViewModel
|
||||
CardDefaults.cardColors(containerColor = colorScheme.primary)
|
||||
else
|
||||
CardDefaults.cardColors()
|
||||
|
||||
) {
|
||||
Box(Modifier.padding(8.dp).fillMaxSize())
|
||||
{
|
||||
Text(modifier = Modifier.align(Alignment.Center), text = it.video.name, maxLines = 4, fontWeight = FontWeight.Bold, fontSize = 12.sp, lineHeight = 13.sp)
|
||||
Box(
|
||||
Modifier
|
||||
.padding(8.dp)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
text = it.video.name,
|
||||
maxLines = 4,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 12.sp,
|
||||
lineHeight = 13.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user