From 38d16e9d26b4f8653063ef2c572ccfc803ab165b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 10 Dec 2017 11:52:54 +0300 Subject: fix layout --- Juick/ViewControllers/DiscoverViewController.m | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'Juick/ViewControllers/DiscoverViewController.m') diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m index 2a109d4..26ec710 100644 --- a/Juick/ViewControllers/DiscoverViewController.m +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -23,10 +23,25 @@ AppDelegate *appDelegate; -(void) viewDidLoad { [super viewDidLoad]; [self.navigationController.navigationBar setPrefersLargeTitles:YES]; - if ([self.path isEqualToString:[APIClient feedUrl]]) { - [self setTitle:@"My feed"]; + if ([User isAuthenticated]) { + [User checkIsValid:^(BOOL success) { + if (success) { + if ([self.path length] == 0) { + self.path = [APIClient feedUrl]; + [self setTitle:@"My feed"]; + } + [self refreshData:NO]; + } else { + [User throwUnableToLogin:self]; + } + }]; + } else { - [self setTitle:@"Discover"]; + if ([self.path length] == 0) { + self.path = [APIClient messagesUrl]; + [self setTitle:@"Discover"]; + } + [self refreshData:NO]; } appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate; if (appDelegate.pushedThread != nil) { @@ -43,9 +58,11 @@ AppDelegate *appDelegate; -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqual: @"threadViewSegue"]) { NSNumber *mid; + BOOL scrollToEnd = NO; if (appDelegate.pushedThread != nil) { mid = appDelegate.pushedThread; appDelegate.pushedThread = nil; + scrollToEnd = YES; } else { Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; mid = msg.mid; @@ -53,12 +70,14 @@ AppDelegate *appDelegate; ThreadViewController *threadVC = (ThreadViewController *)segue.destinationViewController; [threadVC setPath:[APIClient threadUrl]]; [threadVC setParams:[@{@"mid": mid } mutableCopy]]; + [threadVC refreshData:scrollToEnd]; } } - (IBAction)filterAction:(id)sender { UIAlertController *filterAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; [filterAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; [filterAlert addAction:[UIAlertAction actionWithTitle:@"My feed" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + [self setTitle:@"My feed"]; self.path = [APIClient feedUrl]; self.params = nil; [self.messages removeAllObjects]; @@ -66,6 +85,7 @@ AppDelegate *appDelegate; [self refreshData:NO]; }]]; [filterAlert addAction:[UIAlertAction actionWithTitle:@"Discover" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + [self setTitle:@"Discover"]; self.path = [APIClient messagesUrl]; self.params = nil; [self.messages removeAllObjects]; -- cgit v1.2.3