[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.layout.width
|
||||||
import androidx.compose.foundation.lazy.LazyRow
|
import androidx.compose.foundation.lazy.LazyRow
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -28,23 +30,34 @@ import kotlinx.coroutines.launch
|
|||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PlaylistPanel(modifier: Modifier, videoPlayerViewModel: VideoPlayerViewModel)
|
fun PlaylistPanel(modifier: Modifier, videoPlayerViewModel: VideoPlayerViewModel) {
|
||||||
{
|
|
||||||
val colorScheme = MaterialTheme.colorScheme
|
val colorScheme = MaterialTheme.colorScheme
|
||||||
val name by videoPlayerViewModel.currentName
|
val name by videoPlayerViewModel.currentName
|
||||||
val id by videoPlayerViewModel.currentId
|
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(
|
LazyRow(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(80.dp),
|
.height(80.dp),
|
||||||
|
state = listState,
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
contentPadding = PaddingValues(horizontal = 24.dp)
|
contentPadding = PaddingValues(horizontal = 24.dp)
|
||||||
) {
|
) {
|
||||||
items(videoPlayerViewModel.videos) { it ->
|
items(videos) { it ->
|
||||||
// SingleImageItem(img = it, videoPlayerViewModel.imageLoader!!)
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxHeight().width(140.dp),
|
modifier = Modifier
|
||||||
|
.fillMaxHeight()
|
||||||
|
.width(140.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
if (name == it.video.name)
|
if (name == it.video.name)
|
||||||
return@Card
|
return@Card
|
||||||
@@ -58,11 +71,20 @@ fun PlaylistPanel(modifier: Modifier, videoPlayerViewModel: VideoPlayerViewModel
|
|||||||
CardDefaults.cardColors(containerColor = colorScheme.primary)
|
CardDefaults.cardColors(containerColor = colorScheme.primary)
|
||||||
else
|
else
|
||||||
CardDefaults.cardColors()
|
CardDefaults.cardColors()
|
||||||
|
|
||||||
) {
|
) {
|
||||||
Box(Modifier.padding(8.dp).fillMaxSize())
|
Box(
|
||||||
{
|
Modifier
|
||||||
Text(modifier = Modifier.align(Alignment.Center), text = it.video.name, maxLines = 4, fontWeight = FontWeight.Bold, fontSize = 12.sp, lineHeight = 13.sp)
|
.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