diff options
Diffstat (limited to 'Juick/RevealPanelViewController.m')
-rw-r--r-- | Juick/RevealPanelViewController.m | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/Juick/RevealPanelViewController.m b/Juick/RevealPanelViewController.m index 9d27608..563e06d 100644 --- a/Juick/RevealPanelViewController.m +++ b/Juick/RevealPanelViewController.m @@ -15,7 +15,7 @@ #import "NSURL+PathParameters.h" #import "NavCell.h" #import "Message.h" - +#import "User.h" static NSString *CellIdentifier = @"NavCell"; @@ -38,15 +38,57 @@ static NSString *CellIdentifier = @"NavCell"; - (void)viewDidLoad { [super viewDidLoad]; - self.title = @"Juick"; - + if (NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_6_1) { self.navigationController.navigationBar.tintColor = [ColorScheme navbarBackground]; } [self.view setBackgroundColor:[ColorScheme navbarBackground]]; + self.tableView = [[UITableView alloc] init]; + [self.tableView setBackgroundColor:[ColorScheme navbarBackground]]; + self.tableView.delegate = self; + self.tableView.dataSource = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.separatorColor =[UIColor blackColor]; [self.tableView registerClass:[NavCell class] forCellReuseIdentifier:CellIdentifier]; + [self.view addSubview:self.tableView]; + self.signButton = [[UIButton alloc] init]; + [self.signButton addTarget:self action:@selector(signInOut) forControlEvents:UIControlEventTouchUpInside]; + [self.view addSubview:self.signButton]; + self.titleView = [[TitleView alloc] initWithImage:nil title:@"Juick"]; + [self.navigationItem setTitleView:self.titleView]; + [self refreshInfo]; +} + +-(void) refreshInfo { + NSString *text; + UIColor *color; + + if ([User isAuthenticated]) { + text = @"Sign Out"; + color = [UIColor redColor]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ + [User get:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] callback:^(User *user) { + [self.titleView.image setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/as/%@.png", user.uid]]]; + [self.titleView.title setText:user.uname]; + }]; + }); + } else { + text = @"Sign In"; + color = [UIColor greenColor]; + } + [self.signButton setTitle:text forState:UIControlStateNormal]; + [self.signButton setBackgroundColor:color]; +} + +-(void) signInOut { + [self refreshInfo]; + [self pushLoginForm]; +} + +-(void) viewWillLayoutSubviews { + [super viewWillLayoutSubviews]; + self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 400); + self.signButton.frame = CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40); } - (void)didReceiveMemoryWarning @@ -98,6 +140,13 @@ static NSString *CellIdentifier = @"NavCell"; return cell; } +- (void) pushLoginForm { + [self.revealViewController revealToggle:self]; + UIViewController *loginView = [[LoginViewController alloc] initWithStyle:UITableViewStyleGrouped]; + UINavigationController *messages = (UINavigationController *)self.revealViewController.frontViewController; + [messages pushViewController:loginView animated:YES]; +} + - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row = indexPath.row; NSString *targetPath; @@ -105,10 +154,7 @@ static NSString *CellIdentifier = @"NavCell"; NSString *targetTitle; if (row == 0) { if ([[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] == nil) { - [self.revealViewController revealToggle:self]; - UIViewController *loginView = [[LoginViewController alloc] initWithStyle:UITableViewStyleGrouped]; - UINavigationController *messages = (UINavigationController *)self.revealViewController.frontViewController; - [messages pushViewController:loginView animated:YES]; + [self pushLoginForm]; return; } else { targetTitle = @"My feed"; |