// // StoryDetailViewController.m // NewsBlur // // Created by Samuel Clay on 6/24/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "StoryDetailViewController.h" #import "NewsBlurAppDelegate.h" #import "FeedDetailViewController.h" #import "FontSettingsViewController.h" #import "SplitStoryDetailViewController.h" #import "ASIHTTPRequest.h" #import "ASIFormDataRequest.h" #import "Base64.h" #import "Utilities.h" @implementation StoryDetailViewController @synthesize appDelegate; @synthesize activeStoryId; @synthesize progressView; @synthesize webView; @synthesize toolbar; @synthesize buttonPrevious; @synthesize buttonNext; @synthesize buttonAction; @synthesize activity; @synthesize loadingIndicator; @synthesize feedTitleGradient; @synthesize popoverController; #pragma mark - #pragma mark View boilerplate - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { } return self; } - (void)dealloc { [activeStoryId release]; [appDelegate release]; [progressView release]; [webView release]; [toolbar release]; [buttonNext release]; [buttonPrevious release]; [buttonAction release]; [activity release]; [loadingIndicator release]; [feedTitleGradient release]; [popoverController release]; [super dealloc]; } - (void)viewDidLoad { UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; backBtn.frame = CGRectMake(0, 0, 51, 31); [backBtn setImage:[UIImage imageNamed:@"nav_btn_back.png"] forState:UIControlStateNormal]; [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *back = [[[UIBarButtonItem alloc] initWithCustomView:backBtn] autorelease]; self.navigationItem.backBarButtonItem = back; self.loadingIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease]; [super viewDidLoad]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)viewWillAppear:(BOOL)animated { id storyId = [appDelegate.activeStory objectForKey:@"id"]; if (self.activeStoryId != storyId) { [appDelegate pushReadStory:storyId]; [self setActiveStory]; [self showStory]; [self markStoryAsRead]; [self setNextPreviousButtons]; self.webView.scalesPageToFit = YES; } [self.loadingIndicator stopAnimating]; [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { UIBarButtonItem *originalButton = [[UIBarButtonItem alloc] initWithTitle:@"Original" style:UIBarButtonItemStyleBordered target:self action:@selector(showOriginalSubview:) ]; if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad) { appDelegate.splitStoryDetailViewController.navigationItem.rightBarButtonItem = originalButton; } else { self.navigationItem.rightBarButtonItem = originalButton; } [originalButton release]; [super viewDidAppear:animated]; } - (void)viewDidDisappear:(BOOL)animated { Class viewClass = [appDelegate.navigationController.visibleViewController class]; if (viewClass == [appDelegate.feedDetailViewController class] || viewClass == [appDelegate.feedsViewController class]) { self.activeStoryId = nil; [webView loadHTMLString:@"" baseURL:[NSURL URLWithString:@""]]; } } #pragma mark - #pragma mark Story layout - (NSString *)getAvatars:(BOOL)areFriends { NSString *avatarString = @""; NSArray *share_user_ids; if (areFriends) { NSMutableArray *friends = [appDelegate.activeStory objectForKey:@"share_user_ids"]; NSArray *all_share_user_ids = [appDelegate.activeStory objectForKey:@"share_user_ids"]; NSArray *all_shared_by_public = [appDelegate.activeStory objectForKey:@"shared_by_public"]; for (int i = 0; i < all_share_user_ids.count; i++) { for (int j = 0; j < all_shared_by_public.count; j++) { if ([[all_share_user_ids objectAtIndex:i] intValue] == [[all_shared_by_public objectAtIndex:j] intValue]) { [friends removeObject:[all_share_user_ids objectAtIndex:i]]; break; } } } share_user_ids = [NSArray arrayWithArray:friends]; // only if your friends are sharing to do you see the shared label if ([share_user_ids count]) { avatarString = [avatarString stringByAppendingString:@ "
" " " " ", [[appDelegate.activeStory objectForKey:@"share_count"] intValue] == 1 ? [NSString stringWithFormat:@"1 person"] : [NSString stringWithFormat:@"%@ people", [appDelegate.activeStory objectForKey:@"share_count"]], [self getAvatars:NO], [self getAvatars:YES] ]]; for (int i = 0; i < comments_array.count; i++) { NSDictionary *comment_dict = [comments_array objectAtIndex:i]; NSDictionary *user = [self getUser:[[comment_dict objectForKey:@"user_id"] intValue]]; NSString *comment = [NSString stringWithFormat:@ "