NewsBlur/clients/ios/Classes/FontSettingsViewController.m

270 lines
9.8 KiB
Mathematica
Raw Normal View History

//
// FontPopover.m
// NewsBlur
//
// Created by Roy Yang on 6/18/12.
// Copyright (c) 2012 NewsBlur. All rights reserved.
//
#import "FontSettingsViewController.h"
#import "NewsBlurAppDelegate.h"
#import "StoryDetailViewController.h"
#import "StoryPageControl.h"
#import "FeedDetailViewController.h"
2012-10-16 15:48:04 -07:00
#import "MenuTableViewCell.h"
2012-10-16 17:24:01 -07:00
#import "NBContainerViewController.h"
@implementation FontSettingsViewController
#define kMenuOptionHeight 38
@synthesize appDelegate;
2012-06-24 23:02:37 -07:00
@synthesize fontStyleSegment;
@synthesize fontSizeSegment;
@synthesize menuTableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.menuTableView.backgroundColor = UIColorFromRGB(0xECEEEA);
self.menuTableView.separatorColor = UIColorFromRGB(0x909090);
2012-06-24 23:02:37 -07:00
}
- (void)viewWillAppear:(BOOL)animated {
self.appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
2012-06-24 23:02:37 -07:00
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
2012-06-24 23:02:37 -07:00
if ([userPreferences stringForKey:@"fontStyle"]) {
if ([[userPreferences stringForKey:@"fontStyle"] isEqualToString:@"NB-san-serif"]) {
[fontStyleSegment setSelectedSegmentIndex:0];
2012-06-24 23:02:37 -07:00
} else if ([[userPreferences stringForKey:@"fontStyle"] isEqualToString:@"NB-serif"]) {
[fontStyleSegment setSelectedSegmentIndex:1];
2012-06-24 23:02:37 -07:00
}
}
2013-11-23 13:03:14 -08:00
if([userPreferences stringForKey:@"story_font_size"]){
NSString *fontSize = [userPreferences stringForKey:@"story_font_size"];
if ([fontSize isEqualToString:@"xs"]) {
[fontSizeSegment setSelectedSegmentIndex:0];
2013-11-23 13:03:14 -08:00
} else if ([fontSize isEqualToString:@"small"]) {
[fontSizeSegment setSelectedSegmentIndex:1];
2013-11-23 13:03:14 -08:00
} else if ([fontSize isEqualToString:@"medium"]) {
[fontSizeSegment setSelectedSegmentIndex:2];
2013-11-23 13:03:14 -08:00
} else if ([fontSize isEqualToString:@"large"]) {
[fontSizeSegment setSelectedSegmentIndex:3];
2013-11-23 13:03:14 -08:00
} else if ([fontSize isEqualToString:@"xl"]) {
[fontSizeSegment setSelectedSegmentIndex:4];
2012-06-24 23:02:37 -07:00
}
}
2012-10-16 15:48:04 -07:00
[self.menuTableView reloadData];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (IBAction)changeFontStyle:(id)sender {
if ([sender selectedSegmentIndex] == 0) {
2012-06-24 23:02:37 -07:00
[self setSanSerif];
} else {
2012-06-24 23:02:37 -07:00
[self setSerif];
}
2012-06-24 23:02:37 -07:00
}
2012-06-24 23:02:37 -07:00
- (IBAction)changeFontSize:(id)sender {
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
if ([sender selectedSegmentIndex] == 0) {
2013-11-23 13:03:14 -08:00
[appDelegate.storyPageControl changeFontSize:@"xs"];
[userPreferences setObject:@"xs" forKey:@"story_font_size"];
2012-06-24 23:02:37 -07:00
} else if ([sender selectedSegmentIndex] == 1) {
2013-11-23 13:03:14 -08:00
[appDelegate.storyPageControl changeFontSize:@"small"];
[userPreferences setObject:@"small" forKey:@"story_font_size"];
2012-06-24 23:02:37 -07:00
} else if ([sender selectedSegmentIndex] == 2) {
2013-11-23 13:03:14 -08:00
[appDelegate.storyPageControl changeFontSize:@"medium"];
[userPreferences setObject:@"medium" forKey:@"story_font_size"];
2012-06-24 23:02:37 -07:00
} else if ([sender selectedSegmentIndex] == 3) {
2013-11-23 13:03:14 -08:00
[appDelegate.storyPageControl changeFontSize:@"large"];
[userPreferences setObject:@"large" forKey:@"story_font_size"];
2012-06-24 23:02:37 -07:00
} else if ([sender selectedSegmentIndex] == 4) {
2013-11-23 13:03:14 -08:00
[appDelegate.storyPageControl changeFontSize:@"xl"];
[userPreferences setObject:@"xl" forKey:@"story_font_size"];
2012-06-24 23:02:37 -07:00
}
[userPreferences synchronize];
}
2012-06-24 23:02:37 -07:00
- (void)setSanSerif {
[fontStyleSegment setSelectedSegmentIndex:0];
2012-11-09 14:13:44 -08:00
[appDelegate.storyPageControl setFontStyle:@"Helvetica"];
}
2012-06-24 23:02:37 -07:00
- (void)setSerif {
[fontStyleSegment setSelectedSegmentIndex:1];
2012-11-09 14:13:44 -08:00
[appDelegate.storyPageControl setFontStyle:@"Georgia"];
2012-06-24 23:02:37 -07:00
}
#pragma mark -
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 7;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIndentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
if (indexPath.row == 5) {
return [self makeFontSelectionTableCell];
} else if (indexPath.row == 6) {
return [self makeFontSizeTableCell];
}
if (cell == nil) {
2012-10-16 15:48:04 -07:00
cell = [[MenuTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIndentifier];
}
2012-10-16 15:48:04 -07:00
if (indexPath.row == 0) {
bool isSaved = [[appDelegate.activeStory objectForKey:@"starred"] boolValue];
if (isSaved) {
cell.textLabel.text = [@"Unsave this story" uppercaseString];
} else {
cell.textLabel.text = [@"Save this story" uppercaseString];
}
2013-03-07 10:55:23 -05:00
cell.imageView.image = [UIImage imageNamed:@"clock.png"];
} else if (indexPath.row == 1) {
bool isRead = [[appDelegate.activeStory objectForKey:@"read_status"] boolValue];
if (isRead) {
cell.textLabel.text = [@"Mark as unread" uppercaseString];
} else {
cell.textLabel.text = [@"Mark as read" uppercaseString];
}
cell.imageView.image = [UIImage imageNamed:@"g_icn_unread.png"];
} else if (indexPath.row == 2) {
cell.textLabel.text = [@"Send to..." uppercaseString];
cell.imageView.image = [UIImage imageNamed:@"menu_icn_mail.png"];
} else if (indexPath.row == 3) {
cell.textLabel.text = [@"Train this story" uppercaseString];
2013-03-07 10:55:23 -05:00
cell.imageView.image = [UIImage imageNamed:@"menu_icn_train.png"];
} else if (indexPath.row == 4) {
cell.textLabel.text = [@"Share this story" uppercaseString];
2013-03-07 10:55:23 -05:00
cell.imageView.image = [UIImage imageNamed:@"menu_icn_share.png"];
}
2012-10-16 15:48:04 -07:00
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return kMenuOptionHeight;
}
2012-10-16 15:48:04 -07:00
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row >= 5) {
2012-10-16 15:48:04 -07:00
return nil;
}
return indexPath;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
[appDelegate toggleStorySaved];
} else if (indexPath.row == 1) {
[appDelegate toggleStoryUnread];
} else if (indexPath.row == 2) {
[appDelegate.storyPageControl openSendToDialog:appDelegate.storyPageControl.fontSettingsButton];
} else if (indexPath.row == 3) {
[appDelegate openTrainStory:appDelegate.storyPageControl.fontSettingsButton];
} else if (indexPath.row == 4) {
2012-11-09 14:13:44 -08:00
[appDelegate.storyPageControl.currentPage openShareDialog];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (indexPath.row != 2 && indexPath.row != 3) {
// if we're opening another popover, then don't animate out - it looks strange
[appDelegate.masterContainerViewController hidePopover];
}
} else {
[appDelegate.storyPageControl.popoverController dismissPopoverAnimated:YES];
appDelegate.storyPageControl.popoverController = nil;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (UITableViewCell *)makeFontSelectionTableCell {
UITableViewCell *cell = [[UITableViewCell alloc] init];
cell.frame = CGRectMake(0, 0, 240, kMenuOptionHeight);
2012-10-16 15:48:04 -07:00
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.separatorInset = UIEdgeInsetsZero;
fontStyleSegment.frame = CGRectMake(8, 4, cell.frame.size.width - 8*2, kMenuOptionHeight - 4*2);
[fontStyleSegment setTitle:[@"Helvetica" uppercaseString] forSegmentAtIndex:0];
[fontStyleSegment setTitle:[@"Georgia" uppercaseString] forSegmentAtIndex:1];
[fontStyleSegment setTintColor:UIColorFromRGB(0x738570)];
[fontStyleSegment
setTitleTextAttributes:@{NSFontAttributeName:
[UIFont fontWithName:@"Helvetica-Bold" size:11.0f]}
forState:UIControlStateNormal];
[fontStyleSegment setContentOffset:CGSizeMake(0, 1) forSegmentAtIndex:0];
[fontStyleSegment setContentOffset:CGSizeMake(0, 1) forSegmentAtIndex:1];
[cell addSubview:fontStyleSegment];
return cell;
}
- (UITableViewCell *)makeFontSizeTableCell {
UITableViewCell *cell = [[UITableViewCell alloc] init];
cell.frame = CGRectMake(0, 0, 240, kMenuOptionHeight);
2012-10-16 15:48:04 -07:00
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.separatorInset = UIEdgeInsetsZero;
fontSizeSegment.frame = CGRectMake(8, 4, cell.frame.size.width - 8*2, kMenuOptionHeight - 4*2);
2012-12-11 17:53:17 -08:00
[fontSizeSegment setTitle:@"12pt" forSegmentAtIndex:0];
[fontSizeSegment setTitle:@"13pt" forSegmentAtIndex:1];
[fontSizeSegment setTitle:@"14pt" forSegmentAtIndex:2];
2012-12-11 17:53:17 -08:00
[fontSizeSegment setTitle:@"15pt" forSegmentAtIndex:3];
[fontSizeSegment setTitle:@"17pt" forSegmentAtIndex:4];
[fontSizeSegment setTintColor:UIColorFromRGB(0x738570)];
[fontSizeSegment
setTitleTextAttributes:@{NSFontAttributeName:
[UIFont fontWithName:@"Helvetica-Bold" size:11.0f]}
forState:UIControlStateNormal];
[fontSizeSegment setContentOffset:CGSizeMake(0, 1) forSegmentAtIndex:0];
[fontSizeSegment setContentOffset:CGSizeMake(0, 1) forSegmentAtIndex:1];
[fontSizeSegment setContentOffset:CGSizeMake(0, 1) forSegmentAtIndex:2];
[fontSizeSegment setContentOffset:CGSizeMake(0, 1) forSegmentAtIndex:3];
[fontSizeSegment setContentOffset:CGSizeMake(0, 1) forSegmentAtIndex:4];
[cell addSubview:fontSizeSegment];
return cell;
}
@end