From aee5c4adda1f90ecc56e60b76e228bc693b9f8f6 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Mon, 22 Oct 2012 01:08:26 +0200 Subject: [PATCH] Update update view to be more iOS 6 like Not completely finished yet --- Classes/BITAppStoreHeader.m | 2 - Classes/BITHockeyBaseManager.h | 14 ++++ Classes/BITHockeyBaseManager.m | 7 +- Classes/BITStoreButton.h | 18 +---- Classes/BITStoreButton.m | 105 ++++++++++-------------------- Classes/BITUpdateManager.m | 1 + Classes/BITUpdateViewController.m | 85 ++++++++++-------------- 7 files changed, 94 insertions(+), 138 deletions(-) diff --git a/Classes/BITAppStoreHeader.m b/Classes/BITAppStoreHeader.m index b2c7c8800a..db46d83e65 100644 --- a/Classes/BITAppStoreHeader.m +++ b/Classes/BITAppStoreHeader.m @@ -34,8 +34,6 @@ #import "HockeySDKPrivate.h" -#define BIT_RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1] - #define kLightGrayColor BIT_RGBCOLOR(235, 235, 235) #define kDarkGrayColor BIT_RGBCOLOR(186, 186, 186) #define kWhiteBackgroundColor BIT_RGBCOLOR(245, 245, 245) diff --git a/Classes/BITHockeyBaseManager.h b/Classes/BITHockeyBaseManager.h index 3e3340ee7a..234874df0b 100644 --- a/Classes/BITHockeyBaseManager.h +++ b/Classes/BITHockeyBaseManager.h @@ -33,9 +33,23 @@ /** The UIBarStyle of the update user interface navigation bar. + + Default is UIBarStyleBlackOpaque + @see tintColor */ @property (nonatomic, assign) UIBarStyle barStyle; +/** + The tint color of the update user interface navigation bar. + + The tintColor is used by default, you can either overwrite it `tintColor` + or define another `barStyle` instead. + + Default is RGB(25, 25, 25) + @see barStyle + */ +@property (nonatomic, retain) UIColor *tintColor; + /** The UIModalPresentationStyle for showing the update user interface when invoked with the update alert. diff --git a/Classes/BITHockeyBaseManager.m b/Classes/BITHockeyBaseManager.m index d255b88ca7..17db241d6e 100644 --- a/Classes/BITHockeyBaseManager.m +++ b/Classes/BITHockeyBaseManager.m @@ -38,7 +38,8 @@ _serverURL = BITHOCKEYSDK_URL; _navController = nil; - _barStyle = UIBarStyleDefault; + _barStyle = UIBarStyleBlackOpaque; + self.tintColor = BIT_RGBCOLOR(25, 25, 25); _modalPresentationStyle = UIModalPresentationFormSheet; NSLocale *enUSPOSIXLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]; @@ -67,6 +68,8 @@ [_navController release], _navController = nil; [_rfc3339Formatter release], _rfc3339Formatter = nil; + + [_tintColor release], _tintColor = nil; [super dealloc]; } @@ -167,6 +170,7 @@ _navController = [[UINavigationController alloc] initWithRootViewController:viewController]; _navController.navigationBar.barStyle = _barStyle; + _navController.navigationBar.tintColor = _tintColor; _navController.modalPresentationStyle = _modalPresentationStyle; if (parentViewController) { @@ -191,6 +195,7 @@ } } + #pragma mark - Manager Control - (void)startManager { diff --git a/Classes/BITStoreButton.h b/Classes/BITStoreButton.h index 25d7de106e..a54f4475f0 100644 --- a/Classes/BITStoreButton.h +++ b/Classes/BITStoreButton.h @@ -29,18 +29,14 @@ */ -#import #import // defines a button action set (data container) -@interface BITStoreButtonData : NSObject { - CGPoint _customPadding; -} +@interface BITStoreButtonData : NSObject -+ (id)dataWithLabel:(NSString*)aLabel colors:(NSArray*)aColors enabled:(BOOL)flag; ++ (id)dataWithLabel:(NSString*)aLabel enabled:(BOOL)flag; @property (nonatomic, copy) NSString *label; -@property (nonatomic, retain) NSArray *colors; @property (nonatomic, assign, getter=isEnabled) BOOL enabled; @end @@ -54,10 +50,7 @@ // Simulate the Paymeny-Button from the AppStore // The interface is flexible, so there is now fixed order -@interface BITStoreButton : UIButton { - CAGradientLayer *_gradient; - CGPoint _customPadding; -} +@interface BITStoreButton : UIButton - (id)initWithFrame:(CGRect)frame; - (id)initWithPadding:(CGPoint)padding; @@ -73,9 +66,4 @@ @property (nonatomic, assign) CGPoint customPadding; - (void)alignToSuperview; -// helpers to mimic an AppStore button -+ (NSArray *)appStoreGreenColor; -+ (NSArray *)appStoreBlueColor; -+ (NSArray *)appStoreGrayColor; - @end diff --git a/Classes/BITStoreButton.m b/Classes/BITStoreButton.m index 615c42a21a..9cd5480c03 100644 --- a/Classes/BITStoreButton.m +++ b/Classes/BITStoreButton.m @@ -30,11 +30,12 @@ #import "BITStoreButton.h" +#import "HockeySDKPrivate.h" +#import -#define PS_RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1] -#define PS_MIN_HEIGHT 25.0f -#define PS_MAX_WIDTH 120.0f -#define PS_PADDING 12.0f +#define BIT_MIN_HEIGHT 25.0f +#define BIT_MAX_WIDTH 120.0f +#define BIT_PADDING 12.0f #define kDefaultButtonAnimationTime 0.25f @@ -42,34 +43,26 @@ #pragma mark - NSObject -- (id)initWithLabel:(NSString*)aLabel colors:(NSArray*)aColors enabled:(BOOL)flag { +- (id)initWithLabel:(NSString*)aLabel enabled:(BOOL)flag { if ((self = [super init])) { self.label = aLabel; - self.colors = aColors; self.enabled = flag; } return self; } -+ (id)dataWithLabel:(NSString*)aLabel colors:(NSArray*)aColors enabled:(BOOL)flag { - return [[[[self class] alloc] initWithLabel:aLabel colors:aColors enabled:flag] autorelease]; ++ (id)dataWithLabel:(NSString*)aLabel enabled:(BOOL)flag { + return [[[[self class] alloc] initWithLabel:aLabel enabled:flag] autorelease]; } - (void)dealloc { [_label release], _label = nil; - [_colors release]; [super dealloc]; } @end -@interface BITStoreButton () -// call when buttonData was updated -- (void)updateButtonAnimated:(BOOL)animated; -@end - - @implementation BITStoreButton #pragma mark - private @@ -94,21 +87,17 @@ [UIView setAnimationDuration:kDefaultButtonAnimationTime]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; - }else { + } else { [self setTitle:self.buttonData.label forState:UIControlStateNormal]; } self.enabled = self.buttonData.isEnabled; - _gradient.colors = self.buttonData.colors; // show white or gray text, depending on the state if (self.buttonData.isEnabled) { - [self setTitleShadowColor:[UIColor colorWithWhite:0.200 alpha:1.000] forState:UIControlStateNormal]; - [self.titleLabel setShadowOffset:CGSizeMake(0.0, -0.6)]; - [self setTitleColor:[UIColor colorWithWhite:1.0 alpha:1.000] forState:UIControlStateNormal]; - }else { - [self.titleLabel setShadowOffset:CGSizeMake(0.0, 0.0)]; - [self setTitleColor:PS_RGBCOLOR(148,150,151) forState:UIControlStateNormal]; + [self setTitleColor:BIT_RGBCOLOR(106, 106, 106) forState:UIControlStateNormal]; + } else { + [self setTitleColor:BIT_RGBCOLOR(148, 150, 151) forState:UIControlStateNormal]; } // calculate optimal new size @@ -121,7 +110,7 @@ if (animated) { [CATransaction setAnimationDuration:kDefaultButtonAnimationTime]; [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; - }else { + } else { // frame is calculated and explicitely animated. so we absolutely need kCATransactionDisableActions [CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions]; } @@ -165,35 +154,31 @@ // register for touch events [self addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; - // border layers for more sex! - CAGradientLayer *bevelLayer = [CAGradientLayer layer]; - bevelLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:0.4 alpha:1.0] CGColor], [[UIColor whiteColor] CGColor], nil]; - bevelLayer.frame = CGRectMake(0.0, 0.0, CGRectGetWidth(frame), CGRectGetHeight(frame)); - bevelLayer.cornerRadius = 2.5; - bevelLayer.needsDisplayOnBoundsChange = YES; - [self.layer addSublayer:bevelLayer]; - - CAGradientLayer *topBorderLayer = [CAGradientLayer layer]; - topBorderLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor darkGrayColor] CGColor], [[UIColor lightGrayColor] CGColor], nil]; - topBorderLayer.frame = CGRectMake(0.5, 0.5, CGRectGetWidth(frame) - 1.0, CGRectGetHeight(frame) - 1.0); - topBorderLayer.cornerRadius = 2.6; - topBorderLayer.needsDisplayOnBoundsChange = YES; - [self.layer addSublayer:topBorderLayer]; - // main gradient layer - _gradient = [[CAGradientLayer layer] retain]; - _gradient.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:1.0], nil];//[NSNumber numberWithFloat:0.500], [NSNumber numberWithFloat:0.5001], - _gradient.frame = CGRectMake(0.75, 0.75, CGRectGetWidth(frame) - 1.5, CGRectGetHeight(frame) - 1.5); - _gradient.cornerRadius = 2.5; - _gradient.needsDisplayOnBoundsChange = YES; - [self.layer addSublayer:_gradient]; + CAGradientLayer *gradient = [CAGradientLayer layer]; + gradient.colors = @[(id)BIT_RGBCOLOR(243, 243, 243).CGColor, (id)BIT_RGBCOLOR(222, 222, 222).CGColor]; + gradient.locations = @[[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:1.0]]; + gradient.frame = CGRectMake(0.0, 0.0, CGRectGetWidth(frame), CGRectGetHeight(frame)); + gradient.cornerRadius = 2.5; + gradient.needsDisplayOnBoundsChange = YES; + [self.layer addSublayer:gradient]; + + // border layers for more sex! + CALayer *borderLayer = [CALayer layer]; + borderLayer.borderColor = [BIT_RGBCOLOR(191, 191, 191) CGColor]; + borderLayer.borderWidth = 1.0; + borderLayer.frame = CGRectMake(0.0, 0.0, CGRectGetWidth(frame), CGRectGetHeight(frame)); + borderLayer.cornerRadius = 2.5; + borderLayer.needsDisplayOnBoundsChange = YES; + [self.layer addSublayer:borderLayer]; + [self bringSubviewToFront:self.titleLabel]; } return self; } - (id)initWithPadding:(CGPoint)padding { - if ((self = [self initWithFrame:CGRectMake(0, 0, 40, PS_MIN_HEIGHT)])) { + if ((self = [self initWithFrame:CGRectMake(0, 0, 40, BIT_MIN_HEIGHT)])) { _customPadding = padding; } return self; @@ -201,7 +186,6 @@ - (void)dealloc { [_buttonData release]; - [_gradient release]; [super dealloc]; } @@ -210,10 +194,10 @@ #pragma mark - UIView - (CGSize)sizeThatFits:(CGSize)size { - CGSize constr = (CGSize){.height = self.frame.size.height, .width = PS_MAX_WIDTH}; + CGSize constr = (CGSize){.height = self.frame.size.height, .width = BIT_MAX_WIDTH}; CGSize newSize = [self.buttonData.label sizeWithFont:self.titleLabel.font constrainedToSize:constr lineBreakMode:UILineBreakModeMiddleTruncation]; - CGFloat newWidth = newSize.width + (PS_PADDING * 2); - CGFloat newHeight = PS_MIN_HEIGHT > newSize.height ? PS_MIN_HEIGHT : newSize.height; + CGFloat newWidth = newSize.width + (BIT_PADDING * 2); + CGFloat newHeight = BIT_MIN_HEIGHT > newSize.height ? BIT_MIN_HEIGHT : newSize.height; CGSize sizeThatFits = CGSizeMake(newWidth, newHeight); return sizeThatFits; @@ -248,25 +232,4 @@ [self updateButtonAnimated:animated]; } - -#pragma mark - Static - -+ (NSArray *)appStoreGreenColor { - return [NSArray arrayWithObjects:(id) - [UIColor colorWithRed:0.482 green:0.674 blue:0.406 alpha:1.000].CGColor, - [UIColor colorWithRed:0.299 green:0.606 blue:0.163 alpha:1.000].CGColor, nil]; -} - -+ (NSArray *)appStoreBlueColor { - return [NSArray arrayWithObjects:(id) - [UIColor colorWithRed:0.306 green:0.380 blue:0.547 alpha:1.000].CGColor, - [UIColor colorWithRed:0.129 green:0.220 blue:0.452 alpha:1.000].CGColor, nil]; -} - -+ (NSArray *)appStoreGrayColor { - return [NSArray arrayWithObjects:(id) - PS_RGBCOLOR(187,189,191).CGColor, - PS_RGBCOLOR(210,210,210).CGColor, nil]; -} - @end diff --git a/Classes/BITUpdateManager.m b/Classes/BITUpdateManager.m index 43ea073417..1cc9b49643 100644 --- a/Classes/BITUpdateManager.m +++ b/Classes/BITUpdateManager.m @@ -408,6 +408,7 @@ return; } + self.barStyle = UIBarStyleBlack; [self showView:[self hockeyViewController:YES]]; } diff --git a/Classes/BITUpdateViewController.m b/Classes/BITUpdateViewController.m index d5997a1047..c22e107724 100644 --- a/Classes/BITUpdateViewController.m +++ b/Classes/BITUpdateViewController.m @@ -76,20 +76,20 @@ - (void)updateAppStoreHeader { BITAppVersionMetaInfo *appVersion = _updateManager.newestAppVersion; _appStoreHeader.headerLabel = appVersion.name; - _appStoreHeader.middleHeaderLabel = [appVersion versionString]; - NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; - [formatter setDateStyle:NSDateFormatterMediumStyle]; - NSMutableString *subHeaderString = [NSMutableString string]; - if (appVersion.date) { - [subHeaderString appendString:[formatter stringFromDate:appVersion.date]]; - } - if (appVersion.size) { - if ([subHeaderString length]) { - [subHeaderString appendString:@" - "]; - } - [subHeaderString appendString:appVersion.sizeInMB]; - } - _appStoreHeader.subHeaderLabel = subHeaderString; + _appStoreHeader.middleHeaderLabel = [_updateManager currentAppVersion];// [appVersion versionString]; +// NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; +// [formatter setDateStyle:NSDateFormatterMediumStyle]; +// NSMutableString *subHeaderString = [NSMutableString string]; +// if (appVersion.date) { +// [subHeaderString appendString:[formatter stringFromDate:appVersion.date]]; +// } +// if (appVersion.size) { +// if ([subHeaderString length]) { +// [subHeaderString appendString:@" - "]; +// } +// [subHeaderString appendString:appVersion.sizeInMB]; +// } +// _appStoreHeader.subHeaderLabel = subHeaderString; } - (void)appDidBecomeActive { @@ -190,20 +190,30 @@ - (void)configureWebCell:(BITWebTableViewCell *)cell forAppVersion:(BITAppVersionMetaInfo *)appVersion { // create web view for a version + NSMutableString *dateAndSizeString = [NSMutableString string]; + if (appVersion.date) { + [dateAndSizeString appendString:[appVersion dateString]]; + } + if (appVersion.size) { + if ([dateAndSizeString length]) { + [dateAndSizeString appendString:@" - "]; + } + [dateAndSizeString appendString:appVersion.sizeInMB]; + } + NSString *installed = @""; if ([appVersion.version isEqualToString:[_updateManager currentAppVersion]]) { - installed = [NSString stringWithFormat:@"%@", [appVersion isEqual:_updateManager.newestAppVersion] ? @"left" : @"right", BITHockeyLocalizedString(@"UpdateInstalled")]; + installed = [NSString stringWithFormat:@"%@", BITHockeyLocalizedString(@"UpdateInstalled")]; } if ([appVersion isEqual:_updateManager.newestAppVersion]) { if ([appVersion.notes length] > 0) { - installed = [NSString stringWithFormat:@"

 %@

", installed]; - cell.webViewContent = [NSString stringWithFormat:@"%@%@", installed, appVersion.notes]; + cell.webViewContent = [NSString stringWithFormat:@"

%@%@
%@

%@

", [appVersion versionString], installed, dateAndSizeString, appVersion.notes]; } else { cell.webViewContent = [NSString stringWithFormat:@"
%@
", BITHockeyLocalizedString(@"UpdateNoReleaseNotesAvailable")]; } } else { - cell.webViewContent = [NSString stringWithFormat:@"

%@%@
%@

%@

", [appVersion versionString], installed, [appVersion dateString], [appVersion notesOrEmptyString]]; + cell.webViewContent = [NSString stringWithFormat:@"

%@%@
%@

%@

", [appVersion versionString], installed, dateAndSizeString, [appVersion notesOrEmptyString]]; } cell.cellBackgroundColor = BIT_RGBCOLOR(235, 235, 235); @@ -255,29 +265,6 @@ #pragma mark - View lifecycle -//- (CAGradientLayer *)backgroundLayer { -// UIColor *colorOne = [UIColor colorWithWhite:0.9 alpha:1.0]; -// UIColor *colorTwo = [UIColor colorWithHue:0.625 saturation:0.0 brightness:0.85 alpha:1.0]; -// UIColor *colorThree = [UIColor colorWithHue:0.625 saturation:0.0 brightness:0.7 alpha:1.0]; -// UIColor *colorFour = [UIColor colorWithHue:0.625 saturation:0.0 brightness:0.4 alpha:1.0]; -// -// NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, colorThree.CGColor, colorFour.CGColor, nil]; -// -// NSNumber *stopOne = [NSNumber numberWithFloat:0.0]; -// NSNumber *stopTwo = [NSNumber numberWithFloat:0.02]; -// NSNumber *stopThree = [NSNumber numberWithFloat:0.99]; -// NSNumber *stopFour = [NSNumber numberWithFloat:1.0]; -// -// NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, stopThree, stopFour, nil]; -// -// CAGradientLayer *headerLayer = [CAGradientLayer layer]; -// //headerLayer.frame = CGRectMake(0.0, 0.0, 320.0, 77.0); -// headerLayer.colors = colors; -// headerLayer.locations = locations; -// -// return headerLayer; -//} - - (void)viewDidLoad { [super viewDidLoad]; @@ -292,12 +279,12 @@ [_updateManager addObserver:self forKeyPath:@"apps" options:0 context:nil]; _kvoRegistered = YES; - self.tableView.backgroundColor = BIT_RGBCOLOR(235, 235, 235); + self.tableView.backgroundColor = BIT_RGBCOLOR(245, 245, 245); self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; UIView *topView = [[[UIView alloc] initWithFrame:CGRectMake(0, -(600-kAppStoreViewHeight), self.view.frame.size.width, 600)] autorelease]; topView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - topView.backgroundColor = BIT_RGBCOLOR(140, 141, 142); + topView.backgroundColor = BIT_RGBCOLOR(245, 245, 245); [self.tableView addSubview:topView]; _appStoreHeader = [[BITAppStoreHeader alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, kAppStoreViewHeight)]; @@ -359,7 +346,7 @@ storeButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; storeButton.buttonDelegate = self; [self.tableView.tableHeaderView addSubview:storeButton]; - storeButton.buttonData = [BITStoreButtonData dataWithLabel:@"" colors:[BITStoreButton appStoreGrayColor] enabled:NO]; + storeButton.buttonData = [BITStoreButtonData dataWithLabel:@"" enabled:NO]; [storeButton alignToSuperview]; _appStoreButton = [storeButton retain]; self.appStoreButtonState = AppStoreButtonStateCheck; @@ -531,19 +518,19 @@ switch (anAppStoreButtonState) { case AppStoreButtonStateOffline: - [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonOffline") colors:[BITStoreButton appStoreGrayColor] enabled:NO] animated:animated]; + [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonOffline") enabled:NO] animated:animated]; break; case AppStoreButtonStateCheck: - [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonCheck") colors:[BITStoreButton appStoreGreenColor] enabled:YES] animated:animated]; + [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonCheck") enabled:YES] animated:animated]; break; case AppStoreButtonStateSearching: - [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonSearching") colors:[BITStoreButton appStoreGrayColor] enabled:NO] animated:animated]; + [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonSearching") enabled:NO] animated:animated]; break; case AppStoreButtonStateUpdate: - [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonUpdate") colors:[BITStoreButton appStoreBlueColor] enabled:YES] animated:animated]; + [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonUpdate") enabled:YES] animated:animated]; break; case AppStoreButtonStateInstalling: - [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonInstalling") colors:[BITStoreButton appStoreGrayColor] enabled:NO] animated:animated]; + [_appStoreButton setButtonData:[BITStoreButtonData dataWithLabel:BITHockeyLocalizedString(@"UpdateButtonInstalling") enabled:NO] animated:animated]; break; default: break;