From 9a3b76c8088a7267b0dff843dffbce08ca1c1bdc Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Thu, 13 Dec 2012 16:41:52 -0800 Subject: [PATCH] Fixing bug in ios where hitting next unread while story page controls was already waiting on a page fetch would not automatically advance to the next unread story. --- media/ios/Classes/FeedDetailViewController.m | 1 + media/ios/Classes/StoryDetailViewController.m | 6 ++++++ media/ios/Classes/StoryPageControl.h | 3 +++ media/ios/Classes/StoryPageControl.m | 21 ++++++++++++++----- media/ios/Entitlements.entitlements | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/media/ios/Classes/FeedDetailViewController.m b/media/ios/Classes/FeedDetailViewController.m index a845a1d55..07ffd58d8 100644 --- a/media/ios/Classes/FeedDetailViewController.m +++ b/media/ios/Classes/FeedDetailViewController.m @@ -481,6 +481,7 @@ [self renderStories:confirmedNewStories]; [appDelegate.storyPageControl resizeScrollView]; [appDelegate.storyPageControl setStoryFromScroll:YES]; + [appDelegate.storyPageControl advanceToNextUnread]; } #pragma mark - diff --git a/media/ios/Classes/StoryDetailViewController.m b/media/ios/Classes/StoryDetailViewController.m index f0f3e34c7..e0ef70f00 100644 --- a/media/ios/Classes/StoryDetailViewController.m +++ b/media/ios/Classes/StoryDetailViewController.m @@ -631,6 +631,7 @@ " %@" "
%@
" "
%@ ago
" + "
%@
" "" "
%@
" "%@" // location @@ -652,6 +653,7 @@ userReshareString, [user objectForKey:@"username"], [commentDict objectForKey:@"shared_date"], + likingUsers, commentContent, locationHtml, [commentDict objectForKey:@"user_id"], @@ -926,7 +928,11 @@ shouldStartLoadWithRequest:(NSURLRequest *)request height:[[urlComponents objectAtIndex:6] intValue]]; return NO; } + } else if ([url.host hasSuffix:@"itunes.apple.com"]) { + [[UIApplication sharedApplication] openURL:url]; + return NO; } + if (navigationType == UIWebViewNavigationTypeLinkClicked) { [appDelegate showOriginalStory:url]; return NO; diff --git a/media/ios/Classes/StoryPageControl.h b/media/ios/Classes/StoryPageControl.h index 118fb517b..aaf69496c 100644 --- a/media/ios/Classes/StoryPageControl.h +++ b/media/ios/Classes/StoryPageControl.h @@ -32,6 +32,7 @@ Class popoverClass; BOOL isDraggingScrollview; + BOOL waitingForNextUnreadFromServer; } @property (nonatomic) IBOutlet NewsBlurAppDelegate *appDelegate; @@ -56,6 +57,7 @@ @property (nonatomic, strong) IBOutlet UIBarButtonItem *subscribeButton; @property (readwrite) CGFloat inTouchMove; @property (assign) BOOL isDraggingScrollview; +@property (assign) BOOL waitingForNextUnreadFromServer; @property (nonatomic) MBProgressHUD *storyHUD; @property (nonatomic) int scrollingToPage; @@ -70,6 +72,7 @@ - (void)refreshHeaders; - (void)setStoryFromScroll; - (void)setStoryFromScroll:(BOOL)force; +- (void)advanceToNextUnread; - (void)updatePageWithActiveStory:(int)location; - (void)changePage:(NSInteger)pageIndex; - (void)changePage:(NSInteger)pageIndex animated:(BOOL)animated; diff --git a/media/ios/Classes/StoryPageControl.m b/media/ios/Classes/StoryPageControl.m index 974e0a655..81dfa846c 100644 --- a/media/ios/Classes/StoryPageControl.m +++ b/media/ios/Classes/StoryPageControl.m @@ -44,6 +44,7 @@ @synthesize loadingIndicator; @synthesize inTouchMove; @synthesize isDraggingScrollview; +@synthesize waitingForNextUnreadFromServer; @synthesize storyHUD; @synthesize scrollingToPage; @@ -314,7 +315,7 @@ if (newIndex > 0 && newIndex >= [appDelegate.activeFeedStoryLocations count]) { pageController.pageIndex = -2; - if (self.appDelegate.feedDetailViewController.feedPage < 50 && + if (self.appDelegate.feedDetailViewController.feedPage < 100 && !self.appDelegate.feedDetailViewController.pageFinished && !self.appDelegate.feedDetailViewController.pageFetching) { [self.appDelegate.feedDetailViewController fetchNextPage:^() { @@ -518,6 +519,15 @@ } } +- (void)advanceToNextUnread { + if (!self.waitingForNextUnreadFromServer) { + return; + } + + self.waitingForNextUnreadFromServer = NO; + [self doNextUnreadStory]; +} + - (void)updatePageWithActiveStory:(int)location { [self markStoryAsRead]; [appDelegate pushReadStory:[appDelegate.activeStory objectForKey:@"id"]]; @@ -909,15 +919,16 @@ int unreadCount = [appDelegate unreadCount]; [self.loadingIndicator stopAnimating]; + NSLog(@"doNextUnreadStory: %d (out of %d)", nextLocation, unreadCount); + if (nextLocation == -1 && unreadCount > 0 && - fdvc.feedPage < 50) { + fdvc.feedPage < 100) { [self.loadingIndicator startAnimating]; self.activity.customView = self.loadingIndicator; self.buttonNext.enabled = NO; // Fetch next page and see if it has the unreads. - [fdvc fetchNextPage:^() { - [self doNextUnreadStory]; - }]; + self.waitingForNextUnreadFromServer = YES; + [fdvc fetchNextPage:nil]; } else if (nextLocation == -1) { [appDelegate.navigationController popToViewController:[appDelegate.navigationController.viewControllers diff --git a/media/ios/Entitlements.entitlements b/media/ios/Entitlements.entitlements index fe238e5c4..c468210c7 100644 --- a/media/ios/Entitlements.entitlements +++ b/media/ios/Entitlements.entitlements @@ -5,7 +5,7 @@ application-identifier $(AppIdentifierPrefix)$(CFBundleIdentifier) get-task-allow - + keychain-access-groups $(AppIdentifierPrefix)$(CFBundleIdentifier)