2012-11-05 15:12:42 -08:00
|
|
|
//
|
|
|
|
// StoryPageControl.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 11/2/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "StoryPageControl.h"
|
|
|
|
#import "StoryDetailViewController.h"
|
2012-11-05 17:16:10 -08:00
|
|
|
#import "NewsBlurAppDelegate.h"
|
|
|
|
#import "NewsBlurViewController.h"
|
|
|
|
#import "FeedDetailViewController.h"
|
|
|
|
#import "FontSettingsViewController.h"
|
|
|
|
#import "UserProfileViewController.h"
|
|
|
|
#import "ShareViewController.h"
|
|
|
|
#import "ASIHTTPRequest.h"
|
|
|
|
#import "ASIFormDataRequest.h"
|
|
|
|
#import "Base64.h"
|
|
|
|
#import "Utilities.h"
|
|
|
|
#import "NSString+HTML.h"
|
|
|
|
#import "NBContainerViewController.h"
|
|
|
|
#import "DataUtilities.h"
|
|
|
|
#import "JSON.h"
|
|
|
|
#import "SHK.h"
|
2013-02-27 18:04:03 -08:00
|
|
|
#import "TransparentToolbar.h"
|
|
|
|
#import "UIBarButtonItem+Image.h"
|
2012-11-05 15:12:42 -08:00
|
|
|
|
|
|
|
@implementation StoryPageControl
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
2012-11-14 17:31:52 -08:00
|
|
|
@synthesize currentPage, nextPage, previousPage;
|
2012-11-05 17:16:10 -08:00
|
|
|
@synthesize progressView;
|
|
|
|
@synthesize progressViewContainer;
|
2013-02-27 18:04:03 -08:00
|
|
|
@synthesize separatorBarButton;
|
|
|
|
@synthesize spacerBarButton, spacer2BarButton, spacer3BarButton;
|
2013-03-05 17:00:03 -08:00
|
|
|
@synthesize rightToolbar;
|
2012-11-05 17:16:10 -08:00
|
|
|
@synthesize buttonPrevious;
|
|
|
|
@synthesize buttonNext;
|
|
|
|
@synthesize buttonAction;
|
|
|
|
@synthesize fontSettingsButton;
|
|
|
|
@synthesize originalStoryButton;
|
|
|
|
@synthesize subscribeButton;
|
|
|
|
@synthesize buttonBack;
|
|
|
|
@synthesize bottomPlaceholderToolbar;
|
|
|
|
@synthesize popoverController;
|
|
|
|
@synthesize loadingIndicator;
|
2012-11-07 17:54:16 -08:00
|
|
|
@synthesize inTouchMove;
|
2012-11-08 18:30:45 -08:00
|
|
|
@synthesize isDraggingScrollview;
|
2012-12-13 16:41:52 -08:00
|
|
|
@synthesize waitingForNextUnreadFromServer;
|
2012-11-09 14:13:44 -08:00
|
|
|
@synthesize storyHUD;
|
2012-11-14 17:31:52 -08:00
|
|
|
@synthesize scrollingToPage;
|
2012-11-05 15:12:42 -08:00
|
|
|
|
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
if (self) {
|
|
|
|
// Custom initialization
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-11-05 18:23:45 -08:00
|
|
|
- (void)viewDidLoad {
|
2012-11-05 15:12:42 -08:00
|
|
|
currentPage = [[StoryDetailViewController alloc] initWithNibName:@"StoryDetailViewController" bundle:nil];
|
|
|
|
nextPage = [[StoryDetailViewController alloc] initWithNibName:@"StoryDetailViewController" bundle:nil];
|
2012-11-14 17:31:52 -08:00
|
|
|
previousPage = [[StoryDetailViewController alloc] initWithNibName:@"StoryDetailViewController" bundle:nil];
|
|
|
|
|
2012-11-05 15:12:42 -08:00
|
|
|
currentPage.appDelegate = appDelegate;
|
|
|
|
nextPage.appDelegate = appDelegate;
|
2012-11-14 17:31:52 -08:00
|
|
|
previousPage.appDelegate = appDelegate;
|
2012-11-09 09:31:26 -08:00
|
|
|
currentPage.view.frame = self.scrollView.frame;
|
|
|
|
nextPage.view.frame = self.scrollView.frame;
|
2012-11-14 17:31:52 -08:00
|
|
|
previousPage.view.frame = self.scrollView.frame;
|
|
|
|
|
2012-11-05 15:12:42 -08:00
|
|
|
[self.scrollView addSubview:currentPage.view];
|
|
|
|
[self.scrollView addSubview:nextPage.view];
|
2012-11-14 17:31:52 -08:00
|
|
|
[self.scrollView addSubview:previousPage.view];
|
2012-11-05 15:12:42 -08:00
|
|
|
[self.scrollView setPagingEnabled:YES];
|
|
|
|
[self.scrollView setScrollEnabled:YES];
|
|
|
|
[self.scrollView setShowsHorizontalScrollIndicator:NO];
|
|
|
|
[self.scrollView setShowsVerticalScrollIndicator:NO];
|
2012-11-05 17:16:10 -08:00
|
|
|
|
|
|
|
popoverClass = [WEPopoverController class];
|
|
|
|
|
|
|
|
// adding HUD for progress bar
|
|
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapProgressBar:)];
|
|
|
|
|
|
|
|
[self.progressViewContainer addGestureRecognizer:tap];
|
|
|
|
self.progressViewContainer.hidden = YES;
|
2013-03-05 17:00:03 -08:00
|
|
|
|
2013-02-27 18:04:03 -08:00
|
|
|
rightToolbar = [[TransparentToolbar alloc]
|
2013-03-05 17:00:03 -08:00
|
|
|
initWithFrame:CGRectMake(0, 0, 80, 44)];
|
2012-11-05 17:16:10 -08:00
|
|
|
|
2013-02-27 18:04:03 -08:00
|
|
|
spacerBarButton = [[UIBarButtonItem alloc]
|
|
|
|
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
|
|
|
|
spacerBarButton.width = -12;
|
|
|
|
spacer2BarButton = [[UIBarButtonItem alloc]
|
|
|
|
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
|
|
|
|
spacer2BarButton.width = -4;
|
|
|
|
spacer3BarButton = [[UIBarButtonItem alloc]
|
|
|
|
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
|
2013-02-28 17:07:51 -08:00
|
|
|
spacer3BarButton.width = -10;
|
2012-11-05 17:16:10 -08:00
|
|
|
|
2013-02-27 18:04:03 -08:00
|
|
|
UIImage *separatorImage = [UIImage imageNamed:@"bar-separator.png"];
|
|
|
|
separatorBarButton = [UIBarButtonItem barItemWithImage:separatorImage target:nil action:nil];
|
|
|
|
[separatorBarButton setEnabled:NO];
|
2012-11-05 17:16:10 -08:00
|
|
|
|
2013-02-27 18:04:03 -08:00
|
|
|
UIImage *settingsImage = [UIImage imageNamed:@"nav_icn_settings.png"];
|
|
|
|
fontSettingsButton = [UIBarButtonItem barItemWithImage:settingsImage target:self action:@selector(toggleFontSize:)];
|
2012-11-05 17:16:10 -08:00
|
|
|
|
2013-02-27 18:04:03 -08:00
|
|
|
UIImage *markreadImage = [UIImage imageNamed:@"original_button.png"];
|
|
|
|
originalStoryButton = [UIBarButtonItem barItemWithImage:markreadImage target:self action:@selector(showOriginalSubview:)];
|
2012-11-05 17:16:10 -08:00
|
|
|
|
|
|
|
UIBarButtonItem *subscribeBtn = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"Follow User"
|
|
|
|
style:UIBarButtonSystemItemAction
|
|
|
|
target:self
|
|
|
|
action:@selector(subscribeToBlurblog)
|
|
|
|
];
|
|
|
|
|
|
|
|
self.subscribeButton = subscribeBtn;
|
|
|
|
|
|
|
|
// back button
|
|
|
|
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"All Sites" style:UIBarButtonItemStyleBordered target:self action:@selector(transitionFromFeedDetail)];
|
|
|
|
self.buttonBack = backButton;
|
|
|
|
|
|
|
|
|
2013-03-04 18:21:10 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
2013-02-27 18:04:03 -08:00
|
|
|
[rightToolbar setItems: [NSArray arrayWithObjects:
|
|
|
|
spacerBarButton,
|
|
|
|
fontSettingsButton,
|
|
|
|
spacer2BarButton,
|
|
|
|
separatorBarButton,
|
|
|
|
spacer3BarButton,
|
|
|
|
originalStoryButton, nil]];
|
|
|
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightToolbar];
|
2013-03-04 18:21:10 -08:00
|
|
|
}
|
2012-11-08 18:30:45 -08:00
|
|
|
|
|
|
|
[self.scrollView addObserver:self forKeyPath:@"contentOffset"
|
|
|
|
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
|
|
|
|
context:nil];
|
2013-03-04 17:15:50 -08:00
|
|
|
|
|
|
|
_orientation = [UIApplication sharedApplication].statusBarOrientation;
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2012-11-08 17:39:32 -08:00
|
|
|
[self setNextPreviousButtons];
|
|
|
|
[appDelegate adjustStoryDetailWebView];
|
2012-11-14 17:31:52 -08:00
|
|
|
|
2012-11-13 13:07:36 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
|
|
if (!appDelegate.isSocialView) {
|
|
|
|
UIImage *titleImage;
|
2013-02-21 12:19:15 -08:00
|
|
|
if (appDelegate.isSocialRiverView && [appDelegate.activeFolder isEqualToString:@"river_global"]) {
|
|
|
|
titleImage = [UIImage imageNamed:@"ak-icon-global.png"];
|
|
|
|
} else if (appDelegate.isSocialRiverView && [appDelegate.activeFolder isEqualToString:@"river_blurblogs"]) {
|
|
|
|
titleImage = [UIImage imageNamed:@"ak-icon-blurblogs.png"];
|
2012-11-13 13:07:36 -08:00
|
|
|
} else if (appDelegate.isRiverView && [appDelegate.activeFolder isEqualToString:@"everything"]) {
|
2013-02-21 12:19:15 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"ak-icon-allstories.png"];
|
2012-11-13 13:07:36 -08:00
|
|
|
} else if (appDelegate.isRiverView && [appDelegate.activeFolder isEqualToString:@"saved_stories"]) {
|
2013-02-21 14:44:34 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"clock2.png"];
|
2012-11-13 13:07:36 -08:00
|
|
|
} else if (appDelegate.isRiverView) {
|
2013-02-21 14:44:34 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"g_icn_folder.png"];
|
2012-11-13 13:07:36 -08:00
|
|
|
} else {
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",
|
|
|
|
[appDelegate.activeStory objectForKey:@"story_feed_id"]];
|
|
|
|
titleImage = [Utilities getImage:feedIdStr];
|
|
|
|
}
|
|
|
|
|
|
|
|
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:titleImage];
|
|
|
|
if (appDelegate.isRiverView) {
|
|
|
|
titleImageView.frame = CGRectMake(0.0, 2.0, 22.0, 22.0);
|
|
|
|
} else {
|
|
|
|
titleImageView.frame = CGRectMake(0.0, 2.0, 16.0, 16.0);
|
|
|
|
}
|
|
|
|
titleImageView.hidden = YES;
|
|
|
|
titleImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
self.navigationItem.titleView = titleImageView;
|
|
|
|
titleImageView.hidden = NO;
|
|
|
|
} else {
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",
|
|
|
|
[appDelegate.activeFeed objectForKey:@"id"]];
|
|
|
|
UIImage *titleImage = [Utilities getImage:feedIdStr];
|
|
|
|
titleImage = [Utilities roundCorneredImage:titleImage radius:6];
|
|
|
|
|
|
|
|
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
|
|
|
|
imageView.frame = CGRectMake(0.0, 0.0, 28.0, 28.0);
|
|
|
|
imageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
[imageView setImage:titleImage];
|
|
|
|
self.navigationItem.titleView = imageView;
|
|
|
|
}
|
|
|
|
}
|
2012-12-18 17:29:23 -08:00
|
|
|
|
|
|
|
previousPage.view.hidden = YES;
|
2013-03-04 17:15:50 -08:00
|
|
|
|
|
|
|
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
|
|
|
[self layoutForInterfaceOrientation:orientation];
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
|
|
// set the subscribeButton flag
|
|
|
|
if (appDelegate.isTryFeedView) {
|
|
|
|
self.subscribeButton.title = [NSString stringWithFormat:@"Follow %@", [appDelegate.activeFeed objectForKey:@"username"]];
|
|
|
|
self.navigationItem.leftBarButtonItem = self.subscribeButton;
|
|
|
|
// self.subscribeButton.tintColor = UIColorFromRGB(0x0a6720);
|
|
|
|
}
|
|
|
|
appDelegate.isTryFeedView = NO;
|
2012-12-18 17:29:23 -08:00
|
|
|
[self applyNewIndex:previousPage.pageIndex pageController:previousPage];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
2012-11-07 17:54:16 -08:00
|
|
|
- (void)transitionFromFeedDetail {
|
2012-11-26 09:54:20 -08:00
|
|
|
// [self performSelector:@selector(resetPages) withObject:self afterDelay:0.5];
|
2012-11-07 17:54:16 -08:00
|
|
|
[appDelegate.masterContainerViewController transitionFromFeedDetail];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
|
2013-03-04 17:15:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
|
|
|
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
|
|
|
|
|
|
|
|
|
|
|
|
NSLog(@"%f,%f",self.view.frame.size.width,self.view.frame.size.height);
|
|
|
|
|
|
|
|
} else if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){
|
|
|
|
|
|
|
|
NSLog(@"%f,%f",self.view.frame.size.width,self.view.frame.size.height);
|
|
|
|
}
|
2012-11-13 12:28:16 -08:00
|
|
|
[self refreshPages];
|
2013-03-04 17:15:50 -08:00
|
|
|
[self layoutForInterfaceOrientation:toInterfaceOrientation];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
|
|
if (interfaceOrientation != _orientation) {
|
|
|
|
_orientation = interfaceOrientation;
|
|
|
|
[self refreshPages];
|
|
|
|
previousPage.view.hidden = YES;
|
|
|
|
}
|
2012-11-07 17:54:16 -08:00
|
|
|
}
|
|
|
|
|
2012-11-08 18:30:45 -08:00
|
|
|
- (void)resetPages {
|
2012-11-07 17:54:16 -08:00
|
|
|
[currentPage clearStory];
|
|
|
|
[nextPage clearStory];
|
2012-11-26 09:54:20 -08:00
|
|
|
[previousPage clearStory];
|
2012-11-09 09:31:26 -08:00
|
|
|
|
|
|
|
[currentPage hideStory];
|
|
|
|
[nextPage hideStory];
|
2012-11-26 09:54:20 -08:00
|
|
|
[previousPage hideStory];
|
2012-11-08 18:30:45 -08:00
|
|
|
|
2012-11-26 09:54:20 -08:00
|
|
|
CGRect frame = self.scrollView.frame;
|
|
|
|
self.scrollView.contentSize = frame.size;
|
2012-11-26 16:47:20 -08:00
|
|
|
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Pages are at: %f / %f / %f", previousPage.view.frame.origin.x, currentPage.view.frame.origin.x, nextPage.view.frame.origin.x);
|
2012-12-11 12:01:49 -08:00
|
|
|
currentPage.view.frame = self.scrollView.frame;
|
|
|
|
nextPage.view.frame = self.scrollView.frame;
|
|
|
|
previousPage.view.frame = self.scrollView.frame;
|
|
|
|
|
2012-11-26 16:47:20 -08:00
|
|
|
currentPage.pageIndex = -2;
|
|
|
|
nextPage.pageIndex = -2;
|
|
|
|
previousPage.pageIndex = -2;
|
2012-12-11 12:01:49 -08:00
|
|
|
|
2012-11-07 17:54:16 -08:00
|
|
|
}
|
|
|
|
|
2012-11-13 12:28:16 -08:00
|
|
|
- (void)refreshPages {
|
2013-02-06 18:13:28 -08:00
|
|
|
int pageIndex = currentPage.pageIndex;
|
2012-11-13 12:28:16 -08:00
|
|
|
[self resizeScrollView];
|
|
|
|
[appDelegate adjustStoryDetailWebView];
|
2012-11-14 17:31:52 -08:00
|
|
|
currentPage.pageIndex = -2;
|
|
|
|
nextPage.pageIndex = -2;
|
|
|
|
previousPage.pageIndex = -2;
|
2012-11-13 12:28:16 -08:00
|
|
|
[self changePage:pageIndex animated:NO];
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
// self.scrollView.contentOffset = CGPointMake(self.scrollView.frame.size.width * currentPage.pageIndex, 0);
|
|
|
|
}
|
|
|
|
|
2012-12-07 17:18:31 -08:00
|
|
|
- (void)refreshHeaders {
|
|
|
|
[currentPage refreshHeader];
|
|
|
|
[nextPage refreshHeader];
|
|
|
|
[previousPage refreshHeader];
|
|
|
|
}
|
2012-11-06 17:26:08 -08:00
|
|
|
- (void)resizeScrollView {
|
2012-11-26 09:54:20 -08:00
|
|
|
NSInteger widthCount = self.appDelegate.storyLocationsCount;
|
2012-11-06 17:26:08 -08:00
|
|
|
if (widthCount == 0) {
|
|
|
|
widthCount = 1;
|
|
|
|
}
|
|
|
|
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width
|
|
|
|
* widthCount,
|
|
|
|
self.scrollView.frame.size.height);
|
|
|
|
}
|
|
|
|
|
2012-11-07 17:54:16 -08:00
|
|
|
- (void)touchesMoved:(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] || [theTouch.view isKindOfClass: UIView.class]) {
|
|
|
|
self.inTouchMove = YES;
|
|
|
|
CGPoint touchLocation = [theTouch locationInView:self.view];
|
|
|
|
CGFloat y = touchLocation.y;
|
|
|
|
[appDelegate.masterContainerViewController dragStoryToolbar:y];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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] || [theTouch.view isKindOfClass: UIView.class]) && self.inTouchMove) {
|
|
|
|
self.inTouchMove = NO;
|
|
|
|
[appDelegate.masterContainerViewController adjustFeedDetailScreenForStoryTitles];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Side scroll view
|
|
|
|
|
2012-11-14 17:31:52 -08:00
|
|
|
- (void)applyNewIndex:(NSInteger)newIndex pageController:(StoryDetailViewController *)pageController {
|
2012-11-06 13:45:15 -08:00
|
|
|
NSInteger pageCount = [[appDelegate activeFeedStoryLocations] count];
|
2012-11-05 15:12:42 -08:00
|
|
|
BOOL outOfBounds = newIndex >= pageCount || newIndex < 0;
|
|
|
|
|
|
|
|
if (!outOfBounds) {
|
|
|
|
CGRect pageFrame = pageController.view.frame;
|
|
|
|
pageFrame.origin.y = 0;
|
|
|
|
pageFrame.origin.x = self.scrollView.frame.size.width * newIndex;
|
2012-11-14 17:31:52 -08:00
|
|
|
pageFrame.size.height = self.scrollView.frame.size.height;
|
2012-12-18 17:29:23 -08:00
|
|
|
pageController.view.hidden = NO;
|
2012-11-05 15:12:42 -08:00
|
|
|
pageController.view.frame = pageFrame;
|
|
|
|
} else {
|
2012-11-14 17:31:52 -08:00
|
|
|
// NSLog(@"Out of bounds: was %d, now %d", pageController.pageIndex, newIndex);
|
2012-11-05 15:12:42 -08:00
|
|
|
CGRect pageFrame = pageController.view.frame;
|
2012-11-14 17:31:52 -08:00
|
|
|
pageFrame.origin.x = self.scrollView.frame.size.width * newIndex;
|
2012-12-18 17:29:23 -08:00
|
|
|
pageFrame.origin.y = self.scrollView.frame.size.height;
|
2012-12-06 15:30:16 -08:00
|
|
|
pageFrame.size.height = self.scrollView.frame.size.height;
|
2012-12-18 17:29:23 -08:00
|
|
|
pageController.view.hidden = YES;
|
2012-11-05 15:12:42 -08:00
|
|
|
pageController.view.frame = pageFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
pageController.pageIndex = newIndex;
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Applied Index: Was %d, now %d (%d/%d/%d) [%d stories - %d]", wasIndex, newIndex, previousPage.pageIndex, currentPage.pageIndex, nextPage.pageIndex, [appDelegate.activeFeedStoryLocations count], outOfBounds);
|
2012-11-05 15:12:42 -08:00
|
|
|
|
2012-11-26 09:54:20 -08:00
|
|
|
if (newIndex > 0 && newIndex >= [appDelegate.activeFeedStoryLocations count]) {
|
2012-12-06 15:30:16 -08:00
|
|
|
pageController.pageIndex = -2;
|
2012-12-13 16:41:52 -08:00
|
|
|
if (self.appDelegate.feedDetailViewController.feedPage < 100 &&
|
2012-11-05 18:23:45 -08:00
|
|
|
!self.appDelegate.feedDetailViewController.pageFinished &&
|
|
|
|
!self.appDelegate.feedDetailViewController.pageFetching) {
|
|
|
|
[self.appDelegate.feedDetailViewController fetchNextPage:^() {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Fetched next page, %d stories", [appDelegate.activeFeedStoryLocations count]);
|
2012-11-05 18:23:45 -08:00
|
|
|
[self applyNewIndex:newIndex pageController:pageController];
|
|
|
|
}];
|
2012-12-06 15:30:16 -08:00
|
|
|
} else if (!self.appDelegate.feedDetailViewController.pageFinished &&
|
|
|
|
!self.appDelegate.feedDetailViewController.pageFetching) {
|
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
|
|
|
[appDelegate hideStoryDetailView];
|
2012-11-05 18:23:45 -08:00
|
|
|
}
|
2012-11-14 17:31:52 -08:00
|
|
|
} else if (!outOfBounds) {
|
2012-11-06 13:45:15 -08:00
|
|
|
int location = [appDelegate indexFromLocation:pageController.pageIndex];
|
|
|
|
[pageController setActiveStoryAtIndex:location];
|
2012-11-14 17:31:52 -08:00
|
|
|
[pageController clearStory];
|
2012-11-19 19:15:05 -08:00
|
|
|
if (self.isDraggingScrollview ||
|
2012-11-26 16:47:20 -08:00
|
|
|
self.scrollingToPage < 0 ||
|
2012-11-19 19:15:05 -08:00
|
|
|
abs(newIndex - self.scrollingToPage) <= 1) {
|
2012-11-14 17:31:52 -08:00
|
|
|
[pageController initStory];
|
|
|
|
[pageController drawStory];
|
|
|
|
} else {
|
2012-11-26 09:54:20 -08:00
|
|
|
[pageController clearStory];
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Skipping drawing %d (waiting for %d)", newIndex, self.scrollingToPage);
|
2012-11-14 17:31:52 -08:00
|
|
|
}
|
|
|
|
} else if (outOfBounds) {
|
|
|
|
[pageController clearStory];
|
2012-11-05 18:23:45 -08:00
|
|
|
}
|
2012-11-05 17:16:10 -08:00
|
|
|
|
2012-11-06 17:26:08 -08:00
|
|
|
[self resizeScrollView];
|
2012-11-05 17:16:10 -08:00
|
|
|
[self.loadingIndicator stopAnimating];
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
|
|
|
|
2012-11-14 17:31:52 -08:00
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)sender {
|
2012-11-26 09:54:20 -08:00
|
|
|
// [sender setContentOffset:CGPointMake(sender.contentOffset.x, 0)];
|
2012-11-05 15:12:42 -08:00
|
|
|
CGFloat pageWidth = self.scrollView.frame.size.width;
|
|
|
|
float fractionalPage = self.scrollView.contentOffset.x / pageWidth;
|
|
|
|
|
|
|
|
NSInteger lowerNumber = floor(fractionalPage);
|
|
|
|
NSInteger upperNumber = lowerNumber + 1;
|
2012-11-14 17:31:52 -08:00
|
|
|
NSInteger previousNumber = lowerNumber - 1;
|
2012-11-05 15:12:42 -08:00
|
|
|
|
2012-11-26 09:54:20 -08:00
|
|
|
int storyCount = [appDelegate.activeFeedStoryLocations count];
|
|
|
|
if (storyCount == 0 || lowerNumber > storyCount) return;
|
|
|
|
|
2012-11-14 17:31:52 -08:00
|
|
|
// NSLog(@"Did Scroll: %f = %d (%d/%d/%d)", fractionalPage, lowerNumber, previousPage.pageIndex, currentPage.pageIndex, nextPage.pageIndex);
|
|
|
|
if (lowerNumber == currentPage.pageIndex) {
|
|
|
|
if (upperNumber != nextPage.pageIndex) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Next was %d, now %d (A)", nextPage.pageIndex, upperNumber);
|
2012-11-05 15:12:42 -08:00
|
|
|
[self applyNewIndex:upperNumber pageController:nextPage];
|
|
|
|
}
|
2012-11-14 17:31:52 -08:00
|
|
|
if (previousNumber != previousPage.pageIndex) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Prev was %d, now %d (A)", previousPage.pageIndex, previousNumber);
|
2012-11-14 17:31:52 -08:00
|
|
|
[self applyNewIndex:previousNumber pageController:previousPage];
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
2012-11-14 17:31:52 -08:00
|
|
|
} else if (upperNumber == currentPage.pageIndex) {
|
|
|
|
// Going backwards
|
|
|
|
if (lowerNumber != previousPage.pageIndex) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Prev was %d, now %d (B)", previousPage.pageIndex, previousNumber);
|
2012-11-14 17:31:52 -08:00
|
|
|
[self applyNewIndex:lowerNumber pageController:previousPage];
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
2012-11-14 17:31:52 -08:00
|
|
|
} else {
|
|
|
|
// Going forwards
|
|
|
|
if (lowerNumber == nextPage.pageIndex) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Prev was %d, now %d (C1)", previousPage.pageIndex, previousNumber);
|
2012-11-14 17:31:52 -08:00
|
|
|
// [self applyNewIndex:upperNumber pageController:nextPage];
|
|
|
|
// [self applyNewIndex:lowerNumber pageController:currentPage];
|
|
|
|
[self applyNewIndex:previousNumber pageController:previousPage];
|
|
|
|
} else if (upperNumber == nextPage.pageIndex) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Prev was %d, now %d (C2)", previousPage.pageIndex, previousNumber);
|
2012-11-05 15:12:42 -08:00
|
|
|
[self applyNewIndex:lowerNumber pageController:currentPage];
|
2012-11-14 17:31:52 -08:00
|
|
|
[self applyNewIndex:previousNumber pageController:previousPage];
|
|
|
|
} else {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Next was %d, now %d (C3)", nextPage.pageIndex, upperNumber);
|
|
|
|
// NSLog(@"Current was %d, now %d (C3)", currentPage.pageIndex, lowerNumber);
|
|
|
|
// NSLog(@"Prev was %d, now %d (C3)", previousPage.pageIndex, previousNumber);
|
2012-11-05 15:12:42 -08:00
|
|
|
[self applyNewIndex:lowerNumber pageController:currentPage];
|
|
|
|
[self applyNewIndex:upperNumber pageController:nextPage];
|
2012-11-26 09:54:20 -08:00
|
|
|
[self applyNewIndex:previousNumber pageController:previousPage];
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
|
|
|
}
|
2012-11-26 09:54:20 -08:00
|
|
|
|
|
|
|
// if (self.isDraggingScrollview) {
|
|
|
|
[self setStoryFromScroll];
|
|
|
|
// }
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
|
|
|
|
2012-11-08 18:30:45 -08:00
|
|
|
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
|
|
|
|
self.isDraggingScrollview = YES;
|
|
|
|
}
|
|
|
|
|
2012-11-14 17:31:52 -08:00
|
|
|
- (void)scrollViewDidEndDecelerating:(UIScrollView *)newScrollView
|
|
|
|
{
|
|
|
|
[self scrollViewDidEndScrollingAnimation:newScrollView];
|
|
|
|
}
|
|
|
|
|
2012-11-05 15:12:42 -08:00
|
|
|
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)newScrollView
|
|
|
|
{
|
2012-11-08 18:30:45 -08:00
|
|
|
self.isDraggingScrollview = NO;
|
2012-11-14 17:31:52 -08:00
|
|
|
CGFloat pageWidth = self.scrollView.frame.size.width;
|
|
|
|
float fractionalPage = self.scrollView.contentOffset.x / pageWidth;
|
|
|
|
NSInteger nearestNumber = lround(fractionalPage);
|
|
|
|
self.scrollingToPage = nearestNumber;
|
2012-11-08 17:39:32 -08:00
|
|
|
[self setStoryFromScroll];
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
|
|
|
|
2012-11-08 18:30:45 -08:00
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
2012-11-19 19:15:05 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
|
2013-02-06 15:15:43 -08:00
|
|
|
[keyPath isEqual:@"contentOffset"] &&
|
2012-11-19 19:15:05 -08:00
|
|
|
self.isDraggingScrollview) {
|
2012-11-08 18:30:45 -08:00
|
|
|
CGFloat pageWidth = self.scrollView.frame.size.width;
|
|
|
|
float fractionalPage = self.scrollView.contentOffset.x / pageWidth;
|
|
|
|
NSInteger nearestNumber = lround(fractionalPage);
|
|
|
|
|
2012-11-28 15:21:44 -08:00
|
|
|
if (![appDelegate.activeFeedStories count]) return;
|
|
|
|
|
2012-11-08 18:30:45 -08:00
|
|
|
int storyIndex = [appDelegate indexFromLocation:nearestNumber];
|
2012-11-19 19:15:05 -08:00
|
|
|
if (storyIndex != [appDelegate indexOfActiveStory]) {
|
|
|
|
appDelegate.activeStory = [appDelegate.activeFeedStories objectAtIndex:storyIndex];
|
|
|
|
[appDelegate changeActiveFeedDetailRow];
|
|
|
|
}
|
2012-11-08 18:30:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-05 18:23:45 -08:00
|
|
|
- (void)changePage:(NSInteger)pageIndex {
|
2012-11-09 11:39:36 -08:00
|
|
|
[self changePage:pageIndex animated:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)changePage:(NSInteger)pageIndex animated:(BOOL)animated {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"changePage to %d (animated: %d)", pageIndex, animated);
|
2012-11-05 18:23:45 -08:00
|
|
|
// update the scroll view to the appropriate page
|
2012-11-06 17:26:08 -08:00
|
|
|
[self resizeScrollView];
|
|
|
|
|
2012-11-05 18:23:45 -08:00
|
|
|
CGRect frame = self.scrollView.frame;
|
|
|
|
frame.origin.x = frame.size.width * pageIndex;
|
|
|
|
frame.origin.y = 0;
|
2012-11-09 14:57:33 -08:00
|
|
|
|
2012-11-14 17:31:52 -08:00
|
|
|
self.scrollingToPage = pageIndex;
|
|
|
|
|
2012-11-28 15:46:11 -08:00
|
|
|
// Check if already on the selected page
|
2012-11-08 17:39:32 -08:00
|
|
|
if (self.scrollView.contentOffset.x == frame.origin.x) {
|
|
|
|
[self applyNewIndex:pageIndex pageController:currentPage];
|
|
|
|
[self setStoryFromScroll];
|
|
|
|
} else {
|
2012-11-09 11:39:36 -08:00
|
|
|
[self.scrollView scrollRectToVisible:frame animated:animated];
|
|
|
|
if (!animated) {
|
|
|
|
[self setStoryFromScroll];
|
|
|
|
}
|
2012-11-08 17:39:32 -08:00
|
|
|
}
|
2012-11-05 18:23:45 -08:00
|
|
|
}
|
|
|
|
|
2012-11-08 17:39:32 -08:00
|
|
|
- (void)setStoryFromScroll {
|
2012-11-26 09:54:20 -08:00
|
|
|
[self setStoryFromScroll:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setStoryFromScroll:(BOOL)force {
|
2012-11-08 17:39:32 -08:00
|
|
|
CGFloat pageWidth = self.scrollView.frame.size.width;
|
|
|
|
float fractionalPage = self.scrollView.contentOffset.x / pageWidth;
|
|
|
|
NSInteger nearestNumber = lround(fractionalPage);
|
2012-11-07 17:54:16 -08:00
|
|
|
|
2012-11-26 09:54:20 -08:00
|
|
|
if (!force && currentPage.pageIndex > 0 &&
|
|
|
|
currentPage.pageIndex == nearestNumber &&
|
|
|
|
currentPage.pageIndex != self.scrollingToPage) {
|
2012-11-26 16:47:20 -08:00
|
|
|
// NSLog(@"Skipping setStoryFromScroll: currentPage is %d (%d, %d)", currentPage.pageIndex, nearestNumber, self.scrollingToPage);
|
2012-11-26 09:54:20 -08:00
|
|
|
return;
|
|
|
|
}
|
2012-11-19 19:15:05 -08:00
|
|
|
|
2012-11-14 17:31:52 -08:00
|
|
|
if (currentPage.pageIndex < nearestNumber) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Swap next into current, current into previous: %d / %d", currentPage.pageIndex, nearestNumber);
|
2012-11-14 17:31:52 -08:00
|
|
|
StoryDetailViewController *swapCurrentController = currentPage;
|
|
|
|
StoryDetailViewController *swapPreviousController = previousPage;
|
2012-11-08 17:39:32 -08:00
|
|
|
currentPage = nextPage;
|
2012-11-14 17:31:52 -08:00
|
|
|
previousPage = swapCurrentController;
|
|
|
|
nextPage = swapPreviousController;
|
|
|
|
} else if (currentPage.pageIndex > nearestNumber) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Swap previous into current: %d / %d", currentPage.pageIndex, nearestNumber);
|
2012-11-14 17:31:52 -08:00
|
|
|
StoryDetailViewController *swapCurrentController = currentPage;
|
|
|
|
StoryDetailViewController *swapNextController = nextPage;
|
|
|
|
currentPage = previousPage;
|
|
|
|
nextPage = swapCurrentController;
|
|
|
|
previousPage = swapNextController;
|
|
|
|
}
|
2012-11-07 17:54:16 -08:00
|
|
|
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Set Story from scroll: %f = %d (%d/%d/%d)", fractionalPage, nearestNumber, previousPage.pageIndex, currentPage.pageIndex, nextPage.pageIndex);
|
2012-11-08 18:30:45 -08:00
|
|
|
|
2012-11-13 12:28:16 -08:00
|
|
|
nextPage.webView.scrollView.scrollsToTop = NO;
|
2012-11-14 17:31:52 -08:00
|
|
|
previousPage.webView.scrollView.scrollsToTop = NO;
|
2012-11-13 12:28:16 -08:00
|
|
|
currentPage.webView.scrollView.scrollsToTop = YES;
|
2012-11-26 09:54:20 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
appDelegate.feedDetailViewController.storyTitlesTable.scrollsToTop = NO;
|
|
|
|
}
|
2012-11-13 12:28:16 -08:00
|
|
|
self.scrollView.scrollsToTop = NO;
|
|
|
|
|
2012-11-26 09:54:20 -08:00
|
|
|
if (self.isDraggingScrollview || self.scrollingToPage == currentPage.pageIndex) {
|
2013-01-07 16:34:59 -08:00
|
|
|
if (currentPage.pageIndex == -2) return;
|
2012-11-26 09:54:20 -08:00
|
|
|
self.scrollingToPage = -1;
|
|
|
|
int storyIndex = [appDelegate indexFromLocation:currentPage.pageIndex];
|
|
|
|
appDelegate.activeStory = [appDelegate.activeFeedStories objectAtIndex:storyIndex];
|
|
|
|
[self updatePageWithActiveStory:currentPage.pageIndex];
|
|
|
|
}
|
2012-11-08 17:39:32 -08:00
|
|
|
}
|
|
|
|
|
2012-12-13 16:41:52 -08:00
|
|
|
- (void)advanceToNextUnread {
|
|
|
|
if (!self.waitingForNextUnreadFromServer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.waitingForNextUnreadFromServer = NO;
|
|
|
|
[self doNextUnreadStory];
|
|
|
|
}
|
|
|
|
|
2012-11-08 17:39:32 -08:00
|
|
|
- (void)updatePageWithActiveStory:(int)location {
|
2012-11-05 17:16:10 -08:00
|
|
|
[self markStoryAsRead];
|
2012-11-05 18:23:45 -08:00
|
|
|
[appDelegate pushReadStory:[appDelegate.activeStory objectForKey:@"id"]];
|
2012-11-05 17:16:10 -08:00
|
|
|
|
|
|
|
self.bottomPlaceholderToolbar.hidden = YES;
|
|
|
|
self.progressViewContainer.hidden = NO;
|
|
|
|
|
2013-03-04 17:15:50 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2013-03-04 18:21:10 -08:00
|
|
|
[rightToolbar setItems: [NSArray arrayWithObjects:
|
|
|
|
spacerBarButton,
|
|
|
|
fontSettingsButton,
|
|
|
|
spacer2BarButton,
|
|
|
|
separatorBarButton,
|
|
|
|
spacer3BarButton,
|
|
|
|
originalStoryButton, nil]];
|
|
|
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightToolbar];
|
2013-03-04 17:15:50 -08:00
|
|
|
}
|
2012-11-05 17:16:10 -08:00
|
|
|
|
|
|
|
[self setNextPreviousButtons];
|
2012-11-07 17:54:16 -08:00
|
|
|
[appDelegate changeActiveFeedDetailRow];
|
2012-11-08 17:39:32 -08:00
|
|
|
|
|
|
|
if (self.currentPage.pageIndex != location) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Updating Current: from %d to %d", currentPage.pageIndex, location);
|
2012-11-08 17:39:32 -08:00
|
|
|
[self applyNewIndex:location pageController:self.currentPage];
|
|
|
|
}
|
|
|
|
if (self.nextPage.pageIndex != location+1) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Updating Next: from %d to %d", nextPage.pageIndex, location+1);
|
2012-11-08 17:39:32 -08:00
|
|
|
[self applyNewIndex:location+1 pageController:self.nextPage];
|
|
|
|
}
|
2012-11-14 17:31:52 -08:00
|
|
|
if (self.previousPage.pageIndex != location-1) {
|
2013-01-07 16:34:59 -08:00
|
|
|
// NSLog(@"Updating Previous: from %d to %d", previousPage.pageIndex, location-1);
|
2012-11-14 17:31:52 -08:00
|
|
|
[self applyNewIndex:location-1 pageController:self.previousPage];
|
|
|
|
}
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
|
|
|
|
2013-02-06 18:42:15 -08:00
|
|
|
- (void)requestFailed:(id)request {
|
2012-11-05 17:16:10 -08:00
|
|
|
NSString *error;
|
2013-02-06 18:42:15 -08:00
|
|
|
if ([request class] == [ASIHTTPRequest class]) {
|
|
|
|
NSLog(@"Error in story detail: %@", [request error]);
|
|
|
|
if ([request error]) {
|
|
|
|
error = [NSString stringWithFormat:@"%@", [request error]];
|
|
|
|
} else {
|
|
|
|
error = @"The server barfed!";
|
|
|
|
}
|
2012-11-05 17:16:10 -08:00
|
|
|
} else {
|
2013-02-06 18:42:15 -08:00
|
|
|
error = request;
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
[self informError:error];
|
|
|
|
}
|
|
|
|
|
2012-11-16 15:30:54 -08:00
|
|
|
- (void)requestFailedMarkStoryRead:(ASIHTTPRequest *)request {
|
|
|
|
[self informError:@"Failed to mark story as read"];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Actions
|
|
|
|
|
|
|
|
- (void)setNextPreviousButtons {
|
|
|
|
// setting up the PREV BUTTON
|
|
|
|
int readStoryCount = [appDelegate.readStories count];
|
|
|
|
if (readStoryCount == 0 ||
|
|
|
|
(readStoryCount == 1 &&
|
|
|
|
[appDelegate.readStories lastObject] == [appDelegate.activeStory objectForKey:@"id"])) {
|
|
|
|
[buttonPrevious setEnabled:NO];
|
2013-03-05 17:00:03 -08:00
|
|
|
[buttonPrevious setAlpha:.4];
|
2012-11-05 17:16:10 -08:00
|
|
|
} else {
|
|
|
|
[buttonPrevious setEnabled:YES];
|
2013-03-05 17:00:03 -08:00
|
|
|
[buttonPrevious setAlpha:1];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// setting up the NEXT UNREAD STORY BUTTON
|
2013-03-05 17:00:03 -08:00
|
|
|
buttonNext.enabled = YES;
|
2012-11-05 17:16:10 -08:00
|
|
|
int nextIndex = [appDelegate indexOfNextUnreadStory];
|
|
|
|
int unreadCount = [appDelegate unreadCount];
|
2013-03-05 17:00:03 -08:00
|
|
|
if ((nextIndex == -1 && unreadCount > 0) ||
|
|
|
|
nextIndex != -1) {
|
|
|
|
[buttonNext setTitle:@"NEXT" forState:UIControlStateNormal];
|
|
|
|
[buttonNext setBackgroundImage:[UIImage imageNamed:@"traverse_next.png"] forState:UIControlStateNormal];
|
2012-11-05 17:16:10 -08:00
|
|
|
} else {
|
2013-03-05 17:00:03 -08:00
|
|
|
[buttonNext setTitle:@"DONE" forState:UIControlStateNormal];
|
|
|
|
[buttonNext setBackgroundImage:[UIImage imageNamed:@"traverse_done.png"] forState:UIControlStateNormal];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
float unreads = (float)[appDelegate unreadCount];
|
|
|
|
float total = [appDelegate originalStoryCount];
|
|
|
|
float progress = (total - unreads) / total;
|
|
|
|
[progressView setProgress:progress];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markStoryAsRead {
|
|
|
|
// NSLog(@"[appDelegate.activeStory objectForKey:@read_status] intValue] %i", [[appDelegate.activeStory objectForKey:@"read_status"] intValue]);
|
|
|
|
if ([[appDelegate.activeStory objectForKey:@"read_status"] intValue] != 1) {
|
|
|
|
|
|
|
|
[appDelegate markActiveStoryRead];
|
|
|
|
|
|
|
|
NSString *urlString;
|
|
|
|
if (appDelegate.isSocialView || appDelegate.isSocialRiverView) {
|
|
|
|
urlString = [NSString stringWithFormat:@"http://%@/reader/mark_social_stories_as_read",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
} else {
|
|
|
|
urlString = [NSString stringWithFormat:@"http://%@/reader/mark_story_as_read",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
|
|
|
|
if (appDelegate.isSocialRiverView) {
|
|
|
|
// grab the user id from the shared_by_friends
|
|
|
|
NSArray *storyId = [NSArray arrayWithObject:[appDelegate.activeStory objectForKey:@"id"]];
|
|
|
|
NSString *friendUserId;
|
|
|
|
|
|
|
|
if ([[appDelegate.activeStory objectForKey:@"shared_by_friends"] count]) {
|
|
|
|
friendUserId = [NSString stringWithFormat:@"%@",
|
|
|
|
[[appDelegate.activeStory objectForKey:@"shared_by_friends"] objectAtIndex:0]];
|
2012-12-07 15:17:22 -08:00
|
|
|
} else if ([[appDelegate.activeStory objectForKey:@"commented_by_friends"] count]) {
|
2012-11-05 17:16:10 -08:00
|
|
|
friendUserId = [NSString stringWithFormat:@"%@",
|
|
|
|
[[appDelegate.activeStory objectForKey:@"commented_by_friends"] objectAtIndex:0]];
|
2012-12-07 15:17:22 -08:00
|
|
|
} else {
|
|
|
|
friendUserId = [NSString stringWithFormat:@"%@",
|
|
|
|
[[appDelegate.activeStory objectForKey:@"share_user_ids"] objectAtIndex:0]];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NSDictionary *feedStory = [NSDictionary dictionaryWithObject:storyId
|
|
|
|
forKey:[NSString stringWithFormat:@"%@",
|
|
|
|
[appDelegate.activeStory objectForKey:@"story_feed_id"]]];
|
|
|
|
|
|
|
|
NSDictionary *usersFeedsStories = [NSDictionary dictionaryWithObject:feedStory
|
|
|
|
forKey:friendUserId];
|
|
|
|
|
|
|
|
[request setPostValue:[usersFeedsStories JSONRepresentation] forKey:@"users_feeds_stories"];
|
|
|
|
} else if (appDelegate.isSocialView) {
|
|
|
|
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"]]];
|
|
|
|
|
|
|
|
[request setPostValue:[usersFeedsStories JSONRepresentation] forKey:@"users_feeds_stories"];
|
|
|
|
} 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:)];
|
2012-11-16 15:30:54 -08:00
|
|
|
[request setDidFailSelector:@selector(requestFailedMarkStoryRead:)];
|
2012-11-05 17:16:10 -08:00
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)finishMarkAsRead:(ASIHTTPRequest *)request {
|
2012-11-16 15:30:54 -08:00
|
|
|
if ([request responseStatusCode] != 200) {
|
|
|
|
return [self requestFailedMarkStoryRead:request];
|
|
|
|
}
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
// NSString *responseString = [request responseString];
|
|
|
|
// NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
// initWithDictionary:[responseString JSONValue]];
|
|
|
|
// NSLog(@"results in mark as read is %@", results);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)openSendToDialog {
|
|
|
|
NSURL *url = [NSURL URLWithString:[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_permalink"]];
|
|
|
|
SHKItem *item = [SHKItem URL:url title:[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_title"]];
|
|
|
|
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
|
|
|
|
[actionSheet showInView:self.view];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markStoryAsSaved {
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/mark_story_as_starred",
|
|
|
|
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(finishMarkAsSaved:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishMarkAsSaved:(ASIHTTPRequest *)request {
|
|
|
|
if ([request responseStatusCode] != 200) {
|
|
|
|
return [self requestFailed:request];
|
|
|
|
}
|
|
|
|
|
|
|
|
[appDelegate markActiveStorySaved:YES];
|
2012-12-18 17:29:23 -08:00
|
|
|
[self.currentPage flashCheckmarkHud:@"saved"];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markStoryAsUnsaved {
|
|
|
|
// [appDelegate markActiveStoryUnread];
|
|
|
|
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/mark_story_as_unstarred",
|
|
|
|
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(finishMarkAsUnsaved:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishMarkAsUnsaved:(ASIHTTPRequest *)request {
|
|
|
|
if ([request responseStatusCode] != 200) {
|
|
|
|
return [self requestFailed:request];
|
|
|
|
}
|
|
|
|
|
|
|
|
// [appDelegate markActiveStoryUnread];
|
|
|
|
// [appDelegate.feedDetailViewController redrawUnreadStory];
|
|
|
|
|
|
|
|
[appDelegate markActiveStorySaved:NO];
|
2012-12-18 17:29:23 -08:00
|
|
|
[self.currentPage flashCheckmarkHud:@"unsaved"];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markStoryAsUnread {
|
|
|
|
if ([[appDelegate.activeStory objectForKey:@"read_status"] intValue] == 1) {
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/mark_story_as_unread",
|
|
|
|
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(finishMarkAsUnread:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishMarkAsUnread:(ASIHTTPRequest *)request {
|
|
|
|
if ([request responseStatusCode] != 200) {
|
|
|
|
return [self requestFailed:request];
|
|
|
|
}
|
|
|
|
|
2013-02-06 18:42:15 -08:00
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
initWithDictionary:[responseString JSONValue]];
|
|
|
|
|
|
|
|
if ([[results objectForKey:@"code"] intValue] < 0) {
|
|
|
|
return [self requestFailed:[results objectForKey:@"message"]];
|
|
|
|
}
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
[appDelegate markActiveStoryUnread];
|
|
|
|
[appDelegate.feedDetailViewController redrawUnreadStory];
|
|
|
|
|
2012-12-19 15:37:36 -08:00
|
|
|
[self.currentPage flashCheckmarkHud:@"unread"];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)showOriginalSubview:(id)sender {
|
|
|
|
NSURL *url = [NSURL URLWithString:[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_permalink"]];
|
|
|
|
[appDelegate showOriginalStory:url];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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 story left";
|
|
|
|
} else {
|
|
|
|
hud.labelText = [NSString stringWithFormat:@"%i stories left", unreadCount];
|
|
|
|
}
|
|
|
|
[hud hide:YES afterDelay:0.8];
|
|
|
|
}
|
|
|
|
|
2012-11-28 16:24:15 -08:00
|
|
|
- (void)subscribeToBlurblog {
|
|
|
|
[self.currentPage subscribeToBlurblog];
|
|
|
|
}
|
2012-11-05 17:16:10 -08:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Styles
|
|
|
|
|
|
|
|
|
2012-12-18 17:29:23 -08:00
|
|
|
- (IBAction)toggleFontSize:(id)sender {
|
2012-11-05 17:16:10 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2013-03-04 15:09:09 -08:00
|
|
|
[appDelegate.masterContainerViewController showFontSettingsPopover:self.fontSettingsButton];
|
2012-11-05 17:16:10 -08:00
|
|
|
} else {
|
|
|
|
if (self.popoverController == nil) {
|
|
|
|
self.popoverController = [[WEPopoverController alloc]
|
|
|
|
initWithContentViewController:appDelegate.fontSettingsViewController];
|
|
|
|
|
|
|
|
self.popoverController.delegate = self;
|
|
|
|
} else {
|
|
|
|
[self.popoverController dismissPopoverAnimated:YES];
|
|
|
|
self.popoverController = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([self.popoverController respondsToSelector:@selector(setContainerViewProperties:)]) {
|
|
|
|
[self.popoverController setContainerViewProperties:[self improvedContainerViewProperties]];
|
|
|
|
}
|
2012-12-27 00:15:26 -08:00
|
|
|
[self.popoverController setPopoverContentSize:CGSizeMake(240, 38*7-2)];
|
2012-11-05 17:16:10 -08:00
|
|
|
[self.popoverController presentPopoverFromBarButtonItem:self.fontSettingsButton
|
|
|
|
permittedArrowDirections:UIPopoverArrowDirectionAny
|
|
|
|
animated:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-09 14:13:44 -08:00
|
|
|
- (void)setFontStyle:(NSString *)fontStyle {
|
|
|
|
[self.currentPage setFontStyle:fontStyle];
|
|
|
|
[self.nextPage setFontStyle:fontStyle];
|
2012-11-14 17:31:52 -08:00
|
|
|
[self.previousPage setFontStyle:fontStyle];
|
2012-11-09 14:13:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)changeFontSize:(NSString *)fontSize {
|
|
|
|
[self.currentPage changeFontSize:fontSize];
|
|
|
|
[self.nextPage changeFontSize:fontSize];
|
2012-11-14 17:31:52 -08:00
|
|
|
[self.previousPage changeFontSize:fontSize];
|
2012-11-09 14:13:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showShareHUD:(NSString *)msg {
|
|
|
|
// [MBProgressHUD hideHUDForView:self.view animated:NO];
|
|
|
|
self.storyHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
|
self.storyHUD.labelText = msg;
|
|
|
|
self.storyHUD.margin = 20.0f;
|
|
|
|
self.currentPage.noStorySelectedLabel.hidden = YES;
|
|
|
|
self.nextPage.noStorySelectedLabel.hidden = YES;
|
2012-11-14 17:31:52 -08:00
|
|
|
self.previousPage.noStorySelectedLabel.hidden = YES;
|
2012-11-09 14:13:44 -08:00
|
|
|
}
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Story Traversal
|
|
|
|
|
|
|
|
- (IBAction)doNextUnreadStory {
|
2012-11-06 17:26:08 -08:00
|
|
|
FeedDetailViewController *fdvc = self.appDelegate.feedDetailViewController;
|
2012-11-06 13:45:15 -08:00
|
|
|
int nextLocation = [appDelegate locationOfNextUnreadStory];
|
2012-11-05 17:16:10 -08:00
|
|
|
int unreadCount = [appDelegate unreadCount];
|
|
|
|
[self.loadingIndicator stopAnimating];
|
|
|
|
|
2012-12-13 17:25:52 -08:00
|
|
|
// NSLog(@"doNextUnreadStory: %d (out of %d)", nextLocation, unreadCount);
|
2012-12-13 16:41:52 -08:00
|
|
|
|
2012-11-06 13:45:15 -08:00
|
|
|
if (nextLocation == -1 && unreadCount > 0 &&
|
2012-12-13 16:41:52 -08:00
|
|
|
fdvc.feedPage < 100) {
|
2012-11-05 17:16:10 -08:00
|
|
|
[self.loadingIndicator startAnimating];
|
2012-11-06 17:26:08 -08:00
|
|
|
self.buttonNext.enabled = NO;
|
|
|
|
// Fetch next page and see if it has the unreads.
|
2012-12-13 16:41:52 -08:00
|
|
|
self.waitingForNextUnreadFromServer = YES;
|
|
|
|
[fdvc fetchNextPage:nil];
|
2012-11-06 13:45:15 -08:00
|
|
|
} else if (nextLocation == -1) {
|
2012-11-05 17:16:10 -08:00
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
|
|
|
[appDelegate hideStoryDetailView];
|
|
|
|
} else {
|
2012-11-06 13:45:15 -08:00
|
|
|
[self changePage:nextLocation];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)doPreviousStory {
|
|
|
|
[self.loadingIndicator stopAnimating];
|
|
|
|
id previousStoryId = [appDelegate popReadStory];
|
|
|
|
if (!previousStoryId || previousStoryId == [appDelegate.activeStory objectForKey:@"id"]) {
|
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
|
|
|
[appDelegate hideStoryDetailView];
|
|
|
|
} else {
|
2012-11-06 13:45:15 -08:00
|
|
|
int previousLocation = [appDelegate locationOfStoryId:previousStoryId];
|
|
|
|
if (previousLocation == -1) {
|
2012-11-05 17:16:10 -08:00
|
|
|
return [self doPreviousStory];
|
|
|
|
}
|
2012-11-05 18:23:45 -08:00
|
|
|
// [appDelegate setActiveStory:[[appDelegate activeFeedStories]
|
|
|
|
// objectAtIndex:previousIndex]];
|
|
|
|
// [appDelegate changeActiveFeedDetailRow];
|
|
|
|
//
|
2012-11-06 13:45:15 -08:00
|
|
|
[self changePage:previousLocation];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark WEPopoverControllerDelegate implementation
|
|
|
|
|
|
|
|
- (void)popoverControllerDidDismissPopover:(WEPopoverController *)thePopoverController {
|
|
|
|
//Safe to release the popover here
|
|
|
|
self.popoverController = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)popoverControllerShouldDismissPopover:(WEPopoverController *)thePopoverController {
|
|
|
|
//The popover is automatically dismissed if you click outside it, unless you return NO here
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Thanks to Paul Solt for supplying these background images and container view properties
|
|
|
|
*/
|
|
|
|
- (WEPopoverContainerViewProperties *)improvedContainerViewProperties {
|
|
|
|
|
|
|
|
WEPopoverContainerViewProperties *props = [WEPopoverContainerViewProperties alloc];
|
|
|
|
NSString *bgImageName = nil;
|
|
|
|
CGFloat bgMargin = 0.0;
|
|
|
|
CGFloat bgCapSize = 0.0;
|
|
|
|
CGFloat contentMargin = 5.0;
|
|
|
|
|
|
|
|
bgImageName = @"popoverBg.png";
|
|
|
|
|
|
|
|
// These constants are determined by the popoverBg.png image file and are image dependent
|
|
|
|
bgMargin = 13; // margin width of 13 pixels on all sides popoverBg.png (62 pixels wide - 36 pixel background) / 2 == 26 / 2 == 13
|
|
|
|
bgCapSize = 31; // ImageSize/2 == 62 / 2 == 31 pixels
|
|
|
|
|
|
|
|
props.leftBgMargin = bgMargin;
|
|
|
|
props.rightBgMargin = bgMargin;
|
|
|
|
props.topBgMargin = bgMargin;
|
|
|
|
props.bottomBgMargin = bgMargin;
|
|
|
|
props.leftBgCapSize = bgCapSize;
|
|
|
|
props.topBgCapSize = bgCapSize;
|
|
|
|
props.bgImageName = bgImageName;
|
|
|
|
props.leftContentMargin = contentMargin;
|
|
|
|
props.rightContentMargin = contentMargin - 1; // Need to shift one pixel for border to look correct
|
|
|
|
props.topContentMargin = contentMargin;
|
|
|
|
props.bottomContentMargin = contentMargin;
|
|
|
|
|
|
|
|
props.arrowMargin = 4.0;
|
|
|
|
|
|
|
|
props.upArrowImageName = @"popoverArrowUp.png";
|
|
|
|
props.downArrowImageName = @"popoverArrowDown.png";
|
|
|
|
props.leftArrowImageName = @"popoverArrowLeft.png";
|
|
|
|
props.rightArrowImageName = @"popoverArrowRight.png";
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
2012-11-05 15:12:42 -08:00
|
|
|
@end
|