From 9e8580e24063b0f318348f237fa3b4501540a125 Mon Sep 17 00:00:00 2001 From: Lekshmi S Date: Mon, 26 Oct 2020 18:37:26 +0530 Subject: [PATCH 1/4] 22352(iOS - List star rating) initial commit. --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++ MVMCoreUI/Atomic/MoleculeObjectMapping.swift | 1 + .../List/ListStarRating.swift | 73 +++++++++++++++++++ .../List/ListStarRatingModel.swift | 52 +++++++++++++ .../Strings/en.lproj/Localizable.strings | 1 + .../Strings/es-MX.lproj/Localizable.strings | 1 + .../Strings/es.lproj/Localizable.strings | 1 + 7 files changed, 137 insertions(+) create mode 100644 MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift create mode 100644 MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRatingModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 4b0faceb..5668f73a 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -235,6 +235,8 @@ AA71AD4024A32FE700ACA76F /* HeadersH2Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA71AD3F24A32FE700ACA76F /* HeadersH2Link.swift */; }; AA7F32AB246C0F7900C965BA /* ListLeftVariableRadioButtonAllTextAndLinksModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA7F32AA246C0F7900C965BA /* ListLeftVariableRadioButtonAllTextAndLinksModel.swift */; }; AA7F32AD246C0F8C00C965BA /* ListLeftVariableRadioButtonAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA7F32AC246C0F8C00C965BA /* ListLeftVariableRadioButtonAllTextAndLinks.swift */; }; + AA7F47732541AD560015A2C1 /* ListStarRatingModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA7F47722541AD560015A2C1 /* ListStarRatingModel.swift */; }; + AA7F47762541AD6A0015A2C1 /* ListStarRating.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA7F47752541AD6A0015A2C1 /* ListStarRating.swift */; }; AA85236C244435A20059CC1E /* RadioSwatchCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA85236B244435A20059CC1E /* RadioSwatchCollectionViewCell.swift */; }; AA9972502475309F00FC7472 /* ListLeftVariableIconAllTextLinksModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA99724F2475309F00FC7472 /* ListLeftVariableIconAllTextLinksModel.swift */; }; AA997252247530B100FC7472 /* ListLeftVariableIconAllTextLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA997251247530B100FC7472 /* ListLeftVariableIconAllTextLinks.swift */; }; @@ -747,6 +749,8 @@ AA71AD3F24A32FE700ACA76F /* HeadersH2Link.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadersH2Link.swift; sourceTree = ""; }; AA7F32AA246C0F7900C965BA /* ListLeftVariableRadioButtonAllTextAndLinksModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableRadioButtonAllTextAndLinksModel.swift; sourceTree = ""; }; AA7F32AC246C0F8C00C965BA /* ListLeftVariableRadioButtonAllTextAndLinks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableRadioButtonAllTextAndLinks.swift; sourceTree = ""; }; + AA7F47722541AD560015A2C1 /* ListStarRatingModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStarRatingModel.swift; sourceTree = ""; }; + AA7F47752541AD6A0015A2C1 /* ListStarRating.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStarRating.swift; sourceTree = ""; }; AA85236B244435A20059CC1E /* RadioSwatchCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioSwatchCollectionViewCell.swift; sourceTree = ""; }; AA99724F2475309F00FC7472 /* ListLeftVariableIconAllTextLinksModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableIconAllTextLinksModel.swift; sourceTree = ""; }; AA997251247530B100FC7472 /* ListLeftVariableIconAllTextLinks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableIconAllTextLinks.swift; sourceTree = ""; }; @@ -1474,6 +1478,8 @@ D22B38EB23F4E0AE00490EF6 /* LeftVariable */, AAB7EDEE246ADA1600E54929 /* ListProgressBarThinModel.swift */, AAB7EDF0246ADA2A00E54929 /* ListProgressBarThin.swift */, + AA7F47722541AD560015A2C1 /* ListStarRatingModel.swift */, + AA7F47752541AD6A0015A2C1 /* ListStarRating.swift */, ); path = List; sourceTree = ""; @@ -2535,6 +2541,8 @@ 011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */, D22479962316AF6E003FCCF9 /* HeadlineBodyLink.swift in Sources */, 8DE5BECD2456F7A200772E76 /* ListTwoColumnDropdownSelectorsModel.swift in Sources */, + AA7F47732541AD560015A2C1 /* ListStarRatingModel.swift in Sources */, + AA7F47762541AD6A0015A2C1 /* ListStarRating.swift in Sources */, 0A41BA7F23453A6400D4C0BC /* TextEntryField.swift in Sources */, BB55B51D244482C1002001AD /* ListRightVariablePriceChangeBodyText.swift in Sources */, 017BEB382360C6AC0024EF95 /* RadioButtonLabel.swift in Sources */, diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index 8a5b737a..6a66a005 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -201,6 +201,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: ListThreeColumnSpeedTest.self, viewModelClass: ListThreeColumnSpeedTestModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListFourColumnDataUsageListItem.self, viewModelClass: ListFourColumnDataUsageListItemModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListProgressBarThin.self, viewModelClass: ListProgressBarThinModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: ListStarRating.self, viewModelClass: ListStarRatingModel.self) // MARK:- Designed Section Dividers MoleculeObjectMapping.shared()?.register(viewClass: ListFourColumnDataUsageDivider.self, viewModelClass: ListFourColumnDataUsageDividerModel.self) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift new file mode 100644 index 00000000..b1ca1ac4 --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift @@ -0,0 +1,73 @@ +// +// ListStarRating.swift +// MVMCoreUI +// +// Created by Lekshmi S on 22/10/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +@objcMembers open class ListStarRating: TableViewCell { + //----------------------------------------------------- + // MARK: - Outlets + //----------------------------------------------------- + public let stars = Stars() + public var reviewsCount = Label(fontStyle: .RegularBodySmall) + + //----------------------------------------------------- + // MARK: - Properties + //----------------------------------------------------- + public var stack: Stack + + //----------------------------------------------------- + // MARK: - Initializers + //----------------------------------------------------- + public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + stack = Stack.createStack(with: [(view: stars, model: StackItemModel(horizontalAlignment: .fill)), + (view: reviewsCount, model: StackItemModel(horizontalAlignment: .leading))], + axis: .horizontal, spacing: 8) + super.init(style: style, reuseIdentifier: reuseIdentifier) + } + + public required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + //----------------------------------------------------- + // MARK: - Lifecycle + //----------------------------------------------------- + override open func setupView() { + super.setupView() + addMolecule(stack) + stack.restack() + } + + //---------------------------------------------------- + // MARK: - Molecule + //---------------------------------------------------- + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + super.set(with: model, delegateObject, additionalData) + + guard let model = model as? ListStarRatingModel else { return } + stars.set(with: model.stars, delegateObject, additionalData) + reviewsCount.set(with: model.reviewsCount, delegateObject, additionalData) + updateAccessibilityLabel() + } + + open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return 90 + } + + // MARK: - Accessibility + func updateAccessibilityLabel() { + isAccessibilityElement = true + var message = "" + if let starsLabel = stars.accessibilityLabel { + message += starsLabel + ", " + } + + if let reviewsCountLabelText = reviewsCount.text, let reviewText = MVMCoreUIUtility.hardcodedString(withKey: "review_text") { + message += reviewsCountLabelText + reviewText + } + accessibilityLabel = message + } +} diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRatingModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRatingModel.swift new file mode 100644 index 00000000..6838f0b0 --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRatingModel.swift @@ -0,0 +1,52 @@ +// +// ListStarRatingModel.swift +// MVMCoreUI +// +// Created by Lekshmi S on 22/10/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +open class ListStarRatingModel: ListItemModel, MoleculeModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "listStarRating" + public var stars: StarsModel + public var reviewsCount: LabelModel + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(stars: StarsModel, reviewsCount: LabelModel) { + self.stars = stars + self.reviewsCount = reviewsCount + super.init() + } + + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { + case moleculeName + case stars + case reviewsCount + } + + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + stars = try typeContainer.decode(StarsModel.self, forKey: .stars) + reviewsCount = try typeContainer.decode(LabelModel.self, forKey: .reviewsCount) + try super.init(from: decoder) + } + + open override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encode(stars, forKey: .stars) + try container.encode(reviewsCount, forKey: .reviewsCount) + } +} diff --git a/MVMCoreUI/SupportingFiles/Strings/en.lproj/Localizable.strings b/MVMCoreUI/SupportingFiles/Strings/en.lproj/Localizable.strings index f14fe02e..ba70fc2b 100644 --- a/MVMCoreUI/SupportingFiles/Strings/en.lproj/Localizable.strings +++ b/MVMCoreUI/SupportingFiles/Strings/en.lproj/Localizable.strings @@ -92,3 +92,4 @@ "star" = "Star"; "star_percent" = "%d percent progress"; "stars_filled" = "%.1f out of %d stars"; +"review_text" = " reviews"; diff --git a/MVMCoreUI/SupportingFiles/Strings/es-MX.lproj/Localizable.strings b/MVMCoreUI/SupportingFiles/Strings/es-MX.lproj/Localizable.strings index 4d14292c..b279ccdb 100644 --- a/MVMCoreUI/SupportingFiles/Strings/es-MX.lproj/Localizable.strings +++ b/MVMCoreUI/SupportingFiles/Strings/es-MX.lproj/Localizable.strings @@ -70,3 +70,4 @@ "star" = "Estrella"; "star_percent" = "%@ porcentaje de progreso"; "stars_filled" = "%.1f de %d estrellas"; +"review_text" = " críticas"; diff --git a/MVMCoreUI/SupportingFiles/Strings/es.lproj/Localizable.strings b/MVMCoreUI/SupportingFiles/Strings/es.lproj/Localizable.strings index 585e2c1a..0c441812 100644 --- a/MVMCoreUI/SupportingFiles/Strings/es.lproj/Localizable.strings +++ b/MVMCoreUI/SupportingFiles/Strings/es.lproj/Localizable.strings @@ -75,3 +75,4 @@ "star" = "Estrella"; "star_percent" = "%@ porcentaje de progreso"; "stars_filled" = "%.1f de %d estrellas"; +"review_text" = " críticas"; From 46e0c6281f151a8e65caea214af2101baa78d267 Mon Sep 17 00:00:00 2001 From: Lekshmi S Date: Tue, 27 Oct 2020 12:33:56 +0530 Subject: [PATCH 2/4] Code changes after review. --- .../List/ListStarRating.swift | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift index b1ca1ac4..2e1ec8cb 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift @@ -12,26 +12,12 @@ //----------------------------------------------------- public let stars = Stars() public var reviewsCount = Label(fontStyle: .RegularBodySmall) + public lazy var stack: Stack = { + return Stack.createStack(with: [(view: stars, model: StackItemModel(horizontalAlignment: .fill)), + (view: reviewsCount, model: StackItemModel(horizontalAlignment: .leading))], + axis: .horizontal, spacing: Padding.Two) + }() - //----------------------------------------------------- - // MARK: - Properties - //----------------------------------------------------- - public var stack: Stack - - //----------------------------------------------------- - // MARK: - Initializers - //----------------------------------------------------- - public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - stack = Stack.createStack(with: [(view: stars, model: StackItemModel(horizontalAlignment: .fill)), - (view: reviewsCount, model: StackItemModel(horizontalAlignment: .leading))], - axis: .horizontal, spacing: 8) - super.init(style: style, reuseIdentifier: reuseIdentifier) - } - - public required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - //----------------------------------------------------- // MARK: - Lifecycle //----------------------------------------------------- @@ -41,6 +27,11 @@ stack.restack() } + open override func updateView(_ size: CGFloat) { + super.updateView(size) + stack.updateView(size) + } + //---------------------------------------------------- // MARK: - Molecule //---------------------------------------------------- From bc6c23cd914784dd754802d507597e2edd5b9b36 Mon Sep 17 00:00:00 2001 From: Lekshmi S Date: Mon, 2 Nov 2020 18:29:15 +0530 Subject: [PATCH 3/4] Removed redundant method call. --- .../Molecules/DesignedComponents/List/ListStarRating.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift index 2e1ec8cb..1e904c8a 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift @@ -29,7 +29,6 @@ open override func updateView(_ size: CGFloat) { super.updateView(size) - stack.updateView(size) } //---------------------------------------------------- From b90d761f251f32c92de1b73f38788853c8519493 Mon Sep 17 00:00:00 2001 From: Lekshmi S Date: Tue, 3 Nov 2020 11:07:35 +0530 Subject: [PATCH 4/4] Moved molecule to Miscellaneous group. --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++-- .../List/{ => Miscellaneous}/ListStarRating.swift | 4 ---- .../List/{ => Miscellaneous}/ListStarRatingModel.swift | 0 3 files changed, 2 insertions(+), 6 deletions(-) rename MVMCoreUI/Atomic/Molecules/DesignedComponents/List/{ => Miscellaneous}/ListStarRating.swift (96%) rename MVMCoreUI/Atomic/Molecules/DesignedComponents/List/{ => Miscellaneous}/ListStarRatingModel.swift (100%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 7fd14012..3cc6f842 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -1363,6 +1363,8 @@ children = ( AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */, AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */, + AA7F47722541AD560015A2C1 /* ListStarRatingModel.swift */, + AA7F47752541AD6A0015A2C1 /* ListStarRating.swift */, ); path = Miscellaneous; sourceTree = ""; @@ -1547,8 +1549,6 @@ D22B38EB23F4E0AE00490EF6 /* LeftVariable */, AAB7EDEE246ADA1600E54929 /* ListProgressBarThinModel.swift */, AAB7EDF0246ADA2A00E54929 /* ListProgressBarThin.swift */, - AA7F47722541AD560015A2C1 /* ListStarRatingModel.swift */, - AA7F47752541AD6A0015A2C1 /* ListStarRating.swift */, ); path = List; sourceTree = ""; diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Miscellaneous/ListStarRating.swift similarity index 96% rename from MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift rename to MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Miscellaneous/ListStarRating.swift index 1e904c8a..b4bcf03d 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRating.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Miscellaneous/ListStarRating.swift @@ -27,10 +27,6 @@ stack.restack() } - open override func updateView(_ size: CGFloat) { - super.updateView(size) - } - //---------------------------------------------------- // MARK: - Molecule //---------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRatingModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Miscellaneous/ListStarRatingModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListStarRatingModel.swift rename to MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Miscellaneous/ListStarRatingModel.swift