Przeglądaj źródła

UIDevice: remove unneeded speedcategory 1 and refactored the code

Carola Nitz 7 lat temu
rodzic
commit
d540e6de72

+ 10 - 2
Sources/UIDevice+VLC.h

@@ -2,7 +2,7 @@
  * UIDevice+VLC.h
  * VLC for iOS
  *****************************************************************************
- * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
+ * Copyright (c) 2013-2017 VideoLAN. All rights reserved.
  * $Id$
  *
  * Authors: Felix Paul Kühne <fkuehne # videolan.org>
@@ -12,9 +12,17 @@
 
 #import <UIKit/UIKit.h>
 
+typedef NS_ENUM(NSUInteger, VLCSpeedCategory) {
+    VLCSpeedCategoryNotSet = 0,
+    VLCSpeedCategoryOneDevices, // < iOS 9 and not supported anymore
+    VLCSpeedCategoryTwoDevices, // iPhone 4S, iPad 2 and 3, iPod 4 and 5
+    VLCSpeedCategoryThreeDevices, // iPhone 5 + 5S, iPad 4, iPad Air, iPad mini 2G
+    VLCSpeedCategoryFourDevices, // iPhone 6 + 6S, 2014+2015 iPads and newer
+};
+
 @interface UIDevice (VLC)
 
-@property (readonly) int VLCSpeedCategory;
+@property (readonly) VLCSpeedCategory vlcSpeedCategory;
 @property (readonly) NSNumber *VLCFreeDiskSpace;
 @property (readonly) BOOL VLCHasExternalDisplay;
 

+ 22 - 31
Sources/UIDevice+VLC.m

@@ -2,10 +2,11 @@
  * UIDevice+VLC
  * VLC for iOS
  *****************************************************************************
- * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
+ * Copyright (c) 2013-2017 VideoLAN. All rights reserved.
  * $Id$
  *
  * Authors: Felix Paul Kühne <fkuehne # videolan.org>
+ *          Carola Nitz <caro # videolan.org>
  *
  * Refer to the COPYING file of the official project for license.
  *****************************************************************************/
@@ -13,43 +14,33 @@
 #import "UIDevice+VLC.h"
 #import <sys/sysctl.h> // for sysctlbyname
 
-int _currentSpeedCategory;
-
 @implementation UIDevice (VLC)
 
-- (int)VLCSpeedCategory
-{
-    if (_currentSpeedCategory != 0) {
-        return _currentSpeedCategory;
-    }
+VLCSpeedCategory _currentSpeedCategory;
 
-    size_t size;
-    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+- (VLCSpeedCategory)vlcSpeedCategory
+{
+    if (_currentSpeedCategory == VLCSpeedCategoryNotSet) {
+        size_t size;
+        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
 
-    char *answer = malloc(size);
-    sysctlbyname("hw.machine", answer, &size, NULL, 0);
+        char *answer = malloc(size);
+        sysctlbyname("hw.machine", answer, &size, NULL, 0);
 
-    NSString *currentMachine = @(answer);
-    free(answer);
+        NSString *currentMachine = @(answer);
+        free(answer);
 
-    if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) {
-        // iPhone 4, 4th generation iPod touch
-        APLog(@"this is a cat one device");
-        _currentSpeedCategory = 1;
-    } else if ([currentMachine hasPrefix:@"iPhone4"] || [currentMachine hasPrefix:@"iPad3,1"] || [currentMachine hasPrefix:@"iPad3,2"] || [currentMachine hasPrefix:@"iPad3,3"] || [currentMachine hasPrefix:@"iPod4"] || [currentMachine hasPrefix:@"iPad2"] || [currentMachine hasPrefix:@"iPod5"]) {
-        // iPhone 4S, iPad 2 and 3, iPod 4 and 5
-        APLog(@"this is a cat two device");
-        _currentSpeedCategory = 2;
-    } else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) {
-        // iPhone 5 + 5S, iPad 4, iPad Air, iPad mini 2G
-        APLog(@"this is a cat three device");
-        _currentSpeedCategory = 3;
-    } else {
-        // iPhone 6 + 6S, 2014+2015 iPads
-        APLog(@"this is a cat four device");
-        _currentSpeedCategory = 4;
+        if ([currentMachine hasPrefix:@"iPhone4"] || [currentMachine hasPrefix:@"iPad3,1"] || [currentMachine hasPrefix:@"iPad3,2"] || [currentMachine hasPrefix:@"iPad3,3"] || [currentMachine hasPrefix:@"iPod4"] || [currentMachine hasPrefix:@"iPad2"] || [currentMachine hasPrefix:@"iPod5"]) {
+            APLog(@"this is a cat two device");
+            _currentSpeedCategory = VLCSpeedCategoryTwoDevices;
+        } else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) {
+            APLog(@"this is a cat three device");
+            _currentSpeedCategory = VLCSpeedCategoryThreeDevices;
+        } else {
+            APLog(@"this is a cat four device");
+            _currentSpeedCategory = VLCSpeedCategoryFourDevices;
+        }
     }
-
     return _currentSpeedCategory;
 }
 

+ 1 - 2
Sources/VLCAppDelegate.m

@@ -57,8 +57,7 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 
     NSNumber *skipLoopFilterDefaultValue;
-    int deviceSpeedCategory = [[UIDevice currentDevice] VLCSpeedCategory];
-    if (deviceSpeedCategory < 3)
+    if ([[UIDevice currentDevice] vlcSpeedCategory] < VLCSpeedCategoryThreeDevices)
         skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonKey;
     else
         skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonRef;

+ 1 - 1
Sources/VLCEqualizerView.m

@@ -260,7 +260,7 @@
     _tableView.sectionHeaderHeight = 28.;
     [_tableView registerClass:[VLCTrackSelectorHeaderView class] forHeaderFooterViewReuseIdentifier:PROFILE_SELECTOR_TABLEVIEW_SECTIONHEADER];
     [_tableView registerClass:[VLCTrackSelectorTableViewCell class] forCellReuseIdentifier:PROFILE_SELECTOR_TABLEVIEW_CELL];
-    if ([[UIDevice currentDevice] VLCSpeedCategory] >= 3) {
+    if ([[UIDevice currentDevice] vlcSpeedCategory] >= VLCSpeedCategoryThreeDevices) {
         _tableView.opaque = NO;
         _tableView.backgroundColor = [UIColor clearColor];
     } else

+ 1 - 1
Sources/VLCHTTPConnection.m

@@ -159,7 +159,7 @@
 
             /* devices category 3 and faster include HW accelerated JPEG encoding
              * so we can make our transfers faster by using waaay smaller images */
-            if ([[UIDevice currentDevice] VLCSpeedCategory] < 3) {
+            if ([[UIDevice currentDevice] vlcSpeedCategory] < VLCSpeedCategoryThreeDevices) {
                 theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo]);
                 contentType = @"image/png";
             } else {

+ 3 - 5
Sources/VLCMovieViewController.m

@@ -139,8 +139,6 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     [super viewDidLoad];
     CGRect rect;
 
-    int deviceSpeedCategory = [[UIDevice currentDevice] VLCSpeedCategory];
-
     self.extendedLayoutIncludesOpaqueBars = YES;
     self.edgesForExtendedLayout = UIRectEdgeAll;
 
@@ -236,7 +234,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     [self.view addSubview:_equalizerView];
 
     //Sleep Timer initialization
-    [self sleepTimerInitializer:deviceSpeedCategory];
+    [self sleepTimerInitializer];
     [self setupControlPanel];
 
     CGRect screenBounds = [[UIScreen mainScreen] bounds];
@@ -526,7 +524,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
 
 #pragma mark - Initializer helper
 
-- (void)sleepTimerInitializer:(int)deviceSpeedCategory
+- (void)sleepTimerInitializer
 {
     /* add sleep timer UI */
     _sleepTimerContainer = [[VLCFrostedGlasView alloc] initWithFrame:CGRectMake(0., 0., 300., 200.)];
@@ -545,7 +543,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     verticalSeparator.backgroundColor = [UIColor VLCLightTextColor].CGColor;
 
     _sleepTimeDatePicker = [[UIDatePicker alloc] init];
-    if (deviceSpeedCategory >= 3) {
+    if ([[UIDevice currentDevice] vlcSpeedCategory] >= VLCSpeedCategoryThreeDevices) {
         _sleepTimeDatePicker.opaque = NO;
         _sleepTimeDatePicker.backgroundColor = [UIColor clearColor];
     } else

+ 4 - 10
Sources/VLCPlaybackController.m

@@ -152,19 +152,13 @@ VLCMediaDelegate>
 
     NSUInteger totalNumberOfPixels = width * height;
 
-    NSInteger speedCategory = [[UIDevice currentDevice] VLCSpeedCategory];
+    VLCSpeedCategory speedCategory = [[UIDevice currentDevice] vlcSpeedCategory];
 
-    if (speedCategory == 1) {
-        // iPhone 3GS, iPhone 4, first gen. iPad, 3rd and 4th generation iPod touch
-        return (totalNumberOfPixels < 600000); // between 480p and 720p
-    } else if (speedCategory == 2) {
-        // iPhone 4S, iPad 2 and 3, iPod 4 and 5
+    if (speedCategory == VLCSpeedCategoryTwoDevices) {
         return (totalNumberOfPixels < 922000); // 720p
-    } else if (speedCategory == 3) {
-        // iPhone 5, iPad 4
+    } else if (speedCategory == VLCSpeedCategoryThreeDevices) {
         return (totalNumberOfPixels < 2074000); // 1080p
-    } else if (speedCategory == 4) {
-        // iPhone 6, 2014 iPads
+    } else if (speedCategory == VLCSpeedCategoryFourDevices) {
         return (totalNumberOfPixels < 8850000); // 4K
     }
 

+ 1 - 1
Sources/VLCSidebarController.m

@@ -60,7 +60,7 @@
 
     _sideMenuViewController.delegate = self;
 
-    if ([[UIDevice currentDevice] VLCSpeedCategory] <= 2) {
+    if ([[UIDevice currentDevice] vlcSpeedCategory] <= VLCSpeedCategoryTwoDevices) {
         _sideMenuViewController.animationDuration = 0.1f;
         _sideMenuViewController.parallaxEnabled = NO;
         _sideMenuViewController.contentViewShadowEnabled = NO;

+ 1 - 1
Sources/VLCTrackSelectorHeaderView.m

@@ -25,7 +25,7 @@
     self.contentView.backgroundColor = [UIColor VLCDarkBackgroundColor];
     self.textLabel.textColor = [UIColor whiteColor];
 
-    if ([[UIDevice currentDevice] VLCSpeedCategory] >= 3) {
+    if ([[UIDevice currentDevice] vlcSpeedCategory] >= VLCSpeedCategoryThreeDevices) {
         self.opaque = NO;
         self.alpha = .8;
     }

+ 1 - 1
Sources/VLCTrackSelectorView.m

@@ -53,7 +53,7 @@
 }
 
 - (void)configureForDeviceCategory {
-    if ([[UIDevice currentDevice] VLCSpeedCategory] >= 3) {
+    if ([[UIDevice currentDevice] vlcSpeedCategory] >= VLCSpeedCategoryThreeDevices) {
         _trackSelectorTableView.opaque = NO;
         _trackSelectorTableView.backgroundColor = [UIColor clearColor];
     } else {