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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
+ Allow single selection of items
  • Loading branch information
jfmiguel committed Jun 19, 2016
commit eba4e7b6be1c7da25fedd5681aedcd310ebdeea2
1 change: 1 addition & 0 deletions FacebookImagePicker/OLAlbumViewController.h
Original file line number Diff line number Diff line change
@@ -23,4 +23,5 @@
@property (nonatomic, weak) id<OLAlbumViewControllerDelegate> delegate;
@property (nonatomic, strong) NSArray/*<OLFacebookImage>*/ *selected;
@property (nonatomic, assign) BOOL shouldDisplayLogoutButton;
@property (nonatomic, assign) BOOL isMultiselectEnabled;
@end
11 changes: 10 additions & 1 deletion FacebookImagePicker/OLAlbumViewController.m
Original file line number Diff line number Diff line change
@@ -120,6 +120,11 @@ - (void)viewDidAppear:(BOOL)animated {
}
}

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

- (void)setShouldDisplayLogoutButton:(BOOL)shouldDisplayLogoutButton
{
_shouldDisplayLogoutButton = shouldDisplayLogoutButton;
@@ -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];
@@ -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];
}
2 changes: 2 additions & 0 deletions FacebookImagePicker/OLFacebookImagePickerController.h
Original file line number Diff line number Diff line change
@@ -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
@@ -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];
}
@@ -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];
}
@@ -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;
1 change: 1 addition & 0 deletions FacebookImagePicker/OLPhotoViewController.h
Original file line number Diff line number Diff line change
@@ -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
@@ -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];
@@ -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;
@@ -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]];
}