From 2204e2fd777935748d068d4b382ce85a8f996d55 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Thu, 22 Apr 2021 19:27:54 +0530 Subject: [PATCH 1/5] swap contact name changes --- ...eIconWithRightCaretAllTextLinksModel.swift | 7 +++- .../BaseControllers/ViewController.swift | 2 +- MVMCoreUI/Behaviors/GetContactBehavior.swift | 33 ++++++++++++------- .../Protocols/PageBehaviorProtocol.swift | 6 ++++ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift index 9d9291e8..3f48a2d6 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift @@ -6,7 +6,8 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -public class ListLeftVariableIconWithRightCaretAllTextLinksModel: ListItemModel, MoleculeModelProtocol { +public class ListLeftVariableIconWithRightCaretAllTextLinksModel: ListItemModel, ParentMoleculeModelProtocol { + //----------------------------------------------------- // MARK: - Properties //----------------------------------------------------- @@ -16,6 +17,10 @@ public class ListLeftVariableIconWithRightCaretAllTextLinksModel: ListItemModel, public var eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel public var rightLabel: LabelModel + public var children: [MoleculeModelProtocol] { + return [image, eyebrowHeadlineBodyLink,rightLabel] + } + //----------------------------------------------------- // MARK: - Methods //----------------------------------------------------- diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 293bd49f..20ba4a66 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -653,7 +653,7 @@ import UIKit // MARK: - Behavior Execution //-------------------------------------------------- - func executeBehaviors(_ behaviorBlock: (_ behavior: T) -> Void) { + public func executeBehaviors(_ behaviorBlock: (_ behavior: T) -> Void) { behaviors?.compactMap { $0 as? T }.forEach { behaviorBlock($0) } } } diff --git a/MVMCoreUI/Behaviors/GetContactBehavior.swift b/MVMCoreUI/Behaviors/GetContactBehavior.swift index 2c6205f2..6ea969ac 100644 --- a/MVMCoreUI/Behaviors/GetContactBehavior.swift +++ b/MVMCoreUI/Behaviors/GetContactBehavior.swift @@ -21,7 +21,8 @@ public class PageGetContactBehaviorModel: PageBehaviorModelProtocol { public init() {} } -public class PageGetContactBehavior: PageVisibilityBehavior { +public class PageGetContactBehavior: PageVisibilityBehavior,PageNextBatchActionBehavior { + var delegate: MVMCoreUIDelegateObject? public required init(model: PageBehaviorModelProtocol, delegateObject: MVMCoreUIDelegateObject?) { @@ -32,24 +33,34 @@ public class PageGetContactBehavior: PageVisibilityBehavior { // Ask for permission CNContactStore().requestAccess(for: .contacts) { [weak self] (access, error) in guard access, - error == nil, - let rootMolecules = self?.delegate?.moleculeDelegate?.getRootMolecules() else { return } + error == nil else { return } // Iterate models and provide contact - let store = CNContactStore() - let consumers: [PageGetContactBehaviorConsumerProtocol] = rootMolecules.allMoleculesOfType() - for consumer in consumers { - guard let parameters = consumer.getMatchParameters(), - let contacts = try? store.unifiedContacts(matching: parameters.0, keysToFetch: parameters.1) else { return } - consumer.consume(contacts: contacts) - } + self?.getContacts() // Tell template to update MVMCoreDispatchUtility.performBlock(onMainThread: { // TODO: move to protocol function instead - (self?.delegate?.moleculeDelegate as? ViewController)?.handleNewData() + (self?.delegate?.moleculeDelegate as? ViewController)?.handleNewDataAndUpdateUI() }) } } + func getContacts() { + guard let rootMolecules = self.delegate?.moleculeDelegate?.getRootMolecules() else { return } + let store = CNContactStore() + let consumers: [PageGetContactBehaviorConsumerProtocol] = rootMolecules.allMoleculesOfType() + for consumer in consumers { + guard let parameters = consumer.getMatchParameters(), + let contacts = try? store.unifiedContacts(matching: parameters.0, keysToFetch: parameters.1) else { return } + consumer.consume(contacts: contacts) + } + } + public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) {} + + public func nextBatchAction(_ delegateObject: MVMCoreUIDelegateObject?) { + if CNContactStore.authorizationStatus(for: .contacts) == .authorized { + getContacts() + } + } } diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift index e7db54bc..87df7007 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift @@ -39,6 +39,12 @@ public protocol PageLocalDataShareBehavior: PageBehaviorProtocol { func receiveLocalPageData(_ data:[AnyHashable: Any], _ delegateObject: MVMCoreUIDelegateObject) } +public protocol PageNextBatchActionBehavior: PageBehaviorProtocol { + + func nextBatchAction(_ delegateObject: MVMCoreUIDelegateObject?) + +} + public protocol PageCustomActionHandlerBehavior: PageBehaviorProtocol { func handleAction(type actionType: String?, information: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) -> Bool From f583a06725f5f6eb8060c4e15dec035ad0a66789 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Thu, 22 Apr 2021 20:01:37 +0530 Subject: [PATCH 2/5] review changes --- MVMCoreUI/Behaviors/GetContactBehavior.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Behaviors/GetContactBehavior.swift b/MVMCoreUI/Behaviors/GetContactBehavior.swift index 6ea969ac..eaf3d5d9 100644 --- a/MVMCoreUI/Behaviors/GetContactBehavior.swift +++ b/MVMCoreUI/Behaviors/GetContactBehavior.swift @@ -46,7 +46,7 @@ public class PageGetContactBehavior: PageVisibilityBehavior,PageNextBatchActionB } func getContacts() { - guard let rootMolecules = self.delegate?.moleculeDelegate?.getRootMolecules() else { return } + guard let rootMolecules = delegate?.moleculeDelegate?.getRootMolecules() else { return } let store = CNContactStore() let consumers: [PageGetContactBehaviorConsumerProtocol] = rootMolecules.allMoleculesOfType() for consumer in consumers { From c8b382cc892b5ab131b2c84c9aa85458a70ded01 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Thu, 22 Apr 2021 20:44:42 +0530 Subject: [PATCH 3/5] moved behaviour --- MVMCoreUI/Behaviors/GetContactBehavior.swift | 10 ++-------- .../Behaviors/Protocols/PageBehaviorProtocol.swift | 6 ------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/Behaviors/GetContactBehavior.swift b/MVMCoreUI/Behaviors/GetContactBehavior.swift index eaf3d5d9..b36f778b 100644 --- a/MVMCoreUI/Behaviors/GetContactBehavior.swift +++ b/MVMCoreUI/Behaviors/GetContactBehavior.swift @@ -21,7 +21,7 @@ public class PageGetContactBehaviorModel: PageBehaviorModelProtocol { public init() {} } -public class PageGetContactBehavior: PageVisibilityBehavior,PageNextBatchActionBehavior { +public class PageGetContactBehavior: PageVisibilityBehavior { var delegate: MVMCoreUIDelegateObject? @@ -45,7 +45,7 @@ public class PageGetContactBehavior: PageVisibilityBehavior,PageNextBatchActionB } } - func getContacts() { + public func getContacts() { guard let rootMolecules = delegate?.moleculeDelegate?.getRootMolecules() else { return } let store = CNContactStore() let consumers: [PageGetContactBehaviorConsumerProtocol] = rootMolecules.allMoleculesOfType() @@ -57,10 +57,4 @@ public class PageGetContactBehavior: PageVisibilityBehavior,PageNextBatchActionB } public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) {} - - public func nextBatchAction(_ delegateObject: MVMCoreUIDelegateObject?) { - if CNContactStore.authorizationStatus(for: .contacts) == .authorized { - getContacts() - } - } } diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift index 87df7007..e7db54bc 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift @@ -39,12 +39,6 @@ public protocol PageLocalDataShareBehavior: PageBehaviorProtocol { func receiveLocalPageData(_ data:[AnyHashable: Any], _ delegateObject: MVMCoreUIDelegateObject) } -public protocol PageNextBatchActionBehavior: PageBehaviorProtocol { - - func nextBatchAction(_ delegateObject: MVMCoreUIDelegateObject?) - -} - public protocol PageCustomActionHandlerBehavior: PageBehaviorProtocol { func handleAction(type actionType: String?, information: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) -> Bool From a225cf81e3db515a61fd26b42450413045403b74 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Thu, 22 Apr 2021 20:54:44 +0530 Subject: [PATCH 4/5] review changes --- .../ListLeftVariableIconWithRightCaretAllTextLinksModel.swift | 2 +- MVMCoreUI/BaseControllers/ViewController.swift | 2 +- MVMCoreUI/Behaviors/GetContactBehavior.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift index 3f48a2d6..3129776b 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinksModel.swift @@ -18,7 +18,7 @@ public class ListLeftVariableIconWithRightCaretAllTextLinksModel: ListItemModel, public var rightLabel: LabelModel public var children: [MoleculeModelProtocol] { - return [image, eyebrowHeadlineBodyLink,rightLabel] + return [image, eyebrowHeadlineBodyLink, rightLabel] } //----------------------------------------------------- diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 20ba4a66..8a22e23a 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -653,7 +653,7 @@ import UIKit // MARK: - Behavior Execution //-------------------------------------------------- - public func executeBehaviors(_ behaviorBlock: (_ behavior: T) -> Void) { + public func executeBehaviors(_ behaviorBlock: (_ behavior: T) -> Void) { behaviors?.compactMap { $0 as? T }.forEach { behaviorBlock($0) } } } diff --git a/MVMCoreUI/Behaviors/GetContactBehavior.swift b/MVMCoreUI/Behaviors/GetContactBehavior.swift index b36f778b..c7327a1c 100644 --- a/MVMCoreUI/Behaviors/GetContactBehavior.swift +++ b/MVMCoreUI/Behaviors/GetContactBehavior.swift @@ -48,7 +48,7 @@ public class PageGetContactBehavior: PageVisibilityBehavior { public func getContacts() { guard let rootMolecules = delegate?.moleculeDelegate?.getRootMolecules() else { return } let store = CNContactStore() - let consumers: [PageGetContactBehaviorConsumerProtocol] = rootMolecules.allMoleculesOfType() + let consumers: [PageGetContactBehaviorConsumerProtocol] = rootMolecules.allMoleculesOfType() for consumer in consumers { guard let parameters = consumer.getMatchParameters(), let contacts = try? store.unifiedContacts(matching: parameters.0, keysToFetch: parameters.1) else { return } From 96c275d51c4af7b863dfef628a31d40868c3d75c Mon Sep 17 00:00:00 2001 From: Damodaram Date: Fri, 23 Apr 2021 09:46:00 +0530 Subject: [PATCH 5/5] added molecules parameter --- MVMCoreUI/Behaviors/GetContactBehavior.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Behaviors/GetContactBehavior.swift b/MVMCoreUI/Behaviors/GetContactBehavior.swift index c7327a1c..1bb27ac7 100644 --- a/MVMCoreUI/Behaviors/GetContactBehavior.swift +++ b/MVMCoreUI/Behaviors/GetContactBehavior.swift @@ -33,9 +33,10 @@ public class PageGetContactBehavior: PageVisibilityBehavior { // Ask for permission CNContactStore().requestAccess(for: .contacts) { [weak self] (access, error) in guard access, - error == nil else { return } + error == nil, + let rootMolecules = self?.delegate?.moleculeDelegate?.getRootMolecules() else { return } // Iterate models and provide contact - self?.getContacts() + self?.getContacts(for: rootMolecules) // Tell template to update MVMCoreDispatchUtility.performBlock(onMainThread: { @@ -45,10 +46,9 @@ public class PageGetContactBehavior: PageVisibilityBehavior { } } - public func getContacts() { - guard let rootMolecules = delegate?.moleculeDelegate?.getRootMolecules() else { return } + public func getContacts(for molecules: [MoleculeModelProtocol]) { + let consumers: [PageGetContactBehaviorConsumerProtocol] = molecules.allMoleculesOfType() let store = CNContactStore() - let consumers: [PageGetContactBehaviorConsumerProtocol] = rootMolecules.allMoleculesOfType() for consumer in consumers { guard let parameters = consumer.getMatchParameters(), let contacts = try? store.unifiedContacts(matching: parameters.0, keysToFetch: parameters.1) else { return }