From 6b23b3589050405ea8551f8cc2f1192cce59af99 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 21 Oct 2021 10:25:46 -0500 Subject: [PATCH] added other action handler api Signed-off-by: Matt Bruce --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 +++ .../ActionHandling/MVMCoreActionHandler.h | 3 +++ .../ActionHandling/MVMCoreActionHandler.m | 26 ++++++++++++++++++- .../MVMOtherActionHandlerDelegate.h | 21 +++++++++++++++ MVMCore/MVMCore/MVMCore.h | 1 + 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 MVMCore/MVMCore/ActionHandling/MVMOtherActionHandlerDelegate.h diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 22c445b..4e87407 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -156,6 +156,7 @@ D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */; }; D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCBA23C65BC300C44CC4 /* Percent.swift */; }; D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */; }; + EA34EF3327207AAC00DFC625 /* MVMOtherActionHandlerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = EA34EF322720788700DFC625 /* MVMOtherActionHandlerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; EA3B264C25FC0B7600008074 /* ModelHandlerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3B264B25FC0B7600008074 /* ModelHandlerProtocol.swift */; }; /* End PBXBuildFile section */ @@ -303,6 +304,7 @@ D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitInterval.swift; sourceTree = ""; }; D2DEDCBA23C65BC300C44CC4 /* Percent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Percent.swift; sourceTree = ""; }; D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelegateObject.swift; sourceTree = ""; }; + EA34EF322720788700DFC625 /* MVMOtherActionHandlerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMOtherActionHandlerDelegate.h; sourceTree = ""; }; EA3B264B25FC0B7600008074 /* ModelHandlerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelHandlerProtocol.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -615,6 +617,7 @@ AFBB96B61FBA3CEC0008D868 /* MVMCoreActionHandler.h */, AFBB96B71FBA3CEC0008D868 /* MVMCoreActionHandler.m */, D27073CC25BB4CEF001C7246 /* MVMCoreActionHandler+Extension.swift */, + EA34EF322720788700DFC625 /* MVMOtherActionHandlerDelegate.h */, ); path = ActionHandling; sourceTree = ""; @@ -741,6 +744,7 @@ AF43A74C1FC6109F008E9347 /* MVMCoreSessionObject.h in Headers */, 8876D5F41FB50AB000EB2E3D /* UILabel+MFCustom.h in Headers */, AFFCFA681FCCC0D700FD0730 /* MVMCoreLoadingViewControllerProtocol.h in Headers */, + EA34EF3327207AAC00DFC625 /* MVMOtherActionHandlerDelegate.h in Headers */, AFED77A21FCCA29400BAE689 /* MVMCoreViewControllerMappingObject.h in Headers */, AFFCFA661FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.h in Headers */, ); diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index 1dc2aa5..da39dc1 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -11,6 +11,7 @@ #import #import #import +#import @class DelegateObject; extern NSString * _Nonnull const KeyActionType; @@ -22,6 +23,8 @@ extern NSString * _Nonnull const KeyActionTypeOpen; /// Returns the shared action handler + (nullable instancetype)sharedActionHandler; +- (void) registerOtherActionHandler: (id _Nonnull)delegate; + /// Convenience function for handling actions. This will pull action and pageInfo out of the dictionary and call handleAction: actionInformation: with those values - (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 4f307f5..3386bbc 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -34,6 +34,8 @@ NSString * const KeyActionTypeLinkAway = @"openURL"; NSString * const KeyActionTypeOpen = @"openPage"; @interface MVMCoreActionHandler() +@property (nonatomic, nonnull, strong) NSMutableArray> *otherActionHandlers; + @end @implementation MVMCoreActionHandler @@ -41,6 +43,26 @@ NSString * const KeyActionTypeOpen = @"openPage"; return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].actionHandler classToVerify:self]; } +- (instancetype) init { + if (self = [super init]) { + self.otherActionHandlers = [[NSMutableArray alloc] init]; + } + return self; +} + +- (void) registerOtherActionHandler: (id _Nonnull)delegate{ + [self.otherActionHandlers addObject:delegate]; +} + +- (BOOL)handleActionWithAdditionalHandlers:(NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(DelegateObject *)delegateObject { + for (id handler in self.otherActionHandlers) { + if ([handler respondsToSelector:@selector(handleOtherActions:actionInformation:additionalData:delegateObject:)] && [handler handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]) { + return YES; + } + } + return NO; +} + - (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { NSString *action = [dictionary stringForKey:KeyActionType]; @@ -100,6 +122,8 @@ NSString * const KeyActionTypeOpen = @"openPage"; // not a known action type. [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; } + + } - (void)getClientParameter:(nullable NSDictionary *)clientParametersMap requestParameters:(nullable NSDictionary *)requestParameters showLoadingOverlay:(BOOL)showLoadingOverlay completionHandler:(nonnull void (^)(NSDictionary * _Nullable parameters))completionHandler { @@ -387,7 +411,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; } - (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - return NO; + return [self handleActionWithAdditionalHandlers:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; } - (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { diff --git a/MVMCore/MVMCore/ActionHandling/MVMOtherActionHandlerDelegate.h b/MVMCore/MVMCore/ActionHandling/MVMOtherActionHandlerDelegate.h new file mode 100644 index 0000000..8d524a3 --- /dev/null +++ b/MVMCore/MVMCore/ActionHandling/MVMOtherActionHandlerDelegate.h @@ -0,0 +1,21 @@ +// +// MVMOtherActionHandlerDelegate.h +// MVMCore +// +// Created by Matt Bruce on 10/20/21. +// Copyright © 2021 myverizon. All rights reserved. +// + +#ifndef MVMOtherActionHandlerDelegate_h +#define MVMOtherActionHandlerDelegate_h +@class DelegateObject; + +@protocol MVMOtherActionHandlerDelegate + +@optional + +- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; + +@end + +#endif /* MVMOtherActionHandlerDelegate_h */ diff --git a/MVMCore/MVMCore/MVMCore.h b/MVMCore/MVMCore/MVMCore.h index 7ef1d6e..8bf0e4f 100644 --- a/MVMCore/MVMCore/MVMCore.h +++ b/MVMCore/MVMCore/MVMCore.h @@ -69,6 +69,7 @@ FOUNDATION_EXPORT const unsigned char MVMCoreVersionString[]; #import #import #import +#import // Protocols #import