-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStartViewController.m
More file actions
202 lines (174 loc) · 6.97 KB
/
StartViewController.m
File metadata and controls
202 lines (174 loc) · 6.97 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//
// StartViewController.m
// UKEprogram
//
// Created by UKA-11 Accenture AS on 18.07.11.
// Copyright 2011 Accenture AS. All rights reserved.
//
#import "StartViewController.h"
#import "UKEprogramAppDelegate.h"
#import "EventsTableViewController.h"
#import "Facebook.h"
#import "SettingsViewController.h"
#import "EventDetailsViewController.h"
@implementation StartViewController
@synthesize allButton;
@synthesize artistButton;
@synthesize favoritesButton;
@synthesize eventsTableViewController;
@synthesize settingsViewController;
@synthesize fbLoginButton;
@synthesize settingsButton;
//UIImageView *titleImage;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
-(void)settingsClicked:(id)sender
{
[settingsViewController release];
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
self.settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
[delegate.rootController pushViewController:settingsViewController animated:YES];
}
-(void)facebookLogin:(id)sender
{
[self loginFacebook];
}
-(void)loginFacebook
{
NSLog(@"LoginClicked");
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
Facebook *facebook = delegate.facebook;
[facebook authorize:nil delegate:self];
}
-(void)facebookLogout:(id)sender
{
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.facebook logout:self];
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
- (void)setLoggedIn:(bool)sessionValid {
if (!sessionValid) {
[fbLoginButton removeTarget:self action:@selector(facebookLogout:) forControlEvents:UIControlEventTouchUpInside];
[fbLoginButton addTarget:self action:@selector(facebookLogin:) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside];
[fbLoginButton setTitle:@"Logg på" forState:UIControlStateNormal];
[settingsButton setHidden:YES];
} else {
[fbLoginButton removeTarget:self action:@selector(facebookLogin:) forControlEvents:UIControlEventTouchUpInside];
[fbLoginButton addTarget:self action:@selector(facebookLogout:) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside];
[fbLoginButton setTitle:@"Logg ut" forState:UIControlStateNormal];
[settingsButton setHidden:NO];
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate loginBackend];
}
}
-(void)allEventsClicked:(id)sender {
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
self.eventsTableViewController = [[EventsTableViewController alloc] initWithNibName:@"EventsTableView" bundle:nil];
[delegate.rootController pushViewController:eventsTableViewController animated:YES];
[eventsTableViewController showAllEvents];
NSDate *now = [[NSDate alloc] init];
[eventsTableViewController scrollToDate:now animated:YES];
[now dealloc];
}
-(void)favoriteEventsClicked:(id)sender {
self.eventsTableViewController = [[EventsTableViewController alloc] initWithNibName:@"EventsTableView" bundle:nil];
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.rootController pushViewController:eventsTableViewController animated:YES];
[eventsTableViewController showFavoriteEvents];
NSDate *now = [[NSDate alloc] init];
[eventsTableViewController scrollToDate:now animated:YES];
[now dealloc];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
NSLog(@"Loading startupView");
[super viewDidLoad];
[allButton addTarget:self action:@selector(allEventsClicked:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[favoritesButton addTarget:self action:@selector(favoriteEventsClicked:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
self.navigationItem.title = @"Hjem";
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[self setLoggedIn: [delegate.facebook isSessionValid]];
[settingsButton addTarget:self action:@selector(settingsClicked:) forControlEvents:UIControlEventTouchDown];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
[settingsViewController release];
[eventsTableViewController release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[[delegate rootController] setNavigationBarHidden:YES];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[[delegate rootController] setNavigationBarHidden:NO];
}
- (void) notifyViews
{
NSLog(@"blabla %i", [self.navigationController.viewControllers count]);
if ([self.navigationController.viewControllers count] > 2) {
EventsTableViewController *etView = (EventsTableViewController *)[self.navigationController.viewControllers objectAtIndex:1];
EventDetailsViewController *edView = (EventDetailsViewController *)[self.navigationController.viewControllers objectAtIndex:2];
[etView setLoginButtons];
[edView setLoginButtons];
}
}
- (void) fbDidLogin {
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[delegate.facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[delegate.facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[self setLoggedIn: [delegate.facebook isSessionValid]];
[self notifyViews];
}
-(void)fbDidLogout {
UKEprogramAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[delegate.facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults synchronize];
[self setLoggedIn: [delegate.facebook isSessionValid]];
[self notifyViews];
}
-(void)fbDidNotLogin:(BOOL)cancelled {
}
@end