From d8acbec04615cb80f00d8215420f44630336e09f Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 17 Feb 2020 19:07:23 -0500 Subject: [PATCH 1/8] fixes --- .../MFViewController+Model.swift | 4 - MVMCoreUI/BaseControllers/MFViewController.h | 1 + MVMCoreUI/BaseControllers/MFViewController.m | 4 + .../TwoButtonViewModel.swift | 4 +- .../OtherHandlers/IsaacLandingTemplate.swift | 212 ++++++++++++++++++ .../Templates/IsaacLandingTemplate.swift | 192 ++++++++++++++++ .../Templates/MoleculeListTemplate.swift | 4 +- .../Templates/MoleculeStackTemplate.swift | 4 +- MVMCoreUI/Templates/ThreeLayerTemplate.swift | 5 +- 9 files changed, 418 insertions(+), 12 deletions(-) create mode 100644 MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift create mode 100644 MVMCoreUI/Templates/IsaacLandingTemplate.swift diff --git a/MVMCoreUI/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift index 1ddbd4ab..e70e68f6 100644 --- a/MVMCoreUI/BaseControllers/MFViewController+Model.swift +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -37,7 +37,3 @@ extension MFViewController: MoleculeDelegateProtocol { @objc public func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { } } - -public extension MFViewController { - @objc func parsePageJSON() throws { } -} diff --git a/MVMCoreUI/BaseControllers/MFViewController.h b/MVMCoreUI/BaseControllers/MFViewController.h index cd96a07f..ee38cf2b 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.h +++ b/MVMCoreUI/BaseControllers/MFViewController.h @@ -277,6 +277,7 @@ // subclass to set up intro animations - (void)setupIntroAnimations; +- (void)parsePageJSONAndReturnError:(NSError * _Nullable * _Nullable)error; @end diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 09700268..af2db33c 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -112,6 +112,10 @@ return [MFViewController verifyRequiredModulesLoadedForLoadObject:loadObject error:error]; } +- (void)parsePageJSONAndReturnError:(NSError * _Nullable * _Nullable)error { + +} + // Sets the screen to use the screen heading. // it is required in device flow, where we are showing greeting name as screen heading, // device details screen heading needs to be updated/refreshed again, if user has changed device nick name diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift index 057203e9..d4cba24c 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift @@ -22,8 +22,8 @@ public class TwoButtonViewModel: MoleculeModelProtocol { } public init(_ primaryButton: ButtonModel?, _ secondaryButton: ButtonModel?) { - self.primaryButton = primaryButton - self.secondaryButton = secondaryButton + self.primaryButton = primaryButton + self.secondaryButton = secondaryButton } required public init(from decoder: Decoder) throws { diff --git a/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift b/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift new file mode 100644 index 00000000..154cfdfd --- /dev/null +++ b/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift @@ -0,0 +1,212 @@ +// +// IsaacLandingTemplate.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 2/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation +import MVMCoreUI +import MVMCore + +open class IsaacLandingTemplate: MoleculeListTemplate { + + open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { + guard let pageJSON = self.loadObject?.pageJSON else { return } + + var listItems: [MoleculeListItemModel] = [] + (pageJSON.arrayForKey("items") as? [[AnyHashable: Any]])?.forEach { (itemJson) in + if let item = getListItem(itemJson) { + listItems.append(item) + } + } + + let template = ListPageTemplateModel(pageType: pageJSON.stringForkey(KeyPageType), + screenHeading: pageJSON.stringForkey(KeyScreenHeading), + molecules: listItems) + + let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" + template.footer = setFooter(pageJSON, template) + self.templateModel = template + + DispatchQueue.main.async { [weak self] in + self?.view.backgroundColor = UIColor.mfGet(forHex: backgroudColorString) + } + } +// public func parseTemplateJSON() throws { +// guard let pageJSON = self.loadObject?.pageJSON else { return } +// +// var listItems: [MoleculeListItemModel] = [] +// (pageJSON.arrayForKey("items") as? [[AnyHashable: Any]])?.forEach { (itemJson) in +// if let item = getListItem(itemJson) { +// listItems.append(item) +// } +// } +// +// let template = ListPageTemplateModel(pageType: pageJSON.stringForkey(KeyPageType), +// screenHeading: pageJSON.stringForkey(KeyScreenHeading), +// molecules: listItems) +// +// let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" +// template.footer = setFooter(pageJSON, template) +// self.templateModel = template +// +// DispatchQueue.main.async { [weak self] in +// self?.view.backgroundColor = UIColor.mfGet(forHex: backgroudColorString) +// } +// } + + func setFooter(_ pageJSON: [AnyHashable: Any], _ template: ListPageTemplateModel) -> FooterModel? { + + let primaryButtonBGColor = pageJSON.optionalStringForKey("primaryButtonBGColor") ?? "#FFFFFF" + let primaryButtonTextColor = pageJSON.optionalStringForKey("primaryButtonTextColor") ?? "#000000" + + let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" + if let buttonMap = pageJSON.optionalDictionaryForKey("ButtonMap") { + let twoButtonModel = TwoButtonViewModel(nil, nil) + + if let primarybutton = buttonMap.optionalDictionaryForKey(KeyPrimaryButton) { + let buttonDict: [String : Any] = ["title": primarybutton.stringForkey(KeyTitle), + "action": primarybutton, + "moleculeName": "button"] + if let data = try? JSONSerialization.data(withJSONObject: buttonDict) { + let decoder = JSONDecoder() + twoButtonModel.primaryButton = try? decoder.decode(ButtonModel.self, from: data) + twoButtonModel.primaryButton?.fillColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonBGColor)) + twoButtonModel.primaryButton?.textColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonTextColor)) + } + } + if let secondaryButton = buttonMap.optionalDictionaryForKey(KeySecondaryButton) { + let buttonDict: [String : Any] = ["title": secondaryButton.stringForkey(KeyTitle), + "action": secondaryButton, + "moleculeName": "button"] + if let data = try? JSONSerialization.data(withJSONObject: buttonDict) { + let decoder = JSONDecoder() + twoButtonModel.secondaryButton = try? decoder.decode(ButtonModel.self, from: data) + twoButtonModel.secondaryButton?.fillColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonTextColor)) + twoButtonModel.secondaryButton?.textColor = Color(uiColor: UIColor.mfGet(forHex:primaryButtonBGColor)) + } + } + + let footerStack = MoleculeStackModel(molecules: [MoleculeStackItemModel(with:LineModel(type: .standard)), + MoleculeStackItemModel(with: twoButtonModel)]) + footerStack.useHorizontalMargins = false + footerStack.spacing = PaddingFour + + let footer = FooterModel(with: footerStack) + footer.useHorizontalMargins = false + footer.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) + return footer + } + return nil + } + + func getListItem(_ moleculeJson: [AnyHashable: Any]) -> MoleculeListItemModel? { + guard let type = moleculeJson.optionalStringForKey("type") else { + return nil + } + + if type == "rewards" { + return getRewardListItem(moleculeJson) + } else { + return getTitleImageListItem(moleculeJson, type) + } + } + + func getTitleImageListItem(_ moleculeJson: [AnyHashable: Any], _ type: String) -> MoleculeListItemModel? { + let textcolor = moleculeJson.optionalStringForKey("textColor") + var stackItems: [MoleculeStackItemModel] = [] + + let titleLabel = LabelModel(text: moleculeJson.stringForkey(KeyTitle)) + titleLabel.fontName = "NHaasGroteskDSStd-75Bd" + titleLabel.textColor = textcolor + titleLabel.fontSize = (type == "topHeader") ? 70.0 : 25.0 + + let messageLabel = LabelModel(text: moleculeJson.stringForkey("message")) + messageLabel.fontStyle = "B2" + messageLabel.textColor = textcolor + + let headlineBodyModel = HeadlineBodyModel(headline: titleLabel) + headlineBodyModel.body = messageLabel + + if let linkMap = moleculeJson.optionalDictionaryForKey("link") { + do { + let linkDict: [String : Any] = ["title": linkMap.stringForkey(KeyTitle), + "action": linkMap] + let data = try JSONSerialization.data(withJSONObject: linkDict) + let decoder = JSONDecoder() + let linkModel = try decoder.decode(LinkModel.self, from: data) + linkModel.textColor = Color(uiColor: UIColor.mfGet(forHex: textcolor ?? "#FFFFFF")) + let headlineBodyLinkModel = HeadlineBodyLinkModel(headlineBody: headlineBodyModel, + link: linkModel) + stackItems.append(MoleculeStackItemModel(with: headlineBodyLinkModel)) + } catch { + stackItems.append(MoleculeStackItemModel(with: headlineBodyModel)) + } + } else { + stackItems.append(MoleculeStackItemModel(with: headlineBodyModel)) + } + + if let imageurl = moleculeJson.optionalStringForKey("imageUrl") { + let imageModel = ImageViewModel(image: imageurl) + imageModel.height = moleculeJson.optionalCGFloatForKey("imageHeight") ?? 300 + imageModel.imageFormat = "jpeg" + imageModel.contentMode = .scaleAspectFit + stackItems.append(MoleculeStackItemModel(with: imageModel)) + } + + let stack = MoleculeStackModel(molecules: stackItems) + let listItem = MoleculeListItemModel(with: stack) + + let backgroudColorString = moleculeJson.optionalStringForKey("backgroundColor") ?? "#000000" + listItem.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) + listItem.line = LineModel(type: .none) + return listItem + } + + func getRewardListItem(_ moleculeJson: [AnyHashable: Any]) -> MoleculeListItemModel? { + + var stackItems: [MoleculeStackItemModel] = [] + + (moleculeJson.arrayForKey("rewards") as? [[AnyHashable: Any]])?.forEach { (rewardItem) in + let textcolor = rewardItem.optionalStringForKey("textColor") + + let titleLabel = LabelModel(text: rewardItem.stringForkey(KeyTitle)) + titleLabel.fontName = "NHaasGroteskDSStd-75Bd" + titleLabel.textColor = textcolor + titleLabel.fontSize = 48 + + let messageLabel = LabelModel(text: rewardItem.stringForkey("message")) + messageLabel.fontName = "NHaasGroteskDSStd-75Bd" + messageLabel.textColor = textcolor + messageLabel.fontSize = 14 + + let titleStackItem = MoleculeStackItemModel(with: titleLabel) + let messageStackItem = MoleculeStackItemModel(with: messageLabel) + + let itemStack = MoleculeStackModel(molecules: [titleStackItem, messageStackItem]) + itemStack.verticalAlignment = .top + itemStack.spacing = 0 + + let horizontalStack = MoleculeStackItemModel(with: itemStack) + horizontalStack.verticalAlignment = .top + stackItems.append(horizontalStack) + } + + stackItems.first?.percent = 35 + stackItems.last?.percent = 65 + let stack = MoleculeStackModel(molecules: stackItems) + stack.axis = .horizontal + stack.horizontalAlignment = .leading + stack.verticalAlignment = .leading + + let listItem = MoleculeListItemModel(with: stack) + let backgroudColorString = moleculeJson.optionalStringForKey("backgroundColor") ?? "#000000" + listItem.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) + listItem.line = LineModel(type: .none) + + return listItem + } +} + diff --git a/MVMCoreUI/Templates/IsaacLandingTemplate.swift b/MVMCoreUI/Templates/IsaacLandingTemplate.swift new file mode 100644 index 00000000..909c9600 --- /dev/null +++ b/MVMCoreUI/Templates/IsaacLandingTemplate.swift @@ -0,0 +1,192 @@ + +// IsaacLandingTemplate.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 2/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation +import MVMCoreUI +import MVMCore + +open class IsaacLandingTemplate: MoleculeListTemplate { + + open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { + guard let pageJSON = self.loadObject?.pageJSON else { return } + + var listItems: [MoleculeListItemModel] = [] + (pageJSON.arrayForKey("items") as? [[AnyHashable: Any]])?.forEach { (itemJson) in + if let item = getListItem(itemJson) { + listItems.append(item) + } + } + + let template = ListPageTemplateModel(pageType: pageJSON.stringForkey(KeyPageType), + screenHeading: pageJSON.stringForkey(KeyScreenHeading), + molecules: listItems) + + let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" + template.footer = setFooter(pageJSON, template) + self.templateModel = template + + DispatchQueue.main.async { [weak self] in + self?.view.backgroundColor = UIColor.mfGet(forHex: backgroudColorString) + } + } + + + func setFooter(_ pageJSON: [AnyHashable: Any], _ template: ListPageTemplateModel) -> FooterModel? { + + let primaryButtonBGColor = pageJSON.optionalStringForKey("primaryButtonBGColor") ?? "#FFFFFF" + let primaryButtonTextColor = pageJSON.optionalStringForKey("primaryButtonTextColor") ?? "#000000" + + let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" + if let buttonMap = pageJSON.optionalDictionaryForKey("ButtonMap") { + let twoButtonModel = TwoButtonViewModel(nil, nil) + + if let primarybutton = buttonMap.optionalDictionaryForKey(KeyPrimaryButton) { + let buttonDict: [String : Any] = ["title": primarybutton.stringForkey(KeyTitle), + "action": primarybutton, + "moleculeName": "button"] + if let data = try? JSONSerialization.data(withJSONObject: buttonDict) { + let decoder = JSONDecoder() + twoButtonModel.primaryButton = try? decoder.decode(ButtonModel.self, from: data) + twoButtonModel.primaryButton?.fillColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonBGColor)) + twoButtonModel.primaryButton?.textColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonTextColor)) + } + } + if let secondaryButton = buttonMap.optionalDictionaryForKey(KeySecondaryButton) { + let buttonDict: [String : Any] = ["title": secondaryButton.stringForkey(KeyTitle), + "action": secondaryButton, + "moleculeName": "button"] + if let data = try? JSONSerialization.data(withJSONObject: buttonDict) { + let decoder = JSONDecoder() + twoButtonModel.secondaryButton = try? decoder.decode(ButtonModel.self, from: data) + twoButtonModel.secondaryButton?.fillColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonTextColor)) + twoButtonModel.secondaryButton?.textColor = Color(uiColor: UIColor.mfGet(forHex:primaryButtonBGColor)) + } + } + + let footerStack = MoleculeStackModel(molecules: [MoleculeStackItemModel(with:LineModel(type: .standard)), + MoleculeStackItemModel(with: twoButtonModel)]) + footerStack.useHorizontalMargins = false + footerStack.spacing = PaddingFour + + let footer = FooterModel(with: footerStack) + footer.useHorizontalMargins = false + footer.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) + return footer + } + return nil + } + + func getListItem(_ moleculeJson: [AnyHashable: Any]) -> MoleculeListItemModel? { + guard let type = moleculeJson.optionalStringForKey("type") else { + return nil + } + + if type == "rewards" { + return getRewardListItem(moleculeJson) + } else { + return getTitleImageListItem(moleculeJson, type) + } + } + + func getTitleImageListItem(_ moleculeJson: [AnyHashable: Any], _ type: String) -> MoleculeListItemModel? { + let textcolor = moleculeJson.optionalStringForKey("textColor") + var stackItems: [MoleculeStackItemModel] = [] + + let titleLabel = LabelModel(text: moleculeJson.stringForkey(KeyTitle)) + titleLabel.fontName = "NHaasGroteskDSStd-75Bd" + titleLabel.textColor = textcolor + titleLabel.fontSize = (type == "topHeader") ? 70.0 : 25.0 + + let messageLabel = LabelModel(text: moleculeJson.stringForkey("message")) + messageLabel.fontStyle = "B2" + messageLabel.textColor = textcolor + + let headlineBodyModel = HeadlineBodyModel(headline: titleLabel) + headlineBodyModel.body = messageLabel + + if let linkMap = moleculeJson.optionalDictionaryForKey("link") { + do { + let linkDict: [String : Any] = ["title": linkMap.stringForkey(KeyTitle), + "action": linkMap] + let data = try JSONSerialization.data(withJSONObject: linkDict) + let decoder = JSONDecoder() + let linkModel = try decoder.decode(LinkModel.self, from: data) + linkModel.textColor = Color(uiColor: UIColor.mfGet(forHex: textcolor ?? "#FFFFFF")) + let headlineBodyLinkModel = HeadlineBodyLinkModel(headlineBody: headlineBodyModel, + link: linkModel) + stackItems.append(MoleculeStackItemModel(with: headlineBodyLinkModel)) + } catch { + stackItems.append(MoleculeStackItemModel(with: headlineBodyModel)) + } + } else { + stackItems.append(MoleculeStackItemModel(with: headlineBodyModel)) + } + + if let imageurl = moleculeJson.optionalStringForKey("imageUrl") { + let imageModel = ImageViewModel(image: imageurl) + imageModel.height = moleculeJson.optionalCGFloatForKey("imageHeight") ?? 300 + imageModel.imageFormat = "jpeg" + imageModel.contentMode = .scaleAspectFit + stackItems.append(MoleculeStackItemModel(with: imageModel)) + } + + let stack = MoleculeStackModel(molecules: stackItems) + let listItem = MoleculeListItemModel(with: stack) + + let backgroudColorString = moleculeJson.optionalStringForKey("backgroundColor") ?? "#000000" + listItem.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) + listItem.line = LineModel(type: .none) + return listItem + } + + func getRewardListItem(_ moleculeJson: [AnyHashable: Any]) -> MoleculeListItemModel? { + + var stackItems: [MoleculeStackItemModel] = [] + + (moleculeJson.arrayForKey("rewards") as? [[AnyHashable: Any]])?.forEach { (rewardItem) in + let textcolor = rewardItem.optionalStringForKey("textColor") + + let titleLabel = LabelModel(text: rewardItem.stringForkey(KeyTitle)) + titleLabel.fontName = "NHaasGroteskDSStd-75Bd" + titleLabel.textColor = textcolor + titleLabel.fontSize = 48 + + let messageLabel = LabelModel(text: rewardItem.stringForkey("message")) + messageLabel.fontName = "NHaasGroteskDSStd-75Bd" + messageLabel.textColor = textcolor + messageLabel.fontSize = 14 + + let titleStackItem = MoleculeStackItemModel(with: titleLabel) + let messageStackItem = MoleculeStackItemModel(with: messageLabel) + + let itemStack = MoleculeStackModel(molecules: [titleStackItem, messageStackItem]) + itemStack.verticalAlignment = .top + itemStack.spacing = 0 + + let horizontalStack = MoleculeStackItemModel(with: itemStack) + horizontalStack.verticalAlignment = .top + stackItems.append(horizontalStack) + } + + stackItems.first?.percent = 35 + stackItems.last?.percent = 65 + let stack = MoleculeStackModel(molecules: stackItems) + stack.axis = .horizontal + stack.horizontalAlignment = .leading + stack.verticalAlignment = .leading + + let listItem = MoleculeListItemModel(with: stack) + let backgroudColorString = moleculeJson.optionalStringForKey("backgroundColor") ?? "#000000" + listItem.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) + listItem.line = LineModel(type: .none) + + return listItem + } +} + + diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 01d0a5e6..291a6a27 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -23,8 +23,8 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol // MARK: - Computed Properties //-------------------------------------------------- - @objc public override func parsePageJSON() throws { - try parseTemplateJSON() + open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { + try? parseTemplateJSON() } open override var loadObject: MVMCoreLoadObject? { diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index 03d21c6b..b3fb4c3a 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -12,8 +12,8 @@ open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { var observer: NSKeyValueObservation? public var templateModel: StackPageTemplateModel? - public override func parsePageJSON() throws { - try parseTemplateJSON() + open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { + try? parseTemplateJSON() } open override var loadObject: MVMCoreLoadObject? { diff --git a/MVMCoreUI/Templates/ThreeLayerTemplate.swift b/MVMCoreUI/Templates/ThreeLayerTemplate.swift index 785d1055..8d4f7169 100644 --- a/MVMCoreUI/Templates/ThreeLayerTemplate.swift +++ b/MVMCoreUI/Templates/ThreeLayerTemplate.swift @@ -11,8 +11,9 @@ import UIKit @objcMembers open class ThreeLayerTemplate: ThreeLayerViewController, TemplateProtocol { public var templateModel: ThreeLayerPageTemplateModel? - @objc public override func parsePageJSON() throws { - try parseTemplateJSON() + + open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { + try? parseTemplateJSON() } override open func viewDidLoad() { From a2700e81b4e612d0c5012ad6fb1c5d33d5788147 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 17 Feb 2020 21:54:47 -0500 Subject: [PATCH 2/8] remove file --- .../OtherHandlers/IsaacLandingTemplate.swift | 52 ++--- .../Templates/IsaacLandingTemplate.swift | 192 ------------------ 2 files changed, 15 insertions(+), 229 deletions(-) delete mode 100644 MVMCoreUI/Templates/IsaacLandingTemplate.swift diff --git a/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift b/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift index 154cfdfd..8068cdc4 100644 --- a/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift +++ b/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift @@ -15,47 +15,25 @@ open class IsaacLandingTemplate: MoleculeListTemplate { open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { guard let pageJSON = self.loadObject?.pageJSON else { return } - var listItems: [MoleculeListItemModel] = [] - (pageJSON.arrayForKey("items") as? [[AnyHashable: Any]])?.forEach { (itemJson) in - if let item = getListItem(itemJson) { - listItems.append(item) - } - } + var listItems: [MoleculeListItemModel] = [] + (pageJSON.arrayForKey("items") as? [[AnyHashable: Any]])?.forEach { (itemJson) in + if let item = getListItem(itemJson) { + listItems.append(item) + } + } - let template = ListPageTemplateModel(pageType: pageJSON.stringForkey(KeyPageType), - screenHeading: pageJSON.stringForkey(KeyScreenHeading), - molecules: listItems) + let template = ListPageTemplateModel(pageType: pageJSON.stringForkey(KeyPageType), + screenHeading: pageJSON.stringForkey(KeyScreenHeading), + molecules: listItems) - let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" - template.footer = setFooter(pageJSON, template) - self.templateModel = template + let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" + template.footer = setFooter(pageJSON, template) + self.templateModel = template - DispatchQueue.main.async { [weak self] in - self?.view.backgroundColor = UIColor.mfGet(forHex: backgroudColorString) - } + DispatchQueue.main.async { [weak self] in + self?.view.backgroundColor = UIColor.mfGet(forHex: backgroudColorString) + } } -// public func parseTemplateJSON() throws { -// guard let pageJSON = self.loadObject?.pageJSON else { return } -// -// var listItems: [MoleculeListItemModel] = [] -// (pageJSON.arrayForKey("items") as? [[AnyHashable: Any]])?.forEach { (itemJson) in -// if let item = getListItem(itemJson) { -// listItems.append(item) -// } -// } -// -// let template = ListPageTemplateModel(pageType: pageJSON.stringForkey(KeyPageType), -// screenHeading: pageJSON.stringForkey(KeyScreenHeading), -// molecules: listItems) -// -// let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" -// template.footer = setFooter(pageJSON, template) -// self.templateModel = template -// -// DispatchQueue.main.async { [weak self] in -// self?.view.backgroundColor = UIColor.mfGet(forHex: backgroudColorString) -// } -// } func setFooter(_ pageJSON: [AnyHashable: Any], _ template: ListPageTemplateModel) -> FooterModel? { diff --git a/MVMCoreUI/Templates/IsaacLandingTemplate.swift b/MVMCoreUI/Templates/IsaacLandingTemplate.swift deleted file mode 100644 index 909c9600..00000000 --- a/MVMCoreUI/Templates/IsaacLandingTemplate.swift +++ /dev/null @@ -1,192 +0,0 @@ - -// IsaacLandingTemplate.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 2/13/20. -// Copyright © 2020 Verizon Wireless. All rights reserved. -// - -import Foundation -import MVMCoreUI -import MVMCore - -open class IsaacLandingTemplate: MoleculeListTemplate { - - open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { - guard let pageJSON = self.loadObject?.pageJSON else { return } - - var listItems: [MoleculeListItemModel] = [] - (pageJSON.arrayForKey("items") as? [[AnyHashable: Any]])?.forEach { (itemJson) in - if let item = getListItem(itemJson) { - listItems.append(item) - } - } - - let template = ListPageTemplateModel(pageType: pageJSON.stringForkey(KeyPageType), - screenHeading: pageJSON.stringForkey(KeyScreenHeading), - molecules: listItems) - - let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" - template.footer = setFooter(pageJSON, template) - self.templateModel = template - - DispatchQueue.main.async { [weak self] in - self?.view.backgroundColor = UIColor.mfGet(forHex: backgroudColorString) - } - } - - - func setFooter(_ pageJSON: [AnyHashable: Any], _ template: ListPageTemplateModel) -> FooterModel? { - - let primaryButtonBGColor = pageJSON.optionalStringForKey("primaryButtonBGColor") ?? "#FFFFFF" - let primaryButtonTextColor = pageJSON.optionalStringForKey("primaryButtonTextColor") ?? "#000000" - - let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" - if let buttonMap = pageJSON.optionalDictionaryForKey("ButtonMap") { - let twoButtonModel = TwoButtonViewModel(nil, nil) - - if let primarybutton = buttonMap.optionalDictionaryForKey(KeyPrimaryButton) { - let buttonDict: [String : Any] = ["title": primarybutton.stringForkey(KeyTitle), - "action": primarybutton, - "moleculeName": "button"] - if let data = try? JSONSerialization.data(withJSONObject: buttonDict) { - let decoder = JSONDecoder() - twoButtonModel.primaryButton = try? decoder.decode(ButtonModel.self, from: data) - twoButtonModel.primaryButton?.fillColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonBGColor)) - twoButtonModel.primaryButton?.textColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonTextColor)) - } - } - if let secondaryButton = buttonMap.optionalDictionaryForKey(KeySecondaryButton) { - let buttonDict: [String : Any] = ["title": secondaryButton.stringForkey(KeyTitle), - "action": secondaryButton, - "moleculeName": "button"] - if let data = try? JSONSerialization.data(withJSONObject: buttonDict) { - let decoder = JSONDecoder() - twoButtonModel.secondaryButton = try? decoder.decode(ButtonModel.self, from: data) - twoButtonModel.secondaryButton?.fillColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonTextColor)) - twoButtonModel.secondaryButton?.textColor = Color(uiColor: UIColor.mfGet(forHex:primaryButtonBGColor)) - } - } - - let footerStack = MoleculeStackModel(molecules: [MoleculeStackItemModel(with:LineModel(type: .standard)), - MoleculeStackItemModel(with: twoButtonModel)]) - footerStack.useHorizontalMargins = false - footerStack.spacing = PaddingFour - - let footer = FooterModel(with: footerStack) - footer.useHorizontalMargins = false - footer.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) - return footer - } - return nil - } - - func getListItem(_ moleculeJson: [AnyHashable: Any]) -> MoleculeListItemModel? { - guard let type = moleculeJson.optionalStringForKey("type") else { - return nil - } - - if type == "rewards" { - return getRewardListItem(moleculeJson) - } else { - return getTitleImageListItem(moleculeJson, type) - } - } - - func getTitleImageListItem(_ moleculeJson: [AnyHashable: Any], _ type: String) -> MoleculeListItemModel? { - let textcolor = moleculeJson.optionalStringForKey("textColor") - var stackItems: [MoleculeStackItemModel] = [] - - let titleLabel = LabelModel(text: moleculeJson.stringForkey(KeyTitle)) - titleLabel.fontName = "NHaasGroteskDSStd-75Bd" - titleLabel.textColor = textcolor - titleLabel.fontSize = (type == "topHeader") ? 70.0 : 25.0 - - let messageLabel = LabelModel(text: moleculeJson.stringForkey("message")) - messageLabel.fontStyle = "B2" - messageLabel.textColor = textcolor - - let headlineBodyModel = HeadlineBodyModel(headline: titleLabel) - headlineBodyModel.body = messageLabel - - if let linkMap = moleculeJson.optionalDictionaryForKey("link") { - do { - let linkDict: [String : Any] = ["title": linkMap.stringForkey(KeyTitle), - "action": linkMap] - let data = try JSONSerialization.data(withJSONObject: linkDict) - let decoder = JSONDecoder() - let linkModel = try decoder.decode(LinkModel.self, from: data) - linkModel.textColor = Color(uiColor: UIColor.mfGet(forHex: textcolor ?? "#FFFFFF")) - let headlineBodyLinkModel = HeadlineBodyLinkModel(headlineBody: headlineBodyModel, - link: linkModel) - stackItems.append(MoleculeStackItemModel(with: headlineBodyLinkModel)) - } catch { - stackItems.append(MoleculeStackItemModel(with: headlineBodyModel)) - } - } else { - stackItems.append(MoleculeStackItemModel(with: headlineBodyModel)) - } - - if let imageurl = moleculeJson.optionalStringForKey("imageUrl") { - let imageModel = ImageViewModel(image: imageurl) - imageModel.height = moleculeJson.optionalCGFloatForKey("imageHeight") ?? 300 - imageModel.imageFormat = "jpeg" - imageModel.contentMode = .scaleAspectFit - stackItems.append(MoleculeStackItemModel(with: imageModel)) - } - - let stack = MoleculeStackModel(molecules: stackItems) - let listItem = MoleculeListItemModel(with: stack) - - let backgroudColorString = moleculeJson.optionalStringForKey("backgroundColor") ?? "#000000" - listItem.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) - listItem.line = LineModel(type: .none) - return listItem - } - - func getRewardListItem(_ moleculeJson: [AnyHashable: Any]) -> MoleculeListItemModel? { - - var stackItems: [MoleculeStackItemModel] = [] - - (moleculeJson.arrayForKey("rewards") as? [[AnyHashable: Any]])?.forEach { (rewardItem) in - let textcolor = rewardItem.optionalStringForKey("textColor") - - let titleLabel = LabelModel(text: rewardItem.stringForkey(KeyTitle)) - titleLabel.fontName = "NHaasGroteskDSStd-75Bd" - titleLabel.textColor = textcolor - titleLabel.fontSize = 48 - - let messageLabel = LabelModel(text: rewardItem.stringForkey("message")) - messageLabel.fontName = "NHaasGroteskDSStd-75Bd" - messageLabel.textColor = textcolor - messageLabel.fontSize = 14 - - let titleStackItem = MoleculeStackItemModel(with: titleLabel) - let messageStackItem = MoleculeStackItemModel(with: messageLabel) - - let itemStack = MoleculeStackModel(molecules: [titleStackItem, messageStackItem]) - itemStack.verticalAlignment = .top - itemStack.spacing = 0 - - let horizontalStack = MoleculeStackItemModel(with: itemStack) - horizontalStack.verticalAlignment = .top - stackItems.append(horizontalStack) - } - - stackItems.first?.percent = 35 - stackItems.last?.percent = 65 - let stack = MoleculeStackModel(molecules: stackItems) - stack.axis = .horizontal - stack.horizontalAlignment = .leading - stack.verticalAlignment = .leading - - let listItem = MoleculeListItemModel(with: stack) - let backgroudColorString = moleculeJson.optionalStringForKey("backgroundColor") ?? "#000000" - listItem.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) - listItem.line = LineModel(type: .none) - - return listItem - } -} - - From e2860efaf6d6ab41789bbd209f4f24bccdb44eb4 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 17 Feb 2020 22:28:09 -0500 Subject: [PATCH 3/8] fixes --- MVMCoreUI/BaseControllers/MFViewController.h | 2 +- MVMCoreUI/BaseControllers/MFViewController.m | 6 +++--- MVMCoreUI/Templates/MoleculeListTemplate.swift | 2 +- MVMCoreUI/Templates/MoleculeStackTemplate.swift | 2 +- MVMCoreUI/Templates/ThreeLayerTemplate.swift | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController.h b/MVMCoreUI/BaseControllers/MFViewController.h index ee38cf2b..11afe915 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.h +++ b/MVMCoreUI/BaseControllers/MFViewController.h @@ -277,7 +277,7 @@ // subclass to set up intro animations - (void)setupIntroAnimations; -- (void)parsePageJSONAndReturnError:(NSError * _Nullable * _Nullable)error; +- (void)parsePageJSON:(NSError * _Nullable * _Nullable)error; @end diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index af2db33c..f663193f 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -98,7 +98,7 @@ self.loadObject = loadObject; NSError *parseError = nil; - [self parsePageJSONAndReturnError:&parseError]; + [self parsePageJSON:&parseError]; if (parseError) { if (error) { MVMCoreErrorObject *errorObject = [MVMCoreErrorObject createErrorObjectForNSError:parseError location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; @@ -112,7 +112,7 @@ return [MFViewController verifyRequiredModulesLoadedForLoadObject:loadObject error:error]; } -- (void)parsePageJSONAndReturnError:(NSError * _Nullable * _Nullable)error { +- (void)parsePageJSON:(NSError * _Nullable * _Nullable)error { } @@ -265,7 +265,7 @@ - (BOOL)newPageLoaded:(nonnull NSDictionary *)page { self.loadObject.pageJSON = page; NSError *parseError = nil; - [self parsePageJSONAndReturnError:&parseError]; + [self parsePageJSON:&parseError]; return YES; } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 291a6a27..cbe0458c 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -23,7 +23,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol // MARK: - Computed Properties //-------------------------------------------------- - open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { + open override func parsePageJSON(_ error: NSErrorPointer) { try? parseTemplateJSON() } diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index b3fb4c3a..8bf0b4cd 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -12,7 +12,7 @@ open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { var observer: NSKeyValueObservation? public var templateModel: StackPageTemplateModel? - open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { + open override func parsePageJSON(_ error: NSErrorPointer) { try? parseTemplateJSON() } diff --git a/MVMCoreUI/Templates/ThreeLayerTemplate.swift b/MVMCoreUI/Templates/ThreeLayerTemplate.swift index 8d4f7169..72498289 100644 --- a/MVMCoreUI/Templates/ThreeLayerTemplate.swift +++ b/MVMCoreUI/Templates/ThreeLayerTemplate.swift @@ -12,7 +12,7 @@ import UIKit public var templateModel: ThreeLayerPageTemplateModel? - open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { + open override func parsePageJSON(_ error: NSErrorPointer) { try? parseTemplateJSON() } From a29b4b17a0d6b2769fd0238a21e679a084b36007 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Tue, 18 Feb 2020 09:48:58 -0500 Subject: [PATCH 4/8] add toggle for server s7 params --- MVMCoreUI/Atoms/Views/MFLoadImageView.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 5e8cedc8..fa7d369e 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -273,7 +273,9 @@ import UIKit } // MARK: - load functions - public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?, completionHandler: @escaping MVMCoreGetImageBlock) { + public func loadImage(withName imageName: String?, format: String? = nil, width: NSNumber? = nil, height: NSNumber? = nil, customFallbackImage: String? = nil, allowServerParameters: Bool = false, completionHandler: MVMCoreGetImageBlock? = nil) { + + let completionBlock = completionHandler ?? defaultCompletionBlock() MVMCoreDispatchUtility.performBlock(onMainThread: { [unowned self] in self.currentImageName = imageName self.currentImageWidth = width?.cgfloat() @@ -295,15 +297,15 @@ import UIKit if layoutWillChange { self?.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self!) } - completionHandler(image,data,isFallbackImage) + completionBlock(image,data,isFallbackImage) })} let fallbackImageName = customFallbackImage ?? MVMCoreUIUtility.localizedImageName("fallback") if let format = format, format.lowercased().contains("gif") { // Gifs aren't supported by default and need special handling - MVMCoreCache.shared()?.getGif(imageName, useWidth: width != nil, widthForS7: width?.intValue ?? 0, useHeight: height != nil, heightForS7: height?.intValue ?? 0, format: format, localFallbackImageName: fallbackImageName, completionHandler: finishedLoadingBlock) + MVMCoreCache.shared()?.getGif(imageName, useWidth: width != nil, widthForS7: width?.intValue ?? 0, useHeight: height != nil, heightForS7: height?.intValue ?? 0, format: format, localFallbackImageName: fallbackImageName, allowServerQueryParameters: allowServerParameters, completionHandler: finishedLoadingBlock) } else { - MVMCoreCache.shared()?.getImage(imageName, useWidth: width != nil, widthForS7: width?.intValue ?? 0, useHeight: height != nil, heightForS7: height?.intValue ?? 0, format: format, localFallbackImageName: fallbackImageName, completionHandler: finishedLoadingBlock) + MVMCoreCache.shared()?.getImage(imageName, useWidth: width != nil, widthForS7: width?.intValue ?? 0, useHeight: height != nil, heightForS7: height?.intValue ?? 0, format: format, localFallbackImageName: fallbackImageName, allowServerQueryParameters: allowServerParameters, completionHandler: finishedLoadingBlock) } }) } @@ -333,6 +335,8 @@ import UIKit }) } + // Note: Exposed for objective-c interfaces. + public func loadImage(withName imageName: String?) { loadImage(withName: imageName, format: nil, width: nil, height: nil, customFallbackImage: nil, completionHandler: defaultCompletionBlock()) } @@ -368,4 +372,8 @@ import UIKit public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?) { loadImage(withName: imageName, format: format, width: width, height: height, customFallbackImage: customFallbackImage, completionHandler: defaultCompletionBlock()) } + + public func loadImage(withName imageName: String?, format: String?, width: NSNumber?, height: NSNumber?, customFallbackImage: String?, completionHandler: @escaping MVMCoreGetImageBlock) { + loadImage(withName: imageName, format: format, width: width, height: height, customFallbackImage: customFallbackImage, allowServerParameters: false, completionHandler: completionHandler) + } } From ff0758106ef6cde410c7f5d104acd5e2331e9d95 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 18 Feb 2020 12:31:55 -0500 Subject: [PATCH 5/8] init --- .../Atoms/Views/Label/LabelAttributeActionModel.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift b/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift index 2ebcb4b4..135fee45 100644 --- a/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift +++ b/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift @@ -8,12 +8,17 @@ import UIKit -class LabelAttributeActionModel: LabelAttributeModel { +open class LabelAttributeActionModel: LabelAttributeModel { override public class var identifier: String { return "action" } var action: ActionModelProtocol + public init(_ location: Int, _ length: Int, action: ActionModelProtocol) { + self.action = action + super.init(Self.identifier, location, length) + } + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) From db8a27ec2fc44bffa209d66bf699d5c31d1b1d6a Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 18 Feb 2020 14:29:35 -0500 Subject: [PATCH 6/8] update to label attributes --- .../Atoms/Views/Label/LabelAttributeActionModel.swift | 10 +++++----- MVMCoreUI/Atoms/Views/Label/LabelAttributeModel.swift | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift b/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift index 135fee45..503f00d8 100644 --- a/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift +++ b/MVMCoreUI/Atoms/Views/Label/LabelAttributeActionModel.swift @@ -16,7 +16,11 @@ open class LabelAttributeActionModel: LabelAttributeModel { public init(_ location: Int, _ length: Int, action: ActionModelProtocol) { self.action = action - super.init(Self.identifier, location, length) + super.init(location, length) + } + + private enum CodingKeys: String, CodingKey { + case action } required public init(from decoder: Decoder) throws { @@ -30,8 +34,4 @@ open class LabelAttributeActionModel: LabelAttributeModel { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeModel(action, forKey: .action) } - - private enum CodingKeys: String, CodingKey { - case action - } } diff --git a/MVMCoreUI/Atoms/Views/Label/LabelAttributeModel.swift b/MVMCoreUI/Atoms/Views/Label/LabelAttributeModel.swift index 3c073b2f..437ec0cc 100644 --- a/MVMCoreUI/Atoms/Views/Label/LabelAttributeModel.swift +++ b/MVMCoreUI/Atoms/Views/Label/LabelAttributeModel.swift @@ -25,12 +25,14 @@ import Foundation return "" } - var type: String + var type: String { + get { return Self.identifier } + } + var location: Int var length: Int - init(_ type: String, _ location: Int, _ length: Int) { - self.type = type + init(_ location: Int, _ length: Int) { self.location = location self.length = length } @@ -51,7 +53,6 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - type = try typeContainer.decode(String.self, forKey: .type) location = try typeContainer.decode(Int.self, forKey: .location) length = try typeContainer.decode(Int.self, forKey: .length) } From a620dd2401d3e03cabf646271972ec71cf44f6f0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 18 Feb 2020 14:59:17 -0500 Subject: [PATCH 7/8] some fixes for catching and remove file --- MVMCoreUI/BaseControllers/MFViewController.h | 4 +- .../TwoButtonViewModel.swift | 4 +- .../OtherHandlers/IsaacLandingTemplate.swift | 190 ------------------ .../Templates/MoleculeListTemplate.swift | 6 +- .../Templates/MoleculeStackTemplate.swift | 6 +- MVMCoreUI/Templates/ThreeLayerTemplate.swift | 6 +- 6 files changed, 20 insertions(+), 196 deletions(-) delete mode 100644 MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift diff --git a/MVMCoreUI/BaseControllers/MFViewController.h b/MVMCoreUI/BaseControllers/MFViewController.h index 11afe915..38ced354 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.h +++ b/MVMCoreUI/BaseControllers/MFViewController.h @@ -96,6 +96,9 @@ // This view controller should subclass this function and check the load to make sure it has all the needed data. Fills the error object if there are any errors. Returns if we should finish the load or not. - (BOOL)shouldFinishProcessingLoad:(nonnull MVMCoreLoadObject *)loadObject error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error; +/// Called in newDataBuildScreen. Can override to parse the json into a model object. +- (void)parsePageJSON:(NSError * _Nullable * _Nullable)error; + // Sets the screen to use the screen heading. // it is required in device flow, where we are showing greeting name as screen heading, // device details screen heading needs to be updated/refreshed again, if user has changed device nick name @@ -277,7 +280,6 @@ // subclass to set up intro animations - (void)setupIntroAnimations; -- (void)parsePageJSON:(NSError * _Nullable * _Nullable)error; @end diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift index d4cba24c..057203e9 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift @@ -22,8 +22,8 @@ public class TwoButtonViewModel: MoleculeModelProtocol { } public init(_ primaryButton: ButtonModel?, _ secondaryButton: ButtonModel?) { - self.primaryButton = primaryButton - self.secondaryButton = secondaryButton + self.primaryButton = primaryButton + self.secondaryButton = secondaryButton } required public init(from decoder: Decoder) throws { diff --git a/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift b/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift deleted file mode 100644 index 8068cdc4..00000000 --- a/MVMCoreUI/OtherHandlers/IsaacLandingTemplate.swift +++ /dev/null @@ -1,190 +0,0 @@ -// -// IsaacLandingTemplate.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 2/13/20. -// Copyright © 2020 Verizon Wireless. All rights reserved. -// - -import Foundation -import MVMCoreUI -import MVMCore - -open class IsaacLandingTemplate: MoleculeListTemplate { - - open override func parsePageJSONAndReturnError(_ error: NSErrorPointer) { - guard let pageJSON = self.loadObject?.pageJSON else { return } - - var listItems: [MoleculeListItemModel] = [] - (pageJSON.arrayForKey("items") as? [[AnyHashable: Any]])?.forEach { (itemJson) in - if let item = getListItem(itemJson) { - listItems.append(item) - } - } - - let template = ListPageTemplateModel(pageType: pageJSON.stringForkey(KeyPageType), - screenHeading: pageJSON.stringForkey(KeyScreenHeading), - molecules: listItems) - - let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" - template.footer = setFooter(pageJSON, template) - self.templateModel = template - - DispatchQueue.main.async { [weak self] in - self?.view.backgroundColor = UIColor.mfGet(forHex: backgroudColorString) - } - } - - func setFooter(_ pageJSON: [AnyHashable: Any], _ template: ListPageTemplateModel) -> FooterModel? { - - let primaryButtonBGColor = pageJSON.optionalStringForKey("primaryButtonBGColor") ?? "#FFFFFF" - let primaryButtonTextColor = pageJSON.optionalStringForKey("primaryButtonTextColor") ?? "#000000" - - let backgroudColorString = pageJSON.optionalStringForKey("backgroundColor") ?? "#000000" - if let buttonMap = pageJSON.optionalDictionaryForKey("ButtonMap") { - let twoButtonModel = TwoButtonViewModel(nil, nil) - - if let primarybutton = buttonMap.optionalDictionaryForKey(KeyPrimaryButton) { - let buttonDict: [String : Any] = ["title": primarybutton.stringForkey(KeyTitle), - "action": primarybutton, - "moleculeName": "button"] - if let data = try? JSONSerialization.data(withJSONObject: buttonDict) { - let decoder = JSONDecoder() - twoButtonModel.primaryButton = try? decoder.decode(ButtonModel.self, from: data) - twoButtonModel.primaryButton?.fillColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonBGColor)) - twoButtonModel.primaryButton?.textColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonTextColor)) - } - } - if let secondaryButton = buttonMap.optionalDictionaryForKey(KeySecondaryButton) { - let buttonDict: [String : Any] = ["title": secondaryButton.stringForkey(KeyTitle), - "action": secondaryButton, - "moleculeName": "button"] - if let data = try? JSONSerialization.data(withJSONObject: buttonDict) { - let decoder = JSONDecoder() - twoButtonModel.secondaryButton = try? decoder.decode(ButtonModel.self, from: data) - twoButtonModel.secondaryButton?.fillColor = Color(uiColor: UIColor.mfGet(forHex: primaryButtonTextColor)) - twoButtonModel.secondaryButton?.textColor = Color(uiColor: UIColor.mfGet(forHex:primaryButtonBGColor)) - } - } - - let footerStack = MoleculeStackModel(molecules: [MoleculeStackItemModel(with:LineModel(type: .standard)), - MoleculeStackItemModel(with: twoButtonModel)]) - footerStack.useHorizontalMargins = false - footerStack.spacing = PaddingFour - - let footer = FooterModel(with: footerStack) - footer.useHorizontalMargins = false - footer.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) - return footer - } - return nil - } - - func getListItem(_ moleculeJson: [AnyHashable: Any]) -> MoleculeListItemModel? { - guard let type = moleculeJson.optionalStringForKey("type") else { - return nil - } - - if type == "rewards" { - return getRewardListItem(moleculeJson) - } else { - return getTitleImageListItem(moleculeJson, type) - } - } - - func getTitleImageListItem(_ moleculeJson: [AnyHashable: Any], _ type: String) -> MoleculeListItemModel? { - let textcolor = moleculeJson.optionalStringForKey("textColor") - var stackItems: [MoleculeStackItemModel] = [] - - let titleLabel = LabelModel(text: moleculeJson.stringForkey(KeyTitle)) - titleLabel.fontName = "NHaasGroteskDSStd-75Bd" - titleLabel.textColor = textcolor - titleLabel.fontSize = (type == "topHeader") ? 70.0 : 25.0 - - let messageLabel = LabelModel(text: moleculeJson.stringForkey("message")) - messageLabel.fontStyle = "B2" - messageLabel.textColor = textcolor - - let headlineBodyModel = HeadlineBodyModel(headline: titleLabel) - headlineBodyModel.body = messageLabel - - if let linkMap = moleculeJson.optionalDictionaryForKey("link") { - do { - let linkDict: [String : Any] = ["title": linkMap.stringForkey(KeyTitle), - "action": linkMap] - let data = try JSONSerialization.data(withJSONObject: linkDict) - let decoder = JSONDecoder() - let linkModel = try decoder.decode(LinkModel.self, from: data) - linkModel.textColor = Color(uiColor: UIColor.mfGet(forHex: textcolor ?? "#FFFFFF")) - let headlineBodyLinkModel = HeadlineBodyLinkModel(headlineBody: headlineBodyModel, - link: linkModel) - stackItems.append(MoleculeStackItemModel(with: headlineBodyLinkModel)) - } catch { - stackItems.append(MoleculeStackItemModel(with: headlineBodyModel)) - } - } else { - stackItems.append(MoleculeStackItemModel(with: headlineBodyModel)) - } - - if let imageurl = moleculeJson.optionalStringForKey("imageUrl") { - let imageModel = ImageViewModel(image: imageurl) - imageModel.height = moleculeJson.optionalCGFloatForKey("imageHeight") ?? 300 - imageModel.imageFormat = "jpeg" - imageModel.contentMode = .scaleAspectFit - stackItems.append(MoleculeStackItemModel(with: imageModel)) - } - - let stack = MoleculeStackModel(molecules: stackItems) - let listItem = MoleculeListItemModel(with: stack) - - let backgroudColorString = moleculeJson.optionalStringForKey("backgroundColor") ?? "#000000" - listItem.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) - listItem.line = LineModel(type: .none) - return listItem - } - - func getRewardListItem(_ moleculeJson: [AnyHashable: Any]) -> MoleculeListItemModel? { - - var stackItems: [MoleculeStackItemModel] = [] - - (moleculeJson.arrayForKey("rewards") as? [[AnyHashable: Any]])?.forEach { (rewardItem) in - let textcolor = rewardItem.optionalStringForKey("textColor") - - let titleLabel = LabelModel(text: rewardItem.stringForkey(KeyTitle)) - titleLabel.fontName = "NHaasGroteskDSStd-75Bd" - titleLabel.textColor = textcolor - titleLabel.fontSize = 48 - - let messageLabel = LabelModel(text: rewardItem.stringForkey("message")) - messageLabel.fontName = "NHaasGroteskDSStd-75Bd" - messageLabel.textColor = textcolor - messageLabel.fontSize = 14 - - let titleStackItem = MoleculeStackItemModel(with: titleLabel) - let messageStackItem = MoleculeStackItemModel(with: messageLabel) - - let itemStack = MoleculeStackModel(molecules: [titleStackItem, messageStackItem]) - itemStack.verticalAlignment = .top - itemStack.spacing = 0 - - let horizontalStack = MoleculeStackItemModel(with: itemStack) - horizontalStack.verticalAlignment = .top - stackItems.append(horizontalStack) - } - - stackItems.first?.percent = 35 - stackItems.last?.percent = 65 - let stack = MoleculeStackModel(molecules: stackItems) - stack.axis = .horizontal - stack.horizontalAlignment = .leading - stack.verticalAlignment = .leading - - let listItem = MoleculeListItemModel(with: stack) - let backgroudColorString = moleculeJson.optionalStringForKey("backgroundColor") ?? "#000000" - listItem.backgroundColor = Color(uiColor: UIColor.mfGet(forHex: backgroudColorString)) - listItem.line = LineModel(type: .none) - - return listItem - } -} - diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index cbe0458c..9741f110 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -24,7 +24,11 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol //-------------------------------------------------- open override func parsePageJSON(_ error: NSErrorPointer) { - try? parseTemplateJSON() + do { + try parseTemplateJSON() + } catch let parseError { + error?.pointee = parseError as NSError + } } open override var loadObject: MVMCoreLoadObject? { diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index 8bf0b4cd..ef7a470d 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -13,7 +13,11 @@ open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { var observer: NSKeyValueObservation? public var templateModel: StackPageTemplateModel? open override func parsePageJSON(_ error: NSErrorPointer) { - try? parseTemplateJSON() + do { + try parseTemplateJSON() + } catch let parseError { + error?.pointee = parseError as NSError + } } open override var loadObject: MVMCoreLoadObject? { diff --git a/MVMCoreUI/Templates/ThreeLayerTemplate.swift b/MVMCoreUI/Templates/ThreeLayerTemplate.swift index 72498289..eb822279 100644 --- a/MVMCoreUI/Templates/ThreeLayerTemplate.swift +++ b/MVMCoreUI/Templates/ThreeLayerTemplate.swift @@ -13,7 +13,11 @@ import UIKit public var templateModel: ThreeLayerPageTemplateModel? open override func parsePageJSON(_ error: NSErrorPointer) { - try? parseTemplateJSON() + do { + try parseTemplateJSON() + } catch let parseError { + error?.pointee = parseError as NSError + } } override open func viewDidLoad() { From 29f89154f89c68db06d11144366d46ad0013366b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 18 Feb 2020 16:55:56 -0500 Subject: [PATCH 8/8] small model fix for images --- MVMCoreUI/Atoms/Views/MFLoadImageView.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index fa7d369e..156e187d 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -210,6 +210,9 @@ import UIKit } public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + self.delegateObject = delegateObject + // TODO: Temporary, should be moved to init once we have type erasure ready. + setAsMolecule() guard let imageModel = model as? ImageViewModel else { return }