Skip to content

Commit 0d071d1

Browse files
committed
Reload playlist on error response from Playlist.Remove or Playlist.Insert
This avoids mismatching playlist in Kodi and remote app after attempting to move the playing item from the app.
1 parent 8233948 commit 0d071d1

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

XBMC Remote/NowPlaying.m

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,23 +2196,30 @@ - (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourc
21962196
};
21972197
[[Utilities getJsonRPC] callMethod:actionRemove withParameters:paramsRemove onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) {
21982198
if (error == nil && methodError == nil) {
2199-
[[Utilities getJsonRPC] callMethod:actionInsert withParameters:paramsInsert];
2200-
NSInteger numObj = playlistData.count;
2201-
if (sourceIndexPath.row < numObj) {
2202-
[playlistData removeObjectAtIndex:sourceIndexPath.row];
2203-
}
2204-
if (destinationIndexPath.row <= playlistData.count) {
2205-
[playlistData insertObject:objSource atIndex:destinationIndexPath.row];
2206-
}
2207-
if (sourceIndexPath.row > storeSelection.row && destinationIndexPath.row <= storeSelection.row) {
2208-
storeSelection = [NSIndexPath indexPathForRow:storeSelection.row + 1 inSection:storeSelection.section];
2209-
}
2210-
else if (sourceIndexPath.row < storeSelection.row && destinationIndexPath.row >= storeSelection.row) {
2211-
storeSelection = [NSIndexPath indexPathForRow:storeSelection.row - 1 inSection:storeSelection.section];
2212-
}
2199+
[[Utilities getJsonRPC] callMethod:actionInsert withParameters:paramsInsert onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) {
2200+
if (error == nil && methodError == nil) {
2201+
if (sourceIndexPath.row < playlistData.count) {
2202+
[playlistData removeObjectAtIndex:sourceIndexPath.row];
2203+
}
2204+
if (destinationIndexPath.row <= playlistData.count) {
2205+
[playlistData insertObject:objSource atIndex:destinationIndexPath.row];
2206+
}
2207+
if (sourceIndexPath.row > storeSelection.row && destinationIndexPath.row <= storeSelection.row) {
2208+
storeSelection = [NSIndexPath indexPathForRow:storeSelection.row + 1 inSection:storeSelection.section];
2209+
}
2210+
else if (sourceIndexPath.row < storeSelection.row && destinationIndexPath.row >= storeSelection.row) {
2211+
storeSelection = [NSIndexPath indexPathForRow:storeSelection.row - 1 inSection:storeSelection.section];
2212+
}
2213+
}
2214+
else {
2215+
[Utilities showMessage:LOCALIZED_STR(@"Cannot do that") color:ERROR_MESSAGE_COLOR];
2216+
[self createPlaylistAnimated:YES];
2217+
}
2218+
}];
22132219
}
22142220
else {
22152221
[Utilities showMessage:LOCALIZED_STR(@"Cannot do that") color:ERROR_MESSAGE_COLOR];
2222+
[self createPlaylistAnimated:YES];
22162223
}
22172224
}];
22182225
}

0 commit comments

Comments
 (0)