From 9415dfbda85a14e0ca90638c34f4f0b166faa21a Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 15 Sep 2020 11:31:10 -0400 Subject: [PATCH] Comments, organizing, init fix --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 ++ .../MVMCoreAlertHandler+Extension.swift | 69 +++++++++++++++++++ .../AlertHandling/MVMCoreAlertHandler.h | 2 +- .../MVMCoreAlertObject+Swift.swift | 60 ---------------- .../AlertHandling/MVMCoreTopAlertObject.h | 2 +- 5 files changed, 75 insertions(+), 62 deletions(-) create mode 100644 MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler+Extension.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index d22f12c..50d6c52 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -157,6 +157,7 @@ AFFCFA681FCCC0D700FD0730 /* MVMCoreLoadingViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */; }; D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB72240342D00C46919 /* NSNumber+Extension.swift */; }; + D2CAC7C82510F0C500C75681 /* MVMCoreAlertHandler+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2CAC7C72510F0C500C75681 /* MVMCoreAlertHandler+Extension.swift */; }; D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */; }; D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */; }; D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCBA23C65BC300C44CC4 /* Percent.swift */; }; @@ -308,6 +309,7 @@ AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingViewControllerProtocol.h; sourceTree = ""; }; D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreGetterUtility+Extension.swift"; sourceTree = ""; }; D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = ""; }; + D2CAC7C72510F0C500C75681 /* MVMCoreAlertHandler+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreAlertHandler+Extension.swift"; sourceTree = ""; }; D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = ""; }; D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitInterval.swift; sourceTree = ""; }; D2DEDCBA23C65BC300C44CC4 /* Percent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Percent.swift; sourceTree = ""; }; @@ -594,6 +596,7 @@ AFBB967F1FBA3A9A0008D868 /* MVMCoreAlertHandler.m */, AFBB96801FBA3A9A0008D868 /* MVMCoreAlertObject.h */, AFBB96811FBA3A9A0008D868 /* MVMCoreAlertObject.m */, + D2CAC7C72510F0C500C75681 /* MVMCoreAlertHandler+Extension.swift */, 0184D3E224B8D0C600A05369 /* MVMCoreAlertObject+Swift.swift */, AFBB96821FBA3A9A0008D868 /* MVMCoreAlertOperation.h */, AFBB96831FBA3A9A0008D868 /* MVMCoreAlertOperation.m */, @@ -902,6 +905,7 @@ AF43A5781FBA5B7C008E9347 /* MVMCoreJSONConstants.m in Sources */, AFBB96691FBA3A570008D868 /* MVMCoreRequestParameters.m in Sources */, AFED77A31FCCA29400BAE689 /* MVMCoreViewControllerNibMappingObject.m in Sources */, + D2CAC7C82510F0C500C75681 /* MVMCoreAlertHandler+Extension.swift in Sources */, 8876D5EB1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.m in Sources */, 0184D3DB24B7D5A600A05369 /* ActionAlertModel.swift in Sources */, AFBB96A41FBA3A9A0008D868 /* MVMCoreTopAlertObject.m in Sources */, diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler+Extension.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler+Extension.swift new file mode 100644 index 0000000..ffc5e76 --- /dev/null +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler+Extension.swift @@ -0,0 +1,69 @@ +// +// MVMCoreAlertHandler+Extension.swift +// MVMCore +// +// Created by Scott Pfeil on 9/15/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + +// Temporary, until we can move page checking logic into isReady of topAlertOperation. +@objcMembers public class NotificationPagesOperation: Operation { + public let pages: [String] + + public init(with pages: [String]) { + self.pages = pages + } + + public override var isReady: Bool { + get { + return super.isReady && isCancelled + } + } +} + +// TODO: Move this type of logic into isReady for the top alert operation... then can remove this dependency operation. +public extension MVMCoreAlertHandler { + + /// Adds a page type dependency to the operation + @objc func addPagesDependency(to operation: MVMCoreTopAlertOperation) { + // This notification may only show for certain pages. + guard let pages = operation.topAlertObject.json?.optionalArrayForKey("pages") as? [String], + pages.count > 0 else { return } + let pagesOperation = NotificationPagesOperation(with: pages) + pageOperations.addOperation(pagesOperation) + operation.addDependency(pagesOperation) + print("TYTYT added dependency \(operation)") + } + + /// checks top alerts for page dependencies with the new pageType + @objc func checkPagesDependency(for pageType: String?) { + // If the current running operation should not show on the current page, cancel it. If it's persistent, re-add it. If another operation has had the dependency remove previously, add it back. + for case let operation as MVMCoreTopAlertOperation in topAlertQueue.operations { + if !operation.isCancelled, + let pages = operation.topAlertObject.json?.optionalArrayForKey("pages") as? [String], + (pageType == nil || !pages.contains(pageType!)) { + if operation.isExecuting { + operation.reAddAfterCancel = operation.topAlertObject.persistent + operation.cancel() + print("TYTYT cancelled current \(operation)") + } else if !operation.dependencies.contains(where: { !$0.isFinished }) { + let pagesOperation = NotificationPagesOperation(with: pages) + pageOperations.addOperation(pagesOperation) + operation.addDependency(pagesOperation) + print("TYTYT re-added previouly removed \(operation)") + } + } + } + + // Remove the dependency if it contains the current page. + guard let pageType = pageType else { return } + for case let operation as NotificationPagesOperation in pageOperations.operations { + if operation.pages.contains(pageType) { + operation.cancel() + print("TYTYT cancel dependency \(operation)") + } + } + } +} diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h index 2142d63..e41cff4 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h @@ -12,7 +12,6 @@ #import #import -@class NotificationPagesOperation; @class MVMCoreAlertObject; @interface MVMCoreAlertHandler : NSObject @@ -23,6 +22,7 @@ // An operation queue for top alerts @property (nonnull, strong, nonatomic) NSOperationQueue *topAlertQueue; +/// Stores any page dependencies for top alerts @property (nonnull, strong, nonatomic) NSOperationQueue *pageOperations; /// Returns the shared instance of this singleton diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index b58de05..162dd2d 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -43,63 +43,3 @@ public extension MVMCoreAlertObject { return alertObject } } - -// Temporary location -@objcMembers public class NotificationPagesOperation: Operation { - public let pages: [String] - - public init(with pages: [String]) { - self.pages = pages - } - - public override var isReady: Bool { - get { - return super.isReady && isCancelled - } - } -} - -public extension MVMCoreAlertHandler { - @objc func addPagesDependency(to operation: MVMCoreTopAlertOperation) { - // This notification may only show for certain pages. - guard let pages = operation.topAlertObject.json?.optionalArrayForKey("pages") as? [String], - pages.count > 0 else { return } - let pagesOperation = NotificationPagesOperation(with: pages) - pageOperations.addOperation(pagesOperation) - operation.addDependency(pagesOperation) - - print("TYTYT added dependency \(operation)") - } - - @objc func checkPagesDependency(for pageType: String?) { - // TODO: check top alerts that didn't show that had the same page requirement. - - // If the current running operation is persistent and should not show on the current page, cancel it and re-add it. - for case let operation as MVMCoreTopAlertOperation in topAlertQueue.operations { - if !operation.isCancelled, - let pages = operation.topAlertObject.json?.optionalArrayForKey("pages") as? [String], - (pageType == nil || !pages.contains(pageType!)) { - if operation.isExecuting { - operation.reAddAfterCancel = operation.topAlertObject.persistent - operation.cancel() - print("TYTYT cancelled current \(operation)") - } else if !operation.dependencies.contains(where: { !$0.isFinished }) { - let pagesOperation = NotificationPagesOperation(with: pages) - pageOperations.addOperation(pagesOperation) - operation.addDependency(pagesOperation) - print("TYTYT re-added previouly removed \(operation)") - } - } - } - - // Remove the dependency if it contains the page. - // Change to isReady, find a way to get the page type... - guard let pageType = pageType else { return } - for case let operation as NotificationPagesOperation in pageOperations.operations { - if operation.pages.contains(pageType) { - operation.cancel() - print("TYTYT cancel dependency \(operation)") - } - } - } -} diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h index 97897cc..350f6e1 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h @@ -50,7 +50,7 @@ extern NSUInteger const TopAlertDismissTime; @property (nullable, strong, nonatomic) UIColor *backgroundColor; @property (nullable, strong, nonatomic) UIColor *textColor; -// For a json driven approach. +// The full top alert json. Currently only used for molecular. @property (nullable, strong, nonatomic) NSDictionary *json; - (nullable instancetype)initWithResponseInfo:(nullable NSDictionary *)responseInfo;