Initial commit
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
@interface CTAssetsPageViewController (Internal)
|
||||
|
||||
@property (nonatomic, assign) BOOL allowsSelection;
|
||||
|
||||
@end
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
@interface CTAssetsPickerController (Internal)
|
||||
|
||||
- (void)dismiss:(id)sender;
|
||||
- (void)finishPickingAssets:(id)sender;
|
||||
|
||||
- (void)setShouldCollapseDetailViewController:(BOOL)collapse;
|
||||
- (void)showNoAssets;
|
||||
|
||||
- (CGSize)assetCollectionThumbnailSize;
|
||||
- (CGSize)assetThumbnailSize;
|
||||
- (NSString *)selectedAssetsString;
|
||||
|
||||
- (PHImageRequestOptions *)thumbnailRequestOptions;
|
||||
- (CGSize)imageSizeForContainerSize:(CGSize)size;
|
||||
|
||||
@end
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
|
||||
#define CTAssetsPickerLocalizedString(key, comment) \
|
||||
NSLocalizedStringFromTableInBundle((key), @"CTAssetsPicker", [NSBundle ctassetsPickerBundle], (comment))
|
||||
|
||||
@interface NSBundle (CTAssetsPickerController)
|
||||
|
||||
+ (NSBundle *)ctassetsPickerBundle;
|
||||
|
||||
@end
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 "NSBundle+CTAssetsPickerController.h"
|
||||
#import "CTAssetsPickerController.h"
|
||||
|
||||
@implementation NSBundle (CTAssetsPickerController)
|
||||
|
||||
+ (NSBundle *)ctassetsPickerBundle
|
||||
{
|
||||
return [NSBundle bundleWithPath:[NSBundle ctassetsPickerBundlePath]];
|
||||
}
|
||||
|
||||
+ (NSString *)ctassetsPickerBundlePath
|
||||
{
|
||||
return [[NSBundle bundleForClass:[CTAssetsPickerController class]]
|
||||
pathForResource:@"CTAssetsPickerController" ofType:@"bundle"];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
|
||||
|
||||
@interface NSDateFormatter (CTAssetsPickerController)
|
||||
|
||||
- (NSString *)ctassetsPickerStringFromTimeInterval:(NSTimeInterval)timeInterval;
|
||||
- (NSString *)ctassetsPickerSpellOutStringFromTimeInterval:(NSTimeInterval)timeInterval;
|
||||
|
||||
@end
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 "NSDateFormatter+CTAssetsPickerController.h"
|
||||
#import "NSBundle+CTAssetsPickerController.h"
|
||||
|
||||
|
||||
|
||||
@implementation NSDateFormatter (CTAssetsPickerController)
|
||||
|
||||
- (NSString *)ctassetsPickerStringFromTimeInterval:(NSTimeInterval)timeInterval
|
||||
{
|
||||
NSDateComponents *components = [self dateComponetsWithTimeInterval:timeInterval];
|
||||
NSInteger roundedSeconds = lround(timeInterval - (components.hour * 60 * 60) - (components.minute * 60));
|
||||
|
||||
if (components.hour > 0)
|
||||
return [NSString stringWithFormat:@"%ld:%02ld:%02ld", (long)components.hour, (long)components.minute, (long)roundedSeconds];
|
||||
|
||||
else
|
||||
return [NSString stringWithFormat:@"%ld:%02ld", (long)components.minute, (long)roundedSeconds];
|
||||
}
|
||||
|
||||
- (NSString *)ctassetsPickerSpellOutStringFromTimeInterval:(NSTimeInterval)timeInterval
|
||||
{
|
||||
NSString *string = @"";
|
||||
|
||||
NSDateComponents *components = [self dateComponetsWithTimeInterval:timeInterval];
|
||||
|
||||
if (components.hour > 0)
|
||||
string = [string stringByAppendingFormat:@"%ld %@",
|
||||
(long)components.hour,
|
||||
(components.hour > 1) ?
|
||||
CTAssetsPickerLocalizedString(@"hours", nil) :
|
||||
CTAssetsPickerLocalizedString(@"hour", nil)];
|
||||
|
||||
if (components.minute > 0)
|
||||
string = [string stringByAppendingFormat:@"%ld %@",
|
||||
(long)components.minute,
|
||||
(components.minute > 1) ?
|
||||
CTAssetsPickerLocalizedString(@"minutes", nil) :
|
||||
CTAssetsPickerLocalizedString(@"minute", nil)];
|
||||
|
||||
if (components.second > 0)
|
||||
string = [string stringByAppendingFormat:@"%ld %@",
|
||||
(long)components.second,
|
||||
(components.second > 1) ?
|
||||
CTAssetsPickerLocalizedString(@"seconds", nil) :
|
||||
CTAssetsPickerLocalizedString(@"second", nil)];
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
- (NSDateComponents *)dateComponetsWithTimeInterval:(NSTimeInterval)timeInterval
|
||||
{
|
||||
NSCalendar *calendar = [NSCalendar currentCalendar];
|
||||
|
||||
NSDate *date1 = [[NSDate alloc] init];
|
||||
NSDate *date2 = [[NSDate alloc] initWithTimeInterval:timeInterval sinceDate:date1];
|
||||
|
||||
unsigned int unitFlags =
|
||||
NSCalendarUnitSecond | NSCalendarUnitMinute | NSCalendarUnitHour |
|
||||
NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear;
|
||||
|
||||
return [calendar components:unitFlags
|
||||
fromDate:date1
|
||||
toDate:date2
|
||||
options:0];
|
||||
}
|
||||
|
||||
@end
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
@interface NSIndexSet (CTAssetsPickerController)
|
||||
|
||||
- (NSArray *)ctassetsPickerIndexPathsFromIndexesWithSection:(NSUInteger)section;
|
||||
|
||||
@end
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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>
|
||||
#import "NSIndexSet+CTAssetsPickerController.h"
|
||||
|
||||
|
||||
@implementation NSIndexSet (CTAssetsPickerController)
|
||||
|
||||
- (NSArray *)ctassetsPickerIndexPathsFromIndexesWithSection:(NSUInteger)section
|
||||
{
|
||||
NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:self.count];
|
||||
|
||||
[self enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) {
|
||||
[indexPaths addObject:[NSIndexPath indexPathForItem:index inSection:section]];
|
||||
}];
|
||||
|
||||
return indexPaths;
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
@interface NSNumberFormatter (CTAssetsPickerController)
|
||||
|
||||
- (NSString *)ctassetsPickerStringFromAssetsCount:(NSUInteger)count;
|
||||
|
||||
@end
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 "NSNumberFormatter+CTAssetsPickerController.h"
|
||||
|
||||
@implementation NSNumberFormatter (CTAssetsPickerController)
|
||||
|
||||
- (NSString *)ctassetsPickerStringFromAssetsCount:(NSUInteger)count
|
||||
{
|
||||
self.numberStyle = NSNumberFormatterDecimalStyle;
|
||||
self.locale = [NSLocale currentLocale];
|
||||
return [self stringFromNumber:@(count)];
|
||||
}
|
||||
|
||||
@end
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 <Photos/Photos.h>
|
||||
|
||||
@interface PHAsset (CTAssetsPickerController)
|
||||
|
||||
- (BOOL)ctassetsPickerIsPhoto;
|
||||
- (BOOL)ctassetsPickerIsVideo;
|
||||
- (BOOL)ctassetsPickerIsHighFrameRateVideo;
|
||||
- (BOOL)ctassetsPickerIsTimelapseVideo;
|
||||
|
||||
- (UIImage *)badgeImage;
|
||||
- (NSString *)ctassetsPickerAccessibilityLabel;
|
||||
|
||||
@end
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 "PHAsset+CTAssetsPickerController.h"
|
||||
#import "UIImage+CTAssetsPickerController.h"
|
||||
|
||||
|
||||
|
||||
@implementation PHAsset (CTAssetsPickerController)
|
||||
|
||||
- (BOOL)ctassetsPickerIsPhoto
|
||||
{
|
||||
return (self.mediaType == PHAssetMediaTypeImage);
|
||||
}
|
||||
|
||||
- (BOOL)ctassetsPickerIsVideo
|
||||
{
|
||||
return (self.mediaType == PHAssetMediaTypeVideo);
|
||||
}
|
||||
|
||||
- (BOOL)ctassetsPickerIsHighFrameRateVideo
|
||||
{
|
||||
return (self.mediaType == PHAssetMediaTypeVideo && (self.mediaSubtypes & PHAssetMediaSubtypeVideoHighFrameRate));
|
||||
}
|
||||
|
||||
- (BOOL)ctassetsPickerIsTimelapseVideo
|
||||
{
|
||||
return (self.mediaType == PHAssetMediaTypeVideo && (self.mediaSubtypes & PHAssetMediaSubtypeVideoTimelapse));
|
||||
}
|
||||
|
||||
- (UIImage *)badgeImage
|
||||
{
|
||||
NSString *imageName;
|
||||
|
||||
if (self.ctassetsPickerIsHighFrameRateVideo)
|
||||
imageName = @"BadgeSlomoSmall";
|
||||
|
||||
else if (self.ctassetsPickerIsTimelapseVideo)
|
||||
imageName = @"BadgeTimelapseSmall";
|
||||
|
||||
else if (self.ctassetsPickerIsVideo)
|
||||
imageName = @"BadgeVideoSmall";
|
||||
|
||||
if (imageName)
|
||||
return [[UIImage ctassetsPickerImageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *)ctassetsPickerAccessibilityLabel
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 <Photos/Photos.h>
|
||||
|
||||
@interface PHAssetCollection (CTAssetsPickerController)
|
||||
|
||||
+ (PHAssetCollectionType)ctassetPickerAssetCollectionTypeOfSubtype:(PHAssetCollectionSubtype)subtype;
|
||||
- (NSUInteger)ctassetPikcerCountOfAssetsFetchedWithOptions:(PHFetchOptions *)fetchOptions;
|
||||
- (UIImage *)badgeImage;
|
||||
|
||||
@end
|
||||
Executable
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 "PHAssetCollection+CTAssetsPickerController.h"
|
||||
#import "UIImage+CTAssetsPickerController.h"
|
||||
|
||||
|
||||
|
||||
@implementation PHAssetCollection (CTAssetsPickerController)
|
||||
|
||||
+ (PHAssetCollectionType)ctassetPickerAssetCollectionTypeOfSubtype:(PHAssetCollectionSubtype)subtype
|
||||
{
|
||||
return (subtype >= PHAssetCollectionSubtypeSmartAlbumGeneric) ? PHAssetCollectionTypeSmartAlbum : PHAssetCollectionTypeAlbum;
|
||||
}
|
||||
|
||||
- (NSUInteger)ctassetPikcerCountOfAssetsFetchedWithOptions:(PHFetchOptions *)fetchOptions
|
||||
{
|
||||
PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:self options:fetchOptions];
|
||||
return result.count;
|
||||
}
|
||||
|
||||
- (UIImage *)badgeImage
|
||||
{
|
||||
NSString *imageName;
|
||||
|
||||
switch (self.assetCollectionSubtype)
|
||||
{
|
||||
case PHAssetCollectionSubtypeSmartAlbumUserLibrary:
|
||||
imageName = @"BadgeAllPhotos";
|
||||
break;
|
||||
|
||||
case PHAssetCollectionSubtypeSmartAlbumPanoramas:
|
||||
imageName = @"BadgePanorama";
|
||||
break;
|
||||
|
||||
case PHAssetCollectionSubtypeSmartAlbumVideos:
|
||||
imageName = @"BadgeVideo";
|
||||
break;
|
||||
|
||||
case PHAssetCollectionSubtypeSmartAlbumFavorites:
|
||||
imageName = @"BadgeFavorites";
|
||||
break;
|
||||
|
||||
case PHAssetCollectionSubtypeSmartAlbumTimelapses:
|
||||
imageName = @"BadgeTimelapse";
|
||||
break;
|
||||
|
||||
case PHAssetCollectionSubtypeSmartAlbumRecentlyAdded:
|
||||
imageName = @"BadgeLastImport";
|
||||
break;
|
||||
|
||||
case PHAssetCollectionSubtypeSmartAlbumBursts:
|
||||
imageName = @"BadgeBurst";
|
||||
break;
|
||||
|
||||
case PHAssetCollectionSubtypeSmartAlbumSlomoVideos:
|
||||
imageName = @"BadgeSlomo";
|
||||
break;
|
||||
|
||||
case PHAssetCollectionSubtypeSmartAlbumScreenshots:
|
||||
imageName = @"BadgeScreenshots";
|
||||
break;
|
||||
|
||||
case PHAssetCollectionSubtypeSmartAlbumSelfPortraits:
|
||||
imageName = @"BadgeSelfPortraits";
|
||||
break;
|
||||
|
||||
default:
|
||||
imageName = nil;
|
||||
break;
|
||||
}
|
||||
|
||||
if (imageName)
|
||||
return [[UIImage ctassetsPickerImageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// PHImageManager+CTSupport.h
|
||||
// CTAssetsPickerDemo
|
||||
//
|
||||
// Created by Korben Allen Rusek on 4/7/16.
|
||||
// Copyright © 2016 Clement T. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Photos/Photos.h>
|
||||
|
||||
@interface PHImageManager (CTAssetsPickerController)
|
||||
|
||||
- (PHImageRequestID)ctassetsPickerRequestImageForAsset:(PHAsset *)asset targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:( PHImageRequestOptions *)options resultHandler:(void (^)(UIImage * result, NSDictionary * info))resultHandler;
|
||||
|
||||
@end
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// PHImageManager+CTSupport.m
|
||||
// CTAssetsPickerDemo
|
||||
//
|
||||
// Created by Korben Allen Rusek on 4/7/16.
|
||||
// Copyright © 2016 Clement T. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PHImageManager+CTAssetsPickerController.h"
|
||||
|
||||
@implementation PHImageManager (CTAssetsPickerController)
|
||||
|
||||
+ (BOOL)ctassetsPickerNeedsiPadSupportSize {
|
||||
return [(NSString*)[UIDevice currentDevice].model hasPrefix:@"iPad"] && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad == false;
|
||||
}
|
||||
|
||||
+ (CGSize)ctassetsPickerSizeForSize:(CGSize)size withMinimumDimension:(CGFloat)dimension {
|
||||
if (size.width >= dimension && size.height >= dimension) return size;
|
||||
if (size.width <= 0 || size.height <= 0) return size;
|
||||
|
||||
CGFloat width, height;
|
||||
if (size.width < size.height) {
|
||||
width = 500;
|
||||
height = size.height/size.width*width;
|
||||
} else {
|
||||
height = 500;
|
||||
width = size.width/size.height*height;
|
||||
}
|
||||
return CGSizeMake(width, height);
|
||||
}
|
||||
|
||||
- (PHImageRequestID)ctassetsPickerRequestImageForAsset:(PHAsset *)asset targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:( PHImageRequestOptions *)options resultHandler:(void (^)(UIImage * result, NSDictionary * info))resultHandler {
|
||||
CGSize size = targetSize;
|
||||
if ([[self class] ctassetsPickerNeedsiPadSupportSize]) {
|
||||
size = [[self class] ctassetsPickerSizeForSize:targetSize withMinimumDimension:500];
|
||||
}
|
||||
return [self requestImageForAsset:asset targetSize:size contentMode:contentMode options:options resultHandler:resultHandler];
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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>
|
||||
|
||||
@interface UICollectionView (CTAssetsPickerController)
|
||||
|
||||
- (NSArray *)ctassetsPickerIndexPathsForElementsInRect:(CGRect)rect;
|
||||
|
||||
@end
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 "UICollectionView+CTAssetsPickerController.h"
|
||||
|
||||
@implementation UICollectionView (CTAssetsPickerController)
|
||||
|
||||
- (NSArray *)ctassetsPickerIndexPathsForElementsInRect:(CGRect)rect
|
||||
{
|
||||
NSArray *allAttributes = [self.collectionViewLayout layoutAttributesForElementsInRect:rect];
|
||||
|
||||
if (allAttributes.count == 0)
|
||||
return nil;
|
||||
|
||||
NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:allAttributes.count];
|
||||
|
||||
for (UICollectionViewLayoutAttributes *attributes in allAttributes)
|
||||
{
|
||||
NSIndexPath *indexPath = attributes.indexPath;
|
||||
[indexPaths addObject:indexPath];
|
||||
}
|
||||
|
||||
return indexPaths;
|
||||
}
|
||||
|
||||
@end
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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>
|
||||
|
||||
@interface UIImage (CTAssetsPickerController)
|
||||
|
||||
+ (UIImage *)ctassetsPickerImageNamed:(NSString *)name;
|
||||
|
||||
@end
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
|
||||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Clement CN Tsang
|
||||
|
||||
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 "UIImage+CTAssetsPickerController.h"
|
||||
#import "NSBundle+CTAssetsPickerController.h"
|
||||
|
||||
@implementation UIImage (CTAssetsPickerController)
|
||||
|
||||
+ (UIImage *)ctassetsPickerImageNamed:(NSString *)name
|
||||
{
|
||||
return [UIImage imageNamed:name inBundle:[NSBundle ctassetsPickerBundle] compatibleWithTraitCollection:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user