Replaced #1640 - Added `sd_` prefix to the activity indicator related methods (`setShowActivityIndicatorView:`, `setIndicatorStyle:`, `showActivityIndicatorView`, `addActivityIndicator`, `removeActivityIndicator`)

This commit is contained in:
Bogdan Poplauschi 2016-09-30 21:36:34 +03:00
parent fc3a4d8170
commit 17ae791953
4 changed files with 19 additions and 18 deletions

View File

@ -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 - 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 - 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` - Removed `UIImageView` `sd_cancelCurrentHighlightedImageLoad`
- Added `sd_` prefix to the activity indicator related methods (`setShowActivityIndicatorView:`, `setIndicatorStyle:`, `showActivityIndicatorView`, `addActivityIndicator`, `removeActivityIndicator`) #1640
#### Features: #### Features:

View File

@ -124,8 +124,8 @@
cell = [[MyCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell = [[MyCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
} }
[cell.customImageView setShowActivityIndicatorView:YES]; [cell.customImageView sd_setShowActivityIndicatorView:YES];
[cell.customImageView setIndicatorStyle:UIActivityIndicatorViewStyleGray]; [cell.customImageView sd_setIndicatorStyle:UIActivityIndicatorViewStyleGray];
cell.customTextLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row]; cell.customTextLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row];
[cell.customImageView sd_setImageWithURL:[NSURL URLWithString:_objects[indexPath.row]] [cell.customImageView sd_setImageWithURL:[NSURL URLWithString:_objects[indexPath.row]]

View File

@ -61,18 +61,18 @@ typedef void(^SDSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable ima
/** /**
* Show activity UIActivityIndicatorView * Show activity UIActivityIndicatorView
*/ */
- (void)setShowActivityIndicatorView:(BOOL)show; - (void)sd_setShowActivityIndicatorView:(BOOL)show;
/** /**
* set desired UIActivityIndicatorViewStyle * set desired UIActivityIndicatorViewStyle
* *
* @param style The style of the UIActivityIndicatorView * @param style The style of the UIActivityIndicatorView
*/ */
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style; - (void)sd_setIndicatorStyle:(UIActivityIndicatorViewStyle)style;
- (BOOL)showActivityIndicatorView; - (BOOL)sd_showActivityIndicatorView;
- (void)addActivityIndicator; - (void)sd_addActivityIndicator;
- (void)removeActivityIndicator; - (void)sd_removeActivityIndicator;
#endif #endif

View File

@ -46,14 +46,14 @@ static char TAG_ACTIVITY_SHOW;
if (url) { if (url) {
// check if activityView is enabled or not // check if activityView is enabled or not
if ([self showActivityIndicatorView]) { if ([self sd_showActivityIndicatorView]) {
[self addActivityIndicator]; [self sd_addActivityIndicator];
} }
__weak __typeof(self)wself = self; __weak __typeof(self)wself = self;
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { id <SDWebImageOperation> 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; __strong __typeof (wself) sself = wself;
[sself removeActivityIndicator]; [sself sd_removeActivityIndicator];
if (!sself) { if (!sself) {
return; return;
} }
@ -81,7 +81,7 @@ static char TAG_ACTIVITY_SHOW;
[self sd_setImageLoadOperation:operation forKey:validOperationKey]; [self sd_setImageLoadOperation:operation forKey:validOperationKey];
} else { } else {
dispatch_main_async_safe(^{ dispatch_main_async_safe(^{
[self removeActivityIndicator]; [self sd_removeActivityIndicator];
if (completedBlock) { if (completedBlock) {
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
completedBlock(nil, error, SDImageCacheTypeNone, url); completedBlock(nil, error, SDImageCacheTypeNone, url);
@ -136,28 +136,28 @@ static char TAG_ACTIVITY_SHOW;
} }
#endif #endif
- (void)setShowActivityIndicatorView:(BOOL)show { - (void)sd_setShowActivityIndicatorView:(BOOL)show {
objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, @(show), OBJC_ASSOCIATION_RETAIN); objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, @(show), OBJC_ASSOCIATION_RETAIN);
} }
- (BOOL)showActivityIndicatorView { - (BOOL)sd_showActivityIndicatorView {
return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue]; return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue];
} }
#if SD_UIKIT #if SD_UIKIT
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{ - (void)sd_setIndicatorStyle:(UIActivityIndicatorViewStyle)style{
objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN); 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]; return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue];
} }
#endif #endif
- (void)addActivityIndicator { - (void)sd_addActivityIndicator {
#if SD_UIKIT #if SD_UIKIT
if (!self.activityIndicator) { if (!self.activityIndicator) {
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]]; self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self sd_getIndicatorStyle]];
self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO; self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO;
dispatch_main_async_safe(^{ dispatch_main_async_safe(^{
@ -186,7 +186,7 @@ static char TAG_ACTIVITY_SHOW;
#endif #endif
} }
- (void)removeActivityIndicator { - (void)sd_removeActivityIndicator {
#if SD_UIKIT #if SD_UIKIT
if (self.activityIndicator) { if (self.activityIndicator) {
[self.activityIndicator removeFromSuperview]; [self.activityIndicator removeFromSuperview];