Dr0ptp4kt has uploaded a new change for review. https://gerrit.wikimedia.org/r/169950
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. Change-Id: Ic5bcfe79ab80576316ae31bc09901761a5d377ce --- M wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m M wikipedia/View Controllers/WebView/WebViewController.m 2 files changed, 59 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/50/169950/1 diff --git a/wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m b/wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m index 09ebf28..d09ce33 100644 --- a/wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m +++ b/wikipedia/Networking/Fetchers/WikipediaZeroMessageFetcher.m @@ -42,8 +42,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 +68,7 @@ userInfo: errorDict]; } - NSString *output = @""; + NSDictionary *output; if (!error) { output = [self getSanitizedResponse:responseObject]; } @@ -88,18 +97,49 @@ }; } --(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 objectForKey:@"message"]; + UIColor *foreground = [self UIColorFromHexString:[rawResponse objectForKey:@"foreground"]]; + UIColor *background = [self UIColorFromHexString:[rawResponse objectForKey:@"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; + int r = (hex >> 16) & 0xFF; + int g = (hex >> 8) & 0xFF; + int b = (hex) & 0xFF; + return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f]; + } + + @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..50cb69d 100644 --- a/wikipedia/View Controllers/WebView/WebViewController.m +++ b/wikipedia/View Controllers/WebView/WebViewController.m @@ -1658,15 +1658,19 @@ 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 = (NSString*)[banner objectForKey:@"message"]; + UIColor *fg = (UIColor*)[banner objectForKey:@"foreground"]; + UIColor *bg = (UIColor*)[banner objectForKey:@"background"]; 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 = fg; + self.zeroStatusLabel.backgroundColor = bg; [NAV promptFirstTimeZeroOnWithTitleIfAppropriate:title]; } @@ -2041,6 +2045,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: newchange Gerrit-Change-Id: Ic5bcfe79ab80576316ae31bc09901761a5d377ce Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Dr0ptp4kt <ab...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits