[Shuffle Function] Greatly optimize list generator
The list generator now selects only a list of unique album names, which may include empty string as well as NSNull, so filter those as well. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
9820571a94
commit
cad6ddac02
|
@ -1182,29 +1182,30 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
|
||||||
- (NSArray *)shuffleAlbums {
|
- (NSArray *)shuffleAlbums {
|
||||||
NSArray *newList = [self arrangedObjects];
|
NSArray *newList = [self arrangedObjects];
|
||||||
NSMutableArray *temp = [[NSMutableArray alloc] init];
|
NSMutableArray *temp = [[NSMutableArray alloc] init];
|
||||||
NSMutableArray *albums = [[NSMutableArray alloc] init];
|
NSSortDescriptor *sortDescriptorTrack = [[NSSortDescriptor alloc] initWithKey:@"track"
|
||||||
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"track"
|
ascending:YES];
|
||||||
ascending:YES];
|
NSSortDescriptor *sortDescriptorDisc = [[NSSortDescriptor alloc] initWithKey:@"disc"
|
||||||
for(unsigned long i = 0, j = [newList count]; i < j; ++i) {
|
ascending:YES];
|
||||||
PlaylistEntry *pe = newList[i];
|
NSArray *albums = [newList valueForKey:@"album"];
|
||||||
NSString *album = [pe album];
|
albums = [[NSSet setWithArray:albums] allObjects];
|
||||||
if(!album) album = @"";
|
NSArray *tempList = [Shuffle shuffleList:albums];
|
||||||
if([albums containsObject:album]) continue;
|
|
||||||
[albums addObject:album];
|
|
||||||
NSArray *albumContent = [self filterPlaylistOnAlbum:album];
|
|
||||||
NSArray *sortedContent =
|
|
||||||
[albumContent sortedArrayUsingDescriptors:@[sortDescriptor]];
|
|
||||||
if(sortedContent && [sortedContent count])
|
|
||||||
[temp addObject:sortedContent[0]];
|
|
||||||
}
|
|
||||||
NSArray *tempList = [Shuffle shuffleList:temp];
|
|
||||||
temp = [[NSMutableArray alloc] init];
|
temp = [[NSMutableArray alloc] init];
|
||||||
for(unsigned long i = 0, j = [tempList count]; i < j; ++i) {
|
BOOL blankAdded = NO;
|
||||||
PlaylistEntry *pe = tempList[i];
|
for(NSString *album in tempList) {
|
||||||
NSString *album = [pe album];
|
NSString *theAlbum = album;
|
||||||
NSArray *albumContent = [self filterPlaylistOnAlbum:album];
|
if((id)album == [NSNull null]) {
|
||||||
|
if(blankAdded)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
theAlbum = @"";
|
||||||
|
blankAdded = YES;
|
||||||
|
} else if([album isEqualToString:@""]) {
|
||||||
|
if(blankAdded) continue;
|
||||||
|
blankAdded = YES;
|
||||||
|
}
|
||||||
|
NSArray *albumContent = [self filterPlaylistOnAlbum:theAlbum];
|
||||||
NSArray *sortedContent =
|
NSArray *sortedContent =
|
||||||
[albumContent sortedArrayUsingDescriptors:@[sortDescriptor]];
|
[albumContent sortedArrayUsingDescriptors:@[sortDescriptorDisc, sortDescriptorTrack]];
|
||||||
if(sortedContent && [sortedContent count])
|
if(sortedContent && [sortedContent count])
|
||||||
[temp addObjectsFromArray:sortedContent];
|
[temp addObjectsFromArray:sortedContent];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue