-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsProfessionalInfoViewController.m
More file actions
executable file
·279 lines (237 loc) · 11.2 KB
/
SettingsProfessionalInfoViewController.m
File metadata and controls
executable file
·279 lines (237 loc) · 11.2 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//
// SettingsProfessionalInfoViewController.m
// Junction
//
// Created by Bobby Ren on 4/6/13.
//
//
#import "SettingsProfessionalInfoViewController.h"
#import "AppDelegate.h"
static AppDelegate * appDelegate;
@implementation SettingsProfessionalInfoViewController
@synthesize lhHelper;
@synthesize shellUserInfo;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// make a custom header label
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
UIImage * headerbg = [UIImage imageNamed:@"header_bg"];
[self.navigationController.navigationBar setBackgroundImage:headerbg forBarMetrics:UIBarMetricsDefault];
UILabel * titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[titleView setFont:[UIFont boldSystemFontOfSize:23]];
[titleView setTextColor:[UIColor whiteColor]];
[titleView setBackgroundColor:[UIColor colorWithRed:14.0/255.0 green:158.0/255.0 blue:205.0/255.0 alpha:1]];
[titleView setTextAlignment:NSTextAlignmentCenter];
titleView.text = @"Professional Info";
UIFont * font = titleView.font;
CGRect frame = CGRectMake(0, 0, [self.navigationItem.title sizeWithFont:font].width, 44);
frame.origin.x = 320 - frame.size.width / 2;
[titleView setFrame:frame];
self.navigationItem.titleView = titleView;
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"icon-back"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(10, 0, 30, 30)];
UIBarButtonItem * backbutton = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setLeftBarButtonItem:backbutton];
tableView.backgroundColor = COLOR_FAINTBLUE;
buttonAddRole = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonAddRole setFrame:CGRectMake(-5, -1, 310, 46)];
[buttonAddRole setBackgroundImage:[UIImage imageNamed:@"btn-secondary-up"] forState:UIControlStateNormal];
[buttonAddRole setBackgroundImage:[UIImage imageNamed:@"btn-secondary-press"] forState:UIControlStateHighlighted];
[buttonAddRole addTarget:self action:@selector(didClickAddRole:) forControlEvents:UIControlEventTouchUpInside];
[buttonAddRole setTitle:@"Add a Role" forState:UIControlStateNormal];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return [appDelegate.myUserInfo.currentPositions count];
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.textAlignment = NSTextAlignmentLeft;
cell.accessoryType = UITableViewCellAccessoryNone;
}
int row = [indexPath row]; //[chatData count]-[indexPath row]-1;
int section = [indexPath section];
switch (section) {
case 0:
{
NSDictionary * currPos = [appDelegate.myUserInfo.currentPositions objectAtIndex:indexPath.row];
NSLog(@"CurrPos %d: %@", row, currPos);
[cell setBackgroundColor:[UIColor whiteColor]];
cell.accessoryView = self.accessoryRightArrow;
cell.textLabel.text = [currPos objectForKey:@"title"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", [[currPos objectForKey:@"company"] objectForKey:@"name"], [[currPos objectForKey:@"company"] objectForKey:@"industry"]];
}
break;
case 1:
{
[cell setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundView:nil];
cell.accessoryView = nil;
[buttonAddRole removeFromSuperview];
[cell.contentView addSubview:buttonAddRole];
}
break;
default:
break;
}
return cell;
}
-(UIImageView*)accessoryRightArrow {
UIImageView * accessoryRightArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"btn-field-arrow.png"]];
[accessoryRightArrow setFrame:CGRectMake(0, 0, 17, 25)];
return accessoryRightArrow;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0)
return HEADER_HEIGHT;
return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
int index;
if (section == 0) {
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, HEADER_HEIGHT)];
[label setFont:[UIFont boldSystemFontOfSize:11]];
[label setTextColor:COLOR_LIGHTBLUE];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextAlignment:NSTextAlignmentLeft];
[label setText:@"YOUR RECENT ROLES"];
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, HEADER_HEIGHT)];
[view addSubview:label];
return view;
}
else if (section == 1) {
return nil;
}
return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray * positions = appDelegate.myUserInfo.currentPositions;
NSDictionary * currPos = [positions objectAtIndex:indexPath.row];
NSString * company = [[currPos objectForKey:@"company"] objectForKey:@"name"];
NSString * industry = [[currPos objectForKey:@"company"] objectForKey:@"industry"];
NSString * position = [currPos objectForKey:@"title"];
SettingsEditRoleViewController * roleEditor = [[SettingsEditRoleViewController alloc] init];
[roleEditor setDelegate:self];
[roleEditor setRoleIndex:indexPath.row];
[roleEditor setCompany:company];
[roleEditor setIndustry:industry];
[roleEditor setPosition:position];
[self.navigationController pushViewController:roleEditor animated:YES];
}
-(void)didClickAddRole:(id)sender {
NSLog(@"Add a new role!");
SettingsEditRoleViewController * roleEditor = [[SettingsEditRoleViewController alloc] init];
[roleEditor setDelegate:self];
[roleEditor setRoleIndex:-1];
[self.navigationController pushViewController:roleEditor animated:YES];
}
-(void)goBack:(id)sender {
// save
// dismiss
[self.navigationController popViewControllerAnimated:YES];
}
-(void)didClickPullFromLinkedIn:(id)sender {
NSLog(@"Pull from linkedIn");
if (self.lhHelper == nil) {
self.lhHelper = [[LinkedInHelper alloc] init];
self.lhHelper.delegate = self;
[self.lhHelper loadCachedOAuth];
}
progress = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
progress.labelText = @"Pulling from LinkedIn...";
[self.lhHelper requestAllProfileInfoForID:appDelegate.myUserInfo.linkedInString];
}
#pragma mark LinkedInHelperDelegate
-(void)linkedInDidFail:(NSError *)error {
NSLog(@"Could not pull from linkedIn! Error: %@", error);
progress.labelText = @"Error pulling your info!";
progress.mode = MBProgressHUDModeCustomView;
UIView *blankView = [[UIView alloc] initWithFrame:CGRectZero];
progress.customView = blankView;
[progress hide:YES afterDelay:2];
}
-(void)linkedInParseProfileInformation:(NSDictionary*)profile {
// returns the following information: first-name,last-name,industry,location:(name),specialties,summary,picture-url,email-address,educations,three-current-positions
id _currentPositions = [profile objectForKey:@"positions"];
NSArray * currentPositions = nil;
if (_currentPositions && [_currentPositions isKindOfClass:[NSDictionary class]])
currentPositions = [_currentPositions objectForKey:@"values"];
for (NSMutableDictionary * newRole in currentPositions) {
NSMutableDictionary * newCompany = [newRole objectForKey:@"company"];
NSString * newPosition = [newRole objectForKey:@"title"];
NSString * newCompanyName = [newCompany objectForKey:@"name"];
NSString * newIndustry = [newCompany objectForKey:@"industry"];
BOOL alreadyExists = NO;
for (NSMutableDictionary * existingRole in appDelegate.myUserInfo.currentPositions) {
NSMutableDictionary * existingCompany = [existingRole objectForKey:@"company"];
NSString * existingPosition = [existingRole objectForKey:@"title"];
NSString * existingCompanyName = [existingCompany objectForKey:@"name"];
NSString * existingIndustry = [existingCompany objectForKey:@"industry"];
if ([newPosition isEqualToString:existingPosition] && [newIndustry isEqualToString:existingIndustry] && [newCompanyName isEqualToString:existingCompanyName]) {
alreadyExists = YES;
break;
}
}
if (!alreadyExists) {
NSLog(@"Pulled role from linkedIn not listed in app: %@ @ %@ (%@)", newPosition, newCompanyName, newIndustry);
[appDelegate.myUserInfo.currentPositions addObject:newRole];
}
}
[progress hide:YES];
[appDelegate.myUserInfo.toPFObject saveInBackground];
[tableView reloadData];
}
#pragma mark SettingsEditRoleDelegate
-(void)didSaveRoleAtIndex:(int)index withPosition:(NSString *)newPosition withCompany:(NSString *)newCompany withIndustry:(NSString *)newIndustry {
[self.navigationController popToViewController:self animated:YES];
if (!appDelegate.myUserInfo.currentPositions) {
appDelegate.myUserInfo.currentPositions = [[NSMutableArray alloc] init];
}
if (index == -1) {
NSMutableDictionary * newRole = [[NSMutableDictionary alloc] init];
NSMutableDictionary * company = [[NSMutableDictionary alloc] init];
[newRole setObject:company forKey:@"company"];
[appDelegate.myUserInfo.currentPositions addObject:newRole];
index = [appDelegate.myUserInfo.currentPositions count]-1;
}
NSMutableDictionary * role = [appDelegate.myUserInfo.currentPositions objectAtIndex:index];
NSMutableDictionary * company = [role objectForKey:@"company"];
[company setObject:newIndustry forKey:@"industry"];
[company setObject:newCompany forKey:@"name"];
[role setObject:newPosition forKey:@"title"];
NSLog(@"Role at %d saved! %@, %@, %@", index, newPosition, newCompany, newIndustry);
[appDelegate.myUserInfo.toPFObject save];
[tableView reloadData];
}
@end