From d8f79528dd9a7ba9fc7d3388697ffec2f8fc1c43 Mon Sep 17 00:00:00 2001 From: David Sinclair Date: Wed, 28 Oct 2015 21:50:23 -0700 Subject: [PATCH] iOS: done #735 (non-modal story notifications) --- clients/ios/Classes/NBNotifier.h | 3 +- clients/ios/Classes/NBNotifier.m | 69 +++++-------------- .../ios/Classes/StoryDetailViewController.m | 10 ++- clients/ios/Classes/StoryPageControl.h | 4 ++ clients/ios/Classes/StoryPageControl.m | 18 +++++ 5 files changed, 46 insertions(+), 58 deletions(-) diff --git a/clients/ios/Classes/NBNotifier.h b/clients/ios/Classes/NBNotifier.h index 894efc140..45698b809 100644 --- a/clients/ios/Classes/NBNotifier.h +++ b/clients/ios/Classes/NBNotifier.h @@ -46,10 +46,9 @@ typedef enum { - (void)show; - (void)showIn:(float)time; -- (void)showFor:(float)time; - (void)hide; -- (void)hideAfter:(float)seconds; +- (void)hideNow; - (void)hideIn:(float)seconds; @end diff --git a/clients/ios/Classes/NBNotifier.m b/clients/ios/Classes/NBNotifier.m index fcd4429da..083c64c2e 100644 --- a/clients/ios/Classes/NBNotifier.m +++ b/clients/ios/Classes/NBNotifier.m @@ -204,71 +204,34 @@ CGRect frame = self.frame; frame.size.width = self.view.frame.size.width; self.frame = frame; + self.hidden = NO; - [UIView beginAnimations:nil context:nil]; - [UIView setAnimationDuration:time]; - - CGRect move = self.frame; - move.origin.y = self.view.frame.size.height - NOTIFIER_HEIGHT - self.offset.y; - self.frame = move; - - [UIView commitAnimations]; - -} - -- (void)showFor:(float)time{ - showing = YES; - [UIView beginAnimations:nil context:nil]; - [UIView setAnimationDuration:0.3f]; - - CGRect move = self.frame; - move.origin.y = self.view.frame.size.height - NOTIFIER_HEIGHT - self.offset.y; - self.frame = move; - - [UIView commitAnimations]; - - [self hideAfter:time]; -} - -- (void)hideAfter:(float)seconds{ - - if (!showing) return; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ - - [UIView beginAnimations:nil context:nil]; - [UIView setAnimationDuration:0.3f]; - [UIView setAnimationDelegate: self]; //or some other object that has necessary method -// [UIView setAnimationDidStopSelector: @selector(removeFromSuperview)]; - - + [UIView animateWithDuration:time animations:^{ CGRect move = self.frame; - move.origin.y += NOTIFIER_HEIGHT; + move.origin.y = self.view.frame.size.height - NOTIFIER_HEIGHT - self.offset.y; self.frame = move; - - [UIView commitAnimations]; - }); - showing = NO; + } completion:nil]; } - (void)hide { [self hideIn:0.3f]; } + +- (void)hideNow { + [self hideIn:0.0f]; +} + - (void)hideIn:(float)seconds { if (!showing) return; - [UIView beginAnimations:nil context:nil]; - [UIView setAnimationDuration:seconds]; - [UIView setAnimationDelegate: self]; //or some other object that has necessary method -// [UIView setAnimationDidStopSelector: @selector(removeFromSuperview)]; - - - CGRect move = self.frame; - move.origin.y = self.view.frame.size.height - self.offset.y; - self.frame = move; - - [UIView commitAnimations]; + [UIView animateWithDuration:seconds animations:^{ + CGRect move = self.frame; + move.origin.y = self.view.frame.size.height - self.offset.y; + self.frame = move; + } completion:^(BOOL finished) { + self.hidden = YES; + }]; showing = NO; } diff --git a/clients/ios/Classes/StoryDetailViewController.m b/clients/ios/Classes/StoryDetailViewController.m index 5b8ee7163..2a6f75509 100644 --- a/clients/ios/Classes/StoryDetailViewController.m +++ b/clients/ios/Classes/StoryDetailViewController.m @@ -2104,9 +2104,10 @@ shouldStartLoadWithRequest:(NSURLRequest *)request self.inTextView = YES; // NSLog(@"Fetching Text: %@", [self.activeStory objectForKey:@"story_title"]); dispatch_async(dispatch_get_main_queue(), ^{ - [MBProgressHUD hideHUDForView:self.webView animated:YES]; - MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.webView animated:YES]; - HUD.labelText = @"Fetching text..."; +// [MBProgressHUD hideHUDForView:self.webView animated:YES]; +// MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.webView animated:YES]; +// HUD.labelText = @"Fetching text..."; + [self.appDelegate.storyPageControl showFetchingTextNotifier]; }); NSString *urlString = [NSString stringWithFormat:@"%@/rss_feeds/original_text", @@ -2122,6 +2123,7 @@ shouldStartLoadWithRequest:(NSURLRequest *)request } - (void)failedFetchText:(ASIHTTPRequest *)request { + [self.appDelegate.storyPageControl hideNotifier]; [MBProgressHUD hideHUDForView:self.webView animated:YES]; [self informError:@"Could not fetch text"]; self.inTextView = NO; @@ -2144,6 +2146,7 @@ shouldStartLoadWithRequest:(NSURLRequest *)request if (![[request.userInfo objectForKey:@"storyId"] isEqualToString:[self.activeStory objectForKey:@"id"]]) { + [self.appDelegate.storyPageControl hideNotifier]; [MBProgressHUD hideHUDForView:self.webView animated:YES]; self.inTextView = NO; [appDelegate.storyPageControl setTextButton:self]; @@ -2157,6 +2160,7 @@ shouldStartLoadWithRequest:(NSURLRequest *)request } self.activeStory = newActiveStory; + [self.appDelegate.storyPageControl hideNotifier]; [MBProgressHUD hideHUDForView:self.webView animated:YES]; self.inTextView = YES; diff --git a/clients/ios/Classes/StoryPageControl.h b/clients/ios/Classes/StoryPageControl.h index ab5b3aaf1..a38817865 100644 --- a/clients/ios/Classes/StoryPageControl.h +++ b/clients/ios/Classes/StoryPageControl.h @@ -11,6 +11,7 @@ #import "NewsBlurAppDelegate.h" #import "WYPopoverController.h" #import "THCircularProgressView.h" +#import "NBNotifier.h" @class NewsBlurAppDelegate; @class ASIHTTPRequest; @@ -75,6 +76,7 @@ @property (assign) BOOL isAnimatedIntoPlace; @property (assign) BOOL waitingForNextUnreadFromServer; @property (nonatomic) MBProgressHUD *storyHUD; +@property (nonatomic, strong) NBNotifier *notifier; @property (nonatomic) NSInteger scrollingToPage; @property (nonatomic, strong) WYPopoverController *popoverController; @@ -114,6 +116,8 @@ - (void)changeFontSize:(NSString *)fontSize; - (void)changeLineSpacing:(NSString *)lineSpacing; - (void)showShareHUD:(NSString *)msg; +- (void)showFetchingTextNotifier; +- (void)hideNotifier; - (IBAction)showOriginalSubview:(id)sender; diff --git a/clients/ios/Classes/StoryPageControl.m b/clients/ios/Classes/StoryPageControl.m index cdfc791ac..d066b5e4b 100644 --- a/clients/ios/Classes/StoryPageControl.m +++ b/clients/ios/Classes/StoryPageControl.m @@ -179,6 +179,11 @@ action:@selector(transitionFromFeedDetail)]; self.buttonBack = backButton; + self.notifier = [[NBNotifier alloc] initWithTitle:@"Fetching text..." + inView:self.view + withOffset:CGPointMake(0.0, 0.0 /*self.bottomSize.frame.size.height*/)]; + [self.view addSubview:self.notifier]; + [self.notifier hideNow]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects: @@ -413,6 +418,7 @@ previousPage.pageIndex = -2; [self changePage:pageIndex animated:NO]; [MBProgressHUD hideHUDForView:self.view animated:YES]; + [self.notifier hide]; // self.scrollView.contentOffset = CGPointMake(self.scrollView.frame.size.width * currentPage.pageIndex, 0); } @@ -431,6 +437,7 @@ [self.scrollView scrollRectToVisible:frame animated:NO]; [MBProgressHUD hideHUDForView:self.view animated:YES]; + [self.notifier hide]; } - (void)refreshHeaders { @@ -1066,6 +1073,17 @@ [[self currentPage] flashCheckmarkHud:messageType]; } +- (void)showFetchingTextNotifier { + self.notifier.style = NBSyncingStyle; + self.notifier.title = @"Fetching text..."; + [self.notifier setProgress:0]; + [self.notifier show]; +} + +- (void)hideNotifier { + [self.notifier hide]; +} + #pragma mark - #pragma mark Story Traversal