{"action":"created","comment":{"url":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/comments/51429074","id":51429074,"diff_hunk":"@@ -0,0 +1,206 @@\n+  //\n+//  LTPhotoVC.m\n+//  Flickr Browsing\n+//\n+//  Created by Ofer Mano on 15/12/2015.\n+//  Copyright © 2015 Lightricks. All rights reserved.\n+//\n+\n+#import \"LTPhotoVC.h\"\n+\n+#import \"LTImageLoader.h\"\n+\n+\n+NS_ASSUME_NONNULL_BEGIN\n+\n+@interface LTPhotoVC () <UIScrollViewDelegate>\n+\n+/// The class that loads the image in the background.\n+@property (strong,nonatomic) LTImageLoader *imageLoader;\n+\n+/// The scroll view that holds the image.\n+@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;\n+\n+/// The image view (in the scroll view) that holds the image.\n+@property (strong, nonatomic) UIImageView *imageView;\n+\n+/// The image we display.\n+@property (strong, nonatomic, nullable) UIImage *image;\n+\n+/// A spinner to indicates loading is in progress.\n+@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *spinner;\n+@end\n+\n+@implementation LTPhotoVC\n+\n+#pragma mark -\n+#pragma mark Restoration functions.\n+#pragma mark -\n+\n+- (void)setRestoreData:(id)restoreData {\n+  if (![restoreData isKindOfClass:[UIImage class]])\n+    return;\n+  UIImage *imageToRestore = (UIImage *)restoreData;\n+  self.image = imageToRestore;\n+}\n+\n+- (id)restoreData {\n+  return self.image;\n+}\n+\n+#pragma mark -\n+#pragma mark Initialization\n+#pragma mark -\n+\n+- (void)viewDidLoad {\n+  [super viewDidLoad];\n+  [self.scrollView addSubview:self.imageView];\n+  \n+  // If the view is loaded in a split view controller we need to turn off animation upon loading.\n+  if (!self.photoDescription) {\n+    [self.spinner stopAnimating];\n+  }\n+}\n+\n+// After each layout change we will reset the image size to match the new window size.\n+- (void)viewDidLayoutSubviews {\n+  [super viewDidLayoutSubviews];\n+  self.scrollView.contentInset = UIEdgeInsetsZero;\n+  [self imageFitToFrame];\n+}\n+\n+#pragma mark -\n+#pragma mark Setters and Getters\n+#pragma mark -\n+\n+- (LTImageLoader *)imageLoader {\n+  if (!_imageLoader) {\n+    _imageLoader = [[LTImageLoader alloc] init];\n+    [[NSNotificationCenter defaultCenter] addObserver:self\n+                                             selector:@selector(imageLoaded:)\n+                                                 name:[_imageLoader observingKey]\n+                                               object:_imageLoader];\n+\n+  }\n+  return _imageLoader;\n+}\n+\n+- (void)setPhotoDescription:(LTPhotoDescription *)photoDescription {\n+  _photoDescription = photoDescription;\n+  self.title = photoDescription.title;\n+  [self startDownloadingImage];\n+}\n+\n+- (void)setScrollView:(UIScrollView *)scrollView {\n+  _scrollView = scrollView;\n+  _scrollView.delegate = self;\n+}\n+\n+- (UIImageView *)imageView {\n+  if (!_imageView) {\n+    _imageView = [[UIImageView alloc]init];\n+    _imageView.contentMode = UIViewContentModeScaleAspectFit;\n+  }\n+  return _imageView;\n+}\n+\n+// Image is not an actual property we just propagate to image view.\n+- (nullable UIImage *)image {\n+  return self.imageView.image;\n+}\n+\n+- (void)setImage:(nullable UIImage *)image {\n+  if (!image) {\n+    return;\n+  }\n+  self.imageView.image = image;\n+  CGFloat imageViewScale = [self calculateScaleToImage:self.scrollView.frame.size];\n+  CGRect imageViewRect = [self calculateImageViewSize:imageViewScale];\n+  [UIView transitionWithView:self.imageView\n+                    duration:0.5f\n+                     options:UIViewAnimationOptionTransitionFlipFromLeft\n+                  animations:^{ self.imageView.frame = imageViewRect;}\n+                  completion:^(BOOL fin){[self resetScrollViewSize:imageViewScale];[self.spinner stopAnimating];}];\n+  \n+}\n+\n+#pragma mark -\n+#pragma mark ScrollView deligation\n+#pragma mark -\n+\n+- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {\n+  return self.imageView;\n+}\n+\n+- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView\n+                       withView:(nullable UIView *)view\n+                        atScale:(CGFloat)scale {\n+  CGFloat imageScale = [self calculateScaleToImage:self.imageView.frame.size];\n+  self.imageView.frame = [self calculateImageViewSize:imageScale];\n+  self.scrollView.contentSize = self.imageView.frame.size;\n+}\n+\n+#pragma mark -\n+#pragma mark Image loading\n+#pragma mark -\n+\n+- (void)startDownloadingImage {\n+  self.image = nil;\n+  if (!self.photoDescription) {\n+    return;\n+  }\n+  [self.spinner startAnimating];\n+  self.imageLoader.url = self.photoDescription.url;\n+  [self.imageLoader load];\n+}\n+\n+- (void)imageLoaded:(NSNotification *)notification {\n+  UIImage *image = [notification.userInfo valueForKey:[self.imageLoader dataKey]];\n+  self.restoreData = image;\n+}\n+\n+#pragma mark -\n+#pragma mark Size handling\n+#pragma mark -\n+\n+- (IBAction)resetSize:(UITapGestureRecognizer *)sender {\n+  [self imageFitToFrame];\n+}\n+\n+- (void)imageFitToFrame {\n+  CGFloat imageViewScale = [self calculateScaleToImage:self.scrollView.frame.size];\n+  CGRect imageViewRect = [self calculateImageViewSize:imageViewScale];\n+  self.imageView.transform = CGAffineTransformIdentity;\n+  self.imageView.frame = imageViewRect;\n+  [self resetScrollViewSize:imageViewScale];\n+}\n+\n+- (CGFloat)calculateScaleToImage:(CGSize)size {\n+  CGFloat widthRatio = self.image.size.width / size.width;\n+  CGFloat heightRatio = self.image.size.height / size.height;\n+  return MAX(widthRatio,heightRatio);\n+}\n+\n+- (CGRect)calculateImageViewSize:(CGFloat)scale {\n+  CGRect  viewFrame;\n+  viewFrame.size = self.image.size;\n+  viewFrame.origin = CGPointMake(0,0);\n+  viewFrame.size.width /= scale;\n+  viewFrame.size.height /= scale;\n+  viewFrame.size.width = MAX(self.scrollView.frame.size.width, viewFrame.size.width);\n+  viewFrame.size.height = MAX(self.scrollView.frame.size.height, viewFrame.size.height);\n+  return viewFrame;\n+}\n+\n+- (void)resetScrollViewSize:(CGFloat)imageViewScale {\n+  self.scrollView.contentSize = self.imageView.frame.size;\n+  self.scrollView.contentOffset = CGPointMake(0,0);","path":"Flickr Browsing/LTPhotoVC.m","position":197,"original_position":197,"commit_id":"c1adad5e49b49e0df603c7111e491cd23080a504","original_commit_id":"c1adad5e49b49e0df603c7111e491cd23080a504","user":{"login":"alexger","id":603102,"avatar_url":"https://avatars.githubusercontent.com/u/603102?v=3","gravatar_id":"","url":"https://api.github.com/users/alexger","html_url":"https://github.com/alexger","followers_url":"https://api.github.com/users/alexger/followers","following_url":"https://api.github.com/users/alexger/following{/other_user}","gists_url":"https://api.github.com/users/alexger/gists{/gist_id}","starred_url":"https://api.github.com/users/alexger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexger/subscriptions","organizations_url":"https://api.github.com/users/alexger/orgs","repos_url":"https://api.github.com/users/alexger/repos","events_url":"https://api.github.com/users/alexger/events{/privacy}","received_events_url":"https://api.github.com/users/alexger/received_events","type":"User","site_admin":false},"body":"CGPointZero","created_at":"2016-02-01T15:11:57Z","updated_at":"2016-02-01T15:11:57Z","html_url":"https://github.com/alexger/FlickrBrowsing/pull/2#discussion_r51429074","pull_request_url":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/comments/51429074"},"html":{"href":"https://github.com/alexger/FlickrBrowsing/pull/2#discussion_r51429074"},"pull_request":{"href":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/2","id":54270597,"html_url":"https://github.com/alexger/FlickrBrowsing/pull/2","diff_url":"https://github.com/alexger/FlickrBrowsing/pull/2.diff","patch_url":"https://github.com/alexger/FlickrBrowsing/pull/2.patch","issue_url":"https://api.github.com/repos/alexger/FlickrBrowsing/issues/2","number":2,"state":"open","locked":false,"title":"Adding the exercise code","user":{"login":"ofermano","id":16253763,"avatar_url":"https://avatars.githubusercontent.com/u/16253763?v=3","gravatar_id":"","url":"https://api.github.com/users/ofermano","html_url":"https://github.com/ofermano","followers_url":"https://api.github.com/users/ofermano/followers","following_url":"https://api.github.com/users/ofermano/following{/other_user}","gists_url":"https://api.github.com/users/ofermano/gists{/gist_id}","starred_url":"https://api.github.com/users/ofermano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ofermano/subscriptions","organizations_url":"https://api.github.com/users/ofermano/orgs","repos_url":"https://api.github.com/users/ofermano/repos","events_url":"https://api.github.com/users/ofermano/events{/privacy}","received_events_url":"https://api.github.com/users/ofermano/received_events","type":"User","site_admin":false},"body":"The Flickr Browsing exercise.","created_at":"2015-12-21T15:49:05Z","updated_at":"2016-02-01T15:11:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4b8cf19fbef815f6b7f94b5eba921bc3cb7e326f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/2/commits","review_comments_url":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/2/comments","review_comment_url":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alexger/FlickrBrowsing/issues/2/comments","statuses_url":"https://api.github.com/repos/alexger/FlickrBrowsing/statuses/c1adad5e49b49e0df603c7111e491cd23080a504","head":{"label":"ofermano:master","ref":"master","sha":"c1adad5e49b49e0df603c7111e491cd23080a504","user":{"login":"ofermano","id":16253763,"avatar_url":"https://avatars.githubusercontent.com/u/16253763?v=3","gravatar_id":"","url":"https://api.github.com/users/ofermano","html_url":"https://github.com/ofermano","followers_url":"https://api.github.com/users/ofermano/followers","following_url":"https://api.github.com/users/ofermano/following{/other_user}","gists_url":"https://api.github.com/users/ofermano/gists{/gist_id}","starred_url":"https://api.github.com/users/ofermano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ofermano/subscriptions","organizations_url":"https://api.github.com/users/ofermano/orgs","repos_url":"https://api.github.com/users/ofermano/repos","events_url":"https://api.github.com/users/ofermano/events{/privacy}","received_events_url":"https://api.github.com/users/ofermano/received_events","type":"User","site_admin":false},"repo":{"id":48318077,"name":"FlickrBrowsing","full_name":"ofermano/FlickrBrowsing","owner":{"login":"ofermano","id":16253763,"avatar_url":"https://avatars.githubusercontent.com/u/16253763?v=3","gravatar_id":"","url":"https://api.github.com/users/ofermano","html_url":"https://github.com/ofermano","followers_url":"https://api.github.com/users/ofermano/followers","following_url":"https://api.github.com/users/ofermano/following{/other_user}","gists_url":"https://api.github.com/users/ofermano/gists{/gist_id}","starred_url":"https://api.github.com/users/ofermano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ofermano/subscriptions","organizations_url":"https://api.github.com/users/ofermano/orgs","repos_url":"https://api.github.com/users/ofermano/repos","events_url":"https://api.github.com/users/ofermano/events{/privacy}","received_events_url":"https://api.github.com/users/ofermano/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ofermano/FlickrBrowsing","description":"","fork":false,"url":"https://api.github.com/repos/ofermano/FlickrBrowsing","forks_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/forks","keys_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/teams","hooks_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/hooks","issue_events_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/issues/events{/number}","events_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/events","assignees_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/assignees{/user}","branches_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/branches{/branch}","tags_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/tags","blobs_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/git/refs{/sha}","trees_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/statuses/{sha}","languages_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/languages","stargazers_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/stargazers","contributors_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/contributors","subscribers_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/subscribers","subscription_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/subscription","commits_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/commits{/sha}","git_commits_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/git/commits{/sha}","comments_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/comments{/number}","issue_comment_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/issues/comments{/number}","contents_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/contents/{+path}","compare_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/merges","archive_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/downloads","issues_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/issues{/number}","pulls_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/pulls{/number}","milestones_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/milestones{/number}","notifications_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/labels{/name}","releases_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/releases{/id}","deployments_url":"https://api.github.com/repos/ofermano/FlickrBrowsing/deployments","created_at":"2015-12-20T11:44:16Z","updated_at":"2016-01-31T10:46:21Z","pushed_at":"2016-01-31T10:46:20Z","git_url":"git://github.com/ofermano/FlickrBrowsing.git","ssh_url":"git@github.com:ofermano/FlickrBrowsing.git","clone_url":"https://github.com/ofermano/FlickrBrowsing.git","svn_url":"https://github.com/ofermano/FlickrBrowsing","homepage":null,"size":224,"stargazers_count":0,"watchers_count":0,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"alexger:master","ref":"master","sha":"427e354444fd2f261471943d38160612166f7640","user":{"login":"alexger","id":603102,"avatar_url":"https://avatars.githubusercontent.com/u/603102?v=3","gravatar_id":"","url":"https://api.github.com/users/alexger","html_url":"https://github.com/alexger","followers_url":"https://api.github.com/users/alexger/followers","following_url":"https://api.github.com/users/alexger/following{/other_user}","gists_url":"https://api.github.com/users/alexger/gists{/gist_id}","starred_url":"https://api.github.com/users/alexger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexger/subscriptions","organizations_url":"https://api.github.com/users/alexger/orgs","repos_url":"https://api.github.com/users/alexger/repos","events_url":"https://api.github.com/users/alexger/events{/privacy}","received_events_url":"https://api.github.com/users/alexger/received_events","type":"User","site_admin":false},"repo":{"id":48324481,"name":"FlickrBrowsing","full_name":"alexger/FlickrBrowsing","owner":{"login":"alexger","id":603102,"avatar_url":"https://avatars.githubusercontent.com/u/603102?v=3","gravatar_id":"","url":"https://api.github.com/users/alexger","html_url":"https://github.com/alexger","followers_url":"https://api.github.com/users/alexger/followers","following_url":"https://api.github.com/users/alexger/following{/other_user}","gists_url":"https://api.github.com/users/alexger/gists{/gist_id}","starred_url":"https://api.github.com/users/alexger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexger/subscriptions","organizations_url":"https://api.github.com/users/alexger/orgs","repos_url":"https://api.github.com/users/alexger/repos","events_url":"https://api.github.com/users/alexger/events{/privacy}","received_events_url":"https://api.github.com/users/alexger/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alexger/FlickrBrowsing","description":"","fork":true,"url":"https://api.github.com/repos/alexger/FlickrBrowsing","forks_url":"https://api.github.com/repos/alexger/FlickrBrowsing/forks","keys_url":"https://api.github.com/repos/alexger/FlickrBrowsing/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alexger/FlickrBrowsing/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alexger/FlickrBrowsing/teams","hooks_url":"https://api.github.com/repos/alexger/FlickrBrowsing/hooks","issue_events_url":"https://api.github.com/repos/alexger/FlickrBrowsing/issues/events{/number}","events_url":"https://api.github.com/repos/alexger/FlickrBrowsing/events","assignees_url":"https://api.github.com/repos/alexger/FlickrBrowsing/assignees{/user}","branches_url":"https://api.github.com/repos/alexger/FlickrBrowsing/branches{/branch}","tags_url":"https://api.github.com/repos/alexger/FlickrBrowsing/tags","blobs_url":"https://api.github.com/repos/alexger/FlickrBrowsing/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alexger/FlickrBrowsing/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alexger/FlickrBrowsing/git/refs{/sha}","trees_url":"https://api.github.com/repos/alexger/FlickrBrowsing/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alexger/FlickrBrowsing/statuses/{sha}","languages_url":"https://api.github.com/repos/alexger/FlickrBrowsing/languages","stargazers_url":"https://api.github.com/repos/alexger/FlickrBrowsing/stargazers","contributors_url":"https://api.github.com/repos/alexger/FlickrBrowsing/contributors","subscribers_url":"https://api.github.com/repos/alexger/FlickrBrowsing/subscribers","subscription_url":"https://api.github.com/repos/alexger/FlickrBrowsing/subscription","commits_url":"https://api.github.com/repos/alexger/FlickrBrowsing/commits{/sha}","git_commits_url":"https://api.github.com/repos/alexger/FlickrBrowsing/git/commits{/sha}","comments_url":"https://api.github.com/repos/alexger/FlickrBrowsing/comments{/number}","issue_comment_url":"https://api.github.com/repos/alexger/FlickrBrowsing/issues/comments{/number}","contents_url":"https://api.github.com/repos/alexger/FlickrBrowsing/contents/{+path}","compare_url":"https://api.github.com/repos/alexger/FlickrBrowsing/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alexger/FlickrBrowsing/merges","archive_url":"https://api.github.com/repos/alexger/FlickrBrowsing/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alexger/FlickrBrowsing/downloads","issues_url":"https://api.github.com/repos/alexger/FlickrBrowsing/issues{/number}","pulls_url":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls{/number}","milestones_url":"https://api.github.com/repos/alexger/FlickrBrowsing/milestones{/number}","notifications_url":"https://api.github.com/repos/alexger/FlickrBrowsing/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alexger/FlickrBrowsing/labels{/name}","releases_url":"https://api.github.com/repos/alexger/FlickrBrowsing/releases{/id}","deployments_url":"https://api.github.com/repos/alexger/FlickrBrowsing/deployments","created_at":"2015-12-20T14:38:46Z","updated_at":"2015-12-21T15:28:50Z","pushed_at":"2016-01-31T10:46:21Z","git_url":"git://github.com/alexger/FlickrBrowsing.git","ssh_url":"git@github.com:alexger/FlickrBrowsing.git","clone_url":"https://github.com/alexger/FlickrBrowsing.git","svn_url":"https://github.com/alexger/FlickrBrowsing","homepage":null,"size":59,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/2"},"html":{"href":"https://github.com/alexger/FlickrBrowsing/pull/2"},"issue":{"href":"https://api.github.com/repos/alexger/FlickrBrowsing/issues/2"},"comments":{"href":"https://api.github.com/repos/alexger/FlickrBrowsing/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alexger/FlickrBrowsing/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/alexger/FlickrBrowsing/statuses/c1adad5e49b49e0df603c7111e491cd23080a504"}}}}