using type now and not the old way.

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-10-14 15:57:25 -05:00
parent 4487f9b03b
commit 76b58ec88a

View File

@ -305,61 +305,27 @@ extension VDS.Badge.FillColor: Codable {
} }
public init(from decoder: Decoder) throws { public init(from decoder: Decoder) throws {
//try legacy ones that map to real fillColor cases let container = try decoder.container(keyedBy: CodingKeys.self)
if let legacy = try? LegacyFillColor(from: decoder) { let type = try container.decode(CustomColorType.self, forKey: .type)
self = legacy.fillColor
} //try to convert to a color
else if let color = try? Color(from: decoder) {
self = .custom(color.uiColor)
} //try to use new format
else {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decode(CustomColorType.self, forKey: .type)
switch type {
case .red:
self = .red
case .yellow:
self = .yellow
case .green:
self = .green
case .orange:
self = .orange
case .blue:
self = .blue
case .black:
self = .black
case .white:
self = .white
case .custom:
let color = try container.decode(Color.self, forKey: .color)
self = .custom(color.uiColor)
}
}
}
private enum LegacyFillColor: String, Decodable {
case red, yellow, green, orange, blue, black, white
var fillColor: Badge.FillColor { switch type {
switch self { case .red:
case .red: self = .red
return .red case .yellow:
case .yellow: self = .yellow
return .yellow case .green:
case .green: self = .green
return .green case .orange:
case .orange: self = .orange
return .orange case .blue:
case .blue: self = .blue
return .blue case .black:
case .black: self = .black
return .black case .white:
case .white: self = .white
return .white case .custom:
} let color = try container.decode(Color.self, forKey: .color)
self = .custom(color.uiColor)
} }
} }