Skip to content

Commit

Permalink
Faster download of album thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyLB committed Jun 27, 2019
1 parent a218a52 commit 744c1a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 40 deletions.
3 changes: 2 additions & 1 deletion piwigo/Albums/Album Data/AlbumService.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ +(NSURLSessionTask*)getAlbumListForCategory:(NSInteger)categoryId
NSDictionary *parameters = @{
@"cat_id" : @(categoryId),
@"recursive" : recursiveString,
@"faked_by_community" : fakedString
@"faked_by_community" : fakedString,
@"thumbnail_size" : @"medium"
};

// Get albums list for category
Expand Down
58 changes: 20 additions & 38 deletions piwigo/Albums/Cells/AlbumTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,54 +157,36 @@ -(void)setupWithAlbumData:(PiwigoAlbumData*)albumData
self.backgroundImage.layer.cornerRadius = 10;
NSInteger imageSize = CGImageGetHeight(albumData.categoryImage.CGImage) * CGImageGetBytesPerRow(albumData.categoryImage.CGImage);

if(albumData.categoryImage && imageSize > 0)
if (albumData.categoryImage && imageSize > 0)
{
// Album thumbnail in memory
self.backgroundImage.image = albumData.categoryImage;
}
else if(albumData.albumThumbnailId <= 0)
else if (albumData.albumThumbnailUrl.length <= 0)
{
// No album thumbnail
return;
}
else
{
[self downloadBackgroundImageOfAlbum:albumData];
}
}

-(void)downloadBackgroundImageOfAlbum:(PiwigoAlbumData*)albumData
{
__weak typeof(self) weakSelf = self;
[ImageService getImageInfoById:albumData.albumThumbnailId
ListOnCompletion:^(NSURLSessionTask *task, PiwigoImageData *imageData) {
// Success if imageData is not nil
if (imageData != nil)
{
if (imageData.MediumPath.length <= 0)
albumData.categoryImage = [UIImage imageNamed:@"placeholder"];
else
{
NSURL *URL = [NSURL URLWithString:imageData.MediumPath];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
[self.backgroundImage setImageWithURLRequest:request
placeholderImage:[UIImage imageNamed:@"placeholder"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
albumData.categoryImage = image;
weakSelf.backgroundImage.image = image;
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
// Load album thumbnail
NSLog(@"URL: %@", albumData.albumThumbnailUrl);
__weak typeof(self) weakSelf = self;
NSURL *URL = [NSURL URLWithString:albumData.albumThumbnailUrl];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
[self.backgroundImage setImageWithURLRequest:request
placeholderImage:[UIImage imageNamed:@"placeholder"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
albumData.categoryImage = image;
weakSelf.backgroundImage.image = image;
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
#if defined(DEBUG)
NSLog(@"setupWithAlbumData — Fail to get album bg image for album at %@", imageData.MediumPath);
NSLog(@"setupWithAlbumData — Fail to get album bg image for album at %@", albumData.albumThumbnailUrl);
#endif
}];
}
}
}
onFailure:^(NSURLSessionTask *task, NSError *error) {
#if defined(DEBUG)
NSLog(@"setupWithAlbumData — Fail to get album bg image: %@", [error localizedDescription]);
#endif
}];
}];
}
}


Expand Down
2 changes: 1 addition & 1 deletion piwigo/Resources/Base.lproj/ReleaseNotes.strings
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Copyright © 2017 Piwigo.org. All rights reserved.
*/

"v2.4.0_text" = "Version 2.4\n\n• Adds search ability (requires iOS 11 or later)\n• Fixes impossibility to remove tags\n• Fixes inaccurate image data in some circumstances";
"v2.4.0_text" = "Version 2.4\n\n• Add search ability (requires iOS 11 or later)\n• Faster download of album thumbnails\n• Fixes impossibility to remove tags\n• Fixes inaccurate image data in some circumstances";

"v2.3.5_text" = "Version 2.3.5\n\n• Fix a crash which sometimes happens when editing the server address after logout";

Expand Down

0 comments on commit 744c1a1

Please sign in to comment.