Commit e6ff524d authored by Felix Paul Kühne's avatar Felix Paul Kühne

Library: implement thumbnail caching to speed-up scrolling performance

parent b190c991
......@@ -12,6 +12,8 @@
#import "VLCAppDelegate.h"
#import "AQGridView.h"
#define MAX_CACHE_SIZE 18 // twice the number of items shown on iPad
@interface VLCPlaylistGridView (Hack)
@property (nonatomic, retain) NSString *reuseIdentifier;
@end
......@@ -85,8 +87,28 @@
if (self.mediaObject.videoTrack)
self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", [[self.mediaObject videoTrack] valueForKey:@"width"], [[self.mediaObject videoTrack] valueForKey:@"height"]];
}
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath)
self.thumbnailView.image = self.mediaObject.computedThumbnail;
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath) {
static NSMutableArray *_thumbnailCacheIndex;
static NSMutableDictionary *_thumbnailCache;
if (!_thumbnailCache)
_thumbnailCache = [[NSMutableDictionary alloc] initWithCapacity:MAX_CACHE_SIZE];
if (!_thumbnailCacheIndex)
_thumbnailCacheIndex = [[NSMutableArray alloc] initWithCapacity:MAX_CACHE_SIZE];
NSManagedObjectID *objID = self.mediaObject.objectID;
if ([_thumbnailCacheIndex containsObject:objID]) {
[_thumbnailCacheIndex removeObject:objID];
[_thumbnailCacheIndex insertObject:objID atIndex:0];
} else {
if (_thumbnailCacheIndex.count >= MAX_CACHE_SIZE) {
[_thumbnailCache removeObjectForKey:[_thumbnailCacheIndex lastObject]];
[_thumbnailCacheIndex removeLastObject];
}
[_thumbnailCache setObject:self.mediaObject.computedThumbnail forKey:objID];
[_thumbnailCacheIndex insertObject:objID atIndex:0];
}
self.thumbnailView.image = [_thumbnailCache objectForKey:objID];
}
self.progressView.progress = self.mediaObject.lastPosition.floatValue;
self.progressView.hidden = (self.progressView.progress < .1f || .95f) ? YES : NO;
......
......@@ -10,6 +10,8 @@
#import "VLCPlaylistTableViewCell.h"
#define MAX_CACHE_SIZE 14 // twice the number of items shown on iPhone 5
@implementation VLCPlaylistTableViewCell
+ (VLCPlaylistTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
......@@ -70,8 +72,28 @@
if (self.mediaObject.videoTrack)
self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", [[self.mediaObject videoTrack] valueForKey:@"width"], [[self.mediaObject videoTrack] valueForKey:@"height"]];
}
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath)
self.thumbnailView.image = self.mediaObject.computedThumbnail;
if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath) {
static NSMutableArray *_thumbnailCacheIndex;
static NSMutableDictionary *_thumbnailCache;
if (!_thumbnailCache)
_thumbnailCache = [[NSMutableDictionary alloc] initWithCapacity:MAX_CACHE_SIZE];
if (!_thumbnailCacheIndex)
_thumbnailCacheIndex = [[NSMutableArray alloc] initWithCapacity:MAX_CACHE_SIZE];
NSManagedObjectID *objID = self.mediaObject.objectID;
if ([_thumbnailCacheIndex containsObject:objID]) {
[_thumbnailCacheIndex removeObject:objID];
[_thumbnailCacheIndex insertObject:objID atIndex:0];
} else {
if (_thumbnailCacheIndex.count >= MAX_CACHE_SIZE) {
[_thumbnailCache removeObjectForKey:[_thumbnailCacheIndex lastObject]];
[_thumbnailCacheIndex removeLastObject];
}
[_thumbnailCache setObject:self.mediaObject.computedThumbnail forKey:objID];
[_thumbnailCacheIndex insertObject:objID atIndex:0];
}
self.thumbnailView.image = [_thumbnailCache objectForKey:objID];
}
self.progressIndicator.progress = self.mediaObject.lastPosition.floatValue;
self.progressIndicator.hidden = ((self.progressIndicator.progress < .1f) || (self.progressIndicator.progress > .95f)) ? YES : NO;
......
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