Merge branch 'develop' of https://gitlab.verizon.com/BPHV_MIPS/mvm_core into develop

This commit is contained in:
Pfeil, Scott Robert 2020-06-22 10:09:41 -04:00
commit a987fd45b2
3 changed files with 49 additions and 9 deletions

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
@objcMembers public class ActionOpenPageModel: ActionModelProtocol { @objcMembers open class ActionOpenPageModel: ActionModelProtocol {
public static var identifier: String = "openPage" public static var identifier: String = "openPage"
public var actionType: String = ActionOpenPageModel.identifier public var actionType: String = ActionOpenPageModel.identifier
public var pageType: String public var pageType: String

View File

@ -20,6 +20,9 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO
@property (nullable, strong, nonatomic, readonly) NSDictionary *staticStringCache; @property (nullable, strong, nonatomic, readonly) NSDictionary *staticStringCache;
@property (nonnull, strong, nonatomic) NSOperationQueue *completionQueue; @property (nonnull, strong, nonatomic) NSOperationQueue *completionQueue;
/// Contains all bundles to search for images.
@property (nonnull, strong, nonatomic) NSMutableArray<NSBundle *>* imageBundles;
// Returns the shared instance of this singleton // Returns the shared instance of this singleton
+ (nullable instancetype)sharedCache; + (nullable instancetype)sharedCache;
@ -108,8 +111,14 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO
#pragma mark Image Functions #pragma mark Image Functions
// Subclass to return the bundle to use /// Register a bundle as one to search for images in.
- (nonnull NSBundle *)bundleToUseForImages; - (void)registerBundleForImages:(nonnull NSBundle *)bundle;
/// Tries to create an image from a registered bundle.
- (nullable UIImage *)getImageFromRegisteredBundles:(nonnull NSString *)imageName;
/// Tries to get image data from a registered bundle. Can specify the type of extension if desired.
- (nullable NSData *)getImageDataFromRegisteredBundles:(nonnull NSString *)imageName type:(nullable NSString *)type;
/// Returns if the imageName pointing to a local image. Currently just checks if it begins with http. /// Returns if the imageName pointing to a local image. Currently just checks if it begins with http.
+ (BOOL)isHostedImage:(nullable NSString *)imageName; + (BOOL)isHostedImage:(nullable NSString *)imageName;

View File

@ -57,6 +57,8 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
self.moduleQueue.maxConcurrentOperationCount = 1; self.moduleQueue.maxConcurrentOperationCount = 1;
self.imageCacheQueue = dispatch_queue_create("imgCache", DISPATCH_QUEUE_CONCURRENT); self.imageCacheQueue = dispatch_queue_create("imgCache", DISPATCH_QUEUE_CONCURRENT);
self.imageBundles = [NSMutableArray array];
} }
return self; return self;
} }
@ -374,8 +376,30 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
#pragma mark - Image Functions #pragma mark - Image Functions
- (nonnull NSBundle *)bundleToUseForImages { - (void)registerBundleForImages:(nonnull NSBundle *)bundle {
return [MVMCoreGetterUtility bundleForMVMCore]; [self.imageBundles addObject:bundle];
}
- (nullable UIImage *)getImageFromRegisteredBundles:(nonnull NSString *)imageName {
UIImage *image = nil;
for (NSBundle *bundle in self.imageBundles) {
image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
if (image) {
break;
}
}
return image;
}
- (nullable NSData *)getImageDataFromRegisteredBundles:(nonnull NSString *)imageName type:(nullable NSString *)type {
NSData *imageData = nil;
for (NSBundle *bundle in self.imageBundles) {
imageData = [NSData dataWithContentsOfFile:[bundle pathForResource:imageName ofType:type]];
if (imageData) {
break;
}
}
return imageData;
} }
- (NSMutableDictionary *)imgCache { - (NSMutableDictionary *)imgCache {
@ -487,8 +511,11 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
// Try Local. Check in memory cache // Try Local. Check in memory cache
imageData = [self getCachedDataWithName:pathOrName]; imageData = [self getCachedDataWithName:pathOrName];
if (!imageData) { if (!imageData) {
NSBundle *imageBundle = localBundle ? : [self bundleToUseForImages]; if (localBundle) {
imageData = [NSData dataWithContentsOfFile:[imageBundle pathForResource:pathOrName ofType:@"gif"]]; imageData = [NSData dataWithContentsOfFile:[localBundle pathForResource:pathOrName ofType:@"gif"]];
} else {
imageData = [self getImageDataFromRegisteredBundles:pathOrName type:@"gif"];
}
if (imageData) { if (imageData) {
[self addDataToCache:imageData withName:pathOrName]; [self addDataToCache:imageData withName:pathOrName];
} }
@ -525,7 +552,11 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
// Try native image. Check in memory cache // Try native image. Check in memory cache
image = [self getCachedImageWithName:pathOrName]; image = [self getCachedImageWithName:pathOrName];
if (!image) { if (!image) {
image = [UIImage imageNamed:pathOrName inBundle:localBundle ?: [self bundleToUseForImages] compatibleWithTraitCollection:nil]; if (localBundle) {
image = [UIImage imageNamed:pathOrName inBundle:localBundle compatibleWithTraitCollection:nil];
} else {
image = [self getImageFromRegisteredBundles:pathOrName];
}
if (image) { if (image) {
[self addImageToCache:image withName:pathOrName]; [self addImageToCache:image withName:pathOrName];
} }
@ -585,7 +616,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
image = [self getCachedImageWithName:fallbackImageName]; image = [self getCachedImageWithName:fallbackImageName];
if (!image) { if (!image) {
image = [UIImage imageNamed:fallbackImageName inBundle:[self bundleToUseForImages] compatibleWithTraitCollection:nil]; image = [self getImageFromRegisteredBundles:fallbackImageName];
if (image) { if (image) {
// Cache the fallback image if not already cached. // Cache the fallback image if not already cached.