From 657e69b798e254329aced944611fecfe6decdc29 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Tue, 18 Apr 2023 09:07:11 -0400 Subject: [PATCH] more swift files --- MVMCoreUI.xcodeproj/project.pbxproj | 10 ++- MVMCoreUI/Alerts/AlertDelegateProtocol.swift | 19 +++++ MVMCoreUI/Alerts/AlertObject.swift | 4 +- MVMCoreUI/Alerts/AlertOperation.swift | 6 +- .../Alerts/MVMCoreAlertDelegateProtocol.h | 31 --------- .../MVMCoreAlertHandler+Extension.swift | 69 ------------------- MVMCoreUI/MVMCoreUI.h | 3 - .../MVMCoreUIDelegateObject.swift | 6 +- 8 files changed, 31 insertions(+), 117 deletions(-) create mode 100644 MVMCoreUI/Alerts/AlertDelegateProtocol.swift delete mode 100644 MVMCoreUI/Alerts/MVMCoreAlertDelegateProtocol.h delete mode 100644 MVMCoreUI/Alerts/MVMCoreAlertHandler+Extension.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 85b5fea1..665c4cb7 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -291,6 +291,7 @@ 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 */; }; + AFA4935729EE3DCC001A9663 /* AlertDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA4935629EE3DCC001A9663 /* AlertDelegateProtocol.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 */; }; @@ -562,7 +563,6 @@ D2ED27EC254B0CE700A1C293 /* UIAlertControllerStyle+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27E7254B0CE600A1C293 /* UIAlertControllerStyle+Extension.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, ); }; }; D2ED27FC254B0E0300A1C293 /* AlertObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27F3254B0E0200A1C293 /* AlertObject.swift */; }; D2ED280C254B0EB800A1C293 /* MVMCoreTopAlertAnimationDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED2805254B0EB700A1C293 /* MVMCoreTopAlertAnimationDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D2ED280D254B0EB800A1C293 /* MVMCoreTopAlertOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED2806254B0EB700A1C293 /* MVMCoreTopAlertOperation.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -896,6 +896,7 @@ 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 = ""; }; + AFA4935629EE3DCC001A9663 /* AlertDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertDelegateProtocol.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,9 +1169,7 @@ D2ED27E7254B0CE600A1C293 /* UIAlertControllerStyle+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertControllerStyle+Extension.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 = ""; }; D2ED27F3254B0E0200A1C293 /* AlertObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertObject.swift; sourceTree = ""; }; - D2ED27F7254B0E0200A1C293 /* MVMCoreAlertHandler+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "MVMCoreAlertHandler+Extension.swift"; sourceTree = ""; }; D2ED2805254B0EB700A1C293 /* MVMCoreTopAlertAnimationDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreTopAlertAnimationDelegateProtocol.h; sourceTree = ""; }; D2ED2806254B0EB700A1C293 /* MVMCoreTopAlertOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreTopAlertOperation.h; sourceTree = ""; }; D2ED2807254B0EB700A1C293 /* MVMCoreTopAlertOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreTopAlertOperation.m; sourceTree = ""; }; @@ -2521,8 +2520,7 @@ D2ED27D8254B0C1F00A1C293 /* Alerts */ = { isa = PBXGroup; children = ( - D2ED27F2254B0E0200A1C293 /* MVMCoreAlertDelegateProtocol.h */, - D2ED27F7254B0E0200A1C293 /* MVMCoreAlertHandler+Extension.swift */, + AFA4935629EE3DCC001A9663 /* AlertDelegateProtocol.swift */, D2ED27F3254B0E0200A1C293 /* AlertObject.swift */, AF7E509729E477C0009DC2AD /* AlertController.swift */, AF7E509629E477C0009DC2AD /* AlertHandler.swift */, @@ -2582,7 +2580,6 @@ D2ED280F254B0EB800A1C293 /* MVMCoreTopAlertViewProtocol.h in Headers */, D2ED280C254B0EB800A1C293 /* MVMCoreTopAlertAnimationDelegateProtocol.h in Headers */, D2ED280D254B0EB800A1C293 /* MVMCoreTopAlertOperation.h in Headers */, - D2ED27FB254B0E0300A1C293 /* MVMCoreAlertDelegateProtocol.h in Headers */, D2ED2810254B0EB800A1C293 /* MVMCoreTopAlertDelegateProtocol.h in Headers */, D2ED2815254B0EE400A1C293 /* MVMCoreGlobalTopAlertDelegateProtocol.h in Headers */, D29DF26F21E6AA0B003B2FB9 /* FLAnimatedImageView.h in Headers */, @@ -2987,6 +2984,7 @@ D23118B325124E18001C8440 /* Notification.swift in Sources */, AA9972502475309F00FC7472 /* ListLeftVariableIconAllTextLinksModel.swift in Sources */, AA69AAF62445BF5700AF3D3B /* ListLeftVariableCheckboxBodyText.swift in Sources */, + AFA4935729EE3DCC001A9663 /* AlertDelegateProtocol.swift in Sources */, D264FAA3243E632F00D98315 /* ProgrammaticCollectionViewController.swift in Sources */, D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */, 27F9736A246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift in Sources */, diff --git a/MVMCoreUI/Alerts/AlertDelegateProtocol.swift b/MVMCoreUI/Alerts/AlertDelegateProtocol.swift new file mode 100644 index 00000000..4b032f78 --- /dev/null +++ b/MVMCoreUI/Alerts/AlertDelegateProtocol.swift @@ -0,0 +1,19 @@ +// +// AlertDelegateProtocol.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 4/17/23. +// Copyright © 2023 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objc +public protocol AlertDelegateProtocol { + // All are performed on the main thread. + @MainActor func alertShown(_ alertController: UIAlertController) + @MainActor func alertCancelled(_ alertController: UIAlertController) + @MainActor func alertDismissed(_ alertController: UIAlertController) + @MainActor func alertPaused(_ alertController: UIAlertController) + @MainActor func alertUnpaused(_ alertController: UIAlertController) +} diff --git a/MVMCoreUI/Alerts/AlertObject.swift b/MVMCoreUI/Alerts/AlertObject.swift index 398fc7c3..fd20a2fa 100644 --- a/MVMCoreUI/Alerts/AlertObject.swift +++ b/MVMCoreUI/Alerts/AlertObject.swift @@ -17,9 +17,9 @@ public struct AlertObject { /// The alert model for the alert to show. public var alertModel: AlertModel - public weak var alertDelegate: MVMCoreAlertDelegateProtocol? + public weak var alertDelegate: AlertDelegateProtocol? - public init(alertModel: AlertModel, isGreedy: Bool = false, alertDelegate: MVMCoreAlertDelegateProtocol? = nil) { + public init(alertModel: AlertModel, isGreedy: Bool = false, alertDelegate: AlertDelegateProtocol? = nil) { self.alertModel = alertModel self.isGreedy = isGreedy self.alertDelegate = alertDelegate diff --git a/MVMCoreUI/Alerts/AlertOperation.swift b/MVMCoreUI/Alerts/AlertOperation.swift index fdd1c190..be5dadf1 100644 --- a/MVMCoreUI/Alerts/AlertOperation.swift +++ b/MVMCoreUI/Alerts/AlertOperation.swift @@ -67,7 +67,7 @@ public class AlertOperation: MVMCoreOperation { public override func cancel() { super.cancel() Task { @MainActor in - self.alertObject.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.alertObject.alertDelegate?.alertShown?(self.alertController) + self.alertObject.alertDelegate?.alertShown(self.alertController) } else { - self.alertObject.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 deleted file mode 100644 index 4b66fcdb..00000000 --- a/MVMCoreUI/Alerts/MVMCoreAlertDelegateProtocol.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// MVMCoreAlertDelegateProtocol.h -// mobilefirst -// -// Created by Pfeil, Scott Robert on 8/8/17. -// Copyright © 2017 Verizon Wireless. All rights reserved. -// -// Called for popup style alerts. - -#import -@class MVMCoreLoadObject; -@class MVMCoreErrorObject; - -@protocol MVMCoreAlertDelegateProtocol - -@optional - -// All are performed on the main thread. -- (void)alertShown:(nonnull UIAlertController *)alertController; -- (void)alertCancelled:(nonnull UIAlertController *)alertController; -- (void)alertDismissed:(nonnull UIAlertController *)alertController; -- (void)alertPaused:(nonnull UIAlertController *)alertController; -- (void)alertUnpaused:(nonnull UIAlertController *)alertController; - -/** 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. - * 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/MVMCoreAlertHandler+Extension.swift b/MVMCoreUI/Alerts/MVMCoreAlertHandler+Extension.swift deleted file mode 100644 index 6f52ce93..00000000 --- a/MVMCoreUI/Alerts/MVMCoreAlertHandler+Extension.swift +++ /dev/null @@ -1,69 +0,0 @@ -// -// MVMCoreAlertHandler+Extension.swift -// MVMCore -// -// Created by Scott Pfeil on 9/15/20. -// Copyright © 2020 myverizon. All rights reserved. -// - -import Foundation - -public extension MVMCoreAlertHandler { - - /// Re-evaluates the queue operations - @objc func reevaluteQueue() { - var highestReadyOperation: MVMCoreTopAlertOperation? - var executingOperation: MVMCoreTopAlertOperation? - for case let operation as MVMCoreTopAlertOperation in topAlertQueue.operations { - guard !operation.isCancelled, - !operation.isFinished else { continue } - if operation.isReady, - highestReadyOperation == nil || operation.queuePriority.rawValue > highestReadyOperation!.queuePriority.rawValue { - highestReadyOperation = operation - } - if operation.isExecuting { - executingOperation = operation - } - } - guard let currentOperation = executingOperation else { return } - - // Cancel the executing operation if it is no longer ready to run. Re-add for later if it is persistent. - guard currentOperation.isReady else { - currentOperation.reAddAfterCancel = currentOperation.topAlertObject.persistent - currentOperation.cancel() - return - } - - // If the highest priority operation is not executing, and the executing operation is persistent, cancel it. - if let newOperation = highestReadyOperation, - currentOperation != newOperation, - currentOperation.topAlertObject.persistent { - currentOperation.reAddAfterCancel = true - currentOperation.cancel() - } - } - - /// Registers to know when pages change. - @objc func registerForPageChanges() { - MVMCoreNavigationHandler.shared()?.addDelegate(self) - } -} - -extension MVMCoreAlertHandler: MVMCorePresentationDelegateProtocol { - // Update displayable for each top alert operation when page type changes, in top queue priority order. - public func navigationController(_ navigationController: UINavigationController, displayedViewController viewController: UIViewController) { - guard topAlertQueue.operations.count > 0 else { return } - let viewController = MVMCoreUIUtility.getViewControllerTraversingManagers(viewController) - guard viewController == MVMCoreUISplitViewController.main()?.getCurrentViewController() else { return } - let pageType = (viewController as? MVMCoreViewControllerProtocol)?.pageType - topAlertQueue.operations.compactMap { - $0 as? MVMCoreTopAlertOperation - }.sorted { - $0.queuePriority.rawValue > $1.queuePriority.rawValue - }.forEach { - $0.updateDisplayable(byPageType: pageType) - } - reevaluteQueue() - } -} - diff --git a/MVMCoreUI/MVMCoreUI.h b/MVMCoreUI/MVMCoreUI.h index 753c0a75..ceb4b574 100644 --- a/MVMCoreUI/MVMCoreUI.h +++ b/MVMCoreUI/MVMCoreUI.h @@ -21,9 +21,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[]; #import #import -// Alert Handling -#import - #pragma mark - TopAlert #import #import diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift index b4ea0cd7..0a79ae9e 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift @@ -7,7 +7,7 @@ // import UIKit - +import MVMCore open class MVMCoreUIDelegateObject: DelegateObject { @@ -17,7 +17,7 @@ open class MVMCoreUIDelegateObject: DelegateObject { public weak var uiTextViewDelegate: UITextViewDelegate? public weak var observingTextFieldDelegate: ObservingTextFieldDelegate? public weak var moleculeDelegate: MoleculeDelegateProtocol? - public weak var alertDelegate: (MVMCoreAlertDelegateProtocol & NSObjectProtocol)? + public weak var alertDelegate: (AlertDelegateProtocol & NSObjectProtocol)? public weak var topAlertDelegate: (MVMCoreTopAlertDelegateProtocol & NSObjectProtocol)? open override func setAll(withDelegate delegate: Any) { @@ -28,7 +28,7 @@ open class MVMCoreUIDelegateObject: DelegateObject { uiTextViewDelegate = delegate as? UITextViewDelegate observingTextFieldDelegate = delegate as? ObservingTextFieldDelegate moleculeDelegate = delegate as? MoleculeDelegateProtocol - alertDelegate = delegate as? (MVMCoreAlertDelegateProtocol & NSObjectProtocol) + alertDelegate = delegate as? (AlertDelegateProtocol & NSObjectProtocol) topAlertDelegate = delegate as? (MVMCoreTopAlertDelegateProtocol & NSObjectProtocol) }