2010-06-25 18:36:01 -04:00
|
|
|
//
|
|
|
|
// StoryDetailViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 6/24/10.
|
|
|
|
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "StoryDetailViewController.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2010-11-22 10:44:52 -05:00
|
|
|
#import "ASIHTTPRequest.h"
|
|
|
|
#import "ASIFormDataRequest.h"
|
2010-06-25 18:36:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
@implementation StoryDetailViewController
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
2010-06-27 19:35:17 -04:00
|
|
|
@synthesize webView;
|
2011-02-13 19:01:01 -05:00
|
|
|
@synthesize toolbar;
|
|
|
|
@synthesize buttonNext;
|
|
|
|
@synthesize buttonPrevious;
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
|
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
|
|
|
|
2011-03-09 18:23:55 -05:00
|
|
|
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
|
2010-06-25 18:36:01 -04:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2010-11-22 10:44:52 -05:00
|
|
|
[self showStory];
|
|
|
|
if ([[appDelegate.activeStory objectForKey:@"read_status"] intValue] != 1) {
|
|
|
|
[self markStoryAsRead];
|
|
|
|
}
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
2011-02-13 19:01:01 -05:00
|
|
|
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"Original"
|
|
|
|
style:UIBarButtonItemStyleBordered
|
|
|
|
target:self
|
|
|
|
action:@selector(showOriginalSubview:)
|
|
|
|
] autorelease];
|
2010-11-22 10:44:52 -05:00
|
|
|
[super viewDidAppear:animated];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markStoryAsRead {
|
|
|
|
[appDelegate.activeStory setValue:[NSDecimalNumber numberWithInt:1] forKey:@"read_status"];
|
|
|
|
|
|
|
|
NSString *urlString = @"http://nb.local.host:8000/reader/mark_story_as_read";
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
2011-06-16 09:02:40 -04:00
|
|
|
// ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
// [request setPostValue:[appDelegate.activeStory objectForKey:@"id"] forKey:@"story_id"];
|
|
|
|
// [request setPostValue:[appDelegate.activeFeed objectForKey:@"id"] forKey:@"feed_id"];
|
|
|
|
// [request setDelegate:self];
|
|
|
|
// [request startAsynchronous];
|
2010-11-22 10:44:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)requestFinished:(ASIHTTPRequest *)request {
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
initWithDictionary:[responseString JSONValue]];
|
|
|
|
int code = [[results valueForKey:@"code"] intValue];
|
|
|
|
NSLog(@"Read Story: %@", code);
|
|
|
|
|
|
|
|
[results release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request
|
|
|
|
{
|
2011-03-09 18:23:55 -05:00
|
|
|
// NSError *error = [request error];
|
|
|
|
// [error release];
|
2010-11-22 10:44:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)showStory {
|
2011-06-15 11:21:55 -04:00
|
|
|
// NSLog(@"Loaded Story view: %@", appDelegate.activeStory);
|
2010-07-15 23:32:37 -04:00
|
|
|
NSString *imgCssString = [NSString stringWithFormat:@"<style>"
|
|
|
|
"body {"
|
|
|
|
" line-height: 18px;"
|
|
|
|
" font-size: 13px;"
|
|
|
|
" font-family: 'Lucida Grande',Helvetica, Arial;"
|
|
|
|
" text-rendering: optimizeLegibility;"
|
2010-11-22 10:44:52 -05:00
|
|
|
" margin: 0;"
|
2010-07-15 23:32:37 -04:00
|
|
|
"}"
|
|
|
|
"img {"
|
|
|
|
" max-width: 300px;"
|
|
|
|
" width: auto;"
|
|
|
|
" height: auto;"
|
|
|
|
"}"
|
|
|
|
"blockquote {"
|
|
|
|
" background-color: #F0F0F0;"
|
|
|
|
" border-left: 1px solid #9B9B9B;"
|
|
|
|
" padding: .5em 2em;"
|
|
|
|
" margin: 0px;"
|
|
|
|
"}"
|
2010-11-22 10:44:52 -05:00
|
|
|
".NB-header {"
|
|
|
|
" font-size: 14px;"
|
|
|
|
" font-weight: bold;"
|
|
|
|
" background-color: #E0E0E0;"
|
|
|
|
" border-bottom: 1px solid #A0A0A0;"
|
2011-07-18 09:56:48 -07:00
|
|
|
" padding: 8px 8px 8px;"
|
2010-11-22 10:44:52 -05:00
|
|
|
" text-shadow: 1px 1px 0 #EFEFEF;"
|
|
|
|
"}"
|
|
|
|
".NB-story {"
|
2011-07-18 09:56:48 -07:00
|
|
|
" margin: 12px 8px;"
|
2010-11-22 10:44:52 -05:00
|
|
|
"}"
|
2011-06-13 10:44:17 -04:00
|
|
|
".NB-story-author {"
|
|
|
|
" color: #969696;"
|
|
|
|
" font-size: 10px;"
|
|
|
|
" text-transform: uppercase;"
|
2011-07-18 09:56:48 -07:00
|
|
|
" margin: 0 16px 2px 0;"
|
2011-06-13 10:44:17 -04:00
|
|
|
" text-shadow: 0 1px 0 #F9F9F9;"
|
|
|
|
" float: left;"
|
|
|
|
"}"
|
|
|
|
".NB-story-tags {"
|
|
|
|
" clear: both;"
|
|
|
|
" overflow: hidden;"
|
|
|
|
" line-height: 12px;"
|
|
|
|
" height: 14px;"
|
|
|
|
" margin: 6px 0 0 0;"
|
|
|
|
" text-transform: uppercase;"
|
|
|
|
"}"
|
|
|
|
".NB-story-tag {"
|
|
|
|
" float: left;"
|
|
|
|
" font-weight: normal;"
|
|
|
|
" font-size: 9px;"
|
2011-06-14 10:35:33 -04:00
|
|
|
" padding: 0px 4px 0px;"
|
|
|
|
" margin: 0 4px 2px 0;"
|
|
|
|
" background-color: #C6CBC3;"
|
|
|
|
" color: #505050;"
|
|
|
|
" text-shadow: 0 1px 0 #E7E7E7;"
|
2011-06-13 10:44:17 -04:00
|
|
|
" border-radius: 4px;"
|
|
|
|
" -moz-border-radius: 4px;"
|
|
|
|
" -webkit-border-radius: 4px;"
|
|
|
|
"}"
|
|
|
|
".NB-story-date {"
|
|
|
|
" float: right;"
|
|
|
|
" font-size: 11px;"
|
|
|
|
" color: #252D6C;"
|
|
|
|
"}"
|
|
|
|
".NB-story-title {"
|
|
|
|
" clear: left;"
|
|
|
|
"}"
|
2010-07-15 23:32:37 -04:00
|
|
|
"</style>"];
|
2011-06-13 10:44:17 -04:00
|
|
|
NSString *story_author = @"";
|
|
|
|
if ([appDelegate.activeStory objectForKey:@"story_authors"]) {
|
2011-06-14 10:35:33 -04:00
|
|
|
NSString *author = [NSString stringWithFormat:@"%@",[appDelegate.activeStory objectForKey:@"story_authors"]];
|
|
|
|
if (author && ![author isEqualToString:@"<null>"]) {
|
|
|
|
story_author = [NSString stringWithFormat:@"<div class=\"NB-story-author\">%@</div>",author];
|
|
|
|
}
|
2011-06-13 10:44:17 -04:00
|
|
|
}
|
|
|
|
NSString *story_tags = @"";
|
|
|
|
if ([appDelegate.activeStory objectForKey:@"story_tags"]) {
|
|
|
|
NSArray *tag_array = [appDelegate.activeStory objectForKey:@"story_tags"];
|
|
|
|
if ([tag_array count] > 0) {
|
2011-06-14 10:35:33 -04:00
|
|
|
story_tags = [NSString stringWithFormat:@"<div class=\"NB-story-tags\"><div class=\"NB-story-tag\">%@</div></div>",
|
|
|
|
[tag_array componentsJoinedByString:@"</div><div class=\"NB-story-tag\">"]];
|
2011-06-13 10:44:17 -04:00
|
|
|
}
|
|
|
|
}
|
2010-11-22 10:44:52 -05:00
|
|
|
NSString *storyHeader = [NSString stringWithFormat:@"<div class=\"NB-header\">"
|
2011-06-13 10:44:17 -04:00
|
|
|
"<div class=\"NB-story-date\">%@</div>"
|
2010-11-22 10:44:52 -05:00
|
|
|
"%@"
|
2011-06-13 10:44:17 -04:00
|
|
|
"<div class=\"NB-story-title\">%@</div>"
|
|
|
|
"%@"
|
|
|
|
"</div>",
|
2011-06-14 10:35:33 -04:00
|
|
|
[story_tags length] ? [appDelegate.activeStory objectForKey:@"long_parsed_date"] : [appDelegate.activeStory objectForKey:@"short_parsed_date"],
|
2011-06-13 10:44:17 -04:00
|
|
|
story_author,
|
|
|
|
[appDelegate.activeStory objectForKey:@"story_title"],
|
|
|
|
story_tags];
|
2010-11-22 10:44:52 -05:00
|
|
|
NSString *htmlString = [NSString stringWithFormat:@"%@ %@ <div class=\"NB-story\">%@</div>",
|
|
|
|
imgCssString, storyHeader,
|
|
|
|
[appDelegate.activeStory objectForKey:@"story_content"]];
|
2010-07-15 23:32:37 -04:00
|
|
|
[webView loadHTMLString:htmlString
|
2010-06-27 19:35:17 -04:00
|
|
|
baseURL:[NSURL URLWithString:[appDelegate.activeFeed
|
|
|
|
objectForKey:@"feed_link"]]];
|
2011-02-13 19:01:01 -05:00
|
|
|
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
}
|
|
|
|
|
2011-06-14 10:35:33 -04:00
|
|
|
- (IBAction)doNextUnreadStory {
|
2011-06-15 11:21:55 -04:00
|
|
|
int nextIndex = [appDelegate indexOfNextStory];
|
|
|
|
if (nextIndex == -1) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
[appDelegate setActiveStory:[[appDelegate activeFeedStories] objectAtIndex:nextIndex]];
|
|
|
|
[self showStory];
|
|
|
|
|
|
|
|
[UIView beginAnimations:nil context:nil];
|
|
|
|
[UIView setAnimationDuration:.5];
|
|
|
|
[UIView setAnimationBeginsFromCurrentState:NO];
|
|
|
|
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
|
|
|
|
[UIView commitAnimations];
|
|
|
|
}
|
2011-06-14 10:35:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)doPreviousStory {
|
2011-06-15 11:21:55 -04:00
|
|
|
NSInteger nextIndex = [appDelegate indexOfPreviousStory];
|
|
|
|
if (nextIndex == -1) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
[appDelegate setActiveStory:[[appDelegate activeFeedStories] objectAtIndex:nextIndex]];
|
|
|
|
[self showStory];
|
|
|
|
|
|
|
|
[UIView beginAnimations:nil context:nil];
|
|
|
|
[UIView setAnimationDuration:.5];
|
|
|
|
[UIView setAnimationBeginsFromCurrentState:NO];
|
|
|
|
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:NO];
|
|
|
|
[UIView commitAnimations];
|
|
|
|
}
|
2011-06-14 10:35:33 -04:00
|
|
|
}
|
|
|
|
|
2010-11-13 18:32:43 -05:00
|
|
|
- (void)showOriginalSubview:(id)sender {
|
|
|
|
NSURL *url = [NSURL URLWithString:[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_permalink"]];
|
|
|
|
[appDelegate showOriginalStory:url];
|
|
|
|
}
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
// Releases the view if it doesn't have a superview.
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
|
|
|
|
// Release any cached data, images, etc that aren't in use.
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload {
|
|
|
|
// Release any retained subviews of the main view.
|
|
|
|
// e.g. self.myOutlet = nil;
|
2010-06-27 19:35:17 -04:00
|
|
|
self.webView = nil;
|
|
|
|
self.appDelegate = nil;
|
2010-06-25 18:36:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-13 18:32:43 -05:00
|
|
|
|
|
|
|
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
|
|
|
|
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
|
|
|
|
NSURL *url = [request URL];
|
|
|
|
[appDelegate showOriginalStory:url];
|
|
|
|
//[url release];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2011-02-13 19:01:01 -05:00
|
|
|
- (void)webViewDidStartLoad:(UIWebView *)webView {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)webViewDidFinishLoad:(UIWebView *)webView {
|
|
|
|
}
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
- (void)dealloc {
|
|
|
|
[appDelegate release];
|
2010-06-27 19:35:17 -04:00
|
|
|
[webView release];
|
2010-06-25 18:36:01 -04:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|