Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Custom Fetch Result #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions CTAssetsPickerController/CTAssetCollectionViewCell.h
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
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
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
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
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
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
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
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
@@ -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
@@ -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
Expand Up @@ -8,7 +8,7 @@ DEPENDENCIES:

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

SPEC CHECKSUMS:
CTAssetsPickerController: b1d1d50ab87cf6b8b13531de5f4530482e7e53ed
Expand Down