From e55d9e14f680e37282afe975ae68cffa025776d0 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Mon, 17 Apr 2023 13:04:45 -0400 Subject: [PATCH] Swiftify Alert --- MVMCoreUI.xcodeproj/project.pbxproj | 16 +-- MVMCoreUI/Alerts/AlertHandler.swift | 6 +- MVMCoreUI/Alerts/AlertOperation.swift | 22 ++-- .../Alerts/MVMCoreAlertDelegateProtocol.h | 11 +- .../Alerts/MVMCoreAlertObject+Swift.swift | 2 +- MVMCoreUI/Alerts/TopNotificationHandler.swift | 10 -- .../Atomic/Actions/ActionPopupHandler.swift | 121 ------------------ .../Atomic/Actions/ActionPopupModel.swift | 31 ----- MVMCoreUI/Atomic/Actions/AlertModel.swift | 2 +- MVMCoreUI/MVMCoreUI.h | 1 - .../OtherHandlers/CoreUIModelMapping.swift | 1 - .../MVMCoreUIActionDelegateProtocol.h | 16 --- .../MVMCoreUILoggingDelegateProtocol.swift | 13 ++ 13 files changed, 36 insertions(+), 216 deletions(-) delete mode 100644 MVMCoreUI/Atomic/Actions/ActionPopupHandler.swift delete mode 100644 MVMCoreUI/Atomic/Actions/ActionPopupModel.swift delete mode 100644 MVMCoreUI/OtherHandlers/MVMCoreUIActionDelegateProtocol.h create mode 100644 MVMCoreUI/OtherHandlers/MVMCoreUILoggingDelegateProtocol.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 202e1d54..1a59212b 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -278,7 +278,6 @@ AAE96FA225341F6A0037A989 /* ListStoreLocatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */; }; AAE96FA525341F7D0037A989 /* ListStoreLocator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */; }; AF1C33652883B5A4006B1001 /* ActionTopNotificationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C33642883B5A4006B1001 /* ActionTopNotificationHandler.swift */; }; - AF1C33672883B712006B1001 /* ActionPopupHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C33662883B712006B1001 /* ActionPopupHandler.swift */; }; AF1C336928859778006B1001 /* ActionAlertHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C336828859778006B1001 /* ActionAlertHandler.swift */; }; AF1C336B28859C73006B1001 /* ActionTopAlertHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C336A28859C73006B1001 /* ActionTopAlertHandler.swift */; }; AF1C336D28859EE1006B1001 /* ActionOpenPanelHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C336C28859EE1006B1001 /* ActionOpenPanelHandler.swift */; }; @@ -291,6 +290,7 @@ AF7E509929E477C1009DC2AD /* AlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF7E509729E477C0009DC2AD /* AlertController.swift */; }; AFA4932029E5CA73001A9663 /* AlertOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA4931F29E5CA73001A9663 /* AlertOperation.swift */; }; AFA4932229E5EF2E001A9663 /* TopNotificationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA4932129E5EF2E001A9663 /* TopNotificationHandler.swift */; }; + AFA4933F29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA4933E29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift */; }; AFE4A1D127DFB5EE00C458D0 /* VDSColorTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = AFE4A1D027DFB5EE00C458D0 /* VDSColorTokens.xcframework */; }; AFE4A1D627DFBB6F00C458D0 /* UINavigationController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFE4A1D527DFBB6F00C458D0 /* UINavigationController+Extension.swift */; }; BB105859248DEFF70069D008 /* UICollectionViewLeftAlignedLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */; }; @@ -560,7 +560,6 @@ D2EC7BDD2527B83700F540AF /* SectionHeaderFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2EC7BDC2527B83700F540AF /* SectionHeaderFooterView.swift */; }; D2ED27EB254B0CE700A1C293 /* UIAlertActionStyle+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27E6254B0CE600A1C293 /* UIAlertActionStyle+Codable.swift */; }; D2ED27EC254B0CE700A1C293 /* UIAlertControllerStyle+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27E7254B0CE600A1C293 /* UIAlertControllerStyle+Extension.swift */; }; - D2ED27ED254B0CE700A1C293 /* ActionPopupModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27E8254B0CE600A1C293 /* ActionPopupModel.swift */; }; D2ED27EE254B0CE700A1C293 /* ActionAlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27E9254B0CE600A1C293 /* ActionAlertModel.swift */; }; D2ED27EF254B0CE700A1C293 /* AlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27EA254B0CE700A1C293 /* AlertModel.swift */; }; D2ED27FB254B0E0300A1C293 /* MVMCoreAlertDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED27F2254B0E0200A1C293 /* MVMCoreAlertDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -573,7 +572,6 @@ D2ED2811254B0EB800A1C293 /* MVMCoreTopAlertObject.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED280A254B0EB700A1C293 /* MVMCoreTopAlertObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D2ED2812254B0EB800A1C293 /* MVMCoreTopAlertObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D2ED280B254B0EB800A1C293 /* MVMCoreTopAlertObject.m */; }; D2ED2815254B0EE400A1C293 /* MVMCoreGlobalTopAlertDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED2814254B0EE400A1C293 /* MVMCoreGlobalTopAlertDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D2ED2818254B115400A1C293 /* MVMCoreUIActionDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED2817254B112900A1C293 /* MVMCoreUIActionDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D2FA83D22513EA6900564112 /* NotificationXButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FA83D12513EA6900564112 /* NotificationXButton.swift */; }; D2FA83D42514F80C00564112 /* CollapsableNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FA83D32514F80C00564112 /* CollapsableNotification.swift */; }; D2FA83D62515021F00564112 /* CollapsableNotificationTopView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FA83D52515021F00564112 /* CollapsableNotificationTopView.swift */; }; @@ -885,7 +883,6 @@ AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStoreLocatorModel.swift; sourceTree = ""; }; AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStoreLocator.swift; sourceTree = ""; }; AF1C33642883B5A4006B1001 /* ActionTopNotificationHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionTopNotificationHandler.swift; sourceTree = ""; }; - AF1C33662883B712006B1001 /* ActionPopupHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionPopupHandler.swift; sourceTree = ""; }; AF1C336828859778006B1001 /* ActionAlertHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionAlertHandler.swift; sourceTree = ""; }; AF1C336A28859C73006B1001 /* ActionTopAlertHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionTopAlertHandler.swift; sourceTree = ""; }; AF1C336C28859EE1006B1001 /* ActionOpenPanelHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenPanelHandler.swift; sourceTree = ""; }; @@ -898,6 +895,7 @@ AF7E509729E477C0009DC2AD /* AlertController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertController.swift; sourceTree = ""; }; AFA4931F29E5CA73001A9663 /* AlertOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertOperation.swift; sourceTree = ""; }; AFA4932129E5EF2E001A9663 /* TopNotificationHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopNotificationHandler.swift; sourceTree = ""; }; + AFA4933E29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreUILoggingDelegateProtocol.swift; sourceTree = ""; }; AFE4A1D027DFB5EE00C458D0 /* VDSColorTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSColorTokens.xcframework; path = ../SharedFrameworks/VDSColorTokens.xcframework; sourceTree = ""; }; AFE4A1D527DFBB6F00C458D0 /* UINavigationController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Extension.swift"; sourceTree = ""; }; BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UICollectionViewLeftAlignedLayout.swift; sourceTree = ""; }; @@ -1168,7 +1166,6 @@ D2EC7BDC2527B83700F540AF /* SectionHeaderFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeaderFooterView.swift; sourceTree = ""; }; D2ED27E6254B0CE600A1C293 /* UIAlertActionStyle+Codable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertActionStyle+Codable.swift"; sourceTree = ""; }; D2ED27E7254B0CE600A1C293 /* UIAlertControllerStyle+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertControllerStyle+Extension.swift"; sourceTree = ""; }; - D2ED27E8254B0CE600A1C293 /* ActionPopupModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionPopupModel.swift; sourceTree = ""; }; D2ED27E9254B0CE600A1C293 /* ActionAlertModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionAlertModel.swift; sourceTree = ""; }; D2ED27EA254B0CE700A1C293 /* AlertModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertModel.swift; sourceTree = ""; }; D2ED27F2254B0E0200A1C293 /* MVMCoreAlertDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreAlertDelegateProtocol.h; sourceTree = ""; }; @@ -1182,7 +1179,6 @@ D2ED280A254B0EB700A1C293 /* MVMCoreTopAlertObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreTopAlertObject.h; sourceTree = ""; }; D2ED280B254B0EB800A1C293 /* MVMCoreTopAlertObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreTopAlertObject.m; sourceTree = ""; }; D2ED2814254B0EE400A1C293 /* MVMCoreGlobalTopAlertDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreGlobalTopAlertDelegateProtocol.h; sourceTree = ""; }; - D2ED2817254B112900A1C293 /* MVMCoreUIActionDelegateProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIActionDelegateProtocol.h; sourceTree = ""; }; D2FA83D12513EA6900564112 /* NotificationXButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationXButton.swift; sourceTree = ""; }; D2FA83D32514F80C00564112 /* CollapsableNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollapsableNotification.swift; sourceTree = ""; }; D2FA83D52515021F00564112 /* CollapsableNotificationTopView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollapsableNotificationTopView.swift; sourceTree = ""; }; @@ -1522,8 +1518,6 @@ D2ED27E9254B0CE600A1C293 /* ActionAlertModel.swift */, D2ED27EA254B0CE700A1C293 /* AlertModel.swift */, AF1C336828859778006B1001 /* ActionAlertHandler.swift */, - D2ED27E8254B0CE600A1C293 /* ActionPopupModel.swift */, - AF1C33662883B712006B1001 /* ActionPopupHandler.swift */, C6687440259D92D400F32D13 /* ActionTopNotificationModel.swift */, AF1C33642883B5A4006B1001 /* ActionTopNotificationHandler.swift */, AF1C33722885D481006B1001 /* MVMCoreUIActionOpenPageHandler.swift */, @@ -2329,11 +2323,11 @@ D29DF27821E7A533003B2FB9 /* MVMCoreUISession.m */, D29DF27321E79E81003B2FB9 /* MVMCoreUILoggingHandler.h */, D29DF27421E79E81003B2FB9 /* MVMCoreUILoggingHandler.m */, + AFA4933E29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift */, D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */, D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */, D2092352244F7D630044AD09 /* MVMCoreUIViewControllerMappingObject+Extension.swift */, D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */, - D2ED2817254B112900A1C293 /* MVMCoreUIActionDelegateProtocol.h */, AF1C33702885AE76006B1001 /* MVMCoreUIActionHandler.swift */, D23A90672614B0B4007E14CE /* CoreUIModelMapping.swift */, ); @@ -2588,7 +2582,6 @@ D2ED280F254B0EB800A1C293 /* MVMCoreTopAlertViewProtocol.h in Headers */, D2ED280C254B0EB800A1C293 /* MVMCoreTopAlertAnimationDelegateProtocol.h in Headers */, D2ED280D254B0EB800A1C293 /* MVMCoreTopAlertOperation.h in Headers */, - D2ED2818254B115400A1C293 /* MVMCoreUIActionDelegateProtocol.h in Headers */, D2ED27FB254B0E0300A1C293 /* MVMCoreAlertDelegateProtocol.h in Headers */, D2ED2810254B0EB800A1C293 /* MVMCoreTopAlertDelegateProtocol.h in Headers */, D2ED2815254B0EE400A1C293 /* MVMCoreGlobalTopAlertDelegateProtocol.h in Headers */, @@ -2784,7 +2777,6 @@ AAB9C10A243496DD00151545 /* RadioSwatch.swift in Sources */, D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */, 011D9602240DA20A000E3791 /* FormRuleWatcherFieldProtocol.swift in Sources */, - AF1C33672883B712006B1001 /* ActionPopupHandler.swift in Sources */, D23A900926125FFB007E14CE /* GetContactBehavior.swift in Sources */, D264FAA1243CF66B00D98315 /* ContainerCollectionReusableView.swift in Sources */, AA617AB22453012400910B8F /* ListDeviceComplexLinkSmallModel.swift in Sources */, @@ -2846,7 +2838,6 @@ D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */, D23A8FF82612308D007E14CE /* PageBehaviorProtocolRequirer.swift in Sources */, D29DF12B21E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.m in Sources */, - D2ED27ED254B0CE700A1C293 /* ActionPopupModel.swift in Sources */, 94C2D9A723872DA90006CF46 /* LabelAttributeColorModel.swift in Sources */, 943820842432382400B43AF3 /* WebView.swift in Sources */, 0103B84E23D7E33A009C315C /* HeadlineBodyToggleModel.swift in Sources */, @@ -2882,6 +2873,7 @@ D28A838323CCBD3F00DFE4FC /* WheelModel.swift in Sources */, D268C70C2386DFFD007F2C1C /* MoleculeStackItemModel.swift in Sources */, 0A9D091D2433796500D2E6C0 /* BarsCarouselIndicatorModel.swift in Sources */, + AFA4933F29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift in Sources */, DBEFFA04225A829700230692 /* Label.swift in Sources */, D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, AF1C33712885AE76006B1001 /* MVMCoreUIActionHandler.swift in Sources */, diff --git a/MVMCoreUI/Alerts/AlertHandler.swift b/MVMCoreUI/Alerts/AlertHandler.swift index 39b2d046..5a7b843a 100644 --- a/MVMCoreUI/Alerts/AlertHandler.swift +++ b/MVMCoreUI/Alerts/AlertHandler.swift @@ -40,7 +40,7 @@ public class AlertHandler { return !operation.isCancelled && !operation.isFinished && operation.isExecuting && - (operation as? AlertOperation)?.isGreedy ?? false + (operation as? AlertOperation)?.alertObject.isGreedy ?? false }) } @@ -71,14 +71,14 @@ public class AlertHandler { } let alertController = createAlertController(with: alertObject.alertModel) - let alertOperation = AlertOperation(with: alertController, isGreedy: alertObject.isGreedy, alertDelegate: alertObject.alertDelegate) + let alertOperation = AlertOperation(with: alertController, alertObject: alertObject) // If an existing greedy alert is showing, add it as a dependency. if let greedyAlertOperation = queue.operations.first(where: { operation in guard !operation.isFinished, !operation.isCancelled, let alertOperation = operation as? AlertOperation else { return false } - return alertOperation.isGreedy + return alertOperation.alertObject.isGreedy }) { alertOperation.addDependency((greedyAlertOperation as! AlertOperation)) } diff --git a/MVMCoreUI/Alerts/AlertOperation.swift b/MVMCoreUI/Alerts/AlertOperation.swift index ee280473..fdd1c190 100644 --- a/MVMCoreUI/Alerts/AlertOperation.swift +++ b/MVMCoreUI/Alerts/AlertOperation.swift @@ -30,14 +30,11 @@ public class AlertOperation: MVMCoreOperation { public let alertController: AlertController - public let isGreedy: Bool + public let alertObject: AlertObject - public weak var alertDelegate: MVMCoreAlertDelegateProtocol? - - public init(with alert: AlertController, isGreedy: Bool = false, alertDelegate: MVMCoreAlertDelegateProtocol? = nil) { + public init(with alert: AlertController, alertObject: AlertObject) { self.alertController = alert - self.isGreedy = isGreedy - self.alertDelegate = alertDelegate + self.alertObject = alertObject } deinit { @@ -57,8 +54,11 @@ public class AlertOperation: MVMCoreOperation { // We finished but it was not displayed yet. It's possible that it was cancelled. Finish this task if await !self.properties.getIsDisplayed() { self.markAsFinished() - } else if self.isCancelled { - await self.dismissAlertView() + } else { + (CoreUIObject.sharedInstance()?.loggingDelegate as? MVMCoreUILoggingDelegateProtocol)?.logAlert(with: self.alertObject) + if self.isCancelled { + await self.dismissAlertView() + } } } } @@ -67,7 +67,7 @@ public class AlertOperation: MVMCoreOperation { public override func cancel() { super.cancel() Task { @MainActor in - self.alertDelegate?.alertCancelled?(self.alertController) + self.alertObject.alertDelegate?.alertCancelled?(self.alertController) await self.dismissAlertView() } } @@ -92,9 +92,9 @@ public class AlertOperation: MVMCoreOperation { Task { @MainActor in await self.properties.set(displayed: visible) if visible { - self.alertDelegate?.alertShown?(self.alertController) + self.alertObject.alertDelegate?.alertShown?(self.alertController) } else { - self.alertDelegate?.alertDismissed?(self.alertController) + self.alertObject.alertDelegate?.alertDismissed?(self.alertController) // Is visible was set to NO, meaning that the alertview is no longer visible. self.stopObservingAlertView() diff --git a/MVMCoreUI/Alerts/MVMCoreAlertDelegateProtocol.h b/MVMCoreUI/Alerts/MVMCoreAlertDelegateProtocol.h index 1b8d65c1..4b66fcdb 100644 --- a/MVMCoreUI/Alerts/MVMCoreAlertDelegateProtocol.h +++ b/MVMCoreUI/Alerts/MVMCoreAlertDelegateProtocol.h @@ -8,7 +8,6 @@ // Called for popup style alerts. #import -@class MVMCoreAlertObject; @class MVMCoreLoadObject; @class MVMCoreErrorObject; @@ -16,9 +15,6 @@ @optional -// helps tracking alert state -- (nullable NSDictionary *)additionalAlertDataToTrackForAlertWithObject:(nullable MVMCoreAlertObject *)alertObject; - // All are performed on the main thread. - (void)alertShown:(nonnull UIAlertController *)alertController; - (void)alertCancelled:(nonnull UIAlertController *)alertController; @@ -26,11 +22,10 @@ - (void)alertPaused:(nonnull UIAlertController *)alertController; - (void)alertUnpaused:(nonnull UIAlertController *)alertController; -/** Get the alert object whose data will be presented. Overwrite this to alter how you want the alert to show. +/** Overwrite this to alter how you want the alert to show. * @param loadObject The load object. * @param errorObject An error object if there was an error. - * @return Returns the alert object. - * Details: Gets the alert that will display to the screen. Easier to subclass here to avoid subclassing the displaying logic. */ -- (nullable MVMCoreAlertObject *)alertObjectToShow:(nonnull MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)errorObject; + * Details: Easier to subclass here to avoid subclassing the displaying logic. */ +- (void)handleAlertFor:(nonnull MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)errorObject; @end diff --git a/MVMCoreUI/Alerts/MVMCoreAlertObject+Swift.swift b/MVMCoreUI/Alerts/MVMCoreAlertObject+Swift.swift index 60444ef5..69305385 100644 --- a/MVMCoreUI/Alerts/MVMCoreAlertObject+Swift.swift +++ b/MVMCoreUI/Alerts/MVMCoreAlertObject+Swift.swift @@ -15,7 +15,7 @@ public struct AlertObject { public var isGreedy = false /// The alert model for the alert to show. - public let alertModel: AlertModel + public var alertModel: AlertModel public weak var alertDelegate: MVMCoreAlertDelegateProtocol? diff --git a/MVMCoreUI/Alerts/TopNotificationHandler.swift b/MVMCoreUI/Alerts/TopNotificationHandler.swift index 82fe4889..ce6a34a0 100644 --- a/MVMCoreUI/Alerts/TopNotificationHandler.swift +++ b/MVMCoreUI/Alerts/TopNotificationHandler.swift @@ -156,16 +156,6 @@ public class TopNotificationHandler { let alertOperation = MVMCoreTopAlertOperation(topAlertObject: topAlertObject)! add(operation: alertOperation) } - - public func showTopAlertError(with message: String) { - let topAlertObject = MVMCoreTopAlertObject(type: ValueTypeError, message: message)! - showTopAlert(with: topAlertObject) - } - - public func showTopAlertConfirmation(with message: String) { - let topAlertObject = MVMCoreTopAlertObject(type: ValueTypeSuccess, message: message)! - showTopAlert(with: topAlertObject) - } /// Cancel the current top alert view. public func hideTopAlertView() { diff --git a/MVMCoreUI/Atomic/Actions/ActionPopupHandler.swift b/MVMCoreUI/Atomic/Actions/ActionPopupHandler.swift deleted file mode 100644 index 6749838d..00000000 --- a/MVMCoreUI/Atomic/Actions/ActionPopupHandler.swift +++ /dev/null @@ -1,121 +0,0 @@ -// -// ActionPopupHandler.swift -// MVMCoreUI -// -// Created by Scott Pfeil on 7/16/22. -// Copyright © 2022 Verizon Wireless. All rights reserved. -// - -import Foundation -import MVMCore - -/// Shows a popup alert by grabbing the content from a Page in the cache using the pageType. -open class ActionPopupHandler: MVMCoreActionHandlerProtocol { - required public init() {} - - public enum Error: MVMError, CustomStringConvertible { - case jsonNotFound - - public var description: String { - switch self { - case ActionPopupHandler.Error.jsonNotFound: - return "JSON for popup not found." - } - } - - public var errorCode: Int { - ErrorCode.popupFailed.rawValue - } - } - - open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { - guard let model = model as? ActionPopupModel else { return } - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in - MVMCoreCache.shared()?.fetchJSON(forPageType: model.pageType, queue: nil, waitUntilFinished: true, completionHandler: { json in - guard let page = json else { - continuation.resume(throwing: ActionPopupHandler.Error.jsonNotFound) - return - } - Task(priority: .userInitiated) { - do { - try await self.showAlertObjectWithPage(page, isGreedy: false, additionalData: nil, delegateObject: delegateObject) - continuation.resume() - } catch { - continuation.resume(throwing: error) - } - } - }) - } - } - - // TODO: Find a way to wait for the actual alert to show? or finish? - /// Shows the alert using the legacy page format. - open func showAlertObjectWithPage(_ page: [AnyHashable: Any], isGreedy: Bool, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) async throws { - let alertObject = try alertObjectWithPage(page, isGreedy: false, additionalData: additionalData, delegateObject: delegateObject) - _ = await AlertHandler.shared().queueAlertToShow(with: alertObject) - } - - open func alertObjectWithPage(_ page: [AnyHashable: Any], isGreedy: Bool, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) throws -> AlertObject { - let data = try JSONSerialization.data(withJSONObject: page) - let decoder = JSONDecoder.create(with: delegateObject) - let popupModel = try decoder.decode(LegacyAlertModel.self, from: data) - let alert = AlertModel(title: popupModel.title ?? "", message: popupModel.message ?? "", actions: popupModel.buttonActions) - return AlertObject(alertModel: alert, isGreedy: isGreedy) - } -} - -private protocol ActionWithTitle: ActionModelProtocol { - var title: String { get set } -} - -private struct LegacyAlertModel: Codable { - var title: String? - var message: String? - var buttonActions: [UIAlertAction] - private var buttonsForEncode: JSONValueArray - - //-------------------------------------------------- - // MARK: - Keys - //-------------------------------------------------- - - private enum CodingKeys: String, CodingKey { - case title - case message - case Links - } - - //-------------------------------------------------- - // MARK: - Codec - //-------------------------------------------------- - - struct TitleObject: Codable { - var title: String - } - - public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - buttonsForEncode = try typeContainer.decode(JSONValueArray.self, forKey: .Links) - title = try typeContainer.decode(String.self, forKey: .title) - message = try typeContainer.decode(String.self, forKey: .message) - if title?.count == 0 && message?.count == 0 { - throw ModelRegistry.Error.decoderOther(message: "Popups must have either a title or a message") - } - - let buttonTitles = try typeContainer.decode([TitleObject].self, forKey: .Links).map({ object in - return object.title - }) - let delegateObject = try decoder.get() - self.buttonActions = (try typeContainer.decodeModels(codingKey: .Links) as [ActionModelProtocol]).enumerated().map { (index, action) in - return AlertButtonModel(buttonTitles[index], action) - }.map({ alertButtonModel in - return alertButtonModel.generateAction(delegateObject: delegateObject) - }) - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(title, forKey: .title) - try container.encodeIfPresent(message, forKey: .message) - try container.encode(buttonsForEncode, forKey: .Links) - } -} diff --git a/MVMCoreUI/Atomic/Actions/ActionPopupModel.swift b/MVMCoreUI/Atomic/Actions/ActionPopupModel.swift deleted file mode 100644 index cbade308..00000000 --- a/MVMCoreUI/Atomic/Actions/ActionPopupModel.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// ActionPopupModel.swift -// MVMCore -// -// Created by Suresh, Kamlesh on 12/16/19. -// Copyright © 2019 myverizon. All rights reserved. -// - -import MVMCore - -public struct ActionPopupModel: ActionModelProtocol { - //-------------------------------------------------- - // MARK: - Properties - //-------------------------------------------------- - - public static var identifier: String = "popup" - public var actionType: String = ActionPopupModel.identifier - public var pageType: String - public var extraParameters: JSONValueDictionary? - public var analyticsData: JSONValueDictionary? - - //-------------------------------------------------- - // MARK: - Initializer - //-------------------------------------------------- - - public init(pageType: String, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { - self.pageType = pageType - self.extraParameters = extraParameters - self.analyticsData = analyticsData - } -} diff --git a/MVMCoreUI/Atomic/Actions/AlertModel.swift b/MVMCoreUI/Atomic/Actions/AlertModel.swift index 4ee37ab9..e4b82018 100644 --- a/MVMCoreUI/Atomic/Actions/AlertModel.swift +++ b/MVMCoreUI/Atomic/Actions/AlertModel.swift @@ -69,7 +69,7 @@ public struct AlertModel: Codable { public var message: String public var style: UIAlertController.Style = .alert public var actions: [UIAlertAction] - private var alertActions: [AlertButtonModel]? + public var alertActions: [AlertButtonModel]? public var analyticsData: JSONValueDictionary? //-------------------------------------------------- diff --git a/MVMCoreUI/MVMCoreUI.h b/MVMCoreUI/MVMCoreUI.h index f5a0c6fc..753c0a75 100644 --- a/MVMCoreUI/MVMCoreUI.h +++ b/MVMCoreUI/MVMCoreUI.h @@ -20,7 +20,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[]; #import #import #import -#import // Alert Handling #import diff --git a/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift b/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift index c27553ec..680fc2e4 100644 --- a/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift +++ b/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift @@ -229,7 +229,6 @@ open class CoreUIModelMapping: ModelMapping { open override class func registerActions() { super.registerActions() - ModelRegistry.register(handler: ActionPopupHandler.self, for: ActionPopupModel.self) ModelRegistry.register(handler: ActionAlertHandler.self, for: ActionAlertModel.self) ModelRegistry.register(handler: ActionTopAlertHandler.self, for: ActionTopAlertModel.self) ModelRegistry.register(handler: ActionCollapseNotificationHandler.self, for: ActionCollapseNotificationModel.self) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIActionDelegateProtocol.h b/MVMCoreUI/OtherHandlers/MVMCoreUIActionDelegateProtocol.h deleted file mode 100644 index c2f2a4b9..00000000 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIActionDelegateProtocol.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// MVMCoreUIActionDelegateProtocol.h -// MVMCoreUI -// -// Created by Scott Pfeil on 10/28/20. -// Copyright © 2020 Verizon Wireless. All rights reserved. -// -@import MVMCore.MVMCoreActionDelegateProtocol; -@class MVMCoreAlertObject; - -@protocol MVMCoreUIActionDelegateProtocol - -// Gives the delegate a chance to alter the alert object -- (void)willShowPopupWithAlertObject:(nonnull MVMCoreAlertObject *)alertObject alertJson:(nonnull NSDictionary *)alertJson; - -@end diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUILoggingDelegateProtocol.swift b/MVMCoreUI/OtherHandlers/MVMCoreUILoggingDelegateProtocol.swift new file mode 100644 index 00000000..3f135805 --- /dev/null +++ b/MVMCoreUI/OtherHandlers/MVMCoreUILoggingDelegateProtocol.swift @@ -0,0 +1,13 @@ +// +// MVMCoreUILoggingDelegateProtocol.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 4/13/23. +// Copyright © 2023 Verizon Wireless. All rights reserved. +// + +import MVMCore + +public protocol MVMCoreUILoggingDelegateProtocol: MVMCoreLoggingDelegateProtocol { + func logAlert(with alertObject: AlertObject) +}