diff --git a/Pod/Assets/.gitkeep b/Pod/Assets/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/Pod/Classes/.gitkeep b/Pod/Classes/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/Pod/Classes/MWPhotoBrowser.h b/Pod/Classes/MWPhotoBrowser.h index 4225f9cc1..91c12eef6 100644 --- a/Pod/Classes/MWPhotoBrowser.h +++ b/Pod/Classes/MWPhotoBrowser.h @@ -38,9 +38,21 @@ @end -@interface MWPhotoBrowser : UIViewController +@protocol MWProfilePhotosLikeActions + +- (BOOL)canShowLikeAnimation; +- (NSUInteger)likesCount:(NSInteger)photoIndex; +- (BOOL)isLiked:(NSInteger)photoIndex; +- (void)likePhoto:(NSInteger)photoIndex like:(BOOL)like; +- (void)showLikes:(NSInteger)photoIndex; +- (void)removeLikesView; + +@end + +@interface MWPhotoBrowser : UIViewController @property (nonatomic, weak) IBOutlet id delegate; +@property (nonatomic, weak) id fullscreenPhotoDelegate; @property (nonatomic) BOOL zoomPhotosToFill; @property (nonatomic) BOOL displayNavArrows; @property (nonatomic) BOOL displayActionButton; @@ -52,6 +64,10 @@ @property (nonatomic) BOOL autoPlayOnAppear; @property (nonatomic) NSUInteger delayToHideElements; @property (nonatomic, readonly) NSUInteger currentIndex; +@property (nonatomic) NSUInteger currentPageIndex; +@property (nonatomic) BOOL showShareButton; +@property (nonatomic) BOOL showLikesContainer; +@property (nonatomic, copy) void(^onShareButtonTappedBlock)(UIButton *button); // Customise image selection icons as they are the only icons with a colour tint // Icon should be located in the app's main bundle @@ -72,4 +88,8 @@ - (void)showNextPhotoAnimated:(BOOL)animated; - (void)showPreviousPhotoAnimated:(BOOL)animated; +// Like button +- (void)likeButtonPressed; +- (void)update; + @end diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index 0de7faaab..ca6198dd1 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -99,6 +99,7 @@ - (void)dealloc { [[SDImageCache sharedImageCache] clearMemory]; // clear memory } + - (void)releaseAllUnderlyingPhotos:(BOOL)preserveCurrent { // Create a copy in case this array is modified while we are looping through // Release photos @@ -158,7 +159,46 @@ - (void)viewDidLoad { _pagingScrollView.backgroundColor = [UIColor blackColor]; _pagingScrollView.contentSize = [self contentSizeForPagingScrollView]; [self.view addSubview:_pagingScrollView]; - + + if (self.showLikesContainer) { + // Setup likes container under scroll view + CGRect likesContainerRect = [self frameForLikesContainer]; + _likesContainer = [[UIView alloc] initWithFrame:likesContainerRect]; + _likesContainer.backgroundColor = [UIColor clearColor]; + [self.view addSubview:_likesContainer]; + + // Setup like button + CGRect likesButtonRect = [self frameForLikeButton]; + _likesButton = [[UIButton alloc] initWithFrame:likesButtonRect]; + [_likesButton setImage:[UIImage imageNamed:@"like_unselected"] forState:UIControlStateNormal]; + [_likesButton setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected]; + [_likesButton addTarget:self action:@selector(likeButtonPressed) forControlEvents:UIControlEventTouchUpInside]; + [_likesContainer addSubview:_likesButton]; + + // Setup like label + CGRect likesLabelRect = [self frameForLikesLabel]; + _likesLabel = [[UILabel alloc] initWithFrame:likesLabelRect]; + [_likesLabel setFont:[UIFont systemFontOfSize:20]]; + [_likesLabel setUserInteractionEnabled:YES]; + UITapGestureRecognizer *tapOnLikesLabel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showLikesView)]; + tapOnLikesLabel.delegate = self; + [_likesLabel addGestureRecognizer:tapOnLikesLabel]; + _likesLabel.textColor = [UIColor colorWithRed:172.0/255.0 green:172.0/255.0 blue:172.0/255.0 alpha:1]; + _likesLabel.numberOfLines = 1; + [_likesContainer addSubview:_likesLabel]; + } + + /// + if (self.showShareButton) { + CGRect shareButtonFrame = [self frameForShareButton]; + UIButton *shareButton = [[UIButton alloc] initWithFrame:shareButtonFrame]; + [shareButton setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal]; + [shareButton addTarget:self action:@selector(onShareButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [self.view addSubview:shareButton]; + } + + /// + // Toolbar _toolbar = [[UIToolbar alloc] initWithFrame:[self frameForToolbarAtOrientation:self.interfaceOrientation]]; _toolbar.tintColor = [UIColor whiteColor]; @@ -177,7 +217,8 @@ - (void)viewDidLoad { _nextButton = [[UIBarButtonItem alloc] initWithImage:nextButtonImage style:UIBarButtonItemStylePlain target:self action:@selector(gotoNextPage)]; } if (self.displayActionButton) { - _actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionButtonPressed:)]; + UIImage *imageForButton = [UIImage imageNamed:@"three_dots"]; + _actionButton = [[UIBarButtonItem alloc] initWithImage:imageForButton style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)]; } // Update @@ -190,6 +231,11 @@ - (void)viewDidLoad { [self.view addGestureRecognizer:swipeGesture]; } + float version = [[[UIDevice currentDevice] systemVersion] floatValue]; + if (version < 11.0) { + [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, -60) forBarMetrics:UIBarMetricsDefault]; + } + // Super [super viewDidLoad]; @@ -219,6 +265,7 @@ - (void)performLayout { self.navigationItem.rightBarButtonItem = _doneButton; } else { // We're not first so show back button + UIViewController *previousViewController = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2]; NSString *backButtonTitle = previousViewController.navigationItem.backBarButtonItem ? previousViewController.navigationItem.backBarButtonItem.title : previousViewController.title; UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:backButtonTitle style:UIBarButtonItemStylePlain target:nil action:nil]; @@ -299,12 +346,16 @@ - (void)performLayout { - (void)viewDidUnload { _currentPageIndex = 0; _pagingScrollView = nil; + _likesContainer = nil; + _likesLabel = nil; + _likesButton = nil; _visiblePages = nil; _recycledPages = nil; _toolbar = nil; _previousButton = nil; _nextButton = nil; _progressHUD = nil; + [super viewDidUnload]; } @@ -398,19 +449,12 @@ - (void)viewWillDisappear:(BOOL)animated { // Detect if rotation occurs while we're presenting a modal _pageIndexBeforeRotation = _currentPageIndex; - // Check that we're disappearing for good - // self.isMovingFromParentViewController just doesn't work, ever. Or self.isBeingDismissed - if ((_doneButton && self.navigationController.isBeingDismissed) || - ([self.navigationController.viewControllers objectAtIndex:0] != self && ![self.navigationController.viewControllers containsObject:self])) { - - // State - _viewIsActive = NO; - [self clearCurrentVideo]; // Clear current playing video - - // Bar state / appearance - [self restorePreviousNavBarAppearance:animated]; - - } + // State + _viewIsActive = NO; + [self clearCurrentVideo]; // Clear current playing video + + // Bar state / appearance + [self restorePreviousNavBarAppearance:animated]; // Controls [self.navigationController.navigationBar.layer removeAllAnimations]; // Stop all animations on nav bar @@ -431,6 +475,9 @@ - (void)willMoveToParentViewController:(UIViewController *)parent { if (parent && _hasBelongedToViewController) { [NSException raise:@"MWPhotoBrowser Instance Reuse" format:@"MWPhotoBrowser instances cannot be reused."]; } + + // Bar state / appearance + [self restorePreviousNavBarAppearance:YES]; } - (void)didMoveToParentViewController:(UIViewController *)parent { @@ -442,17 +489,17 @@ - (void)didMoveToParentViewController:(UIViewController *)parent { - (void)setNavBarAppearance:(BOOL)animated { [self.navigationController setNavigationBarHidden:NO animated:animated]; UINavigationBar *navBar = self.navigationController.navigationBar; - navBar.tintColor = [UIColor whiteColor]; - navBar.barTintColor = nil; navBar.shadowImage = nil; navBar.translucent = YES; navBar.barStyle = UIBarStyleBlackTranslucent; + navBar.titleTextAttributes = nil; [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsLandscapePhone]; } - (void)storePreviousNavBarAppearance { _didSavePreviousStateOfNavBar = YES; + _previousNavBarTitleAttributes = self.navigationController.navigationBar.titleTextAttributes; _previousNavBarBarTintColor = self.navigationController.navigationBar.barTintColor; _previousNavBarTranslucent = self.navigationController.navigationBar.translucent; _previousNavBarTintColor = self.navigationController.navigationBar.tintColor; @@ -465,11 +512,13 @@ - (void)storePreviousNavBarAppearance { - (void)restorePreviousNavBarAppearance:(BOOL)animated { if (_didSavePreviousStateOfNavBar) { [self.navigationController setNavigationBarHidden:_previousNavBarHidden animated:animated]; + [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}]; UINavigationBar *navBar = self.navigationController.navigationBar; navBar.tintColor = _previousNavBarTintColor; navBar.translucent = _previousNavBarTranslucent; navBar.barTintColor = _previousNavBarBarTintColor; navBar.barStyle = _previousNavBarStyle; + navBar.titleTextAttributes = _previousNavBarTitleAttributes; [navBar setBackgroundImage:_previousNavigationBarBackgroundImageDefault forBarMetrics:UIBarMetricsDefault]; [navBar setBackgroundImage:_previousNavigationBarBackgroundImageLandscapePhone forBarMetrics:UIBarMetricsLandscapePhone]; // Restore back button if we need to @@ -966,15 +1015,80 @@ - (void)didStartViewingPageAtIndex:(NSUInteger)index { // Update nav [self updateNavigation]; + + [self update]; +} + +- (void)update +{ + BOOL likedByMe = [_fullscreenPhotoDelegate isLiked:_currentPageIndex]; + _likesButton.selected = likedByMe; + //Update likes container + NSUInteger likes = [_fullscreenPhotoDelegate likesCount:_currentPageIndex]; + if (likes > 0) { + NSString *likesWord = likes == 1 ? @"like" : @"likes"; + _likesLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)likes, likesWord]; + } else { + _likesLabel.text = @"0 likes"; + } } #pragma mark - Frame Calculations - (CGRect)frameForPagingScrollView { - CGRect frame = self.view.bounds;// [[UIScreen mainScreen] bounds]; - frame.origin.x -= PADDING; - frame.size.width += (2 * PADDING); + //FLAG! +// CGRect frame = self.view.bounds;// [[UIScreen mainScreen] bounds]; +// frame.origin.x -= PADDING; +// frame.size.width += (2 * PADDING); + //return CGRectIntegral(frame); + CGRect tabbar = [self frameForToolbarAtOrientation:self.interfaceOrientation]; + CGFloat scrollViewMargin = [UIApplication sharedApplication].statusBarFrame.size.height + tabbar.size.height; + CGFloat posX = 0 - PADDING; + CGFloat posY = scrollViewMargin; + CGFloat width = self.view.frame.size.width + (2 * PADDING); + CGFloat height = self.view.frame.size.height - (2 * scrollViewMargin); + CGRect frame = CGRectMake(posX, posY, width, height); + return CGRectIntegral(frame); +} + +- (CGRect)frameForShareButton +{ + CGFloat containerWidth = 40; + CGFloat containerHeight = 40; + CGRect scrollViewFrame = [self frameForPagingScrollView]; + CGFloat posX = 12; + CGFloat posY = scrollViewFrame.origin.y + scrollViewFrame.size.height; + CGRect frame = CGRectMake(posX, posY, containerWidth, containerHeight); + return CGRectIntegral(frame); +} + +- (CGRect)frameForLikesContainer { + CGFloat containerWidth = 120; + CGFloat containerHeight = 40; + CGRect scrollViewFrame = [self frameForPagingScrollView]; + CGFloat posX = scrollViewFrame.size.width / 2 - containerWidth / 2; + CGFloat posY = scrollViewFrame.origin.y + scrollViewFrame.size.height; + CGRect frame = CGRectMake(posX, posY, containerWidth, containerHeight); + return CGRectIntegral(frame); +} + +- (CGRect)frameForLikeButton { + CGRect parentContainerRect = [self frameForLikesContainer]; + CGFloat buttonSide = parentContainerRect.size.height; + CGFloat posX = 0; + CGFloat posY = 0; + CGRect frame = CGRectMake(posX, posY, buttonSide, buttonSide); + return CGRectIntegral(frame); +} + +- (CGRect)frameForLikesLabel { + CGRect parentContainerRect = [self frameForLikesContainer]; + CGFloat labelHeight = parentContainerRect.size.height; + CGFloat labelWidth = parentContainerRect.size.width - labelHeight; + CGFloat posX = labelHeight; + CGFloat posY = 0; + CGRect frame = CGRectMake(posX, posY, labelWidth, labelHeight); return CGRectIntegral(frame); } @@ -1102,6 +1216,8 @@ - (void)updateNavigation { } else { self.title = nil; } + //HIDE SELF TITLE ANYWAY + self.title = nil; // Buttons _previousButton.enabled = (_currentPageIndex > 0); @@ -1116,7 +1232,7 @@ - (void)updateNavigation { _actionButton.enabled = YES; _actionButton.tintColor = nil; } - + } - (void)jumpToPageAtIndex:(NSUInteger)index animated:(BOOL)animated { @@ -1630,6 +1746,37 @@ - (void)actionButtonPressed:(id)sender { } +- (void)backButtonPressed:(id)sender { + [self.navigationController popViewControllerAnimated:true]; +} + +- (void)likeButtonPressed { + BOOL like = !_likesButton.selected; + [_fullscreenPhotoDelegate likePhoto:_currentPageIndex like:like]; + [_fullscreenPhotoDelegate isLiked:_currentPageIndex]; +} + +- (void)onShareButtonTapped:(UIButton *)button +{ + if (self.onShareButtonTappedBlock) { + self.onShareButtonTappedBlock(button); + } +} + +// MARK: - Show likes view + +- (void)showLikesView { + if (self.fullscreenPhotoDelegate && ![_likesLabel.text isEqualToString:@""]) { + [self.fullscreenPhotoDelegate showLikes:_currentPageIndex]; + } +} + +// MARK: - UITapGestureRecognizer + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { + return touch.view == _likesLabel; +} + #pragma mark - Action Progress - (MBProgressHUD *)progressHUD { diff --git a/Pod/Classes/MWPhotoBrowserPrivate.h b/Pod/Classes/MWPhotoBrowserPrivate.h index 5770d6787..777be9167 100644 --- a/Pod/Classes/MWPhotoBrowserPrivate.h +++ b/Pod/Classes/MWPhotoBrowserPrivate.h @@ -23,10 +23,12 @@ // Views UIScrollView *_pagingScrollView; + UIView *_likesContainer; + UILabel *_likesLabel; + UIButton *_likesButton; // Paging & layout NSMutableSet *_visiblePages, *_recycledPages; - NSUInteger _currentPageIndex; NSUInteger _previousPageIndex; CGRect _previousLayoutBounds; NSUInteger _pageIndexBeforeRotation; @@ -52,6 +54,7 @@ UIBarButtonItem *_previousViewControllerBackButton; UIImage *_previousNavigationBarBackgroundImageDefault; UIImage *_previousNavigationBarBackgroundImageLandscapePhone; + NSDictionary *_previousNavBarTitleAttributes; // Video MPMoviePlayerViewController *_currentVideoPlayerViewController; diff --git a/Pod/Classes/MWTapDetectingImageView.h b/Pod/Classes/MWTapDetectingImageView.h index 8445b6260..1393556c7 100644 --- a/Pod/Classes/MWTapDetectingImageView.h +++ b/Pod/Classes/MWTapDetectingImageView.h @@ -24,4 +24,4 @@ - (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch; - (void)imageView:(UIImageView *)imageView tripleTapDetected:(UITouch *)touch; -@end \ No newline at end of file +@end diff --git a/Pod/Classes/MWZoomingScrollView.h b/Pod/Classes/MWZoomingScrollView.h index 4694ecffc..7ef5f886f 100644 --- a/Pod/Classes/MWZoomingScrollView.h +++ b/Pod/Classes/MWZoomingScrollView.h @@ -22,6 +22,7 @@ @property (nonatomic, weak) MWCaptionView *captionView; @property (nonatomic, weak) UIButton *selectedButton; @property (nonatomic, weak) UIButton *playButton; +@property (nonatomic, weak) MWPhotoBrowser *photoBrowser; - (id)initWithPhotoBrowser:(MWPhotoBrowser *)browser; - (void)displayImage; diff --git a/Pod/Classes/MWZoomingScrollView.m b/Pod/Classes/MWZoomingScrollView.m index 75039ffa6..df455492e 100644 --- a/Pod/Classes/MWZoomingScrollView.m +++ b/Pod/Classes/MWZoomingScrollView.m @@ -17,7 +17,7 @@ // Private methods and properties @interface MWZoomingScrollView () { - MWPhotoBrowser __weak *_photoBrowser; + //MWPhotoBrowser __weak *_photoBrowser; MWTapDetectingView *_tapView; // for background taps MWTapDetectingImageView *_photoImageView; DACircularProgressView *_loadingIndicator; @@ -49,7 +49,7 @@ - (id)initWithPhotoBrowser:(MWPhotoBrowser *)browser { _photoImageView.contentMode = UIViewContentModeCenter; _photoImageView.backgroundColor = [UIColor blackColor]; [self addSubview:_photoImageView]; - + // Loading indicator _loadingIndicator = [[DACircularProgressView alloc] initWithFrame:CGRectMake(140.0f, 30.0f, 40.0f, 40.0f)]; _loadingIndicator.userInteractionEnabled = NO; @@ -305,6 +305,16 @@ - (void)setMaxMinZoomScalesForCurrentBounds { } +#pragma mark - Frame calculation + +- (CGRect)frameForLikeAnimation:(CGRect)frame { + CGFloat animationContainerSize = 125; + CGFloat posX = (frame.size.width - animationContainerSize) / 2; + CGFloat posY = (frame.size.height - animationContainerSize) / 2; + CGRect frameForRect = CGRectMake(posX, posY, animationContainerSize, animationContainerSize); + return frameForRect; +} + #pragma mark - Layout - (void)layoutSubviews { @@ -409,6 +419,7 @@ - (void)handleDoubleTap:(CGPoint)touchPoint { // Delay controls [_photoBrowser hideControlsAfterDelay]; + } @@ -416,8 +427,38 @@ - (void)handleDoubleTap:(CGPoint)touchPoint { - (void)imageView:(UIImageView *)imageView singleTapDetected:(UITouch *)touch { [self handleSingleTap:[touch locationInView:imageView]]; } -- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch { - [self handleDoubleTap:[touch locationInView:imageView]]; + +- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch +{ + if (!self.photoBrowser.showLikesContainer) { return; } + + if (![self.photoBrowser.fullscreenPhotoDelegate canShowLikeAnimation]) { return; } + + UIImageView *likeAnimationView = [[UIImageView alloc] initWithFrame:[self frameForLikeAnimation:self.frame]]; + likeAnimationView.image = [UIImage imageNamed:@"big_heart"]; + likeAnimationView.contentMode = UIViewContentModeScaleAspectFit; + [self addSubview:likeAnimationView]; + + [UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + likeAnimationView.transform = CGAffineTransformMakeScale(1.3, 1.3); + likeAnimationView.alpha = 1.0; + } completion:^(BOOL finished) { + [UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + likeAnimationView.transform = CGAffineTransformMakeScale(1.0, 1.0); + } completion:^(BOOL finished) { + [UIView animateWithDuration:0.2f delay:0.3 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + likeAnimationView.transform = CGAffineTransformMakeScale(0.3, 0.3); + likeAnimationView.alpha = 0.0; + } completion:^(BOOL finished) { + likeAnimationView.transform = CGAffineTransformMakeScale(1.0, 1.0); + [likeAnimationView removeFromSuperview]; + }]; + }]; + }]; + + if (![self.photoBrowser.fullscreenPhotoDelegate isLiked:self.photoBrowser.currentPageIndex]){ + [self.photoBrowser likeButtonPressed]; + } } // Background View @@ -431,15 +472,5 @@ - (void)view:(UIView *)view singleTapDetected:(UITouch *)touch { touchY += self.contentOffset.y; [self handleSingleTap:CGPointMake(touchX, touchY)]; } -- (void)view:(UIView *)view doubleTapDetected:(UITouch *)touch { - // Translate touch location to image view location - CGFloat touchX = [touch locationInView:view].x; - CGFloat touchY = [touch locationInView:view].y; - touchX *= 1/self.zoomScale; - touchY *= 1/self.zoomScale; - touchX += self.contentOffset.x; - touchY += self.contentOffset.y; - [self handleDoubleTap:CGPointMake(touchX, touchY)]; -} @end