diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 665c4cb7..0f339285 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 /* ListNotificationAuthModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22B678FC29E82B0300CF4196 /* ListNotificationAuthModel.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 */; }; @@ -734,6 +736,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 /* ListNotificationAuthModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListNotificationAuthModel.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 = ""; }; @@ -1427,6 +1431,7 @@ 27F97369246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift */, D23A900826125FFB007E14CE /* GetContactBehavior.swift */, D270E5662642F77300CDBED2 /* AddRemoveMoleculeBehavior.swift */, + 22B678F829E7944E00CF4196 /* GetNotificationAuthStatusBehavior.swift */, ); path = Behaviors; sourceTree = ""; @@ -1583,6 +1588,7 @@ children = ( AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */, AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */, + 22B678FC29E82B0300CF4196 /* ListNotificationAuthModel.swift */, AA7F47722541AD560015A2C1 /* ListStarRatingModel.swift */, AA7F47752541AD6A0015A2C1 /* ListStarRating.swift */, ); @@ -3019,6 +3025,7 @@ 324FB6AC24936717002552C7 /* ListLeftVariableNumberedListBodyText.swift in Sources */, AAA74A172410C04600080241 /* HeadersH2NoButtonsBodyText.swift in Sources */, 522679C223FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinksModel.swift in Sources */, + 22B678FD29E82B0300CF4196 /* ListNotificationAuthModel.swift in Sources */, AA7F32AB246C0F7900C965BA /* ListLeftVariableRadioButtonAllTextAndLinksModel.swift in Sources */, 8D084AD02410BF4800951227 /* ListOneColumnFullWidthTextBodyTextModel.swift in Sources */, AF60A7F82892D34D00919EEB /* ActionDismissNotificationHandler.swift in Sources */, @@ -3095,6 +3102,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/Miscellaneous/ListNotificationAuthModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Miscellaneous/ListNotificationAuthModel.swift new file mode 100644 index 00000000..4469d017 --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Miscellaneous/ListNotificationAuthModel.swift @@ -0,0 +1,69 @@ +// +// ListNotificationAuthModel.swift +// MVMCoreUI +// +// Created by Edayattu Salam, Nowfal on 13/04/23. +// Copyright © 2023 Verizon Wireless. All rights reserved. +// + +import Foundation + +public class ListNotificationAuthModel: ListOneColumnFullWidthTextAllTextAndLinksModel { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public class override var identifier: String { "listNotificationAuth" } + 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 { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + enableStatus = try typeContainer.decode(String.self, forKey: .enableStatus) + disableStatus = try typeContainer.decode(String.self, forKey: .disableStatus) + enableAction = try typeContainer.decodeModelIfPresent(codingKey: .enableAction) + disableAction = try typeContainer.decodeModelIfPresent(codingKey: .disableAction) + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(enableStatus, forKey: .enableStatus) + try container.encode(disableStatus, forKey: .disableStatus) + try container.encodeModelIfPresent(enableAction, forKey: .enableAction) + try container.encodeModelIfPresent(disableAction, forKey: .disableAction) + } +} + +extension ListNotificationAuthModel: PageBehaviorProtocolRequirer { + public func getRequiredBehaviors() -> [PageBehaviorModelProtocol] { + [GetNotificationAuthStatusBehaviorModel()] + } +} + +extension ListNotificationAuthModel: GetNotificationAuthStatusBehaviorConsumerProtocol { + 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/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift index de9ef49f..4e340ab6 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift @@ -235,7 +235,9 @@ extension Tabs: UICollectionViewDelegateFlowLayout { public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { guard let tabCell = cell as? TabItemCell else { return } if indexPath.row == selectedIndex { - moveSelectionLine(toIndex: indexPath, animated: false, cell: tabCell) + DispatchQueue.main.async { + self.moveSelectionLine(toIndex: indexPath, animated: false, cell: tabCell) + } } } diff --git a/MVMCoreUI/Behaviors/GetNotificationAuthStatusBehavior.swift b/MVMCoreUI/Behaviors/GetNotificationAuthStatusBehavior.swift new file mode 100644 index 00000000..78bb1129 --- /dev/null +++ b/MVMCoreUI/Behaviors/GetNotificationAuthStatusBehavior.swift @@ -0,0 +1,59 @@ +// +// GetNotificationAuthStatusBehavior.swift +// MVMCoreUI +// +// Created by Edayattu Salam, Nowfal on 13/04/23. +// Copyright © 2023 Verizon Wireless. All rights reserved. +// + +public protocol GetNotificationAuthStatusBehaviorConsumerProtocol { + func consume(notificationStatus: UNAuthorizationStatus) +} + +public class GetNotificationAuthStatusBehaviorModel: PageBehaviorModelProtocol { + public class var identifier: String { "notificationAuthStatus" } + public var shouldAllowMultipleInstances: Bool { false } + + public init() { } +} + +public class GetNotificationAuthStatusBehavior: PageVisibilityBehavior { + var delegate: MVMCoreUIDelegateObject? + + public required init(model: PageBehaviorModelProtocol, delegateObject: MVMCoreUIDelegateObject?) { + self.delegate = delegateObject + } + + public func onPageShown(_ delegateObject: MVMCoreUIDelegateObject?) { + // Get notification auth status + getNotificationStatus() + + NotificationCenter.default.addObserver(self, selector: #selector(onForeground), name: UIApplication.willEnterForegroundNotification, object: nil) + } + + @objc public func onForeground() { + // Get notification authorization status + getNotificationStatus() + } + + public func getNotificationStatus() { + guard let rootMolecules = self.delegate?.moleculeDelegate?.getRootMolecules() else { return } + let consumers: [GetNotificationAuthStatusBehaviorConsumerProtocol] = 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 680fc2e4..11108eeb 100644 --- a/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift +++ b/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift @@ -156,6 +156,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: ListNotificationAuthModel.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) @@ -225,6 +226,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: GetNotificationAuthStatusBehavior.self, for: GetNotificationAuthStatusBehaviorModel.self) } open override class func registerActions() { diff --git a/MVMCoreUI/Utility/MVMCoreUIUtility.m b/MVMCoreUI/Utility/MVMCoreUIUtility.m index 887d7438..01a8c435 100644 --- a/MVMCoreUI/Utility/MVMCoreUIUtility.m +++ b/MVMCoreUI/Utility/MVMCoreUIUtility.m @@ -150,8 +150,8 @@ if(mdn.length == LengthContactNumber) { NSMutableString * newmdn = [NSMutableString stringWithCapacity:14]; [newmdn appendString:mdn]; - [newmdn insertString:@"." atIndex:6]; - [newmdn insertString:@"." atIndex:3]; + [newmdn insertString:@"-" atIndex:6]; + [newmdn insertString:@"-" atIndex:3]; return newmdn; }