From 184525a47a9de8b7b6e116d7da9356b5b1fe08c7 Mon Sep 17 00:00:00 2001 From: areff Date: Thu, 21 Feb 2008 19:14:20 +0000 Subject: [PATCH] Implemented Repeat All through NSPredicate and filtering, method should be applicable when Shuffle is fixed too. --- Playlist/PlaylistController.h | 1 + Playlist/PlaylistController.m | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Playlist/PlaylistController.h b/Playlist/PlaylistController.h index 5a9fd4956..260a19e94 100644 --- a/Playlist/PlaylistController.h +++ b/Playlist/PlaylistController.h @@ -50,6 +50,7 @@ typedef enum { - (BOOL)shuffle; - (void)setRepeat:(RepeatMode)r; - (RepeatMode)repeat; +- (NSArray *)filterPlaylistOnAlbum:(NSString *)album; - (PlaylistEntry *)getNextEntry:(PlaylistEntry *)pe; - (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe; diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index b3fdd6c14..878fd0f5a 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -399,10 +399,32 @@ i = [[pe index] intValue] + 1; } + if (repeat == RepeatAlbum) + { + PlaylistEntry *next = [self entryAtIndex:i]; + + if ((i > [[self arrangedObjects] count]-1) || ([[next album] caseInsensitiveCompare:[pe album]]) || ([next album] == nil)) + { + NSArray *filtered = [self filterPlaylistOnAlbum:[pe album]]; + if ([pe album] == nil) + i--; + else + i = [[[filtered objectAtIndex:0] index] intValue]; + } + + } + return [self entryAtIndex:i]; } } +- (NSArray *)filterPlaylistOnAlbum:(NSString *)album +{ + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"album like %@", + album]; + return [[self arrangedObjects] filteredArrayUsingPredicate:predicate]; +} + - (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe { if (repeat == RepeatOne) {