Skip to content

Commit

Permalink
Merge pull request arturgrigor#1 from MSchmidt/master
Browse files Browse the repository at this point in the history
Add option to show saved photos (camera roll, photo stream) on top of list
  • Loading branch information
arturgrigor committed Apr 24, 2012
2 parents 11eb92f + 340ba06 commit 99aca00
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions AGImagePickerController Demo/AGViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ - (void)openAction:(id)sender
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}];

// Show saved photos on top
imagePickerController.shouldShowSavedPhotosOnTop = YES;

// Custom toolbar items
AGIPCToolbarItem *selectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:@"+ Select All" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
return YES;
Expand Down
1 change: 1 addition & 0 deletions AGImagePickerController/AGIPCAlbumsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
}

@property (retain) IBOutlet UITableView *tableView;
@property (assign) BOOL savedPhotosOnTop;

@end
13 changes: 12 additions & 1 deletion AGImagePickerController/AGIPCAlbumsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ @implementation AGIPCAlbumsController
#pragma mark - Properties

@synthesize tableView;
@synthesize savedPhotosOnTop;

- (NSMutableArray *)assetsGroups
{
Expand Down Expand Up @@ -181,7 +182,17 @@ - (void)loadAssetsGroups
return;
}

[self.assetsGroups addObject:group];
if (savedPhotosOnTop) {
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];
}

dispatch_async(dispatch_get_main_queue(), ^{
[self reloadData];
Expand Down
3 changes: 3 additions & 0 deletions AGImagePickerController/AGIPCAssetsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ - (void)reloadData
[self.tableView reloadData];
[self setTitle:[self.assetsGroup valueForProperty:ALAssetsGroupPropertyName]];
[self changeSelectionInformation];

NSInteger totalRows = [self.tableView numberOfRowsInSection:0];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:totalRows-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}

- (void)doneAction:(id)sender
Expand Down
2 changes: 2 additions & 0 deletions AGImagePickerController/AGImagePickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef void (^AGIPCDidFail)(NSError *error);

BOOL shouldChangeStatusBarStyle;
BOOL shouldDisplaySelectionInformation;
BOOL shouldShowSavedPhotosOnTop;
UIStatusBarStyle oldStatusBarStyle;

AGIPCDidFinish didFinishBlock;
Expand All @@ -43,6 +44,7 @@ typedef void (^AGIPCDidFail)(NSError *error);

@property (assign) BOOL shouldChangeStatusBarStyle;
@property (assign) BOOL shouldDisplaySelectionInformation;
@property (assign) BOOL shouldShowSavedPhotosOnTop;
@property NSUInteger maximumNumberOfPhotos;

@property (nonatomic, assign) id delegate;
Expand Down
5 changes: 3 additions & 2 deletions AGImagePickerController/AGImagePickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ @implementation AGImagePickerController

#pragma mark - Properties

@synthesize delegate, maximumNumberOfPhotos, shouldChangeStatusBarStyle, shouldDisplaySelectionInformation;
@synthesize delegate, maximumNumberOfPhotos, shouldChangeStatusBarStyle, shouldDisplaySelectionInformation, shouldShowSavedPhotosOnTop;

@synthesize didFailBlock, didFinishBlock;

Expand Down Expand Up @@ -150,12 +150,13 @@ - (void)viewDidLoad
{
[super viewDidLoad];

UIViewController *rootViewController = nil;
AGIPCAlbumsController *rootViewController = nil;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
rootViewController = [[AGIPCAlbumsController alloc] initWithNibName:@"AGIPCAlbumsController_iPhone" bundle:nil];
} else {
rootViewController = [[AGIPCAlbumsController alloc] initWithNibName:@"AGIPCAlbumsController_iPad" bundle:nil];
}
rootViewController.savedPhotosOnTop = shouldShowSavedPhotosOnTop;
self.viewControllers = [NSArray arrayWithObject:rootViewController];
[rootViewController release];
}
Expand Down

0 comments on commit 99aca00

Please sign in to comment.