2012-06-18 14:31:42 -07:00
|
|
|
//
|
|
|
|
// 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"
|
2012-11-05 17:16:10 -08:00
|
|
|
#import "StoryPageControl.h"
|
2012-10-17 18:09:20 -07:00
|
|
|
#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"
|
2012-06-18 14:31:42 -07:00
|
|
|
|
|
|
|
@implementation FontSettingsViewController
|
|
|
|
|
2012-10-15 09:16:01 -07:00
|
|
|
#define kMenuOptionHeight 38
|
|
|
|
|
2012-06-18 14:31:42 -07:00
|
|
|
@synthesize appDelegate;
|
2012-06-24 23:02:37 -07:00
|
|
|
@synthesize fontStyleSegment;
|
2012-06-26 23:12:54 -07:00
|
|
|
@synthesize fontSizeSegment;
|
2012-10-15 09:16:01 -07:00
|
|
|
@synthesize menuTableView;
|
2012-06-18 14:31:42 -07:00
|
|
|
|
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
|
|
|
{
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
if (self) {
|
|
|
|
// Custom initialization
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
2013-04-15 10:29:39 -07:00
|
|
|
self.menuTableView.backgroundColor = UIColorFromRGB(0xECEEEA);
|
|
|
|
self.menuTableView.separatorColor = UIColorFromRGB(0x909090);
|
2012-06-24 23:02:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2012-10-15 09:16:01 -07:00
|
|
|
self.appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
2012-07-14 01:16:35 -07:00
|
|
|
|
2012-06-24 23:02:37 -07:00
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
2012-06-26 23:12:54 -07:00
|
|
|
|
2012-06-24 23:02:37 -07:00
|
|
|
if ([userPreferences stringForKey:@"fontStyle"]) {
|
|
|
|
if ([[userPreferences stringForKey:@"fontStyle"] isEqualToString:@"NB-san-serif"]) {
|
2012-06-26 23:12:54 -07:00
|
|
|
[fontStyleSegment setSelectedSegmentIndex:0];
|
2012-06-24 23:02:37 -07:00
|
|
|
} else if ([[userPreferences stringForKey:@"fontStyle"] isEqualToString:@"NB-serif"]) {
|
2012-06-26 23:12:54 -07:00
|
|
|
[fontStyleSegment setSelectedSegmentIndex:1];
|
2012-06-24 23:02:37 -07:00
|
|
|
}
|
|
|
|
}
|
2012-06-26 23:12:54 -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];
|
2012-06-18 14:31:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload
|
|
|
|
{
|
2012-06-26 23:12:54 -07:00
|
|
|
|
2012-06-18 14:31:42 -07:00
|
|
|
[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];
|
2012-06-18 14:31:42 -07:00
|
|
|
} else {
|
2012-06-24 23:02:37 -07:00
|
|
|
[self setSerif];
|
2012-06-18 14:31:42 -07:00
|
|
|
}
|
2012-06-24 23:02:37 -07:00
|
|
|
}
|
2012-06-18 14:31:42 -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"];
|
2012-06-26 23:12:54 -07:00
|
|
|
[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"];
|
2012-06-26 23:12:54 -07:00
|
|
|
[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"];
|
2012-06-26 23:12:54 -07:00
|
|
|
[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"];
|
2012-06-26 23:12:54 -07:00
|
|
|
[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"];
|
2012-06-26 23:12:54 -07:00
|
|
|
[userPreferences setObject:@"NB-extra-large" forKey:@"fontSizing"];
|
2012-06-24 23:02:37 -07:00
|
|
|
}
|
|
|
|
[userPreferences synchronize];
|
2012-06-18 14:31:42 -07:00
|
|
|
}
|
|
|
|
|
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-18 14:31:42 -07:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2012-10-15 09:16:01 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
|
{
|
2012-12-27 00:15:26 -08:00
|
|
|
return 7;
|
2012-10-15 09:16:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
static NSString *CellIndentifier = @"Cell";
|
|
|
|
|
|
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
|
|
|
|
|
2012-12-27 00:15:26 -08:00
|
|
|
if (indexPath.row == 5) {
|
2012-10-15 09:16:01 -07:00
|
|
|
return [self makeFontSelectionTableCell];
|
2012-12-27 00:15:26 -08:00
|
|
|
} else if (indexPath.row == 6) {
|
2012-10-15 09:16:01 -07:00
|
|
|
return [self makeFontSizeTableCell];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell == nil) {
|
2012-10-16 15:48:04 -07:00
|
|
|
cell = [[MenuTableViewCell alloc]
|
2012-10-15 09:16:01 -07:00
|
|
|
initWithStyle:UITableViewCellStyleDefault
|
|
|
|
reuseIdentifier:CellIndentifier];
|
|
|
|
}
|
2012-10-16 15:48:04 -07:00
|
|
|
|
2012-10-15 09:16:01 -07:00
|
|
|
if (indexPath.row == 0) {
|
2012-10-17 15:07:53 -07:00
|
|
|
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"];
|
2012-10-15 09:16:01 -07:00
|
|
|
} else if (indexPath.row == 1) {
|
2012-10-17 15:07:53 -07:00
|
|
|
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];
|
|
|
|
}
|
2013-02-26 19:58:30 -08:00
|
|
|
cell.imageView.image = [UIImage imageNamed:@"g_icn_unread.png"];
|
2012-10-15 09:16:01 -07:00
|
|
|
} else if (indexPath.row == 2) {
|
|
|
|
cell.textLabel.text = [@"Send to..." uppercaseString];
|
2013-04-23 11:52:34 -07:00
|
|
|
cell.imageView.image = [UIImage imageNamed:@"menu_icn_mail.png"];
|
2012-10-17 15:07:53 -07:00
|
|
|
} else if (indexPath.row == 3) {
|
2012-12-27 00:15:26 -08:00
|
|
|
cell.textLabel.text = [@"Train this story" uppercaseString];
|
2013-03-07 10:55:23 -05:00
|
|
|
cell.imageView.image = [UIImage imageNamed:@"menu_icn_train.png"];
|
2012-12-27 00:15:26 -08:00
|
|
|
} else if (indexPath.row == 4) {
|
2012-10-17 15:07:53 -07:00
|
|
|
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-15 09:16:01 -07:00
|
|
|
}
|
2012-10-16 15:48:04 -07:00
|
|
|
|
2012-10-15 09:16:01 -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 {
|
2012-12-27 00:15:26 -08:00
|
|
|
if (indexPath.row >= 5) {
|
2012-10-16 15:48:04 -07:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
return indexPath;
|
|
|
|
}
|
|
|
|
|
2012-10-15 09:16:01 -07:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
if (indexPath.row == 0) {
|
2012-10-17 15:07:53 -07:00
|
|
|
bool isSaved = [[appDelegate.activeStory objectForKey:@"starred"] boolValue];
|
|
|
|
if (isSaved) {
|
2012-11-05 17:16:10 -08:00
|
|
|
[appDelegate.storyPageControl markStoryAsUnsaved];
|
2012-10-17 15:07:53 -07:00
|
|
|
} else {
|
2012-11-05 17:16:10 -08:00
|
|
|
[appDelegate.storyPageControl markStoryAsSaved];
|
2012-10-17 15:07:53 -07:00
|
|
|
}
|
2012-10-15 09:16:01 -07:00
|
|
|
} else if (indexPath.row == 1) {
|
2012-10-17 15:07:53 -07:00
|
|
|
bool isRead = [[appDelegate.activeStory objectForKey:@"read_status"] boolValue];
|
|
|
|
if (isRead) {
|
2012-11-05 17:16:10 -08:00
|
|
|
[appDelegate.storyPageControl markStoryAsUnread];
|
2012-10-17 15:07:53 -07:00
|
|
|
} else {
|
2012-11-05 17:16:10 -08:00
|
|
|
[appDelegate.storyPageControl markStoryAsRead];
|
2012-10-17 18:09:20 -07:00
|
|
|
[appDelegate.feedDetailViewController redrawUnreadStory];
|
2012-10-17 15:07:53 -07:00
|
|
|
}
|
2012-10-15 09:16:01 -07:00
|
|
|
} else if (indexPath.row == 2) {
|
2013-09-07 02:35:47 -05:00
|
|
|
[appDelegate.storyPageControl openSendToDialog:appDelegate.storyPageControl.fontSettingsButton];
|
2012-10-17 15:07:53 -07:00
|
|
|
} else if (indexPath.row == 3) {
|
2012-12-27 23:04:25 -08:00
|
|
|
[appDelegate openTrainStory:appDelegate.storyPageControl.fontSettingsButton];
|
2012-12-27 00:15:26 -08:00
|
|
|
} else if (indexPath.row == 4) {
|
2012-11-09 14:13:44 -08:00
|
|
|
[appDelegate.storyPageControl.currentPage openShareDialog];
|
2012-10-15 09:16:01 -07:00
|
|
|
}
|
2013-09-07 02:35:47 -05:00
|
|
|
|
2012-10-15 09:16:01 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2013-09-07 02:35:47 -05:00
|
|
|
if (indexPath.row != 2 && indexPath.row != 3) {
|
|
|
|
// if we're opening another popover, then don't animate out - it looks strange
|
|
|
|
[appDelegate.masterContainerViewController hidePopover];
|
|
|
|
}
|
2012-10-15 09:16:01 -07:00
|
|
|
} else {
|
2012-11-05 17:16:10 -08:00
|
|
|
[appDelegate.storyPageControl.popoverController dismissPopoverAnimated:YES];
|
|
|
|
appDelegate.storyPageControl.popoverController = nil;
|
2012-10-15 09:16:01 -07:00
|
|
|
}
|
|
|
|
[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;
|
|
|
|
|
2012-10-15 18:34:53 -07:00
|
|
|
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];
|
|
|
|
|
2012-10-15 09:16:01 -07:00
|
|
|
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;
|
2012-10-15 09:16:01 -07:00
|
|
|
|
2012-10-15 18:34:53 -07:00
|
|
|
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];
|
2012-10-15 18:34:53 -07:00
|
|
|
[fontSizeSegment setTitle:@"14pt" forSegmentAtIndex:2];
|
2012-12-11 17:53:17 -08:00
|
|
|
[fontSizeSegment setTitle:@"15pt" forSegmentAtIndex:3];
|
|
|
|
[fontSizeSegment setTitle:@"17pt" forSegmentAtIndex:4];
|
2012-10-15 18:34:53 -07:00
|
|
|
[fontSizeSegment setTintColor:UIColorFromRGB(0x738570)];
|
|
|
|
|
|
|
|
[cell addSubview:fontSizeSegment];
|
|
|
|
|
2012-10-15 09:16:01 -07:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-18 14:31:42 -07:00
|
|
|
@end
|