Commit 502bc963 authored by Carola Nitz's avatar Carola Nitz Committed by Felix Paul Kühne

adjusted the ThumbnailCache to handle different filetypes itself to remove...

adjusted the ThumbnailCache to handle different filetypes itself to remove complexity from other controllers
parent 06c877d0
......@@ -114,20 +114,7 @@
if (psc) {
NSManagedObject *mo = [moc existingObjectWithID:[psc managedObjectIDForURIRepresentation:[NSURL URLWithString:filePath]] error:nil];
NSData *theData;
if ([mo isKindOfClass:[MLFile class]])
theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForMediaFile:(MLFile *)mo]);
else if ([mo isKindOfClass:[MLShow class]])
theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForShow:(MLShow *)mo]);
else if ([mo isKindOfClass:[MLLabel class]])
theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForLabel:(MLLabel *)mo]);
else if ([mo isKindOfClass:[MLAlbum class]])
theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForMediaFile:[[(MLAlbum *)mo tracks].anyObject files].anyObject]);
else if ([mo isKindOfClass:[MLAlbumTrack class]])
theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForMediaFile:[(MLAlbumTrack *)mo files].anyObject]);
else if ([mo isKindOfClass:[MLShowEpisode class]])
theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForMediaFile:[(MLShowEpisode *)mo files].anyObject]);
NSData *theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo]);
if (theData) {
HTTPDataResponse *dataResponse = [[HTTPDataResponse alloc] initWithData:theData];
dataResponse.contentType = @"image/png";
......
......@@ -2231,7 +2231,7 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle(MPRemoteCommandCente
mediaIsAudioOnly = [item isSupportedAudioFile];
if (mediaIsAudioOnly)
self.artworkImageView.image = [VLCThumbnailsCache thumbnailForMediaFile:item];
self.artworkImageView.image = [VLCThumbnailsCache thumbnailForManagedObject:item];
} else {
NSDictionary * metaDict = _mediaPlayer.media.metaDictionary;
......
......@@ -174,52 +174,27 @@
{
self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
if ([self.mediaObject isKindOfClass:[MLFile class]]) {
MLFile *mediaObject = self.mediaObject;
[self _configureForMLFile:mediaObject];
if (([keyPath isEqualToString:@"computedThumbnail"] || !keyPath) || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:mediaObject];
[self _configureForMLFile:self.mediaObject];
} else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
MLLabel *mediaObject = (MLLabel *)self.mediaObject;
[self _configureForFolder:mediaObject];
if ([keyPath isEqualToString:@"files"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
if (mediaObject.files.count != 0)
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForLabel:mediaObject];
}
[self _configureForFolder:(MLLabel *)self.mediaObject];
} else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
MLAlbum *mediaObject = (MLAlbum *)self.mediaObject;
[self _configureForAlbum:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
MLFile *anyFileFromAnyTrack = [mediaObject.tracks.anyObject files].anyObject;
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromAnyTrack];
}
[self _configureForAlbum:(MLAlbum *)self.mediaObject];
} else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
MLAlbumTrack *mediaObject = (MLAlbumTrack *)self.mediaObject;
[self _configureForAlbumTrack:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || !self.thumbnailView.image) {
MLFile *anyFileFromTrack = mediaObject.files.anyObject;
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromTrack];
}
[self _configureForAlbumTrack:(MLAlbumTrack *)self.mediaObject];
} else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
MLShow *mediaObject = (MLShow *)self.mediaObject;
[self _configureForShow:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject];
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:mediaObject];
}
} else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject;
[self _configureForShowEpisode:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || !self.thumbnailView.image) {
MLFile *anyFileFromEpisode = mediaObject.files.anyObject;
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromEpisode];
}
[self _configureForShowEpisode:(MLShowEpisode *)self.mediaObject];
}
if (![self.mediaObject isKindOfClass:[MLShow class]] && ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))) {
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
}
[self setNeedsDisplay];
}
......
......@@ -157,54 +157,28 @@
- (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
{
self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
if ([self.mediaObject isKindOfClass:[MLFile class]]) {
MLFile *mediaObject = (MLFile*)self.mediaObject;
[self _configureForMLFile:mediaObject];
if (([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])))
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:mediaObject];
[self _configureForMLFile:(MLFile *)self.mediaObject];
} else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
MLLabel *mediaObject = (MLLabel *)self.mediaObject;
[self _configureForFolder:mediaObject];
if ([keyPath isEqualToString:@"files"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
if (mediaObject.files.count != 0)
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForLabel:mediaObject];
}
[self _configureForFolder:(MLLabel *)self.mediaObject];
} else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
MLAlbum *mediaObject = (MLAlbum *)self.mediaObject;
[self _configureForAlbum:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
MLFile *anyFileFromAnyTrack = [mediaObject.tracks.anyObject files].anyObject;
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromAnyTrack];
}
[self _configureForAlbum:(MLAlbum *)self.mediaObject];
} else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
MLAlbumTrack *mediaObject = (MLAlbumTrack *)self.mediaObject;
[self _configureForAlbumTrack:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || !self.thumbnailView.image) {
MLFile *anyFileFromTrack = mediaObject.files.anyObject;
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromTrack];
}
[self _configureForAlbumTrack:(MLAlbumTrack *)self.mediaObject];
} else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
MLShow *mediaObject = (MLShow *)self.mediaObject;
[self _configureForShow:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || !self.thumbnailView.image) {
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:mediaObject];
}
} else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject;
[self _configureForShowEpisode:mediaObject];
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || !self.thumbnailView.image) {
MLFile *anyFileFromEpisode = mediaObject.files.anyObject;
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromEpisode];
}
[self _configureForShowEpisode:(MLShowEpisode *)self.mediaObject];
}
if (![self.mediaObject isKindOfClass:[MLShow class]] && ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))) {
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
}
[self setNeedsDisplay];
}
......
......@@ -7,19 +7,15 @@
*
* Authors: Gleb Pinigin <gpinigin # gmail.com>
* Felix Paul Kühne <fkuehne # videolan.org>
* Carola Nitz <caro # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <Foundation/Foundation.h>
@interface VLCThumbnailsCache : NSObject
+ (UIImage *)thumbnailForMediaFile:(MLFile *)mediaFile;
+ (UIImage *)thumbnailForManagedObject:(NSManagedObject *)object;
+ (UIImage *)thumbnailForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname;
+ (UIImage *)thumbnailForShow:(MLShow *)mediaShow;
+ (UIImage *)thumbnailForLabel:(MLLabel *)mediaLabel;
@end
......@@ -7,6 +7,7 @@
*
* Authors: Gleb Pinigin <gpinigin # gmail.com>
* Felix Paul Kühne <fkuehne # videolan.org>
* Carola Nitz <caro # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
......@@ -52,7 +53,7 @@ static NSInteger _currentDeviceIdiom;
[_thumbnailCacheMetadata setCountLimit: MaxCacheSize];
}
+ (NSString *)_md5FromString:(NSString *)string
- (NSString *)_md5FromString:(NSString *)string
{
const char *ptr = [string UTF8String];
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
......@@ -66,10 +67,10 @@ static NSInteger _currentDeviceIdiom;
+ (UIImage *)thumbnailForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname
{
return [UIImage imageWithContentsOfFile:[self artworkPathForMediaItemWithTitle:title Artist:artist andAlbumName:albumname]];
return [UIImage imageWithContentsOfFile:[[VLCThumbnailsCache new] artworkPathForMediaItemWithTitle:title Artist:artist andAlbumName:albumname]];
}
+ (NSString *)artworkPathForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname
- (NSString *)artworkPathForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname
{
NSString *artworkURL;
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
......@@ -87,7 +88,7 @@ static NSInteger _currentDeviceIdiom;
return artworkURL;
}
+ (NSString *)_getArtworkPathFromMedia:(MLFile *)file
- (NSString *)_getArtworkPathFromMedia:(MLFile *)file
{
NSString *artist, *album, *title;
......@@ -100,7 +101,30 @@ static NSInteger _currentDeviceIdiom;
return [self artworkPathForMediaItemWithTitle:title Artist:artist andAlbumName:album];
}
+ (UIImage *)thumbnailForMediaFile:(MLFile *)mediaFile
+ (UIImage *)thumbnailForManagedObject:(NSManagedObject *)object
{
UIImage *thumbnail;
VLCThumbnailsCache *cache = [VLCThumbnailsCache new];
if ([object isKindOfClass:[MLShow class]]) {
thumbnail = [cache thumbnailForShow:(MLShow *)object];
} else if ([object isKindOfClass:[MLShowEpisode class]]) {
MLFile *anyFileFromEpisode = [(MLShowEpisode *)object files].anyObject;
thumbnail = [cache thumbnailForMediaFile:anyFileFromEpisode];
} else if ([object isKindOfClass:[MLLabel class]]) {
thumbnail = [cache thumbnailForLabel:(MLLabel *)object];
} else if ([object isKindOfClass:[MLAlbum class]]) {
MLFile *anyFileFromAnyTrack = [[(MLAlbum *)object tracks].anyObject files].anyObject;
thumbnail = [cache thumbnailForMediaFile:anyFileFromAnyTrack];
} else if ([object isKindOfClass:[MLAlbumTrack class]]) {
MLFile *anyFileFromTrack = [(MLAlbumTrack *)object files].anyObject;
thumbnail = [cache thumbnailForMediaFile:anyFileFromTrack];
} else {
thumbnail = [cache thumbnailForMediaFile:(MLFile *)object];
}
return thumbnail;
}
- (UIImage *)thumbnailForMediaFile:(MLFile *)mediaFile
{
if (mediaFile == nil || mediaFile.objectID == nil)
return nil;
......@@ -123,7 +147,7 @@ static NSInteger _currentDeviceIdiom;
return displayedImage;
}
+ (UIImage *)thumbnailForShow:(MLShow *)mediaShow
- (UIImage *)thumbnailForShow:(MLShow *)mediaShow
{
NSManagedObjectID *objID = mediaShow.objectID;
UIImage *displayedImage;
......@@ -160,7 +184,7 @@ static NSInteger _currentDeviceIdiom;
return displayedImage;
}
+ (UIImage *)thumbnailForLabel:(MLLabel *)mediaLabel
- (UIImage *)thumbnailForLabel:(MLLabel *)mediaLabel
{
NSManagedObjectID *objID = mediaLabel.objectID;
UIImage *displayedImage;
......@@ -192,7 +216,7 @@ static NSInteger _currentDeviceIdiom;
return displayedImage;
}
+ (UIImage *)clusterThumbFromFiles:(NSArray *)files andNumber:(NSUInteger)fileNumber blur:(BOOL)blurImage
- (UIImage *)clusterThumbFromFiles:(NSArray *)files andNumber:(NSUInteger)fileNumber blur:(BOOL)blurImage
{
UIImage *clusterThumb;
CGSize imageSize;
......@@ -221,7 +245,7 @@ static NSInteger _currentDeviceIdiom;
NSUInteger iter = files.count < fileNumber ? files.count : fileNumber;
for (NSUInteger i = 0; i < iter; i++) {
MLFile *file = [files objectAtIndex:i];
clusterThumb = [VLCThumbnailsCache thumbnailForMediaFile:file];
clusterThumb = [self thumbnailForMediaFile:file];
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat imagePartWidth = (imageSize.width / iter);
//the rect in which the image should be drawn
......
......@@ -159,29 +159,20 @@ typedef enum {
- (void)configureTableRowController:(id)rowController withObject:(id)storageObject {
VLCRowController *row = rowController;
UIImage *backgroundImage;
UIImage *backgroundImage = [VLCThumbnailsCache thumbnailForManagedObject:storageObject];
if ([storageObject isKindOfClass:[MLShow class]]) {
backgroundImage = [VLCThumbnailsCache thumbnailForShow:storageObject];
row.titleLabel.text = ((MLAlbum *)storageObject).name;
} else if ([storageObject isKindOfClass:[MLShowEpisode class]]) {
MLFile *anyFileFromEpisode = [(MLShowEpisode *)storageObject files].anyObject;
backgroundImage = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromEpisode];
row.titleLabel.text = ((MLShowEpisode *)storageObject).name;
} else if ([storageObject isKindOfClass:[MLLabel class]]) {
backgroundImage = [VLCThumbnailsCache thumbnailForLabel:storageObject];
row.titleLabel.text = ((MLLabel *)storageObject).name;
} else if ([storageObject isKindOfClass:[MLAlbum class]]) {
MLFile *anyFileFromAnyTrack = [[(MLAlbum *)storageObject tracks].anyObject files].anyObject;
backgroundImage = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromAnyTrack];
row.titleLabel.text = ((MLAlbum *)storageObject).name;
} else if ([storageObject isKindOfClass:[MLAlbumTrack class]]) {
MLFile *anyFileFromTrack = [(MLAlbumTrack *)storageObject files].anyObject;
backgroundImage = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromTrack];
row.titleLabel.text = ((MLAlbumTrack *)storageObject).title;
} else {
row.titleLabel.text = [(MLFile *)storageObject title];
backgroundImage = [VLCThumbnailsCache thumbnailForMediaFile:(MLFile *)storageObject];
}
/* FIXME: add placeholder image once designed
......
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