Skip to content

Commit

Permalink
Fixed not showing album covers when opening for the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostas Karayannis committed May 20, 2016
1 parent 004793e commit 9fbcb9b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
10 changes: 6 additions & 4 deletions FacebookImagePicker/OLAlbumViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ - (void)setAlbum:(OLFacebookAlbum *)album {
}
}

[self.imageView setAndFadeInFacebookImageWithURL:album.coverPhotoURL placeholder:placeholderImage];
__weak OLAlbumCell *welf = self;
[self.imageView setAndFadeInFacebookImageWithURL:album.coverPhotoURL placeholder:placeholderImage completionHandler:^{
if (!welf.imageView.superview){
[welf addSubview:welf.imageView];
}
}];
self.imageView.clipsToBounds = YES;
self.textLabel.text = album.name;
self.detailTextLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)album.photoCount];
Expand Down Expand Up @@ -113,9 +118,6 @@ - (void)viewDidAppear:(BOOL)animated {
[self.delegate albumViewController:self didFailWithError:error];

}
else{
[self.tableView reloadData];
}
}

- (void)setShouldDisplayLogoutButton:(BOOL)shouldDisplayLogoutButton
Expand Down
2 changes: 1 addition & 1 deletion FacebookImagePicker/OLFacebookImagePickerCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ - (id)initWithFrame:(CGRect)frame {

- (void)bind:(OLFacebookImage *)media {
self.facebookImage = media;
[self.imageView setAndFadeInFacebookImageWithURL:[media bestURLForSize:CGSizeMake(220, 220)]]; // opted for slightly larger than thumb url. Might be better for performance just to go with thumb.
[self.imageView setAndFadeInFacebookImageWithURL:[media bestURLForSize:CGSizeMake(220, 220)] placeholder:nil completionHandler:NULL]; // opted for slightly larger than thumb url. Might be better for performance just to go with thumb.
}

- (void)setSelected:(BOOL)selected {
Expand Down
1 change: 1 addition & 0 deletions FacebookImagePicker/UIImageView+FacebookFadeIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
@interface UIImageView (FacebookFadeIn)
- (void)setAndFadeInFacebookImageWithURL:(NSURL *)url;
- (void)setAndFadeInFacebookImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholder;
-(void)setAndFadeInFacebookImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholder completionHandler:(void(^)())handler;
@end
22 changes: 15 additions & 7 deletions FacebookImagePicker/UIImageView+FacebookFadeIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@

@implementation UIImageView (FacebookFadeIn)
- (void)setAndFadeInFacebookImageWithURL:(NSURL *)url {
[self setAndFadeInFacebookImageWithURL:url placeholder:nil];
[self setAndFadeInFacebookImageWithURL:url placeholder:nil completionHandler:NULL];
}

-(void)setAndFadeInFacebookImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholder {
-(void)setAndFadeInFacebookImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholder{
[self setAndFadeInFacebookImageWithURL:url placeholder:placeholder completionHandler:NULL];
}

-(void)setAndFadeInFacebookImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholder completionHandler:(void(^)())handler{
for (id key in self.tasks.allKeys){
if (![key isEqual:url]){
[self.tasks[key] cancel];
Expand All @@ -27,14 +31,18 @@ -(void)setAndFadeInFacebookImageWithURL:(NSURL *)url placeholder:(UIImage *)plac
self.alpha = 0;
NSURLSessionTask *task = [[OLFacebookImageDownloader sharedInstance] downloadImageAtURL:url withCompletionHandler:^(UIImage *image, NSError *error){
if ([self.tasks[url] state] == NSURLSessionTaskStateCanceling){
[self.tasks removeObjectForKey:url];
return;
}
[self.tasks removeObjectForKey:url];
self.image = image;
[UIView beginAnimations:@"fadeIn" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.3];
self.alpha = 1;
[UIView commitAnimations];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.alpha = 1;
}completion:^(BOOL finished){
if (handler){
handler();
}
}];

}];
self.tasks[url] = task;
Expand Down

0 comments on commit 9fbcb9b

Please sign in to comment.