Commit 164af11c authored by Felix Paul Kühne's avatar Felix Paul Kühne

Fix folder thumbnail refresh when content is modified

parent 70da4a3b
...@@ -103,6 +103,12 @@ ...@@ -103,6 +103,12 @@
[_mediaObject removeObserver:self forKeyPath:@"genre"]; [_mediaObject removeObserver:self forKeyPath:@"genre"];
if ([_mediaObject respondsToSelector:@selector(didHide)]) if ([_mediaObject respondsToSelector:@selector(didHide)])
[(MLFile*)_mediaObject didHide]; [(MLFile*)_mediaObject didHide];
if ([_mediaObject isKindOfClass:[MLLabel class]]) {
[_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"name"];
}
if ([_mediaObject isKindOfClass:[MLShow class]])
[_mediaObject removeObserver:self forKeyPath:@"episodes"];
_mediaObject = mediaObject; _mediaObject = mediaObject;
...@@ -120,6 +126,12 @@ ...@@ -120,6 +126,12 @@
if ([_mediaObject respondsToSelector:@selector(willDisplay)]) if ([_mediaObject respondsToSelector:@selector(willDisplay)])
[(MLFile*)_mediaObject willDisplay]; [(MLFile*)_mediaObject willDisplay];
if ([_mediaObject isKindOfClass:[MLLabel class]]) {
[_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
}
if ([_mediaObject isKindOfClass:[MLShow class]])
[_mediaObject addObserver:self forKeyPath:@"episodes" options:0 context:nil];
} }
[self _updatedDisplayedInformationForKeyPath:nil]; [self _updatedDisplayedInformationForKeyPath:nil];
...@@ -138,12 +150,15 @@ ...@@ -138,12 +150,15 @@
} else if ([self.mediaObject isKindOfClass:[MLLabel class]]) { } else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
MLLabel *mediaObject = (MLLabel *)self.mediaObject; MLLabel *mediaObject = (MLLabel *)self.mediaObject;
[self _configureForFolder:mediaObject]; [self _configureForFolder:mediaObject];
BOOL forceRefresh = NO;
if ([keyPath isEqualToString:@"files"] || [keyPath isEqualToString:@"labels"] || !keyPath)
forceRefresh = YES;
if (([keyPath isEqualToString:@"computedThumbnail"] || !keyPath) || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) { if (forceRefresh || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
if (mediaObject.files.count == 0) if (mediaObject.files.count == 0)
self.thumbnailView.image = [UIImage imageNamed:@"folderIcon"]; self.thumbnailView.image = [UIImage imageNamed:@"folderIcon"];
else else
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForLabel:mediaObject]; self.thumbnailView.image = [VLCThumbnailsCache thumbnailForLabel:mediaObject forceRefresh:forceRefresh];
} }
} else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) { } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
MLAlbum *mediaObject = (MLAlbum *)self.mediaObject; MLAlbum *mediaObject = (MLAlbum *)self.mediaObject;
...@@ -164,9 +179,12 @@ ...@@ -164,9 +179,12 @@
} else if ([self.mediaObject isKindOfClass:[MLShow class]]) { } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
MLShow *mediaObject = (MLShow *)self.mediaObject; MLShow *mediaObject = (MLShow *)self.mediaObject;
[self _configureForShow:mediaObject]; [self _configureForShow:mediaObject];
BOOL forceRefresh = NO;
if ([keyPath isEqualToString:@"episodes"])
forceRefresh = YES;
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) { if ([keyPath isEqualToString:@"computedThumbnail"] || forceRefresh || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject]; self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject forceRefresh:forceRefresh];
} }
} else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) { } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject; MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject;
......
...@@ -42,36 +42,49 @@ ...@@ -42,36 +42,49 @@
- (void)setMediaObject:(MLFile *)mediaObject - (void)setMediaObject:(MLFile *)mediaObject
{ {
if (_mediaObject != mediaObject) { if (_mediaObject != mediaObject) {
[_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"]; if ([_mediaObject isKindOfClass:[MLLabel class]]) {
[_mediaObject removeObserver:self forKeyPath:@"lastPosition"]; [_mediaObject removeObserver:self forKeyPath:@"files"];
[_mediaObject removeObserver:self forKeyPath:@"duration"]; [_mediaObject removeObserver:self forKeyPath:@"name"];
[_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"]; } else if ([_mediaObject isKindOfClass:[MLShow class]])
[_mediaObject removeObserver:self forKeyPath:@"title"]; [_mediaObject removeObserver:self forKeyPath:@"episodes"];
[_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"]; else if ([mediaObject isKindOfClass:[MLFile class]]) {
[_mediaObject removeObserver:self forKeyPath:@"unread"]; [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
[_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"]; [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
[_mediaObject removeObserver:self forKeyPath:@"album"]; [_mediaObject removeObserver:self forKeyPath:@"duration"];
[_mediaObject removeObserver:self forKeyPath:@"artist"]; [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
[_mediaObject removeObserver:self forKeyPath:@"genre"]; [_mediaObject removeObserver:self forKeyPath:@"title"];
if ([_mediaObject respondsToSelector:@selector(didHide)]) [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
[_mediaObject removeObserver:self forKeyPath:@"unread"];
[_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
[_mediaObject removeObserver:self forKeyPath:@"album"];
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"genre"];
[_mediaObject removeObserver:self forKeyPath:@"labels"];
[(MLFile*)_mediaObject didHide]; [(MLFile*)_mediaObject didHide];
}
_mediaObject = mediaObject; _mediaObject = mediaObject;
[_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil]; if ([_mediaObject isKindOfClass:[MLLabel class]]) {
[_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil]; [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil]; [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil]; } else if ([_mediaObject isKindOfClass:[MLShow class]])
[_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil]; [_mediaObject addObserver:self forKeyPath:@"episodes" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil]; else if ([_mediaObject isKindOfClass:[MLFile class]]) {
[_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil]; [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"albumTrackNumber" options:0 context:nil]; [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"album" options:0 context:nil]; [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil]; [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"genre" options:0 context:nil]; [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
if ([_mediaObject respondsToSelector:@selector(willDisplay)]) [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"albumTrackNumber" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"album" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"genre" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"labels" options:0 context:nil];
[(MLFile*)_mediaObject willDisplay]; [(MLFile*)_mediaObject willDisplay];
}
} }
[self _updatedDisplayedInformationForKeyPath:nil]; [self _updatedDisplayedInformationForKeyPath:nil];
...@@ -97,12 +110,15 @@ ...@@ -97,12 +110,15 @@
} else if (isFolder) { } else if (isFolder) {
MLLabel *mediaObject = (MLLabel *)self.mediaObject; MLLabel *mediaObject = (MLLabel *)self.mediaObject;
[self _configureForFolder:mediaObject]; [self _configureForFolder:mediaObject];
BOOL forceRefresh = NO;
if ([keyPath isEqualToString:@"files"] || [keyPath isEqualToString:@"labels"] || !keyPath)
forceRefresh = YES;
if (([keyPath isEqualToString:@"computedThumbnail"] || !keyPath) || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) { if (forceRefresh || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
if (mediaObject.files.count == 0) if (mediaObject.files.count == 0)
self.thumbnailView.image = [UIImage imageNamed:@"folderIcon"]; self.thumbnailView.image = [UIImage imageNamed:@"folderIcon"];
else else
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForLabel:mediaObject]; self.thumbnailView.image = [VLCThumbnailsCache thumbnailForLabel:mediaObject forceRefresh:forceRefresh];
} }
} else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) { } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
MLAlbum *mediaObject = (MLAlbum *)self.mediaObject; MLAlbum *mediaObject = (MLAlbum *)self.mediaObject;
...@@ -123,9 +139,12 @@ ...@@ -123,9 +139,12 @@
} else if ([self.mediaObject isKindOfClass:[MLShow class]]) { } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
MLShow *mediaObject = (MLShow *)self.mediaObject; MLShow *mediaObject = (MLShow *)self.mediaObject;
[self _configureForShow:mediaObject]; [self _configureForShow:mediaObject];
BOOL forceRefresh = NO;
if ([keyPath isEqualToString:@"episodes"])
forceRefresh = YES;
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) { if ([keyPath isEqualToString:@"computedThumbnail"] || forceRefresh || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject]; self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject forceRefresh:forceRefresh];
} }
} else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) { } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject; MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
+ (UIImage *)thumbnailForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname; + (UIImage *)thumbnailForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname;
+ (UIImage *)thumbnailForShow:(MLShow *)mediaShow; + (UIImage *)thumbnailForShow:(MLShow *)mediaShow forceRefresh:(BOOL)forceRefresh;
+ (UIImage *)thumbnailForLabel:(MLLabel *)mediaLabel; + (UIImage *)thumbnailForLabel:(MLLabel *)mediaLabel forceRefresh:(BOOL)forceRefresh;
@end @end
...@@ -102,13 +102,16 @@ static NSCache *_thumbnailCache; ...@@ -102,13 +102,16 @@ static NSCache *_thumbnailCache;
return displayedImage; return displayedImage;
} }
+ (UIImage *)thumbnailForShow:(MLShow *)mediaShow + (UIImage *)thumbnailForShow:(MLShow *)mediaShow forceRefresh:(BOOL)forceRefresh
{ {
NSManagedObjectID *objID = mediaShow.objectID; NSManagedObjectID *objID = mediaShow.objectID;
UIImage *displayedImage = [_thumbnailCache objectForKey:objID]; UIImage *displayedImage;
if (displayedImage) if (!forceRefresh) {
return displayedImage; displayedImage = [_thumbnailCache objectForKey:objID];
if (displayedImage)
return displayedImage;
}
NSUInteger count = [mediaShow.episodes count]; NSUInteger count = [mediaShow.episodes count];
NSUInteger fileNumber = count > 3 ? 3 : count; NSUInteger fileNumber = count > 3 ? 3 : count;
...@@ -124,13 +127,16 @@ static NSCache *_thumbnailCache; ...@@ -124,13 +127,16 @@ static NSCache *_thumbnailCache;
return displayedImage; return displayedImage;
} }
+ (UIImage *)thumbnailForLabel:(MLLabel *)mediaLabel + (UIImage *)thumbnailForLabel:(MLLabel *)mediaLabel forceRefresh:(BOOL)forceRefresh
{ {
NSManagedObjectID *objID = mediaLabel.objectID; NSManagedObjectID *objID = mediaLabel.objectID;
UIImage *displayedImage = [_thumbnailCache objectForKey:objID]; UIImage *displayedImage;
if (displayedImage) if (!forceRefresh) {
return displayedImage; displayedImage = [_thumbnailCache objectForKey:objID];
if (displayedImage)
return displayedImage;
}
NSUInteger count = [mediaLabel.files count]; NSUInteger count = [mediaLabel.files count];
NSUInteger fileNumber = count > 3 ? 3 : count; NSUInteger fileNumber = count > 3 ? 3 : count;
......
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