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"
|
2011-09-05 22:06:31 -07:00
|
|
|
#import "FeedDetailViewController.h"
|
2012-06-18 14:31:42 -07:00
|
|
|
#import "FontSettingsViewController.h"
|
2012-06-11 21:00:09 -07:00
|
|
|
#import "SplitStoryDetailViewController.h"
|
2010-11-22 10:44:52 -05:00
|
|
|
#import "ASIHTTPRequest.h"
|
|
|
|
#import "ASIFormDataRequest.h"
|
2011-09-05 22:06:31 -07:00
|
|
|
#import "Base64.h"
|
2011-10-17 09:37:16 -07:00
|
|
|
#import "Utilities.h"
|
2010-06-25 18:36:01 -04:00
|
|
|
|
|
|
|
@implementation StoryDetailViewController
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
2012-06-20 07:39:49 -07:00
|
|
|
@synthesize activeStoryId;
|
2011-07-26 08:37:10 -07:00
|
|
|
@synthesize progressView;
|
2010-06-27 19:35:17 -04:00
|
|
|
@synthesize webView;
|
2011-02-13 19:01:01 -05:00
|
|
|
@synthesize toolbar;
|
|
|
|
@synthesize buttonPrevious;
|
2012-06-20 07:39:49 -07:00
|
|
|
@synthesize buttonNext;
|
2011-12-01 18:39:35 -08:00
|
|
|
@synthesize buttonAction;
|
2011-09-05 22:06:31 -07:00
|
|
|
@synthesize activity;
|
|
|
|
@synthesize loadingIndicator;
|
2011-10-30 20:24:12 -07:00
|
|
|
@synthesize feedTitleGradient;
|
2012-06-18 14:31:42 -07:00
|
|
|
@synthesize popoverController;
|
2010-06-25 18:36:01 -04:00
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark View boilerplate
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-14 00:16:25 -07:00
|
|
|
- (void)dealloc {
|
|
|
|
[activeStoryId release];
|
|
|
|
[appDelegate release];
|
|
|
|
[progressView release];
|
|
|
|
[webView release];
|
|
|
|
[toolbar release];
|
|
|
|
[buttonNext release];
|
|
|
|
[buttonPrevious release];
|
2011-12-01 18:39:35 -08:00
|
|
|
[buttonAction release];
|
2011-09-05 22:06:31 -07:00
|
|
|
[activity release];
|
|
|
|
[loadingIndicator release];
|
2011-10-30 20:24:12 -07:00
|
|
|
[feedTitleGradient release];
|
2012-06-18 14:31:42 -07:00
|
|
|
[popoverController release];
|
2011-08-14 00:16:25 -07:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2011-08-24 10:24:02 -07:00
|
|
|
- (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;
|
2011-09-05 22:06:31 -07:00
|
|
|
self.loadingIndicator = [[[UIActivityIndicatorView alloc]
|
|
|
|
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]
|
|
|
|
autorelease];
|
2011-10-30 22:17:35 -07:00
|
|
|
|
2011-08-24 10:24:02 -07:00
|
|
|
[super viewDidLoad];
|
|
|
|
}
|
|
|
|
|
2012-06-08 10:37:51 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
2012-06-08 19:21:10 -07:00
|
|
|
return YES;
|
2012-06-08 10:37:51 -07:00
|
|
|
}
|
|
|
|
|
2012-06-19 14:06:37 -07:00
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2011-08-22 18:25:33 -07:00
|
|
|
id storyId = [appDelegate.activeStory objectForKey:@"id"];
|
|
|
|
if (self.activeStoryId != storyId) {
|
|
|
|
[appDelegate pushReadStory:storyId];
|
2011-08-14 00:16:25 -07:00
|
|
|
[self setActiveStory];
|
|
|
|
[self showStory];
|
|
|
|
[self markStoryAsRead];
|
|
|
|
[self setNextPreviousButtons];
|
|
|
|
self.webView.scalesPageToFit = YES;
|
|
|
|
}
|
2011-09-05 22:06:31 -07:00
|
|
|
[self.loadingIndicator stopAnimating];
|
2011-07-25 09:08:20 -07:00
|
|
|
|
2010-11-22 10:44:52 -05:00
|
|
|
[super viewWillAppear:animated];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
2011-08-14 00:16:25 -07:00
|
|
|
UIBarButtonItem *originalButton = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"Original"
|
|
|
|
style:UIBarButtonItemStyleBordered
|
|
|
|
target:self
|
|
|
|
action:@selector(showOriginalSubview:)
|
|
|
|
];
|
2012-06-11 19:17:58 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad) {
|
2012-06-13 18:07:24 -07:00
|
|
|
appDelegate.splitStoryDetailViewController.navigationItem.rightBarButtonItem = originalButton;
|
2012-06-11 19:17:58 -07:00
|
|
|
} else {
|
|
|
|
self.navigationItem.rightBarButtonItem = originalButton;
|
|
|
|
}
|
|
|
|
|
2011-08-14 00:16:25 -07:00
|
|
|
[originalButton release];
|
2011-11-04 08:46:24 -07:00
|
|
|
|
2010-11-22 10:44:52 -05:00
|
|
|
[super viewDidAppear:animated];
|
|
|
|
}
|
|
|
|
|
2011-08-14 10:22:26 -07:00
|
|
|
- (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:@""]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Story layout
|
2010-11-22 10:44:52 -05:00
|
|
|
|
2012-06-22 15:53:51 -07:00
|
|
|
- (NSString *)getComments {
|
|
|
|
NSString *comments = @"";
|
|
|
|
|
|
|
|
if ([appDelegate.activeStory objectForKey:@"comments"]) {
|
|
|
|
NSArray *comments_array = [appDelegate.activeStory objectForKey:@"comments"];
|
|
|
|
if ([comments_array count] > 0) {
|
|
|
|
|
|
|
|
comments = [comments stringByAppendingString:[NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-story-comments-shares-teaser-wrapper\">"
|
|
|
|
"<div class=\"NB-story-comments-shares-teaser\">"
|
|
|
|
"<div class=\"NB-right\">Shared by <b>4</b> people</div>"
|
|
|
|
"<div class=\"NB-story-share-label\">Shared by: </div>"
|
|
|
|
"<div class=\"NB-story-share-profiles NB-story-share-profiles-friends\">"
|
|
|
|
"<div class=\"NB-story-share-profile\"><div class=\"NB-user-avatar\" original-title=\"popular\"><img src=\"http://f.cl.ly/items/0L3E37240r1O1V140k2q/popular.jpg\"></div></div>"
|
|
|
|
"<div class=\"NB-story-share-profile\"><div class=\"NB-user-avatar\" original-title=\"roy\"><img src=\"http://a0.twimg.com/profile_images/1220963194/32457_608147485418_1702670_35737586_6975021_n_normal.jpg\"></div></div>"
|
|
|
|
"<div class=\"NB-story-share-profile\"><div class=\"NB-user-avatar\" original-title=\"samuel\"><img src=\"http://a0.twimg.com/profile_images/1382021023/Campeche_Steps_normal.jpg\"></div></div>"
|
|
|
|
"</div></div></div>"]];
|
|
|
|
|
|
|
|
for (int i = 0; i < comments_array.count; i++) {
|
|
|
|
NSDictionary *comment_dict = [comments_array objectAtIndex:i];
|
|
|
|
NSString *comment = [NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-story-comment\"><div>"
|
|
|
|
"<img class=\"NB-user-avatar NB-story-comment-reply-photo\" src=\"%@\" />"
|
|
|
|
"<div class=\"NB-story-comment-username NB-story-comment-reply-username\">%@</div>"
|
|
|
|
"<div class=\"NB-story-comment-date NB-story-comment-reply-date\">%@</div>"
|
|
|
|
"<div class=\"NB-story-comment-reply-content\">%@</div>"
|
|
|
|
"</div></div>",
|
|
|
|
[comment_dict objectForKey:@"user_id"],
|
|
|
|
[comment_dict objectForKey:@"user_id"],
|
|
|
|
[comment_dict objectForKey:@"shared_date"],
|
|
|
|
[comment_dict objectForKey:@"comments"]];
|
|
|
|
comments = [comments stringByAppendingString:comment];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return comments;
|
|
|
|
}
|
2010-11-22 10:44:52 -05:00
|
|
|
- (void)showStory {
|
2012-06-22 15:53:51 -07:00
|
|
|
|
|
|
|
for (id key in appDelegate.activeStory) {
|
|
|
|
|
|
|
|
NSLog(@"key is: %@ value: %@", key, [appDelegate.activeStory objectForKey:key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *commentsString = [self getComments];
|
|
|
|
|
2012-06-14 16:30:37 -07:00
|
|
|
NSString *customImgCssString, *universalImgCssString, *sharingHtmlString;
|
2012-06-21 11:53:48 -07:00
|
|
|
// set up layout values based on iPad/iPhone
|
2012-06-14 10:19:36 -07:00
|
|
|
universalImgCssString = [NSString stringWithFormat:@
|
2012-06-20 19:18:29 -07:00
|
|
|
"<script src=\"zepto.js\"></script>"
|
|
|
|
"<script src=\"storyDetailView.js\"></script>"
|
2012-06-22 15:53:51 -07:00
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"reader.css\" >"
|
2012-06-20 19:18:29 -07:00
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"storyDetailView.css\" >"
|
2012-06-11 17:49:20 -07:00
|
|
|
"<meta name=\"viewport\" content=\"width=device-width\"/>"];
|
2012-06-07 17:52:14 -07:00
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
|
2012-06-11 17:49:20 -07:00
|
|
|
customImgCssString = [NSString stringWithFormat:@"<style>"
|
|
|
|
"h1, h2, h3, h4, h5, h6, div, table, span, pre, code, img {"
|
2012-06-14 10:19:36 -07:00
|
|
|
" max-width: 588px;"
|
2012-06-11 17:49:20 -07:00
|
|
|
"}"
|
|
|
|
"</style>"];
|
2012-06-07 17:52:14 -07:00
|
|
|
} else {
|
2012-06-11 17:49:20 -07:00
|
|
|
customImgCssString = [NSString stringWithFormat:@"<style>"
|
|
|
|
"h1, h2, h3, h4, h5, h6, div, table, span, pre, code, img {"
|
|
|
|
" max-width: 296px;"
|
|
|
|
"}"
|
|
|
|
"</style>"];
|
2012-06-07 17:52:14 -07:00
|
|
|
}
|
2012-06-11 17:49:20 -07:00
|
|
|
|
2012-06-14 16:30:37 -07:00
|
|
|
sharingHtmlString = [NSString stringWithFormat:@
|
|
|
|
"<div class='NB-share-header'></div>"
|
|
|
|
"<div class='NB-share-wrapper'><div class='NB-share-inner-wrapper'>"
|
2012-06-22 13:15:31 -07:00
|
|
|
"<a class='NB-share-button' href='nb-share://share-link'><span class='NB-share-icon'></span>Share this story</a>"
|
|
|
|
// "<a class='NB-save-button' href='save://save'><span class='NB-save-icon'></span>Save this story</a>"
|
2012-06-14 16:30:37 -07:00
|
|
|
"</div></div>"];
|
2011-06-13 10:44:17 -04:00
|
|
|
NSString *story_author = @"";
|
|
|
|
if ([appDelegate.activeStory objectForKey:@"story_authors"]) {
|
2011-08-14 00:16:25 -07:00
|
|
|
NSString *author = [NSString stringWithFormat:@"%@",
|
|
|
|
[appDelegate.activeStory objectForKey:@"story_authors"]];
|
2011-06-14 10:35:33 -04:00
|
|
|
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-08-14 00:16:25 -07:00
|
|
|
story_tags = [NSString
|
|
|
|
stringWithFormat:@"<div class=\"NB-story-tags\">"
|
|
|
|
"<div class=\"NB-story-tag\">"
|
|
|
|
"%@</div></div>",
|
2011-06-14 10:35:33 -04:00
|
|
|
[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>"
|
|
|
|
"<div class=\"NB-story-title\">%@</div>"
|
|
|
|
"%@"
|
2011-07-20 21:08:57 -07:00
|
|
|
"%@"
|
2011-06-13 10:44:17 -04:00
|
|
|
"</div>",
|
2011-08-14 00:16:25 -07:00
|
|
|
[story_tags length] ?
|
|
|
|
[appDelegate.activeStory
|
|
|
|
objectForKey:@"long_parsed_date"] :
|
|
|
|
[appDelegate.activeStory
|
|
|
|
objectForKey:@"short_parsed_date"],
|
2011-06-13 10:44:17 -04:00
|
|
|
[appDelegate.activeStory objectForKey:@"story_title"],
|
2011-07-20 21:08:57 -07:00
|
|
|
story_author,
|
2011-06-13 10:44:17 -04:00
|
|
|
story_tags];
|
2012-06-22 15:53:51 -07:00
|
|
|
NSString *htmlString = [NSString stringWithFormat:@
|
|
|
|
"<html><head>%@ %@</head>"
|
|
|
|
"<body id=\"story_pane\">%@"
|
|
|
|
"<div class=\"NB-story\">%@ </div>"
|
|
|
|
"<div class=\"NB-feed-story-comments\">%@</div>" // comments
|
|
|
|
"%@" // share
|
|
|
|
"</body></html>",
|
2012-06-14 16:30:37 -07:00
|
|
|
universalImgCssString,
|
|
|
|
customImgCssString,
|
|
|
|
storyHeader,
|
2012-06-22 13:15:31 -07:00
|
|
|
[appDelegate.activeStory objectForKey:@"story_content"],
|
2012-06-22 15:53:51 -07:00
|
|
|
commentsString,
|
2012-06-22 13:15:31 -07:00
|
|
|
sharingHtmlString
|
2012-06-14 16:30:37 -07:00
|
|
|
];
|
2011-10-27 19:05:38 -07:00
|
|
|
|
2012-06-21 11:53:48 -07:00
|
|
|
NSLog(@"\n\n\n\nstory content\n\n\n%@<div class=\"NB-story\">%@</div>\n\n\n", storyHeader, [appDelegate.activeStory objectForKey:@"story_content"]);
|
2012-06-14 10:19:36 -07:00
|
|
|
NSString *path = [[NSBundle mainBundle] bundlePath];
|
|
|
|
NSURL *baseURL = [NSURL fileURLWithPath:path];
|
|
|
|
|
2010-07-15 23:32:37 -04:00
|
|
|
[webView loadHTMLString:htmlString
|
2012-06-14 10:19:36 -07:00
|
|
|
//baseURL:[NSURL URLWithString:feed_link]];
|
|
|
|
baseURL:baseURL];
|
2011-10-27 19:05:38 -07:00
|
|
|
|
|
|
|
NSDictionary *feed = [appDelegate.dictFeeds objectForKey:[NSString stringWithFormat:@"%@",
|
|
|
|
[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_feed_id"]]];
|
2011-10-30 22:17:35 -07:00
|
|
|
self.feedTitleGradient = [appDelegate makeFeedTitleGradient:feed
|
2012-06-08 10:37:51 -07:00
|
|
|
withRect:CGRectMake(0, -1, 1024, 21)]; // 1024 hack for self.webView.frame.size.width
|
2011-10-30 22:17:35 -07:00
|
|
|
|
2012-06-20 08:42:19 -07:00
|
|
|
self.feedTitleGradient.tag = FEED_TITLE_GRADIENT_TAG; // Not attached yet. Remove old gradients, first.
|
2011-11-03 09:19:24 -07:00
|
|
|
for (UIView *subview in self.webView.subviews) {
|
2012-06-20 08:42:19 -07:00
|
|
|
if (subview.tag == FEED_TITLE_GRADIENT_TAG) {
|
2011-10-30 22:17:35 -07:00
|
|
|
[subview removeFromSuperview];
|
|
|
|
}
|
|
|
|
}
|
2011-10-27 19:05:38 -07:00
|
|
|
for (NSObject *aSubView in [self.webView subviews]) {
|
|
|
|
if ([aSubView isKindOfClass:[UIScrollView class]]) {
|
|
|
|
UIScrollView * theScrollView = (UIScrollView *)aSubView;
|
2011-10-28 10:51:03 -07:00
|
|
|
if (appDelegate.isRiverView) {
|
2011-10-30 18:53:10 -07:00
|
|
|
theScrollView.contentInset = UIEdgeInsetsMake(19, 0, 0, 0);
|
2012-06-07 18:49:50 -07:00
|
|
|
theScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(24, 0, 5, 0);
|
2011-10-28 10:51:03 -07:00
|
|
|
} else {
|
2012-06-07 18:49:50 -07:00
|
|
|
theScrollView.contentInset = UIEdgeInsetsMake(9, 0, 0, 0);
|
|
|
|
theScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(14, 0, 5, 0);
|
2011-10-28 10:51:03 -07:00
|
|
|
}
|
2012-06-07 18:49:50 -07:00
|
|
|
[self.webView insertSubview:feedTitleGradient aboveSubview:theScrollView];
|
2011-11-04 08:46:24 -07:00
|
|
|
[theScrollView setContentOffset:CGPointMake(0, appDelegate.isRiverView ? -19 : -9) animated:NO];
|
2012-06-22 15:54:17 -07:00
|
|
|
|
2011-10-28 10:51:03 -07:00
|
|
|
break;
|
2011-10-27 19:05:38 -07:00
|
|
|
}
|
|
|
|
}
|
2011-10-30 22:17:35 -07:00
|
|
|
}
|
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
- (void)setActiveStory {
|
|
|
|
self.activeStoryId = [appDelegate.activeStory objectForKey:@"id"];
|
|
|
|
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"story_feed_id"]];
|
|
|
|
UIImage *titleImage = appDelegate.isRiverView ?
|
|
|
|
[UIImage imageNamed:@"folder.png"] :
|
|
|
|
[Utilities getImage:feedIdStr];
|
|
|
|
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:titleImage];
|
|
|
|
titleImageView.frame = CGRectMake(0.0, 2.0, 16.0, 16.0);
|
|
|
|
self.navigationItem.titleView = titleImageView;
|
|
|
|
[titleImageView release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)webView:(UIWebView *)webView
|
|
|
|
shouldStartLoadWithRequest:(NSURLRequest *)request
|
|
|
|
navigationType:(UIWebViewNavigationType)navigationType {
|
|
|
|
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
|
|
|
|
NSURL *url = [request URL];
|
2012-06-22 13:15:31 -07:00
|
|
|
if ([[url absoluteString] isEqualToString: @"nb-share://share-link"]) {
|
|
|
|
[appDelegate showShareView];
|
|
|
|
return NO;
|
|
|
|
} else {
|
|
|
|
[appDelegate showOriginalStory:url];
|
|
|
|
return NO;
|
|
|
|
}
|
2011-12-01 09:01:18 -08:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)webViewDidStartLoad:(UIWebView *)webView {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)webViewDidFinishLoad:(UIWebView *)webView {
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Actions
|
|
|
|
|
|
|
|
- (void)setNextPreviousButtons {
|
|
|
|
int nextIndex = [appDelegate indexOfNextStory];
|
|
|
|
int unreadCount = [appDelegate unreadCount];
|
|
|
|
if (nextIndex == -1 && unreadCount > 0) {
|
|
|
|
[buttonNext setStyle:UIBarButtonItemStyleBordered];
|
|
|
|
[buttonNext setTitle:@"Next Unread"];
|
|
|
|
} else if (nextIndex == -1) {
|
|
|
|
[buttonNext setStyle:UIBarButtonItemStyleDone];
|
|
|
|
[buttonNext setTitle:@"Done"];
|
|
|
|
} else {
|
|
|
|
[buttonNext setStyle:UIBarButtonItemStyleBordered];
|
|
|
|
[buttonNext setTitle:@"Next Unread"];
|
|
|
|
}
|
|
|
|
|
|
|
|
int readStoryCount = [appDelegate.readStories count];
|
|
|
|
if (readStoryCount == 0 ||
|
|
|
|
(readStoryCount == 1 &&
|
|
|
|
[appDelegate.readStories lastObject] == [appDelegate.activeStory objectForKey:@"id"])) {
|
|
|
|
|
|
|
|
[buttonPrevious setStyle:UIBarButtonItemStyleDone];
|
|
|
|
[buttonPrevious setTitle:@"Done"];
|
|
|
|
} else {
|
|
|
|
[buttonPrevious setStyle:UIBarButtonItemStyleBordered];
|
|
|
|
[buttonPrevious setTitle:@"Previous"];
|
|
|
|
}
|
|
|
|
|
|
|
|
float unreads = (float)[appDelegate unreadCount];
|
|
|
|
float total = [appDelegate originalStoryCount];
|
|
|
|
float progress = (total - unreads) / total;
|
|
|
|
[progressView setProgress:progress];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markStoryAsRead {
|
|
|
|
if ([[appDelegate.activeStory objectForKey:@"read_status"] intValue] != 1) {
|
|
|
|
[appDelegate markActiveStoryRead];
|
|
|
|
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/mark_story_as_read",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
[request setPostValue:[appDelegate.activeStory
|
|
|
|
objectForKey:@"id"]
|
|
|
|
forKey:@"story_id"];
|
|
|
|
[request setPostValue:[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_feed_id"]
|
|
|
|
forKey:@"feed_id"];
|
|
|
|
[request setDidFinishSelector:@selector(markedAsRead)];
|
|
|
|
[request setDidFailSelector:@selector(markedAsRead)];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markedAsRead {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-06-14 10:35:33 -04:00
|
|
|
- (IBAction)doNextUnreadStory {
|
2011-06-15 11:21:55 -04:00
|
|
|
int nextIndex = [appDelegate indexOfNextStory];
|
2011-09-05 22:06:31 -07:00
|
|
|
int unreadCount = [appDelegate unreadCount];
|
|
|
|
[self.loadingIndicator stopAnimating];
|
2011-12-01 09:01:18 -08:00
|
|
|
|
|
|
|
if (self.appDelegate.feedDetailViewController.pageFetching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-05 22:06:31 -07:00
|
|
|
if (nextIndex == -1 && unreadCount > 0 &&
|
|
|
|
self.appDelegate.feedDetailViewController.feedPage < 50 &&
|
|
|
|
!self.appDelegate.feedDetailViewController.pageFinished &&
|
|
|
|
!self.appDelegate.feedDetailViewController.pageFetching) {
|
|
|
|
// Fetch next page and see if it has the unreads.
|
|
|
|
[self.loadingIndicator startAnimating];
|
|
|
|
self.activity.customView = self.loadingIndicator;
|
|
|
|
[self.appDelegate.feedDetailViewController fetchNextPage:^() {
|
|
|
|
[self doNextUnreadStory];
|
|
|
|
}];
|
|
|
|
} else if (nextIndex == -1) {
|
2011-08-14 00:16:25 -07:00
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
2012-06-19 14:06:37 -07:00
|
|
|
[appDelegate showMasterPopover];
|
2012-06-20 09:32:55 -07:00
|
|
|
[appDelegate hideStoryDetailView];
|
2011-06-15 11:21:55 -04:00
|
|
|
} else {
|
2011-08-14 00:16:25 -07:00
|
|
|
[appDelegate setActiveStory:[[appDelegate activeFeedStories]
|
|
|
|
objectAtIndex:nextIndex]];
|
2011-08-22 18:25:33 -07:00
|
|
|
[appDelegate pushReadStory:[appDelegate.activeStory objectForKey:@"id"]];
|
2011-08-14 00:16:25 -07:00
|
|
|
[self setActiveStory];
|
2011-06-15 11:21:55 -04:00
|
|
|
[self showStory];
|
2011-07-24 21:47:58 -07:00
|
|
|
[self markStoryAsRead];
|
2011-07-25 09:08:20 -07:00
|
|
|
[self setNextPreviousButtons];
|
2012-06-20 19:18:29 -07:00
|
|
|
[appDelegate changeActiveFeedDetailRow];
|
2011-06-15 11:21:55 -04:00
|
|
|
[UIView beginAnimations:nil context:nil];
|
|
|
|
[UIView setAnimationDuration:.5];
|
|
|
|
[UIView setAnimationBeginsFromCurrentState:NO];
|
2011-08-14 00:16:25 -07:00
|
|
|
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
|
|
|
|
forView:self.view
|
|
|
|
cache:NO];
|
2011-06-15 11:21:55 -04:00
|
|
|
[UIView commitAnimations];
|
|
|
|
}
|
2011-06-14 10:35:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)doPreviousStory {
|
2011-09-05 22:06:31 -07:00
|
|
|
[self.loadingIndicator stopAnimating];
|
2011-08-22 18:25:33 -07:00
|
|
|
id previousStoryId = [appDelegate popReadStory];
|
|
|
|
if (!previousStoryId || previousStoryId == [appDelegate.activeStory objectForKey:@"id"]) {
|
2011-08-14 00:16:25 -07:00
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
2012-06-19 14:06:37 -07:00
|
|
|
[appDelegate showMasterPopover];
|
2012-06-20 09:32:55 -07:00
|
|
|
[appDelegate hideStoryDetailView];
|
2011-06-15 11:21:55 -04:00
|
|
|
} else {
|
2011-08-22 18:25:33 -07:00
|
|
|
int previousIndex = [appDelegate locationOfStoryId:previousStoryId];
|
|
|
|
if (previousIndex == -1) {
|
|
|
|
return [self doPreviousStory];
|
|
|
|
}
|
2011-08-14 00:16:25 -07:00
|
|
|
[appDelegate setActiveStory:[[appDelegate activeFeedStories]
|
|
|
|
objectAtIndex:previousIndex]];
|
2012-06-20 19:18:29 -07:00
|
|
|
[appDelegate changeActiveFeedDetailRow];
|
2011-08-14 00:16:25 -07:00
|
|
|
[self setActiveStory];
|
2011-06-15 11:21:55 -04:00
|
|
|
[self showStory];
|
2011-07-24 21:47:58 -07:00
|
|
|
[self markStoryAsRead];
|
2011-07-25 09:08:20 -07:00
|
|
|
[self setNextPreviousButtons];
|
2011-06-15 11:21:55 -04:00
|
|
|
|
|
|
|
[UIView beginAnimations:nil context:nil];
|
|
|
|
[UIView setAnimationDuration:.5];
|
|
|
|
[UIView setAnimationBeginsFromCurrentState:NO];
|
2011-08-14 00:16:25 -07:00
|
|
|
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
|
|
|
|
forView:self.view
|
|
|
|
cache:NO];
|
2011-06-15 11:21:55 -04:00
|
|
|
[UIView commitAnimations];
|
|
|
|
}
|
2011-06-14 10:35:33 -04:00
|
|
|
}
|
|
|
|
|
2012-06-18 14:31:42 -07:00
|
|
|
- (IBAction)toggleFontSize:(id)sender {
|
|
|
|
if (popoverController == nil) {
|
|
|
|
popoverController = [[UIPopoverController alloc]
|
|
|
|
initWithContentViewController:appDelegate.fontSettingsViewController];
|
|
|
|
|
|
|
|
popoverController.delegate=self;
|
|
|
|
}
|
|
|
|
|
|
|
|
[popoverController presentPopoverFromBarButtonItem:sender
|
|
|
|
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFontSize:(float)fontSize {
|
|
|
|
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%f%%'",
|
|
|
|
fontSize];
|
|
|
|
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
|
|
|
|
[jsString release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFontStyle:(NSString *)fontStyle {
|
|
|
|
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.fontFamily= '%@'",
|
|
|
|
fontStyle];
|
|
|
|
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
|
|
|
|
[jsString release];
|
|
|
|
}
|
|
|
|
|
2012-06-21 11:53:48 -07:00
|
|
|
- (IBAction)doShareButton:(id)sender {
|
|
|
|
[appDelegate showShareView];
|
|
|
|
}
|
|
|
|
|
2010-11-13 18:32:43 -05:00
|
|
|
- (void)showOriginalSubview:(id)sender {
|
|
|
|
NSURL *url = [NSURL URLWithString:[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_permalink"]];
|
2012-06-14 10:19:36 -07:00
|
|
|
[appDelegate showOriginalStory:url];
|
2010-11-13 18:32:43 -05:00
|
|
|
}
|
|
|
|
|
2012-06-20 08:33:16 -07:00
|
|
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
|
|
UITouch *theTouch = [touches anyObject];
|
|
|
|
CGPoint touchLocation = [theTouch locationInView:self.view];
|
|
|
|
CGFloat y = touchLocation.y;
|
|
|
|
[appDelegate dragFeedDetailView:y];
|
|
|
|
}
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
@end
|