Commit 9482d339 authored by Tobias's avatar Tobias Committed by Felix Paul Kühne
Browse files

reduce unnecessary UI updates

parent 4b885c61
......@@ -21,5 +21,9 @@
@property (weak, nonatomic) IBOutlet WKInterfaceGroup *group;
@property (weak, nonatomic) IBOutlet WKInterfaceObject *progressObject;
@property (copy, nonatomic) NSString *mediaTitle;
@property (copy, nonatomic) NSString *mediaDuration;
@property (nonatomic) CGFloat playbackProgress;
- (IBAction)playNow;
@end
......@@ -33,22 +33,12 @@
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
[self setTitle:NSLocalizedString(@"DETAIL", nil)];
[self addNowPlayingMenu];
[self configureWithFile:context];
}
- (void)willActivate {
[self setTitle:NSLocalizedString(@"DETAIL", nil)];
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
- (void)updateData {
[super updateData];
NSManagedObject *managedObject = self.managedObject;
......@@ -59,23 +49,29 @@
- (void)configureWithFile:(NSManagedObject *)managedObject {
self.managedObject = managedObject;
NSString *title = nil;
NSString *durationString = nil;
float playbackProgress = 0.0;
if ([managedObject isKindOfClass:[MLShowEpisode class]]) {
[self.titleLabel setText:((MLShowEpisode *)managedObject).name];
title = ((MLShowEpisode *)managedObject).name;
} else if ([managedObject isKindOfClass:[MLFile class]]) {
MLFile *file = (MLFile *)managedObject;
self.durationLabel.text = [VLCTime timeWithNumber:file.duration].stringValue;
durationString = [VLCTime timeWithNumber:file.duration].stringValue;
playbackProgress = file.lastPosition.floatValue;
[self.titleLabel setText:((MLFile *)file).title];
title = ((MLFile *)file).title;
} else if ([managedObject isKindOfClass:[MLAlbumTrack class]]) {
[self.titleLabel setText:((MLAlbumTrack *)managedObject).title];
title = ((MLAlbumTrack *)managedObject).title;
} else {
NSAssert(NO, @"check what filetype we try to show here and add it above");
}
BOOL playEnabled = managedObject != nil;
self.playNowButton.enabled = playEnabled;
[self.progressObject vlc_setProgress:playbackProgress hideForNoProgress:YES];
self.mediaTitle = title;
self.mediaDuration = durationString;
self.playbackProgress = playbackProgress;
/* do not block the main thread */
[self performSelectorInBackground:@selector(loadThumbnailForManagedObject:) withObject:managedObject];
......@@ -100,6 +96,30 @@
[self showNowPlaying:nil];
}];
}
- (void)setMediaTitle:(NSString *)mediaTitle {
if (![_mediaTitle isEqualToString:mediaTitle]) {
_mediaTitle = [mediaTitle copy];
self.titleLabel.text = mediaTitle;
self.titleLabel.hidden = mediaTitle.length == 0;
}
}
- (void)setMediaDuration:(NSString *)mediaDuration {
if (![_mediaDuration isEqualToString:mediaDuration]) {
_mediaDuration = [mediaDuration copy];
self.durationLabel.text = mediaDuration;
self.durationLabel.hidden = mediaDuration.length == 0;
}
}
- (void)setPlaybackProgress:(CGFloat)playbackProgress {
if (_playbackProgress != playbackProgress) {
_playbackProgress = playbackProgress;
[self.progressObject vlc_setProgress:playbackProgress hideForNoProgress:YES];
}
}
@end
......
......@@ -35,7 +35,6 @@
{
self = [super init];
if (self) {
[self setTitle:NSLocalizedString(@"PLAYING", nil)];
_isPlaying = YES;
}
return self;
......@@ -48,7 +47,8 @@
_screenBounds = currentDevice.screenBounds;
_screenScale = currentDevice.screenScale;
// Configure interface objects here.
[self setTitle:NSLocalizedString(@"PLAYING", nil)];
[self requestNowPlayingInfo];
[[VLCNotificationRelay sharedRelay] addRelayRemoteName:@"org.videolan.ios-app.nowPlayingInfoUpdate" toLocalName:@"nowPlayingInfoUpdate"];
}
......@@ -56,7 +56,6 @@
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
[self setTitle:NSLocalizedString(@"PLAYING", nil)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestNowPlayingInfo) name:@"nowPlayingInfoUpdate" object:nil];
[self requestNowPlayingInfo];
......@@ -148,7 +147,7 @@
}
- (void)setTitleString:(NSString *)titleString {
if (![_titleString isEqualToString:titleString] || (_titleString==nil && titleString)) {
if (![_titleString isEqualToString:titleString]) {
_titleString = [titleString copy];
[self.titleLabel setText:titleString];
}
......
......@@ -64,6 +64,7 @@ typedef enum {
self.title = [self.groupObject name];
self.libraryMode = VLCLibraryModeInGroup;
}
[self addNowPlayingMenu];
[[VLCNotificationRelay sharedRelay] addRelayRemoteName:VLCDBUpdateNotificationRemote toLocalName:VLCDBUpdateNotification];
......@@ -86,11 +87,6 @@ typedef enum {
[self updateData];
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {
id object = self.tableController.displayedObjects[rowIndex];
if ([object isKindOfClass:[MLAlbum class]] || [object isKindOfClass:[MLLabel class]] || [object isKindOfClass:[MLShow class]]) {
......@@ -115,7 +111,6 @@ typedef enum {
[self addMenuItemWithImageNamed:@"AllFiles" title: NSLocalizedString(@"LIBRARY_ALL_FILES", nil) action:@selector(switchToAllFiles)];
[self addMenuItemWithImageNamed:@"MusicAlbums" title: NSLocalizedString(@"LIBRARY_MUSIC", nil) action:@selector(switchToMusic)];
[self addMenuItemWithImageNamed:@"TVShows" title: NSLocalizedString(@"LIBRARY_SERIES", nil) action:@selector(switchToSeries)];
[self addNowPlayingMenu];
}
- (void)switchToAllFiles{
......
......@@ -16,6 +16,10 @@
@property (nonatomic, weak) IBOutlet WKInterfaceGroup *group;
@property (nonatomic, weak) IBOutlet WKInterfaceObject *progressObject;
@property (nonatomic, copy) NSString *mediaTitle;
@property (nonatomic) CGFloat playbackProgress;
@property (nonatomic, weak, readonly) id mediaLibraryObject;
- (void) configureWithMediaLibraryObject:(id)object;
......
......@@ -20,6 +20,8 @@
@property (nonatomic, readonly) CGRect thumbnailSize;
@property (nonatomic, readonly) CGFloat rowWidth;
@property (nonatomic) UIImage *rawBackgroundImage;
@end
@implementation VLCRowController
......@@ -29,6 +31,7 @@
self = [super init];
if (self) {
[self calculateThumbnailSizeAndRowWidth];
_playbackProgress = -1;
}
return self;
}
......@@ -48,24 +51,26 @@
- (void)configureWithMediaLibraryObject:(id)storageObject
{
NSString *title = nil;
float playbackProgress = 0.0;
if ([storageObject isKindOfClass:[MLShow class]]) {
self.titleLabel.text = ((MLAlbum *)storageObject).name;
title = ((MLAlbum *)storageObject).name;
} else if ([storageObject isKindOfClass:[MLShowEpisode class]]) {
self.titleLabel.text = ((MLShowEpisode *)storageObject).name;
title = ((MLShowEpisode *)storageObject).name;
} else if ([storageObject isKindOfClass:[MLLabel class]]) {
self.titleLabel.text = ((MLLabel *)storageObject).name;
title = ((MLLabel *)storageObject).name;
} else if ([storageObject isKindOfClass:[MLAlbum class]]) {
self.titleLabel.text = ((MLAlbum *)storageObject).name;
title = ((MLAlbum *)storageObject).name;
} else if ([storageObject isKindOfClass:[MLAlbumTrack class]]) {
self.titleLabel.text = ((MLAlbumTrack *)storageObject).title;
title = ((MLAlbumTrack *)storageObject).title;
} else if ([storageObject isKindOfClass:[MLFile class]]){
MLFile *file = (MLFile *)storageObject;
self.titleLabel.text = [file title];
title = [file title];
playbackProgress = file.lastPosition.floatValue;
}
[self.progressObject vlc_setProgress:playbackProgress hideForNoProgress:YES];
self.mediaTitle = title;
self.playbackProgress = playbackProgress;
/* FIXME: add placeholder image once designed */
......@@ -82,6 +87,13 @@
- (void)backgroundThumbnailSetter:(NSArray *)array
{
UIImage *backgroundImage = [VLCThumbnailsCache thumbnailForManagedObject:array[1] toFitRect:_thumbnailSize shouldReplaceCache:YES];
// don't redo image processing if no necessary
if ([self.rawBackgroundImage isEqual:backgroundImage]) {
return;
}
self.rawBackgroundImage = backgroundImage;
UIImage *gradient = [UIImage imageNamed:@"tableview-gradient"];
CGSize newSize = backgroundImage ? backgroundImage.size : CGSizeMake(_rowWidth, 120.);
......@@ -102,4 +114,21 @@
[array.firstObject performSelectorOnMainThread:@selector(setBackgroundImage:) withObject:newImage waitUntilDone:NO];
}
- (void)setMediaTitle:(NSString *)mediaTitle {
if (![_mediaTitle isEqualToString:mediaTitle]) {
_mediaTitle = [mediaTitle copy];
self.titleLabel.text = mediaTitle;
self.accessibilityValue = mediaTitle;
self.titleLabel.hidden = mediaTitle.length == 0;
}
}
- (void)setPlaybackProgress:(CGFloat)playbackProgress {
if (_playbackProgress != playbackProgress) {
_playbackProgress = playbackProgress;
[self.progressObject vlc_setProgress:playbackProgress hideForNoProgress:YES];
}
}
@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