diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3efd30 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# Created by http://www.gitignore.io + +### Xcode ### +build +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcworkspace/contents.xcworkspacedata + + +### Objective-C ### +# OS X +.DS_Store + +# Xcode +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +profile +*.moved-aside +DerivedData +*.hmap +*.ipa + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control? +# +Pods/ + +# Custom +Headers/ +StaticLib/ diff --git a/AGImagePickerController Demo.xcodeproj/project.pbxproj b/AGImagePickerController Demo.xcodeproj/project.pbxproj index 9cf6c7d..5be8725 100644 --- a/AGImagePickerController Demo.xcodeproj/project.pbxproj +++ b/AGImagePickerController Demo.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 54A1E5551882A31E00D556FD /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 54A1E5541882A31E00D556FD /* CoreLocation.framework */; }; + C1F27BD91946A34000614393 /* AGImagePickerController.bundle in Resources */ = {isa = PBXBuildFile; fileRef = C1F27BD81946A34000614393 /* AGImagePickerController.bundle */; }; FE1E332914ED167800F6A6A2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FE1E332814ED167800F6A6A2 /* UIKit.framework */; }; FE1E332B14ED167800F6A6A2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FE1E332A14ED167800F6A6A2 /* Foundation.framework */; }; FE1E333314ED167800F6A6A2 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = FE1E333114ED167800F6A6A2 /* InfoPlist.strings */; }; @@ -27,7 +28,6 @@ FECDC90114EDB9C30038006D /* AGIPCGridCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FECDC90014EDB9C30038006D /* AGIPCGridCell.m */; }; FECDC90514EDBB690038006D /* AGIPCGridItem.m in Sources */ = {isa = PBXBuildFile; fileRef = FECDC90414EDBB690038006D /* AGIPCGridItem.m */; }; FEDAA95516C2F3D600234FF0 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FEA599E114ED30140057FF9C /* AssetsLibrary.framework */; }; - FEDAA95716C3089600234FF0 /* AGImagePickerController.bundle in Resources */ = {isa = PBXBuildFile; fileRef = FEDAA95616C3089600234FF0 /* AGImagePickerController.bundle */; }; FEE0F35D16C509EF001A077B /* AGImagePickerController.podspec in Resources */ = {isa = PBXBuildFile; fileRef = FEE0F35C16C509EF001A077B /* AGImagePickerController.podspec */; }; FEF247F2150DF461008FEFAD /* AGImagePickerController-icon.png in Resources */ = {isa = PBXBuildFile; fileRef = FEF247F1150DF461008FEFAD /* AGImagePickerController-icon.png */; }; FEF247F5150DF463008FEFAD /* AGImagePickerController-icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FEF247F4150DF463008FEFAD /* AGImagePickerController-icon@2x.png */; }; @@ -35,6 +35,7 @@ /* Begin PBXFileReference section */ 54A1E5541882A31E00D556FD /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; + C1F27BD81946A34000614393 /* AGImagePickerController.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = AGImagePickerController.bundle; sourceTree = ""; }; FE1E332414ED167800F6A6A2 /* AGImagePickerController Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "AGImagePickerController Demo.app"; sourceTree = BUILT_PRODUCTS_DIR; }; FE1E332814ED167800F6A6A2 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; FE1E332A14ED167800F6A6A2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -69,7 +70,6 @@ FECDC90014EDB9C30038006D /* AGIPCGridCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AGIPCGridCell.m; sourceTree = ""; }; FECDC90314EDBB690038006D /* AGIPCGridItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AGIPCGridItem.h; sourceTree = ""; }; FECDC90414EDBB690038006D /* AGIPCGridItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AGIPCGridItem.m; sourceTree = ""; }; - FEDAA95616C3089600234FF0 /* AGImagePickerController.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = AGImagePickerController.bundle; sourceTree = ""; }; FEE0F35C16C509EF001A077B /* AGImagePickerController.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AGImagePickerController.podspec; sourceTree = ""; }; FEF247F1150DF461008FEFAD /* AGImagePickerController-icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "AGImagePickerController-icon.png"; path = "../AGImagePickerController-icon.png"; sourceTree = ""; }; FEF247F4150DF463008FEFAD /* AGImagePickerController-icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "AGImagePickerController-icon@2x.png"; path = "../AGImagePickerController-icon@2x.png"; sourceTree = ""; }; @@ -155,7 +155,7 @@ children = ( FE4DE10216C267400075E499 /* AGImagePickerController+Helper.h */, FE4DE10316C267410075E499 /* AGImagePickerController+Helper.m */, - FEDAA95616C3089600234FF0 /* AGImagePickerController.bundle */, + C1F27BD81946A34000614393 /* AGImagePickerController.bundle */, FEA599C914ED1C500057FF9C /* AGImagePickerController.h */, FEA599CA14ED1C500057FF9C /* AGImagePickerController.m */, FE6E796014FCDC8A006612F0 /* AGImagePickerControllerDefines.h */, @@ -230,10 +230,10 @@ FE1E333F14ED167800F6A6A2 /* AGViewController_iPhone.xib in Resources */, FE1E334214ED167800F6A6A2 /* AGViewController_iPad.xib in Resources */, FE3850CB1501B8A10053C9DD /* README.md in Resources */, + C1F27BD91946A34000614393 /* AGImagePickerController.bundle in Resources */, FEF247F2150DF461008FEFAD /* AGImagePickerController-icon.png in Resources */, FEF247F5150DF463008FEFAD /* AGImagePickerController-icon@2x.png in Resources */, FE4DE10116C2546B0075E499 /* Default-568h@2x.png in Resources */, - FEDAA95716C3089600234FF0 /* AGImagePickerController.bundle in Resources */, FEE0F35D16C509EF001A077B /* AGImagePickerController.podspec in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -350,13 +350,15 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "AGImagePickerController Demo/AGImagePickerController Demo-Prefix.pch"; INFOPLIST_FILE = "AGImagePickerController Demo/AGImagePickerController Demo-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 4.3; PRODUCT_NAME = "$(TARGET_NAME)"; - "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; + PROVISIONING_PROFILE = "6C433C2D-C147-40FD-B0BC-8B865CBC8444"; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = "6C433C2D-C147-40FD-B0BC-8B865CBC8444"; WRAPPER_EXTENSION = app; }; name = Debug; @@ -365,12 +367,14 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "AGImagePickerController Demo/AGImagePickerController Demo-Prefix.pch"; INFOPLIST_FILE = "AGImagePickerController Demo/AGImagePickerController Demo-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 4.3; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = "6C433C2D-C147-40FD-B0BC-8B865CBC8444"; WRAPPER_EXTENSION = app; }; name = Release; diff --git a/AGImagePickerController Demo.xcodeproj/project.xcworkspace/xcshareddata/AGImagePickerController Demo.xccheckout b/AGImagePickerController Demo.xcodeproj/project.xcworkspace/xcshareddata/AGImagePickerController Demo.xccheckout new file mode 100644 index 0000000..18dff82 --- /dev/null +++ b/AGImagePickerController Demo.xcodeproj/project.xcworkspace/xcshareddata/AGImagePickerController Demo.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 78F5169C-438B-4683-911B-0A793A9CE480 + IDESourceControlProjectName + AGImagePickerController Demo + IDESourceControlProjectOriginsDictionary + + 4EB08CCB-4EE8-46E7-9CA7-663BC809B225 + ssh://github.com/Xummer/AGImagePickerController.git + + IDESourceControlProjectPath + AGImagePickerController Demo.xcodeproj/project.xcworkspace + IDESourceControlProjectRelativeInstallPathDictionary + + 4EB08CCB-4EE8-46E7-9CA7-663BC809B225 + ../.. + + IDESourceControlProjectURL + ssh://github.com/Xummer/AGImagePickerController.git + IDESourceControlProjectVersion + 110 + IDESourceControlProjectWCCIdentifier + 4EB08CCB-4EE8-46E7-9CA7-663BC809B225 + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + 4EB08CCB-4EE8-46E7-9CA7-663BC809B225 + IDESourceControlWCCName + AGImagePickerController + + + + diff --git a/AGImagePickerController Demo.xcodeproj/xcuserdata/xummer.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/AGImagePickerController Demo.xcodeproj/xcuserdata/xummer.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/AGImagePickerController Demo.xcodeproj/xcuserdata/xummer.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/AGImagePickerController Demo.xcodeproj/xcuserdata/xummer.xcuserdatad/xcschemes/AGImagePickerController Demo.xcscheme b/AGImagePickerController Demo.xcodeproj/xcuserdata/xummer.xcuserdatad/xcschemes/AGImagePickerController Demo.xcscheme new file mode 100644 index 0000000..3011610 --- /dev/null +++ b/AGImagePickerController Demo.xcodeproj/xcuserdata/xummer.xcuserdatad/xcschemes/AGImagePickerController Demo.xcscheme @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AGImagePickerController Demo.xcodeproj/xcuserdata/xummer.xcuserdatad/xcschemes/xcschememanagement.plist b/AGImagePickerController Demo.xcodeproj/xcuserdata/xummer.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..f777f29 --- /dev/null +++ b/AGImagePickerController Demo.xcodeproj/xcuserdata/xummer.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + AGImagePickerController Demo.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + FE1E332314ED167800F6A6A2 + + primary + + + + + diff --git a/AGImagePickerController Demo/AGViewController.m b/AGImagePickerController Demo/AGViewController.m index 66314e8..5ccd7ab 100644 --- a/AGImagePickerController Demo/AGViewController.m +++ b/AGImagePickerController Demo/AGViewController.m @@ -32,41 +32,8 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil if (self) { self.selectedPhotos = [NSMutableArray array]; - - __block AGViewController *blockSelf = self; - - ipc = [[AGImagePickerController alloc] initWithDelegate:self]; - ipc.didFailBlock = ^(NSError *error) { - NSLog(@"Fail. Error: %@", error); - - if (error == nil) { - [blockSelf.selectedPhotos removeAllObjects]; - NSLog(@"User has cancelled."); - - [blockSelf dismissModalViewControllerAnimated:YES]; - } else { - - // We need to wait for the view controller to appear first. - double delayInSeconds = 0.5; - dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); - dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ - [blockSelf dismissModalViewControllerAnimated:YES]; - }); - } - - [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; - - }; - ipc.didFinishBlock = ^(NSArray *info) { - [blockSelf.selectedPhotos setArray:info]; - - NSLog(@"Info: %@", info); - [blockSelf dismissModalViewControllerAnimated:YES]; - - [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; - }; + } - return self; } @@ -104,29 +71,54 @@ - (NSUInteger)supportedInterfaceOrientations #pragma mark - Public methods - (void)openAction:(id)sender -{ +{ + + __block AGViewController *blockSelf = self; + + ipc = [[AGImagePickerController alloc] initWithDelegate:self]; + // modified by springox(20140503) + // ipc = [AGImagePickerController sharedInstance:self]; + + ipc.didFailBlock = ^(NSError *error) { + NSLog(@"Fail. Error: %@", error); + + if (error == nil) { + [blockSelf.selectedPhotos removeAllObjects]; + NSLog(@"User has cancelled."); + + [blockSelf dismissModalViewControllerAnimated:YES]; + } else { + + // We need to wait for the view controller to appear first. + double delayInSeconds = 0.5; + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); + dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ + [blockSelf dismissModalViewControllerAnimated:YES]; + }); + } + + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; + + }; + ipc.didFinishBlock = ^(NSArray *info) { + [blockSelf.selectedPhotos setArray:info]; + + NSLog(@"Info: %@", info); + [blockSelf dismissModalViewControllerAnimated:YES]; + + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; + }; + // Show saved photos on top - ipc.shouldShowSavedPhotosOnTop = NO; - ipc.shouldChangeStatusBarStyle = YES; + ipc.shouldShowSavedPhotosOnTop = YES; + ipc.shouldChangeStatusBarStyle = NO; ipc.selection = self.selectedPhotos; -// ipc.maximumNumberOfPhotosToBeSelected = 10; - - // Custom toolbar items - AGIPCToolbarItem *selectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"+ Select All" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) { - return YES; - }]; - AGIPCToolbarItem *flexible = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] andSelectionBlock:nil]; - AGIPCToolbarItem *selectOdd = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"+ Select Odd" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) { - return !(index % 2); - }]; - AGIPCToolbarItem *deselectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"- Deselect All" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) { - return NO; - }]; - ipc.toolbarItemsForManagingTheSelection = @[selectAll, flexible, selectOdd, flexible, deselectAll]; -// imagePickerController.toolbarItemsForManagingTheSelection = [NSArray array]; + ipc.maximumNumberOfPhotosToBeSelected = 3; -// imagePickerController.maximumNumberOfPhotos = 3; [self presentModalViewController:ipc animated:YES]; + + // modified by springox(20140503) + [ipc showFirstAssetsController]; } #pragma mark - AGImagePickerControllerDelegate methods @@ -151,12 +143,12 @@ - (NSUInteger)agImagePickerController:(AGImagePickerController *)picker - (BOOL)agImagePickerController:(AGImagePickerController *)picker shouldDisplaySelectionInformationInSelectionMode:(AGImagePickerControllerSelectionMode)selectionMode { - return (selectionMode == AGImagePickerControllerSelectionModeSingle ? NO : YES); + return NO;//(selectionMode == AGImagePickerControllerSelectionModeSingle ? NO : YES); } - (BOOL)agImagePickerController:(AGImagePickerController *)picker shouldShowToolbarForManagingTheSelectionInSelectionMode:(AGImagePickerControllerSelectionMode)selectionMode { - return (selectionMode == AGImagePickerControllerSelectionModeSingle ? NO : YES); + return NO;//(selectionMode == AGImagePickerControllerSelectionModeSingle ? NO : YES); } - (AGImagePickerControllerSelectionBehaviorType)selectionBehaviorInSingleSelectionModeForAGImagePickerController:(AGImagePickerController *)picker diff --git a/AGImagePickerController/AGIPCAlbumsController.h b/AGImagePickerController/AGIPCAlbumsController.h index 683f949..37358bf 100644 --- a/AGImagePickerController/AGIPCAlbumsController.h +++ b/AGImagePickerController/AGIPCAlbumsController.h @@ -16,8 +16,11 @@ @interface AGIPCAlbumsController : UITableViewController -@property (strong) AGImagePickerController *imagePickerController; +@property (ag_weak, nonatomic, readonly) NSMutableArray *assetsGroups; +@property (ag_weak) AGImagePickerController *imagePickerController; - (id)initWithImagePickerController:(AGImagePickerController *)imagePickerController; +- (void)pushFirstAssetsController; + @end diff --git a/AGImagePickerController/AGIPCAlbumsController.m b/AGImagePickerController/AGIPCAlbumsController.m index b16a88a..423fd2a 100644 --- a/AGImagePickerController/AGIPCAlbumsController.m +++ b/AGImagePickerController/AGIPCAlbumsController.m @@ -17,11 +17,10 @@ @interface AGIPCAlbumsController () { NSMutableArray *_assetsGroups; - AGImagePickerController *_imagePickerController; + __ag_weak AGImagePickerController *_imagePickerController; + NSUInteger _pushTryCount; } -@property (ag_weak, nonatomic, readonly) NSMutableArray *assetsGroups; - @end @interface AGIPCAlbumsController () @@ -31,7 +30,6 @@ - (void)unregisterFromNotifications; - (void)didChangeLibrary:(NSNotification *)notification; -- (void)loadAssetsGroups; - (void)reloadData; - (void)cancelAction:(id)sender; @@ -49,7 +47,6 @@ - (NSMutableArray *)assetsGroups if (_assetsGroups == nil) { _assetsGroups = [[NSMutableArray alloc] init]; - [self loadAssetsGroups]; } return _assetsGroups; @@ -63,6 +60,10 @@ - (id)initWithImagePickerController:(AGImagePickerController *)imagePickerContro if (self) { self.imagePickerController = imagePickerController; + + [self assetsGroups]; + + [self loadAssetsGroups]; } return self; @@ -94,6 +95,8 @@ - (void)viewDidLoad self.wantsFullScreenLayout = YES; } + self.title = NSLocalizedStringWithDefaultValue(@"AGIPC.Albums", nil, [NSBundle mainBundle], @"Albums", nil); + // Setup Notifications [self registerForNotifications]; @@ -110,6 +113,11 @@ - (void)viewDidUnload [self unregisterFromNotifications]; } +- (void)dealloc { + // Destroy Notifications + [self unregisterFromNotifications]; +} + - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; @@ -120,6 +128,23 @@ - (NSUInteger)supportedInterfaceOrientations return UIInterfaceOrientationMaskAll; } +- (void)pushFirstAssetsController +{ + [self.navigationController popToRootViewControllerAnimated:NO]; + + @synchronized(self) { + if (0 < self.assetsGroups.count) { + AGIPCAssetsController *controller = [[AGIPCAssetsController alloc] initWithImagePickerController:self.imagePickerController andAssetsGroup:self.assetsGroups[0]]; + [self.navigationController pushViewController:controller animated:NO]; + } else { + if (_pushTryCount < 3) { + [self performSelector:@selector(pushFirstAssetsController) withObject:nil afterDelay:0.8]; + ++_pushTryCount; + } + } + } +} + #pragma mark - UITableViewDataSource Methods - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section @@ -145,7 +170,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", numberOfAssets]; [cell.imageView setImage:[UIImage imageWithCGImage:[(ALAssetsGroup *)self.assetsGroups[indexPath.row] posterImage]]]; [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; - + return cell; } @@ -178,21 +203,48 @@ - (void)loadAssetsGroups void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) { - if (group == nil) + // filter the value==0, springox(20140502) + if (group == nil || group.numberOfAssets == 0) { return; } - if (weakSelf.imagePickerController.shouldShowSavedPhotosOnTop) { - if ([[group valueForProperty:ALAssetsGroupPropertyType] intValue] == ALAssetsGroupSavedPhotos) { + /* + if (weakSelf.imagePickerController.shouldShowSavedPhotosOnTop) { + if ([[group valueForProperty:ALAssetsGroupPropertyType] intValue] == ALAssetsGroupSavedPhotos) { + [self.assetsGroups insertObject:group atIndex:0]; + } else if ([[group valueForProperty:ALAssetsGroupPropertyType] intValue] > ALAssetsGroupSavedPhotos) { + [self.assetsGroups insertObject:group atIndex:1]; + } else { + [self.assetsGroups addObject:group]; + } + } else { + [self.assetsGroups addObject:group]; + } + */ + + @synchronized(weakSelf) { + // optimize the sort algorithm by springox(20140327) + int groupType = [[group valueForProperty:ALAssetsGroupPropertyType] intValue]; + if (weakSelf.imagePickerController.shouldShowSavedPhotosOnTop && groupType == ALAssetsGroupSavedPhotos) { [self.assetsGroups insertObject:group atIndex:0]; - } else if ([[group valueForProperty:ALAssetsGroupPropertyType] intValue] > ALAssetsGroupSavedPhotos) { - [self.assetsGroups insertObject:group atIndex:1]; } else { - [self.assetsGroups addObject:group]; + NSUInteger index = 0; + for (ALAssetsGroup *g in [NSArray arrayWithArray:self.assetsGroups]) { + if (weakSelf.imagePickerController.shouldShowSavedPhotosOnTop && [[g valueForProperty:ALAssetsGroupPropertyType] intValue] == ALAssetsGroupSavedPhotos) { + index++; + continue; + } + if (groupType > [[g valueForProperty:ALAssetsGroupPropertyType] intValue]) { + [self.assetsGroups insertObject:group atIndex:index]; + break; + } + index++; + } + if (![self.assetsGroups containsObject:group]) { + [self.assetsGroups addObject:group]; + } } - } else { - [self.assetsGroups addObject:group]; } dispatch_async(dispatch_get_main_queue(), ^{ @@ -217,7 +269,6 @@ - (void)loadAssetsGroups - (void)reloadData { [self.tableView reloadData]; - self.title = NSLocalizedStringWithDefaultValue(@"AGIPC.Albums", nil, [NSBundle mainBundle], @"Albums", nil); } - (void)cancelAction:(id)sender diff --git a/AGImagePickerController/AGIPCAssetsController.h b/AGImagePickerController/AGIPCAssetsController.h index a10129e..20bf18b 100644 --- a/AGImagePickerController/AGIPCAssetsController.h +++ b/AGImagePickerController/AGIPCAssetsController.h @@ -20,7 +20,7 @@ @property (strong) ALAssetsGroup *assetsGroup; @property (ag_weak, readonly) NSArray *selectedAssets; -@property (strong) AGImagePickerController *imagePickerController; +@property (ag_weak) AGImagePickerController *imagePickerController; - (id)initWithImagePickerController:(AGImagePickerController *)imagePickerController andAssetsGroup:(ALAssetsGroup *)assetsGroup; diff --git a/AGImagePickerController/AGIPCAssetsController.m b/AGImagePickerController/AGIPCAssetsController.m index 5e74154..d43ae6d 100644 --- a/AGImagePickerController/AGIPCAssetsController.m +++ b/AGImagePickerController/AGIPCAssetsController.m @@ -20,7 +20,7 @@ @interface AGIPCAssetsController () { ALAssetsGroup *_assetsGroup; NSMutableArray *_assets; - AGImagePickerController *_imagePickerController; + __ag_weak AGImagePickerController *_imagePickerController; } @property (nonatomic, strong) NSMutableArray *assets; @@ -82,7 +82,8 @@ - (void)setAssetsGroup:(ALAssetsGroup *)theAssetsGroup _assetsGroup = theAssetsGroup; [_assetsGroup setAssetsFilter:[ALAssetsFilter allPhotos]]; - [self reloadData]; + // modified by springox(20140510) + //[self reloadData]; } } } @@ -140,7 +141,7 @@ - (id)initWithImagePickerController:(AGImagePickerController *)imagePickerContro [self setupToolbarItems]; // Start loading the assets - [self loadAssets]; + [self performSelectorInBackground:@selector(loadAssets) withObject:nil]; } return self; @@ -169,10 +170,11 @@ - (NSArray *)itemsForRowAtIndexPath:(NSIndexPath *)indexPath NSUInteger startIndex = indexPath.row * self.imagePickerController.numberOfItemsPerRow, endIndex = startIndex + self.imagePickerController.numberOfItemsPerRow - 1; - if (startIndex < self.assets.count) + NSInteger assetsCount = [self.assets count]; + if (startIndex < assetsCount) { - if (endIndex > self.assets.count - 1) - endIndex = self.assets.count - 1; + if (endIndex > assetsCount - 1) + endIndex = assetsCount - 1; for (NSUInteger i = startIndex; i <= endIndex; i++) { @@ -183,6 +185,24 @@ - (NSArray *)itemsForRowAtIndexPath:(NSIndexPath *)indexPath return items; } +- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section +{ + return self.imagePickerController.itemRect.origin.y; +} + +- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section +{ + UIView *view = [[UIView alloc] init]; + view.backgroundColor = [UIColor whiteColor]; + return view; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + CGRect itemRect = self.imagePickerController.itemRect; + return itemRect.size.height + itemRect.origin.y; +} + - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; @@ -200,12 +220,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N return cell; } -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - CGRect itemRect = self.imagePickerController.itemRect; - return itemRect.size.height + itemRect.origin.y; -} - #pragma mark - View Lifecycle - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation @@ -237,6 +251,9 @@ - (void)viewDidLoad self.wantsFullScreenLayout = YES; } + // modified by springox(20140510) + [self reloadData]; + // Setup Notifications [self registerForNotifications]; } @@ -315,17 +332,14 @@ - (void)loadAssets } */ - //[strongSelf.assets addObject:gridItem]; // Descending photos, springox(20131225) - [strongSelf.assets insertObject:gridItem atIndex:0]; - + [strongSelf.assets addObject:gridItem]; + //[strongSelf.assets insertObject:gridItem atIndex:0]; }]; } dispatch_async(dispatch_get_main_queue(), ^{ - [strongSelf reloadData]; - }); }); @@ -341,13 +355,15 @@ - (void)reloadData //[self setTitle:[self.assetsGroup valueForProperty:ALAssetsGroupPropertyName]]; [self changeSelectionInformation]; - /* - NSInteger totalRows = [self.tableView numberOfRowsInSection:0]; - //Prevents crash if totalRows = 0 (when the album is empty). - if (totalRows > 0) { - [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:totalRows-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO]; + NSInteger section = [self numberOfSectionsInTableView:self.tableView] - 1; + NSInteger row = [self tableView:self.tableView numberOfRowsInSection:section] - 1; + if (section >= 0 && row >= 0) { + NSIndexPath *ip = [NSIndexPath indexPathForRow:row + inSection:section]; + [self.tableView scrollToRowAtIndexPath:ip + atScrollPosition:UITableViewScrollPositionBottom + animated:NO]; } - */ } - (void)doneAction:(id)sender diff --git a/AGImagePickerController/AGIPCGridCell.h b/AGImagePickerController/AGIPCGridCell.h index 879e99f..bd611c4 100644 --- a/AGImagePickerController/AGIPCGridCell.h +++ b/AGImagePickerController/AGIPCGridCell.h @@ -16,7 +16,8 @@ @interface AGIPCGridCell : UITableViewCell @property (strong) NSArray *items; -@property (strong) AGImagePickerController *imagePickerController; + +@property (ag_weak) AGImagePickerController *imagePickerController; - (id)initWithImagePickerController:(AGImagePickerController *)imagePickerController items:(NSArray *)items andReuseIdentifier:(NSString *)identifier; diff --git a/AGImagePickerController/AGIPCGridCell.m b/AGImagePickerController/AGIPCGridCell.m index 540523d..ef359b1 100644 --- a/AGImagePickerController/AGIPCGridCell.m +++ b/AGImagePickerController/AGIPCGridCell.m @@ -18,7 +18,7 @@ @interface AGIPCGridCell () { NSArray *_items; - AGImagePickerController *_imagePickerController; + __ag_weak AGImagePickerController *_imagePickerController; } @end @@ -37,14 +37,11 @@ - (void)setItems:(NSArray *)items { _items = items; - for (UIView *view in [self.contentView subviews]) - { - [view removeFromSuperview]; - } - + [[self.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; + for (AGIPCGridItem *gridItem in _items) { - [self addSubview:gridItem]; + [self.contentView addSubview:gridItem]; } } } @@ -98,6 +95,10 @@ - (void)layoutSubviews frame.origin.x = frame.origin.x + frame.size.width + leftMargin; } + + CGRect rect = self.contentView.frame; + rect.size.height = frame.origin.x + frame.size.height; + self.contentView.frame = rect; } @end diff --git a/AGImagePickerController/AGIPCGridItem.h b/AGImagePickerController/AGIPCGridItem.h index ac609ce..783a35d 100644 --- a/AGImagePickerController/AGIPCGridItem.h +++ b/AGImagePickerController/AGIPCGridItem.h @@ -32,10 +32,9 @@ @property (assign) BOOL selected; @property (strong) ALAsset *asset; - @property (nonatomic, ag_weak) id delegate; -@property (strong) AGImagePickerController *imagePickerController; +@property (ag_weak) AGImagePickerController *imagePickerController; - (id)initWithImagePickerController:(AGImagePickerController *)imagePickerController andAsset:(ALAsset *)asset; - (id)initWithImagePickerController:(AGImagePickerController *)imagePickerController asset:(ALAsset *)asset andDelegate:(id)delegate; diff --git a/AGImagePickerController/AGIPCGridItem.m b/AGImagePickerController/AGIPCGridItem.m index 5ef441d..d1425f6 100644 --- a/AGImagePickerController/AGIPCGridItem.m +++ b/AGImagePickerController/AGIPCGridItem.m @@ -16,7 +16,7 @@ @interface AGIPCGridItem () { - AGImagePickerController *_imagePickerController; + __ag_weak AGImagePickerController *_imagePickerController; ALAsset *_asset; id __ag_weak _delegate; diff --git a/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPad.png b/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPad.png index 49c9a52..e4f4dc9 100644 Binary files a/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPad.png and b/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPad.png differ diff --git a/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPhone.png b/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPhone.png index 28ba9c8..e4f4dc9 100644 Binary files a/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPhone.png and b/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPhone.png differ diff --git a/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPhone@2x.png b/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPhone@2x.png index 84c1228..cba50ed 100644 Binary files a/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPhone@2x.png and b/AGImagePickerController/AGImagePickerController.bundle/AGIPC-Checkmark-iPhone@2x.png differ diff --git a/AGImagePickerController/AGImagePickerController.h b/AGImagePickerController/AGImagePickerController.h index 3dad647..92e87d0 100644 --- a/AGImagePickerController/AGImagePickerController.h +++ b/AGImagePickerController/AGImagePickerController.h @@ -81,8 +81,12 @@ shouldShowToolbarForManagingTheSelectionInSelectionMode:(AGImagePickerController @property (nonatomic, readonly) AGImagePickerControllerSelectionMode selectionMode; +@property (nonatomic, assign) BOOL userIsDenied; + + (ALAssetsLibrary *)defaultAssetsLibrary; ++ (AGImagePickerController *)sharedInstance:(id)delegate; + - (id)initWithDelegate:(id)delegate; - (id)initWithFailureBlock:(AGIPCDidFail)failureBlock andSuccessBlock:(AGIPCDidFinish)successBlock; @@ -94,6 +98,8 @@ shouldChangeStatusBarStyle:(BOOL)shouldChangeStatusBarStyle toolbarItemsForManagingTheSelection:(NSArray *)toolbarItemsForManagingTheSelection andShouldShowSavedPhotosOnTop:(BOOL)shouldShowSavedPhotosOnTop; +- (void)showFirstAssetsController; + @end diff --git a/AGImagePickerController/AGImagePickerController.m b/AGImagePickerController/AGImagePickerController.m index cec8103..d2f3b56 100644 --- a/AGImagePickerController/AGImagePickerController.m +++ b/AGImagePickerController/AGImagePickerController.m @@ -14,6 +14,8 @@ #import "AGIPCAlbumsController.h" #import "AGIPCGridItem.h" +static AGImagePickerController *_sharedInstance = nil; + @interface AGImagePickerController () { @@ -27,6 +29,46 @@ - (void)didFail:(NSError *)error; @implementation AGImagePickerController ++ (ALAssetsLibrary *)defaultAssetsLibrary +{ + static ALAssetsLibrary *assetsLibrary = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + assetsLibrary = [[ALAssetsLibrary alloc] init]; + + // Workaround for triggering ALAssetsLibraryChangedNotification + [assetsLibrary writeImageToSavedPhotosAlbum:nil metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) { }]; + }); + + return assetsLibrary; +} + ++ (AGImagePickerController *)sharedInstance:(id)delegate +{ + if (nil == _sharedInstance){ + @synchronized(self) { + if (nil == _sharedInstance){ + _sharedInstance = [AGImagePickerController imagePickerWithDelegate:nil]; + } + } + } + _sharedInstance.delegate = delegate; + return _sharedInstance; +} + ++ (AGImagePickerController *)imagePickerWithDelegate:(id)delegate +{ + AGImagePickerController *picker = [[AGImagePickerController alloc] initWithDelegate:delegate]; + + // Show saved photos on top + picker.shouldShowSavedPhotosOnTop = YES; + picker.shouldChangeStatusBarStyle = YES; + picker.maximumNumberOfPhotosToBeSelected = 5; + picker.toolbarItemsForManagingTheSelection = @[]; + + return picker; +} + #pragma mark - Properties @synthesize @@ -76,20 +118,6 @@ - (void)setShouldChangeStatusBarStyle:(BOOL)shouldChangeStatusBarStyle } } -+ (ALAssetsLibrary *)defaultAssetsLibrary -{ - static ALAssetsLibrary *assetsLibrary = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - assetsLibrary = [[ALAssetsLibrary alloc] init]; - - // Workaround for triggering ALAssetsLibraryChangedNotification - [assetsLibrary writeImageToSavedPhotosAlbum:nil metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) { }]; - }); - - return assetsLibrary; -} - #pragma mark - Object Lifecycle - (id)init @@ -139,8 +167,16 @@ - (id)initWithDelegate:(id)delegate barStyle = UIBarStyleDefault; } self.navigationBar.barStyle = barStyle; + /* + self.navigationBar.barStyle = UIBarStyleBlack; self.navigationBar.translucent = YES; self.toolbar.barStyle = barStyle; + self.toolbar.translucent = YES; + */ + // change the bar style for ios7, springox(20131225) + self.navigationBar.barStyle = UIBarStyleDefault; + self.navigationBar.translucent = YES; + self.toolbar.barStyle = UIBarStyleDefault; self.toolbar.translucent = YES; self.toolbarItemsForManagingTheSelection = toolbarItemsForManagingTheSelection; @@ -156,6 +192,14 @@ - (id)initWithDelegate:(id)delegate return self; } +- (void)showFirstAssetsController +{ + AGIPCAlbumsController *albumsCtl = (AGIPCAlbumsController *)[self.viewControllers firstObject]; + if ([albumsCtl respondsToSelector:@selector(pushFirstAssetsController)]) { + [albumsCtl pushFirstAssetsController]; + } +} + #pragma mark - View lifecycle - (NSUInteger)supportedInterfaceOrientations @@ -167,7 +211,9 @@ - (NSUInteger)supportedInterfaceOrientations - (void)didFinishPickingAssets:(NSArray *)selectedAssets { - [self popToRootViewControllerAnimated:NO]; + //[self popToRootViewControllerAnimated:NO]; + + self.userIsDenied = NO; // Reset the number of selections [AGIPCGridItem performSelector:@selector(resetNumberOfSelections)]; @@ -183,7 +229,7 @@ - (void)didFinishPickingAssets:(NSArray *)selectedAssets - (void)didCancelPickingAssets { - [self popToRootViewControllerAnimated:NO]; + //[self popToRootViewControllerAnimated:NO]; // Reset the number of selections [AGIPCGridItem performSelector:@selector(resetNumberOfSelections)]; @@ -199,6 +245,10 @@ - (void)didCancelPickingAssets - (void)didFail:(NSError *)error { + if (nil != error) { + self.userIsDenied = YES; + } + [self popToRootViewControllerAnimated:NO]; // Reset the number of selections