diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 9768fcf8..e600e30f 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -10,6 +10,9 @@ 0105618D224BBE7700E1557D /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618A224BBE7700E1557D /* FormValidator.swift */; }; 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; }; 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; }; + 01509D98232803C900EF99AA /* BaseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D97232803C900EF99AA /* BaseModel.swift */; }; + 01509D9A2328077C00EF99AA /* LabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D992328077C00EF99AA /* LabelModel.swift */; }; + 01509D9C23283F5000EF99AA /* AttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D9B23283F5000EF99AA /* AttributeModel.swift */; }; 016A1071228122180009D605 /* HeadlineBodyTextButtonSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A1070228122180009D605 /* HeadlineBodyTextButtonSwitch.swift */; }; 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198F79E225679870066C936 /* FormValidationProtocol.swift */; }; 0198F7A62256A80B0066C936 /* MFRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 0198F7A02256A80A0066C936 /* MFRadioButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -193,6 +196,9 @@ 0105618A224BBE7700E1557D /* FormValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = ""; }; 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = ""; }; 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = ""; }; + 01509D97232803C900EF99AA /* BaseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseModel.swift; sourceTree = ""; }; + 01509D992328077C00EF99AA /* LabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelModel.swift; sourceTree = ""; }; + 01509D9B23283F5000EF99AA /* AttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributeModel.swift; sourceTree = ""; }; 016A1070228122180009D605 /* HeadlineBodyTextButtonSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyTextButtonSwitch.swift; sourceTree = ""; }; 0198F79E225679870066C936 /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = ""; }; 0198F7A02256A80A0066C936 /* MFRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFRadioButton.h; sourceTree = ""; }; @@ -388,6 +394,16 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 01509D96232803B200EF99AA /* Models */ = { + isa = PBXGroup; + children = ( + 01509D97232803C900EF99AA /* BaseModel.swift */, + 01509D992328077C00EF99AA /* LabelModel.swift */, + 01509D9B23283F5000EF99AA /* AttributeModel.swift */, + ); + path = Models; + sourceTree = ""; + }; 01C74D87224298E2009C25A3 /* FormUIHelpers */ = { isa = PBXGroup; children = ( @@ -488,6 +504,7 @@ D29DF0CE21E404D4003B2FB9 /* MVMCoreUI */ = { isa = PBXGroup; children = ( + 01509D96232803B200EF99AA /* Models */, 01C74D87224298E2009C25A3 /* FormUIHelpers */, D29DF31421ECECA7003B2FB9 /* SupportingFiles */, D29DF27021E79B2C003B2FB9 /* OtherHandlers */, @@ -1002,6 +1019,7 @@ D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */, D29DF11721E6805F003B2FB9 /* UIColor+MFConvenience.m in Sources */, D29DF25321E6A177003B2FB9 /* MFDigitTextField.m in Sources */, + 01509D9C23283F5000EF99AA /* AttributeModel.swift in Sources */, D29DF12F21E6851E003B2FB9 /* MVMCoreUITopAlertMainView.m in Sources */, DBC4392122491730001AB423 /* LabelWithInternalButton.swift in Sources */, D224798C231450C8003FCCF9 /* HeadlineBodySwitch.swift in Sources */, @@ -1024,6 +1042,7 @@ D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, DBEFFA04225A829700230692 /* Label.swift in Sources */, D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, + 01509D98232803C900EF99AA /* BaseModel.swift in Sources */, D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */, D28B4F8B21FF967C00712C7A /* MVMCoreUIObject.m in Sources */, D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */, @@ -1071,6 +1090,7 @@ D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */, D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */, D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */, + 01509D9A2328077C00EF99AA /* LabelModel.swift in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index ed99fcac..fcc3de4e 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -196,7 +196,7 @@ public typealias ActionBlock = () -> () } @objc public static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) { - + //LabelModel() guard let label = label else { return } label.attributedText = nil label.text = json?.optionalStringForKey(KeyText) @@ -519,6 +519,15 @@ extension Label { @objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { clauses = [] + + do { + let data = try JSONSerialization.data(withJSONObject: json!, options: .prettyPrinted) + let labelModel = try JSONDecoder().decode(LabelModel.self, from: data) + print("") + } catch let error { + print(error.localizedDescription) + } + Label.setUILabel(self, withJSON: json, delegate: delegateObject, additionalData: additionalData) originalAttributedString = attributedText } diff --git a/MVMCoreUI/Models/AttributeModel.swift b/MVMCoreUI/Models/AttributeModel.swift new file mode 100644 index 00000000..426618e0 --- /dev/null +++ b/MVMCoreUI/Models/AttributeModel.swift @@ -0,0 +1,48 @@ +// +// AttributeModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 9/10/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public class AttributeModel: BaseModel { + var type: String? + var location: Int? + var length: Int? + var textColor: String? + var size: Int? + var name: String? + + private enum CodingKeys : String, CodingKey { + case type + case location + case length + case textColor + case size + case name + } + + public required init(from decoder: Decoder) throws { + try super.init(from: decoder) + let container = try decoder.container(keyedBy: CodingKeys.self) + type = try container.decode(String.self, forKey: CodingKeys.type) + location = try container.decode(Int.self, forKey: CodingKeys.location) + length = try container.decode(Int.self, forKey: CodingKeys.length) + textColor = try container.decode(String.self, forKey: CodingKeys.textColor) + size = try container.decode(Int.self, forKey: CodingKeys.size) + name = try container.decode(String.self, forKey: CodingKeys.name) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(type, forKey: .type) + try container.encode(location, forKey: .location) + try container.encode(textColor, forKey: .textColor) + try container.encode(size, forKey: .size) + try container.encode(name, forKey: .name) + } +} diff --git a/MVMCoreUI/Models/BaseModel.swift b/MVMCoreUI/Models/BaseModel.swift new file mode 100644 index 00000000..140833a5 --- /dev/null +++ b/MVMCoreUI/Models/BaseModel.swift @@ -0,0 +1,63 @@ +// +// BaseModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 9/10/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +public class BaseModel: Codable { + + public var moleculeName: String? + // public var dictionaryRepresentation: [AnyHashable: Any] + + private enum CodingKeys : String, CodingKey { + case moleculeName + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + moleculeName = try container.decode(String.self, forKey: CodingKeys.moleculeName) + } + + public func encode(to encoder: Encoder) throws { + //try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + } + +// //init +// public init(_ dictionary:[AnyHashable: Any]){ +// dictionaryRepresentation = dictionary +// } +// +// public func getString(_ key:String) -> String { +// return dictionaryRepresentation[key] as? String ?? "" +// } +// +// public func getOptionalString(_ key:String) -> String? { +// return dictionaryRepresentation[key] as? String ?? nil +// } +// +// public func dictionaryForKey(_ key : String) -> [String : Any]? { +// let dict = dictionaryRepresentation.dictionaryForKey(key) +// if dict.count > 0 { +// return dict +// } +// return nil +// } +// +// public func arrayForKey(_ key : String) -> Array>? { +// return dictionaryRepresentation.arrayForKey(key) as? Array> +// } +// +// public func convertStringToBool(_ string:String)-> Bool{ +// var converter = dictionaryRepresentation[string] as? String ?? "" +// converter = converter.lowercased() +// let convertedValue = converter == "true" || converter == "yes" +// return convertedValue +// } +} diff --git a/MVMCoreUI/Models/LabelModel.swift b/MVMCoreUI/Models/LabelModel.swift new file mode 100644 index 00000000..5aa7fffa --- /dev/null +++ b/MVMCoreUI/Models/LabelModel.swift @@ -0,0 +1,66 @@ +// +// LabelModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 9/10/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +class LabelModel: BaseModel { + + var text: String + var accessibilityText: String + var textColor: String + var backgroundColor: String + var fontStyle: String + var fontName: String + var fontSize: Int + var textAlignment: String + //var attributes: AttributeModel + var html: String + + private enum CodingKeys : String, CodingKey { + case text + case accessibilityText + case textColor + case backgroundColor + case fontStyle + case fontName + case fontSize + case textAlignment + //case attributes + case html + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + text = try container.decode(String.self, forKey: CodingKeys.text) + accessibilityText = try container.decode(String.self, forKey: CodingKeys.accessibilityText) + textColor = try container.decode(String.self, forKey: CodingKeys.textColor) + backgroundColor = try container.decode(String.self, forKey: CodingKeys.backgroundColor) + fontStyle = try container.decode(String.self, forKey: CodingKeys.backgroundColor) + fontName = try container.decode(String.self, forKey: CodingKeys.fontName) + textAlignment = try container.decode(String.self, forKey: CodingKeys.textAlignment) + //attributes = try container.decode(AttributeModel.self, forKey: CodingKeys.attributes) + html = try container.decode(String.self, forKey: CodingKeys.html) + fontSize = try container.decode(Int.self, forKey: CodingKeys.fontSize) + 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(text, forKey: .text) + try container.encode(accessibilityText, forKey: .accessibilityText) + try container.encode(textColor, forKey: .textColor) + try container.encode(backgroundColor, forKey: .backgroundColor) + try container.encode(fontStyle, forKey: .fontStyle) + try container.encode(fontName, forKey: .fontName) + try container.encode(textAlignment, forKey: .textAlignment) + //try container.encode(attributes, forKey: .attributes) + try container.encode(html, forKey: .html) + } +}