From 17ae79195312128ae77fce7798e82a6be22dba9b Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Fri, 30 Sep 2016 21:36:34 +0300 Subject: [PATCH] Replaced #1640 - Added `sd_` prefix to the activity indicator related methods (`setShowActivityIndicatorView:`, `setIndicatorStyle:`, `showActivityIndicatorView`, `addActivityIndicator`, `removeActivityIndicator`) --- CHANGELOG.md | 1 + .../SDWebImage Demo/MasterViewController.m | 4 ++-- SDWebImage/UIView+WebCache.h | 10 ++++----- SDWebImage/UIView+WebCache.m | 22 +++++++++---------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b3dba40..0de3d1be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ - Another `SDImageCache` clarification: `imageFromDiskCacheForKey:` used to also check the memory cache which I think is misleading. Now `imageFromDiskCacheForKey` only checks the disk cache and the new method `imageFromCacheForKey` checks both caches - Got rid of `removeImageForKey:` and `removeImageForKey:fromDisk:` from `SDImageCache` that looked sync but were async. Left only the 2 async ones - Removed `UIImageView` `sd_cancelCurrentHighlightedImageLoad` +- Added `sd_` prefix to the activity indicator related methods (`setShowActivityIndicatorView:`, `setIndicatorStyle:`, `showActivityIndicatorView`, `addActivityIndicator`, `removeActivityIndicator`) #1640 #### Features: diff --git a/Examples/SDWebImage Demo/MasterViewController.m b/Examples/SDWebImage Demo/MasterViewController.m index 33cc82ba..70fcc1e4 100644 --- a/Examples/SDWebImage Demo/MasterViewController.m +++ b/Examples/SDWebImage Demo/MasterViewController.m @@ -124,8 +124,8 @@ cell = [[MyCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } - [cell.customImageView setShowActivityIndicatorView:YES]; - [cell.customImageView setIndicatorStyle:UIActivityIndicatorViewStyleGray]; + [cell.customImageView sd_setShowActivityIndicatorView:YES]; + [cell.customImageView sd_setIndicatorStyle:UIActivityIndicatorViewStyleGray]; cell.customTextLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row]; [cell.customImageView sd_setImageWithURL:[NSURL URLWithString:_objects[indexPath.row]] diff --git a/SDWebImage/UIView+WebCache.h b/SDWebImage/UIView+WebCache.h index bab19f1e..d6a71068 100644 --- a/SDWebImage/UIView+WebCache.h +++ b/SDWebImage/UIView+WebCache.h @@ -61,18 +61,18 @@ typedef void(^SDSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable ima /** * Show activity UIActivityIndicatorView */ -- (void)setShowActivityIndicatorView:(BOOL)show; +- (void)sd_setShowActivityIndicatorView:(BOOL)show; /** * set desired UIActivityIndicatorViewStyle * * @param style The style of the UIActivityIndicatorView */ -- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style; +- (void)sd_setIndicatorStyle:(UIActivityIndicatorViewStyle)style; -- (BOOL)showActivityIndicatorView; -- (void)addActivityIndicator; -- (void)removeActivityIndicator; +- (BOOL)sd_showActivityIndicatorView; +- (void)sd_addActivityIndicator; +- (void)sd_removeActivityIndicator; #endif diff --git a/SDWebImage/UIView+WebCache.m b/SDWebImage/UIView+WebCache.m index 32a76ed8..ad2b54c4 100644 --- a/SDWebImage/UIView+WebCache.m +++ b/SDWebImage/UIView+WebCache.m @@ -46,14 +46,14 @@ static char TAG_ACTIVITY_SHOW; if (url) { // check if activityView is enabled or not - if ([self showActivityIndicatorView]) { - [self addActivityIndicator]; + if ([self sd_showActivityIndicatorView]) { + [self sd_addActivityIndicator]; } __weak __typeof(self)wself = self; id operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { __strong __typeof (wself) sself = wself; - [sself removeActivityIndicator]; + [sself sd_removeActivityIndicator]; if (!sself) { return; } @@ -81,7 +81,7 @@ static char TAG_ACTIVITY_SHOW; [self sd_setImageLoadOperation:operation forKey:validOperationKey]; } else { dispatch_main_async_safe(^{ - [self removeActivityIndicator]; + [self sd_removeActivityIndicator]; if (completedBlock) { NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; completedBlock(nil, error, SDImageCacheTypeNone, url); @@ -136,28 +136,28 @@ static char TAG_ACTIVITY_SHOW; } #endif -- (void)setShowActivityIndicatorView:(BOOL)show { +- (void)sd_setShowActivityIndicatorView:(BOOL)show { objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, @(show), OBJC_ASSOCIATION_RETAIN); } -- (BOOL)showActivityIndicatorView { +- (BOOL)sd_showActivityIndicatorView { return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue]; } #if SD_UIKIT -- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{ +- (void)sd_setIndicatorStyle:(UIActivityIndicatorViewStyle)style{ objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN); } -- (int)getIndicatorStyle{ +- (int)sd_getIndicatorStyle{ return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue]; } #endif -- (void)addActivityIndicator { +- (void)sd_addActivityIndicator { #if SD_UIKIT if (!self.activityIndicator) { - self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]]; + self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self sd_getIndicatorStyle]]; self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO; dispatch_main_async_safe(^{ @@ -186,7 +186,7 @@ static char TAG_ACTIVITY_SHOW; #endif } -- (void)removeActivityIndicator { +- (void)sd_removeActivityIndicator { #if SD_UIKIT if (self.activityIndicator) { [self.activityIndicator removeFromSuperview];