-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPullFromLinkedInProfilePreviewController.m
More file actions
executable file
·153 lines (129 loc) · 6.32 KB
/
PullFromLinkedInProfilePreviewController.m
File metadata and controls
executable file
·153 lines (129 loc) · 6.32 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
//
// PullFromLinkedInProfilePreviewController.m
// Junction
//
// Created by Bobby Ren on 4/21/13.
//
//
#import "PullFromLinkedInProfilePreviewController.h"
#import "AppDelegate.h"
#import "AWSHelper.h"
#import "UIImage+Resize.h"
@implementation PullFromLinkedInProfilePreviewController
static AppDelegate * appDelegate;
@synthesize viewForConnections, viewForFrame, viewForStrangers;
@synthesize isViewForConnections;
@synthesize userProfileViewController;
@synthesize userInfo;
@synthesize delegate;
- (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 = @"Approve Changes";
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;
UIBarButtonItem * backbutton = [[UIBarButtonItem alloc] initWithCustomView:buttonCancel];
[self.navigationItem setLeftBarButtonItem:backbutton];
UIBarButtonItem * saveButton = [[UIBarButtonItem alloc] initWithCustomView:buttonApprove];
[self.navigationItem setRightBarButtonItem:saveButton];
self.view.backgroundColor = COLOR_FAINTBLUE;
[self.viewForStrangers setSelected:YES];
self.userProfileViewController = [[UserProfileViewController alloc] init];
// to prevent the photo to default to some previously generated photo, remove the linkedInString so photoURL and photoBlurURL cannot be generated by UserProfileViewController
savedLinkedInString = [self.userInfo.linkedInString copy];
self.userInfo.linkedInString = nil;
[self.userProfileViewController setDelegate:self];
[self.userProfileViewController setUserInfo:userInfo];
[self.view addSubview:self.userProfileViewController.view];
[self.userProfileViewController.view setFrame:self.viewForFrame.frame]; //CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height - 60)];
[self toggleViewForConnections:viewForStrangers];
[self.userProfileViewController toggleInteraction:NO];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)toggleViewForConnections:(id)sender {
if ((UIButton*)sender == viewForConnections) {
[viewForConnections setSelected:YES];
[viewForStrangers setSelected:NO];
isViewForConnections = YES;
[self.userProfileViewController toggleViewForConnection:isViewForConnections];
}
else if ((UIButton*)sender == viewForStrangers) {
[viewForConnections setSelected:NO];
[viewForStrangers setSelected:YES];
isViewForConnections = NO;
[self.userProfileViewController toggleViewForConnection:isViewForConnections];
}
}
-(IBAction)didClickApprove:(id)sender {
NSLog(@"Next!");
UIImage * newImage = userInfo.photo;
UIImage * newBlur = userInfo.photoBlur;
NSLog(@"Clearing cache for user at %@ and %@", userInfo.photoURL, userInfo.photoURL);
[AsyncImageView clearCacheForURL:userInfo.photoURL];
[AsyncImageView clearCacheForURL:userInfo.photoBlurURL];
NSString * nullurl = [AWSHelper getURLForKey:nil inBucket:PHOTO_BUCKET];
NSString * nullblururl = [AWSHelper getURLForKey:nil inBucket:PHOTO_BUCKET];
NSLog(@"Clearing cache for user at %@ and %@", nullurl, nullblururl);
[AsyncImageView clearCacheForURL:nullurl];
[AsyncImageView clearCacheForURL:nullblururl];
progress = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
progress.labelText = @"Saving profile picture";
// save thumbnails first so proximity controller will have a valid image
CGSize thumbSize = CGSizeMake(BROWSE_THUMB_SIZE, BROWSE_THUMB_SIZE);
UIImage * newImageThumb = [newImage resizedImage:thumbSize interpolationQuality:kCGInterpolationHigh];
UIImage * newBlurThumb;
if (newBlur.size.width > BROWSE_THUMB_SIZE)
newBlurThumb = [newBlur resizedImage:thumbSize interpolationQuality:kCGInterpolationHigh];
else
newBlurThumb = newBlur;
NSLog(@"blur size: %f %f", newBlur.size.width, newBlur.size.height);
[userInfo saveThumbsToAWSSerial:newImageThumb andBlur:newBlurThumb withBlock:^(BOOL finished) {
NSLog(@"New thumbnails saved!");
}];
[userInfo savePhotoToAWSSerial:newImage andBlur:newBlur withBlock:^(BOOL saved) {
NSLog(@"Saved image at %@!", userInfo.photoURL);
NSLog(@"Saved blur image at %@!", userInfo.photoBlurURL);
[progress hide:YES];
[delegate didApprovePreview];
// prevent old images for this user from showing up
[AsyncImageView clearCacheForURL:userInfo.photoURL];
[AsyncImageView clearCacheForURL:userInfo.photoBlurURL];
[[NSNotificationCenter defaultCenter] postNotificationName:kMyUserInfoDidChangeNotification object:nil];
}];
// todo: solve this problem:
/* subway low connectivity
AmazonServiceException { RequestId:031EF73E53C9E45C, ErrorCode:RequestTimeout, Message:Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed. }
2013-03-18 09:28:21.611 Junction[16888:907] AWSHelper upload Success: 0
*/
}
-(IBAction)didClickCancel:(id)sender {
// do nothing
[self.navigationController popViewControllerAnimated:YES];
}
@end