Brion VIBBER has submitted this change and it was merged. Change subject: Support colorized zero-rating messaging ......................................................................
Support colorized zero-rating messaging Allow for a colorized zero-rating "banner" in the Wikipedia for iOS app. Additionally, make memory warning-based toggle debugging easier. Previously, only a black-n-white banner. Change-Id: Ic5bcfe79ab80576316ae31bc09901761a5d377ce --- M wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m M wikipedia/View Controllers/WebView/WebViewController.m 2 files changed, 55 insertions(+), 14 deletions(-) Approvals: Brion VIBBER: Looks good to me, approved jenkins-bot: Verified diff --git a/wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m b/wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m index 09ebf28..0deb09a 100644 --- a/wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m +++ b/wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m @@ -8,6 +8,7 @@ #import "NSObject+Extras.h" #import "Defines.h" #import "WikipediaAppUtils.h" +#import "WMF_Colors.h" @interface WikipediaZeroMessageFetcher() @@ -42,8 +43,17 @@ [[MWNetworkActivityIndicatorManager sharedManager] pop]; - // Fake out an error if non-dictionary response received. - if(![responseObject isDict]){ + // If we're simulating with memory warnings in WebViewcontroller.m, + // don't trigger an error for non-dictionary responses, but rather + // simulate a received message. + // But if we're not simulating, force an error on non-dictionary responses. + if ([SessionSingleton sharedInstance].zeroConfigState.fakeZeroOn) { + responseObject = @{ + @"message": @"Free Wikipedia by Test Operator", + @"foreground": @"#00FF00", + @"background": @"#ff69b4" + }; + } else if (![responseObject isDict]) { responseObject = @{@"error": @{@"info": @"Wikipedia Zero message not found."}}; } @@ -59,7 +69,7 @@ userInfo: errorDict]; } - NSString *output = @""; + NSDictionary *output; if (!error) { output = [self getSanitizedResponse:responseObject]; } @@ -88,18 +98,46 @@ }; } --(NSString *)getSanitizedResponse:(NSDictionary *)rawResponse +-(NSDictionary *)getSanitizedResponse:(NSDictionary *)rawResponse { - NSString *zeroRatedMessage = rawResponse.count > 0 ? [rawResponse objectForKey:@"message"] : nil; - - // For testing Wikipedia Zero visual flourishes. - // Go to WebViewController.m and uncomment the W0 part, + // For testing Wikipedia Zero visual flourishes, + // go to WebViewController.m and uncomment the W0 part, // then when running the app in the simulator fire the // memory warning to toggle the fake state on or off. - if ([SessionSingleton sharedInstance].zeroConfigState.fakeZeroOn) { - zeroRatedMessage = @"Free Wikipedia by Test Operator"; + if (rawResponse.count == 0) { + return nil; } - return zeroRatedMessage; + + NSString *message = rawResponse[@"message"]; + UIColor *foreground = [self UIColorFromHexString:rawResponse[@"foreground"]]; + UIColor *background = [self UIColorFromHexString:rawResponse[@"background"]]; + + if (message && foreground && background) { + return @{ + @"message": message, + @"foreground": foreground, + @"background": background + }; + } + return nil; +} + +-(UIColor *)UIColorFromHexString:(NSString*)hexString +{ + if (hexString && [hexString hasPrefix:@"#"] && hexString.length == 7) { + @try { + // Tip from https://stackoverflow.com/questions/3010216/how-can-i-convert-rgb-hex-string-into-uicolor-in-objective-c/13648705#13648705 + NSScanner *scanner = [NSScanner scannerWithString:[hexString substringWithRange:NSMakeRange(1, 6)]]; + unsigned hex; + if (![scanner scanHexInt:&hex]) return nil; + return UIColorFromRGBWithAlpha(hex,1.0); + } + + @catch (NSException *e) { + return nil; + } + } + return nil; } /* diff --git a/wikipedia/View Controllers/WebView/WebViewController.m b/wikipedia/View Controllers/WebView/WebViewController.m index 3ef3862..817c85a 100644 --- a/wikipedia/View Controllers/WebView/WebViewController.m +++ b/wikipedia/View Controllers/WebView/WebViewController.m @@ -1658,15 +1658,17 @@ switch (status) { case FETCH_FINAL_STATUS_SUCCEEDED: { - NSString *title = (NSString *)userData; - if (title) { + NSDictionary *banner = (NSDictionary*)userData; + if (banner) { TopMenuTextFieldContainer *textFieldContainer = [ROOT.topMenuViewController getNavBarItem:NAVBAR_TEXT_FIELD]; textFieldContainer.textField.placeholder = MWLocalizedString(@"search-field-placeholder-text-zero", nil); //[self showAlert:title type:ALERT_TYPE_TOP duration:2]; + NSString *title = banner[@"message"]; self.zeroStatusLabel.text = title; self.zeroStatusLabel.padding = UIEdgeInsetsMake(3, 10, 3, 10); - self.zeroStatusLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.93]; + self.zeroStatusLabel.textColor = banner[@"foreground"]; + self.zeroStatusLabel.backgroundColor = banner[@"background"]; [NAV promptFirstTimeZeroOnWithTitleIfAppropriate:title]; } @@ -2041,6 +2043,7 @@ //[self showAlert:warnVerbiage type:ALERT_TYPE_TOP duration:duration]; self.zeroStatusLabel.text = warnVerbiage; self.zeroStatusLabel.backgroundColor = [UIColor redColor]; + self.zeroStatusLabel.textColor = [UIColor whiteColor]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ self.zeroStatusLabel.text = @""; -- To view, visit https://gerrit.wikimedia.org/r/169950 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic5bcfe79ab80576316ae31bc09901761a5d377ce Gerrit-PatchSet: 3 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Dr0ptp4kt <ab...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Dr0ptp4kt <ab...@wikimedia.org> Gerrit-Reviewer: Mhurd <mh...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits