101 lines
3.7 KiB
Swift
101 lines
3.7 KiB
Swift
//
|
|
// IsaacLandingTemplate.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Suresh, Kamlesh on 2/13/20.
|
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
|
|
open class IsaacLandingTemplate: MoleculeListTemplate {
|
|
|
|
func parseTemplateJSON() throws {
|
|
|
|
}
|
|
|
|
@objc public override func parsePageJSON() 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)
|
|
|
|
|
|
self.templateModel = template
|
|
}
|
|
|
|
func getListItem(_ moleculeJson: [AnyHashable: Any]) -> MoleculeListItemModel? {
|
|
guard let type = moleculeJson.optionalStringForKey("type") else {
|
|
return nil
|
|
}
|
|
|
|
if type == "rewards" {
|
|
return getRewardListItem(moleculeJson)
|
|
}
|
|
|
|
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 {
|
|
|
|
}
|
|
} 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? {
|
|
return nil
|
|
}
|
|
}
|
|
|