This repository has been archived by the owner on Mar 15, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
11,022 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
54 changes: 54 additions & 0 deletions
54
Classes/ALAssetsLibrary+GCImagePickerControllerAdditions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright (C) 2011 GUI Cocoa, LLC. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#import <AssetsLibrary/AssetsLibrary.h> | ||
|
||
@interface ALAssetsLibrary (GCImagePickerControllerAdditions) | ||
|
||
|
||
/* | ||
get assets groups sorted the same as seen in UIImagePickerController | ||
types: filter group types. pass ALAssetGroupAll for all groups. | ||
filter: filter the types of assets shown. groups with no assets | ||
matching the filter will be omitted. | ||
error: will be populated if no groups can be loaded. | ||
returns: an array of groups. | ||
*/ | ||
- (NSArray *)gc_assetGroupsWithTypes:(ALAssetsGroupType)types assetsFilter:(ALAssetsFilter *)filter error:(NSError **)error; | ||
|
||
/* | ||
get assets belonging to a certain group. | ||
identifier: the persistent identifier of the group. | ||
filter: filter the types of assets returned. | ||
group: will be populated with the resulting group. | ||
error: will be populated if loading assets fails. | ||
returns: an array of groups. | ||
*/ | ||
- (NSArray *)gc_assetsInGroupWithIdentifier:(NSString *)identifier filter:(ALAssetsFilter *)filter group:(ALAssetsGroup **)inGroup error:(NSError **)inError; | ||
|
||
@end |
134 changes: 134 additions & 0 deletions
134
Classes/ALAssetsLibrary+GCImagePickerControllerAdditions.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
Copyright (C) 2011 GUI Cocoa, LLC. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#import "ALAssetsLibrary+GCImagePickerControllerAdditions.h" | ||
|
||
@implementation ALAssetsLibrary (GCImagePickerControllerAdditions) | ||
- (NSArray *)gc_assetGroupsWithTypes:(ALAssetsGroupType)types assetsFilter:(ALAssetsFilter *)filter error:(NSError **)inError { | ||
|
||
// this will be returned | ||
__block NSMutableArray *groups = nil; | ||
|
||
// load groups | ||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; | ||
[self | ||
enumerateGroupsWithTypes:types | ||
usingBlock:^(ALAssetsGroup *group, BOOL *stop) { | ||
if (group) { | ||
[group setAssetsFilter:filter]; | ||
if ([group numberOfAssets]) { | ||
NSNumber *type = [group valueForProperty:ALAssetsGroupPropertyType]; | ||
NSMutableArray *groupsByType = [dictionary objectForKey:type]; | ||
if (groupsByType == nil) { | ||
groupsByType = [NSMutableArray arrayWithCapacity:1]; | ||
[dictionary setObject:groupsByType forKey:type]; | ||
} | ||
[groupsByType addObject:group]; | ||
} | ||
} | ||
else { | ||
|
||
// make our groups array | ||
groups = [[NSMutableArray alloc] init]; | ||
|
||
// sort groups into final container | ||
NSArray *typeNumbers = [NSArray arrayWithObjects: | ||
[NSNumber numberWithUnsignedInteger:ALAssetsGroupSavedPhotos], | ||
[NSNumber numberWithUnsignedInteger:ALAssetsGroupAlbum], | ||
[NSNumber numberWithUnsignedInteger:ALAssetsGroupEvent], | ||
[NSNumber numberWithUnsignedInteger:ALAssetsGroupFaces], | ||
nil]; | ||
for (NSNumber *type in typeNumbers) { | ||
NSArray *groupsByType = [dictionary objectForKey:type]; | ||
[groups addObjectsFromArray:groupsByType]; | ||
[dictionary removeObjectForKey:type]; | ||
} | ||
|
||
// get any groups we do not have contants for | ||
for (NSNumber *type in [dictionary keysSortedByValueUsingSelector:@selector(compare:)]) { | ||
NSArray *groupsByType = [dictionary objectForKey:type]; | ||
[groups addObjectsFromArray:groupsByType]; | ||
[dictionary removeObjectForKey:type]; | ||
} | ||
|
||
} | ||
} | ||
failureBlock:^(NSError *error) { | ||
if (inError) { *inError = [error retain]; } | ||
groups = [[NSArray alloc] init]; | ||
}]; | ||
|
||
// wait | ||
while (groups == nil) { | ||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, NO); | ||
} | ||
|
||
// return | ||
if (inError) { [*inError autorelease]; } | ||
return [groups autorelease]; | ||
|
||
} | ||
- (NSArray *)gc_assetsInGroupWithIdentifier:(NSString *)identifier filter:(ALAssetsFilter *)filter group:(ALAssetsGroup **)inGroup error:(NSError **)inError { | ||
|
||
// this will be returned | ||
__block NSMutableArray *assets = nil; | ||
|
||
[self | ||
enumerateGroupsWithTypes:ALAssetsGroupAll | ||
usingBlock:^(ALAssetsGroup *group, BOOL *stop) { | ||
if (group) { | ||
NSString *groupIdentifier = [group valueForProperty:ALAssetsGroupPropertyPersistentID]; | ||
if ([groupIdentifier isEqualToString:identifier]) { | ||
[group setAssetsFilter:filter]; | ||
assets = [[NSMutableArray alloc] initWithCapacity:[group numberOfAssets]]; | ||
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { | ||
if (result) { [assets addObject:result]; } | ||
}]; | ||
if (inGroup) { *inGroup = [group retain]; } | ||
*stop = YES; | ||
} | ||
} | ||
else { | ||
if (assets == nil) { | ||
assets = [[NSArray alloc] init]; | ||
} | ||
} | ||
} | ||
failureBlock:^(NSError *error) { | ||
if (inError) { *inError = [error retain]; } | ||
assets = [[NSArray alloc] init]; | ||
}]; | ||
|
||
// wait | ||
while (assets == nil) { | ||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, NO); | ||
} | ||
|
||
// return | ||
if (inGroup) { [*inGroup autorelease]; } | ||
if (inError) { [*inError autorelease]; } | ||
return [assets autorelease]; | ||
|
||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Copyright (C) 2011 GUI Cocoa, LLC. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
// cell designed to display a grid of assets | ||
@interface GCIPAssetPickerCell : UITableViewCell { | ||
|
||
} | ||
|
||
// number of columns for the cell to display | ||
@property (nonatomic, assign) NSUInteger numberOfColumns; | ||
|
||
// set assets to display and pass a set of selected asset urls | ||
- (void)setAssets:(NSArray *)assets selected:(NSSet *)selected; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Copyright (C) 2011 GUI Cocoa, LLC. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#import <AssetsLibrary/AssetsLibrary.h> | ||
|
||
#import "GCIPAssetPickerCell.h" | ||
#import "GCIPAssetPickerView.h" | ||
|
||
@implementation GCIPAssetPickerCell | ||
|
||
@synthesize numberOfColumns = __numberOfColumns; | ||
|
||
#pragma mark - object methods | ||
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier { | ||
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; | ||
if (self) { | ||
self.selectionStyle = UITableViewCellSelectionStyleNone; | ||
} | ||
return self; | ||
} | ||
- (void)setNumberOfColumns:(NSUInteger)count { | ||
|
||
// check for same value | ||
if (count == __numberOfColumns) { | ||
return; | ||
} | ||
|
||
// save value | ||
__numberOfColumns = count; | ||
|
||
// set needs layout | ||
[self setNeedsLayout]; | ||
|
||
} | ||
- (void)setAssets:(NSArray *)assets selected:(NSSet *)selected { | ||
|
||
// setup stuff | ||
NSUInteger count = [assets count]; | ||
|
||
for (NSUInteger index = 0; index < self.numberOfColumns; index++) { | ||
|
||
// get view | ||
NSUInteger tag = index + 1; | ||
GCIPAssetPickerView *assetView = (GCIPAssetPickerView *)[self.contentView viewWithTag:tag]; | ||
|
||
// create view if we need one | ||
if (assetView == nil && index < count) { | ||
assetView = [[GCIPAssetPickerView alloc] initWithFrame:CGRectZero]; | ||
assetView.tag = tag; | ||
[self.contentView addSubview:assetView]; | ||
[assetView release]; | ||
} | ||
|
||
// setup view | ||
ALAsset *asset = nil; | ||
if (index < count) { | ||
asset = [assets objectAtIndex:index]; | ||
NSURL *assetURL = [[asset defaultRepresentation] url]; | ||
[assetView setSelected:[selected containsObject:assetURL]]; | ||
} | ||
[assetView setAsset:asset]; | ||
|
||
} | ||
|
||
} | ||
- (void)layoutSubviews { | ||
[super layoutSubviews]; | ||
CGSize viewSize = self.contentView.bounds.size; | ||
CGSize tileSize = { 0.0, viewSize.height - 4.0 }; | ||
NSUInteger columns = self.numberOfColumns; | ||
NSUInteger spaces = columns + 1; | ||
CGFloat totalHorizontalSpace = (CGFloat)spaces * 4.0; | ||
CGFloat occupiedWidth = viewSize.width - totalHorizontalSpace; | ||
tileSize.width = occupiedWidth / (CGFloat)columns; | ||
[self.contentView.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){ | ||
CGRect frame = CGRectMake(4.0 + (4.0 + tileSize.width) * (CGFloat)idx, 0.0, tileSize.width, tileSize.height); | ||
[(UIView *)obj setFrame:frame]; | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Copyright (C) 2011 GUI Cocoa, LLC. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#import <MessageUI/MessageUI.h> | ||
|
||
#import "GCIPTableViewController.h" | ||
|
||
// select an asset from a given group | ||
@interface GCIPAssetPickerController : GCIPTableViewController | ||
<UIActionSheetDelegate, MFMailComposeViewControllerDelegate> { | ||
|
||
} | ||
|
||
// the group to browse | ||
@property (nonatomic, copy) NSString *groupIdentifier; | ||
|
||
@end |
Oops, something went wrong.