diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index eb5327be..7fa7844c 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -129,6 +129,8 @@ 187FEB2A2844D2A600BF29C2 /* VDSFormControlsTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 187FEB292844D2A600BF29C2 /* VDSFormControlsTokens.xcframework */; }; 1D6D258826899B0C00DEBB08 /* ImageButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D6D258626899B0B00DEBB08 /* ImageButtonModel.swift */; }; 1D6D258926899B0C00DEBB08 /* ImageButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D6D258726899B0B00DEBB08 /* ImageButton.swift */; }; + 22B678F929E7944E00CF4196 /* GetNotificationAuthStatusBehavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22B678F829E7944E00CF4196 /* GetNotificationAuthStatusBehavior.swift */; }; + 22B678FD29E82B0300CF4196 /* ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22B678FC29E82B0300CF4196 /* ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift */; }; 27559EFC27D691D3000836C1 /* ViewMaskingProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27559EFB27D691D3000836C1 /* ViewMaskingProtocol.swift */; }; 27577DCD286CA959001EC47E /* MoleculeMaskingProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27577DCC286CA959001EC47E /* MoleculeMaskingProtocol.swift */; }; 279B1569242BBC2F00921D6C /* ActionModelAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 279B1568242BBC2F00921D6C /* ActionModelAdapter.swift */; }; @@ -730,6 +732,8 @@ 187FEB292844D2A600BF29C2 /* VDSFormControlsTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSFormControlsTokens.xcframework; path = ../SharedFrameworks/VDSFormControlsTokens.xcframework; sourceTree = ""; }; 1D6D258626899B0B00DEBB08 /* ImageButtonModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImageButtonModel.swift; path = MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift; sourceTree = SOURCE_ROOT; }; 1D6D258726899B0B00DEBB08 /* ImageButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImageButton.swift; path = MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift; sourceTree = SOURCE_ROOT; }; + 22B678F829E7944E00CF4196 /* GetNotificationAuthStatusBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetNotificationAuthStatusBehavior.swift; sourceTree = ""; }; + 22B678FC29E82B0300CF4196 /* ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift; sourceTree = ""; }; 27559EFB27D691D3000836C1 /* ViewMaskingProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewMaskingProtocol.swift; sourceTree = ""; }; 27577DCC286CA959001EC47E /* MoleculeMaskingProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeMaskingProtocol.swift; sourceTree = ""; }; 279B1568242BBC2F00921D6C /* ActionModelAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionModelAdapter.swift; sourceTree = ""; }; @@ -1417,6 +1421,7 @@ 27F97369246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift */, D23A900826125FFB007E14CE /* GetContactBehavior.swift */, D270E5662642F77300CDBED2 /* AddRemoveMoleculeBehavior.swift */, + 22B678F829E7944E00CF4196 /* GetNotificationAuthStatusBehavior.swift */, ); path = Behaviors; sourceTree = ""; @@ -1437,6 +1442,7 @@ 52267A0623FFE25000906CBA /* ListOneColumnFullWidthTextAllTextAndLinks.swift */, 8D084ACF2410BF4800951227 /* ListOneColumnFullWidthTextBodyTextModel.swift */, 8D084AD12410BF7600951227 /* ListOneColumnFullWidthTextBodyText.swift */, + 22B678FC29E82B0300CF4196 /* ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift */, ); path = OneColumn; sourceTree = ""; @@ -3007,6 +3013,7 @@ 324FB6AC24936717002552C7 /* ListLeftVariableNumberedListBodyText.swift in Sources */, AAA74A172410C04600080241 /* HeadersH2NoButtonsBodyText.swift in Sources */, 522679C223FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinksModel.swift in Sources */, + 22B678FD29E82B0300CF4196 /* ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift in Sources */, AA7F32AB246C0F7900C965BA /* ListLeftVariableRadioButtonAllTextAndLinksModel.swift in Sources */, 8D084AD02410BF4800951227 /* ListOneColumnFullWidthTextBodyTextModel.swift in Sources */, AF60A7F82892D34D00919EEB /* ActionDismissNotificationHandler.swift in Sources */, @@ -3081,6 +3088,7 @@ 01F2C20427C81F9700DC3D36 /* SubNavInteractor.swift.swift in Sources */, D28A837D23CCA86A00DFE4FC /* TabsListItemModel.swift in Sources */, 0A51F3E32475CB73002E08B6 /* LoadingSpinner.swift in Sources */, + 22B678F929E7944E00CF4196 /* GetNotificationAuthStatusBehavior.swift in Sources */, BB2FB3BB247E7EBC00DF73CD /* TagCollectionViewCell.swift in Sources */, 012A88C6238DA34000FE3DA1 /* ModuleMoleculeModel.swift in Sources */, 94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift new file mode 100644 index 00000000..fe0eaf04 --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift @@ -0,0 +1,69 @@ +// +// ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.swift +// MVMCoreUI +// +// Created by Edayattu Salam, Nowfal on 13/04/23. +// Copyright © 2023 Verizon Wireless. All rights reserved. +// + +import Foundation + +public class ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel: ListOneColumnFullWidthTextAllTextAndLinksModel { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public class override var identifier: String { "list1CTxtConsumeNotificationAuth" } + public var enableStatus: String? + public var disableStatus: String? + public var enableAction: ActionModelProtocol? + public var disableAction: ActionModelProtocol? + + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { + case enableStatus + case disableStatus + case enableAction + case disableAction + } + + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + required public init(from decoder: Decoder) throws { + try super.init(from: decoder) + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + enableStatus = try typeContainer.decodeIfPresent(String.self, forKey: .enableStatus) + disableStatus = try typeContainer.decodeIfPresent(String.self, forKey: .disableStatus) + enableAction = try typeContainer.decodeModelIfPresent(codingKey: .enableAction) + disableAction = try typeContainer.decodeModelIfPresent(codingKey: .disableAction) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(enableStatus, forKey: .enableStatus) + try container.encodeIfPresent(disableStatus, forKey: .disableStatus) + try container.encodeModelIfPresent(enableAction, forKey: .enableAction) + try container.encodeModelIfPresent(disableAction, forKey: .disableAction) + } +} + +extension ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel: PageBehaviorProtocolRequirer { + public func getRequiredBehaviors() -> [PageBehaviorModelProtocol] { + [PageGetNotificationAuthStatusBehaviorModel()] + } +} + +extension ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel: PageGetNotificationAuthStatusBehaviorConsumerProtocol { + public func consume(notificationStatus: UNAuthorizationStatus) { + if(notificationStatus == .authorized){ + body?.text = enableStatus ?? "" + action = enableAction + } else { + body?.text = disableStatus ?? "" + action = disableAction + } + } +} diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextAllTextAndLinksModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextAllTextAndLinksModel.swift index 34e1d28b..1bdb2b41 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextAllTextAndLinksModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextAllTextAndLinksModel.swift @@ -13,8 +13,7 @@ public class ListOneColumnFullWidthTextAllTextAndLinksModel: ListItemModel, Mole //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - - public static var identifier: String = "list1CTxt" + open class var identifier: String { "list1CTxt" } public var eyebrow: LabelModel? public var headline : LabelModel? public var subHeadline: LabelModel? diff --git a/MVMCoreUI/Behaviors/GetNotificationAuthStatusBehavior.swift b/MVMCoreUI/Behaviors/GetNotificationAuthStatusBehavior.swift new file mode 100644 index 00000000..fea35cf7 --- /dev/null +++ b/MVMCoreUI/Behaviors/GetNotificationAuthStatusBehavior.swift @@ -0,0 +1,61 @@ +// +// GetNotificationAuthStatusBehavior.swift +// MVMCoreUI +// +// Created by Edayattu Salam, Nowfal on 13/04/23. +// Copyright © 2023 Verizon Wireless. All rights reserved. +// + +public protocol PageGetNotificationAuthStatusBehaviorConsumerProtocol { + func consume(notificationStatus: UNAuthorizationStatus) +} + +public class PageGetNotificationAuthStatusBehaviorModel: PageBehaviorModelProtocol { + public class var identifier: String { "pageGetNotificationAuthStatusBehavior" } + public var shouldAllowMultipleInstances: Bool { false } + + public init() { } +} + +public class PageGetNotificationAuthStatusBehavior: PageVisibilityBehavior { + var delegate: MVMCoreUIDelegateObject? + + public required init(model: PageBehaviorModelProtocol, delegateObject: MVMCoreUIDelegateObject?) { + self.delegate = delegateObject + } + + public func onPageShown(_ delegateObject: MVMCoreUIDelegateObject?) { + // Get notification auth status + self.getNotificationStatus() + + NotificationCenter.default.addObserver(self, selector: #selector(onForeground), name: UIApplication.willEnterForegroundNotification, object: nil) + } + + @objc public func onForeground() { + // Get notification authorization status + self.getNotificationStatus() + } + + public func getNotificationStatus() { + guard let rootMolecules = self.delegate?.moleculeDelegate?.getRootMolecules() else { return } + let consumers: [PageGetNotificationAuthStatusBehaviorConsumerProtocol] = rootMolecules.allMoleculesOfType() + + let center = UNUserNotificationCenter.current() + center.getNotificationSettings { (settings) in + for consumer in consumers { + consumer.consume(notificationStatus: settings.authorizationStatus) + } + } + + // Tell template to update + MVMCoreDispatchUtility.performBlock(onMainThread: { + guard let controller = self.delegate?.moleculeDelegate as? ViewController else { return } + controller.handleNewDataAndUpdateUI() + }) + + } + + public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) { + NotificationCenter.default.removeObserver(self, name: UIApplication.willEnterForegroundNotification, object: nil) + } +} diff --git a/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift b/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift index 3e5357ea..39d100d4 100644 --- a/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift +++ b/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift @@ -155,6 +155,7 @@ open class CoreUIModelMapping: ModelMapping { ModelRegistry.register(handler: ListRightVariableToggleAllTextAndLinks.self, for: ListRightVariableToggleAllTextAndLinksModel.self) ModelRegistry.register(handler: ListRightVariableRightCaretAllTextAndLinks.self, for: ListRightVariableRightCaretAllTextAndLinksModel.self) ModelRegistry.register(handler: ListOneColumnFullWidthTextAllTextAndLinks.self, for: ListOneColumnFullWidthTextAllTextAndLinksModel.self) + ModelRegistry.register(handler: ListOneColumnFullWidthTextAllTextAndLinks.self, for: ConsumeNotificationAuthListOneColumnFullWidthTextAllTextAndLinksModel.self) ModelRegistry.register(handler: ListOneColumnFullWidthTextBodyText.self, for: ListOneColumnFullWidthTextBodyTextModel.self) ModelRegistry.register(handler: ListTwoColumnCompareChanges.self, for: ListTwoColumnCompareChangesModel.self) ModelRegistry.register(handler: ListTwoColumnPriceDetails.self, for: ListTwoColumnPriceDetailsModel.self) @@ -224,6 +225,7 @@ open class CoreUIModelMapping: ModelMapping { ModelRegistry.register(handler: ScreenBrightnessModifierBehavior.self, for: ScreenBrightnessModifierBehaviorModel.self) ModelRegistry.register(handler: PageGetContactBehavior.self, for: PageGetContactBehaviorModel.self) ModelRegistry.register(handler: AddRemoveMoleculesBehavior.self, for: AddRemoveMoleculesBehaviorModel.self) + ModelRegistry.register(handler: PageGetNotificationAuthStatusBehavior.self, for: PageGetNotificationAuthStatusBehaviorModel.self) } open override class func registerActions() {