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

This commit is contained in:
Suresh, Kamlesh 2020-06-28 16:25:29 -04:00
commit e573262990
7 changed files with 102 additions and 12 deletions

View File

@ -8,18 +8,20 @@
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
public var extraParameters: JSONValueDictionary? public var extraParameters: JSONValueDictionary?
public var analyticsData: JSONValueDictionary? public var analyticsData: JSONValueDictionary?
public var presentationStyle: String? public var presentationStyle: String?
public var tabBarIndex: Int?
public init(pageType: String, _ presentationStyle: String? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { public init(pageType: String, presentationStyle: String? = nil, extraParameters: JSONValueDictionary? = nil, analyticsData: JSONValueDictionary? = nil, tabBarIndex: Int? = nil) {
self.pageType = pageType self.pageType = pageType
self.presentationStyle = presentationStyle self.presentationStyle = presentationStyle
self.extraParameters = extraParameters self.extraParameters = extraParameters
self.analyticsData = analyticsData self.analyticsData = analyticsData
self.tabBarIndex = tabBarIndex
} }
} }

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.

View File

@ -14,7 +14,7 @@
@class MVMCoreNavigationObject; @class MVMCoreNavigationObject;
@class MVMCoreLoadObject; @class MVMCoreLoadObject;
@interface MVMCoreNavigationHandler : NSObject @interface MVMCoreNavigationHandler : NSObject <UINavigationControllerDelegate>
// Returns the shared instance of this singleton // Returns the shared instance of this singleton
+ (nullable instancetype)sharedNavigationHandler; + (nullable instancetype)sharedNavigationHandler;
@ -25,6 +25,8 @@
// reference to main navigation controller // reference to main navigation controller
@property (nullable, weak, nonatomic) UINavigationController *navigationController; @property (nullable, weak, nonatomic) UINavigationController *navigationController;
/// A list of possible delegates looking for information.
@property (nonnull, strong, nonatomic) NSHashTable<MVMCorePresentationDelegateProtocol> *delegates;
// Will navigate appropriately based on the load style // Will navigate appropriately based on the load style
- (void)navigateWithLoadObject:(nullable MVMCoreLoadObject *)loadObject viewController:(nonnull UIViewController *)viewController delegate:(nullable NSObject<MVMCorePresentationDelegateProtocol>*)delegate completionHandler:(nullable void (^)(void))completionBlock; - (void)navigateWithLoadObject:(nullable MVMCoreLoadObject *)loadObject viewController:(nonnull UIViewController *)viewController delegate:(nullable NSObject<MVMCorePresentationDelegateProtocol>*)delegate completionHandler:(nullable void (^)(void))completionBlock;
@ -35,6 +37,14 @@
// pops or dimisses as needed // pops or dimisses as needed
- (void)removeCurrentViewController; - (void)removeCurrentViewController;
#pragma mark - Delegate Handling
/// Adds a listener for navigation delegate functions
- (void)addDelegate:(nonnull id <MVMCorePresentationDelegateProtocol>)delegate;
/// Removes a listener for navigation delegate functions
- (void)removeDelegate:(nullable id <MVMCorePresentationDelegateProtocol>)delegate;
#pragma mark - Navigation Simple #pragma mark - Navigation Simple
// Uses the default navigation controller in app delegate // Uses the default navigation controller in app delegate

View File

@ -47,10 +47,24 @@
self.presentationQueue = [[NSOperationQueue alloc] init]; self.presentationQueue = [[NSOperationQueue alloc] init];
self.presentationQueue.maxConcurrentOperationCount = 1; self.presentationQueue.maxConcurrentOperationCount = 1;
self.delegates = (NSHashTable <MVMCorePresentationDelegateProtocol>*)[NSHashTable weakObjectsHashTable];
} }
return self; return self;
} }
#pragma mark - Delegate Handling
- (void)addDelegate:(nonnull id <MVMCorePresentationDelegateProtocol>)delegate {
[self.delegates addObject:delegate];
}
- (void)removeDelegate:(nullable id <MVMCorePresentationDelegateProtocol>)delegate {
[self.delegates removeObject:delegate];
}
#pragma mark - Navigation Helpers
- (void)navigateWithLoadObject:(nullable MVMCoreLoadObject *)loadObject viewController:(nonnull UIViewController *)viewController delegate:(nullable NSObject<MVMCorePresentationDelegateProtocol>*)delegate completionHandler:(nullable void (^)(void))completionBlock { - (void)navigateWithLoadObject:(nullable MVMCoreLoadObject *)loadObject viewController:(nonnull UIViewController *)viewController delegate:(nullable NSObject<MVMCorePresentationDelegateProtocol>*)delegate completionHandler:(nullable void (^)(void))completionBlock {
BOOL shouldAnimate = !loadObject.requestParameters.shouldNotAnimatePush; BOOL shouldAnimate = !loadObject.requestParameters.shouldNotAnimatePush;

View File

@ -13,6 +13,7 @@
#import "MVMCoreLoggingHandler.h" #import "MVMCoreLoggingHandler.h"
#import "MVMCoreLoadingOverlayHandler.h" #import "MVMCoreLoadingOverlayHandler.h"
#import "MVMCoreViewControllerAnimatedTransitioning.h" #import "MVMCoreViewControllerAnimatedTransitioning.h"
#import "MVMCoreNavigationHandler.h"
@interface MVMCoreNavigationOperation () @interface MVMCoreNavigationOperation ()
@ -225,6 +226,8 @@
[super markAsFinished]; [super markAsFinished];
} }
#pragma mark - Delegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.navigationObject.stopLoadingOverlay) { if (self.navigationObject.stopLoadingOverlay) {
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:YES]; [[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:YES];
@ -234,6 +237,11 @@
if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:willDisplayViewController:)]) { if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:willDisplayViewController:)]) {
[self.delegate navigationController:navigationController willDisplayViewController:viewController]; [self.delegate navigationController:navigationController willDisplayViewController:viewController];
} }
for (NSObject<MVMCorePresentationDelegateProtocol> *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates.allObjects) {
if (delegate && [delegate respondsToSelector:@selector(navigationController:willDisplayViewController:)]) {
[delegate navigationController:navigationController willDisplayViewController:viewController];
}
}
} }
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
@ -241,8 +249,13 @@
if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:displayedViewController:)]) { if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:displayedViewController:)]) {
[self.delegate navigationController:navigationController displayedViewController:viewController]; [self.delegate navigationController:navigationController displayedViewController:viewController];
} }
for (NSObject<MVMCorePresentationDelegateProtocol> *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates.allObjects) {
if (delegate && [delegate respondsToSelector:@selector(navigationController:displayedViewController:)]) {
[delegate navigationController:navigationController displayedViewController:viewController];
}
}
[self markAsFinished]; [self markAsFinished];
// Notify that page has changed // Legacy notify that page has changed
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:MVMCoreNotificationViewControllerChanged object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:MVMCoreNotificationViewControllerChanged object:nil];
}); });

View File

@ -7,6 +7,7 @@
// //
#import "MVMCorePresentAnimationOperation.h" #import "MVMCorePresentAnimationOperation.h"
#import "MVMCoreNavigationHandler.h"
@interface MVMCorePresentAnimationOperation () @interface MVMCorePresentAnimationOperation ()
@ -39,12 +40,22 @@
if (self.delegate && [self.delegate respondsToSelector:@selector(viewController:willPresentViewController:)]) { if (self.delegate && [self.delegate respondsToSelector:@selector(viewController:willPresentViewController:)]) {
[self.delegate viewController:self.presentingViewController willPresentViewController:self.presentedViewController]; [self.delegate viewController:self.presentingViewController willPresentViewController:self.presentedViewController];
} }
for (NSObject<MVMCorePresentationDelegateProtocol> *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates.allObjects) {
if (delegate && [delegate respondsToSelector:@selector(viewController:willPresentViewController:)]) {
[delegate viewController:self.presentingViewController willPresentViewController:self.presentedViewController];
}
}
[self.presentingViewController presentViewController:self.presentedViewController animated:self.animate completion:^{ [self.presentingViewController presentViewController:self.presentedViewController animated:self.animate completion:^{
if (self.delegate && [self.delegate respondsToSelector:@selector(viewController:didPresentViewController:)]) { if (self.delegate && [self.delegate respondsToSelector:@selector(viewController:didPresentViewController:)]) {
[self.delegate viewController:self.presentingViewController didPresentViewController:self.presentedViewController]; [self.delegate viewController:self.presentingViewController didPresentViewController:self.presentedViewController];
} }
for (NSObject<MVMCorePresentationDelegateProtocol> *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates.allObjects) {
if (delegate && [delegate respondsToSelector:@selector(viewController:didPresentViewController:)]) {
[delegate viewController:self.presentingViewController didPresentViewController:self.presentedViewController];
}
}
[self markAsFinished]; [self markAsFinished];
}]; }];
} }