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"
|
2013-02-27 18:04:03 -08:00
|
|
|
#import "UIBarButtonItem+Image.h"
|
2013-04-10 21:06:17 -07:00
|
|
|
#import "THCircularProgressView.h"
|
2013-06-16 08:15:40 -07:00
|
|
|
#import "FMDatabase.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;
|
2013-04-10 21:06:17 -07:00
|
|
|
@synthesize circularProgressView;
|
2013-02-27 18:04:03 -08:00
|
|
|
@synthesize separatorBarButton;
|
|
|
|
@synthesize spacerBarButton, spacer2BarButton, spacer3BarButton;
|
2012-11-05 17:16:10 -08:00
|
|
|
@synthesize buttonPrevious;
|
|
|
|
@synthesize buttonNext;
|
|
|
|
@synthesize buttonAction;
|
2013-05-29 13:36:39 -07:00
|
|
|
@synthesize buttonText;
|
2013-07-19 18:19:30 -07:00
|
|
|
@synthesize buttonSend;
|
2012-11-05 17:16:10 -08:00
|
|
|
@synthesize fontSettingsButton;
|
|
|
|
@synthesize originalStoryButton;
|
|
|
|
@synthesize subscribeButton;
|
|
|
|
@synthesize buttonBack;
|
2013-09-26 19:26:10 -07:00
|
|
|
@synthesize bottomSize;
|
2012-11-05 17:16:10 -08:00
|
|
|
@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;
|
2013-03-06 14:29:40 -08:00
|
|
|
@synthesize traverseView;
|
2014-01-30 20:28:08 -08:00
|
|
|
@synthesize isAnimatedIntoPlace;
|
2013-04-26 13:51:03 -07:00
|
|
|
@synthesize progressView, progressViewContainer;
|
2013-03-07 10:55:23 -05:00
|
|
|
@synthesize traversePinned, traverseFloating;
|
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 {
|
2013-10-03 13:54:15 -07:00
|
|
|
currentPage = [[StoryDetailViewController alloc]
|
|
|
|
initWithNibName:@"StoryDetailViewController"
|
|
|
|
bundle:nil];
|
|
|
|
nextPage = [[StoryDetailViewController alloc]
|
|
|
|
initWithNibName:@"StoryDetailViewController"
|
|
|
|
bundle:nil];
|
|
|
|
previousPage = [[StoryDetailViewController alloc]
|
|
|
|
initWithNibName:@"StoryDetailViewController"
|
|
|
|
bundle:nil];
|
2012-11-14 17:31:52 -08:00
|
|
|
|
2013-06-10 00:29:03 -07:00
|
|
|
currentPage.appDelegate = appDelegate;
|
|
|
|
nextPage.appDelegate = appDelegate;
|
|
|
|
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];
|
|
|
|
|
2013-05-30 16:31:57 -07:00
|
|
|
// adding HUD for progress bar
|
2013-04-12 13:06:47 -07:00
|
|
|
CGFloat radius = 8;
|
2013-04-10 21:06:17 -07:00
|
|
|
circularProgressView = [[THCircularProgressView alloc]
|
2013-05-30 16:31:57 -07:00
|
|
|
initWithCenter:CGPointMake(self.buttonNext.frame.origin.x + 2*radius,
|
2013-04-10 21:06:17 -07:00
|
|
|
self.traverseView.frame.size.height / 2)
|
|
|
|
radius:radius
|
|
|
|
lineWidth:radius / 4.0f
|
|
|
|
progressMode:THProgressModeFill
|
2013-04-12 13:06:47 -07:00
|
|
|
progressColor:[UIColor colorWithRed:0.612f green:0.62f blue:0.596f alpha:0.4f]
|
2013-04-10 21:06:17 -07:00
|
|
|
progressBackgroundMode:THProgressBackgroundModeCircumference
|
2013-07-19 17:53:52 -07:00
|
|
|
progressBackgroundColor:[UIColor colorWithRed:0.312f green:0.32f blue:0.296f alpha:.04f]
|
2013-04-10 21:06:17 -07:00
|
|
|
percentage:20];
|
2013-05-30 16:31:57 -07:00
|
|
|
circularProgressView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
|
2013-04-10 21:06:17 -07:00
|
|
|
[self.traverseView addSubview:circularProgressView];
|
2013-10-03 13:54:15 -07:00
|
|
|
UIView *tapIndicator = [[UIView alloc]
|
|
|
|
initWithFrame:CGRectMake(circularProgressView.frame.origin.x -
|
|
|
|
circularProgressView.frame.size.width / 2,
|
|
|
|
circularProgressView.frame.origin.y -
|
|
|
|
circularProgressView.frame.size.height / 2,
|
|
|
|
circularProgressView.frame.size.width*2,
|
|
|
|
circularProgressView.frame.size.height*2)];
|
|
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
|
|
|
|
initWithTarget:self
|
|
|
|
action:@selector(tapProgressBar:)];
|
2013-05-28 18:07:19 -07:00
|
|
|
[tapIndicator addGestureRecognizer:tap];
|
2013-05-30 16:31:57 -07:00
|
|
|
tapIndicator.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
|
2013-05-28 18:07:19 -07:00
|
|
|
[self.traverseView insertSubview:tapIndicator aboveSubview:circularProgressView];
|
2013-04-23 11:52:34 -07:00
|
|
|
self.loadingIndicator.frame = self.circularProgressView.frame;
|
2013-04-10 21:06:17 -07:00
|
|
|
|
2013-02-27 18:04:03 -08:00
|
|
|
spacerBarButton = [[UIBarButtonItem alloc]
|
2013-10-03 13:54:15 -07:00
|
|
|
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
|
|
|
|
target:nil action:nil];
|
2013-02-27 18:04:03 -08:00
|
|
|
spacerBarButton.width = -12;
|
|
|
|
spacer2BarButton = [[UIBarButtonItem alloc]
|
2013-10-03 13:54:15 -07:00
|
|
|
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
|
|
|
|
target:nil action:nil];
|
|
|
|
spacer2BarButton.width = -6;
|
2013-02-27 18:04:03 -08:00
|
|
|
spacer3BarButton = [[UIBarButtonItem alloc]
|
2013-10-03 13:54:15 -07:00
|
|
|
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
|
|
|
|
target:nil action:nil];
|
|
|
|
spacer3BarButton.width = -6;
|
2012-11-05 17:16:10 -08:00
|
|
|
|
2013-02-27 18:04:03 -08:00
|
|
|
UIImage *separatorImage = [UIImage imageNamed:@"bar-separator.png"];
|
2013-10-03 13:54:15 -07:00
|
|
|
separatorBarButton = [UIBarButtonItem barItemWithImage:separatorImage
|
|
|
|
target:nil
|
|
|
|
action:nil];
|
2013-02-27 18:04:03 -08:00
|
|
|
[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"];
|
2013-10-03 13:54:15 -07:00
|
|
|
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"];
|
2013-10-03 13:54:15 -07:00
|
|
|
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]
|
2013-10-03 13:54:15 -07:00
|
|
|
initWithTitle:@"All Sites"
|
|
|
|
style:UIBarButtonItemStyleBordered
|
|
|
|
target:self
|
|
|
|
action:@selector(transitionFromFeedDetail)];
|
2012-11-05 17:16:10 -08:00
|
|
|
self.buttonBack = backButton;
|
|
|
|
|
|
|
|
|
2013-03-04 18:21:10 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
2013-10-11 17:46:09 -07:00
|
|
|
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:
|
|
|
|
originalStoryButton,
|
|
|
|
separatorBarButton,
|
|
|
|
fontSettingsButton, nil];
|
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];
|
2013-12-11 18:06:22 -08:00
|
|
|
[self setTextButton];
|
2013-12-06 16:19:27 -08:00
|
|
|
|
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
|
|
|
BOOL swipeEnabled = [[userPreferences stringForKey:@"story_detail_swipe_left_edge"]
|
|
|
|
isEqualToString:@"pop_to_story_list"];;
|
|
|
|
self.navigationController.interactivePopGestureRecognizer.enabled = swipeEnabled;
|
2013-09-26 19:26:10 -07:00
|
|
|
|
2012-11-13 13:07:36 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
|
|
if (!appDelegate.isSocialView) {
|
|
|
|
UIImage *titleImage;
|
2013-10-03 13:54:15 -07:00
|
|
|
if (appDelegate.isSocialRiverView && [appDelegate.activeFolder
|
|
|
|
isEqualToString:@"river_global"]) {
|
2013-02-21 12:19:15 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"ak-icon-global.png"];
|
2013-10-03 13:54:15 -07:00
|
|
|
} else if (appDelegate.isSocialRiverView && [appDelegate.activeFolder
|
|
|
|
isEqualToString:@"river_blurblogs"]) {
|
2013-02-21 12:19:15 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"ak-icon-blurblogs.png"];
|
2013-10-03 13:54:15 -07:00
|
|
|
} else if (appDelegate.isRiverView && [appDelegate.activeFolder
|
|
|
|
isEqualToString:@"everything"]) {
|
2013-02-21 12:19:15 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"ak-icon-allstories.png"];
|
2013-10-03 13:54:15 -07:00
|
|
|
} else if (appDelegate.isRiverView && [appDelegate.activeFolder
|
|
|
|
isEqualToString:@"saved_stories"]) {
|
2013-03-07 10:55:23 -05:00
|
|
|
titleImage = [UIImage imageNamed:@"clock.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;
|
2014-01-07 18:26:17 -08:00
|
|
|
if (!self.navigationItem.titleView) {
|
|
|
|
self.navigationItem.titleView = titleImageView;
|
|
|
|
}
|
2012-11-13 13:07:36 -08:00
|
|
|
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-09-05 16:34:39 -07:00
|
|
|
self.traverseView.alpha = 1;
|
2014-01-30 20:28:08 -08:00
|
|
|
self.isAnimatedIntoPlace = NO;
|
2013-03-04 17:15:50 -08:00
|
|
|
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
|
|
|
[self layoutForInterfaceOrientation:orientation];
|
2013-09-26 19:26:10 -07:00
|
|
|
[self adjustDragBar:orientation];
|
2014-01-08 13:38:18 -08:00
|
|
|
|
|
|
|
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@" "
|
|
|
|
style:UIBarButtonItemStylePlain
|
|
|
|
target:nil action:nil];
|
|
|
|
|
2012-11-05 15:12:42 -08:00
|
|
|
}
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
|
|
// set the subscribeButton flag
|
2013-09-25 12:05:17 -07:00
|
|
|
if (appDelegate.isTryFeedView && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2013-10-03 13:54:15 -07:00
|
|
|
self.subscribeButton.title = [NSString stringWithFormat:@"Follow %@",
|
|
|
|
[appDelegate.activeFeed objectForKey:@"username"]];
|
2012-11-05 17:16:10 -08:00
|
|
|
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];
|
2013-09-25 10:47:35 -07:00
|
|
|
previousPage.view.hidden = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
|
|
previousPage.view.hidden = YES;
|
2013-10-11 17:46:09 -07:00
|
|
|
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
|
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-12-11 18:49:21 -08:00
|
|
|
// [self changePage:currentPage.pageIndex animated:YES];
|
2013-03-04 17:15:50 -08:00
|
|
|
}
|
|
|
|
|
2013-10-03 13:54:15 -07:00
|
|
|
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
|
|
|
|
duration:(NSTimeInterval)duration {
|
2013-03-04 17:15:50 -08:00
|
|
|
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
|
2013-05-30 16:31:57 -07:00
|
|
|
NSLog(@"Rotate: %f,%f",self.view.frame.size.width,self.view.frame.size.height);
|
2013-03-04 17:15:50 -08:00
|
|
|
|
|
|
|
} else if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){
|
2013-05-30 16:31:57 -07:00
|
|
|
NSLog(@"Rotate: %f,%f",self.view.frame.size.width,self.view.frame.size.height);
|
2013-03-04 17:15:50 -08:00
|
|
|
}
|
2013-05-30 16:31:57 -07:00
|
|
|
|
2013-03-04 17:15:50 -08:00
|
|
|
[self layoutForInterfaceOrientation:toInterfaceOrientation];
|
2013-09-26 19:26:10 -07:00
|
|
|
[self adjustDragBar:toInterfaceOrientation];
|
2013-03-04 17:15:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
|
|
if (interfaceOrientation != _orientation) {
|
|
|
|
_orientation = interfaceOrientation;
|
|
|
|
[self refreshPages];
|
2013-09-12 21:26:38 -07:00
|
|
|
if (currentPage.pageIndex == 0) {
|
|
|
|
previousPage.view.hidden = YES;
|
|
|
|
}
|
2013-03-04 17:15:50 -08:00
|
|
|
}
|
2012-11-07 17:54:16 -08:00
|
|
|
}
|
|
|
|
|
2013-09-26 19:26:10 -07:00
|
|
|
- (void)adjustDragBar:(UIInterfaceOrientation)orientation {
|
|
|
|
CGRect scrollViewFrame = self.scrollView.frame;
|
|
|
|
CGRect traverseViewFrame = self.traverseView.frame;
|
|
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad ||
|
|
|
|
UIInterfaceOrientationIsLandscape(orientation)) {
|
|
|
|
scrollViewFrame.size.height = self.view.frame.size.height;
|
|
|
|
self.bottomSize.hidden = YES;
|
|
|
|
} else {
|
|
|
|
scrollViewFrame.size.height = self.view.frame.size.height - 12;
|
|
|
|
self.bottomSize.hidden = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.scrollView.frame = scrollViewFrame;
|
|
|
|
traverseViewFrame.origin.y = scrollViewFrame.size.height - traverseViewFrame.size.height;
|
|
|
|
self.traverseView.frame = traverseViewFrame;
|
|
|
|
}
|
|
|
|
|
2013-10-08 13:57:15 -07:00
|
|
|
- (void)highlightButton:(UIButton *)b {
|
2013-10-10 13:00:35 -07:00
|
|
|
if (![b isKindOfClass:[UIButton class]]) return;
|
2013-10-08 13:57:15 -07:00
|
|
|
[b setHighlighted:YES];
|
|
|
|
}
|
|
|
|
- (void)unhighlightButton:(UIButton *)b {
|
2013-10-10 13:00:35 -07:00
|
|
|
if (![b isKindOfClass:[UIButton class]]) return;
|
2013-10-08 13:57:15 -07:00
|
|
|
[b setHighlighted:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)beginTouchDown:(UIButton *)sender {
|
|
|
|
[self performSelector:@selector(highlightButton:) withObject:sender afterDelay:0.0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)endTouchDown:(UIButton *)sender {
|
|
|
|
if (!sender) return;
|
|
|
|
|
|
|
|
[self performSelector:@selector(unhighlightButton:) withObject:sender afterDelay:0.2];
|
|
|
|
}
|
|
|
|
|
2012-11-08 18:30:45 -08:00
|
|
|
- (void)resetPages {
|
2014-01-07 18:26:17 -08:00
|
|
|
self.navigationItem.titleView = nil;
|
|
|
|
|
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
|
|
|
|
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;
|
2013-10-11 17:46:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)hidePages {
|
|
|
|
[currentPage hideStory];
|
|
|
|
[nextPage hideStory];
|
|
|
|
[previousPage hideStory];
|
2012-11-07 17:54:16 -08:00
|
|
|
}
|
|
|
|
|
2012-11-13 12:28:16 -08:00
|
|
|
- (void)refreshPages {
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger 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 {
|
2013-10-01 14:19:12 -07:00
|
|
|
[currentPage setActiveStoryAtIndex:[appDelegate indexOfStoryId:currentPage.activeStoryId]];
|
|
|
|
[nextPage setActiveStoryAtIndex:[appDelegate indexOfStoryId:nextPage.activeStoryId]];
|
|
|
|
[previousPage setActiveStoryAtIndex:[appDelegate indexOfStoryId:previousPage.activeStoryId]];
|
|
|
|
|
2012-12-07 17:18:31 -08:00
|
|
|
[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;
|
|
|
|
|
2013-10-03 13:54:15 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
|
|
|
|
UIInterfaceOrientationIsPortrait(orientation)) {
|
2012-11-07 17:54:16 -08:00
|
|
|
UITouch *theTouch = [touches anyObject];
|
2013-12-12 18:41:39 -08:00
|
|
|
CGPoint tappedPt = [theTouch locationInView:self.view];
|
|
|
|
NSInteger fudge = appDelegate.masterContainerViewController.storyTitlesOnLeft ? -30 : -20;
|
|
|
|
BOOL inside = CGRectContainsPoint(CGRectInset(self.bottomSize.frame, 0, fudge), tappedPt);
|
|
|
|
BOOL attached = self.inTouchMove;
|
|
|
|
|
|
|
|
if (theTouch.view == self.bottomSize || inside || attached) {
|
2012-11-07 17:54:16 -08:00
|
|
|
self.inTouchMove = YES;
|
2013-09-26 19:26:10 -07:00
|
|
|
CGPoint touchLocation = [theTouch locationInView:self.view];
|
|
|
|
CGFloat y = touchLocation.y;
|
|
|
|
[appDelegate.masterContainerViewController dragStoryToolbar:y];
|
2012-11-07 17:54:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
|
|
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
|
|
|
|
2013-10-03 13:54:15 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
|
|
|
|
UIInterfaceOrientationIsPortrait(orientation)) {
|
2013-12-12 18:41:39 -08:00
|
|
|
if (self.inTouchMove) {
|
2012-11-07 17:54:16 -08:00
|
|
|
self.inTouchMove = NO;
|
|
|
|
[appDelegate.masterContainerViewController adjustFeedDetailScreenForStoryTitles];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Side scroll view
|
|
|
|
|
2013-10-03 13:54:15 -07: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) {
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger location = [appDelegate indexFromLocation:pageController.pageIndex];
|
2012-11-06 13:45:15 -08:00
|
|
|
[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 ||
|
2013-09-25 17:43:00 -07: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];
|
2013-05-29 13:36:39 -07:00
|
|
|
[self setTextButton];
|
2012-11-05 17:16:10 -08:00
|
|
|
[self.loadingIndicator stopAnimating];
|
2013-04-23 11:52:34 -07:00
|
|
|
self.circularProgressView.hidden = NO;
|
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
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger storyCount = [appDelegate.activeFeedStoryLocations count];
|
2012-11-26 09:54:20 -08:00
|
|
|
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];
|
|
|
|
// }
|
2013-03-07 10:55:23 -05:00
|
|
|
|
|
|
|
// Stick to bottom
|
|
|
|
CGRect tvf = self.traverseView.frame;
|
|
|
|
traversePinned = YES;
|
|
|
|
[UIView animateWithDuration:.3 delay:0
|
|
|
|
options:UIViewAnimationOptionCurveEaseInOut
|
|
|
|
animations:^{
|
|
|
|
self.traverseView.frame = CGRectMake(tvf.origin.x,
|
|
|
|
self.scrollView.frame.size.height - tvf.size.height,
|
|
|
|
tvf.size.width, tvf.size.height);
|
2013-03-13 14:05:58 -07:00
|
|
|
self.traverseView.alpha = 1;
|
|
|
|
self.traversePinned = YES;
|
2013-03-07 10:55:23 -05:00
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
|
|
|
|
}];
|
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
|
|
|
}
|
|
|
|
|
2013-10-03 13:54:15 -07: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;
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 20:28:08 -08:00
|
|
|
- (void)animateIntoPlace {
|
|
|
|
// Move view into position if no story is selected yet
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
|
|
|
|
!self.isAnimatedIntoPlace) {
|
|
|
|
CGRect frame = self.scrollView.frame;
|
|
|
|
frame.origin.x = frame.size.width;
|
|
|
|
self.scrollView.frame = frame;
|
2014-01-30 20:42:55 -08:00
|
|
|
[UIView animateWithDuration:.22 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
2014-01-30 20:28:08 -08:00
|
|
|
CGRect frame = self.scrollView.frame;
|
|
|
|
frame.origin.x = 0;
|
|
|
|
self.scrollView.frame = frame;
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
self.isAnimatedIntoPlace = YES;
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2013-09-12 21:26:38 -07:00
|
|
|
[self.currentPage hideNoStoryMessage];
|
|
|
|
[self.nextPage hideNoStoryMessage];
|
|
|
|
[self.previousPage hideNoStoryMessage];
|
|
|
|
|
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
|
|
|
|
2013-09-23 18:09:05 -07:00
|
|
|
if (!force && currentPage.pageIndex >= 0 &&
|
2012-11-26 09:54:20 -08:00
|
|
|
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;
|
2013-10-07 10:02:44 -07:00
|
|
|
currentPage.isRecentlyUnread = NO;
|
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;
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger storyIndex = [appDelegate indexFromLocation:currentPage.pageIndex];
|
2012-11-26 09:54:20 -08:00
|
|
|
appDelegate.activeStory = [appDelegate.activeFeedStories objectAtIndex:storyIndex];
|
|
|
|
[self updatePageWithActiveStory:currentPage.pageIndex];
|
2013-09-23 18:09:05 -07:00
|
|
|
[self markStoryAsRead];
|
2012-11-26 09:54:20 -08:00
|
|
|
}
|
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;
|
2013-10-08 13:57:15 -07:00
|
|
|
[self doNextUnreadStory:nil];
|
2012-12-13 16:41:52 -08:00
|
|
|
}
|
|
|
|
|
2013-09-25 10:47:35 -07:00
|
|
|
- (void)updatePageWithActiveStory:(NSInteger)location {
|
2012-11-05 18:23:45 -08:00
|
|
|
[appDelegate pushReadStory:[appDelegate.activeStory objectForKey:@"id"]];
|
2012-11-05 17:16:10 -08:00
|
|
|
|
2013-09-26 19:26:10 -07:00
|
|
|
[self.view setNeedsLayout];
|
2012-11-05 17:16:10 -08:00
|
|
|
|
2013-03-04 17:15:50 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2013-10-11 17:46:09 -07:00
|
|
|
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:
|
|
|
|
originalStoryButton,
|
|
|
|
separatorBarButton,
|
|
|
|
fontSettingsButton, nil];
|
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 {
|
2013-09-06 14:31:12 -07:00
|
|
|
[self informError:@"The server barfed!"];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Actions
|
|
|
|
|
|
|
|
- (void)setNextPreviousButtons {
|
|
|
|
// setting up the PREV BUTTON
|
2013-09-25 10:47:35 -07:00
|
|
|
NSInteger readStoryCount = [appDelegate.readStories count];
|
2012-11-05 17:16:10 -08:00
|
|
|
if (readStoryCount == 0 ||
|
|
|
|
(readStoryCount == 1 &&
|
|
|
|
[appDelegate.readStories lastObject] == [appDelegate.activeStory objectForKey:@"id"])) {
|
2013-07-19 16:49:48 -07:00
|
|
|
[buttonPrevious setEnabled:NO];
|
|
|
|
} else {
|
|
|
|
[buttonPrevious setEnabled:YES];
|
|
|
|
}
|
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;
|
2013-09-25 10:47:35 -07:00
|
|
|
NSInteger nextIndex = [appDelegate indexOfNextUnreadStory];
|
|
|
|
NSInteger unreadCount = [appDelegate unreadCount];
|
2013-03-05 17:00:03 -08:00
|
|
|
if ((nextIndex == -1 && unreadCount > 0) ||
|
|
|
|
nextIndex != -1) {
|
2013-10-02 16:05:22 -07:00
|
|
|
[buttonNext setTitle:[@"Next" uppercaseString] forState:UIControlStateNormal];
|
2013-10-03 13:54:15 -07:00
|
|
|
[buttonNext setBackgroundImage:[UIImage imageNamed:@"traverse_next.png"]
|
|
|
|
forState:UIControlStateNormal];
|
2012-11-05 17:16:10 -08:00
|
|
|
} else {
|
2013-10-02 16:05:22 -07:00
|
|
|
[buttonNext setTitle:[@"Done" uppercaseString] forState:UIControlStateNormal];
|
2013-10-03 13:54:15 -07:00
|
|
|
[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;
|
2013-04-10 21:06:17 -07:00
|
|
|
circularProgressView.percentage = progress;
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
2013-05-29 13:36:39 -07:00
|
|
|
- (void)setTextButton {
|
2013-05-30 16:31:57 -07:00
|
|
|
if (currentPage.pageIndex >= 0) {
|
|
|
|
[buttonText setEnabled:YES];
|
|
|
|
[buttonText setAlpha:1];
|
2013-07-19 18:19:30 -07:00
|
|
|
[buttonSend setEnabled:YES];
|
|
|
|
[buttonSend setAlpha:1];
|
2013-05-30 16:31:57 -07:00
|
|
|
} else {
|
|
|
|
[buttonText setEnabled:NO];
|
|
|
|
[buttonText setAlpha:.4];
|
2013-07-19 18:19:30 -07:00
|
|
|
[buttonSend setEnabled:NO];
|
|
|
|
[buttonSend setAlpha:.4];
|
2013-05-30 16:31:57 -07:00
|
|
|
}
|
|
|
|
|
2013-05-29 13:36:39 -07:00
|
|
|
if (currentPage.inTextView) {
|
|
|
|
[buttonText setTitle:[@"Story" uppercaseString] forState:UIControlStateNormal];
|
|
|
|
[buttonText setBackgroundImage:[UIImage imageNamed:@"traverse_text_on.png"]
|
|
|
|
forState:nil];
|
2013-10-02 17:31:51 -07:00
|
|
|
self.buttonText.titleEdgeInsets = UIEdgeInsetsMake(0, 26, 0, 0);
|
2013-05-29 13:36:39 -07:00
|
|
|
} else {
|
|
|
|
[buttonText setTitle:[@"Text" uppercaseString] forState:UIControlStateNormal];
|
|
|
|
[buttonText setBackgroundImage:[UIImage imageNamed:@"traverse_text.png"]
|
|
|
|
forState:nil];
|
2013-10-02 17:31:51 -07:00
|
|
|
self.buttonText.titleEdgeInsets = UIEdgeInsetsMake(0, 22, 0, 0);
|
2013-05-29 13:36:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
- (void)markStoryAsRead {
|
2013-09-25 10:47:35 -07:00
|
|
|
if (!appDelegate.activeStory) return;
|
|
|
|
|
2013-10-03 18:07:39 -07:00
|
|
|
if ([appDelegate isStoryUnread:appDelegate.activeStory]) {
|
2012-11-05 17:16:10 -08:00
|
|
|
|
|
|
|
[appDelegate markActiveStoryRead];
|
2013-10-04 12:37:51 -07:00
|
|
|
[self.currentPage refreshHeader];
|
|
|
|
[appDelegate.feedDetailViewController redrawUnreadStory];
|
2012-11-05 17:16:10 -08:00
|
|
|
|
2013-10-01 16:21:23 -07:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_story_hashes_as_read",
|
|
|
|
NEWSBLUR_URL];
|
2012-11-05 17:16:10 -08:00
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2013-10-01 16:21:23 -07:00
|
|
|
[request setPostValue:[appDelegate.activeStory objectForKey:@"story_hash"]
|
|
|
|
forKey:@"story_hash"];
|
|
|
|
[request setUserInfo:@{@"story_feed_id":[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_feed_id"],
|
|
|
|
@"story_hash":[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_hash"]}];
|
2012-11-05 17:16:10 -08:00
|
|
|
[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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-16 08:15:40 -07:00
|
|
|
- (void)finishMarkAsRead:(ASIFormDataRequest *)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);
|
|
|
|
}
|
|
|
|
|
2013-10-01 16:21:23 -07:00
|
|
|
- (void)requestFailedMarkStoryRead:(ASIFormDataRequest *)request {
|
|
|
|
// [self informError:@"Failed to mark story as read"];
|
|
|
|
NSString *storyFeedId = [request.userInfo objectForKey:@"story_feed_id"];
|
|
|
|
NSString *storyHash = [request.userInfo objectForKey:@"story_hash"];
|
|
|
|
|
|
|
|
[appDelegate queueReadStories:@{storyFeedId: @[storyHash]}];
|
|
|
|
}
|
|
|
|
|
2013-07-19 16:49:48 -07:00
|
|
|
- (IBAction)openSendToDialog:(id)sender {
|
2013-10-08 13:57:15 -07:00
|
|
|
[self endTouchDown:sender];
|
|
|
|
|
2014-01-06 18:37:57 -08:00
|
|
|
[appDelegate showSendTo:self sender:sender];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markStoryAsSaved {
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_story_as_starred",
|
2012-11-05 17:16:10 -08:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
|
|
|
|
[request setPostValue:[appDelegate.activeStory
|
2013-06-16 08:15:40 -07:00
|
|
|
objectForKey:@"story_hash"]
|
2012-11-05 17:16:10 -08:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2013-06-16 08:15:40 -07:00
|
|
|
- (void)finishMarkAsSaved:(ASIFormDataRequest *)request {
|
2012-11-05 17:16:10 -08:00
|
|
|
if ([request responseStatusCode] != 200) {
|
|
|
|
return [self requestFailed:request];
|
|
|
|
}
|
|
|
|
|
2013-10-01 14:19:12 -07:00
|
|
|
[appDelegate markStory:appDelegate.activeStory asSaved:YES];
|
2013-08-05 17:29:42 -07:00
|
|
|
[appDelegate.feedDetailViewController redrawUnreadStory];
|
|
|
|
[self refreshHeaders];
|
2012-12-18 17:29:23 -08:00
|
|
|
[self.currentPage flashCheckmarkHud:@"saved"];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markStoryAsUnsaved {
|
|
|
|
// [appDelegate markActiveStoryUnread];
|
|
|
|
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_story_as_unstarred",
|
2012-11-05 17:16:10 -08:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
|
|
|
|
[request setPostValue:[appDelegate.activeStory
|
2013-06-16 08:15:40 -07:00
|
|
|
objectForKey:@"story_hash"]
|
2012-11-05 17:16:10 -08:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2013-06-16 08:15:40 -07:00
|
|
|
- (void)finishMarkAsUnsaved:(ASIFormDataRequest *)request {
|
2012-11-05 17:16:10 -08:00
|
|
|
if ([request responseStatusCode] != 200) {
|
|
|
|
return [self requestFailed:request];
|
|
|
|
}
|
|
|
|
|
2013-10-01 14:19:12 -07:00
|
|
|
[appDelegate markStory:appDelegate.activeStory asSaved:NO];
|
2013-08-05 17:29:42 -07:00
|
|
|
[appDelegate.feedDetailViewController redrawUnreadStory];
|
|
|
|
[self refreshHeaders];
|
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) {
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_story_as_unread",
|
2012-11-05 17:16:10 -08:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
|
|
|
|
[request setPostValue:[appDelegate.activeStory
|
2013-06-16 08:15:40 -07:00
|
|
|
objectForKey:@"story_hash"]
|
2012-11-05 17:16:10 -08:00
|
|
|
forKey:@"story_id"];
|
|
|
|
[request setPostValue:[appDelegate.activeStory
|
|
|
|
objectForKey:@"story_feed_id"]
|
|
|
|
forKey:@"feed_id"];
|
|
|
|
|
|
|
|
[request setDidFinishSelector:@selector(finishMarkAsUnread:)];
|
2013-10-03 18:07:39 -07:00
|
|
|
[request setDidFailSelector:@selector(failedMarkAsUnread:)];
|
2012-11-05 17:16:10 -08:00
|
|
|
[request setDelegate:self];
|
2013-10-03 18:07:39 -07:00
|
|
|
[request setUserInfo:appDelegate.activeStory];
|
2012-11-05 17:16:10 -08:00
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-16 08:15:40 -07:00
|
|
|
- (void)finishMarkAsUnread:(ASIFormDataRequest *)request {
|
2012-11-05 17:16:10 -08:00
|
|
|
if ([request responseStatusCode] != 200) {
|
2013-10-03 18:07:39 -07:00
|
|
|
return [self failedMarkAsUnread:request];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
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];
|
2013-10-07 10:02:44 -07:00
|
|
|
currentPage.isRecentlyUnread = YES;
|
|
|
|
[currentPage refreshHeader];
|
2013-04-10 21:06:17 -07:00
|
|
|
[self setNextPreviousButtons];
|
2012-12-19 15:37:36 -08:00
|
|
|
[self.currentPage flashCheckmarkHud:@"unread"];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
|
2013-10-03 18:07:39 -07:00
|
|
|
- (void)failedMarkAsUnread:(ASIFormDataRequest *)request {
|
|
|
|
NSString *storyFeedId = [request.userInfo objectForKey:@"story_feed_id"];
|
|
|
|
NSString *storyHash = [request.userInfo objectForKey:@"story_hash"];
|
|
|
|
|
|
|
|
BOOL dequeued = [appDelegate dequeueReadStoryHash:storyHash inFeed:storyFeedId];
|
|
|
|
if (!dequeued) {
|
|
|
|
[self informError:@"Failed to unread story"];
|
|
|
|
[appDelegate markStoryRead:storyHash feedId:storyFeedId];
|
|
|
|
} else {
|
|
|
|
[appDelegate.unreadStoryHashes setObject:[NSNumber numberWithBool:YES] forKey:storyHash];
|
|
|
|
[appDelegate markActiveStoryUnread];
|
|
|
|
[appDelegate.feedDetailViewController redrawUnreadStory];
|
|
|
|
[self setNextPreviousButtons];
|
|
|
|
[self.currentPage flashCheckmarkHud:@"unread"];
|
|
|
|
}
|
2013-10-04 12:37:51 -07:00
|
|
|
|
|
|
|
[self refreshHeaders];
|
2013-10-03 18:07:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
- (IBAction)showOriginalSubview:(id)sender {
|
2013-09-07 01:58:05 -05:00
|
|
|
[appDelegate.masterContainerViewController hidePopover];
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
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;
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger unreadCount = appDelegate.unreadCount;
|
2012-11-05 17:16:10 -08:00
|
|
|
if (unreadCount == 0) {
|
|
|
|
hud.labelText = @"No unread stories";
|
|
|
|
} else if (unreadCount == 1) {
|
|
|
|
hud.labelText = @"1 story left";
|
|
|
|
} else {
|
2013-09-25 17:43:00 -07:00
|
|
|
hud.labelText = [NSString stringWithFormat:@"%li stories left", (long)unreadCount];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
|
|
|
[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
|
|
|
|
2013-05-28 18:07:19 -07:00
|
|
|
- (IBAction)toggleView:(id)sender {
|
2013-10-08 13:57:15 -07:00
|
|
|
[self endTouchDown:sender];
|
|
|
|
|
2013-05-28 18:07:19 -07:00
|
|
|
[self.currentPage fetchTextView];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-07-13 16:56:33 +02:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark HUDs
|
|
|
|
|
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;
|
2013-09-26 19:26:10 -07:00
|
|
|
self.currentPage.noStoryMessage.hidden = YES;
|
2012-11-09 14:13:44 -08:00
|
|
|
}
|
|
|
|
|
2013-07-13 16:56:33 +02:00
|
|
|
- (void)flashCheckmarkHud:(NSString *)messageType {
|
|
|
|
[[self currentPage] flashCheckmarkHud:messageType];
|
|
|
|
}
|
|
|
|
|
2012-11-05 17:16:10 -08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Story Traversal
|
|
|
|
|
2013-10-08 13:57:15 -07:00
|
|
|
- (IBAction)doNextUnreadStory:(id)sender {
|
2012-11-06 17:26:08 -08:00
|
|
|
FeedDetailViewController *fdvc = self.appDelegate.feedDetailViewController;
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger nextLocation = [appDelegate locationOfNextUnreadStory];
|
|
|
|
NSInteger unreadCount = [appDelegate unreadCount];
|
2012-11-05 17:16:10 -08:00
|
|
|
[self.loadingIndicator stopAnimating];
|
|
|
|
|
2013-10-08 13:57:15 -07:00
|
|
|
[self endTouchDown:sender];
|
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];
|
2013-04-23 11:52:34 -07:00
|
|
|
self.circularProgressView.hidden = YES;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 13:57:15 -07:00
|
|
|
- (IBAction)doPreviousStory:(id)sender {
|
|
|
|
[self endTouchDown:sender];
|
2012-11-05 17:16:10 -08:00
|
|
|
[self.loadingIndicator stopAnimating];
|
2013-04-23 11:52:34 -07:00
|
|
|
self.circularProgressView.hidden = NO;
|
2012-11-05 17:16:10 -08:00
|
|
|
id previousStoryId = [appDelegate popReadStory];
|
|
|
|
if (!previousStoryId || previousStoryId == [appDelegate.activeStory objectForKey:@"id"]) {
|
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
|
|
|
[appDelegate hideStoryDetailView];
|
|
|
|
} else {
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger previousLocation = [appDelegate locationOfStoryId:previousStoryId];
|
2012-11-06 13:45:15 -08:00
|
|
|
if (previousLocation == -1) {
|
2013-10-08 13:57:15 -07:00
|
|
|
return [self doPreviousStory:sender];
|
2012-11-05 17:16:10 -08:00
|
|
|
}
|
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
|