Ticket #925: ticket#925.diff
| File ticket#925.diff, 8.2 KB (added by irbrad, 21 months ago) |
|---|
-
Classes/BlogsViewController.h
20 20 Blog *currentBlog; 21 21 QuickPhotoButton *quickPhotoButton, *readerButton; 22 22 QuickPhotoUploadProgressController *uploadController; 23 Post *quickPicturePost;24 23 UILabel *uploadLabel; 25 24 IBOutlet UITableView *tableView; 26 25 WPWebViewController *readerViewController; -
Classes/BlogsViewController.m
94 94 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showBlogWithoutAnimation) name:@"NewBlogAdded" object:nil]; 95 95 96 96 //quick photo upload notifications 97 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaDidUploadSuccessfully:) name:ImageUploadSuccessful object:nil];98 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaUploadFailed:) name:ImageUploadFailed object:nil];99 97 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(postDidUploadSuccessfully:) name:@"PostUploaded" object:nil]; 100 98 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(postUploadFailed:) name:@"PostUploadFailed" object:nil]; 101 99 … … 644 642 } 645 643 } 646 644 647 - (void)uploadQuickPhoto:(Post *)post{ 648 649 appDelegate.isUploadingPost = YES; 650 651 quickPicturePost = post; 645 - (void)uploadQuickPhoto:(Post *)post { 652 646 if (post != nil) { 653 647 //remove the quick photo button w/ sexy animation 654 648 CGRect frame = quickPhotoButton.frame; … … 676 670 uploadController.view.frame = CGRectMake(frame.origin.x, self.view.bounds.size.height - 83, frame.size.width, frame.size.height); 677 671 678 672 [UIView commitAnimations]; 679 680 //upload the image681 [[post.media anyObject] performSelector:@selector(upload) withObject:nil];682 673 } 683 674 } 684 675 … … 698 689 [UIView commitAnimations]; 699 690 } 700 691 701 - (void)mediaDidUploadSuccessfully:(NSNotification *)notification {702 703 Media *media = (Media *)[notification object];704 [media save];705 quickPicturePost.content = [NSString stringWithFormat:@"%@\n\n%@", [media html], quickPicturePost.content];706 [quickPicturePost upload];707 }708 709 - (void)mediaUploadFailed:(NSNotification *)notification {710 appDelegate.isUploadingPost = NO;711 [self showQuickPhotoButton: NO];712 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Quick Photo Failed", @"")713 message:NSLocalizedString(@"Sorry, the photo upload failed. The post has been saved as a Local Draft.", @"")714 delegate:self715 cancelButtonTitle:NSLocalizedString(@"OK", @"")716 otherButtonTitles:nil];717 [alert show];718 [alert release];719 }720 721 692 - (void)postDidUploadSuccessfully:(NSNotification *)notification { 722 693 appDelegate.isUploadingPost = NO; 723 694 [UIView beginAnimations:nil context:nil]; … … 755 726 self.currentBlog = nil; 756 727 [quickPhotoButton release]; quickPhotoButton = nil; 757 728 self.tableView = nil; 758 [quickPicturePost release];759 729 [uploadController release]; 760 730 [readerViewController release]; 761 731 [super dealloc]; -
Classes/QuickPhotoViewController.h
12 12 #import "Post.h" 13 13 #import "QuickPicturePreviewView.h" 14 14 #import "BlogsViewController.h" 15 #import "WordPressAppDelegate.h" 15 16 16 17 #define QPVCBlogForQuickPhoto @"blogForQuickPhoto" 17 18 18 19 @interface QuickPhotoViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate,BlogSelectorButtonDelegate,QuickPicturePreviewViewDelegate> { 20 WordPressAppDelegate *appDelegate; 19 21 Post *post; 20 22 BlogsViewController *blogsViewController; 21 23 } -
Classes/Post.h
10 10 #import "Category.h" 11 11 #import "Coordinate.h" 12 12 #import "AbstractPost.h" 13 #import "Media.h" 13 14 14 @interface Post : AbstractPost 15 { 15 @interface Post : AbstractPost { 16 WordPressAppDelegate *appDelegate; 16 17 } 17 18 18 19 #pragma mark - … … 54 55 + (Post *)findWithBlog:(Blog *)blog andPostID:(NSNumber *)postID; 55 56 // Takes the NSDictionary from a XMLRPC call and creates or updates a post 56 57 + (Post *)createOrReplaceFromDictionary:(NSDictionary *)postInfo forBlog:(Blog *)blog; 58 // Set up NSNotificationCenter observers 59 - (void)instantiateNotificationObservers; 57 60 58 61 @end 62 No newline at end of file -
Classes/QuickPhotoViewController.m
71 71 [FileLogger log:@"%@ %@", self, NSStringFromSelector(_cmd)]; 72 72 [super viewDidLoad]; 73 73 74 appDelegate = (WordPressAppDelegate *)[[UIApplication sharedApplication] delegate]; 75 74 76 self.titleTextField.placeholder = NSLocalizedString(@"Title (optional)", @"Quick Photo title"); 75 77 [self.blogSelector loadBlogsForType:BlogSelectorButtonTypeQuickPhoto]; 76 78 self.blogSelector.delegate = self; … … 166 168 #pragma mark Custom methods 167 169 168 170 - (void)postInBackground { 169 171 [[post.media anyObject] performSelector:@selector(upload) withObject:nil]; 172 170 173 [post save]; 171 172 174 } 173 175 174 176 - (void)post { … … 183 185 post.content = contentTextView.text; 184 186 post.specialType = @"QuickPhoto"; 185 187 post.postFormat = @"image"; 186 188 [post instantiateNotificationObservers]; 189 190 appDelegate.isUploadingPost = YES; 191 187 192 [self performSelectorOnMainThread:@selector(postInBackground) withObject:nil waitUntilDone:YES]; 188 193 [self.navigationController popViewControllerAnimated:YES]; 189 194 [blogsViewController uploadQuickPhoto: post]; 190 191 195 } 192 196 193 197 - (void)dismiss { -
Classes/Post.m
22 22 @dynamic categories; 23 23 @synthesize specialType; 24 24 25 - (id)init { 26 if (self = [super init]) { 27 appDelegate = (WordPressAppDelegate *)[[UIApplication sharedApplication] delegate]; 28 } 29 30 return self; 31 } 32 25 33 - (void)dealloc { 26 34 self.specialType = nil; 27 35 [super dealloc]; … … 268 276 return NO; 269 277 } 270 278 279 #pragma mark - QuickPhoto 280 - (void)instantiateNotificationObservers { 281 if ([[self specialType] isEqualToString:@"QuickPhoto"]) { 282 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaDidUploadSuccessfully:) name:ImageUploadSuccessful object:nil]; 283 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaUploadFailed:) name:ImageUploadFailed object:nil]; 284 } 285 } 286 287 - (void)mediaDidUploadSuccessfully:(NSNotification *)notification { 288 Media *media = (Media *)[notification object]; 289 [media save]; 290 291 self.content = [NSString stringWithFormat:@"%@\n\n%@", [media html], self.content]; 292 [self upload]; 293 294 [[NSNotificationCenter defaultCenter] removeObserver:self]; 295 } 296 297 - (void)mediaUploadFailed:(NSNotification *)notification { 298 appDelegate.isUploadingPost = NO; 299 300 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Quick Photo Failed", @"") 301 message:NSLocalizedString(@"Sorry, the photo upload failed. The post has been saved as a Local Draft.", @"") 302 delegate:self 303 cancelButtonTitle:NSLocalizedString(@"OK", @"") 304 otherButtonTitles:nil]; 305 [alert show]; 306 [alert release]; 307 308 [[NSNotificationCenter defaultCenter] removeObserver:self]; 309 } 310 271 311 @end
