diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h index 86dcd8a..faeefee 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h @@ -6,7 +6,7 @@ // Copyright © 2016 Verizon Wireless. All rights reserved. // -#import +#import #import extern NSUInteger const TopAlertDismissTime; @@ -44,6 +44,10 @@ extern NSUInteger const TopAlertDismissTime; // If 0, uses default 5 seconds. @property (nonatomic) NSInteger topAlertDismissTime; +// Server can set color. +@property (nullable, strong, nonatomic) UIColor *backgroundColor; +@property (nullable, strong, nonatomic) UIColor *textColor; + - (nullable instancetype)initWithResponseInfo:(nullable NSDictionary *)responseInfo; - (nullable instancetype)initWithType:(nullable NSString *)type message:(nullable NSString *)message; diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.m b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.m index 381074d..b6aaf91 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.m +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.m @@ -8,9 +8,11 @@ #import "MVMCoreTopAlertObject.h" #import +#import "MVMCoreGetterUtility.h" #import "MVMCoreAlertHandler.h" #import "MVMCoreJSONConstants.h" + NSUInteger const TopAlertDismissTime = 5; @implementation MVMCoreTopAlertObject @@ -27,6 +29,15 @@ NSUInteger const TopAlertDismissTime = 5; self.topMessage = [responseInfo string:KeyTopMessage]; self.imageNameOrURL = [responseInfo string:@"topAlertImageUrl"]; + NSString *color = [responseInfo string:@"topAlertColor"]; + if (color) { + self.backgroundColor = [MVMCoreGetterUtility getColorForHexString:color]; + } + color = [responseInfo string:@"messageColor"]; + if (color) { + self.textColor = [MVMCoreGetterUtility getColorForHexString:color]; + } + // The default is yes if not sent by server (for legacy to work as is) NSNumber *closeButton = [responseInfo objectForKey:KeyCloseButton ofType:[NSNumber class]]; if (closeButton) { diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h index ffd31c6..ef653c4 100644 --- a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h @@ -21,4 +21,8 @@ // Returns true if the user's language is Spanish + (BOOL)userPrefersSpanish; + +// Returns a UIColor ++ (nonnull UIColor *)getColorForHexString:(nonnull NSString *)hexString; + @end diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m index 5985fcf..b2a3e11 100644 --- a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m @@ -34,5 +34,20 @@ } } ++ (nonnull UIColor *)getColorForHexString:(nonnull NSString *)hexString { + unsigned int hexint = 0; + + // Create scanner + NSScanner *scanner = [NSScanner scannerWithString:hexString]; + + // Tell scanner to skip the # character + [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]]; + [scanner scanHexInt:&hexint]; + + return [UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16))/255 + green:((CGFloat) ((hexint & 0xFF00) >> 8))/255 + blue:((CGFloat) (hexint & 0xFF))/255 + alpha:1]; +} @end