| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /*
- * This file is part of the SDWebImage package.
- * (c) Olivier Poitrey <rs@dailymotion.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- #import "UIImageView+EMHighlightedWebCache.h"
- #import "UIView+EMWebCacheOperation.h"
- #define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage"
- @implementation UIImageView (EMHighlightedWebCache)
- - (void)sd_setHighlightedImageWithURL:(NSURL *)url {
- [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
- }
- - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(EMSDWebImageOptions)options {
- [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
- }
- - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(EMSDWebImageCompletionBlock)completedBlock {
- [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
- }
- - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(EMSDWebImageOptions)options completed:(EMSDWebImageCompletionBlock)completedBlock {
- [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
- }
- - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(EMSDWebImageOptions)options progress:(EMSDWebImageDownloaderProgressBlock)progressBlock completed:(EMSDWebImageCompletionBlock)completedBlock {
- [self sd_cancelCurrentHighlightedImageLoad];
- if (url) {
- __weak UIImageView *wself = self;
- id<EMSDWebImageOperation> operation = [EMSDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, EMSDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
- if (!wself) return;
- dispatch_main_sync_safe (^
- {
- if (!wself) return;
- if (image) {
- wself.highlightedImage = image;
- [wself setNeedsLayout];
- }
- if (completedBlock && finished) {
- completedBlock(image, error, cacheType, url);
- }
- });
- }];
- [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey];
- } else {
- dispatch_main_async_safe(^{
- NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
- if (completedBlock) {
- completedBlock(nil, error, EMSDImageCacheTypeNone, url);
- }
- });
- }
- }
- - (void)sd_cancelCurrentHighlightedImageLoad {
- [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey];
- }
- @end
- @implementation UIImageView (HighlightedWebCacheDeprecated)
- - (void)setHighlightedImageWithURL:(NSURL *)url {
- [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
- }
- - (void)setHighlightedImageWithURL:(NSURL *)url options:(EMSDWebImageOptions)options {
- [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
- }
- - (void)setHighlightedImageWithURL:(NSURL *)url completed:(EMSDWebImageCompletedBlock)completedBlock {
- [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, EMSDImageCacheType cacheType, NSURL *imageURL) {
- if (completedBlock) {
- completedBlock(image, error, cacheType);
- }
- }];
- }
- - (void)setHighlightedImageWithURL:(NSURL *)url options:(EMSDWebImageOptions)options completed:(EMSDWebImageCompletedBlock)completedBlock {
- [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, EMSDImageCacheType cacheType, NSURL *imageURL) {
- if (completedBlock) {
- completedBlock(image, error, cacheType);
- }
- }];
- }
- - (void)setHighlightedImageWithURL:(NSURL *)url options:(EMSDWebImageOptions)options progress:(EMSDWebImageDownloaderProgressBlock)progressBlock completed:(EMSDWebImageCompletedBlock)completedBlock {
- [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, EMSDImageCacheType cacheType, NSURL *imageURL) {
- if (completedBlock) {
- completedBlock(image, error, cacheType);
- }
- }];
- }
- - (void)cancelCurrentHighlightedImageLoad {
- [self sd_cancelCurrentHighlightedImageLoad];
- }
- @end
|