From a60194c5a724432399b57acbb573c180f3889282 Mon Sep 17 00:00:00 2001 From: Yuriy Panov Date: Fri, 23 Oct 2026 16:27:59 +0600 Subject: [PATCH] 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 --- core/src/main/java/it/panov/musyx/api/YmClient.kt | 4 +++- .../src/main/java/it/panov/musyx/mobile/ui/screens/Sheets.kt | 2 +- tv/src/main/java/it/panov/musyx/tv/ui/screens/Sheets.kt | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/it/panov/musyx/api/YmClient.kt b/core/src/main/java/it/panov/musyx/api/YmClient.kt index fc2540e..c952c0c 100644 --- a/core/src/main/java/it/panov/musyx/api/YmClient.kt +++ b/core/src/main/java/it/panov/musyx/api/YmClient.kt @@ -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) } diff --git a/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Sheets.kt b/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Sheets.kt index 5b26a0a..f6d30d7 100644 --- a/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Sheets.kt +++ b/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Sheets.kt @@ -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) } } } diff --git a/tv/src/main/java/it/panov/musyx/tv/ui/screens/Sheets.kt b/tv/src/main/java/it/panov/musyx/tv/ui/screens/Sheets.kt index 3cd5aea..380a474 100644 --- a/tv/src/main/java/it/panov/musyx/tv/ui/screens/Sheets.kt +++ b/tv/src/main/java/it/panov/musyx/tv/ui/screens/Sheets.kt @@ -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)) {