[Shuffle] Fix Shuffle Album mode

Oops, I should have remembered that the data structure changes would
break this search predicate. Now apply the search predicate to the
playlist representation, which allows searching against the data blocks
using the PlaylistEntry property implementation.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
xcode15
Christopher Snowhill 2022-07-11 18:54:06 -07:00
parent a217bbec1e
commit 25b90f300f
1 changed files with 4 additions and 18 deletions

View File

@ -1221,27 +1221,13 @@ static void *playlistControllerContext = &playlistControllerContext;
} }
- (NSArray *)filterPlaylistOnAlbum:(NSString *)album { - (NSArray *)filterPlaylistOnAlbum:(NSString *)album {
NSPredicate *hasUrlPredicate = [NSPredicate predicateWithFormat:@"urlString != nil && urlString != %@", @""]; NSPredicate *predicate;
NSPredicate *deletedPredicate = [NSPredicate predicateWithFormat:@"deLeted == NO || deLeted == nil"];
NSPredicate *searchPredicate;
if([album length] > 0) if([album length] > 0)
searchPredicate = [NSPredicate predicateWithFormat:@"album == %@", album]; predicate = [NSPredicate predicateWithFormat:@"album == %@", album];
else else
searchPredicate = [NSPredicate predicateWithFormat:@"album == nil || album == %@", @""]; predicate = [NSPredicate predicateWithFormat:@"album == nil || album == %@", @""];
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[deletedPredicate, hasUrlPredicate, searchPredicate]]; return [[self arrangedObjects] filteredArrayUsingPredicate:predicate];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"index" ascending:YES];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
request.predicate = predicate;
request.sortDescriptors = @[sortDescriptor];
NSError *error = nil;
NSArray *results = [self.persistentContainer.viewContext executeFetchRequest:request error:&error];
return results;
} }
- (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe { - (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe {