From e103cd554d5db119feef7618092343a66b83d181 Mon Sep 17 00:00:00 2001 From: gonch26 Date: Fri, 9 Oct 2020 01:53:17 -0500 Subject: [PATCH 1/6] [ COREUI: IMPROV ] Improve symbol with additional data parameter --- .../Containers/SplitViewController/MVMCoreUIPanelProtocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h index 4537e791..9ab2e8ce 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h @@ -17,7 +17,7 @@ - (BOOL)panelAvailable; // Notified when it is appearing and disappearing. Called by the container. -- (void)willOpenWithActionInformation:(nullable NSDictionary *)actionInformation; +- (void)willOpenWithActionInformation: (nullable NSDictionary *)actionInformation additionalData: (nullable NSDictionary *) additionalData; - (void)willAppear:(BOOL)animated; - (void)didAppear:(BOOL)animated; - (void)willDisappear:(BOOL)animated; From 24864bc99db1ea7da95a8441067661c802f7be4d Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 9 Oct 2020 10:51:52 -0400 Subject: [PATCH 2/6] Polling top notification --- .../Atomic/Molecules/OtherContainers/MoleculeContainer.swift | 4 ++-- .../Molecules/OtherContainers/MoleculeContainerModel.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainer.swift b/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainer.swift index 4e2c6279..d6b795ce 100644 --- a/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainer.swift +++ b/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainer.swift @@ -11,11 +11,11 @@ import UIKit open class MoleculeContainer: Container { /// Can be overriden to change how the molecule is added to the hierarchy. - public func addMolecule(_ molecule: UIView) { + open func addMolecule(_ molecule: UIView) { addAndContain(molecule) } - public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { if let casteModel = model as? MoleculeContainerModelProtocol { if view != nil { (view as? MoleculeViewProtocol)?.set(with: casteModel.molecule, delegateObject, additionalData) diff --git a/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainerModel.swift b/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainerModel.swift index aa847f88..77b40716 100644 --- a/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainerModel.swift +++ b/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainerModel.swift @@ -9,7 +9,7 @@ import Foundation open class MoleculeContainerModel: ContainerModel, MoleculeContainerModelProtocol, MoleculeModelProtocol { - public class var identifier: String { + open class var identifier: String { return "container" } public var backgroundColor: Color? @@ -41,7 +41,7 @@ open class MoleculeContainerModel: ContainerModel, MoleculeContainerModelProtoco try super.init(from: decoder) } - public override func encode(to encoder: Encoder) throws { + open override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) From 3b1e3d01c081f914b1b659054b32a06b37dd93cf Mon Sep 17 00:00:00 2001 From: gonch26 Date: Fri, 9 Oct 2020 11:12:30 -0500 Subject: [PATCH 3/6] [ Chatbot: FIX ] Update to remove space between parameter's types --- .../Containers/SplitViewController/MVMCoreUIPanelProtocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h index 9ab2e8ce..8d381b76 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIPanelProtocol.h @@ -17,7 +17,7 @@ - (BOOL)panelAvailable; // Notified when it is appearing and disappearing. Called by the container. -- (void)willOpenWithActionInformation: (nullable NSDictionary *)actionInformation additionalData: (nullable NSDictionary *) additionalData; +- (void)willOpenWithActionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData; - (void)willAppear:(BOOL)animated; - (void)didAppear:(BOOL)animated; - (void)willDisappear:(BOOL)animated; From 159798f0d8cbc7134e64b4cb28029e5d0eb88831 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 15 Oct 2020 10:37:36 -0400 Subject: [PATCH 4/6] updates for polling --- .../TopNotification/CollapsableNotificationModel.swift | 8 ++++---- .../Molecules/TopNotification/NotificationModel.swift | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift index 804bfeb6..17b1aef7 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift @@ -8,7 +8,7 @@ import Foundation -public class CollapsableNotificationModel: NotificationModel { +open class CollapsableNotificationModel: NotificationModel { public class override var identifier: String { return "collapsableNotification" } @@ -19,12 +19,12 @@ public class CollapsableNotificationModel: NotificationModel { public var initiallyCollapsed = false public var pages: [String]? - init(with topLabel: LabelModel, headline: LabelModel) { + public init(with topLabel: LabelModel, headline: LabelModel) { self.topLabel = topLabel super.init(with: headline) } - override func setDefault() { + open override func setDefault() { super.setDefault() if topLabel.textColor == nil { topLabel.textColor = Color(uiColor: .white) @@ -61,7 +61,7 @@ public class CollapsableNotificationModel: NotificationModel { try super.init(from: decoder) } - public override func encode(to encoder: Encoder) throws { + open override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift index e2f94326..70ff00bb 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift @@ -8,7 +8,7 @@ import Foundation -public class NotificationModel: MoleculeModelProtocol { +open class NotificationModel: MoleculeModelProtocol { public class var identifier: String { return "notification" } @@ -18,11 +18,11 @@ public class NotificationModel: MoleculeModelProtocol { public var button: ButtonModel? public var closeButton: NotificationXButtonModel? - init(with headline: LabelModel) { + public init(with headline: LabelModel) { self.headline = headline } - func setDefault() { + open func setDefault() { if backgroundColor == nil { backgroundColor = Color(uiColor: .mvmGreen()) } @@ -59,7 +59,7 @@ public class NotificationModel: MoleculeModelProtocol { setDefault() } - public func encode(to encoder: Encoder) throws { + open func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) From b371cf5e8374834ff3dff72ddd6c2f4eb74974bb Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 15 Oct 2020 16:36:29 -0400 Subject: [PATCH 5/6] new timers top alert update function --- .../MVMCoreUITopAlertView+Extension.swift | 46 +++++++++++++++---- MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h | 3 ++ MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m | 6 ++- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift index 8bf4860f..5c199c14 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift @@ -21,14 +21,17 @@ public extension MVMCoreUITopAlertView { NotificationCenter.default.addObserver(self, selector: #selector(viewControllerChanged(notification:)), name: NSNotification.Name(rawValue: MVMCoreNotificationViewControllerChanged), object: nil) } + @objc func getDelegateObject() -> MVMCoreUIDelegateObject { + // TODO: Top alert view is current delegate. Should move to current view controller eventually? + return MVMCoreUIDelegateObject.create(withDelegateForAll: self) + } + /// Checks for new top alert json @objc func responseJSONUpdated(notification: Notification) { guard let responseJSON = (notification.userInfo?[String(describing: MVMCoreLoadObject.self)] as? MVMCoreLoadObject)?.responseJSON, - let json = responseJSON.optionalDictionaryForKey("TopNotification") else { return } - - // TODO: Top alert view is current delegate. Should move to current view controller eventually? - let delegateObject = MVMCoreUIDelegateObject.create(withDelegateForAll: self) - showTopAlert(with: json, delegateObject: delegateObject) + let json = responseJSON.optionalDictionaryForKey("TopNotification"), + let model = decodeTopNotification(with: json, delegateObject: getDelegateObject()) else { return } + showTopAlert(with: model) } /// When a detail page changes, check top alerts. @@ -37,24 +40,47 @@ public extension MVMCoreUITopAlertView { MVMCoreAlertHandler.shared()?.checkPagesDependency(for: controller.pageType) } - /// Shows the top alert with the json payload. - func showTopAlert(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) { + func decodeTopNotification(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) -> TopNotificationModel? { do { - let model = try TopNotificationModel.decode(json: json, delegateObject: delegateObject) - showTopAlert(with: model, delegateObject: delegateObject) + return try TopNotificationModel.decode(json: json, delegateObject: delegateObject) } catch { if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "\(self)") { MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject) } + return nil } } /// Shows the top alert with the model. - func showTopAlert(with model: TopNotificationModel, delegateObject: MVMCoreUIDelegateObject?) { + func showTopAlert(with model: TopNotificationModel) { let object = model.createTopAlertObject() MVMCoreAlertHandler.shared()?.showTopAlert(with: object) } + @objc func updateMolecule(with topAlertObject: MVMCoreTopAlertObject) { + guard topAlertObject.type == self.topAlertObject?.type else { return } + let delegateObject = getDelegateObject() + guard let newJson = topAlertObject.json, + let newModel = decodeTopNotification(with: newJson, delegateObject: delegateObject), + let newModelName = MoleculeObjectMapping.shared()?.getMoleculeClass(newModel.molecule)?.nameForReuse(with: newModel.molecule, delegateObject), + let currentJson = self.topAlertObject?.json, + let currentModel = decodeTopNotification(with: currentJson, delegateObject: delegateObject), + let currentModelName = MoleculeObjectMapping.shared()?.getMoleculeClass(currentModel.molecule)?.nameForReuse(with: currentModel.molecule, delegateObject), + newModelName == currentModelName, + let molecule = currentAlert as? MoleculeViewProtocol else { return /* Something is not right, revisit */} + // Update molecule + MVMCoreDispatchUtility.performBlock(onMainThread: { + molecule.reset() + molecule.set(with: newModel.molecule, delegateObject, nil) + (molecule as? MVMCoreViewProtocol)?.updateView(self.bounds.width) + + // Update status bar. + guard let statusBarDelegate = molecule as? StatusBarUI else { return } + let statusBarUI = statusBarDelegate.getStatusBarUI() + self.setStatusBarColor(statusBarUI.color, statusBarStyle: statusBarUI.style) + }) + } + /// Returns the top alert molecule to use and status bar color legacy style. @objc func molecule(for topAlertObject: MVMCoreTopAlertObject, statusBarColor: AutoreleasingUnsafeMutablePointer?, statusBarStyle: UnsafeMutablePointer?) -> UIView? { do { diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h index 82c0a7e9..1979a850 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h @@ -27,6 +27,9 @@ // Current top alert object @property (strong, nullable, nonatomic) MVMCoreTopAlertObject *topAlertObject; +/// Current top alert view. +@property (weak, nullable, nonatomic, readonly) UIView *currentAlert; + // Returns the top alert view + (nullable instancetype)sharedGlobal; diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m index d54190b0..14f4dee2 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m @@ -39,7 +39,7 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; @property (strong, nonatomic) NSLayoutConstraint *statusBarBottomConstraint; @property (weak, nonatomic) UIView *alertView; -@property (weak, nonatomic) UIView *currentAlert; +@property (weak, nullable, nonatomic, readwrite) UIView *currentAlert; @property (strong, nonatomic) NSLayoutConstraint *height; @property (weak, nonatomic) MVMCoreUITopAlertExpandableView *topAlertClearspotView; @@ -181,6 +181,10 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; }); } +- (void)updateTopAlertWith:(MVMCoreTopAlertObject *)topAlertObject { + [self updateMoleculeWith:topAlertObject]; +} + - (void)setStatusBarColor:(nullable UIColor *)statusBarColor statusBarStyle:(UIStatusBarStyle)style { self.statusBarView.backgroundColor = statusBarColor; self.statusBarStyle = style; From 44c74765425cab5444cef34d26b46235f6ec1331 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 15 Oct 2020 16:51:27 -0400 Subject: [PATCH 6/6] clean --- .../TopAlert/MVMCoreUITopAlertView+Extension.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift index 5c199c14..6a3c78de 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView+Extension.swift @@ -40,6 +40,7 @@ public extension MVMCoreUITopAlertView { MVMCoreAlertHandler.shared()?.checkPagesDependency(for: controller.pageType) } + /// Decodes the json into a TopNotificationModel func decodeTopNotification(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) -> TopNotificationModel? { do { return try TopNotificationModel.decode(json: json, delegateObject: delegateObject) @@ -57,6 +58,7 @@ public extension MVMCoreUITopAlertView { MVMCoreAlertHandler.shared()?.showTopAlert(with: object) } + /// Updates the current top alert molecule with the new object @objc func updateMolecule(with topAlertObject: MVMCoreTopAlertObject) { guard topAlertObject.type == self.topAlertObject?.type else { return } let delegateObject = getDelegateObject() @@ -67,9 +69,15 @@ public extension MVMCoreUITopAlertView { let currentModel = decodeTopNotification(with: currentJson, delegateObject: delegateObject), let currentModelName = MoleculeObjectMapping.shared()?.getMoleculeClass(currentModel.molecule)?.nameForReuse(with: currentModel.molecule, delegateObject), newModelName == currentModelName, - let molecule = currentAlert as? MoleculeViewProtocol else { return /* Something is not right, revisit */} - // Update molecule + let molecule = currentAlert as? MoleculeViewProtocol else { + // Log that we couldn't update. + if let errorObject = MVMCoreErrorObject(title: nil, message: nil, messageToLog: nil, code: ErrorCode.parsingJSON.rawValue, domain: ErrorDomainNative, location: "TopNotification update \(String(describing: topAlertObject.type))") { + MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject) + } + return + } MVMCoreDispatchUtility.performBlock(onMainThread: { + // Update molecule molecule.reset() molecule.set(with: newModel.molecule, delegateObject, nil) (molecule as? MVMCoreViewProtocol)?.updateView(self.bounds.width)