Fix moving a track down in a playlist
Yandex reads both operations of a change against the playlist as it was, so deleting a track and inserting it at the next row's index put it back where it was. A track moving down is now inserted after the row it passes. Moving up was already right. The fix is in the shared client, so the TV app gets it too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b7778d95c
commit
a60194c5a7
3 files changed
+5
-3
No files matched your search
@@ -456,7 +456,9 @@ class YmClient private constructor(
|
||||
|
||||
/** Moves the track at `from` so it ends up at `to`. */
|
||||
suspend fun moveInPlaylist(id: PlaylistId, track: Track, from: Int, to: Int) {
|
||||
val add = insert(to, track)
|
||||
// Yandex reads both operations against the playlist as it was, so a track moving down
|
||||
// is inserted after the row it passes, not at that row's index.
|
||||
val add = insert(if (to > from) to + 1 else to, track)
|
||||
val (rev, _) = revision(id)
|
||||
change(id, JsonArray(listOf(delete(from, from + 1), add)), rev)
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ private fun TrackMenu(state: AppState, sheet: Sheet.TrackMenu) {
|
||||
slot.up?.let { up ->
|
||||
item { Item(R.drawable.ic_chevron_left, stringResource(R.string.menu_move_up)) { state.movePlaylistTrack(slot.id, track, slot.index, up) } }
|
||||
}
|
||||
// Delete-then-insert: the row below shifts up one, so inserting at its old index lands after it.
|
||||
// The track ends up where the row below is now; the client works out Yandex's indices.
|
||||
slot.down?.let { down ->
|
||||
item { Item(R.drawable.ic_chevron_right, stringResource(R.string.menu_move_down)) { state.movePlaylistTrack(slot.id, track, slot.index, down) } }
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ private fun TrackMenu(state: AppState, sheet: Sheet.TrackMenu) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Delete-then-insert: the row below shifts up one, so inserting at its old index lands after it.
|
||||
// The track ends up where the row below is now; the client works out Yandex's indices.
|
||||
slot.down?.let { down ->
|
||||
item {
|
||||
Item(R.drawable.ic_chevron_right, stringResource(R.string.menu_move_down)) {
|
||||
|
||||
Reference in new issue
Block a user