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"
|
2012-07-15 15:06:06 -07:00
|
|
|
#import "NewsBlurViewController.h"
|
2011-09-05 22:06:31 -07:00
|
|
|
#import "FeedDetailViewController.h"
|
2012-06-18 14:31:42 -07:00
|
|
|
#import "FontSettingsViewController.h"
|
2012-07-03 17:54:36 -07:00
|
|
|
#import "UserProfileViewController.h"
|
2012-07-12 13:34:41 -07:00
|
|
|
#import "ShareViewController.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"
|
2012-06-29 12:54:52 -07:00
|
|
|
#import "JSON.h"
|
2012-07-20 19:55:38 -07:00
|
|
|
#import "NSString+HTML.h"
|
2012-07-24 15:29:01 -07:00
|
|
|
#import "NBContainerViewController.h"
|
2012-07-26 13:54:45 -07:00
|
|
|
#import "DataUtilities.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;
|
2012-07-12 13:34:41 -07:00
|
|
|
@synthesize innerView;
|
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-28 13:24:40 -07:00
|
|
|
@synthesize buttonNextStory;
|
2012-07-23 15:27:20 -07:00
|
|
|
@synthesize popoverController;
|
2012-07-24 23:21:28 -07:00
|
|
|
@synthesize fontSettingsButton;
|
|
|
|
@synthesize originalStoryButton;
|
2012-07-25 17:29:29 -07:00
|
|
|
@synthesize buttonBack;
|
2012-07-24 23:21:28 -07:00
|
|
|
|
2012-07-24 16:42:18 -07:00
|
|
|
@synthesize bottomPlaceholderToolbar;
|
2010-06-25 18:36:01 -04:00
|
|
|
|
2012-07-24 23:21:28 -07: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
|
|
|
|
2011-08-24 10:24:02 -07:00
|
|
|
- (void)viewDidLoad {
|
2012-07-16 10:10:52 -07:00
|
|
|
[super viewDidLoad];
|
|
|
|
|
2012-07-25 10:50:52 -07:00
|
|
|
// adding HUD for progress bar
|
|
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapProgressBar:)];
|
|
|
|
[self.progressView addGestureRecognizer:tap];
|
|
|
|
|
|
|
|
// adding drag property for toolbars
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-16 10:10:52 -07:00
|
|
|
UIBarButtonItem *originalButton = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"Original"
|
|
|
|
style:UIBarButtonItemStyleBordered
|
|
|
|
target:self
|
|
|
|
action:@selector(showOriginalSubview:)
|
|
|
|
];
|
|
|
|
|
2012-07-24 23:21:28 -07:00
|
|
|
UIBarButtonItem *fontSettings = [[UIBarButtonItem alloc]
|
2012-07-16 10:10:52 -07:00
|
|
|
initWithTitle:@"Aa"
|
|
|
|
style:UIBarButtonItemStyleBordered
|
|
|
|
target:self
|
|
|
|
action:@selector(toggleFontSize:)
|
|
|
|
];
|
2012-07-24 23:21:28 -07:00
|
|
|
|
2012-07-25 17:29:29 -07:00
|
|
|
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(transitionFromFeedDetail)];
|
|
|
|
|
|
|
|
self.buttonBack = backButton;
|
|
|
|
|
2012-07-24 23:21:28 -07:00
|
|
|
self.originalStoryButton = originalButton;
|
|
|
|
self.fontSettingsButton = fontSettings;
|
2012-07-23 15:27:20 -07:00
|
|
|
|
2012-07-16 10:10:52 -07:00
|
|
|
self.loadingIndicator = [[UIActivityIndicatorView alloc]
|
|
|
|
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
|
|
|
|
|
2012-07-23 15:27:20 -07:00
|
|
|
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
|
|
2012-07-16 10:10:52 -07:00
|
|
|
self.webView.scalesPageToFit = NO;
|
|
|
|
self.webView.multipleTouchEnabled = NO;
|
|
|
|
|
2012-07-23 15:27:20 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
2012-07-10 12:34:58 -07:00
|
|
|
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];
|
2012-07-15 15:06:06 -07:00
|
|
|
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
|
2012-07-16 10:10:52 -07:00
|
|
|
self.navigationItem.backBarButtonItem = back;
|
|
|
|
|
|
|
|
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:originalButton, fontSettingsButton, nil];
|
2012-07-24 15:29:01 -07:00
|
|
|
} else {
|
2012-07-24 23:21:28 -07:00
|
|
|
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
|
|
|
self.bottomPlaceholderToolbar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
2012-07-10 12:34:58 -07:00
|
|
|
}
|
2011-08-24 10:24:02 -07:00
|
|
|
}
|
|
|
|
|
2012-07-24 15:29:01 -07:00
|
|
|
- (void)transitionFromFeedDetail {
|
|
|
|
[appDelegate.masterContainerViewController transitionFromFeedDetail];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2012-07-10 12:34:58 -07:00
|
|
|
[super viewWillAppear:animated];
|
2012-07-23 15:27:20 -07:00
|
|
|
|
2012-07-20 22:00:30 -07:00
|
|
|
[self setActiveStory];
|
2012-07-10 12:34:58 -07:00
|
|
|
}
|
|
|
|
|
2012-07-20 19:55:38 -07:00
|
|
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
2012-07-25 10:50:52 -07:00
|
|
|
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
|
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && UIInterfaceOrientationIsPortrait(orientation)) {
|
|
|
|
UITouch *theTouch = [touches anyObject];
|
|
|
|
if ([theTouch.view isKindOfClass: UIToolbar.class]) {
|
|
|
|
CGPoint touchLocation = [theTouch locationInView:self.view];
|
|
|
|
CGFloat y = touchLocation.y;
|
|
|
|
[appDelegate.masterContainerViewController dragStoryToolbar:y];
|
|
|
|
}
|
|
|
|
}
|
2012-07-20 19:55:38 -07:00
|
|
|
}
|
|
|
|
|
2012-07-25 17:29:29 -07:00
|
|
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
|
|
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
|
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && UIInterfaceOrientationIsPortrait(orientation)) {
|
|
|
|
UITouch *theTouch = [touches anyObject];
|
|
|
|
if ([theTouch.view isKindOfClass: UIToolbar.class]) {
|
|
|
|
[appDelegate.masterContainerViewController adjustFeedDetailScreenForStoryTitles];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-20 19:55:38 -07:00
|
|
|
- (void)viewDidUnload {
|
|
|
|
[self setButtonNextStory:nil];
|
|
|
|
[self setInnerView:nil];
|
2012-07-24 16:42:18 -07:00
|
|
|
[self setBottomPlaceholderToolbar:nil];
|
2012-07-20 19:55:38 -07:00
|
|
|
[super viewDidUnload];
|
|
|
|
}
|
|
|
|
|
2012-07-10 12:34:58 -07:00
|
|
|
- (void)initStory {
|
2011-08-22 18:25:33 -07:00
|
|
|
id storyId = [appDelegate.activeStory objectForKey:@"id"];
|
2012-07-20 22:00:30 -07:00
|
|
|
[appDelegate pushReadStory:storyId];
|
|
|
|
[self showStory];
|
|
|
|
[self markStoryAsRead];
|
2012-07-25 10:50:52 -07:00
|
|
|
[self setNextPreviousButtons];
|
2012-07-20 22:00:30 -07:00
|
|
|
self.webView.scalesPageToFit = YES;
|
2012-07-10 12:34:58 -07:00
|
|
|
[self.loadingIndicator stopAnimating];
|
2010-11-22 10:44:52 -05:00
|
|
|
}
|
|
|
|
|
2011-08-14 10:22:26 -07:00
|
|
|
- (void)viewDidDisappear:(BOOL)animated {
|
2012-07-23 15:27:20 -07:00
|
|
|
// Class viewClass = [appDelegate.navigationController.visibleViewController class];
|
|
|
|
// if (viewClass == [appDelegate.feedDetailViewController class] ||
|
|
|
|
// viewClass == [appDelegate.feedsViewController class]) {
|
|
|
|
//// self.activeStoryId = nil;
|
|
|
|
// [webView loadHTMLString:@"" baseURL:[NSURL URLWithString:@""]];
|
|
|
|
// }
|
2011-08-14 10:22:26 -07:00
|
|
|
}
|
|
|
|
|
2012-07-12 13:34:41 -07:00
|
|
|
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
|
2012-07-20 22:00:30 -07:00
|
|
|
[appDelegate adjustStoryDetailWebView];
|
2012-07-10 12:34:58 -07:00
|
|
|
}
|
|
|
|
|
2012-07-12 13:34:41 -07:00
|
|
|
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
2012-07-25 20:38:44 -07:00
|
|
|
// [appDelegate.shareViewController.commentField resignFirstResponder];
|
2012-07-12 13:34:41 -07:00
|
|
|
}
|
|
|
|
|
2012-07-10 12:34:58 -07:00
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Story layout
|
2010-11-22 10:44:52 -05:00
|
|
|
|
2012-06-24 18:17:22 -07:00
|
|
|
- (NSString *)getAvatars:(BOOL)areFriends {
|
|
|
|
NSString *avatarString = @"";
|
|
|
|
NSArray *share_user_ids;
|
2012-06-25 18:05:25 -07:00
|
|
|
if (areFriends) {
|
|
|
|
share_user_ids = [appDelegate.activeStory objectForKey:@"shared_by_friends"];
|
2012-06-24 18:17:22 -07:00
|
|
|
|
|
|
|
// only if your friends are sharing to do you see the shared label
|
|
|
|
if ([share_user_ids count]) {
|
|
|
|
avatarString = [avatarString stringByAppendingString:@
|
|
|
|
"<div class=\"NB-story-share-label\">Shared by: </div>"
|
|
|
|
"<div class=\"NB-story-share-profiles NB-story-share-profiles-friends\">"];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
share_user_ids = [appDelegate.activeStory objectForKey:@"shared_by_public"];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < share_user_ids.count; i++) {
|
|
|
|
NSDictionary *user = [self getUser:[[share_user_ids objectAtIndex:i] intValue]];
|
|
|
|
NSString *avatar = [NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-story-share-profile\"><div class=\"NB-user-avatar\">"
|
2012-07-03 17:54:36 -07:00
|
|
|
"<a class=\"NB-show-profile\" href=\"http://ios.newsblur.com/show-profile/%@\"><img src=\"%@\" /></a>"
|
2012-06-24 18:17:22 -07:00
|
|
|
"</div></div>",
|
2012-07-01 21:58:55 -07:00
|
|
|
[user objectForKey:@"user_id"],
|
2012-07-11 10:33:39 -07:00
|
|
|
[user objectForKey:@"photo_url"]];
|
2012-06-24 18:17:22 -07:00
|
|
|
avatarString = [avatarString stringByAppendingString:avatar];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (areFriends && [share_user_ids count]) {
|
2012-06-24 23:02:37 -07:00
|
|
|
avatarString = [avatarString stringByAppendingString:@"</div>"];
|
2012-06-25 18:05:25 -07:00
|
|
|
|
2012-06-24 18:17:22 -07:00
|
|
|
}
|
|
|
|
return avatarString;
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:21:24 -07:00
|
|
|
- (NSString *)getComments:(NSString *)type {
|
2012-06-22 15:53:51 -07:00
|
|
|
NSString *comments = @"";
|
2012-06-28 11:12:38 -07:00
|
|
|
// NSLog(@"the comment string is %@", [appDelegate.activeStory objectForKey:@"share_count"]);
|
|
|
|
// NSLog(@"appDelegate.activeStory is %@", appDelegate.activeStory);
|
2012-07-03 17:54:36 -07:00
|
|
|
if ([appDelegate.activeStory objectForKey:@"share_count"] != [NSNull null] &&
|
|
|
|
[[appDelegate.activeStory objectForKey:@"share_count"] intValue] > 0) {
|
|
|
|
|
2012-07-20 00:21:24 -07:00
|
|
|
NSDictionary *story = appDelegate.activeStory;
|
|
|
|
NSArray *friendsCommentsArray = [story objectForKey:@"friend_comments"];
|
|
|
|
NSArray *publicCommentsArray = [story objectForKey:@"public_comments"];
|
|
|
|
|
2012-06-24 18:17:22 -07:00
|
|
|
comments = [comments stringByAppendingString:[NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-feed-story-comments\">"
|
|
|
|
"<div class=\"NB-story-comments-shares-teaser-wrapper\">"
|
|
|
|
"<div class=\"NB-story-comments-shares-teaser\">"
|
|
|
|
|
2012-06-25 23:06:16 -07:00
|
|
|
"<div class=\"NB-right\">Shared by %@</div>"
|
2012-06-24 18:17:22 -07:00
|
|
|
|
|
|
|
"<div class=\"NB-story-share-profiles NB-story-share-profiles-public\">"
|
|
|
|
"%@"
|
|
|
|
"</div>"
|
2012-06-24 23:02:37 -07:00
|
|
|
|
2012-06-24 18:17:22 -07:00
|
|
|
"%@"
|
2012-06-24 23:02:37 -07:00
|
|
|
|
2012-06-24 18:17:22 -07:00
|
|
|
"</div></div>",
|
|
|
|
[[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]
|
|
|
|
]];
|
2012-06-24 23:02:37 -07:00
|
|
|
|
2012-07-20 00:21:24 -07:00
|
|
|
// add friends comments
|
|
|
|
for (int i = 0; i < friendsCommentsArray.count; i++) {
|
|
|
|
NSString *comment = [self getComment:[friendsCommentsArray objectAtIndex:i]];
|
2012-06-24 18:17:22 -07:00
|
|
|
comments = [comments stringByAppendingString:comment];
|
2012-06-22 15:53:51 -07:00
|
|
|
}
|
2012-07-20 00:21:24 -07:00
|
|
|
|
|
|
|
if ([[story objectForKey:@"comment_count_public"] intValue] > 0 ) {
|
|
|
|
NSString *publicCommentHeader = [NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-story-comments-public-header-wrapper\">"
|
|
|
|
"<div class=\"NB-story-comments-public-header\">%i public comment%@</div>"
|
|
|
|
"</div>",
|
|
|
|
[[story objectForKey:@"comment_count_public"] intValue],
|
|
|
|
[[story objectForKey:@"comment_count_public"] intValue] == 1 ? @"" : @"s"];
|
|
|
|
|
|
|
|
comments = [comments stringByAppendingString:publicCommentHeader];
|
|
|
|
|
|
|
|
// add friends comments
|
|
|
|
for (int i = 0; i < publicCommentsArray.count; i++) {
|
|
|
|
NSString *comment = [self getComment:[publicCommentsArray objectAtIndex:i]];
|
|
|
|
comments = [comments stringByAppendingString:comment];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-24 18:17:22 -07:00
|
|
|
comments = [comments stringByAppendingString:[NSString stringWithFormat:@"</div>"]];
|
2012-06-22 15:53:51 -07:00
|
|
|
}
|
2012-06-28 15:11:39 -07:00
|
|
|
|
2012-06-22 15:53:51 -07:00
|
|
|
return comments;
|
|
|
|
}
|
2012-06-22 18:01:08 -07:00
|
|
|
|
2012-06-25 20:28:07 -07:00
|
|
|
- (NSString *)getComment:(NSDictionary *)commentDict {
|
2012-07-03 17:54:36 -07:00
|
|
|
|
2012-06-25 20:28:07 -07:00
|
|
|
NSDictionary *user = [self getUser:[[commentDict objectForKey:@"user_id"] intValue]];
|
2012-07-03 17:54:36 -07:00
|
|
|
NSString *userAvatarClass = @"NB-user-avatar";
|
|
|
|
NSString *userReshareString = @"";
|
2012-07-20 00:21:24 -07:00
|
|
|
NSString *userEditButton = @"";
|
2012-07-23 10:57:11 -07:00
|
|
|
NSString *userLikeButton = @"";
|
2012-07-20 00:21:24 -07:00
|
|
|
NSString *commentUserId = [NSString stringWithFormat:@"%@", [commentDict objectForKey:@"user_id"]];
|
|
|
|
NSString *currentUserId = [NSString stringWithFormat:@"%@", [appDelegate.dictUserProfile objectForKey:@"user_id"]];
|
2012-07-26 13:54:45 -07:00
|
|
|
NSArray *likingUsers = [commentDict objectForKey:@"liking_users"];
|
|
|
|
|
|
|
|
|
2012-07-20 00:21:24 -07:00
|
|
|
|
|
|
|
if ([commentUserId isEqualToString:currentUserId]) {
|
|
|
|
userEditButton = [NSString stringWithFormat:@
|
2012-07-23 10:57:11 -07:00
|
|
|
"<div class=\"NB-story-comment-edit-button NB-story-comment-share-edit-button NB-button\">"
|
2012-07-20 00:21:24 -07:00
|
|
|
"<div class=\"NB-story-comment-edit-button-wrapper\">"
|
2012-07-26 10:17:08 -07:00
|
|
|
"<a href=\"http://ios.newsblur.com/edit-share/%@\">Edit</a>"
|
2012-07-20 00:21:24 -07:00
|
|
|
"</div>"
|
2012-07-20 18:04:54 -07:00
|
|
|
"</div>",
|
|
|
|
commentUserId];
|
2012-07-23 10:57:11 -07:00
|
|
|
} else {
|
2012-07-26 13:54:45 -07:00
|
|
|
BOOL isInLikingUsers = NO;
|
|
|
|
for (int i = 0; i < likingUsers.count; i++) {
|
|
|
|
if ([[[likingUsers objectAtIndex:i] stringValue] isEqualToString:currentUserId]) {
|
|
|
|
isInLikingUsers = YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInLikingUsers) {
|
|
|
|
userLikeButton = [NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-story-comment-like-button NB-button selected\">"
|
|
|
|
"<div class=\"NB-story-comment-like-button-wrapper\">"
|
|
|
|
"<a href=\"http://ios.newsblur.com/unlike-comment/%@\">Favorited</a>"
|
|
|
|
"</div>"
|
|
|
|
"</div>",
|
|
|
|
commentUserId];
|
|
|
|
} else {
|
|
|
|
userLikeButton = [NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-story-comment-like-button NB-button\">"
|
|
|
|
"<div class=\"NB-story-comment-like-button-wrapper\">"
|
|
|
|
"<a href=\"http://ios.newsblur.com/like-comment/%@\">Favorite</a>"
|
|
|
|
"</div>"
|
|
|
|
"</div>",
|
|
|
|
commentUserId];
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:21:24 -07:00
|
|
|
}
|
2012-07-03 17:54:36 -07:00
|
|
|
|
|
|
|
if ([commentDict objectForKey:@"source_user_id"] != [NSNull null]) {
|
|
|
|
userAvatarClass = @"NB-user-avatar NB-story-comment-reshare";
|
|
|
|
|
|
|
|
NSDictionary *sourceUser = [self getUser:[[commentDict objectForKey:@"source_user_id"] intValue]];
|
|
|
|
userReshareString = [NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-story-comment-reshares\">"
|
|
|
|
" <div class=\"NB-story-share-profile\">"
|
|
|
|
" <div class=\"NB-user-avatar\"><img src=\"%@\"></div>"
|
|
|
|
" </div>"
|
|
|
|
"</div>",
|
2012-07-11 10:33:39 -07:00
|
|
|
[sourceUser objectForKey:@"photo_url"]];
|
2012-07-03 17:54:36 -07:00
|
|
|
}
|
2012-07-23 16:17:49 -07:00
|
|
|
|
|
|
|
NSString *commentContent = [self textToHtml:[commentDict objectForKey:@"comments"]];
|
2012-07-21 18:25:56 -07:00
|
|
|
|
2012-06-25 20:28:07 -07:00
|
|
|
NSString *comment = [NSString stringWithFormat:@
|
2012-07-03 17:54:36 -07:00
|
|
|
"<div class=\"NB-story-comment\" id=\"NB-user-comment-%@\">"
|
|
|
|
"<div class=\"%@\"><a class=\"NB-show-profile\" href=\"http://ios.newsblur.com/show-profile/%@\"><img src=\"%@\" /></a></div>"
|
|
|
|
"<div class=\"NB-story-comment-author-container\">"
|
|
|
|
" %@"
|
|
|
|
" <div class=\"NB-story-comment-username\">%@</div>"
|
|
|
|
" <div class=\"NB-story-comment-date\">%@ ago</div>"
|
2012-07-23 10:57:11 -07:00
|
|
|
" <div class=\"NB-story-comment-reply-button NB-button\">"
|
2012-07-03 17:54:36 -07:00
|
|
|
" <div class=\"NB-story-comment-reply-button-wrapper\">"
|
2012-07-26 10:17:08 -07:00
|
|
|
" <a href=\"http://ios.newsblur.com/reply/%@/%@\">Reply</a>"
|
2012-07-03 17:54:36 -07:00
|
|
|
" </div>"
|
|
|
|
" </div>"
|
2012-07-23 10:57:11 -07:00
|
|
|
" %@" //User Edit Button>"
|
|
|
|
" %@" //User Like Button>"
|
2012-07-03 17:54:36 -07:00
|
|
|
"</div>"
|
|
|
|
"<div class=\"NB-story-comment-content\">%@</div>"
|
|
|
|
"%@"
|
|
|
|
"</div>",
|
|
|
|
[commentDict objectForKey:@"user_id"],
|
|
|
|
userAvatarClass,
|
|
|
|
[commentDict objectForKey:@"user_id"],
|
2012-07-11 10:33:39 -07:00
|
|
|
[user objectForKey:@"photo_url"],
|
2012-07-20 00:21:24 -07:00
|
|
|
userReshareString,
|
2012-07-03 17:54:36 -07:00
|
|
|
[user objectForKey:@"username"],
|
|
|
|
[commentDict objectForKey:@"shared_date"],
|
|
|
|
[commentDict objectForKey:@"user_id"],
|
|
|
|
[user objectForKey:@"username"],
|
2012-07-23 10:57:11 -07:00
|
|
|
userEditButton,
|
|
|
|
userLikeButton,
|
2012-07-23 16:17:49 -07:00
|
|
|
commentContent,
|
2012-07-20 15:54:10 -07:00
|
|
|
[self getReplies:[commentDict objectForKey:@"replies"] forUserId:[commentDict objectForKey:@"user_id"]]];
|
2012-07-03 17:54:36 -07:00
|
|
|
|
2012-06-25 20:28:07 -07:00
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
|
2012-07-20 15:54:10 -07:00
|
|
|
- (NSString *)getReplies:(NSArray *)replies forUserId:(NSString *)commentUserId {
|
2012-06-22 18:01:08 -07:00
|
|
|
NSString *repliesString = @"";
|
|
|
|
if (replies.count > 0) {
|
|
|
|
repliesString = [repliesString stringByAppendingString:@"<div class=\"NB-story-comment-replies\">"];
|
|
|
|
for (int i = 0; i < replies.count; i++) {
|
2012-07-20 15:54:10 -07:00
|
|
|
NSDictionary *replyDict = [replies objectAtIndex:i];
|
|
|
|
NSDictionary *user = [self getUser:[[replyDict objectForKey:@"user_id"] intValue]];
|
|
|
|
|
|
|
|
NSString *userEditButton = @"";
|
|
|
|
NSString *replyUserId = [NSString stringWithFormat:@"%@", [replyDict objectForKey:@"user_id"]];
|
|
|
|
NSString *currentUserId = [NSString stringWithFormat:@"%@", [appDelegate.dictUserProfile objectForKey:@"user_id"]];
|
|
|
|
|
|
|
|
if ([replyUserId isEqualToString:currentUserId]) {
|
|
|
|
userEditButton = [NSString stringWithFormat:@
|
2012-07-23 10:57:11 -07:00
|
|
|
"<div class=\"NB-story-comment-edit-button NB-story-comment-share-edit-button NB-button\">"
|
2012-07-20 15:54:10 -07:00
|
|
|
"<div class=\"NB-story-comment-edit-button-wrapper\">"
|
|
|
|
"<a href=\"http://ios.newsblur.com/edit-reply/%@/%@/%i\">edit</a>"
|
|
|
|
"</div>"
|
|
|
|
"</div>",
|
|
|
|
commentUserId,
|
|
|
|
replyUserId,
|
|
|
|
i // comment number in array
|
|
|
|
];
|
|
|
|
}
|
2012-07-23 16:17:49 -07:00
|
|
|
|
|
|
|
NSString *replyContent = [self textToHtml:[replyDict objectForKey:@"comments"]];
|
2012-07-21 18:25:56 -07:00
|
|
|
|
2012-06-22 18:01:08 -07:00
|
|
|
NSString *reply = [NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-story-comment-reply\">"
|
2012-07-11 18:08:07 -07:00
|
|
|
" <a class=\"NB-show-profile\" href=\"http://ios.newsblur.com/show-profile/%@\">"
|
|
|
|
" <img class=\"NB-user-avatar NB-story-comment-reply-photo\" src=\"%@\" />"
|
|
|
|
" </a>"
|
2012-06-28 15:11:39 -07:00
|
|
|
" <div class=\"NB-story-comment-username NB-story-comment-reply-username\">%@</div>"
|
|
|
|
" <div class=\"NB-story-comment-date NB-story-comment-reply-date\">%@ ago</div>"
|
2012-07-20 15:54:10 -07:00
|
|
|
" %@" //User Edit Button>"
|
2012-06-28 15:11:39 -07:00
|
|
|
" <div class=\"NB-story-comment-reply-content\">%@</div>"
|
2012-06-22 18:01:08 -07:00
|
|
|
"</div>",
|
2012-07-11 18:08:07 -07:00
|
|
|
[user objectForKey:@"user_id"],
|
2012-07-11 10:33:39 -07:00
|
|
|
[user objectForKey:@"photo_url"],
|
2012-06-22 18:01:08 -07:00
|
|
|
[user objectForKey:@"username"],
|
2012-07-20 15:54:10 -07:00
|
|
|
[replyDict objectForKey:@"publish_date"],
|
|
|
|
userEditButton,
|
2012-07-23 16:17:49 -07:00
|
|
|
replyContent];
|
2012-06-22 18:01:08 -07:00
|
|
|
repliesString = [repliesString stringByAppendingString:reply];
|
|
|
|
}
|
|
|
|
repliesString = [repliesString stringByAppendingString:@"</div>"];
|
|
|
|
}
|
|
|
|
return repliesString;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)getUser:(int)user_id {
|
|
|
|
for (int i = 0; i < appDelegate.activeFeedUserProfiles.count; i++) {
|
|
|
|
if ([[[appDelegate.activeFeedUserProfiles objectAtIndex:i] objectForKey:@"user_id"] intValue] == user_id) {
|
|
|
|
return [appDelegate.activeFeedUserProfiles objectAtIndex:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2010-11-22 10:44:52 -05:00
|
|
|
- (void)showStory {
|
2012-07-26 11:52:07 -07:00
|
|
|
appDelegate.shareViewController.commentField.text = nil;
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[appDelegate.masterContainerViewController transitionFromShareView];
|
|
|
|
}
|
|
|
|
|
2012-07-24 16:42:18 -07:00
|
|
|
self.webView.hidden = NO;
|
|
|
|
self.bottomPlaceholderToolbar.hidden = YES;
|
2012-07-24 23:21:28 -07:00
|
|
|
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:self.originalStoryButton, self.fontSettingsButton, nil];
|
|
|
|
|
2012-07-19 11:26:17 -07:00
|
|
|
[appDelegate hideFindingStoryHUD];
|
2012-07-12 13:34:41 -07:00
|
|
|
[appDelegate hideShareView:YES];
|
2012-06-29 23:25:56 -07:00
|
|
|
|
2012-06-28 13:24:40 -07:00
|
|
|
int activeLocation = appDelegate.locationOfActiveStory;
|
2012-06-28 15:03:28 -07:00
|
|
|
if (activeLocation >= ([appDelegate.activeFeedStoryLocations count] - 1)) {
|
2012-06-28 13:24:40 -07:00
|
|
|
self.buttonNextStory.enabled = NO;
|
|
|
|
} else {
|
|
|
|
self.buttonNextStory.enabled = YES;
|
|
|
|
}
|
2012-06-27 15:24:18 -07:00
|
|
|
|
|
|
|
[appDelegate resetShareComments];
|
2012-07-20 00:21:24 -07:00
|
|
|
NSString *commentString = [self getComments:@"friends"];
|
2012-06-28 13:24:40 -07:00
|
|
|
NSString *headerString;
|
|
|
|
NSString *sharingHtmlString;
|
|
|
|
NSString *footerString;
|
2012-06-26 23:12:54 -07:00
|
|
|
NSString *fontStyleClass = @"";
|
|
|
|
NSString *fontSizeClass = @"";
|
2012-06-22 15:53:51 -07:00
|
|
|
|
2012-06-24 23:02:37 -07:00
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
|
|
|
if ([userPreferences stringForKey:@"fontStyle"]){
|
2012-06-26 23:12:54 -07:00
|
|
|
fontStyleClass = [fontStyleClass stringByAppendingString:[userPreferences stringForKey:@"fontStyle"]];
|
|
|
|
} else {
|
|
|
|
fontStyleClass = [fontStyleClass stringByAppendingString:@"NB-san-serif"];
|
2012-06-27 21:28:04 -07:00
|
|
|
}
|
2012-06-26 23:12:54 -07:00
|
|
|
if ([userPreferences stringForKey:@"fontSizing"]){
|
|
|
|
fontSizeClass = [fontSizeClass stringByAppendingString:[userPreferences stringForKey:@"fontSizing"]];
|
2012-06-24 23:02:37 -07:00
|
|
|
} else {
|
2012-06-26 23:12:54 -07:00
|
|
|
fontSizeClass = [fontSizeClass stringByAppendingString:@"NB-medium"];
|
2012-06-22 15:53:51 -07:00
|
|
|
}
|
|
|
|
|
2012-06-27 21:28:04 -07:00
|
|
|
int contentWidth = self.view.frame.size.width;
|
2012-06-28 11:12:38 -07:00
|
|
|
NSString *contentWidthClass;
|
|
|
|
|
|
|
|
if (contentWidth > 700) {
|
|
|
|
contentWidthClass = @"NB-ipad-wide";
|
|
|
|
} else if (contentWidth > 420) {
|
|
|
|
contentWidthClass = @"NB-ipad-narrow";
|
|
|
|
} else {
|
|
|
|
contentWidthClass = @"NB-iphone";
|
|
|
|
}
|
|
|
|
|
2012-06-26 23:12:54 -07:00
|
|
|
|
2012-06-21 11:53:48 -07:00
|
|
|
// set up layout values based on iPad/iPhone
|
2012-06-25 20:28:07 -07:00
|
|
|
headerString = [NSString stringWithFormat:@
|
2012-06-28 13:24:40 -07:00
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"reader.css\" >"
|
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"storyDetailView.css\" >"
|
2012-07-19 15:48:35 -07:00
|
|
|
"<meta name=\"viewport\" id=\"viewport\" content=\"width=%i, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"/>",
|
2012-07-01 21:58:55 -07:00
|
|
|
|
|
|
|
|
2012-06-28 13:24:40 -07:00
|
|
|
contentWidth];
|
|
|
|
footerString = [NSString stringWithFormat:@
|
|
|
|
"<script src=\"zepto.js\"></script>"
|
|
|
|
"<script src=\"storyDetailView.js\"></script>"];
|
|
|
|
|
|
|
|
sharingHtmlString = [NSString stringWithFormat:@
|
|
|
|
"<div class='NB-share-header'></div>"
|
|
|
|
"<div class='NB-share-wrapper'><div class='NB-share-inner-wrapper'>"
|
2012-07-26 10:17:08 -07:00
|
|
|
"<div class='NB-share-button'>"
|
|
|
|
"<a href=\"http://ios.newsblur.com/share\">Post to Blurblog</a>"
|
|
|
|
"</div>"
|
2012-06-28 15:03:28 -07:00
|
|
|
//"<div class='NB-save-button'><span class='NB-save-icon'></span>Save this story</div>"
|
2012-06-28 13:24:40 -07:00
|
|
|
"</div></div>"];
|
|
|
|
NSString *story_author = @"";
|
2011-06-13 10:44:17 -04:00
|
|
|
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
|
|
|
}
|
2012-06-28 13:24:40 -07:00
|
|
|
NSString *story_tags = @"";
|
2011-06-13 10:44:17 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2012-07-23 15:27:20 -07:00
|
|
|
NSString *storyHeader = [NSString stringWithFormat:@
|
|
|
|
"<div class=\"NB-header\"><div class=\"NB-header-inner\">"
|
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
|
|
|
"%@"
|
2012-07-23 15:27:20 -07:00
|
|
|
"</div></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:@
|
2012-06-28 11:12:38 -07:00
|
|
|
"<html>"
|
|
|
|
"<head>%@</head>" // header string
|
|
|
|
"<body id=\"story_pane\" class=\"%@\">"
|
2012-06-28 13:24:40 -07:00
|
|
|
" %@" // storyHeader
|
2012-07-16 10:10:52 -07:00
|
|
|
" <div class=\"%@\" id=\"NB-font-style\">"
|
|
|
|
" <div class=\"%@\" id=\"NB-font-size\">"
|
|
|
|
" <div class=\"NB-story\">%@</div>"
|
|
|
|
" </div>" // font-size
|
2012-06-28 13:24:40 -07:00
|
|
|
" </div>" // font-style
|
2012-07-22 14:23:50 -07:00
|
|
|
" %@" // share
|
2012-07-20 00:21:24 -07:00
|
|
|
" <div id=\"NB-comments-wrapper\">"
|
|
|
|
" %@" // friends comments
|
|
|
|
" </div>"
|
2012-06-28 13:24:40 -07:00
|
|
|
" %@"
|
2012-06-28 11:12:38 -07:00
|
|
|
"</body>"
|
|
|
|
"</html>",
|
2012-06-26 23:12:54 -07:00
|
|
|
headerString,
|
2012-06-28 11:12:38 -07:00
|
|
|
contentWidthClass,
|
2012-06-14 16:30:37 -07:00
|
|
|
storyHeader,
|
2012-07-16 10:10:52 -07:00
|
|
|
fontStyleClass,
|
2012-06-28 11:12:38 -07:00
|
|
|
fontSizeClass,
|
2012-06-22 13:15:31 -07:00
|
|
|
[appDelegate.activeStory objectForKey:@"story_content"],
|
2012-06-28 13:24:40 -07:00
|
|
|
sharingHtmlString,
|
2012-07-22 14:23:50 -07:00
|
|
|
commentString,
|
2012-06-28 13:24:40 -07:00
|
|
|
footerString
|
2012-06-14 16:30:37 -07:00
|
|
|
];
|
2011-10-27 19:05:38 -07:00
|
|
|
|
2012-07-23 15:27:20 -07:00
|
|
|
// NSLog(@"\n\n\n\nhtmlString:\n\n\n%@\n\n\n", htmlString);
|
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
|
|
|
|
2012-06-29 10:20:06 -07:00
|
|
|
|
|
|
|
NSDictionary *feed;
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",
|
|
|
|
[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_feed_id"]];
|
|
|
|
|
|
|
|
if (appDelegate.isSocialView) {
|
|
|
|
feed = [appDelegate.dictActiveFeeds objectForKey:feedIdStr];
|
|
|
|
// this is to catch when a user is already subscribed
|
|
|
|
if (!feed) {
|
|
|
|
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
2012-07-01 09:32:18 -07:00
|
|
|
|
2011-10-27 19:05:38 -07:00
|
|
|
for (NSObject *aSubView in [self.webView subviews]) {
|
|
|
|
if ([aSubView isKindOfClass:[UIScrollView class]]) {
|
|
|
|
UIScrollView * theScrollView = (UIScrollView *)aSubView;
|
2012-06-26 16:24:19 -07:00
|
|
|
if (appDelegate.isRiverView || appDelegate.isSocialView) {
|
2012-07-03 17:54:36 -07:00
|
|
|
theScrollView.contentInset = UIEdgeInsetsMake(19, 0, 0, 0);
|
2012-07-01 09:32:18 -07:00
|
|
|
theScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(19, 0, 0, 0);
|
2011-10-28 10:51:03 -07:00
|
|
|
} else {
|
2012-07-03 17:54:36 -07:00
|
|
|
theScrollView.contentInset = UIEdgeInsetsMake(9, 0, 0, 0);
|
2012-07-01 09:32:18 -07:00
|
|
|
theScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(9, 0, 0, 0);
|
2011-10-28 10:51:03 -07:00
|
|
|
}
|
2012-06-07 18:49:50 -07:00
|
|
|
[self.webView insertSubview:feedTitleGradient aboveSubview:theScrollView];
|
2012-06-26 16:24:19 -07:00
|
|
|
[theScrollView setContentOffset:CGPointMake(0, (appDelegate.isRiverView || appDelegate.isSocialView) ? -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"];
|
2012-07-15 17:18:23 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
|
|
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);
|
2012-07-20 22:00:30 -07:00
|
|
|
titleImageView.hidden = YES;
|
|
|
|
self.navigationItem.titleView = titleImageView;
|
|
|
|
titleImageView.hidden = NO;
|
|
|
|
|
2012-07-15 17:18:23 -07:00
|
|
|
}
|
2011-12-01 09:01:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)webView:(UIWebView *)webView
|
|
|
|
shouldStartLoadWithRequest:(NSURLRequest *)request
|
|
|
|
navigationType:(UIWebViewNavigationType)navigationType {
|
2012-06-25 23:06:16 -07:00
|
|
|
NSURL *url = [request URL];
|
|
|
|
NSArray *urlComponents = [url pathComponents];
|
2012-07-23 16:17:49 -07:00
|
|
|
NSString *action = @"";
|
|
|
|
if ([urlComponents count] > 1) {
|
|
|
|
action = [NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:1]];
|
|
|
|
}
|
|
|
|
|
2012-06-25 23:06:16 -07:00
|
|
|
// HACK: Using ios.newsblur.com to intercept the javascript share, reply, and edit events.
|
|
|
|
// the pathComponents do not work correctly unless it is a correctly formed url
|
|
|
|
// Is there a better way? Someone show me the light
|
|
|
|
if ([[url host] isEqualToString: @"ios.newsblur.com"]){
|
2012-07-20 15:54:10 -07:00
|
|
|
if ([action isEqualToString:@"reply"] ||
|
|
|
|
[action isEqualToString:@"edit-reply"] ||
|
2012-07-26 13:54:45 -07:00
|
|
|
[action isEqualToString:@"edit-share"] ||
|
|
|
|
[action isEqualToString:@"like-comment"] ||
|
|
|
|
[action isEqualToString:@"unlike-comment"]) {
|
2012-07-20 00:21:24 -07:00
|
|
|
appDelegate.activeComment = nil;
|
|
|
|
// search for the comment from friends comments
|
|
|
|
NSArray *friendComments = [appDelegate.activeStory objectForKey:@"friend_comments"];
|
|
|
|
for (int i = 0; i < friendComments.count; i++) {
|
2012-06-25 23:06:16 -07:00
|
|
|
NSString *userId = [NSString stringWithFormat:@"%@",
|
2012-07-20 00:21:24 -07:00
|
|
|
[[friendComments objectAtIndex:i] objectForKey:@"user_id"]];
|
2012-06-25 23:06:16 -07:00
|
|
|
if([userId isEqualToString:[NSString stringWithFormat:@"%@",
|
|
|
|
[urlComponents objectAtIndex:2]]]){
|
2012-07-20 00:21:24 -07:00
|
|
|
appDelegate.activeComment = [friendComments objectAtIndex:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appDelegate.activeComment == nil) {
|
|
|
|
NSArray *publicComments = [appDelegate.activeStory objectForKey:@"public_comments"];
|
|
|
|
for (int i = 0; i < publicComments.count; i++) {
|
|
|
|
NSString *userId = [NSString stringWithFormat:@"%@",
|
|
|
|
[[publicComments objectAtIndex:i] objectForKey:@"user_id"]];
|
|
|
|
if([userId isEqualToString:[NSString stringWithFormat:@"%@",
|
|
|
|
[urlComponents objectAtIndex:2]]]){
|
|
|
|
appDelegate.activeComment = [publicComments objectAtIndex:i];
|
|
|
|
}
|
2012-06-25 18:05:25 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-20 15:54:10 -07:00
|
|
|
|
|
|
|
if ([action isEqualToString:@"reply"]) {
|
|
|
|
[appDelegate showShareView:@"reply"
|
|
|
|
setUserId:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:2]]
|
|
|
|
setUsername:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:3]]
|
2012-07-25 20:38:44 -07:00
|
|
|
setCommentIndex:nil];
|
2012-07-20 15:54:10 -07:00
|
|
|
} else if ([action isEqualToString:@"edit-reply"]) {
|
|
|
|
[appDelegate showShareView:@"edit-reply"
|
|
|
|
setUserId:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:2]]
|
|
|
|
setUsername:nil
|
|
|
|
setCommentIndex:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:4]]];
|
|
|
|
} else if ([action isEqualToString:@"edit-share"]) {
|
|
|
|
[appDelegate showShareView:@"edit-share"
|
|
|
|
setUserId:nil
|
|
|
|
setUsername:nil
|
2012-07-20 18:04:54 -07:00
|
|
|
setCommentIndex:nil];
|
2012-07-26 13:54:45 -07:00
|
|
|
} else if ([action isEqualToString:@"like-comment"]) {
|
|
|
|
[self toggleLikeComment:YES];
|
|
|
|
} else if ([action isEqualToString:@"unlike-comment"]) {
|
|
|
|
[self toggleLikeComment:NO];
|
2012-07-20 15:54:10 -07:00
|
|
|
}
|
|
|
|
return NO;
|
2012-06-25 23:06:16 -07:00
|
|
|
} else if ([action isEqualToString:@"share"]) {
|
2012-07-26 13:54:45 -07:00
|
|
|
// test to see if the user has commented
|
|
|
|
|
|
|
|
// search for the comment from friends comments
|
|
|
|
NSArray *friendComments = [appDelegate.activeStory objectForKey:@"friend_comments"];
|
|
|
|
NSString *currentUserId = [NSString stringWithFormat:@"%@", [appDelegate.dictUserProfile objectForKey:@"user_id"]];
|
|
|
|
for (int i = 0; i < friendComments.count; i++) {
|
|
|
|
NSString *userId = [NSString stringWithFormat:@"%@",
|
|
|
|
[[friendComments objectAtIndex:i] objectForKey:@"user_id"]];
|
|
|
|
if([userId isEqualToString:currentUserId]){
|
|
|
|
appDelegate.activeComment = [friendComments objectAtIndex:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appDelegate.activeComment == nil) {
|
|
|
|
[appDelegate showShareView:@"share"
|
|
|
|
setUserId:nil
|
|
|
|
setUsername:nil
|
|
|
|
setCommentIndex:nil];
|
|
|
|
} else {
|
|
|
|
[appDelegate showShareView:@"edit-share"
|
|
|
|
setUserId:nil
|
|
|
|
setUsername:nil
|
|
|
|
setCommentIndex:nil];
|
|
|
|
}
|
2012-06-25 23:06:16 -07:00
|
|
|
return NO;
|
2012-07-01 21:58:55 -07:00
|
|
|
} else if ([action isEqualToString:@"show-profile"]) {
|
2012-07-03 17:54:36 -07:00
|
|
|
appDelegate.activeUserProfileId = [NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:2]];
|
|
|
|
[self showUserProfile:[urlComponents objectAtIndex:2]
|
|
|
|
xCoordinate:[[urlComponents objectAtIndex:3] intValue]
|
|
|
|
yCoordinate:[[urlComponents objectAtIndex:4] intValue]
|
|
|
|
width:[[urlComponents objectAtIndex:5] intValue]
|
|
|
|
height:[[urlComponents objectAtIndex:6] intValue]];
|
2012-07-01 21:58:55 -07:00
|
|
|
return NO;
|
2012-06-22 13:15:31 -07:00
|
|
|
}
|
2011-12-01 09:01:18 -08:00
|
|
|
}
|
2012-06-25 23:06:16 -07:00
|
|
|
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
|
|
|
|
[appDelegate showOriginalStory:url];
|
|
|
|
return NO;
|
|
|
|
}
|
2011-12-01 09:01:18 -08:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
- (void)showUserProfile:(NSString *)userId xCoordinate:(int)x yCoordinate:(int)y width:(int)width height:(int)height {
|
2012-07-12 22:05:23 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-07-25 17:34:45 -07:00
|
|
|
if (popoverController == nil) {
|
|
|
|
popoverController = [[UIPopoverController alloc]
|
|
|
|
initWithContentViewController:appDelegate.userProfileViewController];
|
|
|
|
|
|
|
|
popoverController.delegate = self;
|
|
|
|
} else {
|
|
|
|
if (popoverController.isPopoverVisible) {
|
|
|
|
[popoverController dismissPopoverAnimated:YES];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[popoverController setContentViewController:appDelegate.userProfileViewController];
|
|
|
|
}
|
|
|
|
|
|
|
|
[popoverController setPopoverContentSize:CGSizeMake(320, 416)];
|
|
|
|
|
|
|
|
// only adjust for the bar if user is scrolling
|
|
|
|
if (appDelegate.isRiverView || appDelegate.isSocialView) {
|
|
|
|
if (self.webView.scrollView.contentOffset.y == -19) {
|
|
|
|
y = y + 19;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (self.webView.scrollView.contentOffset.y == -9) {
|
|
|
|
y = y + 9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[popoverController presentPopoverFromRect:CGRectMake(x, y, width, height)
|
|
|
|
inView:self.view
|
|
|
|
permittedArrowDirections:UIPopoverArrowDirectionAny
|
|
|
|
animated:YES];
|
2012-07-03 17:54:36 -07:00
|
|
|
} else {
|
2012-07-12 22:05:23 -07:00
|
|
|
[appDelegate showUserProfileModal];
|
|
|
|
}
|
2012-07-03 17:54:36 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
- (void)webViewDidStartLoad:(UIWebView *)webView {
|
2012-06-24 23:02:37 -07:00
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
2012-06-26 23:12:54 -07:00
|
|
|
if ([userPreferences integerForKey:@"fontSizing"]){
|
|
|
|
[self changeFontSize:[userPreferences stringForKey:@"fontSizing"]];
|
2012-06-24 23:02:37 -07:00
|
|
|
}
|
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)webViewDidFinishLoad:(UIWebView *)webView {
|
2012-06-24 23:02:37 -07:00
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
2012-06-26 23:12:54 -07:00
|
|
|
if ([userPreferences integerForKey:@"fontSizing"]){
|
|
|
|
[self changeFontSize:[userPreferences stringForKey:@"fontSizing"]];
|
2012-06-24 23:02:37 -07:00
|
|
|
}
|
2011-12-01 09:01:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Actions
|
|
|
|
|
2012-07-25 10:50:52 -07:00
|
|
|
- (IBAction)tapProgressBar:(id)sender {
|
|
|
|
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:NO];
|
|
|
|
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
|
hud.mode = MBProgressHUDModeText;
|
|
|
|
hud.removeFromSuperViewOnHide = YES;
|
|
|
|
int unreadCount = appDelegate.unreadCount;
|
|
|
|
if (unreadCount == 0) {
|
|
|
|
hud.labelText = @"No unread stories";
|
|
|
|
} else if (unreadCount == 1) {
|
|
|
|
hud.labelText = @"1 unread story";
|
|
|
|
} else {
|
|
|
|
hud.labelText = [NSString stringWithFormat:@"%i unread stories", unreadCount];
|
|
|
|
}
|
|
|
|
[hud hide:YES afterDelay:0.8];
|
|
|
|
}
|
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
- (void)setNextPreviousButtons {
|
2012-06-28 15:03:28 -07:00
|
|
|
int nextIndex = [appDelegate indexOfNextUnreadStory];
|
2011-12-01 09:01:18 -08:00
|
|
|
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"])) {
|
|
|
|
|
2012-07-25 10:50:52 -07:00
|
|
|
[buttonPrevious setStyle:UIBarButtonItemStyleBordered];
|
|
|
|
[buttonPrevious setTitle:@"Previous"];
|
|
|
|
[buttonPrevious setEnabled:NO];
|
2011-12-01 09:01:18 -08:00
|
|
|
} else {
|
|
|
|
[buttonPrevious setStyle:UIBarButtonItemStyleBordered];
|
|
|
|
[buttonPrevious setTitle:@"Previous"];
|
2012-07-25 10:50:52 -07:00
|
|
|
[buttonPrevious setEnabled:YES];
|
2011-12-01 09:01:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
2012-06-29 12:54:52 -07:00
|
|
|
NSString *urlString;
|
|
|
|
|
|
|
|
if (appDelegate.isSocialView) {
|
|
|
|
urlString = [NSString stringWithFormat:@"http://%@/reader/mark_social_stories_as_read",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
} else {
|
|
|
|
urlString = [NSString stringWithFormat:@"http://%@/reader/mark_story_as_read",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
}
|
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2012-06-29 12:54:52 -07:00
|
|
|
|
|
|
|
if (appDelegate.isSocialView) {
|
2012-06-29 17:37:08 -07:00
|
|
|
NSArray *storyId = [NSArray arrayWithObject:[appDelegate.activeStory objectForKey:@"id"]];
|
|
|
|
NSDictionary *feedStory = [NSDictionary dictionaryWithObject:storyId
|
|
|
|
forKey:[NSString stringWithFormat:@"%@",
|
|
|
|
[appDelegate.activeStory objectForKey:@"story_feed_id"]]];
|
|
|
|
|
|
|
|
NSDictionary *usersFeedsStories = [NSDictionary dictionaryWithObject:feedStory
|
|
|
|
forKey:[NSString stringWithFormat:@"%@",
|
|
|
|
[appDelegate.activeStory objectForKey:@"social_user_id"]]];
|
2012-06-29 12:54:52 -07:00
|
|
|
|
2012-06-29 17:37:08 -07:00
|
|
|
[request setPostValue:[usersFeedsStories JSONRepresentation] forKey:@"users_feeds_stories"];
|
2012-06-29 12:54:52 -07:00
|
|
|
} else {
|
|
|
|
[request setPostValue:[appDelegate.activeStory
|
|
|
|
objectForKey:@"id"]
|
|
|
|
forKey:@"story_id"];
|
|
|
|
[request setPostValue:[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_feed_id"]
|
|
|
|
forKey:@"feed_id"];
|
|
|
|
}
|
|
|
|
|
|
|
|
[request setDidFinishSelector:@selector(finishMarkAsRead:)];
|
|
|
|
[request setDidFailSelector:@selector(finishedWithError:)];
|
2011-12-01 09:01:18 -08:00
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 13:54:45 -07:00
|
|
|
- (void)toggleLikeComment:(BOOL)likeComment {
|
|
|
|
NSString *urlString;
|
|
|
|
if (likeComment) {
|
|
|
|
urlString = [NSString stringWithFormat:@"http://%@/social/like_comment",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
} else {
|
|
|
|
urlString = [NSString stringWithFormat:@"http://%@/social/remove_like_comment",
|
|
|
|
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:@"story_feed_id"];
|
|
|
|
|
|
|
|
|
|
|
|
[request setPostValue:[appDelegate.activeComment objectForKey:@"user_id"] forKey:@"comment_user_id"];
|
|
|
|
|
|
|
|
[request setDidFinishSelector:@selector(finishLikeComment:)];
|
|
|
|
[request setDidFailSelector:@selector(finishedWithError:)];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishLikeComment:(ASIHTTPRequest *)request {
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
initWithDictionary:[responseString JSONValue]];
|
|
|
|
// add the comment into the activeStory dictionary
|
|
|
|
NSDictionary *newStory = [DataUtilities updateComment:results for:appDelegate];
|
|
|
|
|
|
|
|
// update the current story and the activeFeedStories
|
|
|
|
appDelegate.activeStory = newStory;
|
|
|
|
|
|
|
|
NSMutableArray *newActiveFeedStories = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
for (int i = 0; i < appDelegate.activeFeedStories.count; i++) {
|
|
|
|
NSDictionary *feedStory = [appDelegate.activeFeedStories objectAtIndex:i];
|
|
|
|
NSString *storyId = [NSString stringWithFormat:@"%@", [feedStory objectForKey:@"id"]];
|
|
|
|
NSString *currentStoryId = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"id"]];
|
|
|
|
if ([storyId isEqualToString: currentStoryId]){
|
|
|
|
[newActiveFeedStories addObject:newStory];
|
|
|
|
} else {
|
|
|
|
[newActiveFeedStories addObject:[appDelegate.activeFeedStories objectAtIndex:i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
appDelegate.activeFeedStories = [NSArray arrayWithArray:newActiveFeedStories];
|
|
|
|
|
|
|
|
[appDelegate refreshComments];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-29 12:54:52 -07:00
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request {
|
|
|
|
NSLog(@"Error in mark as read is %@", [request error]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishMarkAsRead:(ASIHTTPRequest *)request {
|
2012-07-15 15:06:06 -07:00
|
|
|
// NSString *responseString = [request responseString];
|
|
|
|
// NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
// initWithDictionary:[responseString JSONValue]];
|
2012-07-14 01:16:35 -07:00
|
|
|
// NSLog(@"results in mark as read is %@", results);
|
2012-06-29 12:54:52 -07:00
|
|
|
}
|
|
|
|
|
2012-06-25 20:28:07 -07:00
|
|
|
- (void)refreshComments {
|
2012-07-20 19:14:59 -07:00
|
|
|
NSString *commentString = [self getComments:@"friends"];
|
2012-06-25 20:28:07 -07:00
|
|
|
NSString *jsString = [[NSString alloc] initWithFormat:@
|
2012-07-20 18:04:54 -07:00
|
|
|
"document.getElementById('NB-comments-wrapper').innerHTML = '%@';",
|
2012-07-20 15:54:10 -07:00
|
|
|
commentString];
|
2012-07-23 16:17:49 -07:00
|
|
|
NSLog(@"JSSTRING IS %@\n\n\n", jsString);
|
2012-06-25 20:28:07 -07:00
|
|
|
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
|
2012-07-12 13:34:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)scrolltoBottom {
|
2012-07-19 15:48:35 -07:00
|
|
|
CGPoint bottomOffset = CGPointMake(0, self.webView.scrollView.contentSize.height - self.webView.bounds.size.height);
|
|
|
|
[self.webView.scrollView setContentOffset:bottomOffset animated:YES];
|
2012-06-25 20:28:07 -07:00
|
|
|
}
|
|
|
|
|
2012-06-29 12:54:52 -07:00
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
|
2011-06-14 10:35:33 -04:00
|
|
|
- (IBAction)doNextUnreadStory {
|
2012-06-28 15:03:28 -07:00
|
|
|
int nextIndex = [appDelegate indexOfNextUnreadStory];
|
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-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
|
|
|
}
|
|
|
|
|
2012-06-28 13:24:40 -07:00
|
|
|
- (IBAction)doNextStory {
|
2012-06-28 15:03:28 -07:00
|
|
|
int nextIndex = [appDelegate indexOfNextStory];
|
2012-06-28 13:24:40 -07:00
|
|
|
|
2012-06-28 15:03:28 -07:00
|
|
|
if (nextIndex == -1) {
|
2012-06-28 13:24:40 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-06-28 15:03:28 -07:00
|
|
|
|
2012-06-28 13:24:40 -07:00
|
|
|
[self.loadingIndicator stopAnimating];
|
|
|
|
|
|
|
|
if (self.appDelegate.feedDetailViewController.pageFetching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[appDelegate setActiveStory:[[appDelegate activeFeedStories]
|
|
|
|
objectAtIndex:nextIndex]];
|
|
|
|
[appDelegate pushReadStory:[appDelegate.activeStory objectForKey:@"id"]];
|
|
|
|
[self setActiveStory];
|
|
|
|
[self showStory];
|
|
|
|
[self markStoryAsRead];
|
|
|
|
[self setNextPreviousButtons];
|
|
|
|
[appDelegate changeActiveFeedDetailRow];
|
2012-06-28 15:03:28 -07:00
|
|
|
|
2012-06-28 13:24:40 -07:00
|
|
|
[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-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-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-27 21:28:04 -07:00
|
|
|
- (void)changeWebViewWidth:(int)width {
|
2012-06-28 11:12:38 -07:00
|
|
|
int contentWidth = self.view.frame.size.width;
|
|
|
|
NSString *contentWidthClass;
|
|
|
|
|
2012-07-16 10:10:52 -07:00
|
|
|
if (contentWidth > 740) {
|
2012-06-28 11:12:38 -07:00
|
|
|
contentWidthClass = @"NB-ipad-wide";
|
|
|
|
} else if (contentWidth > 420) {
|
|
|
|
contentWidthClass = @"NB-ipad-narrow";
|
|
|
|
} else {
|
|
|
|
contentWidthClass = @"NB-iphone";
|
|
|
|
}
|
|
|
|
|
2012-07-12 13:34:41 -07:00
|
|
|
NSString *jsString = [[NSString alloc] initWithFormat:
|
2012-07-19 15:48:35 -07:00
|
|
|
@"document.getElementsByTagName('body')[0].setAttribute('class', '%@');"
|
|
|
|
"document.getElementById(\"viewport\").setAttribute(\"content\", \"width=%i;initial-scale=1; maximum-scale=1.0; user-scalable=0;\");",
|
2012-07-16 10:10:52 -07:00
|
|
|
contentWidthClass,
|
|
|
|
contentWidth];
|
2012-06-27 21:28:04 -07:00
|
|
|
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
|
|
|
|
}
|
|
|
|
|
2012-06-18 14:31:42 -07:00
|
|
|
- (IBAction)toggleFontSize:(id)sender {
|
2012-07-24 23:21:28 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
if (popoverController == nil) {
|
|
|
|
popoverController = [[UIPopoverController alloc]
|
|
|
|
initWithContentViewController:appDelegate.fontSettingsViewController];
|
|
|
|
|
|
|
|
popoverController.delegate = self;
|
|
|
|
} else {
|
|
|
|
if (popoverController.isPopoverVisible) {
|
|
|
|
[popoverController dismissPopoverAnimated:YES];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[popoverController setContentViewController:appDelegate.fontSettingsViewController];
|
|
|
|
}
|
|
|
|
|
|
|
|
[popoverController setPopoverContentSize:CGSizeMake(274.0, 130.0)];
|
|
|
|
|
|
|
|
[popoverController presentPopoverFromBarButtonItem:sender
|
|
|
|
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
|
|
|
|
} else {
|
|
|
|
FontSettingsViewController *fontSettings = [[FontSettingsViewController alloc] init];
|
|
|
|
appDelegate.fontSettingsViewController = fontSettings;
|
|
|
|
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:appDelegate.fontSettingsViewController];
|
|
|
|
|
|
|
|
// adding Done button
|
|
|
|
UIBarButtonItem *donebutton = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"Done"
|
|
|
|
style:UIBarButtonItemStyleDone
|
|
|
|
target:self
|
|
|
|
action:@selector(hideToggleFontSize)];
|
|
|
|
|
|
|
|
appDelegate.fontSettingsViewController.navigationItem.rightBarButtonItem = donebutton;
|
|
|
|
appDelegate.fontSettingsViewController.navigationItem.title = @"Style";
|
|
|
|
navController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
|
|
|
[self presentModalViewController:navController animated:YES];
|
|
|
|
|
|
|
|
}
|
2012-07-13 21:31:48 -07:00
|
|
|
}
|
2012-07-12 11:43:49 -07:00
|
|
|
|
2012-07-13 21:31:48 -07:00
|
|
|
- (void)hideToggleFontSize {
|
|
|
|
[self dismissModalViewControllerAnimated:YES];
|
2012-06-18 14:31:42 -07:00
|
|
|
}
|
|
|
|
|
2012-06-26 23:12:54 -07:00
|
|
|
- (void)changeFontSize:(NSString *)fontSize {
|
|
|
|
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementById('NB-font-size').setAttribute('class', '%@')",
|
2012-06-18 14:31:42 -07:00
|
|
|
fontSize];
|
2012-07-14 01:16:35 -07:00
|
|
|
|
2012-06-18 14:31:42 -07:00
|
|
|
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
|
|
|
|
}
|
2012-07-14 01:16:35 -07:00
|
|
|
|
2012-06-18 14:31:42 -07:00
|
|
|
- (void)setFontStyle:(NSString *)fontStyle {
|
2012-07-09 21:26:53 -07:00
|
|
|
NSString *jsString;
|
|
|
|
NSString *fontStyleStr;
|
2012-06-24 23:02:37 -07:00
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
2012-07-09 21:26:53 -07:00
|
|
|
|
2012-06-24 23:02:37 -07:00
|
|
|
if ([fontStyle isEqualToString:@"Helvetica"]) {
|
|
|
|
[userPreferences setObject:@"NB-san-serif" forKey:@"fontStyle"];
|
2012-07-09 21:26:53 -07:00
|
|
|
fontStyleStr = @"NB-san-serif";
|
2012-06-24 23:02:37 -07:00
|
|
|
} else {
|
|
|
|
[userPreferences setObject:@"NB-serif" forKey:@"fontStyle"];
|
2012-07-09 21:26:53 -07:00
|
|
|
fontStyleStr = @"NB-serif";
|
2012-06-24 23:02:37 -07:00
|
|
|
}
|
|
|
|
[userPreferences synchronize];
|
|
|
|
|
2012-07-09 21:26:53 -07:00
|
|
|
jsString = [NSString stringWithFormat:@
|
|
|
|
"document.getElementById('NB-font-style').setAttribute('class', '%@')",
|
|
|
|
fontStyleStr];
|
2012-06-29 21:26:47 -07:00
|
|
|
|
2012-06-18 14:31:42 -07:00
|
|
|
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
|
|
|
|
}
|
|
|
|
|
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-07-23 16:17:49 -07:00
|
|
|
- (NSString *)textToHtml:(NSString*)htmlString {
|
|
|
|
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
|
|
|
|
return htmlString;
|
|
|
|
}
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
@end
|