changed git call from https to git readonly
[atutor.git] / mods / atsocial_iphone_app / Classes / ATutorAppDelegate.m
1 //
2 //  ATutorAppDelegate.m
3 //  ATutor
4 //
5 //  Created by Quang Anh Do on 25/05/2010.
6 //  Copyright Quang Anh Do 2010. All rights reserved.
7 //
8
9 #import "ATutorAppDelegate.h"
10 #import "StyleSheet.h"
11 #import "OSConsumer.h"
12 #import "OSProvider.h"
13
14 #import "ActivitiesViewController.h"
15 #import "ContactsViewController.h"
16 #import "ContactViewController.h"
17 #import "GroupsViewController.h"
18 #import "CommonFunctions.h"
19
20 @interface ATutorAppDelegate (Private) 
21
22 - (void)wireUpNavigator;
23
24 @end
25
26
27 @implementation ATutorAppDelegate
28
29 @synthesize window;
30 @synthesize consumer;
31 @synthesize launcher;
32 @synthesize webController;
33 @synthesize helper;
34 @synthesize settingsViewController;
35
36 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
37         // Set service consumer
38         consumer = [[OSConsumer alloc] init];
39         
40         // Set global stylesheet
41         [TTDefaultStyleSheet setGlobalStyleSheet:[[[StyleSheet alloc] init] autorelease]];      
42         
43         // Set web controller handler
44         launcher = [[LauncherViewController alloc] init];
45         
46         webController = [[QAWebController alloc] init];
47         webController.oAuthDelegate = launcher;
48         
49         // Set up settings VC
50         settingsViewController = [[IASKAppSettingsViewController alloc] initWithNibName:@"IASKAppSettingsView" 
51                                                                                                                                                          bundle:nil];
52         [settingsViewController setDelegate:self];
53         
54         // Wire things up
55         [self wireUpNavigator];
56         
57         // Home screen
58         [[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"atutor://launcher"]];
59         
60         // Prepare helper
61         helper = [[ATutorHelper alloc] init];
62         [helper setDelegate:self];
63         
64         if (!kATutorURL || !kShindigURL) {
65                 NSLog(@"Settings required");
66                 [[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:@"atutor://settings"] applyAnimated:YES]];
67         } else {
68                 [helper fetchContactList];
69         }
70         
71         return YES;
72 }
73
74 - (void)dealloc {
75     [window release];
76         [consumer release];
77         [launcher release];
78         [webController release];
79         [helper release];
80         [settingsViewController release];
81         
82     [super dealloc];
83 }
84
85 #pragma mark -
86 #pragma mark Misc
87
88 - (void)wireUpNavigator {
89         TTNavigator *navigator = [TTNavigator navigator];
90         navigator.window = window;
91         navigator.persistenceMode = TTNavigatorPersistenceModeNone;
92         
93         TTURLMap *map = navigator.URLMap;
94         [map from:@"*" toViewController:webController];
95         [map from:@"atutor://launcher" toViewController:launcher];
96         [map from:@"atutor://activities" toViewController:[ActivitiesViewController class]];
97         [map from:@"atutor://contacts" toViewController:[ContactsViewController class]];
98         [map from:@"atutor://contact/(initWithId:)" toViewController:[ContactViewController class]];
99         [map from:@"atutor://contact/(initWithId:)/(name:)" toViewController:[ContactViewController class]];
100         [map from:@"atutor://groups" toViewController:[GroupsViewController class]];
101         [map from:@"atutor://settings" toViewController:settingsViewController];
102 }
103
104 #pragma mark -
105 #pragma mark Helper delegate
106
107 - (void)doneFetchingContactList {
108         [[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"atutor://launcher"]];
109 }
110
111 #pragma mark -
112 #pragma mark IASK delegate
113
114 - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController *)sender {
115         NSLog(@"Settings updated, refresh consumer");
116         consumer.currentProvider = [OSProvider getATutorProviderWithKey:kConsumerKey withSecret:kConsumerSecret];
117 }
118
119 @end