From 310af60183edc2cf2bff75fe940393cc655ca047 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 19 Aug 2019 13:30:50 -0400 Subject: [PATCH] height changes minor --- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h | 3 +++ MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h index 6d7d5a9..223ab5f 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h @@ -111,6 +111,9 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO // Subclass to return the bundle to use - (nonnull NSBundle *)bundleToUseForImages; +/// Returns if the imageName pointing to a local image. Currently just checks if it begins with http. ++ (BOOL)isHostedImage:(nullable NSString *)imageName; + // Checks if the image is in the cache. If not, will try to download or create the image. // Width is used for downloading from scene7. // Height is used for downloading from scene7. diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 7e12a81..2e61955 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -387,6 +387,10 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; return _imgCache; } ++ (BOOL)isHostedImage:(nullable NSString *)imageName { + return imageName.length >=4 && [[imageName substringToIndex:4] isEqualToString:@"http"]; +} + - (NSURL *)handleS7Path:(NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format finalRect:(CGRect)finalRect flipImage:(BOOL)flipImage { // For scene 7 @@ -466,7 +470,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData *imageData = nil; if (pathOrName.length > 0) { - if (pathOrName.length >=4 && [[pathOrName substringToIndex:4] isEqualToString:@"http"]) { + if ([MVMCoreCache isHostedImage:pathOrName]) { // Gets the full path NSURL *s7URL = [self handleS7Path:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:CGRectNull flipImage:NO]; if (s7URL) { @@ -498,7 +502,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; UIImage *image = nil; if (pathOrName.length > 0) { // try the url if it's a url. - if (pathOrName.length >=4 && [[pathOrName substringToIndex:4] isEqualToString:@"http"]) { + if ([MVMCoreCache isHostedImage:pathOrName]) { // Gets the full path NSURL *s7URL = [self handleS7Path:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:finalRect flipImage:flip]; if (s7URL) { @@ -633,7 +637,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; if (imageName) { dispatch_barrier_async(self.imageCacheQueue, ^{ - if ([imageName hasPrefix:@"http"]) { + if ([MVMCoreCache isHostedImage:imageName]) { for (NSString *key in self.imgCache.allKeys) { NSURLComponents *components = [[NSURLComponents alloc] initWithString:key]; if (components) {