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)) {