From 8727b683a5815693ff93766a37ef5f3a676c8176 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Sat, 23 Nov 2013 13:03:14 -0800 Subject: [PATCH] Adding font size overrides. --- clients/ios/Classes/FeedDetailTableCell.m | 14 ++++ .../ios/Classes/FeedDetailViewController.h | 1 + .../ios/Classes/FeedDetailViewController.m | 24 ++++++- clients/ios/Classes/FeedTableCell.m | 20 +++++- clients/ios/Classes/FolderTitleView.m | 13 ++++ .../ios/Classes/FontSettingsViewController.m | 34 +++++----- clients/ios/Classes/NewsBlurAppDelegate.h | 3 +- clients/ios/Classes/NewsBlurViewController.m | 1 + .../ios/Classes/StoryDetailViewController.m | 18 ++--- .../ios/Resources/Settings.bundle/Root.plist | 68 +++++++++++++++++++ clients/ios/static/storyDetailView.css | 16 ++--- 11 files changed, 168 insertions(+), 44 deletions(-) diff --git a/clients/ios/Classes/FeedDetailTableCell.m b/clients/ios/Classes/FeedDetailTableCell.m index ae1f851c4..b82257029 100644 --- a/clients/ios/Classes/FeedDetailTableCell.m +++ b/clients/ios/Classes/FeedDetailTableCell.m @@ -103,6 +103,7 @@ static UIFont *indicatorFont = nil; @synthesize cell; - (void)drawRect:(CGRect)r { + NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; int riverPadding = 0; if (cell.isRiverOrSocial) { riverPadding = 20; @@ -123,6 +124,19 @@ static UIFont *indicatorFont = nil; UIColor *textColor; UIFont *font; UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle: UIFontTextStyleCaption1]; + if (![userPreferences boolForKey:@"use_system_font_size"]) { + if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xs"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:10.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"small"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:11.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"medium"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:12.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"large"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:14.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xl"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:16.0f]; + } + } if (cell.isRead) { font = [UIFont fontWithDescriptor:fontDescriptor size:0.0]; diff --git a/clients/ios/Classes/FeedDetailViewController.h b/clients/ios/Classes/FeedDetailViewController.h index 292cde2ae..62e02e174 100644 --- a/clients/ios/Classes/FeedDetailViewController.h +++ b/clients/ios/Classes/FeedDetailViewController.h @@ -72,6 +72,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scroll; - (void)changeIntelligence:(NSInteger)newLevel; - (NSDictionary *)getStoryAtRow:(NSInteger)indexPathRow; +- (UIFontDescriptor *)fontDescriptorUsingPreferredSize:(NSString *)textStyle; - (void)checkScroll; - (void)setUserAvatarLayout:(UIInterfaceOrientation)orientation; diff --git a/clients/ios/Classes/FeedDetailViewController.m b/clients/ios/Classes/FeedDetailViewController.m index 7a20f14f1..882b659cd 100644 --- a/clients/ios/Classes/FeedDetailViewController.m +++ b/clients/ios/Classes/FeedDetailViewController.m @@ -1035,7 +1035,7 @@ heightForRowAtIndexPath:(NSIndexPath *)indexPath { && UIInterfaceOrientationIsPortrait(orientation)) { height = height - kTableViewShortRowDifference; } - UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle: UIFontTextStyleCaption1]; + UIFontDescriptor *fontDescriptor = [self fontDescriptorUsingPreferredSize:UIFontTextStyleCaption1]; UIFont *font = [UIFont fontWithDescriptor:fontDescriptor size:0.0]; return height + font.pointSize*2; } else { @@ -1045,7 +1045,7 @@ heightForRowAtIndexPath:(NSIndexPath *)indexPath { && UIInterfaceOrientationIsPortrait(orientation)) { height = height - kTableViewShortRowDifference; } - UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle: UIFontTextStyleCaption1]; + UIFontDescriptor *fontDescriptor = [self fontDescriptorUsingPreferredSize:UIFontTextStyleCaption1]; UIFont *font = [UIFont fontWithDescriptor:fontDescriptor size:0.0]; return height + font.pointSize*2; } @@ -1058,6 +1058,26 @@ heightForRowAtIndexPath:(NSIndexPath *)indexPath { [self checkScroll]; } +- (UIFontDescriptor *)fontDescriptorUsingPreferredSize:(NSString *)textStyle { + UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:textStyle]; + NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; + + if (![userPreferences boolForKey:@"use_system_font_size"]) { + if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xs"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:10.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"small"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:11.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"medium"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:12.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"large"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:14.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xl"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:16.0f]; + } + } + return fontDescriptor; +} + - (void)checkScroll { NSInteger currentOffset = self.storyTitlesTable.contentOffset.y; NSInteger maximumOffset = self.storyTitlesTable.contentSize.height - self.storyTitlesTable.frame.size.height; diff --git a/clients/ios/Classes/FeedTableCell.m b/clients/ios/Classes/FeedTableCell.m index 8f2fd14aa..cb7a4e9a4 100644 --- a/clients/ios/Classes/FeedTableCell.m +++ b/clients/ios/Classes/FeedTableCell.m @@ -144,10 +144,24 @@ static UIFont *textFont = nil; [UIColor blackColor]: UIColorFromRGB(0x3a3a3a); UIFont *font; - UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle: UIFontTextStyleFootnote]; + NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; + UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleFootnote]; + if (![userPreferences boolForKey:@"use_system_font_size"]) { + if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xs"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:11.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"small"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:12.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"medium"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:13.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"large"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:14.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xl"]) { + fontDescriptor = [fontDescriptor fontDescriptorWithSize:16.0f]; + } + } if (cell.negativeCount || cell.neutralCount || cell.positiveCount) { - UIFontDescriptor *boldFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits: UIFontDescriptorTraitBold]; - font = [UIFont fontWithDescriptor: boldFontDescriptor size:0.0]; + UIFontDescriptor *boldFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; + font = [UIFont fontWithDescriptor:boldFontDescriptor size:0.0]; } else { font = [UIFont fontWithDescriptor:fontDescriptor size:0.0]; } diff --git a/clients/ios/Classes/FolderTitleView.m b/clients/ios/Classes/FolderTitleView.m index c16d0bbc9..da400a9c1 100644 --- a/clients/ios/Classes/FolderTitleView.m +++ b/clients/ios/Classes/FolderTitleView.m @@ -102,6 +102,19 @@ UIColor *textColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1.0]; UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle: UIFontTextStyleCaption1]; UIFontDescriptor *boldFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits: UIFontDescriptorTraitBold]; + if (![userPreferences boolForKey:@"use_system_font_size"]) { + if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xs"]) { + boldFontDescriptor = [boldFontDescriptor fontDescriptorWithSize:10.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"small"]) { + boldFontDescriptor = [boldFontDescriptor fontDescriptorWithSize:11.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"medium"]) { + boldFontDescriptor = [boldFontDescriptor fontDescriptorWithSize:12.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"large"]) { + boldFontDescriptor = [boldFontDescriptor fontDescriptorWithSize:14.0f]; + } else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xl"]) { + boldFontDescriptor = [boldFontDescriptor fontDescriptorWithSize:16.0f]; + } + } UIFont *font = [UIFont fontWithDescriptor: boldFontDescriptor size:0.0]; NSInteger titleOffsetY = ((rect.size.height - font.pointSize) / 2) - 1; NSString *folderTitle; diff --git a/clients/ios/Classes/FontSettingsViewController.m b/clients/ios/Classes/FontSettingsViewController.m index 1b5908c0c..e7303a7d3 100644 --- a/clients/ios/Classes/FontSettingsViewController.m +++ b/clients/ios/Classes/FontSettingsViewController.m @@ -52,17 +52,17 @@ } } - if([userPreferences stringForKey:@"fontSizing"]){ - NSString *fontSize = [NSString stringWithFormat:@"%@", [userPreferences stringForKey:@"fontSizing"]]; - if ([fontSize isEqualToString:@"NB-extra-small"]) { + if([userPreferences stringForKey:@"story_font_size"]){ + NSString *fontSize = [userPreferences stringForKey:@"story_font_size"]; + if ([fontSize isEqualToString:@"xs"]) { [fontSizeSegment setSelectedSegmentIndex:0]; - } else if ([fontSize isEqualToString:@"NB-small"]) { + } else if ([fontSize isEqualToString:@"small"]) { [fontSizeSegment setSelectedSegmentIndex:1]; - } else if ([fontSize isEqualToString:@"NB-medium"]) { + } else if ([fontSize isEqualToString:@"medium"]) { [fontSizeSegment setSelectedSegmentIndex:2]; - } else if ([fontSize isEqualToString:@"NB-large"]) { + } else if ([fontSize isEqualToString:@"large"]) { [fontSizeSegment setSelectedSegmentIndex:3]; - } else if ([fontSize isEqualToString:@"NB-extra-large"]) { + } else if ([fontSize isEqualToString:@"xl"]) { [fontSizeSegment setSelectedSegmentIndex:4]; } } @@ -94,20 +94,20 @@ - (IBAction)changeFontSize:(id)sender { NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; if ([sender selectedSegmentIndex] == 0) { - [appDelegate.storyPageControl changeFontSize:@"NB-extra-small"]; - [userPreferences setObject:@"NB-extra-small" forKey:@"fontSizing"]; + [appDelegate.storyPageControl changeFontSize:@"xs"]; + [userPreferences setObject:@"xs" forKey:@"story_font_size"]; } else if ([sender selectedSegmentIndex] == 1) { - [appDelegate.storyPageControl changeFontSize:@"NB-small"]; - [userPreferences setObject:@"NB-small" forKey:@"fontSizing"]; + [appDelegate.storyPageControl changeFontSize:@"small"]; + [userPreferences setObject:@"small" forKey:@"story_font_size"]; } else if ([sender selectedSegmentIndex] == 2) { - [appDelegate.storyPageControl changeFontSize:@"NB-medium"]; - [userPreferences setObject:@"NB-medium" forKey:@"fontSizing"]; + [appDelegate.storyPageControl changeFontSize:@"medium"]; + [userPreferences setObject:@"medium" forKey:@"story_font_size"]; } else if ([sender selectedSegmentIndex] == 3) { - [appDelegate.storyPageControl changeFontSize:@"NB-large"]; - [userPreferences setObject:@"NB-large" forKey:@"fontSizing"]; + [appDelegate.storyPageControl changeFontSize:@"large"]; + [userPreferences setObject:@"large" forKey:@"story_font_size"]; } else if ([sender selectedSegmentIndex] == 4) { - [appDelegate.storyPageControl changeFontSize:@"NB-extra-large"]; - [userPreferences setObject:@"NB-extra-large" forKey:@"fontSizing"]; + [appDelegate.storyPageControl changeFontSize:@"xl"]; + [userPreferences setObject:@"xl" forKey:@"story_font_size"]; } [userPreferences synchronize]; } diff --git a/clients/ios/Classes/NewsBlurAppDelegate.h b/clients/ios/Classes/NewsBlurAppDelegate.h index f7cadc6d7..cea48a171 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.h +++ b/clients/ios/Classes/NewsBlurAppDelegate.h @@ -43,7 +43,8 @@ @class IASKAppSettingsViewController; @class UnreadCounts; -@interface NewsBlurAppDelegate : BaseViewController { +@interface NewsBlurAppDelegate : BaseViewController + { UIWindow *window; UINavigationController *ftuxNavigationController; UINavigationController *navigationController; diff --git a/clients/ios/Classes/NewsBlurViewController.m b/clients/ios/Classes/NewsBlurViewController.m index bee37cfa3..267e5d135 100644 --- a/clients/ios/Classes/NewsBlurViewController.m +++ b/clients/ios/Classes/NewsBlurViewController.m @@ -864,6 +864,7 @@ static UIFont *userLabelFont; } else { [appDelegate.navigationController dismissViewControllerAnimated:YES completion:nil]; } + [self.feedTitlesTable reloadData]; } - (void)settingDidChange:(NSNotification*)notification { diff --git a/clients/ios/Classes/StoryDetailViewController.m b/clients/ios/Classes/StoryDetailViewController.m index 0db1f37f2..068f18cce 100644 --- a/clients/ios/Classes/StoryDetailViewController.m +++ b/clients/ios/Classes/StoryDetailViewController.m @@ -130,7 +130,7 @@ NSString *sharingHtmlString; NSString *footerString; NSString *fontStyleClass = @""; - NSString *fontSizeClass = @""; + NSString *fontSizeClass = @"NB-"; NSString *storyContent = [self.activeStory objectForKey:@"story_content"]; NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; @@ -139,11 +139,7 @@ } else { fontStyleClass = [fontStyleClass stringByAppendingString:@"NB-san-serif"]; } - if ([userPreferences stringForKey:@"fontSizing"]){ - fontSizeClass = [fontSizeClass stringByAppendingString:[userPreferences stringForKey:@"fontSizing"]]; - } else { - fontSizeClass = [fontSizeClass stringByAppendingString:@"NB-medium"]; - } + fontSizeClass = [fontSizeClass stringByAppendingString:[userPreferences stringForKey:@"story_font_size"]]; int contentWidth = self.appDelegate.storyPageControl.view.frame.size.width; NSString *contentWidthClass; @@ -1071,18 +1067,14 @@ shouldStartLoadWithRequest:(NSURLRequest *)request - (void)webViewDidStartLoad:(UIWebView *)webView { NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; - if ([userPreferences integerForKey:@"fontSizing"]){ - [self changeFontSize:[userPreferences stringForKey:@"fontSizing"]]; - } + [self changeFontSize:[userPreferences stringForKey:@"story_font_size"]]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults]; - if ([userPreferences integerForKey:@"fontSizing"]){ - [self changeFontSize:[userPreferences stringForKey:@"fontSizing"]]; - } + [self changeFontSize:[userPreferences stringForKey:@"story_font_size"]]; if ([appDelegate.activeFeedStories count] && self.activeStoryId && @@ -1138,7 +1130,7 @@ shouldStartLoadWithRequest:(NSURLRequest *)request } - (void)changeFontSize:(NSString *)fontSize { - NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementById('NB-font-size').setAttribute('class', '%@')", + NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementById('NB-font-size').setAttribute('class', 'NB-%@')", fontSize]; [self.webView stringByEvaluatingJavaScriptFromString:jsString]; diff --git a/clients/ios/Resources/Settings.bundle/Root.plist b/clients/ios/Resources/Settings.bundle/Root.plist index 9852e1aac..feca01c48 100644 --- a/clients/ios/Resources/Settings.bundle/Root.plist +++ b/clients/ios/Resources/Settings.bundle/Root.plist @@ -70,6 +70,74 @@ Key default_feed_read_filter + + Title + Text Size + Type + PSGroupSpecifier + + + Type + PSToggleSwitchSpecifier + Title + Use system size + Key + use_system_font_size + DefaultValue + + + + Type + PSMultiValueSpecifier + Title + Feed and story list + Titles + + Extra small + Small + Medium + Large + Extra Large + + DefaultValue + medium + Values + + xs + small + medium + large + xl + + Key + feed_list_font_size + + + Type + PSMultiValueSpecifier + Title + Story detail + Titles + + Extra small + Small + Medium + Large + Extra Large + + DefaultValue + medium + Values + + xs + small + medium + large + xl + + Key + story_font_size + Title Offline stories diff --git a/clients/ios/static/storyDetailView.css b/clients/ios/static/storyDetailView.css index bc89991d7..c1f4e84c5 100644 --- a/clients/ios/static/storyDetailView.css +++ b/clients/ios/static/storyDetailView.css @@ -5,9 +5,9 @@ .NB-story { line-height: 1.5em; } -.NB-extra-small .NB-story, -.NB-extra-small .NB-story-comment, -.NB-extra-small .NB-header { +.NB-xs .NB-story, +.NB-xs .NB-story-comment, +.NB-xs .NB-header { font-size: 12px; } @@ -29,9 +29,9 @@ font-size: 15px; } -.NB-extra-large .NB-story, -.NB-extra-large .NB-story-comment, -.NB-extra-large .NB-header { +.NB-xl .NB-story, +.NB-xl .NB-story-comment, +.NB-xl .NB-header { font-size: 17px; } @@ -212,7 +212,7 @@ body.NB-iphone { background: transparent url("data:image/png;charset=utf-8;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACVElEQVQ4EXVTPW8TQRCd/XCM7QgF2QSnsYQbRGKgpA+QitY/IBUSrgAjQWW5oojocCTSRKJ1SRMpgCIhIVrERwlSmthnsBXLd7bPtzvM7HFgkDlrvbuz782+N7srEBHmv/395+tCQY2imwCiHK/hVwHwBg20trfvfJnHiyRBu91eGgU/dohYI4CaB82NDSVqLWfzD6vVashxl4DJQ//7S5pvcbB4YQ2KxTXIZDI8hfF4DJ3OCXS6J25OtMOzufxtTiI5cjrq7ViLW+l0GiqVq1AqlUBrDWEYusZjjvEaY6y1t5jDXLG392wDJX6gsapsXCHAGTA2YhAk9oQQIKUEJTVMpxP49PkjAEKECq9pC+YuWlCr51dBKQWTyRiM+U8CpZ2yQr4AXs/TIoKaNoibVBhYWTlH5AlE0YwUGECLtEl8QgLoJwUpUJQg5bBdrwuWTkqT1DIn4I/lRf/sHq+Q1182jDEuibMIUNZI+vkqTMOpk86AxHtCTnpOwsSIMNxT2pAVfCOll4LAd4ViciI9ISY9W2GitVPX0/xYgsHX7HcwGJAC45o1BFrQknXGuhpZeyStwV2L1gyHQ1fEeAfeZXHjQjOWOcxVBweHvXfv3xZI+nVeTKVSrmDOCtuZa3yx+v2+U0m2WvfvPXqh2d/oNKxnl/Xl2Wx20/M8yGazkMvl3JlzApbu+z4EQRCXA+GVP5rVefL7MTWbzaVMTtL1FPwSFz4mOm6DAnYnI1NvNBp/HlOcNv5/8rS5LlDW6Chu0H29SH1IxT8mX0cobOvxg8Zfz/knWROSyKoTDHAAAAAASUVORK5CYII=") no-repeat center center; background-size: 8px; } -.NB-extra-small .NB-story-unread { +.NB-xs .NB-story-unread { margin-top: 4px; } .NB-small .NB-story-unread { @@ -221,7 +221,7 @@ body.NB-iphone { .NB-large .NB-story-unread { margin-top: 7px; } -.NB-extra-large .NB-story-unread { +.NB-xl .NB-story-unread { margin-top: 8px; } .NB-story-unread.NB-positive {