NewsBlur/clients/ios/Classes/FontSettingsViewController.m

265 lines
9.4 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
}
}
if([userPreferences stringForKey:@"fontSizing"]){
NSString *fontSize = [NSString stringWithFormat:@"%@", [userPreferences stringForKey:@"fontSizing"]];
if ([fontSize isEqualToString:@"NB-extra-small"]) {
[fontSizeSegment setSelectedSegmentIndex:0];
} else if ([fontSize isEqualToString:@"NB-small"]) {
[fontSizeSegment setSelectedSegmentIndex:1];
} else if ([fontSize isEqualToString:@"NB-medium"]) {
[fontSizeSegment setSelectedSegmentIndex:2];
} else if ([fontSize isEqualToString:@"NB-large"]) {
[fontSizeSegment setSelectedSegmentIndex:3];
} else if ([fontSize isEqualToString:@"NB-extra-large"]) {
[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) {
2012-11-09 14:13:44 -08:00
[appDelegate.storyPageControl changeFontSize:@"NB-extra-small"];
[userPreferences setObject:@"NB-extra-small" forKey:@"fontSizing"];
2012-06-24 23:02:37 -07:00
} else if ([sender selectedSegmentIndex] == 1) {
2012-11-09 14:13:44 -08:00
[appDelegate.storyPageControl changeFontSize:@"NB-small"];
[userPreferences setObject:@"NB-small" forKey:@"fontSizing"];
2012-06-24 23:02:37 -07:00
} else if ([sender selectedSegmentIndex] == 2) {
2012-11-09 14:13:44 -08:00
[appDelegate.storyPageControl changeFontSize:@"NB-medium"];
[userPreferences setObject:@"NB-medium" forKey:@"fontSizing"];
2012-06-24 23:02:37 -07:00
} else if ([sender selectedSegmentIndex] == 3) {
2012-11-09 14:13:44 -08:00
[appDelegate.storyPageControl changeFontSize:@"NB-large"];
[userPreferences setObject:@"NB-large" forKey:@"fontSizing"];
2012-06-24 23:02:37 -07:00
} else if ([sender selectedSegmentIndex] == 4) {
2012-11-09 14:13:44 -08:00
[appDelegate.storyPageControl changeFontSize:@"NB-extra-large"];
[userPreferences setObject:@"NB-extra-large" forKey:@"fontSizing"];
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;
}
- (float)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) {
bool isSaved = [[appDelegate.activeStory objectForKey:@"starred"] boolValue];
if (isSaved) {
[appDelegate.storyPageControl markStoryAsUnsaved];
} else {
[appDelegate.storyPageControl markStoryAsSaved];
}
} else if (indexPath.row == 1) {
bool isRead = [[appDelegate.activeStory objectForKey:@"read_status"] boolValue];
if (isRead) {
[appDelegate.storyPageControl markStoryAsUnread];
} else {
[appDelegate.storyPageControl markStoryAsRead];
[appDelegate.feedDetailViewController redrawUnreadStory];
}
} 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;
fontStyleSegment.frame = CGRectMake(8, 4, cell.frame.size.width - 8*2, kMenuOptionHeight - 4*2);
[fontStyleSegment setTitle:@"Helvetica" forSegmentAtIndex:0];
[fontStyleSegment setTitle:@"Georgia" forSegmentAtIndex:1];
[fontStyleSegment setTintColor:UIColorFromRGB(0x738570)];
[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;
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)];
[cell addSubview:fontSizeSegment];
return cell;
}
@end