From df007bc3a84bf1eb99f0574f5ca837cf6f7cdc40 Mon Sep 17 00:00:00 2001 From: ebalassanian Date: Tue, 3 May 2016 11:31:02 -0700 Subject: [PATCH 01/11] Fixes jumping searchbar when using one service If you only configure one service, the segmented search titles do not appear which causes the search bar to misplaced. Also, changed the text for empty results if there is no initial search term. --- .../Classes/Core/DZNPhotoDisplayViewController.m | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index 3b7ebdf7..9db55586 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -181,7 +181,7 @@ - (UISearchController *)searchController UISearchBar *searchBar = _searchController.searchBar; searchBar.placeholder = NSLocalizedString(@"Search", nil); searchBar.text = self.navigationController.initialSearchTerm; - searchBar.scopeButtonTitles = self.segmentedControlTitles; + searchBar.scopeButtonTitles = [self segmentedControlTitles].count > 1 ? [self segmentedControlTitles] : nil; searchBar.searchBarStyle = UISearchBarStyleProminent; searchBar.barStyle = UIBarStyleDefault; searchBar.selectedScopeButtonIndex = 0; @@ -234,14 +234,6 @@ - (UIActivityIndicatorView *)activityIndicator return _activityIndicator; } -- (NSArray *)segmentedControlTitles -{ - if (_segmentedControlTitles.count > 1) { - return _segmentedControlTitles; - } - return nil; -} - /* Returns the appropriate cell view's size. */ - (CGSize)cellSize { @@ -900,7 +892,10 @@ - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView text = localizedDescription; } else if (!self.loading) { - text = NSLocalizedString(@"Make sure that all words are\nspelled correctly.", nil); + if (self.navigationController.initialSearchTerm) + text = NSLocalizedString(@"Make sure that all words are\nspelled correctly.", nil); + else + text = nil; } if (text) { From 8b4e73a19583b16db636cae70ac788bf2f878757 Mon Sep 17 00:00:00 2001 From: ebalassanian Date: Tue, 3 May 2016 11:31:39 -0700 Subject: [PATCH 02/11] remove defunct services Only google images and flickr seem to work --- Source/Classes/Core/DZNPhotoPickerController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Classes/Core/DZNPhotoPickerController.m b/Source/Classes/Core/DZNPhotoPickerController.m index 8891930b..24569bdd 100644 --- a/Source/Classes/Core/DZNPhotoPickerController.m +++ b/Source/Classes/Core/DZNPhotoPickerController.m @@ -34,7 +34,7 @@ - (id)init self.enablePhotoDownload = YES; self.allowAutoCompletedSearch = YES; - self.supportedServices = DZNPhotoPickerControllerService500px | DZNPhotoPickerControllerServiceFlickr; + self.supportedServices = DZNPhotoPickerControllerServiceGoogleImages | DZNPhotoPickerControllerServiceFlickr; self.supportedLicenses = DZNPhotoPickerControllerCCLicenseBY_ALL; self.cropMode = DZNPhotoEditorViewControllerCropModeSquare; } From f5464f32edb49b00c7da325d8cf0b7035a78eb8c Mon Sep 17 00:00:00 2001 From: ebalassanian Date: Tue, 3 May 2016 11:32:40 -0700 Subject: [PATCH 03/11] Address google being stingy Google only allows 10 photos per search. This code will recursively fetch more results until the total number needed to fulfill the search page are returned. Google also returns an error after 100 results are fetched so that is the hard limit on the number of images per query. --- .../Classes/Services/DZNPhotoServiceClient.m | 28 +++++++++++++++++-- .../Services/DZNPhotoServiceConstants.m | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Source/Classes/Services/DZNPhotoServiceClient.m b/Source/Classes/Services/DZNPhotoServiceClient.m index f72f6556..43a52985 100644 --- a/Source/Classes/Services/DZNPhotoServiceClient.m +++ b/Source/Classes/Services/DZNPhotoServiceClient.m @@ -150,7 +150,8 @@ - (NSDictionary *)photosParamsWithKeyword:(NSString *)keyword page:(NSInteger)pa [params setObject:[self consumerSecret] forKey:keyForAPIConsumerSecret(self.service)]; [params setObject:@"image" forKey:@"searchType"]; [params setObject:@"medium" forKey:@"safe"]; - if (page > 1) [params setObject:@((page - 1) * resultPerPage + 1) forKey:@"start"]; + [params setObject:@(10) forKey:@"num"]; + [params setObject:@(page ? page * resultPerPage + 1 : 1) forKey:@"start"]; } else if (self.service == DZNPhotoPickerControllerServiceBingImages) { @@ -158,6 +159,7 @@ - (NSDictionary *)photosParamsWithKeyword:(NSString *)keyword page:(NSInteger)pa //Default to size medium. Size Large causes some buggy behavior with download times. [params setObject:@"'Size:Medium'" forKey:@"ImageFilters"]; + [params setObject:@"Image" forKey:@"Source"]; } else if (self.service == DZNPhotoPickerControllerServiceGiphy) { @@ -236,7 +238,29 @@ - (void)searchPhotosWithKeyword:(NSString *)keyword page:(NSInteger)page resultP NSString *path = photoSearchUrlPathForService(self.service); NSDictionary *params = [self photosParamsWithKeyword:keyword page:page resultPerPage:resultPerPage]; - [self getObject:[DZNPhotoMetadata class] path:path params:params completion:completion]; + __block NSMutableArray * aggregate = [NSMutableArray arrayWithCapacity:resultPerPage]; + __block NSInteger currentPage = [[params objectForKey:keyForSearchPage(self.service)] integerValue]; + NSLog(@"starting with currentPage %ul", currentPage); + __block DZNHTTPRequestCompletion recursive = ^(NSArray *list, NSError *error) { + if (error) + completion(nil, error); + + [aggregate addObjectsFromArray:list]; + currentPage = currentPage + list.count; + if ((aggregate.count < resultPerPage) && list.count) { + NSLog(@"asking for more at %ul after receiving %ul", currentPage, list.count); + [params setValue:@(currentPage) forKey:keyForSearchPage(self.service)]; + [params setValue:MIN(@(resultPerPage - aggregate.count),[params objectForKey:keyForSearchResultPerPage(self.service)]) forKey:keyForSearchResultPerPage(self.service)]; + [self getObject:[DZNPhotoMetadata class] path:path params:params completion:recursive]; + } else { + NSLog(@"received all items %ul",aggregate.count); + completion(aggregate, nil); + } + }; + + [self getObject:[DZNPhotoMetadata class] path:path params:params completion:recursive]; + + } - (void)getObject:(Class)class path:(NSString *)path params:(NSDictionary *)params completion:(DZNHTTPRequestCompletion)completion diff --git a/Source/Classes/Services/DZNPhotoServiceConstants.m b/Source/Classes/Services/DZNPhotoServiceConstants.m index e405d681..ee8b4d9d 100644 --- a/Source/Classes/Services/DZNPhotoServiceConstants.m +++ b/Source/Classes/Services/DZNPhotoServiceConstants.m @@ -143,6 +143,7 @@ NSString *keyForSearchPage(DZNPhotoPickerControllerServices service) { switch (service) { + case DZNPhotoPickerControllerServiceGoogleImages: return @"start"; default: return @"page"; } } From d73a89038cceb7071cd77ccfe71fa62b853ec9dc Mon Sep 17 00:00:00 2001 From: ebalassanian Date: Tue, 3 May 2016 12:48:26 -0700 Subject: [PATCH 04/11] fix for a merge issue --- Source/Classes/Core/DZNPhotoDisplayViewController.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index 9db55586..1e838906 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -181,7 +181,7 @@ - (UISearchController *)searchController UISearchBar *searchBar = _searchController.searchBar; searchBar.placeholder = NSLocalizedString(@"Search", nil); searchBar.text = self.navigationController.initialSearchTerm; - searchBar.scopeButtonTitles = [self segmentedControlTitles].count > 1 ? [self segmentedControlTitles] : nil; + searchBar.scopeButtonTitles = [self segmentedControlTitles]; searchBar.searchBarStyle = UISearchBarStyleProminent; searchBar.barStyle = UIBarStyleDefault; searchBar.selectedScopeButtonIndex = 0; @@ -234,6 +234,14 @@ - (UIActivityIndicatorView *)activityIndicator return _activityIndicator; } +- (NSArray *)segmentedControlTitles +{ + if (_segmentedControlTitles.count > 1) { + return _segmentedControlTitles; + } + return nil; +} + /* Returns the appropriate cell view's size. */ - (CGSize)cellSize { From 7f8f65ea024f1146648589194e28820307c75aeb Mon Sep 17 00:00:00 2001 From: ebalassanian Date: Tue, 3 May 2016 21:28:10 -0700 Subject: [PATCH 05/11] address issue with searchbar frame On some devices (ipod touch for example) the searchbar frame is not set properly. This addresses the issue and ensures a valid frame. --- Source/Classes/Core/DZNPhotoDisplayViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index 1e838906..af7ec2e3 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -179,6 +179,7 @@ - (UISearchController *)searchController _searchController.hidesNavigationBarDuringPresentation = YES; UISearchBar *searchBar = _searchController.searchBar; + [searchBar sizeToFit]; searchBar.placeholder = NSLocalizedString(@"Search", nil); searchBar.text = self.navigationController.initialSearchTerm; searchBar.scopeButtonTitles = [self segmentedControlTitles]; From 54e6bf395eb44e0574a42bb993b38cc7f85aca7f Mon Sep 17 00:00:00 2001 From: Richard Burgess Date: Tue, 14 Feb 2017 19:28:34 -0600 Subject: [PATCH 06/11] merged in changes from strings project --- .../Core/DZNPhotoDisplayViewController.h | 2 +- .../Core/DZNPhotoDisplayViewController.m | 30 ++++---- .../Classes/Core/DZNPhotoPickerController.h | 2 +- .../Classes/Core/DZNPhotoPickerController.m | 13 ++-- .../UIImagePickerController+Block.h | 26 ------- .../UIImagePickerController+Block.m | 74 ------------------- 6 files changed, 25 insertions(+), 122 deletions(-) delete mode 100644 Source/Classes/UIImagePickerController/UIImagePickerController+Block.h delete mode 100644 Source/Classes/UIImagePickerController/UIImagePickerController+Block.m diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.h b/Source/Classes/Core/DZNPhotoDisplayViewController.h index 8c7ba0dd..79832ef0 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.h +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.h @@ -17,7 +17,7 @@ @interface DZNPhotoDisplayViewController : UICollectionViewController /** The nearest ancestor in the view controller hierarchy that is a photo picker controller. */ -@property (nonatomic, readonly) DZNPhotoPickerController *navigationController; +@property (nonatomic, readonly) DZNPhotoPickerController *pickerController; /** The view controller's search controller. */ @property (nonatomic, readonly) UISearchController *searchController; /** The count number of rows of thumbs to be diplayed. */ diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index af7ec2e3..17ee0f9b 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -92,10 +92,10 @@ - (void)loadView { [super loadView]; - _segmentedControlTitles = NSArrayFromServices(self.navigationController.supportedServices); + _segmentedControlTitles = NSArrayFromServices(self.pickerController.supportedServices); NSAssert((_segmentedControlTitles.count <= 4), @"DZNPhotoPickerController doesn't support more than 4 photo service providers"); - _selectedService = DZNFirstPhotoServiceFromPhotoServices(self.navigationController.supportedServices); + _selectedService = DZNFirstPhotoServiceFromPhotoServices(self.pickerController.supportedServices); NSAssert((_selectedService > 0), @"DZNPhotoPickerController requieres at least 1 supported photo service provider"); self.extendedLayoutIncludesOpaqueBars = YES; @@ -159,10 +159,10 @@ + (UICollectionViewFlowLayout *)layoutFittingSize:(CGSize)size return [[DZNPhotoServiceFactory defaultFactory] clientForService:self.selectedService]; } -/* Returns the navigation controller casted to DZNPhotoPickerController. */ -- (DZNPhotoPickerController *)navigationController +///* Returns the navigation controller casted to DZNPhotoPickerController. */ +- (DZNPhotoPickerController *)pickerController { - return (DZNPhotoPickerController *)[super navigationController]; + return (DZNPhotoPickerController *) self.parentViewController; } /* Returns the custom search display controller. */ @@ -176,12 +176,12 @@ - (UISearchController *)searchController _searchController.searchResultsUpdater = self; _searchController.delegate = self; _searchController.dimsBackgroundDuringPresentation = YES; - _searchController.hidesNavigationBarDuringPresentation = YES; + _searchController.hidesNavigationBarDuringPresentation = NO; UISearchBar *searchBar = _searchController.searchBar; [searchBar sizeToFit]; searchBar.placeholder = NSLocalizedString(@"Search", nil); - searchBar.text = self.navigationController.initialSearchTerm; + searchBar.text = self.pickerController.initialSearchTerm; searchBar.scopeButtonTitles = [self segmentedControlTitles]; searchBar.searchBarStyle = UISearchBarStyleProminent; searchBar.barStyle = UIBarStyleDefault; @@ -419,16 +419,16 @@ - (void)resetPhotos */ - (void)selectedMetadata:(DZNPhotoMetadata *)metadata { - if (!self.navigationController.enablePhotoDownload) { + if (!self.pickerController.enablePhotoDownload) { [metadata postMetadataUpdate:nil]; } - else if (self.navigationController.allowsEditing) { + else if (self.pickerController.allowsEditing) { UIImage *image = [[SDImageCache sharedImageCache] imageFromMemoryCacheForKey:metadata.sourceURL.absoluteString]; DZNPhotoEditorViewController *controller = [[DZNPhotoEditorViewController alloc] initWithImage:image]; - controller.cropMode = self.navigationController.cropMode; - controller.cropSize = self.navigationController.cropSize; + controller.cropMode = self.pickerController.cropMode; + controller.cropSize = self.pickerController.cropSize; [self.navigationController pushViewController:controller animated:YES]; @@ -486,7 +486,7 @@ - (void)selectedMetadata:(DZNPhotoMetadata *)metadata - (BOOL)canSearchTags { - if (!self.navigationController.allowAutoCompletedSearch) { + if (!self.pickerController.allowAutoCompletedSearch) { return NO; } @@ -644,7 +644,7 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView UIView *subview = nil; if ([self canDisplayFooterView]) { - if (self.isLoading || self.navigationController.infiniteScrollingEnabled) { + if (self.isLoading || self.pickerController.infiniteScrollingEnabled) { subview = self.activityIndicator; } else { @@ -686,7 +686,7 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { if ([elementKind isEqualToString:UICollectionElementKindSectionFooter]) { - if (self.navigationController.infiniteScrollingEnabled && [self canDisplayFooterView] && !self.isLoading) { + if (self.pickerController.infiniteScrollingEnabled && [self canDisplayFooterView] && !self.isLoading) { // It is important to schedule this call on the next run loop so it doesn't // interfere with the current scroll's run loop. @@ -901,7 +901,7 @@ - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView text = localizedDescription; } else if (!self.loading) { - if (self.navigationController.initialSearchTerm) + if (self.pickerController.initialSearchTerm) text = NSLocalizedString(@"Make sure that all words are\nspelled correctly.", nil); else text = nil; diff --git a/Source/Classes/Core/DZNPhotoPickerController.h b/Source/Classes/Core/DZNPhotoPickerController.h index 39c5232a..ce3a5b42 100644 --- a/Source/Classes/Core/DZNPhotoPickerController.h +++ b/Source/Classes/Core/DZNPhotoPickerController.h @@ -19,7 +19,7 @@ @discussion Due to Terms of Use of some photo services, the images can only be cached in memory, but not the device's hard drive. */ -@interface DZNPhotoPickerController : UINavigationController +@interface DZNPhotoPickerController : UIViewController typedef void (^DZNPhotoPickerControllerFinalizationBlock)(DZNPhotoPickerController *picker, NSDictionary *info); typedef void (^DZNPhotoPickerControllerFailureBlock)(DZNPhotoPickerController *picker, NSError *error); diff --git a/Source/Classes/Core/DZNPhotoPickerController.m b/Source/Classes/Core/DZNPhotoPickerController.m index 24569bdd..8bc883cb 100644 --- a/Source/Classes/Core/DZNPhotoPickerController.m +++ b/Source/Classes/Core/DZNPhotoPickerController.m @@ -21,6 +21,7 @@ @interface DZNPhotoPickerController () @property (nonatomic, getter=isEditModeEnabled) BOOL editModeEnabled; +@property (nonatomic, assign) BOOL firstAppear; @end @implementation DZNPhotoPickerController @@ -33,8 +34,9 @@ - (id)init self.allowsEditing = NO; self.enablePhotoDownload = YES; self.allowAutoCompletedSearch = YES; + self.firstAppear = YES; - self.supportedServices = DZNPhotoPickerControllerServiceGoogleImages | DZNPhotoPickerControllerServiceFlickr; + self.supportedServices = DZNPhotoPickerControllerServiceGoogleImages | DZNPhotoPickerControllerServiceFlickr | DZNPhotoPickerControllerServiceBingImages; self.supportedLicenses = DZNPhotoPickerControllerCCLicenseBY_ALL; self.cropMode = DZNPhotoEditorViewControllerCropModeSquare; } @@ -58,7 +60,8 @@ - (void)viewWillAppear:(BOOL)animated [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPickingPhoto:) name:DZNPhotoPickerDidFinishPickingNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFailPickingPhoto:) name:DZNPhotoPickerDidFailPickingNotification object:nil]; - if (!self.isEditModeEnabled) { + if (!self.isEditModeEnabled && self.firstAppear) { + self.firstAppear = NO; [self showPhotoDisplayController]; } } @@ -120,7 +123,6 @@ + (void)registerService:(DZNPhotoPickerControllerServices)service consumerKey:(N /* Shows the photo display controller. */ - (void)showPhotoDisplayController { - [self setViewControllers:@[]]; DZNPhotoDisplayViewController *controller = [[DZNPhotoDisplayViewController alloc] initWithPreferredContentSize:self.view.frame.size]; if (self.title) controller.title = self.title; @@ -130,7 +132,8 @@ - (void)showPhotoDisplayController [controller.navigationItem setRightBarButtonItem:cancel]; } - [self setViewControllers:@[controller]]; + [self addChildViewController:controller]; + [self.view addSubview:controller.view]; } /* Called by a notification whenever the user picks a photo. */ @@ -158,7 +161,7 @@ - (void)didFailPickingPhoto:(NSNotification *)notification /* Called whenever the user cancels the picker. */ - (void)cancelPicker:(id)sender { - DZNPhotoDisplayViewController *controller = (DZNPhotoDisplayViewController *)[self.viewControllers firstObject]; + DZNPhotoDisplayViewController *controller = (DZNPhotoDisplayViewController *)[self.childViewControllers firstObject]; if ([controller respondsToSelector:@selector(stopLoadingRequest)]) { [controller stopLoadingRequest]; } diff --git a/Source/Classes/UIImagePickerController/UIImagePickerController+Block.h b/Source/Classes/UIImagePickerController/UIImagePickerController+Block.h deleted file mode 100644 index 8554518e..00000000 --- a/Source/Classes/UIImagePickerController/UIImagePickerController+Block.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// UIImagePickerController+Block.h -// DZNPhotoPickerController -// https://github.com/dzenbot/DZNPhotoPickerController -// -// Created by Ignacio Romero Zurbuchen on 3/25/14. -// Copyright (c) 2014 DZN Labs. All rights reserved. -// Licence: MIT-Licence -// - -#import - -typedef void (^UIImagePickerControllerFinalizationBlock)(UIImagePickerController *picker, NSDictionary *info); -typedef void (^UIImagePickerControllerCancellationBlock)(UIImagePickerController *picker); - -/** - A category class adding block support to UIImagePickerController, replacing delegation implementation. - */ -@interface UIImagePickerController (Block) - -/** A block to be executed whenever the user picks a new photo. Use this block to replace delegate method imagePickerController:didFinishPickingPhotoWithInfo: */ -@property (nonatomic, strong) UIImagePickerControllerFinalizationBlock finalizationBlock; -/** A block to be executed whenever the user cancels the pick operation. Use this block to replace delegate method imagePickerControllerDidCancel: */ -@property (nonatomic, strong) UIImagePickerControllerCancellationBlock cancellationBlock; - -@end \ No newline at end of file diff --git a/Source/Classes/UIImagePickerController/UIImagePickerController+Block.m b/Source/Classes/UIImagePickerController/UIImagePickerController+Block.m deleted file mode 100644 index 68a25ffd..00000000 --- a/Source/Classes/UIImagePickerController/UIImagePickerController+Block.m +++ /dev/null @@ -1,74 +0,0 @@ -// -// UIImagePickerController+Block.h -// DZNPhotoPickerController -// https://github.com/dzenbot/DZNPhotoPickerController -// -// Created by Ignacio Romero Zurbuchen on 3/25/14. -// Copyright (c) 2014 DZN Labs. All rights reserved. -// Licence: MIT-Licence -// - -#import "UIImagePickerController+Block.h" -#import - -static char finalizationBlockKey; -static char cancelationBlockKey; - -@interface UIImagePickerController () -@end - -@implementation UIImagePickerController (Block) - -#pragma mark - Getter methods - -- (UIImagePickerControllerFinalizationBlock)finalizationBlock -{ - return objc_getAssociatedObject(self, &finalizationBlockKey); -} - -- (UIImagePickerControllerCancellationBlock)cancellationBlock -{ - return objc_getAssociatedObject(self, &cancelationBlockKey); -} - - -#pragma mark - Setter methods - -- (void)setFinalizationBlock:(UIImagePickerControllerFinalizationBlock)block -{ - if (!block) { - return; - } - - self.delegate = self; - objc_setAssociatedObject(self, &finalizationBlockKey, block, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -- (void)setCancellationBlock:(UIImagePickerControllerCancellationBlock)block -{ - if (!block) { - return; - } - - self.delegate = self; - objc_setAssociatedObject(self, &cancelationBlockKey, block, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - - -#pragma mark - UIImagePickerControllerDelegate methods - -- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info -{ - if (self.finalizationBlock) { - self.finalizationBlock(self, info); - } -} - -- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker -{ - if (self.cancellationBlock) { - self.cancellationBlock(self); - } -} - -@end \ No newline at end of file From b4ea2912a1c3841bbf3ac080f831073542d3ae6a Mon Sep 17 00:00:00 2001 From: Robert Johnson Date: Fri, 19 May 2017 15:53:47 -0500 Subject: [PATCH 07/11] Show activity indicator when downloading images --- .../Core/DZNPhotoDisplayViewController.m | 25 ++++++++++--------- .../Classes/Core/DZNPhotoPickerController.h | 4 +++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index 17ee0f9b..8a3c7bd2 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -465,21 +465,22 @@ - (void)selectedMetadata:(DZNPhotoMetadata *)metadata } } else { - [self setActivityIndicatorsVisible:YES]; - + self.pickerController.activityBlock(self.pickerController, YES); [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:metadata.sourceURL options:SDWebImageCacheMemoryOnly|SDWebImageRetryFailed progress:NULL - completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished){ - if (image) { - NSDictionary *userInfo = @{UIImagePickerControllerOriginalImage: image}; - [metadata postMetadataUpdate:userInfo]; - } - else { - [self setLoadingError:error]; - } - - [self setActivityIndicatorsVisible:NO]; + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (image) { + NSDictionary *userInfo = @{UIImagePickerControllerOriginalImage: image}; + [metadata postMetadataUpdate:userInfo]; + } + else { + [self setLoadingError:error]; + } + + self.pickerController.activityBlock(self.pickerController, NO); + }); }]; } } diff --git a/Source/Classes/Core/DZNPhotoPickerController.h b/Source/Classes/Core/DZNPhotoPickerController.h index ce3a5b42..4b9878f9 100644 --- a/Source/Classes/Core/DZNPhotoPickerController.h +++ b/Source/Classes/Core/DZNPhotoPickerController.h @@ -21,6 +21,7 @@ */ @interface DZNPhotoPickerController : UIViewController +typedef void (^DZNPhotoPickerControllerActivityBlock)(DZNPhotoPickerController *picker, BOOL show); typedef void (^DZNPhotoPickerControllerFinalizationBlock)(DZNPhotoPickerController *picker, NSDictionary *info); typedef void (^DZNPhotoPickerControllerFailureBlock)(DZNPhotoPickerController *picker, NSError *error); typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerController *picker); @@ -41,6 +42,9 @@ typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerControll @property (nonatomic) DZNPhotoPickerControllerCCLicenses supportedLicenses; /** YES if the picker should download the full size photo after selecting its thumbnail, when allowsEditing is NO. Default is YES. */ @property (nonatomic) BOOL enablePhotoDownload; + +@property (nonatomic, strong) DZNPhotoPickerControllerActivityBlock activityBlock; + /** A block to be executed whenever the user pickes a new photo. Use this block to replace delegate method photoPickerController:didFinishPickingPhotoWithInfo: */ @property (nonatomic, strong) DZNPhotoPickerControllerFinalizationBlock finalizationBlock; /** A block to be executed whenever an error occurs while picking a photo. Use this block to replace delegate method photoPickerController:didFailedPickingPhotoWithError: */ From 7e390b7c915fde0b6fbc181b781a68672d1b6f55 Mon Sep 17 00:00:00 2001 From: Robert Johnson Date: Sun, 21 May 2017 15:19:08 -0500 Subject: [PATCH 08/11] Automatically show keyboard when opening web image search --- Source/Classes/Core/DZNPhotoDisplayViewController.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index 8a3c7bd2..ea54223c 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -128,6 +128,17 @@ - (void)viewWillAppear:(BOOL)animated } } +- (void) viewDidAppear:(BOOL)animated +{ + [super viewDidAppear:animated]; + + if (([self.searchController.searchBar.text length] == 0) && (self.metadataList.count == 0)) { + // Calling becomeFirstResponder directly doesn't open the keybord for some reason + dispatch_async(dispatch_get_main_queue(), ^{ + [self.searchController.searchBar becomeFirstResponder]; + }); + } +} #pragma mark - Getter methods From 46df6c2480d03060776e69c1fcb7bdde375a1cc4 Mon Sep 17 00:00:00 2001 From: ebalassanian Date: Tue, 14 Nov 2017 09:29:19 -0600 Subject: [PATCH 09/11] Update DZNPhotoPickerController.podspec --- DZNPhotoPickerController.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DZNPhotoPickerController.podspec b/DZNPhotoPickerController.podspec index 707bdbde..6b901a53 100644 --- a/DZNPhotoPickerController.podspec +++ b/DZNPhotoPickerController.podspec @@ -23,7 +23,7 @@ Pod::Spec.new do |s| ss.source_files = 'Source/Classes/Core/*.{h,m}' ss.dependency 'DZNPhotoPickerController/Services' ss.dependency 'DZNPhotoPickerController/Editor' - ss.dependency 'SDWebImage', '~> 3.7' + ss.dependency 'SDWebImage', '~> 4.0' ss.dependency 'DZNEmptyDataSet', '~> 1.7' end From 050c3be9921aa1064ef7582afa51d0e5153fd23c Mon Sep 17 00:00:00 2001 From: ebalassanian Date: Thu, 4 Jan 2018 13:19:33 -0600 Subject: [PATCH 10/11] Update DZNPhotoDisplayViewCell.m --- Source/Classes/Core/DZNPhotoDisplayViewCell.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Classes/Core/DZNPhotoDisplayViewCell.m b/Source/Classes/Core/DZNPhotoDisplayViewCell.m index 2498dc12..ee0fc0bd 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewCell.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewCell.m @@ -10,6 +10,7 @@ #import "DZNPhotoDisplayViewCell.h" #import "UIImageView+WebCache.h" +#import "UIView+WebCache.h" @implementation DZNPhotoDisplayViewCell @synthesize imageView = _imageView; From 3243b22ab32fd7b4c89b10dc5439fb043fdf98f0 Mon Sep 17 00:00:00 2001 From: Eddie Saenz Date: Thu, 8 Feb 2018 15:13:07 -0600 Subject: [PATCH 11/11] Rebase w/ master & finish child vc setup to fix ipad display bug --- Source/Classes/Core/DZNPhotoPickerController.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/Classes/Core/DZNPhotoPickerController.m b/Source/Classes/Core/DZNPhotoPickerController.m index 8bc883cb..e01f9385 100644 --- a/Source/Classes/Core/DZNPhotoPickerController.m +++ b/Source/Classes/Core/DZNPhotoPickerController.m @@ -134,6 +134,14 @@ - (void)showPhotoDisplayController [self addChildViewController:controller]; [self.view addSubview:controller.view]; + + controller.view.translatesAutoresizingMaskIntoConstraints = false; + [NSLayoutConstraint activateConstraints:@[[controller.view.topAnchor constraintEqualToAnchor:self.view.topAnchor], + [controller.view.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], + [controller.view.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], + [controller.view.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor]]]; + + [controller didMoveToParentViewController:self]; } /* Called by a notification whenever the user picks a photo. */