-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateProfilePreviewController.m
More file actions
executable file
·139 lines (116 loc) · 5.22 KB
/
CreateProfilePreviewController.m
File metadata and controls
executable file
·139 lines (116 loc) · 5.22 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
//
// CreateProfilePreviewController.m
// Junction
//
// Created by Bobby Ren on 3/13/13.
//
//
#import "CreateProfilePreviewController.h"
#import "AppDelegate.h"
#import "AWSHelper.h"
#import "UIImage+Resize.h"
@interface CreateProfilePreviewController ()
@end
static AppDelegate * appDelegate;
@implementation CreateProfilePreviewController
@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.
[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)didClickPhoto:(id)sender {
self.userInfo.linkedInString = savedLinkedInString;
[self.navigationController popViewControllerAnimated:YES];
}
-(IBAction)didClickSaveProfile:(id)sender {
NSLog(@"Next!");
UIImage * newImage = userInfo.photo;
UIImage * newBlur = userInfo.photoBlur;
self.userInfo.linkedInString = savedLinkedInString;
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 didFinishPreview];
// 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
*/
}
#pragma mark UserProfileDelegate
-(void)didClickClose {
// do nothing
}
@end