Authored by Bogdan Poplauschi

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
@@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
21 * 21 *
22 * @param url The url for the image. 22 * @param url The url for the image.
23 */ 23 */
24 -- (void)setHighlightedImageWithURL:(NSURL *)url; 24 +- (void)loadHighlightedImageWithURL:(NSURL *)url;
25 25
26 /** 26 /**
27 * Set the imageView `highlightedImage` with an `url` and custom options. 27 * Set the imageView `highlightedImage` with an `url` and custom options.
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 * @param url The url for the image. 31 * @param url The url for the image.
32 * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 32 * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
33 */ 33 */
34 -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; 34 +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
35 35
36 /** 36 /**
37 * Set the imageView `highlightedImage` with an `url`. 37 * Set the imageView `highlightedImage` with an `url`.
@@ -39,12 +39,13 @@ @@ -39,12 +39,13 @@
39 * The downloand is asynchronous and cached. 39 * The downloand is asynchronous and cached.
40 * 40 *
41 * @param url The url for the image. 41 * @param url The url for the image.
42 - * @param completedBlock A block called when operation has been completed. This block as no return value 42 + * @param completedBlock A block called when operation has been completed. This block has no return value
43 * and takes the requested UIImage as first parameter. In case of error the image parameter 43 * and takes the requested UIImage as first parameter. In case of error the image parameter
44 * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 44 * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
45 * indicating if the image was retrived from the local cache of from the network. 45 * indicating if the image was retrived from the local cache of from the network.
  46 + * The forth parameter is the original image url.
46 */ 47 */
47 -- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock; 48 +- (void)loadHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
48 49
49 /** 50 /**
50 * Set the imageView `highlightedImage` with an `url` and custom options. 51 * Set the imageView `highlightedImage` with an `url` and custom options.
@@ -53,12 +54,13 @@ @@ -53,12 +54,13 @@
53 * 54 *
54 * @param url The url for the image. 55 * @param url The url for the image.
55 * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 56 * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
56 - * @param completedBlock A block called when operation has been completed. This block as no return value 57 + * @param completedBlock A block called when operation has been completed. This block has no return value
57 * and takes the requested UIImage as first parameter. In case of error the image parameter 58 * and takes the requested UIImage as first parameter. In case of error the image parameter
58 * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 59 * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
59 * indicating if the image was retrived from the local cache of from the network. 60 * indicating if the image was retrived from the local cache of from the network.
  61 + * The forth parameter is the original image url.
60 */ 62 */
61 -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock; 63 +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
62 64
63 /** 65 /**
64 * Set the imageView `highlightedImage` with an `url` and custom options. 66 * Set the imageView `highlightedImage` with an `url` and custom options.
@@ -68,12 +70,24 @@ @@ -68,12 +70,24 @@
68 * @param url The url for the image. 70 * @param url The url for the image.
69 * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 71 * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
70 * @param progressBlock A block called while image is downloading 72 * @param progressBlock A block called while image is downloading
71 - * @param completedBlock A block called when operation has been completed. This block as no return value 73 + * @param completedBlock A block called when operation has been completed. This block has no return value
72 * and takes the requested UIImage as first parameter. In case of error the image parameter 74 * and takes the requested UIImage as first parameter. In case of error the image parameter
73 * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 75 * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
74 * indicating if the image was retrived from the local cache of from the network. 76 * indicating if the image was retrived from the local cache of from the network.
  77 + * The forth parameter is the original image url.
75 */ 78 */
76 -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock; 79 +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
77 80
  81 +@end
  82 +
  83 +
  84 +@interface UIImageView (HighlightedWebCacheDeprecated)
  85 +
  86 +- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:`");
  87 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:`");
  88 +
  89 +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:completed:`");
  90 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:completed:`");
  91 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:progress:completed:`");
78 92
79 @end 93 @end
@@ -13,23 +13,23 @@ static char operationKey; @@ -13,23 +13,23 @@ static char operationKey;
13 13
14 @implementation UIImageView (HighlightedWebCache) 14 @implementation UIImageView (HighlightedWebCache)
15 15
16 -- (void)setHighlightedImageWithURL:(NSURL *)url {  
17 - [self setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; 16 +- (void)loadHighlightedImageWithURL:(NSURL *)url {
  17 + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:nil];
18 } 18 }
19 19
20 -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {  
21 - [self setHighlightedImageWithURL:url options:options progress:nil completed:nil]; 20 +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
  21 + [self loadHighlightedImageWithURL:url options:options progress:nil completed:nil];
22 } 22 }
23 23
24 -- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {  
25 - [self setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; 24 +- (void)loadHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
  25 + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
26 } 26 }
27 27
28 -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {  
29 - [self setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; 28 +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
  29 + [self loadHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
30 } 30 }
31 31
32 -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { 32 +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
33 [self cancelCurrentImageLoad]; 33 [self cancelCurrentImageLoad];
34 34
35 if (url) { 35 if (url) {
@@ -44,7 +44,7 @@ static char operationKey; @@ -44,7 +44,7 @@ static char operationKey;
44 [wself setNeedsLayout]; 44 [wself setNeedsLayout];
45 } 45 }
46 if (completedBlock && finished) { 46 if (completedBlock && finished) {
47 - completedBlock(image, error, cacheType); 47 + completedBlock(image, error, cacheType, url);
48 } 48 }
49 }); 49 });
50 }]; 50 }];
@@ -53,3 +53,40 @@ static char operationKey; @@ -53,3 +53,40 @@ static char operationKey;
53 } 53 }
54 54
55 @end 55 @end
  56 +
  57 +
  58 +@implementation UIImageView (HighlightedWebCacheDeprecated)
  59 +
  60 +- (void)setHighlightedImageWithURL:(NSURL *)url {
  61 + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:nil];
  62 +}
  63 +
  64 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
  65 + [self loadHighlightedImageWithURL:url options:options progress:nil completed:nil];
  66 +}
  67 +
  68 +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
  69 + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  70 + if (completedBlock) {
  71 + completedBlock(image, error, cacheType);
  72 + }
  73 + }];
  74 +}
  75 +
  76 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
  77 + [self loadHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  78 + if (completedBlock) {
  79 + completedBlock(image, error, cacheType);
  80 + }
  81 + }];
  82 +}
  83 +
  84 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
  85 + [self loadHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  86 + if (completedBlock) {
  87 + completedBlock(image, error, cacheType);
  88 + }
  89 + }];
  90 +}
  91 +
  92 +@end