Skip to content

Commit

Permalink
support of custom fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-dumit committed Jul 11, 2017
1 parent 2ca7959 commit 70cde51
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CTAssetsPickerController/CTAssetCollectionViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
@property (nonatomic, weak, nullable) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR;


- (instancetype)initWithThumbnailSize:(CGSize)size reuseIdentifier:(nullable NSString *)reuseIdentifier;
- (nonnull instancetype)initWithThumbnailSize:(CGSize)size reuseIdentifier:(nullable NSString *)reuseIdentifier;
- (void)bind:(nonnull PHAssetCollection *)collection count:(NSUInteger)count;

@end
@end
2 changes: 1 addition & 1 deletion CTAssetsPickerController/CTAssetThumbnailStacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@interface CTAssetThumbnailStacks : UIView

@property (nonatomic, assign) CGSize thumbnailSize;
@property (nonatomic, copy, readonly) NSArray<CTAssetThumbnailView*> *thumbnailViews;
@property (nonatomic, copy, readonly, nonnull) NSArray<CTAssetThumbnailView*> *thumbnailViews;
@property (nonatomic, assign, readonly) UIEdgeInsets edgeInsets;

- (nonnull CTAssetThumbnailView *)thumbnailAtIndex:(NSUInteger)index;
Expand Down
4 changes: 2 additions & 2 deletions CTAssetsPickerController/CTAssetsGridViewController.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@

@interface CTAssetsGridViewController : UICollectionViewController

@property (nonatomic, weak) id<CTAssetsGridViewControllerDelegate> delegate;
@property (nonatomic, weak, nullable) id<CTAssetsGridViewControllerDelegate> delegate;
@property (nonatomic, strong, nonnull) PHAssetCollection *assetCollection;
@property (nonatomic, strong, nullable) PHFetchResult<PHAsset*> *pickFromFetch;

@end


25 changes: 19 additions & 6 deletions CTAssetsPickerController/CTAssetsGridViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ @interface CTAssetsGridViewController ()
<PHPhotoLibraryChangeObserver>

@property (nonatomic, weak) CTAssetsPickerController *picker;
@property (nonatomic, strong) PHFetchResult *fetchResult;
@property (nonatomic, strong) PHFetchResult<PHAsset*> *fetchResult;
@property (nonatomic, strong) PHCachingImageManager *imageManager;

@property (nonatomic, assign) CGRect previousPreheatRect;
Expand Down Expand Up @@ -188,15 +188,28 @@ - (void)setupButtons
target:self.picker
action:@selector(finishPickingAssets:)];
}

if (self.pickFromFetch && self.picker.showsCancelButton) {
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:CTAssetsPickerLocalizedString(@"Cancel", nil)
style:UIBarButtonItemStylePlain
target:self.picker
action:@selector(dismiss:)];
}
}

- (void)setupAssets
{
PHFetchResult *fetchResult =
[PHAsset fetchAssetsInAssetCollection:self.assetCollection
options:self.picker.assetsFetchOptions];
if (_pickFromFetch) {
self.fetchResult = _pickFromFetch;
} else {
PHFetchResult *fetchResult =
[PHAsset fetchAssetsInAssetCollection:self.assetCollection
options:self.picker.assetsFetchOptions];

self.fetchResult = fetchResult;
}

self.fetchResult = fetchResult;
[self reloadData];
}

Expand Down Expand Up @@ -799,4 +812,4 @@ - (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIn
[self.picker.delegate assetsPickerController:self.picker didUnhighlightAsset:asset];
}

@end
@end
8 changes: 7 additions & 1 deletion CTAssetsPickerController/CTAssetsPickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, strong) UISplitViewController *childSplitViewController;

/**
* Displays the picker to pick between the fetch result. Must be a PHAsset type fetch.
*
* It will not display the list of albums, but only the assets in the specified fetch result.
*/
@property (strong, nonatomic) PHFetchResult<PHAsset*> *pickFromFetch;

/**
* @name Managing Selections
Expand Down Expand Up @@ -371,4 +377,4 @@ extern NSString * const CTAssetsPickerDidDeselectAssetNotification;

@end

NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
7 changes: 7 additions & 0 deletions CTAssetsPickerController/CTAssetsPickerController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ - (void)setupSplitViewController
{
CTAssetCollectionViewController *vc = [CTAssetCollectionViewController new];
CTAssetsNavigationController *master = [[CTAssetsNavigationController alloc] initWithRootViewController:vc];

if (self.pickFromFetch) {
CTAssetsGridViewController *grid = [CTAssetsGridViewController new];
grid.pickFromFetch = self.pickFromFetch;
master.viewControllers = @[grid];
}

UINavigationController *detail = [self emptyNavigationController];
UISplitViewController *svc = [UISplitViewController new];

Expand Down
7 changes: 6 additions & 1 deletion CTAssetsPickerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
ADFC004C1B54FF740024CBB9 /* CTLayoutViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ADFC004B1B54FF740024CBB9 /* CTLayoutViewController.m */; };
ADFE23881B46602400E44353 /* CTProgrammaticViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ADFE23871B46602400E44353 /* CTProgrammaticViewController.m */; };
ADFE238B1B46868100E44353 /* CTApperanceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ADFE238A1B46868100E44353 /* CTApperanceViewController.m */; };
D57946551CB452DE008C14D4 /* CTCustomFetchViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D57946541CB452DE008C14D4 /* CTCustomFetchViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -185,6 +186,8 @@
ADFE23871B46602400E44353 /* CTProgrammaticViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTProgrammaticViewController.m; sourceTree = "<group>"; };
ADFE23891B46868100E44353 /* CTApperanceViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTApperanceViewController.h; sourceTree = "<group>"; };
ADFE238A1B46868100E44353 /* CTApperanceViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTApperanceViewController.m; sourceTree = "<group>"; };
D57946531CB452DE008C14D4 /* CTCustomFetchViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTCustomFetchViewController.h; sourceTree = "<group>"; };
D57946541CB452DE008C14D4 /* CTCustomFetchViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTCustomFetchViewController.m; sourceTree = "<group>"; };
F1B2FBB7FD634FB543BB7BB6 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FD69CDFBA7D07D903CCC8B80 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -225,6 +228,8 @@
AD18AFD61BCC9BA9008B507D /* CTSelectionOrderViewController.m */,
ADA0730B1B4625AA009FB7C7 /* CTUITweaksViewController.h */,
ADA0730C1B4625AA009FB7C7 /* CTUITweaksViewController.m */,
D57946531CB452DE008C14D4 /* CTCustomFetchViewController.h */,
D57946541CB452DE008C14D4 /* CTCustomFetchViewController.m */,
AD4B06C91B44CD5A00D99C5A /* CTSortedAssetsViewController.h */,
AD4B06CA1B44CD5A00D99C5A /* CTSortedAssetsViewController.m */,
ADA073051B4515AF009FB7C7 /* CTPhotosViewController.h */,
Expand Down Expand Up @@ -423,7 +428,6 @@
TargetAttributes = {
ADD965C51AAD4C49002A26A2 = {
CreatedOnToolsVersion = 6.1.1;
DevelopmentTeam = VE5FET45CD;
};
};
};
Expand Down Expand Up @@ -552,6 +556,7 @@
AD18AFD71BCC9BA9008B507D /* CTSelectionOrderViewController.m in Sources */,
ADFE238B1B46868100E44353 /* CTApperanceViewController.m in Sources */,
ADE2713C1ACBA6BA0090EFB1 /* NSIndexSet+CTAssetsPickerController.m in Sources */,
D57946551CB452DE008C14D4 /* CTCustomFetchViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 7 additions & 1 deletion CTAssetsPickerDemo/CTMasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTDefaultAlbumViewController.h"
#import "CTSelectionOrderViewController.h"
#import "CTUITweaksViewController.h"
#import "CTCustomFetchViewController.h"

#import "CTSortedAssetsViewController.h"

Expand Down Expand Up @@ -71,7 +72,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
{
switch (section) {
case 0:
return 6;
return 7;
break;

case 1:
Expand Down Expand Up @@ -166,6 +167,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

if (row == 5)
title = @"UI tweaks";

if (row == 6)
title = @"Custom Fetch";
}

if (section == 1)
Expand Down Expand Up @@ -241,6 +245,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath

if (row == 5)
vc = (UIViewController *)[CTUITweaksViewController new];
if (row == 6)
vc = (UIViewController *)[CTCustomFetchViewController new];
}

if (section == 1)
Expand Down
13 changes: 13 additions & 0 deletions CTAssetsPickerDemo/Examples/CTCustomFetchViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CTCustomFetchViewController.h
// CTAssetsPickerDemo
//
// Created by Felix Dumit on 4/5/16.
// Copyright © 2016 Clement T. All rights reserved.
//

#import "CTBasicViewController.h"

@interface CTCustomFetchViewController : CTBasicViewController

@end
36 changes: 36 additions & 0 deletions CTAssetsPickerDemo/Examples/CTCustomFetchViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// CTCustomFetchViewController.m
// CTAssetsPickerDemo
//
// Created by Felix Dumit on 4/5/16.
// Copyright © 2016 Clement T. All rights reserved.
//

#import "CTCustomFetchViewController.h"

@implementation CTCustomFetchViewController

- (void)pickAssets:(id)sender {
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
dispatch_async(dispatch_get_main_queue(), ^{
// init picker
CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];

// set delegate
picker.delegate = self;

// set custom fetch
picker.pickFromFetch = [PHAsset fetchAssetsWithOptions:nil];

// to present picker as a form sheet in iPad
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) picker.modalPresentationStyle = UIModalPresentationFormSheet;

// present picker
[self presentViewController:picker
animated:YES
completion:nil];
});
}];
}

@end
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DEPENDENCIES:

EXTERNAL SOURCES:
CTAssetsPickerController:
:path: .
:path: "."

SPEC CHECKSUMS:
CTAssetsPickerController: b1d1d50ab87cf6b8b13531de5f4530482e7e53ed
Expand Down

0 comments on commit 70cde51

Please sign in to comment.