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 @@
+ (NSArray *)allTracks;
+ (MLAlbumTrack *)trackWithAlbum:(id)album trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded;
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated;
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album
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) NSString *artist;
......
......@@ -11,6 +11,9 @@ Added Public APIs:
- new selector: setComputedThumbnailScaledForDevice
- MLAlbum:
- new selector: addAlbumTrack
- MLAlbumTrack:
- new selectors: trackWithAlbum:trackNumber:trackName:createIfNeeded:
trackWithAlbumName:trackNumber:trackName:createIfNeeded:wasCreated:
Version 2.5
-----------
......
......@@ -52,27 +52,52 @@
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;
if (trackNumber) {
for (MLAlbumTrack *trackIter in tracks) {
if ([trackIter.trackNumber intValue] == [trackNumber intValue]) {
track = trackIter;
break;
} else if ([trackIter.title isEqualToString:trackName]) {
track = trackIter;
break;
}
}
}
if (!track && createIfNeeded) {
track = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"AlbumTrack"];
if (trackNumber.integerValue == 0)
trackNumber = @(tracks.count + 1);
track.trackNumber = trackNumber;
[tracks addObject:track];
[album addTrack:track];
}
return track;
}
+ (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];
*wasCreated = NO;
......@@ -83,7 +108,7 @@
} else if (!album && !createIfNeeded)
return nil;
return [MLAlbumTrack trackWithAlbum:album trackNumber:trackNumber createIfNeeded:createIfNeeded];
return [MLAlbumTrack trackWithAlbum:album trackNumber:trackNumber trackName:trackName createIfNeeded:createIfNeeded];
}
@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