-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsEditProfileViewController.m
More file actions
executable file
·375 lines (328 loc) · 14.9 KB
/
SettingsEditProfileViewController.m
File metadata and controls
executable file
·375 lines (328 loc) · 14.9 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
//
// SettingsEditProfileViewController.m
// Junction
//
// Created by Bobby Ren on 4/6/13.
//
//
#import "SettingsEditProfileViewController.h"
#import "AppDelegate.h"
#import "SettingsEditPersonalViewController.h"
#import "SettingsEditGoalsViewController.h"
#import "SettingsEditBlurrinessViewController.h"
#import "SettingsProfessionalInfoViewController.h"
#import "UIImage+Resize.h"
static AppDelegate * appDelegate;
@interface SettingsEditProfileViewController ()
@end
@implementation SettingsEditProfileViewController
@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 = @"Profile";
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 setFrame:CGRectMake(10, 0, 30, 30)];
[button addTarget:self action:@selector(dismissModalViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * backbutton = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setLeftBarButtonItem:backbutton];
self.view.backgroundColor = COLOR_FAINTBLUE;
[photoView setImage:appDelegate.myUserInfo.photo];
[photoView setImageURL:[NSURL URLWithString:appDelegate.myUserInfo.photoURL]];
}
- (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 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
- (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 setBackgroundColor:[UIColor whiteColor]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.textAlignment = NSTextAlignmentLeft;
cell.accessoryType = UITableViewCellAccessoryNone;
}
int section = [indexPath section];
int row = [indexPath row]; //[chatData count]-[indexPath row]-1;
cell.accessoryView = self.accessoryRightArrow;
switch (row) {
case 0:
{
cell.textLabel.text = @"Personal";
}
break;
case 1:
{
cell.textLabel.text = @"Professional";
}
break;
case 2:
{
cell.textLabel.text = @"Goals";
}
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 {
return HEADER_HEIGHT;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
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:@"UPDATE INFORMATION"];
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, HEADER_HEIGHT)];
[view addSubview:label];
return view;
}
return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 0:
{
NSLog(@"Personal");
SettingsEditPersonalViewController * controller = [[SettingsEditPersonalViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
}
break;
case 1:
{
NSLog(@"Professional");
SettingsProfessionalInfoViewController * controller = [[SettingsProfessionalInfoViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
}
break;
case 2:
{
NSLog(@"Goals");
SettingsEditGoalsViewController * controller = [[SettingsEditGoalsViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
}
break;
default:
break;
}
}
-(IBAction)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];
}
-(IBAction)didClickButtonEditBlurriness:(id)sender {
NSLog(@"Edit bluriness");
SettingsEditBlurrinessViewController * controller = [[SettingsEditBlurrinessViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
}
#pragma mark changing photo
-(IBAction)didClickButtonChangePicture:(id)sender; {
NSLog(@"Change picture");
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.navigationController.navigationBar.tintColor = [UIColor colorWithRed:23.0/255 green:153.0/255 blue:228.0/255 alpha:1];
picker.allowsEditing = YES;
[UIAlertView alertViewWithTitle:nil message:@"Where do you want to get your profile picture?" cancelButtonTitle:@"Cancel" otherButtonTitles:[NSArray arrayWithObjects:@"Camera", @"Photo Album", nil] onDismiss:^(int buttonIndex) {
if (buttonIndex == 0) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
else if (buttonIndex == 1) {
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; // regular res!
}
[self presentModalViewController:picker animated:YES];
} onCancel:^{
return;
}];
}
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage * origImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImage * editImage = [info objectForKey:@"UIImagePickerControllerEditedImage"];
[photoView setImage:origImage];
appDelegate.myUserInfo.photo = origImage;
NSLog(@"Origimage: %f %f", origImage.size.width, origImage.size.height);
NSLog(@"editImage: %f %f", editImage.size.width, editImage.size.height);
if (editImage) {
[photoView setImage:editImage];
appDelegate.myUserInfo.photo = editImage;
}
// force to go into blur
[self didClickButtonEditBlurriness:nil];
}
#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
//NSString * userID = [profile objectForKey:@"pfUserID"];
NSString * name = [[NSString alloc] initWithFormat:@"%@ %@",
[profile objectForKey:@"firstName"], [profile objectForKey:@"lastName"]];
NSString * headline = [profile objectForKey:@"headline"];
NSString * industry = [profile objectForKey:@"industry"];
NSString * summary = [profile objectForKey:@"summary"];
NSString * pictureUrl = [profile objectForKey:@"pictureUrl"];
NSString * email = [profile objectForKey:@"emailAddress"];
NSString * location = [[profile objectForKey:@"location"] objectForKey:@"name"]; // format: "location": {"name": loc}
id _specialties = [profile objectForKey:@"specialties"];
id _currentPositions = [profile objectForKey:@"positions"];
NSArray * specialties = nil;
NSArray * currentPositions = nil;
if (_specialties && [_specialties isKindOfClass:[NSDictionary class]])
specialties = [_specialties objectForKey:@"values"];
if (_currentPositions && [_currentPositions isKindOfClass:[NSDictionary class]])
currentPositions = [_currentPositions objectForKey:@"values"];
self.shellUserInfo = [[UserInfo alloc] init];
if (name)
[shellUserInfo setUsername:name];
if (headline)
[shellUserInfo setHeadline:headline];
if (industry)
[shellUserInfo setIndustry:industry];
if (summary)
[shellUserInfo setSummary:summary];
if (email)
[shellUserInfo setEmail:email];
if (location)
[shellUserInfo setLocation:location];
if (specialties)
[shellUserInfo setSpecialties:specialties];
if (currentPositions) {
[shellUserInfo setCurrentPositions:currentPositions];
id mostRecentPosition = [currentPositions objectAtIndex:0];
id company = [mostRecentPosition objectForKey:@"company"];
if ([company objectForKey:@"name"])
[shellUserInfo setCompany:[company objectForKey:@"name"]];
if ([company objectForKey:@"industry"]) // select current company's industry over personal industry
[shellUserInfo setIndustry:[company objectForKey:@"industry"]];
if ([mostRecentPosition objectForKey:@"title"])
[shellUserInfo setPosition:[mostRecentPosition objectForKey:@"title"]];
}
// information not from linkedIn should be added to shellUser for display
shellUserInfo.lookingFor = appDelegate.myUserInfo.lookingFor;
shellUserInfo.talkAbout = appDelegate.myUserInfo.talkAbout;
shellUserInfo.privacyLevel = appDelegate.myUserInfo.privacyLevel;
if (pictureUrl) {
NSLog(@"PictureURL: %@", pictureUrl);
// if creating a new user and will go through profile process, must request photo
[self requestOriginalLinkedInPhoto];
// if logging in, request this photo but must get AWS photo later
}
}
-(void)requestOriginalLinkedInPhoto {
// load photo in background
[self.lhHelper requestOriginalPhotoWithBlock:^(NSString * originalURL) {
NSLog(@"Picture OriginalURL: %@", originalURL);
shellUserInfo.photo = nil;
shellUserInfo.photoBlur = nil;
// upload unblurred photo to aws
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
UIImage * image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:originalURL]]];
// resize
CGSize frame = image.size;
float scale = 1;
if (frame.width < frame.height)
scale = PROFILE_WIDTH / frame.width;
else
scale = PROFILE_HEIGHT / frame.height;
CGSize target = frame;
target.width *= scale;
target.height *= scale;
image = [image resizedImage:target interpolationQuality:kCGInterpolationHigh];
dispatch_sync(dispatch_get_main_queue(), ^{
[progress hide:YES];
// if we are creating a profile, first save this photo as unblurred
shellUserInfo.photo = image;
shellUserInfo.photoBlur = [appDelegate blurPhoto:image atPrivacyLevel:shellUserInfo.privacyLevel];
PullFromLinkedInProfilePreviewController * controller = [[PullFromLinkedInProfilePreviewController alloc] init];
[controller setDelegate:self];
shellUserInfo.privacyLevel = appDelegate.myUserInfo.privacyLevel;
[controller setUserInfo:shellUserInfo];
[self.navigationController pushViewController:controller animated:YES];
});
});
}];
}
-(void)didApprovePreview {
// save shellUserInfo into myUserInfo
progress = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
progress.mode = MBProgressHUDModeCustomView;
UIView *blankView = [[UIView alloc] initWithFrame:CGRectZero];
progress.customView = blankView;
progress.labelText = @"Info updated from LinkedIn!";
[progress hide:YES afterDelay:2];
appDelegate.myUserInfo.username = shellUserInfo.username;
appDelegate.myUserInfo.headline = shellUserInfo.headline;
appDelegate.myUserInfo.industry = shellUserInfo.industry;
appDelegate.myUserInfo.summary = shellUserInfo.summary;
appDelegate.myUserInfo.email = shellUserInfo.email;
appDelegate.myUserInfo.location = shellUserInfo.location;
appDelegate.myUserInfo.company = shellUserInfo.company;
appDelegate.myUserInfo.industry = shellUserInfo.industry;
appDelegate.myUserInfo.position = shellUserInfo.position;
[[appDelegate.myUserInfo toPFObject] save];
[self.navigationController popViewControllerAnimated:YES];
}
@end