From 25b90f300f8ef10d6c55bb6dc4f53b0e69e317d1 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 11 Jul 2022 18:54:06 -0700 Subject: [PATCH] [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 --- Playlist/PlaylistController.m | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index a883aa518..bb6fa0b8a 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -1221,27 +1221,13 @@ static void *playlistControllerContext = &playlistControllerContext; } - (NSArray *)filterPlaylistOnAlbum:(NSString *)album { - NSPredicate *hasUrlPredicate = [NSPredicate predicateWithFormat:@"urlString != nil && urlString != %@", @""]; - NSPredicate *deletedPredicate = [NSPredicate predicateWithFormat:@"deLeted == NO || deLeted == nil"]; - - NSPredicate *searchPredicate; + NSPredicate *predicate; if([album length] > 0) - searchPredicate = [NSPredicate predicateWithFormat:@"album == %@", album]; + predicate = [NSPredicate predicateWithFormat:@"album == %@", album]; else - searchPredicate = [NSPredicate predicateWithFormat:@"album == nil || album == %@", @""]; + predicate = [NSPredicate predicateWithFormat:@"album == nil || album == %@", @""]; - NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[deletedPredicate, hasUrlPredicate, searchPredicate]]; - - 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; + return [[self arrangedObjects] filteredArrayUsingPredicate:predicate]; } - (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe {