Commit 0f9f63e9 authored by Felix Paul Kühne's avatar Felix Paul Kühne
Browse files

generalize thumbnail clustering code to also use it with TV shows

parent f3dd4f66
......@@ -166,8 +166,7 @@
[self _configureForShow:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
MLFile *anyFileFromAnyEpisode = [mediaObject.episodes.anyObject files].anyObject;
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromAnyEpisode];
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject];
}
} else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject;
......
......@@ -125,8 +125,7 @@
[self _configureForShow:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
MLFile *anyFileFromAnyEpisode = [mediaObject.episodes.anyObject files].anyObject;
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromAnyEpisode];
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject];
}
} else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject;
......
......@@ -19,6 +19,7 @@
+ (UIImage *)thumbnailForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname;
+ (UIImage *)thumbnailForShow:(MLShow *)mediaShow;
+ (UIImage *)thumbnailForLabel:(MLLabel *)mediaLabel;
@end
......@@ -102,6 +102,28 @@ static NSCache *_thumbnailCache;
return displayedImage;
}
+ (UIImage *)thumbnailForShow:(MLShow *)mediaShow
{
NSManagedObjectID *objID = mediaShow.objectID;
UIImage *displayedImage = [_thumbnailCache objectForKey:objID];
if (displayedImage)
return displayedImage;
NSUInteger count = [mediaShow.episodes count];
NSUInteger fileNumber = count > 3 ? 3 : count;
NSArray *episodes = [mediaShow.episodes allObjects];
NSMutableArray *files = [[NSMutableArray alloc] init];
for (NSUInteger x = 0; x < count; x++)
[files addObject:[episodes[x] files].anyObject];
displayedImage = [self clusterThumbFromFiles:files andNumber:fileNumber];
if (displayedImage)
[_thumbnailCache setObject:displayedImage forKey:objID];
return displayedImage;
}
+ (UIImage *)thumbnailForLabel:(MLLabel *)mediaLabel
{
NSManagedObjectID *objID = mediaLabel.objectID;
......@@ -110,9 +132,19 @@ static NSCache *_thumbnailCache;
if (displayedImage)
return displayedImage;
NSUInteger fileNumber = [mediaLabel.files count] > 3 ? 3 : [mediaLabel.files count];
NSUInteger count = [mediaLabel.files count];
NSUInteger fileNumber = count > 3 ? 3 : count;
NSArray *files = [mediaLabel.files allObjects];
displayedImage = [self clusterThumbFromFiles:files andNumber:fileNumber];
if (displayedImage)
[_thumbnailCache setObject:displayedImage forKey:objID];
return displayedImage;
}
+ (UIImage *)clusterThumbFromFiles:(NSArray *)files andNumber:(NSUInteger)fileNumber
{
UIImage *clusterThumb;
CGSize imageSize;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if ([UIScreen mainScreen].scale==2.0)
......@@ -133,7 +165,7 @@ static NSCache *_thumbnailCache;
UIGraphicsBeginImageContext(imageSize);
for (NSUInteger i = 0; i < fileNumber; i++) {
MLFile *file = [files objectAtIndex:i];
displayedImage = [VLCThumbnailsCache thumbnailForMediaFile:file];
clusterThumb = [VLCThumbnailsCache thumbnailForMediaFile:file];
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat imagePartWidth = (imageSize.width / fileNumber);
//the rect in which the image should be drawn
......@@ -144,16 +176,14 @@ static NSCache *_thumbnailCache;
CGFloat centerOffset = (imagePartWidth * i + imagePartWidth / 2) - imageSize.width / 2;
//shift the rect to draw the middle of the image in the clippingrect
CGRect drawingRect = CGRectMake(centerOffset, 0, imageSize.width, imageSize.height);
[displayedImage drawInRect:drawingRect];
[clusterThumb drawInRect:drawingRect];
//get rid of the old clippingRect
CGContextRestoreGState(context);
}
displayedImage = UIGraphicsGetImageFromCurrentImageContext();
clusterThumb = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[_thumbnailCache setObject:displayedImage forKey:objID];
return displayedImage;
return clusterThumb;
}
@end
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