Authored by Olivier Poitrey

Merge pull request #646 from Whirlwind/master

add category for imageView's highlighted state
@@ -193,6 +193,12 @@ @@ -193,6 +193,12 @@
193 A18A6CC8172DC28500419892 /* UIImage+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CC5172DC28500419892 /* UIImage+GIF.h */; }; 193 A18A6CC8172DC28500419892 /* UIImage+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CC5172DC28500419892 /* UIImage+GIF.h */; };
194 A18A6CC9172DC28500419892 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; }; 194 A18A6CC9172DC28500419892 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; };
195 A18A6CCA172DC28500419892 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; }; 195 A18A6CCA172DC28500419892 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; };
  196 + ABBE71A718C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = ABBE71A518C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
  197 + ABBE71A818C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = ABBE71A618C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m */; };
  198 + ABBE71A918C43B5800B75E91 /* UIImageView+HighlightedWebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = ABBE71A518C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
  199 + ABBE71AA18C43B5800B75E91 /* UIImageView+HighlightedWebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = ABBE71A518C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
  200 + ABBE71AB18C43B6000B75E91 /* UIImageView+HighlightedWebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = ABBE71A618C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m */; };
  201 + ABBE71AC18C43B6000B75E91 /* UIImageView+HighlightedWebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = ABBE71A618C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m */; };
196 /* End PBXBuildFile section */ 202 /* End PBXBuildFile section */
197 203
198 /* Begin PBXContainerItemProxy section */ 204 /* Begin PBXContainerItemProxy section */
@@ -283,6 +289,8 @@ @@ -283,6 +289,8 @@
283 5DA509F3187B68E7002FEB5C /* random.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = random.h; path = Vendors/libwebp/src/utils/random.h; sourceTree = "<group>"; }; 289 5DA509F3187B68E7002FEB5C /* random.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = random.h; path = Vendors/libwebp/src/utils/random.h; sourceTree = "<group>"; };
284 A18A6CC5172DC28500419892 /* UIImage+GIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+GIF.h"; sourceTree = "<group>"; }; 290 A18A6CC5172DC28500419892 /* UIImage+GIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+GIF.h"; sourceTree = "<group>"; };
285 A18A6CC6172DC28500419892 /* UIImage+GIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+GIF.m"; sourceTree = "<group>"; }; 291 A18A6CC6172DC28500419892 /* UIImage+GIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+GIF.m"; sourceTree = "<group>"; };
  292 + ABBE71A518C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+HighlightedWebCache.h"; sourceTree = "<group>"; };
  293 + ABBE71A618C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+HighlightedWebCache.m"; sourceTree = "<group>"; };
286 /* End PBXFileReference section */ 294 /* End PBXFileReference section */
287 295
288 /* Begin PBXFrameworksBuildPhase section */ 296 /* Begin PBXFrameworksBuildPhase section */
@@ -367,6 +375,8 @@ @@ -367,6 +375,8 @@
367 53922DA9148C562D0056699D /* Categories */ = { 375 53922DA9148C562D0056699D /* Categories */ = {
368 isa = PBXGroup; 376 isa = PBXGroup;
369 children = ( 377 children = (
  378 + ABBE71A518C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h */,
  379 + ABBE71A618C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m */,
370 5D5B9140188EE8DD006D06BD /* NSData+ImageContentType.h */, 380 5D5B9140188EE8DD006D06BD /* NSData+ImageContentType.h */,
371 5D5B9141188EE8DD006D06BD /* NSData+ImageContentType.m */, 381 5D5B9141188EE8DD006D06BD /* NSData+ImageContentType.m */,
372 53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */, 382 53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */,
@@ -511,6 +521,7 @@ @@ -511,6 +521,7 @@
511 530E49EB16464C7F002868E7 /* SDWebImageDownloaderOperation.h in Headers */, 521 530E49EB16464C7F002868E7 /* SDWebImageDownloaderOperation.h in Headers */,
512 A18A6CC8172DC28500419892 /* UIImage+GIF.h in Headers */, 522 A18A6CC8172DC28500419892 /* UIImage+GIF.h in Headers */,
513 53EDFB8B17623F7C00698166 /* UIImage+MultiFormat.h in Headers */, 523 53EDFB8B17623F7C00698166 /* UIImage+MultiFormat.h in Headers */,
  524 + ABBE71AA18C43B5800B75E91 /* UIImageView+HighlightedWebCache.h in Headers */,
514 53E481E017C300F6003E8957 /* alpha_processing.h in Headers */, 525 53E481E017C300F6003E8957 /* alpha_processing.h in Headers */,
515 53EDFB941762547D00698166 /* UIImage+WebP.h in Headers */, 526 53EDFB941762547D00698166 /* UIImage+WebP.h in Headers */,
516 53EDFC9317625BE300698166 /* webpi.h in Headers */, 527 53EDFC9317625BE300698166 /* webpi.h in Headers */,
@@ -546,6 +557,7 @@ @@ -546,6 +557,7 @@
546 53761320155AD0D5005750A4 /* UIImageView+WebCache.h in Headers */, 557 53761320155AD0D5005750A4 /* UIImageView+WebCache.h in Headers */,
547 530E49E816464C25002868E7 /* SDWebImageOperation.h in Headers */, 558 530E49E816464C25002868E7 /* SDWebImageOperation.h in Headers */,
548 530E49EA16464C7C002868E7 /* SDWebImageDownloaderOperation.h in Headers */, 559 530E49EA16464C7C002868E7 /* SDWebImageDownloaderOperation.h in Headers */,
  560 + ABBE71A718C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h in Headers */,
549 A18A6CC7172DC28500419892 /* UIImage+GIF.h in Headers */, 561 A18A6CC7172DC28500419892 /* UIImage+GIF.h in Headers */,
550 53EDFB8A17623F7C00698166 /* UIImage+MultiFormat.h in Headers */, 562 53EDFB8A17623F7C00698166 /* UIImage+MultiFormat.h in Headers */,
551 ); 563 );
@@ -568,6 +580,7 @@ @@ -568,6 +580,7 @@
568 537D95AA17ECC1FE0097C263 /* UIImage+GIF.h in Headers */, 580 537D95AA17ECC1FE0097C263 /* UIImage+GIF.h in Headers */,
569 537D95AC17ECC1FE0097C263 /* UIImage+MultiFormat.h in Headers */, 581 537D95AC17ECC1FE0097C263 /* UIImage+MultiFormat.h in Headers */,
570 537D95AD17ECC1FE0097C263 /* UIImage+WebP.h in Headers */, 582 537D95AD17ECC1FE0097C263 /* UIImage+WebP.h in Headers */,
  583 + ABBE71A918C43B5800B75E91 /* UIImageView+HighlightedWebCache.h in Headers */,
571 537D95AE17ECC1FE0097C263 /* webpi.h in Headers */, 584 537D95AE17ECC1FE0097C263 /* webpi.h in Headers */,
572 537D95AF17ECC1FE0097C263 /* vp8li.h in Headers */, 585 537D95AF17ECC1FE0097C263 /* vp8li.h in Headers */,
573 537D95B017ECC1FE0097C263 /* vp8i.h in Headers */, 586 537D95B017ECC1FE0097C263 /* vp8i.h in Headers */,
@@ -735,6 +748,7 @@ @@ -735,6 +748,7 @@
735 A18A6CCA172DC28500419892 /* UIImage+GIF.m in Sources */, 748 A18A6CCA172DC28500419892 /* UIImage+GIF.m in Sources */,
736 53EDFB8D17623F7C00698166 /* UIImage+MultiFormat.m in Sources */, 749 53EDFB8D17623F7C00698166 /* UIImage+MultiFormat.m in Sources */,
737 53EDFB961762547D00698166 /* UIImage+WebP.m in Sources */, 750 53EDFB961762547D00698166 /* UIImage+WebP.m in Sources */,
  751 + ABBE71AC18C43B6000B75E91 /* UIImageView+HighlightedWebCache.m in Sources */,
738 53EDFC9517625BE300698166 /* webp.c in Sources */, 752 53EDFC9517625BE300698166 /* webp.c in Sources */,
739 53EDFC9D17625C1100698166 /* vp8l.c in Sources */, 753 53EDFC9D17625C1100698166 /* vp8l.c in Sources */,
740 53EDFCA117625C1100698166 /* vp8.c in Sources */, 754 53EDFCA117625C1100698166 /* vp8.c in Sources */,
@@ -780,6 +794,7 @@ @@ -780,6 +794,7 @@
780 A18A6CC9172DC28500419892 /* UIImage+GIF.m in Sources */, 794 A18A6CC9172DC28500419892 /* UIImage+GIF.m in Sources */,
781 5D5B9145188EE8DD006D06BD /* NSData+ImageContentType.m in Sources */, 795 5D5B9145188EE8DD006D06BD /* NSData+ImageContentType.m in Sources */,
782 53EDFB8C17623F7C00698166 /* UIImage+MultiFormat.m in Sources */, 796 53EDFB8C17623F7C00698166 /* UIImage+MultiFormat.m in Sources */,
  797 + ABBE71A818C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m in Sources */,
783 ); 798 );
784 runOnlyForDeploymentPostprocessing = 0; 799 runOnlyForDeploymentPostprocessing = 0;
785 }; 800 };
@@ -805,6 +820,7 @@ @@ -805,6 +820,7 @@
805 537D958417ECC1FE0097C263 /* vp8.c in Sources */, 820 537D958417ECC1FE0097C263 /* vp8.c in Sources */,
806 5D5B9146188EE8DD006D06BD /* NSData+ImageContentType.m in Sources */, 821 5D5B9146188EE8DD006D06BD /* NSData+ImageContentType.m in Sources */,
807 537D958517ECC1FE0097C263 /* huffman.c in Sources */, 822 537D958517ECC1FE0097C263 /* huffman.c in Sources */,
  823 + ABBE71AB18C43B6000B75E91 /* UIImageView+HighlightedWebCache.m in Sources */,
808 537D958617ECC1FE0097C263 /* frame.c in Sources */, 824 537D958617ECC1FE0097C263 /* frame.c in Sources */,
809 537D958717ECC1FE0097C263 /* alpha.c in Sources */, 825 537D958717ECC1FE0097C263 /* alpha.c in Sources */,
810 537D958817ECC1FE0097C263 /* quant_levels_dec.c in Sources */, 826 537D958817ECC1FE0097C263 /* quant_levels_dec.c in Sources */,
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +#import "UIImageView+WebCache.h"
  11 +
  12 +/**
  13 + * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state.
  14 + */
  15 +@interface UIImageView (HighlightedWebCache)
  16 +
  17 +/**
  18 + * Set the imageView `highlightedImage` with an `url`.
  19 + *
  20 + * The downloand is asynchronous and cached.
  21 + *
  22 + * @param url The url for the image.
  23 + */
  24 +- (void)setHighlightedImageWithURL:(NSURL *)url;
  25 +/**
  26 + * Set the imageView `highlightedImage` with an `url` and custom options.
  27 + *
  28 + * The downloand is asynchronous and cached.
  29 + *
  30 + * @param url The url for the image.
  31 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  32 + */
  33 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
  34 +
  35 +/**
  36 + * Set the imageView `highlightedImage` with an `url`.
  37 + *
  38 + * The downloand is asynchronous and cached.
  39 + *
  40 + * @param url The url for the image.
  41 + * @param completedBlock A block called when operation has been completed. This block as no return value
  42 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  43 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  44 + * indicating if the image was retrived from the local cache of from the network.
  45 + */
  46 +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;
  47 +
  48 +/**
  49 + * Set the imageView `highlightedImage` with an `url` and custom options.
  50 + *
  51 + * The downloand is asynchronous and cached.
  52 + *
  53 + * @param url The url for the image.
  54 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  55 + * @param completedBlock A block called when operation has been completed. This block as no return value
  56 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  57 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  58 + * indicating if the image was retrived from the local cache of from the network.
  59 + */
  60 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
  61 +
  62 +/**
  63 + * Set the imageView `highlightedImage` with an `url` and custom options.
  64 + *
  65 + * The downloand is asynchronous and cached.
  66 + *
  67 + * @param url The url for the image.
  68 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  69 + * @param progressBlock A block called while image is downloading
  70 + * @param completedBlock A block called when operation has been completed. This block as no return value
  71 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  72 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  73 + * indicating if the image was retrived from the local cache of from the network.
  74 + */
  75 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock;
  76 +
  77 +
  78 +@end
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "UIImageView+HighlightedWebCache.h"
  10 +#import "objc/runtime.h"
  11 +
  12 +static char operationKey;
  13 +
  14 +@implementation UIImageView (HighlightedWebCache)
  15 +
  16 +- (void)setHighlightedImageWithURL:(NSURL *)url {
  17 + [self setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
  18 +}
  19 +
  20 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
  21 + [self setHighlightedImageWithURL:url options:options progress:nil completed:nil];
  22 +}
  23 +
  24 +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
  25 + [self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
  26 +}
  27 +
  28 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
  29 + [self setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
  30 +}
  31 +
  32 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
  33 + [self cancelCurrentImageLoad];
  34 +
  35 + if (url) {
  36 + __weak UIImageView *wself = self;
  37 + id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url
  38 + options:options
  39 + progress:progressBlock
  40 + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
  41 + {
  42 + if (!wself) return;
  43 + dispatch_main_sync_safe (^
  44 + {
  45 + if (!wself) return;
  46 + if (image) {
  47 + wself.highlightedImage = image;
  48 + [wself setNeedsLayout];
  49 + }
  50 + if (completedBlock && finished) {
  51 + completedBlock(image, error, cacheType);
  52 + }
  53 + });
  54 + }];
  55 + objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  56 + }
  57 +}
  58 +
  59 +@end