From 7be18dd5170ee598b72c2022c09d56f4dabc64df Mon Sep 17 00:00:00 2001 From: acite <1498045907@qq.com> Date: Thu, 9 Oct 2025 11:33:34 +0800 Subject: [PATCH] [feat] Playlist remember --- .../view/components/VideoPlayerLandscape.kt | 19 +++++++++++++++---- .../view/components/VideoPlayerPortal.kt | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/acitelight/aether/view/components/VideoPlayerLandscape.kt b/app/src/main/java/com/acitelight/aether/view/components/VideoPlayerLandscape.kt index b4dd032..1f69718 100644 --- a/app/src/main/java/com/acitelight/aether/view/components/VideoPlayerLandscape.kt +++ b/app/src/main/java/com/acitelight/aether/view/components/VideoPlayerLandscape.kt @@ -31,6 +31,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack @@ -52,6 +53,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.remember @@ -87,6 +89,18 @@ fun VideoPlayerLandscape(videoPlayerViewModel: VideoPlayerViewModel) { val activity = (context as? Activity)!! val exoPlayer: ExoPlayer = videoPlayerViewModel.player!! + 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) + } + } + val audioManager = remember { context.getSystemService(Context.AUDIO_SERVICE) as AudioManager } val maxVolume = remember { audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) } var volFactor by remember { @@ -95,9 +109,6 @@ fun VideoPlayerLandscape(videoPlayerViewModel: VideoPlayerViewModel) { ) } - val name by videoPlayerViewModel.currentName - val id by videoPlayerViewModel.currentId - fun setVolume(value: Int) { audioManager.setStreamVolume( AudioManager.STREAM_MUSIC, @@ -590,7 +601,7 @@ fun VideoPlayerLandscape(videoPlayerViewModel: VideoPlayerViewModel) { colors = CardDefaults.cardColors(containerColor = colorScheme.surface.copy(0.75f)) ) { - LazyColumn(contentPadding = PaddingValues(vertical = 4.dp)) { + LazyColumn(state = listState, contentPadding = PaddingValues(vertical = 4.dp)) { items(videoPlayerViewModel.videos) { item -> MiniPlaylistCard(Modifier.padding(4.dp), video = item, imageLoader = videoPlayerViewModel.imageLoader!!, selected = id == item.id, apiClient = videoPlayerViewModel.apiClient) diff --git a/app/src/main/java/com/acitelight/aether/view/components/VideoPlayerPortal.kt b/app/src/main/java/com/acitelight/aether/view/components/VideoPlayerPortal.kt index 5300c4f..a43a205 100644 --- a/app/src/main/java/com/acitelight/aether/view/components/VideoPlayerPortal.kt +++ b/app/src/main/java/com/acitelight/aether/view/components/VideoPlayerPortal.kt @@ -260,7 +260,7 @@ fun VideoPlayerPortal( playList.add("${i.klass}/${i.id}") } - val route = "video_player_route/${playList.joinToString(",").toHex()}" + val route = "video_player_route/${(playList.joinToString(",") + "|${i.id}").toHex()}" navController.navigate(route) } HorizontalDivider(