diff --git a/LoopKit/TemporaryPreset.swift b/LoopKit/TemporaryPreset.swift index edf0df3e0..1a88511bb 100644 --- a/LoopKit/TemporaryPreset.swift +++ b/LoopKit/TemporaryPreset.swift @@ -115,15 +115,15 @@ public struct PresetSymbol: Hashable, Sendable, Codable, RawRepresentable, Expre } public init(from decoder: any Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - if let symbolTypeValue = try container.decodeIfPresent(SymbolType.self, forKey: .symbolType) { - self.symbolType = symbolTypeValue + if let container = try? decoder.container(keyedBy: CodingKeys.self) { + self.symbolType = try container.decode(SymbolType.self, forKey: .symbolType) self.tint = try container.decodeIfPresent(SymbolTint.self, forKey: .tint) self.value = try container.decode(String.self, forKey: .value) } else { + let container = try decoder.singleValueContainer() self.symbolType = .emoji self.tint = nil - self.value = try container.decode(String.self, forKey: .symbolType) + self.value = try container.decode(String.self) } } @@ -156,6 +156,10 @@ public struct PresetSymbol: Hashable, Sendable, Codable, RawRepresentable, Expre return nil } } + + public var isEmpty: Bool { + value.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty + } } public struct TemporaryPreset: Hashable, Sendable { diff --git a/LoopKit/TemporaryScheduleOverride.swift b/LoopKit/TemporaryScheduleOverride.swift index 7f479147e..167ef5b00 100644 --- a/LoopKit/TemporaryScheduleOverride.swift +++ b/LoopKit/TemporaryScheduleOverride.swift @@ -64,11 +64,8 @@ public struct ActivityPreset: Hashable, Identifiable, Sendable, RawRepresentable } } - private var defaultDuration: TemporaryScheduleOverride.Duration { - .finite(.hours(1)) - } - public var defaultPreset: TemporaryPreset { + public func defaultPreset(duration: TemporaryScheduleOverride.Duration) -> TemporaryPreset { TemporaryPreset( id: id, symbol: symbol, @@ -77,7 +74,7 @@ public struct ActivityPreset: Hashable, Identifiable, Sendable, RawRepresentable targetRange: defaultTargetRange, insulinNeedsScaleFactor: defaultInsulinNeedsScaleFactor ), - duration: defaultDuration + duration: duration ) } } @@ -111,7 +108,7 @@ public struct ActivityPreset: Hashable, Identifiable, Sendable, RawRepresentable } public var isModifiedFromDefault: Bool { - preset != activityType.defaultPreset + preset != activityType.defaultPreset(duration: preset.duration) } public var id: String { @@ -365,6 +362,8 @@ extension TemporaryScheduleOverride.Context: Codable { self = .preMeal case CodableKeys.custom.rawValue: self = .custom + case "legacyWorkout": + self = .custom default: throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "invalid enumeration")) } diff --git a/LoopKitUI/ViewModels/TherapySettingsViewModel.swift b/LoopKitUI/ViewModels/TherapySettingsViewModel.swift index e8965b427..81be18656 100644 --- a/LoopKitUI/ViewModels/TherapySettingsViewModel.swift +++ b/LoopKitUI/ViewModels/TherapySettingsViewModel.swift @@ -24,19 +24,16 @@ public class TherapySettingsViewModel { public var therapySettings: TherapySettings @ObservationIgnored private let initialTherapySettings: TherapySettings - @ObservationIgnored let sensitivityOverridesEnabled: Bool @ObservationIgnored public var prescription: Prescription? @ObservationIgnored private weak var delegate: TherapySettingsViewModelDelegate? public init(therapySettings: TherapySettings, pumpSupportedIncrements: (() -> PumpSupportedIncrements?)? = nil, - sensitivityOverridesEnabled: Bool = false, prescription: Prescription? = nil, delegate: TherapySettingsViewModelDelegate? = nil) { self.therapySettings = therapySettings self.initialTherapySettings = therapySettings - self.sensitivityOverridesEnabled = sensitivityOverridesEnabled self.prescription = prescription self.delegate = delegate }