Commit 2c93d52b authored by Felix Paul Kühne's avatar Felix Paul Kühne

MLAlbumTrack: add API to allow album track (and in turn album) creation...

MLAlbumTrack: add API to allow album track (and in turn album) creation without knowledge about the track number
parent aecf5633
...@@ -29,8 +29,22 @@ ...@@ -29,8 +29,22 @@
+ (NSArray *)allTracks; + (NSArray *)allTracks;
+ (MLAlbumTrack *)trackWithAlbum:(id)album trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded; + (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated; trackNumber:(NSNumber *)trackNumber
createIfNeeded:(BOOL)createIfNeeded;
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album
trackNumber:(NSNumber *)trackNumber
trackName:(NSString *)trackName
createIfNeeded:(BOOL)createIfNeeded;
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName
trackNumber:(NSNumber *)trackNumber
createIfNeeded:(BOOL)createIfNeeded
wasCreated:(BOOL *)wasCreated;
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName
trackNumber:(NSNumber *)trackNumber
trackName:(NSString *)trackName
createIfNeeded:(BOOL)createIfNeeded
wasCreated:(BOOL *)wasCreated;
@property (nonatomic, strong) NSNumber *unread; @property (nonatomic, strong) NSNumber *unread;
@property (nonatomic, strong) NSString *artist; @property (nonatomic, strong) NSString *artist;
......
...@@ -11,6 +11,9 @@ Added Public APIs: ...@@ -11,6 +11,9 @@ Added Public APIs:
- new selector: setComputedThumbnailScaledForDevice - new selector: setComputedThumbnailScaledForDevice
- MLAlbum: - MLAlbum:
- new selector: addAlbumTrack - new selector: addAlbumTrack
- MLAlbumTrack:
- new selectors: trackWithAlbum:trackNumber:trackName:createIfNeeded:
trackWithAlbumName:trackNumber:trackName:createIfNeeded:wasCreated:
Version 2.5 Version 2.5
----------- -----------
......
...@@ -52,27 +52,52 @@ ...@@ -52,27 +52,52 @@
return tracks; return tracks;
} }
+ (MLAlbumTrack *)trackWithAlbum:(id)album trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded + (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded
{ {
NSMutableSet *tracks = [album mutableSetValueForKey:@"tracks"]; return [MLAlbumTrack trackWithAlbum:album
trackNumber:trackNumber
trackName:@""
createIfNeeded:createIfNeeded];
}
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album trackNumber:(NSNumber *)trackNumber trackName:(NSString *)trackName createIfNeeded:(BOOL)createIfNeeded
{
if (!album)
return nil;
NSSet *tracks = [album tracks];
MLAlbumTrack *track = nil; MLAlbumTrack *track = nil;
if (trackNumber) { if (trackNumber) {
for (MLAlbumTrack *trackIter in tracks) { for (MLAlbumTrack *trackIter in tracks) {
if ([trackIter.trackNumber intValue] == [trackNumber intValue]) { if ([trackIter.trackNumber intValue] == [trackNumber intValue]) {
track = trackIter; track = trackIter;
break; break;
} else if ([trackIter.title isEqualToString:trackName]) {
track = trackIter;
break;
} }
} }
} }
if (!track && createIfNeeded) { if (!track && createIfNeeded) {
track = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"AlbumTrack"]; track = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"AlbumTrack"];
if (trackNumber.integerValue == 0)
trackNumber = @(tracks.count + 1);
track.trackNumber = trackNumber; track.trackNumber = trackNumber;
[tracks addObject:track]; [album addTrack:track];
} }
return track; return track;
} }
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated + (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated
{
return [MLAlbumTrack trackWithAlbumName:albumName
trackNumber:trackNumber
trackName:@""
createIfNeeded:createIfNeeded
wasCreated:wasCreated];
}
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber trackName:(NSString *)trackName createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated
{ {
MLAlbum *album = [MLAlbum albumWithName:albumName]; MLAlbum *album = [MLAlbum albumWithName:albumName];
*wasCreated = NO; *wasCreated = NO;
...@@ -83,7 +108,7 @@ ...@@ -83,7 +108,7 @@
} else if (!album && !createIfNeeded) } else if (!album && !createIfNeeded)
return nil; return nil;
return [MLAlbumTrack trackWithAlbum:album trackNumber:trackNumber createIfNeeded:createIfNeeded]; return [MLAlbumTrack trackWithAlbum:album trackNumber:trackNumber trackName:trackName createIfNeeded:createIfNeeded];
} }
@dynamic primitiveUnread; @dynamic primitiveUnread;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment