Comments, organizing, init fix

This commit is contained in:
Pfeil, Scott Robert 2020-09-15 11:31:10 -04:00
parent ce6661fa84
commit 9415dfbda8
5 changed files with 75 additions and 62 deletions

View File

@ -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 = "<group>"; };
D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreGetterUtility+Extension.swift"; sourceTree = "<group>"; };
D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = "<group>"; };
D2CAC7C72510F0C500C75681 /* MVMCoreAlertHandler+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreAlertHandler+Extension.swift"; sourceTree = "<group>"; };
D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = "<group>"; };
D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitInterval.swift; sourceTree = "<group>"; };
D2DEDCBA23C65BC300C44CC4 /* Percent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Percent.swift; sourceTree = "<group>"; };
@ -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 */,

View File

@ -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)")
}
}
}
}

View File

@ -12,7 +12,6 @@
#import <MVMCore/MVMCoreTopAlertObject.h>
#import <MVMCore/MVMCoreAlertDelegateProtocol.h>
@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

View File

@ -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)")
}
}
}
}

View File

@ -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;