summaryrefslogtreecommitdiff
path: root/Juick/AppDelegate.m
blob: 82408929e530e8e56c0f2146f7327eead4f147cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
//  AppDelegate.m
//  Juick
//
//  Created by Vitaly Takmazov on 26.10.13.
//  Copyright (c) 2013 com.juick. All rights reserved.
//

#import "AppDelegate.h"
#import "MessagesViewController.h"
#import "RevealPanelViewController.h"
#import "SWRevealViewController.h"
#import "LoginViewController.h"

#import "ColorScheme.h"
#import "Message.h"

@implementation AppDelegate

SWRevealViewController *reveal;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UINavigationBar appearance] setTintColor:[ColorScheme linkColor]];
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [ColorScheme linkColor]}];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
    MessagesViewController *messages = [[MessagesViewController alloc] init];
    RevealPanelViewController *rear = [[RevealPanelViewController alloc] init];
    
    UINavigationController *main = [[UINavigationController alloc] initWithRootViewController:messages];
    UINavigationController *rearNav = [[UINavigationController alloc] initWithRootViewController:rear];
    reveal = [[SWRevealViewController alloc] initWithRearViewController:rearNav frontViewController:main];
    self.viewController = reveal;
    [messages.navigationController.navigationBar addGestureRecognizer:reveal.panGestureRecognizer];
    UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"]
                                                                         style:UIBarButtonItemStylePlain target:reveal action:@selector(revealToggle:)];
    messages.navigationItem.leftBarButtonItem = revealButtonItem;
    UIBarButtonItem *compose = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
                                                                             target:messages action:@selector(composePressed)];
    messages.navigationItem.rightBarButtonItem = compose;
    
    if ([User isAuthenticated]) {
        [User checkIsValid:^(BOOL success) {
            if (success) {
                [messages loadFromPath:[Message feedUrl] withParams:nil withTitle:@"My feed"];
            } else {
                [User throwUnableToLogin];
            }
        }];
        
    } else {
        [messages loadFromPath:[Message messagesUrl] withParams:nil withTitle:@"Discover"];
    }
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    
    return YES;
}
							
- (void) pushLoginForm {
    if ([reveal isBeingPresented]) {
        [reveal revealToggle:self];
    }
    UIViewController *loginView = [[LoginViewController alloc] init];
    UINavigationController *messages = (UINavigationController *)reveal.frontViewController;
    [messages pushViewController:loginView animated:YES];
}

@end