From 7f77b6c3337648c8523ea501d0848a1fa83227f2 Mon Sep 17 00:00:00 2001 From: Malopieds Date: Mon, 1 Apr 2024 19:36:03 +0200 Subject: [PATCH] fix(history_screen): fix #35 --- .../music/ui/screens/HistoryScreen.kt | 78 ++++++++++--------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/zionhuang/music/ui/screens/HistoryScreen.kt b/app/src/main/java/com/zionhuang/music/ui/screens/HistoryScreen.kt index 5d92e2385..b5295b9e1 100644 --- a/app/src/main/java/com/zionhuang/music/ui/screens/HistoryScreen.kt +++ b/app/src/main/java/com/zionhuang/music/ui/screens/HistoryScreen.kt @@ -28,6 +28,7 @@ import com.zionhuang.innertube.models.WatchEndpoint import com.zionhuang.music.LocalPlayerAwareWindowInsets import com.zionhuang.music.LocalPlayerConnection import com.zionhuang.music.R +import com.zionhuang.music.db.entities.EventWithSong import com.zionhuang.music.extensions.togglePlayPause import com.zionhuang.music.models.toMediaMetadata import com.zionhuang.music.playback.queues.YouTubeQueue @@ -74,50 +75,55 @@ fun HistoryScreen( ) } + var prev: EventWithSong? = null items( items = events, key = { it.event.id } ) { event -> - SongListItem( - song = event.song, - isActive = event.song.id == mediaMetadata?.id, - isPlaying = isPlaying, - showInLibraryIcon = true, - trailingContent = { - IconButton( - onClick = { - menuState.show { - SongMenu( - originalSong = event.song, - event = event.event, - navController = navController, - onDismiss = menuState::dismiss - ) + if (prev == null || prev!!.song.song.id != event.song.song.id) { + SongListItem( + song = event.song, + isActive = event.song.id == mediaMetadata?.id, + isPlaying = isPlaying, + showInLibraryIcon = true, + trailingContent = { + IconButton( + onClick = { + menuState.show { + SongMenu( + originalSong = event.song, + event = event.event, + navController = navController, + onDismiss = menuState::dismiss + ) + } } + ) { + Icon( + painter = painterResource(R.drawable.more_vert), + contentDescription = null + ) } - ) { - Icon( - painter = painterResource(R.drawable.more_vert), - contentDescription = null - ) - } - }, - modifier = Modifier - .fillMaxWidth() - .combinedClickable { - if (event.song.id == mediaMetadata?.id) { - playerConnection.player.togglePlayPause() - } else { - playerConnection.playQueue( - YouTubeQueue( - endpoint = WatchEndpoint(videoId = event.song.id), - preloadItem = event.song.toMediaMetadata() + }, + modifier = Modifier + .fillMaxWidth() + .combinedClickable { + if (event.song.id == mediaMetadata?.id) { + playerConnection.player.togglePlayPause() + } else { + playerConnection.playQueue( + YouTubeQueue( + endpoint = WatchEndpoint(videoId = event.song.id), + preloadItem = event.song.toMediaMetadata() + ) ) - ) + } } - } - .animateItemPlacement() - ) + .animateItemPlacement() + + ) + } + prev = event } } }