From 4def5e724aac712bf56bdb98e4a7901fc001b706 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Mon, 14 Sep 2020 17:31:44 +0530 Subject: [PATCH 1/6] added noop Action type --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 +++ .../ActionHandling/MVMCoreActionHandler.m | 2 ++ .../MVMCore/Constants/MVMCoreJSONConstants.m | 1 + .../Models/ActionType/ActionNoopModel.swift | 27 +++++++++++++++++++ MVMCore/MVMCore/Models/ModelMapping.swift | 1 + 5 files changed, 35 insertions(+) create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionNoopModel.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index d22f12c..28dcf0f 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -155,6 +155,7 @@ AFFCFA661FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA621FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = AFFCFA631FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.m */; }; AFFCFA681FCCC0D700FD0730 /* MVMCoreLoadingViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; + BB780ADF250F8C890030BD2F /* ActionNoopModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB780ADE250F8C890030BD2F /* ActionNoopModel.swift */; }; 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 */; }; D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */; }; @@ -306,6 +307,7 @@ AFFCFA621FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingOverlayHandler.h; sourceTree = ""; }; AFFCFA631FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreLoadingOverlayHandler.m; sourceTree = ""; }; AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingViewControllerProtocol.h; sourceTree = ""; }; + BB780ADE250F8C890030BD2F /* ActionNoopModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionNoopModel.swift; 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 = ""; }; D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = ""; }; @@ -467,6 +469,7 @@ 94C014D2242119E6005811A9 /* ActionPreviousSubmitModel.swift */, 94C014D424211AF0005811A9 /* ActionCancelModel.swift */, 94C014D824212360005811A9 /* ActionSettingModel.swift */, + BB780ADE250F8C890030BD2F /* ActionNoopModel.swift */, 0184D3FE24BE554A00A05369 /* AlertModel.swift */, ); path = ActionType; @@ -867,6 +870,7 @@ AFBB96641FBA3A570008D868 /* MVMCoreLoadHandler.m in Sources */, AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */, AFBB968E1FBA3A9A0008D868 /* MVMCoreNavigationHandler.m in Sources */, + BB780ADF250F8C890030BD2F /* ActionNoopModel.swift in Sources */, D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */, 01F2A03623A80A7300D954D8 /* ActionModelProtocol.swift in Sources */, AFBB96991FBA3A9A0008D868 /* MVMCoreAlertController.m in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 44f5851..8b2beac 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -94,6 +94,8 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeAlert]) { [self showAlert:actionInformation additionalData:additionalData delegateObject:delegateObject]; + } else if ([actionType isEqualToString:KeyActionTypeNoop]){ + // Need to tag analytics data } else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]) { // not a known action type. [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index c283fd6..80122db 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -42,6 +42,7 @@ NSString * const KeyActionTypeTopAlert = @"topAlert"; NSString * const KeyActionTypeSettings = @"openSettings"; NSString * const KeyActionTypeCollapseNotification = @"collapseNotification"; NSString * const KeyActionTypeAlert = @"alert"; +NSString * const KeyActionTypeNoop = @"noop"; NSString * const KeyActionInformation = @"actionInformation"; NSString * const KeyLinkAwayAppURL = @"appURL"; NSString * const KeyLinkAwayURL = @"browserUrl"; diff --git a/MVMCore/MVMCore/Models/ActionType/ActionNoopModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionNoopModel.swift new file mode 100644 index 0000000..25f3ded --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionNoopModel.swift @@ -0,0 +1,27 @@ +// +// ActionNoopModel.swift +// MVMCore +// +// Created by Dhamodaram Nandi on 14/09/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +@objcMembers public class ActionNoopModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public static var identifier: String = "noop" + public var actionType: String = ActionNoopModel.identifier + public var extraParameters: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + + public init(_ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { + self.extraParameters = extraParameters + self.analyticsData = analyticsData + } +} diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index 66fdab0..21ff0c1 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -22,5 +22,6 @@ import Foundation try? ModelRegistry.register(ActionCancelModel.self) try? ModelRegistry.register(ActionSettingModel.self) try? ModelRegistry.register(ActionAlertModel.self) + try? ModelRegistry.register(ActionNoopModel.self) } } From 30aa2093576b58a342de5776f3fb7364def36657 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Mon, 14 Sep 2020 18:08:00 +0530 Subject: [PATCH 2/6] added Constant --- MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index 697374c..da64130 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -42,6 +42,7 @@ extern NSString * const KeyActionTypeTopAlert; extern NSString * const KeyActionTypeSettings; extern NSString * const KeyActionTypeCollapseNotification; extern NSString * const KeyActionTypeAlert; +extern NSString * const KeyActionTypeNoop; extern NSString * const KeyActionInformation; extern NSString * const KeyLinkAwayAppURL; extern NSString * const KeyLinkAwayURL; From 881f1276ec95c724cfa7960d17bb3953d9729f6f Mon Sep 17 00:00:00 2001 From: Damodaram Date: Mon, 14 Sep 2020 21:12:56 +0530 Subject: [PATCH 3/6] removed comment --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 1 - 1 file changed, 1 deletion(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 8b2beac..b03dcc4 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -95,7 +95,6 @@ NSString * const KeyActionTypeOpen = @"openPage"; [self showAlert:actionInformation additionalData:additionalData delegateObject:delegateObject]; } else if ([actionType isEqualToString:KeyActionTypeNoop]){ - // Need to tag analytics data } else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]) { // not a known action type. [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; From ce6661fa8446231116d2c4df2e77d21746f225c2 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 14 Sep 2020 21:39:01 -0400 Subject: [PATCH 4/6] molecular top alert quick draft --- .../AlertHandling/MVMCoreAlertHandler.h | 9 +++ .../AlertHandling/MVMCoreAlertHandler.m | 15 ++--- .../MVMCoreAlertObject+Swift.swift | 60 +++++++++++++++++++ .../AlertHandling/MVMCoreTopAlertObject.h | 4 ++ .../MVMCore/LoadHandling/MVMCoreLoadObject.h | 3 + .../MVMCoreLoadRequestOperation.m | 2 + 6 files changed, 86 insertions(+), 7 deletions(-) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h index a4c44ec..2142d63 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.h @@ -12,10 +12,19 @@ #import #import +@class NotificationPagesOperation; @class MVMCoreAlertObject; @interface MVMCoreAlertHandler : NSObject +// An operation queue for displaying popup alerts. +@property (nonnull, strong, nonatomic) NSOperationQueue *popupAlertQueue; + +// An operation queue for top alerts +@property (nonnull, strong, nonatomic) NSOperationQueue *topAlertQueue; + +@property (nonnull, strong, nonatomic) NSOperationQueue *pageOperations; + /// Returns the shared instance of this singleton + (nullable instancetype)sharedAlertHandler; diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.m b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.m index 0c9393a..1e64663 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.m +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler.m @@ -14,18 +14,13 @@ #import "MVMCoreJSONConstants.h" #import "NSDictionary+MFConvenience.h" #import "NSArray+MFConvenience.h" +#import @interface MVMCoreAlertHandler () // Flag that keeps track of if the alerts are supressed or not. @property (assign, nonatomic) BOOL mfAlertsSupressed; -// An operation queue for displaying popup alerts. -@property (nonnull, strong, nonatomic) NSOperationQueue *popupAlertQueue; - -// An operation queue for top alerts -@property (nonnull, strong, nonatomic) NSOperationQueue *topAlertQueue; - @end @implementation MVMCoreAlertHandler @@ -47,6 +42,7 @@ self.popupAlertQueue.maxConcurrentOperationCount = 1; self.topAlertQueue = [[NSOperationQueue alloc] init]; self.topAlertQueue.maxConcurrentOperationCount = 1; + self.pageOperations = [[NSOperationQueue alloc] init]; } return self; } @@ -167,14 +163,19 @@ if (topAlertObject) { __block MVMCoreTopAlertOperation *alertOperation = [[MVMCoreTopAlertOperation alloc] initWithTopAlertObject:topAlertObject]; + __weak typeof(self) weakSelf = self; [alertOperation setCompletionBlock:^{ // If the alert was cancelled to show another with higher priority, re-add to the operation when cancelled to the queue. if (alertOperation.reAddAfterCancel) { - [self showTopAlertWithObject:alertOperation.topAlertObject]; + [weakSelf showTopAlertWithObject:alertOperation.topAlertObject]; } alertOperation = nil; }]; + + // This notification may only show for certain pages. + [self addPagesDependencyTo:alertOperation]; + [self.topAlertQueue addOperation:alertOperation]; // If the current running operation is persistent and has a lower queue priority then the added operation, cancel it and re-add it. diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index 162dd2d..b58de05 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -43,3 +43,63 @@ 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 5a4b587..97897cc 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertObject.h @@ -15,6 +15,7 @@ extern NSUInteger const TopAlertDismissTime; @property (nonatomic) BOOL persistent; @property (nullable, nonatomic) NSString *type; +@property (nonatomic) NSOperationQueuePriority queuePriority; // The text @property (nullable, strong, nonatomic) NSString *title; @@ -49,6 +50,9 @@ extern NSUInteger const TopAlertDismissTime; @property (nullable, strong, nonatomic) UIColor *backgroundColor; @property (nullable, strong, nonatomic) UIColor *textColor; +// For a json driven approach. +@property (nullable, strong, nonatomic) NSDictionary *json; + - (nullable instancetype)initWithResponseInfo:(nullable NSDictionary *)responseInfo; - (nullable instancetype)initWithType:(nullable NSString *)type message:(nullable NSString *)message; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h index f167ea7..92063b8 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h @@ -56,6 +56,9 @@ @property (nonatomic) BOOL pageDataFromCache; @property (nonatomic) BOOL moduleDataFromCache; +// The full response json +@property (nullable, strong, nonatomic) NSDictionary *responseJSON; + - (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject; - (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 2f4019b..b6e0ca9 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -354,6 +354,8 @@ return; } + loadObject.responseJSON = jsonDictionary; + // Store the new page data if we didn't load page data from the cache. NSDictionary *pageJSON = [jsonDictionary objectForKey:KeyPage ofType:[NSDictionary class]]; if (!loadObject.pageDataFromCache) { From 9415dfbda85a14e0ca90638c34f4f0b166faa21a Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 15 Sep 2020 11:31:10 -0400 Subject: [PATCH 5/6] 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; From fd4e6ae96b34591d3d621875dbde9cc88e1c57b3 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 15 Sep 2020 12:20:41 -0400 Subject: [PATCH 6/6] remove print statements --- .../MVMCore/AlertHandling/MVMCoreAlertHandler+Extension.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler+Extension.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler+Extension.swift index ffc5e76..44e8a08 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler+Extension.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertHandler+Extension.swift @@ -34,7 +34,6 @@ public extension MVMCoreAlertHandler { 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 @@ -47,12 +46,10 @@ public extension MVMCoreAlertHandler { 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)") } } } @@ -62,7 +59,6 @@ public extension MVMCoreAlertHandler { for case let operation as NotificationPagesOperation in pageOperations.operations { if operation.pages.contains(pageType) { operation.cancel() - print("TYTYT cancel dependency \(operation)") } } }