From 7cba93e9f571672d462328cc06ead3e82caab0bd Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Thu, 9 Apr 2020 15:24:08 +0530 Subject: [PATCH] confluence changes Updated --- .../Views/RadioBoxCollectionViewCell.swift | 1 - .../Atomic/Atoms/Views/RadioBoxModel.swift | 11 ++++++++++ MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift | 22 +++++++++++++++---- .../Atomic/Atoms/Views/RadioBoxesModel.swift | 9 +------- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxCollectionViewCell.swift b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxCollectionViewCell.swift index d959285d..419f278c 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxCollectionViewCell.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxCollectionViewCell.swift @@ -135,7 +135,6 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco lineView.backgroundColor = collectionModel.selectedAccentColor?.uiColor bodyLabel.text = collectionModel.text subTextLabel.text = collectionModel.subText -// isSelected = collectionModel.selected fieldValue = collectionModel.fieldValue isOutOfStock = collectionModel.strikethrough diff --git a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxModel.swift b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxModel.swift index 4ce1e302..0c119ed8 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxModel.swift @@ -17,6 +17,8 @@ import Foundation public var enabled: Bool = true public var strikethrough: Bool = false public var fieldValue: String? + public var fieldKey: String? + public var groupName: String? private enum CodingKeys: String, CodingKey { case moleculeName @@ -28,6 +30,9 @@ import Foundation case enabled case strikethrough case fieldValue + case fieldKey + case groupName + } required public init(from decoder: Decoder) throws { @@ -50,6 +55,9 @@ import Foundation strikethrough = isStrikeTrough } fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue) + fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) + groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) + } public func encode(to encoder: Encoder) throws { @@ -63,5 +71,8 @@ import Foundation try container.encodeIfPresent(enabled, forKey: .enabled) try container.encodeIfPresent(strikethrough, forKey: .strikethrough) try container.encodeIfPresent(fieldValue, forKey: .fieldValue) + try container.encodeIfPresent(fieldKey, forKey: .fieldKey) + try container.encodeIfPresent(groupName, forKey: .groupName) + } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift index ec0689bc..d0cae6b4 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift @@ -14,13 +14,18 @@ open class RadioBoxes: View { /// The models for the molecules. var boxes: [RadioBoxModel]? - public var fieldKey: String? - public var groupName: String? public var collectionViewHeight: NSLayoutConstraint? private let boxWidth: Double = 151.0 private let boxHeight: Double = 64.0 private let itemSpacing: Double = 10.0 private let leadingSpacing: Double = 0 + + public var selectedBox: RadioBoxModel? { + get{ + guard let selectedItem = collectionView.indexPathsForSelectedItems?.first else {return nil} + return boxes?[selectedItem.item] + } + } // MARK: - MVMCoreViewProtocol open override func setupView() { @@ -45,8 +50,6 @@ open class RadioBoxes: View { super.set(with: model, delegateObject, additionalData) guard let radioBoxesModel = model as? RadioBoxesModel else { return } backgroundColor = radioBoxesModel.backgroundColor?.uiColor - fieldKey = radioBoxesModel.fieldKey - groupName = radioBoxesModel.groupName registerCells() setupLayout(with: radioBoxesModel) prepareMolecules(with: radioBoxesModel) @@ -119,3 +122,14 @@ extension RadioBoxes: UICollectionViewDataSource { return cell } } +extension RadioBoxes: UICollectionViewDelegate { + public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + guard let boxItem = boxes?[indexPath.row] else { return } + boxItem.selected = true + } + public func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) { + guard let boxItem = boxes?[indexPath.row] else { return } + boxItem.selected = false + } +} + diff --git a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxesModel.swift b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxesModel.swift index 4e690ffa..d50978a1 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxesModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxesModel.swift @@ -12,16 +12,13 @@ import Foundation public var backgroundColor: Color? = Color(uiColor: .white) public var selectedAccentColor: Color? = Color(uiColor: .red) public var boxes: [RadioBoxModel] - public var fieldKey: String? - public var groupName: String? private enum CodingKeys: String, CodingKey { case moleculeName case selectedAccentColor case backgroundColor case boxes - case fieldKey - case groupName + } required public init(from decoder: Decoder) throws { @@ -33,8 +30,6 @@ import Foundation backgroundColor = color } boxes = try typeContainer.decode([RadioBoxModel].self, forKey: .boxes) - fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) - groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) } public func encode(to encoder: Encoder) throws { @@ -42,7 +37,5 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(selectedAccentColor, forKey: .selectedAccentColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) - try container.encodeIfPresent(fieldKey, forKey: .fieldKey) - try container.encodeIfPresent(groupName, forKey: .groupName) } }