diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 2b86370..9f5937b 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -163,6 +163,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 */; }; + EAE09C5E23F4389600765089 /* ActionOpenPanelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAE09C5D23F4389600765089 /* ActionOpenPanelModel.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -316,6 +317,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 = ""; }; + EAE09C5D23F4389600765089 /* ActionOpenPanelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenPanelModel.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -457,6 +459,7 @@ 01F2A04D23A82CF500D954D8 /* ActionPopupModel.swift */, 01F2A04F23A82D0800D954D8 /* ActionTopAlertModel.swift */, 01C851D023CF97FE0021F976 /* ActionBackModel.swift */, + EAE09C5D23F4389600765089 /* ActionOpenPanelModel.swift */, ); path = ActionType; sourceTree = ""; @@ -904,6 +907,7 @@ D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */, 8876D5E91FB50AB000EB2E3D /* NSArray+MFConvenience.m in Sources */, 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, + EAE09C5E23F4389600765089 /* ActionOpenPanelModel.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, AFBB96581FBA3A570008D868 /* FreeBeeAuthObject.m in Sources */, 01F2A04E23A82CF500D954D8 /* ActionPopupModel.swift in Sources */, diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h index b6454c0..a4c44ec 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h @@ -16,15 +16,15 @@ @interface MVMCoreAlertHandler : NSObject -// Returns the shared instance of this singleton +/// Returns the shared instance of this singleton + (nullable instancetype)sharedAlertHandler; #pragma mark - Popup Alert Functions -// Returns if any alert is currently showing (even if supressed). +/// Returns if any alert is currently showing (even if supressed). - (BOOL)alertCurrentlyShowing; -// Returns if a greedy alert is currently showing (even if supressed). +/// Returns if a greedy alert is currently showing (even if supressed). - (BOOL)greedyAlertShowing; /** Shows the popup with the passed in parameter. @@ -53,38 +53,51 @@ */ - (nonnull UIAlertController *)showAlertWithAlertObject:(nonnull MVMCoreAlertObject *)alertObject; -// Removes all alerts. +/** Cancels and removes an alert operation for the given alertObject. + * @param alertObject The alertObject scheduled to be shown. + */ +- (void)removeAlertViewForObject:(nonnull MVMCoreAlertObject *)alertObject; + +/** Iterates through all scheduled alerts and cancels any that match the provided predicate. +* @param predicate The predicate block to decide whether to cancel an alert. +*/ +- (void)removeAlertViewUsingPredicate:(BOOL(^_Nonnull)(MVMCoreAlertObject * _Nonnull obj))predicate; + +/// Removes all alerts. - (void)removeAllAlertViews; #pragma mark - Supression Functions -// Returns true if alerts are supressed. +/// Returns true if alerts are supressed. - (BOOL)mfAlertsSupressed; -// Supresses the alerts (Used by other "apps" in our app). +/// Supresses the alerts (Used by other "apps" in our app). - (void)supressMFAlerts; -// Unsupresses the alerts (Used by other "apps" in our app). +/// Unsupresses the alerts (Used by other "apps" in our app). - (void)unSupressMFAlerts; #pragma mark - Top Alert Functions -// Show based on the object. Will be used by the architecture. +/// Show based on the object. Will be used by the architecture. - (void)showTopAlertWithObject:(nullable MVMCoreTopAlertObject *)topAlertObject; -// Convenience functions +/// Convenience functions - (void)showTopAlertErrorWithMessage:(nullable NSString *)message; - (void)showTopAlertConfirmationWithMessage:(nullable NSString *)message; - (void)showTopAlertWithType:(nullable NSString *)type message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage persistent:(BOOL)persistent actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData; - (void)showTopAlertWithType:(nullable NSString *)type message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage persistent:(BOOL)persistent buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler; -// Hides the current alert view. +/// Hides the current alert view. - (void)hideTopAlertView; -// Hides a persistent alert based on the type string. +/// Hides a persistent alert based on the type string. - (void)hidePersistentTopAlertViewOfType:(nullable NSString *)type; -// Removes all top alerts. +/// Removes a scheduled top alert given its top alert object. +- (void)removeTopAlertForObject:(nonnull MVMCoreTopAlertObject *)topAlertObject; + +/// Removes all top alerts. - (void)removeAllTopAlerts; /// Returns YES if the persistent type is already registered in the alert queue. diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.m b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.m index 5d5f93b..0c9393a 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.m +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.m @@ -107,6 +107,25 @@ return controller; } +- (void)removeAlertViewForObject:(MVMCoreAlertObject *)alertObject { + for (MVMCoreAlertOperation *operation in self.popupAlertQueue.operations) { + if ([operation.currentAlertView isKindOfClass:[MVMCoreAlertController class]] && [(MVMCoreAlertController *)operation.currentAlertView alertObject] == alertObject) { + [operation cancel]; + } + } +} + +- (void)removeAlertViewUsingPredicate:(BOOL(^)(MVMCoreAlertObject *obj))predicate { + for (MVMCoreAlertOperation *operation in self.popupAlertQueue.operations) { + if ([operation.currentAlertView isKindOfClass:[MVMCoreAlertController class]]) { + MVMCoreAlertObject *alertObject = [(MVMCoreAlertController *)operation.currentAlertView alertObject]; + if (alertObject && predicate(alertObject)) { + [operation cancel]; + } + } + } +} + - (void)removeAllAlertViews { [self.popupAlertQueue cancelAllOperations]; } @@ -225,6 +244,16 @@ } } +- (void)removeTopAlertForObject:(MVMCoreTopAlertObject *)topAlertObject { + for (MVMCoreTopAlertOperation *operation in self.topAlertQueue.operations) { + // Finds an cancels top alerts associated with the object. + if (operation.topAlertObject == topAlertObject) { + operation.reAddAfterCancel = NO; + [operation cancel]; + } + } +} + - (void)removeAllTopAlerts { [self.topAlertQueue cancelAllOperations]; } diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertOperation.h b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertOperation.h index e83ef07..c48fd86 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertOperation.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertOperation.h @@ -14,23 +14,26 @@ @interface MVMCoreAlertOperation : MVMCoreOperation -// If this operation is temporarily paused. +/// Alert controller to be displayed. +@property (nonnull, readonly) UIAlertController *currentAlertView; + +/// If this operation is temporarily paused. @property (readonly, getter=isPaused) BOOL paused; -// If this alert is a greedy alert (See MVMCoreAlertHandler). +/// If this alert is a greedy alert (See MVMCoreAlertHandler). @property (readonly, getter=isGreedy) BOOL greedy; -// The alert delegate if needed. +/// The alert delegate if needed. @property (readonly, nullable, nonatomic, weak) NSObject *alertDelegate; -// Initializes the operation with the alert to display and if it is greedy or not. +/// Initializes the operation with the alert to display and if it is greedy or not. - (nullable instancetype)initWithAlert:(nonnull UIAlertController *)alert isGreedy:(BOOL)isGreedy; - (nullable instancetype)initWithAlert:(nonnull UIAlertController *)alert isGreedy:(BOOL)isGreedy alertDelegate:(nullable id )alertDelegate; -// Pauses the operation. Temporarily removes any alert. +/// Pauses the operation. Temporarily removes any alert. - (void)pause; -// Unpauses the operation, resuming any alert. +/// Unpauses the operation, resuming any alert. - (void)unpause; @end diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPanelModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPanelModel.swift new file mode 100644 index 0000000..c439d69 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPanelModel.swift @@ -0,0 +1,23 @@ +// +// ActionOpenPanelModel.swift +// MVMCore +// +// Created by Khan, Arshad on 12/02/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionOpenPanelModel: ActionModelProtocol { + public static var identifier: String = "openPanel" + public var actionType: String? + public var panel: String + public var extraParameters: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? + // Temporary fix till server changes + public var title: String? + + public init(panel: String) { + self.panel = panel + } +} diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index bb9b0df..0183069 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -10,12 +10,13 @@ import Foundation @objcMembers public class ModelMapping: NSObject { public static func registerObjects() { - try? ModelRegistry.register(ActionOpenPageModel.self) - try? ModelRegistry.register(ActionOpenUrlModel.self) - try? ModelRegistry.register(ActionOpenAppModel.self) - try? ModelRegistry.register(ActionCallModel.self) - try? ModelRegistry.register(ActionPopupModel.self) - try? ModelRegistry.register(ActionTopAlertModel.self) - try? ModelRegistry.register(ActionBackModel.self) + ModelRegistry.register(ActionOpenPageModel.self) + ModelRegistry.register(ActionOpenUrlModel.self) + ModelRegistry.register(ActionOpenAppModel.self) + ModelRegistry.register(ActionCallModel.self) + ModelRegistry.register(ActionPopupModel.self) + ModelRegistry.register(ActionTopAlertModel.self) + ModelRegistry.register(ActionBackModel.self) + ModelRegistry.register(ActionOpenPanelModel.self) } }