From bf573afb9d05ce34ecd22b3dca85aca2c3896ae6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 2 Oct 2019 17:16:01 +0300 Subject: Shared navigation --- Juick/AppDelegate.m | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'Juick/AppDelegate.m') diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index 3bdb774..fe1b0eb 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -85,18 +85,16 @@ NSString * const UserUpdatedNotificationName = @"UserUpdated"; NSDictionary *userInfo = response.notification.request.content.userInfo; [self parseNotificationPayload:userInfo]; [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - UITabBarController *main = (UITabBarController *)self.window.rootViewController; + UITabBarController *main = (UITabBarController *)[self navigator]; if ([self.pushedThread integerValue] > 0) { [main setSelectedIndex:0]; - UINavigationController *discover = (UINavigationController *)[main.viewControllers objectAtIndex:0]; - [discover popToRootViewControllerAnimated:NO]; - MessagesViewController *msgVC = (MessagesViewController *)[discover.viewControllers objectAtIndex:0]; - [msgVC viewThreadForMessage:nil mid:self.pushedThread scrollTo:self.pushedReplyId]; + MessagesViewController *discover = (MessagesViewController *)[main.viewControllers objectAtIndex:0]; + [discover viewThreadForMessage:nil mid:self.pushedThread scrollTo:self.pushedReplyId]; [self cleanupPushedData]; } else { [main setSelectedIndex:2]; - UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:2]; - [[dialogs.viewControllers objectAtIndex:0] performSegueWithIdentifier:@"chatSegue" sender:dialogs]; + MessagesViewController *dialogs = (MessagesViewController *)[main.viewControllers objectAtIndex:2]; + [dialogs performSegueWithIdentifier:@"chatSegue" sender:dialogs]; } }]; completionHandler(); @@ -106,8 +104,8 @@ NSString * const UserUpdatedNotificationName = @"UserUpdated"; if (userInfo[@"service"]) { User *user = [User fromJSON:userInfo[@"user"]]; application.applicationIconBadgeNumber = user.unreadCount; - UITabBarController *main = (UITabBarController *)self.window.rootViewController; - UINavigationController *discussions = [main.viewControllers objectAtIndex:1]; + UITabBarController *main = (UITabBarController *)[self navigator]; + UIViewController *discussions = [main.viewControllers objectAtIndex:1]; if (user.unreadCount > 0) { [discussions tabBarItem].badgeColor = [UIColor colorNamed:@"Funny"]; [discussions tabBarItem].badgeValue = [NSString stringWithFormat:@"%ld", user.unreadCount]; @@ -142,13 +140,20 @@ NSString * const UserUpdatedNotificationName = @"UserUpdated"; return (AppDelegate *)[UIApplication sharedApplication].delegate; } -+ (id)threadViewController { - UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; - return [mainStoryboard instantiateViewControllerWithIdentifier:@"threadViewControllerIdentifier"]; +- (UINavigationController *) navigator { + return [[(UINavigationController *)self.window.rootViewController viewControllers] firstObject]; +} + +- (void)presentThread:(UIViewController *)vc { + [[self navigator] performSegueWithIdentifier:@"threadSegue" sender:vc]; +} + +- (void) presentEditor:(UIViewController *)vc { + [[self navigator] performSegueWithIdentifier:@"editorSegue" sender:vc]; } - (void) presentLoginView:(UIViewController *)vc { - [self.window.rootViewController performSegueWithIdentifier:@"loginSegue" sender:vc]; + [[self navigator] performSegueWithIdentifier:@"loginSegue" sender:vc]; } @end -- cgit v1.2.3