Commit 30d5e6f8 authored by Felix Paul Kühne's avatar Felix Paul Kühne
Browse files

detail and now playing view: do not block the main thread when loading...

detail and now playing view: do not block the main thread when loading thumbnails and micro-optimize the code
parent 00ff7035
......@@ -35,7 +35,6 @@
[self addNowPlayingMenu];
[self configureWithFile:context];
}
- (void)willActivate {
......@@ -68,14 +67,20 @@
BOOL playEnabled = managedObject != nil;
self.playNowButton.enabled = playEnabled;
BOOL noProgress = (playbackProgress == 0.0 || playbackProgress == 1.0);
self.progressSeparator.hidden = noProgress;
self.progressSeparator.width = floor(playbackProgress * CGRectGetWidth([WKInterfaceDevice currentDevice].screenBounds));
/* do not block the main thread */
[self performSelectorInBackground:@selector(loadThumbnailForManagedObject:) withObject:managedObject];
}
- (void)loadThumbnailForManagedObject:(NSManagedObject *)managedObject
{
UIImage *thumbnail = [VLCThumbnailsCache thumbnailForManagedObject:managedObject];
if (thumbnail) {
[self.group setBackgroundImage:thumbnail];
}
BOOL noProgress = (playbackProgress == 0.0 || playbackProgress == 1.0);
self.progressSeparator.hidden = noProgress;
self.progressSeparator.width = floor(playbackProgress * CGRectGetWidth([WKInterfaceDevice currentDevice].screenBounds));
}
- (IBAction)playNow {
......
......@@ -18,6 +18,10 @@
#import "VLCThumbnailsCache.h"
@interface VLCNowPlayingInterfaceController ()
{
CGRect _screenBounds;
CGFloat _screenScale;
}
@property (nonatomic, copy) NSString *titleString;
@property (nonatomic, copy) NSNumber *playBackDurationNumber;
@property (nonatomic) BOOL isPlaying;
......@@ -38,6 +42,10 @@
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
WKInterfaceDevice *currentDevice = [WKInterfaceDevice currentDevice];
_screenBounds = currentDevice.screenBounds;
_screenScale = currentDevice.screenScale;
// Configure interface objects here.
[self requestNowPlayingInfo];
[[VLCNotificationRelay sharedRelay] addRelayRemoteName:@"org.videolan.ios-app.nowPlayingInfoUpdate" toLocalName:@"nowPlayingInfoUpdate"];
......@@ -92,9 +100,14 @@
self.progressSeparator.width = noProgress ? 0.0 : progressWidth;
self.playBackDurationNumber = duration;
CGFloat width = CGRectGetWidth([WKInterfaceDevice currentDevice].screenBounds);
CGFloat height = CGRectGetHeight([WKInterfaceDevice currentDevice].screenBounds);
UIImage *image = [VLCThumbnailsCache thumbnailForManagedObject:file toFitRect:CGRectMake(0, 0, width*2, height*2) shouldReplaceCache:NO];
/* do not block */
[self performSelectorInBackground:@selector(loadThumbnailForFile:) withObject:file];
}
- (void)loadThumbnailForFile:(MLFile *)file
{
UIImage *image = [VLCThumbnailsCache thumbnailForManagedObject:file toFitRect:CGRectMake(0., 0., _screenBounds.size.width * _screenScale, _screenBounds.size.height * _screenScale) shouldReplaceCache:NO];
[self.playElementsGroup setBackgroundImage:image];
}
......
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