Skip to content

Commit

Permalink
Added toolbar for downloading and deleting a selection of images on i…
Browse files Browse the repository at this point in the history
…Phone in portrait
  • Loading branch information
EddyLB committed Jul 7, 2018
1 parent e234a89 commit fe0416b
Showing 1 changed file with 64 additions and 29 deletions.
93 changes: 64 additions & 29 deletions piwigo/Albums/AlbumImagesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

CGFloat const kRadius = 25.0;

@interface AlbumImagesViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIGestureRecognizerDelegate, ImageDetailDelegate, CategorySortDelegate, CategoryCollectionViewCellDelegate>
@interface AlbumImagesViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIGestureRecognizerDelegate, UIToolbarDelegate, ImageDetailDelegate, CategorySortDelegate, CategoryCollectionViewCellDelegate>

@property (nonatomic, strong) UICollectionView *imagesCollection;
@property (nonatomic, strong) AlbumData *albumData;
Expand All @@ -49,6 +49,7 @@ @interface AlbumImagesViewController () <UICollectionViewDelegate, UICollectionV
@property (nonatomic, strong) UIBarButtonItem *settingsBarButton;
@property (nonatomic, strong) UIBarButtonItem *selectBarButton;
@property (nonatomic, strong) UIBarButtonItem *cancelBarButton;
@property (nonatomic, strong) UIBarButtonItem *spaceBetweenButtons;
@property (nonatomic, strong) UIBarButtonItem *deleteBarButton;
@property (nonatomic, strong) UIBarButtonItem *downloadBarButton;
@property (nonatomic, strong) UIButton *uploadButton;
Expand Down Expand Up @@ -111,9 +112,14 @@ -(instancetype)initWithAlbumId:(NSInteger)albumId inCache:(BOOL)isCached
self.settingsBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"preferences"] style:UIBarButtonItemStylePlain target:self action:@selector(displayPreferences)];
self.selectBarButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"categoryImageList_selectButton", @"Select") style:UIBarButtonItemStylePlain target:self action:@selector(select)];
self.cancelBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelSelect)];
self.spaceBetweenButtons = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(deleteImages)];
self.deleteBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteImages)];
self.deleteBarButton.tintColor = [UIColor redColor];
self.downloadBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"download"] style:UIBarButtonItemStylePlain target:self action:@selector(downloadImages)];

self.downloadBarButton.tintColor = [UIColor piwigoOrange];
self.navigationController.toolbar.barStyle = UIBarStyleDefault;
self.navigationController.toolbarHidden = YES;

// Upload button above collection view
self.uploadButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGFloat xPos = [UIScreen mainScreen].bounds.size.width - 3*kRadius;
Expand Down Expand Up @@ -298,19 +304,23 @@ -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIVie

//Reload the tableview on orientation change, to match the new width of the table.
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
CGFloat xPos = [UIScreen mainScreen].bounds.size.width - 3*kRadius;
CGFloat yPos = [UIScreen mainScreen].bounds.size.height - 3*kRadius;
self.uploadButton.frame = CGRectMake(xPos, yPos, 2*kRadius, 2*kRadius);
self.homeAlbumButton.frame = CGRectMake(xPos - 3*kRadius, yPos, 2*kRadius, 2*kRadius);
[self updateNavBar];
[self.imagesCollection reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)]];
} completion:nil];
}

-(void)updateNavBar
{
// For positioning the buttons
CGFloat xPos = [UIScreen mainScreen].bounds.size.width - 3*kRadius;
CGFloat yPos = [UIScreen mainScreen].bounds.size.height - 3*kRadius;

// Update buttons
if(!self.isSelect) { // Image selection mode inactive

// Hide toolbar
self.navigationController.toolbarHidden = NO;

// Title is name of the category
if (self.categoryId == 0) {
self.title = NSLocalizedString(@"tabBar_albums", @"Albums");
Expand All @@ -325,6 +335,7 @@ -(void)updateNavBar
([Model sharedInstance].usesCommunityPluginV29 && [Model sharedInstance].hadOpenedSession))
{
// Show Upload button
self.uploadButton.frame = CGRectMake(xPos, yPos, 2*kRadius, 2*kRadius);
[self.uploadButton setHidden:NO];
}

Expand All @@ -337,8 +348,6 @@ -(void)updateNavBar
else
{
// Display Home button
CGFloat xPos = self.uploadButton.frame.origin.x;
CGFloat yPos = self.uploadButton.frame.origin.y;
self.homeAlbumButton.frame = CGRectMake(xPos - 3*kRadius, yPos, 2*kRadius, 2*kRadius);
[self.homeAlbumButton setHidden:NO];
}
Expand Down Expand Up @@ -367,14 +376,12 @@ -(void)updateNavBar
// No images: no button
[self.navigationItem setRightBarButtonItems:@[] animated:YES];
}

// No toolbar
self.navigationController.toolbarHidden = YES;
}
else { // Image selection mode active

// Hide back button item and upload button
[self.navigationItem setHidesBackButton:YES];
[self.uploadButton setHidden:YES];
[self.homeAlbumButton setHidden:YES];

// Update title
switch (self.selectedImageIds.count) {
case 0:
Expand All @@ -389,27 +396,55 @@ -(void)updateNavBar
self.title = [NSString stringWithFormat:NSLocalizedString(@"selectImagesSelected", @"%@ Images Selected"), @(self.selectedImageIds.count)];
break;
}

// Hide back, Settings, Upload and Home buttons
[self.navigationItem setHidesBackButton:YES];
[self.uploadButton setHidden:YES];
[self.homeAlbumButton setHidden:YES];

// Interface depends on device and orientation
if ( UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]) &&
([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)) {

// Hide navigation bar buttons and use a toolbar
[self.navigationItem setLeftBarButtonItems:@[] animated:YES];

// Update buttons
if([Model sharedInstance].hasAdminRights)
// Redefine bar buttons (definition lost after rotation of the device)
self.spaceBetweenButtons = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(deleteImages)];
self.deleteBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteImages)];
self.deleteBarButton.tintColor = [UIColor redColor];
self.downloadBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"download"] style:UIBarButtonItemStylePlain target:self action:@selector(downloadImages)];
self.downloadBarButton.tintColor = [UIColor piwigoOrange];

// Present toolbar
self.navigationController.toolbarHidden = NO;
if([Model sharedInstance].hasAdminRights)
{
// Only admins have delete rights
self.toolbarItems = @[self.downloadBarButton, self.spaceBetweenButtons, self.deleteBarButton];
self.downloadBarButton.enabled = (self.selectedImageIds.count > 0);
self.deleteBarButton.enabled = (self.selectedImageIds.count > 0);
}
else {
// No admin rights
self.toolbarItems = @[self.spaceBetweenButtons, self.downloadBarButton, self.spaceBetweenButtons];
self.downloadBarButton.enabled = (self.selectedImageIds.count > 0);
}
}
else // iPhone in landscape mode, iPad in any orientation
{
// Only admins have delete rights
if (self.selectedImageIds.count > 0) {
// Images selected
// Present buttons in the navigation bar
if([Model sharedInstance].hasAdminRights)
{
// Only admins have delete rights
[self.navigationItem setLeftBarButtonItems:@[self.downloadBarButton, self.deleteBarButton] animated:YES];
} else {
// No images selected
[self.navigationItem setLeftBarButtonItems:@[] animated:YES];
self.downloadBarButton.enabled = (self.selectedImageIds.count > 0);
self.deleteBarButton.enabled = (self.selectedImageIds.count > 0);
}
}
else {
// No admin rights
if (self.selectedImageIds.count > 0) {
// Images selected
else {
// No admin rights
[self.navigationItem setLeftBarButtonItems:@[self.downloadBarButton] animated:YES];
} else {
// No images selected
[self.navigationItem setLeftBarButtonItems:@[] animated:YES];
self.downloadBarButton.enabled = (self.selectedImageIds.count > 0);
}
}

Expand Down

1 comment on commit fe0416b

@EddyLB
Copy link
Collaborator Author

@EddyLB EddyLB commented on fe0416b Jul 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #68

Please sign in to comment.