Bug Fix: Adding tracks to playlist while in search
When adding tracks to the playlist, clear the search filter first, so the playlist doesn't become all jumbled, or so we don't overflow the playlist indexes. Also add some bug fixes for reversing the arranged to disarranged index lists, so if an arranged index is past the end of the arranged list, as is the case for appending, we shift the indexes forward past the end of the diarranged object list. Extra exception handling was added as well, so these things will only cause a failure to add playlist items at worst, instead of crashing the player entirely. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
2e884b9e85
commit
1c92c56d75
1 changed files with 21 additions and 7 deletions
|
@ -861,12 +861,16 @@ static void *playlistControllerContext = &playlistControllerContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSIndexSet *)disarrangeIndexes:(NSIndexSet *)indexes {
|
- (NSIndexSet *)disarrangeIndexes:(NSIndexSet *)indexes {
|
||||||
if([[self arrangedObjects] count] <= [indexes lastIndex]) return indexes;
|
|
||||||
|
|
||||||
NSMutableIndexSet *disarrangedIndexes = [[NSMutableIndexSet alloc] init];
|
NSMutableIndexSet *disarrangedIndexes = [[NSMutableIndexSet alloc] init];
|
||||||
|
|
||||||
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *_Nonnull stop) {
|
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *_Nonnull stop) {
|
||||||
[disarrangedIndexes addIndex:[[self content] indexOfObject:[[self arrangedObjects] objectAtIndex:idx]]];
|
NSUInteger arrCount = [[self arrangedObjects] count];
|
||||||
|
NSUInteger disCount = [[self content] count];
|
||||||
|
if(idx >= arrCount) {
|
||||||
|
[disarrangedIndexes addIndex:idx - arrCount + disCount];
|
||||||
|
} else {
|
||||||
|
[disarrangedIndexes addIndex:[[self content] indexOfObject:[[self arrangedObjects] objectAtIndex:idx]]];
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
return disarrangedIndexes;
|
return disarrangedIndexes;
|
||||||
|
@ -895,11 +899,12 @@ static void *playlistControllerContext = &playlistControllerContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes {
|
- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes {
|
||||||
|
[self clearFilterPredicate:self];
|
||||||
[self insertObjects:objects atArrangedObjectIndexes:indexes];
|
[self insertObjects:objects atArrangedObjectIndexes:indexes];
|
||||||
[self rearrangeObjects];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)untrashObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes {
|
- (void)untrashObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes {
|
||||||
|
[self clearFilterPredicate:self];
|
||||||
[self untrashObjects:objects atArrangedObjectIndexes:indexes];
|
[self untrashObjects:objects atArrangedObjectIndexes:indexes];
|
||||||
[self rearrangeObjects];
|
[self rearrangeObjects];
|
||||||
}
|
}
|
||||||
|
@ -919,7 +924,7 @@ static void *playlistControllerContext = &playlistControllerContext;
|
||||||
index = range.location;
|
index = range.location;
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
NSUInteger count = [[self content] count];
|
NSUInteger count = [[self arrangedObjects] count];
|
||||||
if(index > count) {
|
if(index > count) {
|
||||||
// Ah, oops, bodge fix
|
// Ah, oops, bodge fix
|
||||||
__block NSMutableIndexSet *replacementIndexes = [[NSMutableIndexSet alloc] init];
|
__block NSMutableIndexSet *replacementIndexes = [[NSMutableIndexSet alloc] init];
|
||||||
|
@ -944,8 +949,15 @@ static void *playlistControllerContext = &playlistControllerContext;
|
||||||
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
||||||
}
|
}
|
||||||
@catch(id anException) {
|
@catch(id anException) {
|
||||||
indexes = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(count, [objects count])];
|
// Even further bodge fix
|
||||||
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
@try {
|
||||||
|
count = [[self arrangedObjects] count];
|
||||||
|
indexes = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(count, [objects count])];
|
||||||
|
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
||||||
|
}
|
||||||
|
@catch(id anException) {
|
||||||
|
DLog(@"Exception thrown adding tracks to the playlist: %@", anException);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[self commitPersistentStore];
|
[self commitPersistentStore];
|
||||||
|
@ -1836,6 +1848,8 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)insertURLsInBackground:(NSDictionary *)input {
|
- (void)insertURLsInBackground:(NSDictionary *)input {
|
||||||
|
[self performSelectorOnMainThread:@selector(clearFilterPredicate:) withObject:self waitUntilDone:YES];
|
||||||
|
|
||||||
NSArray *entries = [input objectForKey:@"entries"];
|
NSArray *entries = [input objectForKey:@"entries"];
|
||||||
NSUInteger row = [[input objectForKey:@"index"] integerValue];
|
NSUInteger row = [[input objectForKey:@"index"] integerValue];
|
||||||
BOOL sort = [[input objectForKey:@"sort"] boolValue];
|
BOOL sort = [[input objectForKey:@"sort"] boolValue];
|
||||||
|
|
Loading…
Reference in a new issue