5 // Created by Quang Anh Do on 25/05/2010.
6 // Copyright Quang Anh Do 2010. All rights reserved.
9 #import "ATutorAppDelegate.h"
10 #import "StyleSheet.h"
11 #import "OSConsumer.h"
12 #import "OSProvider.h"
14 #import "ActivitiesViewController.h"
15 #import "ContactsViewController.h"
16 #import "ContactViewController.h"
17 #import "GroupsViewController.h"
18 #import "CommonFunctions.h"
20 @interface ATutorAppDelegate (Private)
22 - (void)wireUpNavigator;
27 @implementation ATutorAppDelegate
32 @synthesize webController;
34 @synthesize settingsViewController;
36 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
37 // Set service consumer
38 consumer = [[OSConsumer alloc] init];
40 // Set global stylesheet
41 [TTDefaultStyleSheet setGlobalStyleSheet:[[[StyleSheet alloc] init] autorelease]];
43 // Set web controller handler
44 launcher = [[LauncherViewController alloc] init];
46 webController = [[QAWebController alloc] init];
47 webController.oAuthDelegate = launcher;
50 settingsViewController = [[IASKAppSettingsViewController alloc] initWithNibName:@"IASKAppSettingsView"
52 [settingsViewController setDelegate:self];
55 [self wireUpNavigator];
58 [[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"atutor://launcher"]];
61 helper = [[ATutorHelper alloc] init];
62 [helper setDelegate:self];
64 if (!kATutorURL || !kShindigURL) {
65 NSLog(@"Settings required");
66 [[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:@"atutor://settings"] applyAnimated:YES]];
68 [helper fetchContactList];
78 [webController release];
80 [settingsViewController release];
88 - (void)wireUpNavigator {
89 TTNavigator *navigator = [TTNavigator navigator];
90 navigator.window = window;
91 navigator.persistenceMode = TTNavigatorPersistenceModeNone;
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];
105 #pragma mark Helper delegate
107 - (void)doneFetchingContactList {
108 [[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"atutor://launcher"]];
112 #pragma mark IASK delegate
114 - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController *)sender {
115 NSLog(@"Settings updated, refresh consumer");
116 consumer.currentProvider = [OSProvider getATutorProviderWithKey:kConsumerKey withSecret:kConsumerSecret];