Skip to content

Commit

Permalink
#154 Add iOS 9' new Photo Albums
Browse files Browse the repository at this point in the history
  • Loading branch information
1and2papa committed Sep 24, 2015
1 parent 24d63c5 commit 25d8630
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 65 deletions.
65 changes: 4 additions & 61 deletions CTAssetsPickerController/CTAssetThumbnailOverlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTAssetThumbnailOverlay.h"
#import "UIImage+CTAssetsPickerController.h"
#import "PHAsset+CTAssetsPickerController.h"
#import "PHAssetCollection+CTAssetsPickerController.h"



Expand Down Expand Up @@ -111,34 +112,14 @@ - (void)updateConstraints

- (void)bind:(PHAsset *)asset duration:(NSString *)duration;
{
self.badge.image = [self imageForAsset:asset];
self.badge.image = [asset badgeImage];
self.badge.layoutMargins = [self layoutMarginsForAsset:asset];
self.duration.text = duration;

[self setNeedsUpdateConstraints];
[self updateConstraintsIfNeeded];
}


- (UIImage *)imageForAsset:(PHAsset *)asset
{
NSString *imageName;

if (asset.ctassetsPickerIsHighFrameRateVideo)
imageName = @"BadgeSloMoSmall";

else if (asset.ctassetsPickerIsTimelapseVideo)
imageName = @"BadgeTimelapseSmall";

else if (asset.ctassetsPickerIsVideo)
imageName = @"BadgeVideoSmall";

if (imageName)
return [[UIImage ctassetsPickerImageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
else
return nil;
}

- (UIEdgeInsets)layoutMarginsForAsset:(PHAsset *)asset
{
if (asset.ctassetsPickerIsHighFrameRateVideo)
Expand All @@ -159,55 +140,17 @@ - (UIEdgeInsets)layoutMarginsForAsset:(PHAsset *)asset

- (void)bind:(PHAssetCollection *)assetCollection;
{
self.badge.image = [self imageForAssetCollection:assetCollection];
self.badge.image = [assetCollection badgeImage];
self.badge.layoutMargins = [self layoutMarginsForAssetCollection:assetCollection];
self.duration.text = nil;

[self setNeedsUpdateConstraints];
[self updateConstraintsIfNeeded];
}

- (UIImage *)imageForAssetCollection:(PHAssetCollection *)assetCollection
{
NSString *imageName;

if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumUserLibrary)
imageName = @"BadgeAllPhotos";

else if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumPanoramas)
imageName = @"BadgePanorama";

else if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumVideos)
imageName = @"BadgeVideo";

else if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumFavorites)
imageName = @"BadgeFavorites";

else if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumTimelapses)
imageName = @"BadgeTimelapse";

else if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumAllHidden)
imageName = nil;

else if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumRecentlyAdded)
imageName = @"BadgeLastImport";

else if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumBursts)
imageName = @"BadgeBurst";

else if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumSlomoVideos)
imageName = @"BadgeSlomo";


if (imageName)
return [[UIImage ctassetsPickerImageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
else
return nil;
}

- (UIEdgeInsets)layoutMarginsForAssetCollection:(PHAssetCollection *)assetCollection
{
return UIEdgeInsetsMake(4,4,4,4);
return UIEdgeInsetsMake(4.0, 4.0, 4.0, 4.0);
}

@end
12 changes: 11 additions & 1 deletion CTAssetsPickerController/CTAssetsPickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,23 @@ - (void)initAssetCollectionSubtypes
[NSNumber numberWithInt:PHAssetCollectionSubtypeSmartAlbumTimelapses],
[NSNumber numberWithInt:PHAssetCollectionSubtypeSmartAlbumBursts],
[NSNumber numberWithInt:PHAssetCollectionSubtypeSmartAlbumAllHidden],
[NSNumber numberWithInt:PHAssetCollectionSubtypeSmartAlbumGeneric],
[NSNumber numberWithInt:PHAssetCollectionSubtypeSmartAlbumGeneric],
[NSNumber numberWithInt:PHAssetCollectionSubtypeAlbumRegular],
[NSNumber numberWithInt:PHAssetCollectionSubtypeAlbumSyncedAlbum],
[NSNumber numberWithInt:PHAssetCollectionSubtypeAlbumSyncedEvent],
[NSNumber numberWithInt:PHAssetCollectionSubtypeAlbumSyncedFaces],
[NSNumber numberWithInt:PHAssetCollectionSubtypeAlbumImported],
[NSNumber numberWithInt:PHAssetCollectionSubtypeAlbumCloudShared]];

// Add iOS 9's new albums
if ([[PHAsset new] respondsToSelector:@selector(sourceType)])
{
NSMutableArray *subtypes = [NSMutableArray arrayWithArray:self.assetCollectionSubtypes];
[subtypes insertObject:[NSNumber numberWithInt:PHAssetCollectionSubtypeSmartAlbumSelfPortraits] atIndex:4];
[subtypes insertObject:[NSNumber numberWithInt:PHAssetCollectionSubtypeSmartAlbumScreenshots] atIndex:10];

self.assetCollectionSubtypes = [NSArray arrayWithArray:subtypes];
}
}

- (void)initThumbnailRequestOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- (BOOL)ctassetsPickerIsHighFrameRateVideo;
- (BOOL)ctassetsPickerIsTimelapseVideo;

- (UIImage *)badgeImage;
- (NSString *)ctassetsPickerAccessibilityLabel;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ of this software and associated documentation files (the "Software"), to deal
*/

#import "PHAsset+CTAssetsPickerController.h"
#import "UIImage+CTAssetsPickerController.h"



@implementation PHAsset (CTAssetsPickerController)

Expand All @@ -48,6 +51,25 @@ - (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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@

+ (PHAssetCollectionType)ctassetPickerAssetCollectionTypeOfSubtype:(PHAssetCollectionSubtype)subtype;
- (NSUInteger)ctassetPikcerCountOfAssetsFetchedWithOptions:(PHFetchOptions *)fetchOptions;
- (UIImage *)badgeImage;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ of this software and associated documentation files (the "Software"), to deal
*/

#import "PHAssetCollection+CTAssetsPickerController.h"
#import "UIImage+CTAssetsPickerController.h"



@implementation PHAssetCollection (CTAssetsPickerController)

Expand All @@ -39,5 +42,62 @@ - (NSUInteger)ctassetPikcerCountOfAssetsFetchedWithOptions:(PHFetchOptions *)fet
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "BadgeScreenshots@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "BadgeScreenshots@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "BadgeSelfPortraits@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "BadgeSelfPortraits@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"images" : [
{
"idiom" : "universal",
"filename" : "BadgeSloMoSmall.png",
"filename" : "BadgeSlomoSmall.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "BadgeSloMoSmall@2x.png",
"filename" : "BadgeSlomoSmall@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "BadgeSloMoSmall@3x.png",
"filename" : "BadgeSlomoSmall@3x.png",
"scale" : "3x"
}
],
Expand Down

0 comments on commit 25d8630

Please sign in to comment.