Ticket #925: ticket#925.diff

File ticket#925.diff, 8.2 KB (added by irbrad, 21 months ago)
  • Classes/BlogsViewController.h

     
    2020    Blog *currentBlog; 
    2121    QuickPhotoButton *quickPhotoButton, *readerButton; 
    2222    QuickPhotoUploadProgressController *uploadController; 
    23     Post *quickPicturePost; 
    2423    UILabel *uploadLabel; 
    2524    IBOutlet UITableView *tableView; 
    2625    WPWebViewController *readerViewController; 
  • Classes/BlogsViewController.m

     
    9494    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showBlogWithoutAnimation) name:@"NewBlogAdded" object:nil]; 
    9595 
    9696    //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]; 
    9997        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(postDidUploadSuccessfully:) name:@"PostUploaded" object:nil]; 
    10098        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(postUploadFailed:) name:@"PostUploadFailed" object:nil]; 
    10199     
     
    644642    } 
    645643} 
    646644 
    647 - (void)uploadQuickPhoto:(Post *)post{ 
    648      
    649     appDelegate.isUploadingPost = YES; 
    650      
    651     quickPicturePost = post; 
     645- (void)uploadQuickPhoto:(Post *)post { 
    652646    if (post != nil) { 
    653647        //remove the quick photo button w/ sexy animation 
    654648        CGRect frame = quickPhotoButton.frame; 
     
    676670        uploadController.view.frame = CGRectMake(frame.origin.x, self.view.bounds.size.height - 83, frame.size.width, frame.size.height); 
    677671         
    678672        [UIView commitAnimations]; 
    679   
    680         //upload the image 
    681         [[post.media anyObject] performSelector:@selector(upload) withObject:nil]; 
    682673    } 
    683674} 
    684675 
     
    698689    [UIView commitAnimations]; 
    699690} 
    700691 
    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:self 
    715                                           cancelButtonTitle:NSLocalizedString(@"OK", @"") 
    716                                           otherButtonTitles:nil]; 
    717     [alert show]; 
    718     [alert release]; 
    719 } 
    720  
    721692- (void)postDidUploadSuccessfully:(NSNotification *)notification { 
    722693    appDelegate.isUploadingPost = NO; 
    723694    [UIView beginAnimations:nil context:nil];  
     
    755726        self.currentBlog = nil; 
    756727    [quickPhotoButton release]; quickPhotoButton = nil; 
    757728    self.tableView = nil; 
    758     [quickPicturePost release]; 
    759729    [uploadController release]; 
    760730    [readerViewController release];  
    761731    [super dealloc]; 
  • Classes/QuickPhotoViewController.h

     
    1212#import "Post.h" 
    1313#import "QuickPicturePreviewView.h" 
    1414#import "BlogsViewController.h" 
     15#import "WordPressAppDelegate.h" 
    1516 
    1617#define QPVCBlogForQuickPhoto @"blogForQuickPhoto" 
    1718 
    1819@interface QuickPhotoViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate,BlogSelectorButtonDelegate,QuickPicturePreviewViewDelegate> { 
     20        WordPressAppDelegate *appDelegate; 
    1921    Post *post; 
    2022    BlogsViewController *blogsViewController; 
    2123} 
  • Classes/Post.h

     
    1010#import "Category.h" 
    1111#import "Coordinate.h" 
    1212#import "AbstractPost.h" 
     13#import "Media.h" 
    1314 
    14 @interface Post :  AbstractPost   
    15 { 
     15@interface Post :  AbstractPost { 
     16    WordPressAppDelegate *appDelegate; 
    1617} 
    1718 
    1819#pragma mark - 
     
    5455+ (Post *)findWithBlog:(Blog *)blog andPostID:(NSNumber *)postID; 
    5556// Takes the NSDictionary from a XMLRPC call and creates or updates a post 
    5657+ (Post *)createOrReplaceFromDictionary:(NSDictionary *)postInfo forBlog:(Blog *)blog; 
     58// Set up NSNotificationCenter observers 
     59- (void)instantiateNotificationObservers; 
    5760 
    5861@end 
     62 No newline at end of file 
  • Classes/QuickPhotoViewController.m

     
    7171    [FileLogger log:@"%@ %@", self, NSStringFromSelector(_cmd)]; 
    7272    [super viewDidLoad]; 
    7373     
     74    appDelegate = (WordPressAppDelegate *)[[UIApplication sharedApplication] delegate]; 
     75     
    7476    self.titleTextField.placeholder = NSLocalizedString(@"Title (optional)", @"Quick Photo title"); 
    7577    [self.blogSelector loadBlogsForType:BlogSelectorButtonTypeQuickPhoto]; 
    7678    self.blogSelector.delegate = self; 
     
    166168#pragma mark Custom methods 
    167169 
    168170- (void)postInBackground { 
    169  
     171    [[post.media anyObject] performSelector:@selector(upload) withObject:nil]; 
     172     
    170173    [post save]; 
    171  
    172174} 
    173175 
    174176- (void)post { 
     
    183185    post.content = contentTextView.text; 
    184186    post.specialType = @"QuickPhoto"; 
    185187    post.postFormat = @"image"; 
    186  
     188    [post instantiateNotificationObservers]; 
     189     
     190    appDelegate.isUploadingPost = YES; 
     191     
    187192    [self performSelectorOnMainThread:@selector(postInBackground) withObject:nil waitUntilDone:YES]; 
    188193    [self.navigationController popViewControllerAnimated:YES]; 
    189194    [blogsViewController uploadQuickPhoto: post]; 
    190      
    191195} 
    192196 
    193197- (void)dismiss { 
  • Classes/Post.m

     
    2222@dynamic categories; 
    2323@synthesize specialType; 
    2424 
     25- (id)init { 
     26    if (self = [super init]) { 
     27        appDelegate = (WordPressAppDelegate *)[[UIApplication sharedApplication] delegate]; 
     28    } 
     29     
     30    return self; 
     31} 
     32 
    2533- (void)dealloc { 
    2634    self.specialType = nil; 
    2735    [super dealloc]; 
     
    268276    return NO; 
    269277} 
    270278 
     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 
    271311@end