summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers/JuickNavigationController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewControllers/JuickNavigationController.m')
-rw-r--r--Juick/ViewControllers/JuickNavigationController.m35
1 files changed, 29 insertions, 6 deletions
diff --git a/Juick/ViewControllers/JuickNavigationController.m b/Juick/ViewControllers/JuickNavigationController.m
index 8673866..aaf3765 100644
--- a/Juick/ViewControllers/JuickNavigationController.m
+++ b/Juick/ViewControllers/JuickNavigationController.m
@@ -8,31 +8,54 @@
#import "JuickNavigationController.h"
-#import "AppDelegate.h"
-#import "APIClient.h"
#import "MessagesViewController.h"
#import "ThreadViewController.h"
#import "NewPostViewController.h"
#import "Message.h"
+#import "LoginViewController.h"
@interface JuickNavigationController ()
+@property(nonatomic, strong) UIButton *avatarButton;
@end
@implementation JuickNavigationController
+
+-(void) refreshStatus {
+ [[AppDelegate shared].api me:^(User *user, NSError *err) {
+ NSString *avatarUrl;
+ if (err || !user) {
+ avatarUrl = @"https://i.juick.com/av-96.png";
+ } else {
+ avatarUrl = user.avatar;
+ }
+ [[AppDelegate shared].api fetchImageWithURL:[NSURL URLWithString:avatarUrl] callback:^(NSData *data) {
+ self.avatarButton = [UIButton buttonWithType:UIButtonTypeCustom];
+ [self.avatarButton addTarget:self action:@selector(showLoginForm:) forControlEvents:UIControlEventTouchUpInside];
+ [self.avatarButton setImage:[UIImage imageWithImage:[UIImage imageWithData:data] fitInsideWidth:44 fitInsideHeight:44] forState:UIControlStateNormal];
+ self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.avatarButton];
+ }];
+ }];
+}
+
- (void)viewDidLoad {
[super viewDidLoad];
- // Do any additional setup after loading the view.
+ [self refreshStatus];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidSignedIn:) name:UserChangedNotificationName object:nil];
+}
+
+- (void)userDidSignedIn:(NSNotification *) notification {
+ [self refreshStatus];
}
#pragma mark - Navigation
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
if ([identifier isEqualToString:@"editorSegue"]) {
- if ([[APIClient sharedClient] isAuthenticated]) {
+ if ([[AppDelegate shared].api currentUser]) {
return YES;
} else {
[[AppDelegate shared] presentLoginView:self];
@@ -71,7 +94,7 @@
}
}
-- (IBAction)newMessage:(id)sender {
- [[AppDelegate shared] presentLoginView:self];
+- (IBAction)showLoginForm:(id)sender {
+ [self performSegueWithIdentifier:@"loginSegue" sender:self];
}
@end