Explorar el Código

UI updates should always happen on the main thread always set the gradient as default background image so the wrong image doesn't stay for a short time after page changes move progress related calculations to category

Tobias Conradi hace 10 años
padre
commit
195046b5a0

+ 2 - 3
VLC for iOS WatchKit Extension/VLCDetailInterfaceController.m

@@ -14,6 +14,7 @@
 #import <MediaLibraryKit/MediaLibraryKit.h>
 #import <MobileVLCKit/MobileVLCKit.h>
 #import "VLCThumbnailsCache.h"
+#import "WKInterfaceObject+VLCProgress.h"
 
 @interface VLCDetailInterfaceController ()
 @property (nonatomic, weak) NSManagedObject *managedObject;
@@ -67,9 +68,7 @@
     BOOL playEnabled = managedObject != nil;
     self.playNowButton.enabled = playEnabled;
 
-    BOOL noProgress = (playbackProgress == 0.0 || playbackProgress == 1.0);
-    self.progressObject.hidden = noProgress;
-    self.progressObject.width = floor(playbackProgress * CGRectGetWidth([WKInterfaceDevice currentDevice].screenBounds));
+    [self.progressObject vlc_setProgress:playbackProgress hideForNoProgress:YES];
 
     /* do not block the main thread */
     [self performSelectorInBackground:@selector(loadThumbnailForManagedObject:) withObject:managedObject];

+ 4 - 9
VLC for iOS WatchKit Extension/VLCNowPlayingInterfaceController.m

@@ -16,6 +16,7 @@
 #import <MediaLibraryKit/MediaLibraryKit.h>
 #import "VLCNotificationRelay.h"
 #import "VLCThumbnailsCache.h"
+#import "WKInterfaceObject+VLCProgress.h"
 
 @interface VLCNowPlayingInterfaceController ()
 {
@@ -98,17 +99,11 @@
     }
 
     NSNumber *playbackTime = nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime];
-    float playbackProgress = 0.0;
     float playbackTimeFloat = playbackTime.floatValue; // seconds
     float durationFloat = duration.floatValue; // milliseconds
-    if (playbackTimeFloat > 0.0 && durationFloat > 0.0) {
-        playbackProgress = playbackTimeFloat / (durationFloat/1000);
-    }
-    BOOL noProgress = (playbackProgress == 0.0 || playbackProgress == 1.0);
-    CGFloat progressWidth = floor(playbackProgress * CGRectGetWidth([WKInterfaceDevice currentDevice].screenBounds));
-    CGFloat newWidth = noProgress ? 0.0 : progressWidth;
-    self.progressObject.width = newWidth;
-    self.progressObject.hidden = noProgress;
+    durationFloat/=1000; // seconds
+
+    [self.progressObject vlc_setProgressFromPlaybackTime:playbackTimeFloat duration:durationFloat hideForNoProgess:YES];
 
     self.playBackDurationNumber = duration;
 

+ 8 - 15
VLC for iOS WatchKit Extension/VLCPlaylistInterfaceController.m

@@ -20,6 +20,7 @@
 #import "VLCNotificationRelay.h"
 #import "VLCWatchTableController.h"
 #import "VLCThumbnailsCache.h"
+#import "WKInterfaceObject+VLCProgress.h"
 
 static NSString *const rowType = @"mediaRow";
 static NSString *const VLCDBUpdateNotification = @"VLCUpdateDataBase";
@@ -158,18 +159,13 @@ typedef enum {
 - (void)updateData {
     // if not activated/visible we defer the update til activation
     if (self.activated) {
-        [self performSelectorInBackground:@selector(backgroundUpdateData) withObject:nil];
+        self.tableController.objects = [self mediaArray];
+        self.needsUpdate = NO;
     } else {
         self.needsUpdate = YES;
     }
 }
 
-- (void)backgroundUpdateData
-{
-    self.tableController.objects = [self mediaArray];
-    self.needsUpdate = NO;
-}
-
 - (void)configureTableRowController:(id)rowController withObject:(id)storageObject {
 
     VLCRowController *row = rowController;
@@ -191,14 +187,11 @@ typedef enum {
         playbackProgress = file.lastPosition.floatValue;
     }
 
-    BOOL noProgress = (playbackProgress == 0.0 || playbackProgress == 1.0);
-    row.progressObject.hidden = noProgress;
-    row.progressObject.width = floor(playbackProgress * CGRectGetWidth([WKInterfaceDevice currentDevice].screenBounds));
+    [row.progressObject vlc_setProgress:playbackProgress hideForNoProgress:YES];
+
+    /* FIXME: add placeholder image once designed */
 
-    /* FIXME: add placeholder image once designed
-    if (backgroundImage == nil)
-        backgroundImage = nil;
-     */
+    row.group.backgroundImage = [UIImage imageNamed:@"tableview-gradient"];
 
     NSArray *array = @[row.group, storageObject];
     [self performSelectorInBackground:@selector(backgroundThumbnailSetter:) withObject:array];
@@ -225,7 +218,7 @@ typedef enum {
 
     UIGraphicsEndImageContext();
 
-    [array[0] setBackgroundImage:newImage];
+    [array.firstObject performSelectorOnMainThread:@selector(setBackgroundImage:) withObject:newImage waitUntilDone:YES];
 }
 
 //TODO: this code could use refactoring to be more readable

+ 22 - 0
VLC for iOS WatchKit Extension/WKInterfaceObject+VLCProgress.h

@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * WKInterfaceObject+VLCProgress.h
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2015 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Author: Tobias Conradi <videolan # tobias-conradi.de>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+#import <WatchKit/WatchKit.h>
+
+@interface WKInterfaceObject (VLCProgress)
+
+- (void)vlc_setProgress:(float)progress;
+- (void)vlc_setProgress:(float)progress hideForNoProgress:(BOOL)hide;
+
+/* time and duration must be in the same timescale but we don't care about the scale*/
+- (void)vlc_setProgressFromPlaybackTime:(float)playbackTime duration:(float)duration hideForNoProgess:(BOOL)hide;
+@end

+ 39 - 0
VLC for iOS WatchKit Extension/WKInterfaceObject+VLCProgress.m

@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * WKInterfaceObject+VLCProgress.m
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2015 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Author: Tobias Conradi <videolan # tobias-conradi.de>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+#import "WKInterfaceObject+VLCProgress.h"
+
+@implementation WKInterfaceObject (VLCProgress)
+
+-(void)vlc_setProgress:(float)progress
+{
+    float progressWidth = ceil(progress * CGRectGetWidth([WKInterfaceDevice currentDevice].screenBounds));
+    self.width = progressWidth;
+}
+
+- (void)vlc_setProgress:(float)progress hideForNoProgress:(BOOL)hideForNoProgress
+{
+    [self vlc_setProgress:progress];
+    BOOL noProgress = progress == 0.0;
+    self.hidden = noProgress && hideForNoProgress;
+}
+
+- (void)vlc_setProgressFromPlaybackTime:(float)playbackTime duration:(float)duration hideForNoProgess:(BOOL)hideForNoProgress
+{
+    float playbackProgress = 0.0;
+    if (playbackTime > 0.0 && duration > 0.0) {
+        playbackProgress = playbackTime / duration;
+    }
+    [self vlc_setProgress:playbackProgress hideForNoProgress:hideForNoProgress];
+}
+
+@end

+ 6 - 0
VLC for iOS.xcodeproj/project.pbxproj

@@ -551,6 +551,7 @@
 		DD02C30E1ACAF4A50026EFEE /* VLCRowController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD02C30D1ACAF4A50026EFEE /* VLCRowController.m */; };
 		DD1542121ACFF76400AFD4EC /* VLCWatchTableController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD1542111ACFF76400AFD4EC /* VLCWatchTableController.m */; };
 		DD6FA7B01ACD641C006DEB2E /* VLCNowPlayingInterfaceController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD6FA7AF1ACD641C006DEB2E /* VLCNowPlayingInterfaceController.m */; };
+		DDACEB561ADAD11300735484 /* WKInterfaceObject+VLCProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = DDACEB551ADAD11300735484 /* WKInterfaceObject+VLCProgress.m */; };
 		DDE4906C1ACDB63F00B1B5E3 /* VLCNotificationRelay.m in Sources */ = {isa = PBXBuildFile; fileRef = DDE4906B1ACDB63F00B1B5E3 /* VLCNotificationRelay.m */; };
 		DDE4906D1ACDBEA000B1B5E3 /* VLCNotificationRelay.m in Sources */ = {isa = PBXBuildFile; fileRef = DDE4906B1ACDB63F00B1B5E3 /* VLCNotificationRelay.m */; };
 		DDE490701ACE8BBC00B1B5E3 /* VLCDetailInterfaceController.m in Sources */ = {isa = PBXBuildFile; fileRef = DDE4906F1ACE8BBC00B1B5E3 /* VLCDetailInterfaceController.m */; };
@@ -1612,6 +1613,8 @@
 		DD1542111ACFF76400AFD4EC /* VLCWatchTableController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCWatchTableController.m; sourceTree = "<group>"; };
 		DD6FA7AE1ACD641C006DEB2E /* VLCNowPlayingInterfaceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCNowPlayingInterfaceController.h; sourceTree = "<group>"; };
 		DD6FA7AF1ACD641C006DEB2E /* VLCNowPlayingInterfaceController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCNowPlayingInterfaceController.m; sourceTree = "<group>"; };
+		DDACEB541ADAD11300735484 /* WKInterfaceObject+VLCProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "WKInterfaceObject+VLCProgress.h"; sourceTree = "<group>"; };
+		DDACEB551ADAD11300735484 /* WKInterfaceObject+VLCProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "WKInterfaceObject+VLCProgress.m"; sourceTree = "<group>"; };
 		DDE4906A1ACDB63F00B1B5E3 /* VLCNotificationRelay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCNotificationRelay.h; sourceTree = "<group>"; };
 		DDE4906B1ACDB63F00B1B5E3 /* VLCNotificationRelay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCNotificationRelay.m; sourceTree = "<group>"; };
 		DDE4906E1ACE8BBC00B1B5E3 /* VLCDetailInterfaceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCDetailInterfaceController.h; sourceTree = "<group>"; };
@@ -1832,6 +1835,8 @@
 			isa = PBXGroup;
 			children = (
 				DD02C2FC1ACACF400026EFEE /* VLC for iOS WatchKit Extension.entitlements */,
+				DDACEB541ADAD11300735484 /* WKInterfaceObject+VLCProgress.h */,
+				DDACEB551ADAD11300735484 /* WKInterfaceObject+VLCProgress.m */,
 				DDE4906A1ACDB63F00B1B5E3 /* VLCNotificationRelay.h */,
 				DDE4906B1ACDB63F00B1B5E3 /* VLCNotificationRelay.m */,
 				DDE490711ACE964200B1B5E3 /* VLCBaseInterfaceController.h */,
@@ -3621,6 +3626,7 @@
 				DD02C30E1ACAF4A50026EFEE /* VLCRowController.m in Sources */,
 				DDE490701ACE8BBC00B1B5E3 /* VLCDetailInterfaceController.m in Sources */,
 				4173AEA61ABF1B850004101D /* VLCPlaylistInterfaceController.m in Sources */,
+				DDACEB561ADAD11300735484 /* WKInterfaceObject+VLCProgress.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};