Commit d540e6de authored by Carola Nitz's avatar Carola Nitz

UIDevice: remove unneeded speedcategory 1 and refactored the code

parent 5571b743
Pipeline #209 failed with stage
in 0 seconds
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* UIDevice+VLC.h * UIDevice+VLC.h
* VLC for iOS * VLC for iOS
***************************************************************************** *****************************************************************************
* Copyright (c) 2013-2015 VideoLAN. All rights reserved. * Copyright (c) 2013-2017 VideoLAN. All rights reserved.
* $Id$ * $Id$
* *
* Authors: Felix Paul Kühne <fkuehne # videolan.org> * Authors: Felix Paul Kühne <fkuehne # videolan.org>
...@@ -12,9 +12,17 @@ ...@@ -12,9 +12,17 @@
#import <UIKit/UIKit.h> #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) @interface UIDevice (VLC)
@property (readonly) int VLCSpeedCategory; @property (readonly) VLCSpeedCategory vlcSpeedCategory;
@property (readonly) NSNumber *VLCFreeDiskSpace; @property (readonly) NSNumber *VLCFreeDiskSpace;
@property (readonly) BOOL VLCHasExternalDisplay; @property (readonly) BOOL VLCHasExternalDisplay;
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
* UIDevice+VLC * UIDevice+VLC
* VLC for iOS * VLC for iOS
***************************************************************************** *****************************************************************************
* Copyright (c) 2013-2015 VideoLAN. All rights reserved. * Copyright (c) 2013-2017 VideoLAN. All rights reserved.
* $Id$ * $Id$
* *
* Authors: Felix Paul Kühne <fkuehne # videolan.org> * Authors: Felix Paul Kühne <fkuehne # videolan.org>
* Carola Nitz <caro # videolan.org>
* *
* Refer to the COPYING file of the official project for license. * Refer to the COPYING file of the official project for license.
*****************************************************************************/ *****************************************************************************/
...@@ -13,43 +14,33 @@ ...@@ -13,43 +14,33 @@
#import "UIDevice+VLC.h" #import "UIDevice+VLC.h"
#import <sys/sysctl.h> // for sysctlbyname #import <sys/sysctl.h> // for sysctlbyname
int _currentSpeedCategory;
@implementation UIDevice (VLC) @implementation UIDevice (VLC)
- (int)VLCSpeedCategory VLCSpeedCategory _currentSpeedCategory;
{
if (_currentSpeedCategory != 0) {
return _currentSpeedCategory;
}
size_t size; - (VLCSpeedCategory)vlcSpeedCategory
sysctlbyname("hw.machine", NULL, &size, NULL, 0); {
if (_currentSpeedCategory == VLCSpeedCategoryNotSet) {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *answer = malloc(size); char *answer = malloc(size);
sysctlbyname("hw.machine", answer, &size, NULL, 0); sysctlbyname("hw.machine", answer, &size, NULL, 0);
NSString *currentMachine = @(answer); NSString *currentMachine = @(answer);
free(answer); free(answer);
if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) { 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 4, 4th generation iPod touch APLog(@"this is a cat two device");
APLog(@"this is a cat one device"); _currentSpeedCategory = VLCSpeedCategoryTwoDevices;
_currentSpeedCategory = 1; } else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) {
} 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"]) { APLog(@"this is a cat three device");
// iPhone 4S, iPad 2 and 3, iPod 4 and 5 _currentSpeedCategory = VLCSpeedCategoryThreeDevices;
APLog(@"this is a cat two device"); } else {
_currentSpeedCategory = 2; APLog(@"this is a cat four device");
} else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) { _currentSpeedCategory = VLCSpeedCategoryFourDevices;
// 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;
} }
return _currentSpeedCategory; return _currentSpeedCategory;
} }
......
...@@ -57,8 +57,7 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize ...@@ -57,8 +57,7 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *skipLoopFilterDefaultValue; NSNumber *skipLoopFilterDefaultValue;
int deviceSpeedCategory = [[UIDevice currentDevice] VLCSpeedCategory]; if ([[UIDevice currentDevice] vlcSpeedCategory] < VLCSpeedCategoryThreeDevices)
if (deviceSpeedCategory < 3)
skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonKey; skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonKey;
else else
skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonRef; skipLoopFilterDefaultValue = kVLCSettingSkipLoopFilterNonRef;
......
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
_tableView.sectionHeaderHeight = 28.; _tableView.sectionHeaderHeight = 28.;
[_tableView registerClass:[VLCTrackSelectorHeaderView class] forHeaderFooterViewReuseIdentifier:PROFILE_SELECTOR_TABLEVIEW_SECTIONHEADER]; [_tableView registerClass:[VLCTrackSelectorHeaderView class] forHeaderFooterViewReuseIdentifier:PROFILE_SELECTOR_TABLEVIEW_SECTIONHEADER];
[_tableView registerClass:[VLCTrackSelectorTableViewCell class] forCellReuseIdentifier:PROFILE_SELECTOR_TABLEVIEW_CELL]; [_tableView registerClass:[VLCTrackSelectorTableViewCell class] forCellReuseIdentifier:PROFILE_SELECTOR_TABLEVIEW_CELL];
if ([[UIDevice currentDevice] VLCSpeedCategory] >= 3) { if ([[UIDevice currentDevice] vlcSpeedCategory] >= VLCSpeedCategoryThreeDevices) {
_tableView.opaque = NO; _tableView.opaque = NO;
_tableView.backgroundColor = [UIColor clearColor]; _tableView.backgroundColor = [UIColor clearColor];
} else } else
......
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
/* devices category 3 and faster include HW accelerated JPEG encoding /* devices category 3 and faster include HW accelerated JPEG encoding
* so we can make our transfers faster by using waaay smaller images */ * 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]); theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo]);
contentType = @"image/png"; contentType = @"image/png";
} else { } else {
......
...@@ -139,8 +139,6 @@ typedef NS_ENUM(NSInteger, VLCPanType) { ...@@ -139,8 +139,6 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
[super viewDidLoad]; [super viewDidLoad];
CGRect rect; CGRect rect;
int deviceSpeedCategory = [[UIDevice currentDevice] VLCSpeedCategory];
self.extendedLayoutIncludesOpaqueBars = YES; self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeAll; self.edgesForExtendedLayout = UIRectEdgeAll;
...@@ -236,7 +234,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) { ...@@ -236,7 +234,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
[self.view addSubview:_equalizerView]; [self.view addSubview:_equalizerView];
//Sleep Timer initialization //Sleep Timer initialization
[self sleepTimerInitializer:deviceSpeedCategory]; [self sleepTimerInitializer];
[self setupControlPanel]; [self setupControlPanel];
CGRect screenBounds = [[UIScreen mainScreen] bounds]; CGRect screenBounds = [[UIScreen mainScreen] bounds];
...@@ -526,7 +524,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) { ...@@ -526,7 +524,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
#pragma mark - Initializer helper #pragma mark - Initializer helper
- (void)sleepTimerInitializer:(int)deviceSpeedCategory - (void)sleepTimerInitializer
{ {
/* add sleep timer UI */ /* add sleep timer UI */
_sleepTimerContainer = [[VLCFrostedGlasView alloc] initWithFrame:CGRectMake(0., 0., 300., 200.)]; _sleepTimerContainer = [[VLCFrostedGlasView alloc] initWithFrame:CGRectMake(0., 0., 300., 200.)];
...@@ -545,7 +543,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) { ...@@ -545,7 +543,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
verticalSeparator.backgroundColor = [UIColor VLCLightTextColor].CGColor; verticalSeparator.backgroundColor = [UIColor VLCLightTextColor].CGColor;
_sleepTimeDatePicker = [[UIDatePicker alloc] init]; _sleepTimeDatePicker = [[UIDatePicker alloc] init];
if (deviceSpeedCategory >= 3) { if ([[UIDevice currentDevice] vlcSpeedCategory] >= VLCSpeedCategoryThreeDevices) {
_sleepTimeDatePicker.opaque = NO; _sleepTimeDatePicker.opaque = NO;
_sleepTimeDatePicker.backgroundColor = [UIColor clearColor]; _sleepTimeDatePicker.backgroundColor = [UIColor clearColor];
} else } else
......
...@@ -152,19 +152,13 @@ VLCMediaDelegate> ...@@ -152,19 +152,13 @@ VLCMediaDelegate>
NSUInteger totalNumberOfPixels = width * height; NSUInteger totalNumberOfPixels = width * height;
NSInteger speedCategory = [[UIDevice currentDevice] VLCSpeedCategory]; VLCSpeedCategory speedCategory = [[UIDevice currentDevice] vlcSpeedCategory];
if (speedCategory == 1) { if (speedCategory == VLCSpeedCategoryTwoDevices) {
// 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
return (totalNumberOfPixels < 922000); // 720p return (totalNumberOfPixels < 922000); // 720p
} else if (speedCategory == 3) { } else if (speedCategory == VLCSpeedCategoryThreeDevices) {
// iPhone 5, iPad 4
return (totalNumberOfPixels < 2074000); // 1080p return (totalNumberOfPixels < 2074000); // 1080p
} else if (speedCategory == 4) { } else if (speedCategory == VLCSpeedCategoryFourDevices) {
// iPhone 6, 2014 iPads
return (totalNumberOfPixels < 8850000); // 4K return (totalNumberOfPixels < 8850000); // 4K
} }
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
_sideMenuViewController.delegate = self; _sideMenuViewController.delegate = self;
if ([[UIDevice currentDevice] VLCSpeedCategory] <= 2) { if ([[UIDevice currentDevice] vlcSpeedCategory] <= VLCSpeedCategoryTwoDevices) {
_sideMenuViewController.animationDuration = 0.1f; _sideMenuViewController.animationDuration = 0.1f;
_sideMenuViewController.parallaxEnabled = NO; _sideMenuViewController.parallaxEnabled = NO;
_sideMenuViewController.contentViewShadowEnabled = NO; _sideMenuViewController.contentViewShadowEnabled = NO;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
self.contentView.backgroundColor = [UIColor VLCDarkBackgroundColor]; self.contentView.backgroundColor = [UIColor VLCDarkBackgroundColor];
self.textLabel.textColor = [UIColor whiteColor]; self.textLabel.textColor = [UIColor whiteColor];
if ([[UIDevice currentDevice] VLCSpeedCategory] >= 3) { if ([[UIDevice currentDevice] vlcSpeedCategory] >= VLCSpeedCategoryThreeDevices) {
self.opaque = NO; self.opaque = NO;
self.alpha = .8; self.alpha = .8;
} }
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
} }
- (void)configureForDeviceCategory { - (void)configureForDeviceCategory {
if ([[UIDevice currentDevice] VLCSpeedCategory] >= 3) { if ([[UIDevice currentDevice] vlcSpeedCategory] >= VLCSpeedCategoryThreeDevices) {
_trackSelectorTableView.opaque = NO; _trackSelectorTableView.opaque = NO;
_trackSelectorTableView.backgroundColor = [UIColor clearColor]; _trackSelectorTableView.backgroundColor = [UIColor clearColor];
} else { } else {
......
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