Skip to content

Commit

Permalink
fix(history_screen): fix #35
Browse files Browse the repository at this point in the history
  • Loading branch information
Malopieds committed Apr 1, 2024
1 parent d21bb03 commit 7f77b6c
Showing 1 changed file with 42 additions and 36 deletions.
78 changes: 42 additions & 36 deletions app/src/main/java/com/zionhuang/music/ui/screens/HistoryScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 7f77b6c

Please sign in to comment.