Skip to content

Commit

Permalink
Disabled action button for videos
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaterfall committed Jul 8, 2015
1 parent 7a5fdd6 commit 3eb597f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
101 changes: 52 additions & 49 deletions Pod/Classes/MWPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,16 @@ - (void)updateNavigation {
// Buttons
_previousButton.enabled = (_currentPageIndex > 0);
_nextButton.enabled = (_currentPageIndex < numberOfPhotos - 1);
_actionButton.enabled = [[self photoAtIndex:_currentPageIndex] underlyingImage] != nil;

// Disable action button if there is no image or it's a video
MWPhoto *photo = [self photoAtIndex:_currentPageIndex];
if ([photo underlyingImage] == nil || ([photo respondsToSelector:@selector(isVideo)] && photo.isVideo)) {
_actionButton.enabled = NO;
_actionButton.tintColor = [UIColor clearColor]; // Tint to hide button
} else {
_actionButton.enabled = YES;
_actionButton.tintColor = nil;
}

}

Expand Down Expand Up @@ -1529,61 +1538,55 @@ - (void)doneButtonPressed:(id)sender {
#pragma mark - Actions

- (void)actionButtonPressed:(id)sender {
if (_actionsSheet) {

// Dismiss
[_actionsSheet dismissWithClickedButtonIndex:_actionsSheet.cancelButtonIndex animated:YES];

} else {

// Only react when image has loaded
id <MWPhoto> photo = [self photoAtIndex:_currentPageIndex];
if ([self numberOfPhotos] > 0 && [photo underlyingImage]) {

// Only react when image has loaded
id <MWPhoto> photo = [self photoAtIndex:_currentPageIndex];
if ([self numberOfPhotos] > 0 && [photo underlyingImage]) {
// If they have defined a delegate method then just message them
if ([self.delegate respondsToSelector:@selector(photoBrowser:actionButtonPressedForPhotoAtIndex:)]) {

// If they have defined a delegate method then just message them
if ([self.delegate respondsToSelector:@selector(photoBrowser:actionButtonPressedForPhotoAtIndex:)]) {

// Let delegate handle things
[self.delegate photoBrowser:self actionButtonPressedForPhotoAtIndex:_currentPageIndex];

} else {

// Show activity view controller
NSMutableArray *items = [NSMutableArray arrayWithObject:[photo underlyingImage]];
if (photo.caption) {
[items addObject:photo.caption];
}
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];

// Show loading spinner after a couple of seconds
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if (self.activityViewController) {
[self showProgressHUDWithMessage:nil];
}
});

// Show
typeof(self) __weak weakSelf = self;
[self.activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
weakSelf.activityViewController = nil;
[weakSelf hideControlsAfterDelay];
[weakSelf hideProgressHUD:YES];
}];
// iOS 8 - Set the Anchor Point for the popover
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8")) {
self.activityViewController.popoverPresentationController.barButtonItem = _actionButton;
}
[self presentViewController:self.activityViewController animated:YES completion:nil];

// Let delegate handle things
[self.delegate photoBrowser:self actionButtonPressedForPhotoAtIndex:_currentPageIndex];

} else {

// Show activity view controller
NSMutableArray *items = [NSMutableArray arrayWithObject:[photo underlyingImage]];
if (photo.caption) {
[items addObject:photo.caption];
}
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];

// Keep controls hidden
[self setControlsHidden:NO animated:YES permanent:YES];
// Show loading spinner after a couple of seconds
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if (self.activityViewController) {
[self showProgressHUDWithMessage:nil];
}
});

// Show
typeof(self) __weak weakSelf = self;
[self.activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
weakSelf.activityViewController = nil;
[weakSelf hideControlsAfterDelay];
[weakSelf hideProgressHUD:YES];
}];
// iOS 8 - Set the Anchor Point for the popover
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8")) {
self.activityViewController.popoverPresentationController.barButtonItem = _actionButton;
}
[self presentViewController:self.activityViewController animated:YES completion:nil];

}

// Keep controls hidden
[self setControlsHidden:NO animated:YES permanent:YES];

}

}

#pragma mark - Action Progress
Expand Down
1 change: 0 additions & 1 deletion Pod/Classes/MWPhotoBrowserPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
NSTimer *_controlVisibilityTimer;
UIBarButtonItem *_previousButton, *_nextButton, *_actionButton, *_doneButton;
MBProgressHUD *_progressHUD;
UIActionSheet *_actionsSheet;

// Grid
MWGridViewController *_gridController;
Expand Down

0 comments on commit 3eb597f

Please sign in to comment.