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

added option to single select items #34

Open
wants to merge 4 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FacebookImagePicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Pod::Spec.new do |s|
}
s.source_files = ['FacebookImagePicker/OL*.{h,m}', 'FacebookImagePicker/UIImageView+FacebookFadeIn.{h,m}']
s.resources = ['FacebookImagePicker/FacebookImagePicker.xcassets', 'FacebookImagePicker/*.xib']
s.dependency 'FBSDKCoreKit', '~> 4.11.0'
s.dependency 'FBSDKLoginKit', '~> 4.11.0'
s.dependency 'FBSDKCoreKit'#, '~> 4.13.1'
s.dependency 'FBSDKLoginKit'#, '~> 4.13.1'
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "CTAssetsPickerChecked.png"
"filename" : "CTAssetsPickerChecked.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "CTAssetsPickerChecked~iOS6.png"
"filename" : "CTAssetsPickerChecked~iOS6.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
Expand Down
4 changes: 4 additions & 0 deletions FacebookImagePicker/OLAlbumViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
@class OLAlbumViewController;
@class OLFacebookImage;

@interface OLAlbumCell : UITableViewCell
@end

@protocol OLAlbumViewControllerDelegate <NSObject>
- (void)albumViewControllerDoneClicked:(OLAlbumViewController *)albumController;
- (void)albumViewController:(OLAlbumViewController *)albumController didFailWithError:(NSError *)error;
Expand All @@ -23,4 +26,5 @@
@property (nonatomic, weak) id<OLAlbumViewControllerDelegate> delegate;
@property (nonatomic, strong) NSArray/*<OLFacebookImage>*/ *selected;
@property (nonatomic, assign) BOOL shouldDisplayLogoutButton;
@property (nonatomic, assign) BOOL isMultiselectEnabled;
@end
13 changes: 11 additions & 2 deletions FacebookImagePicker/OLAlbumViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

static const NSUInteger kAlbumPreviewImageSize = 78;

@interface OLAlbumCell : UITableViewCell
@interface OLAlbumCell ()
@property (nonatomic, strong) OLFacebookAlbum *album;
@end

Expand Down Expand Up @@ -120,6 +120,11 @@ - (void)viewDidAppear:(BOOL)animated {
}
}

- (void)setIsMultiselectEnabled:(BOOL)isMultiselectEnabled
{
_isMultiselectEnabled = isMultiselectEnabled;
}

- (void)setShouldDisplayLogoutButton:(BOOL)shouldDisplayLogoutButton
{
_shouldDisplayLogoutButton = shouldDisplayLogoutButton;
Expand Down Expand Up @@ -230,6 +235,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
OLFacebookAlbum *album = [self.albums objectAtIndex:indexPath.row];
self.photoViewController = [[OLPhotoViewController alloc] initWithAlbum:album];
self.photoViewController.isMultiselectEnabled = self.isMultiselectEnabled;
self.photoViewController.selected = self.selected;
self.photoViewController.delegate = self;
[self.navigationController pushViewController:self.photoViewController animated:YES];
Expand Down Expand Up @@ -257,7 +263,10 @@ - (void)photoViewController:(OLPhotoViewController *)photoController didFailWith
}

- (void)photoViewController:(OLPhotoViewController *)photoController didSelectImage:(OLFacebookImage *)image{
[self updateSelectedFromPhotoViewController];
if(self.isMultiselectEnabled) {
[self updateSelectedFromPhotoViewController];
}

if ([self.delegate respondsToSelector:@selector(albumViewController:didSelectImage:)]){
[self.delegate albumViewController:self didSelectImage:image];
}
Expand Down
2 changes: 2 additions & 0 deletions FacebookImagePicker/OLFacebookImagePickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@

@property (nonatomic, assign) BOOL shouldDisplayLogoutButton;

@property (nonatomic, assign) BOOL isMultiselectEnabled;

@end
8 changes: 8 additions & 0 deletions FacebookImagePicker/OLFacebookImagePickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ - (id)init {
vc.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonClicked)];
if (self = [super initWithRootViewController:vc]) {
_shouldDisplayLogoutButton = YES;
_isMultiselectEnabled = YES;
if ([FBSDKAccessToken currentAccessToken]){
[self showAlbumList];
}
Expand Down Expand Up @@ -68,6 +69,7 @@ - (void)showAlbumList{
OLAlbumViewController *albumController = [[OLAlbumViewController alloc] init];
self.albumVC = albumController;
self.albumVC.delegate = self;
self.albumVC.isMultiselectEnabled = self.isMultiselectEnabled;
self.albumVC.shouldDisplayLogoutButton = self.shouldDisplayLogoutButton;
self.viewControllers = @[albumController];
}
Expand All @@ -80,6 +82,12 @@ - (NSArray *)selected {
return self.albumVC.selected;
}

- (void)setIsMultiselectEnabled:(BOOL)isMultiselectEnabled
{
_isMultiselectEnabled = isMultiselectEnabled;
self.albumVC.isMultiselectEnabled = self.isMultiselectEnabled;
}

- (void)setShouldDisplayLogoutButton:(BOOL)shouldDisplayLogoutButton
{
_shouldDisplayLogoutButton = shouldDisplayLogoutButton;
Expand Down
1 change: 1 addition & 0 deletions FacebookImagePicker/OLPhotoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@

@property (nonatomic, weak) id<OLPhotoViewControllerDelegate> delegate;
@property (nonatomic, strong) NSArray/*<OLFacebookImage>*/ *selected;
@property (nonatomic, assign) BOOL isMultiselectEnabled;

@end
16 changes: 14 additions & 2 deletions FacebookImagePicker/OLPhotoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (void)viewDidLoad {
layout.minimumLineSpacing = 1.0;
layout.footerReferenceSize = CGSizeMake(0, 0);
self.collectionView.collectionViewLayout = layout;
self.collectionView.allowsMultipleSelection = YES;
self.collectionView.allowsMultipleSelection = self.isMultiselectEnabled;

[self.collectionView registerClass:[OLFacebookImagePickerCell class] forCellWithReuseIdentifier:kImagePickerCellReuseIdentifier];
[self.collectionView registerClass:[SupplementaryView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:kSupplementaryViewFooterReuseIdentifier];
Expand All @@ -69,6 +69,12 @@ - (void)viewDidLoad {
[self loadNextPage];
}

- (void) setIsMultiselectEnabled:(BOOL)isMultiselectEnabled
{
_isMultiselectEnabled = isMultiselectEnabled;
self.collectionView.allowsMultipleSelection = isMultiselectEnabled;
}

- (NSArray *)selected {
NSMutableArray *selectedItems = [[NSMutableArray alloc] init];
NSArray *selectedPaths = self.collectionView.indexPathsForSelectedItems;
Expand Down Expand Up @@ -204,7 +210,13 @@ -(void) collectionView:(UICollectionView *)collectionView didDeselectItemAtIndex
}

-(void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
[self updateTitleWithSelectedIndexPaths:collectionView.indexPathsForSelectedItems];
if(self.isMultiselectEnabled) {
[self updateTitleWithSelectedIndexPaths:collectionView.indexPathsForSelectedItems];

} else {
[collectionView deselectItemAtIndexPath:indexPath animated:NO];
}

if ([self.delegate respondsToSelector:@selector(photoViewController:didSelectImage:)]){
[self.delegate photoViewController:self didSelectImage:[self.photos objectAtIndex:indexPath.item]];
}
Expand Down