Simplify queries to move song in playlist
This commit is contained in:
@@ -132,17 +132,8 @@ fun InPlaylistMediaItemMenu(
|
||||
onDismiss = onDismiss,
|
||||
onRemoveFromPlaylist = {
|
||||
transaction {
|
||||
Database.delete(
|
||||
SongPlaylistMap(
|
||||
songId = song.id,
|
||||
playlistId = playlistId,
|
||||
position = positionInPlaylist
|
||||
)
|
||||
)
|
||||
Database.decrementSongPositions(
|
||||
playlistId = playlistId,
|
||||
fromPosition = positionInPlaylist + 1
|
||||
)
|
||||
Database.move(playlistId, positionInPlaylist, Int.MAX_VALUE)
|
||||
Database.delete(SongPlaylistMap(song.id, playlistId, Int.MAX_VALUE))
|
||||
}
|
||||
},
|
||||
modifier = modifier
|
||||
|
||||
@@ -92,28 +92,8 @@ fun LocalPlaylistScreen(playlistId: Long) {
|
||||
lazyListState = lazyListState,
|
||||
key = playlistWithSongs.songs,
|
||||
onDragEnd = { fromIndex, toIndex ->
|
||||
transaction {
|
||||
if (fromIndex > toIndex) {
|
||||
Database.incrementSongPositions(
|
||||
playlistId = playlistWithSongs.playlist.id,
|
||||
fromPosition = toIndex,
|
||||
toPosition = fromIndex - 1
|
||||
)
|
||||
} else if (fromIndex < toIndex) {
|
||||
Database.decrementSongPositions(
|
||||
playlistId = playlistWithSongs.playlist.id,
|
||||
fromPosition = fromIndex + 1,
|
||||
toPosition = toIndex
|
||||
)
|
||||
}
|
||||
|
||||
Database.update(
|
||||
SongPlaylistMap(
|
||||
songId = playlistWithSongs.songs[fromIndex].id,
|
||||
playlistId = playlistWithSongs.playlist.id,
|
||||
position = toIndex
|
||||
)
|
||||
)
|
||||
query {
|
||||
Database.move(playlistWithSongs.playlist.id, fromIndex, toIndex)
|
||||
}
|
||||
},
|
||||
extraItemCount = 1
|
||||
|
||||
Reference in New Issue
Block a user