This commit is contained in:
Suresh, Kamlesh 2020-02-17 19:07:23 -05:00
parent d40d15e344
commit d8acbec046
9 changed files with 418 additions and 12 deletions

View File

@ -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 { }
}

View File

@ -277,6 +277,7 @@
// subclass to set up intro animations
- (void)setupIntroAnimations;
- (void)parsePageJSONAndReturnError:(NSError * _Nullable * _Nullable)error;
@end

View File

@ -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

View File

@ -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 {

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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? {

View File

@ -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? {

View File

@ -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() {