Guest User

Untitled

a guest
Sep 30th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(void)selectedAssets:(NSArray*)_assets {
  2.     // leoparro fix - if there's no selected assets go back to rootvc
  3.     if ([_assets count] == 0 && [[[Global sharedInstance] cacheSelectedImgArray] count] == 0) {
  4.         [self popToRootViewControllerAnimated:YES];
  5.         [[self parentViewController] dismissModalViewControllerAnimated:YES];
  6.         return;
  7.     }
  8.     else if ([_assets count] == 0 && [[[Global sharedInstance] cacheSelectedImgArray] count] > 0) {
  9.        
  10.         [self popToRootViewControllerAnimated:NO];
  11.         [[self parentViewController] dismissModalViewControllerAnimated:YES];
  12.        
  13.         if([delegate respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)]) {
  14.             [delegate performSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:) withObject:self withObject:nil];
  15.         }
  16.     }
  17.     else {
  18.              
  19.         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Preparing Photos\nPlease Wait..."
  20.                                                         message:nil
  21.                                                        delegate:self
  22.                                               cancelButtonTitle:nil
  23.                                               otherButtonTitles: nil];
  24.    
  25.         UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  26.    
  27.         // Adjust the indicator so it is up a few pixels from the bottom of the alert
  28.         indicator.center = CGPointMake((alert.bounds.size.width/2) + 140, alert.bounds.size.height + 85);
  29.         [indicator startAnimating];
  30.         [alert addSubview:indicator];
  31.         [indicator release];
  32.  
  33.         [alert performSelectorInBackground:@selector(show) withObject:nil];
  34.        
  35.     NSMutableArray *returnArray = [[NSMutableArray alloc] init];
  36.     if (self.returnArray) {
  37.           [returnArray release];
  38.           self.returnArray = nil;
  39.     }
  40.     self.returnArray = [[NSMutableArray alloc] init];
  41.        
  42.         [_assets enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  43.        
  44.             ALAsset *asset = (ALAsset *)obj;
  45.             NSString *sFilename = [[asset defaultRepresentation] filename];
  46.        
  47.             if (![[Global sharedInstance] checkExistImage:sFilename]) {
  48.            
  49.                 NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
  50.                 [workingDictionary setObject:sFilename forKey:@"filename"];
  51.            
  52. //                ALAssetRepresentation *rep = [asset defaultRepresentation];
  53. //                CGImageRef imgRef = [[asset defaultRepresentation] fullScreenImage];
  54. //                DLog(@"rep: %@", rep);
  55. //                CGImageRef imgRef = [rep fullScreenImage];
  56. //                DLog(@"imgRef: %@", imgRef);
  57.                
  58.                 UIImage *tmpImage = [[UIImage alloc] initWithCGImage:[[asset defaultRepresentation] fullScreenImage]];
  59.                 DLog(@"tmpImage: %@", tmpImage);
  60.                
  61.                 NSData *jpegData = UIImageJPEGRepresentation(tmpImage, 0.5);
  62.                 NSString *sImgFilePath = [[Global sharedInstance] cachedPathForFileName:sFilename];
  63.                 DLog(@"imgPath: %@", sImgFilePath);
  64.            
  65.                 BOOL bWriteSuccess = [jpegData writeToFile:sImgFilePath atomically:YES];
  66.                 if (!bWriteSuccess) {
  67.                     ALog(@"Error writing file - %@", sImgFilePath);
  68.                 }
  69.                 else {
  70.                     [returnArray addObject:sFilename]; // add image filename to array
  71.                 }
  72.            
  73.                 [tmpImage release];
  74.                 [workingDictionary release];
  75.                
  76.                 if (*stop == YES) {
  77.                     DLog(@"true");                    
  78.                 }
  79.             }
  80.             else {
  81.                 DLog(@"Image already exists! Filename: %@", sFilename);
  82.             }
  83.         }];
  84.      
  85.         // save to cached selected images array
  86.         if ([self.returnArray count] > 0) {
  87.             [[[Global sharedInstance] cacheSelectedImgArray] addObjectsFromArray:self.returnArray];
  88.         }
  89.  
  90.         [alert dismissWithClickedButtonIndex:0 animated:YES];
  91.         [alert release];
  92.    
  93.         [self popToRootViewControllerAnimated:NO];
  94.         [[self parentViewController] dismissModalViewControllerAnimated:YES];
  95.    
  96.         if([delegate respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)]) {
  97.             [delegate performSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:) withObject:self withObject:nil];
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment