From 76b552e21e5f7c7bceee46ab336cb9c6ee57f3c7 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 12:12:58 +0300 Subject: [PATCH] Pass image URL in completion blocks - step 4: - deprecated all UIImageView(HighlightedWebCache) `setImage*` methods. Replaced with `loadImage*` methods that use the `SDWebImageCompletionBlock` as completion block type - created HighlightedWebCacheDeprecated category on UIImageView (to avoid collisions, we didn't name it Deprecated) - replaced the usages of the deprecated items with the new ones --- SDWebImage/UIImageView+HighlightedWebCache.h | 46 ++++++++++------ SDWebImage/UIImageView+HighlightedWebCache.m | 57 ++++++++++++++++---- 2 files changed, 77 insertions(+), 26 deletions(-) diff --git a/SDWebImage/UIImageView+HighlightedWebCache.h b/SDWebImage/UIImageView+HighlightedWebCache.h index 40646ea4..cbc97a50 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.h +++ b/SDWebImage/UIImageView+HighlightedWebCache.h @@ -21,59 +21,73 @@ * * @param url The url for the image. */ -- (void)setHighlightedImageWithURL:(NSURL *)url; +- (void)loadHighlightedImageWithURL:(NSURL *)url; /** * Set the imageView `highlightedImage` with an `url` and custom options. * * The downloand is asynchronous and cached. * - * @param url The url for the image. + * @param url The url for the image. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; /** * Set the imageView `highlightedImage` with an `url`. * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `highlightedImage` with an `url` and custom options. * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `highlightedImage` with an `url` and custom options. * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param progressBlock A block called while image is downloading - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock; - +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; + +@end + + +@interface UIImageView (HighlightedWebCacheDeprecated) + +- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:`"); + +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:completed:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:completed:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:progress:completed:`"); @end diff --git a/SDWebImage/UIImageView+HighlightedWebCache.m b/SDWebImage/UIImageView+HighlightedWebCache.m index 1816f7b5..5a5776bd 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.m +++ b/SDWebImage/UIImageView+HighlightedWebCache.m @@ -13,23 +13,23 @@ static char operationKey; @implementation UIImageView (HighlightedWebCache) -- (void)setHighlightedImageWithURL:(NSURL *)url { - [self setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; +- (void)loadHighlightedImageWithURL:(NSURL *)url { + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:nil]; } -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { - [self setHighlightedImageWithURL:url options:options progress:nil completed:nil]; +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { + [self loadHighlightedImageWithURL:url options:options progress:nil completed:nil]; } -- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { - [self setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; +- (void)loadHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; } -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { - [self setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; } -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { [self cancelCurrentImageLoad]; if (url) { @@ -44,7 +44,7 @@ static char operationKey; [wself setNeedsLayout]; } if (completedBlock && finished) { - completedBlock(image, error, cacheType); + completedBlock(image, error, cacheType, url); } }); }]; @@ -53,3 +53,40 @@ static char operationKey; } @end + + +@implementation UIImageView (HighlightedWebCacheDeprecated) + +- (void)setHighlightedImageWithURL:(NSURL *)url { + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:nil]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { + [self loadHighlightedImageWithURL:url options:options progress:nil completed:nil]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +@end