From 809f3838e3b36f33740de20d36eda79fe558fe36 Mon Sep 17 00:00:00 2001 From: Cameron Ingham Date: Thu, 21 Aug 2025 11:52:12 -0700 Subject: [PATCH 1/5] [LOOP-5405] Activity Presets Core --- LoopKitUI/ViewModels/TherapySettingsViewModel.swift | 3 --- 1 file changed, 3 deletions(-) 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 } From dd4157ddbeb642d23e8eeed600dfafbebc11da5e Mon Sep 17 00:00:00 2001 From: Cameron Ingham Date: Thu, 21 Aug 2025 12:34:49 -0700 Subject: [PATCH 2/5] [LOOP-5405] Activity Presets Core --- LoopKit/TemporaryScheduleOverride.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/LoopKit/TemporaryScheduleOverride.swift b/LoopKit/TemporaryScheduleOverride.swift index 7f479147e..9b45bd2bb 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 { From 006928247e29111666a74c35113bd3f6e6d4c252 Mon Sep 17 00:00:00 2001 From: Cameron Ingham Date: Thu, 21 Aug 2025 13:53:04 -0700 Subject: [PATCH 3/5] [LOOP-5405] Activity Presets Core --- LoopKit/TemporaryScheduleOverride.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LoopKit/TemporaryScheduleOverride.swift b/LoopKit/TemporaryScheduleOverride.swift index 9b45bd2bb..167ef5b00 100644 --- a/LoopKit/TemporaryScheduleOverride.swift +++ b/LoopKit/TemporaryScheduleOverride.swift @@ -362,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")) } From 3cbc7288194b482e71a80a1a84cddc76cb4d7d63 Mon Sep 17 00:00:00 2001 From: Cameron Ingham Date: Thu, 21 Aug 2025 13:54:52 -0700 Subject: [PATCH 4/5] [LOOP-5405] Activity Presets Core --- LoopKit/TemporaryPreset.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LoopKit/TemporaryPreset.swift b/LoopKit/TemporaryPreset.swift index edf0df3e0..2e1baaade 100644 --- a/LoopKit/TemporaryPreset.swift +++ b/LoopKit/TemporaryPreset.swift @@ -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 { From f15d810d11b2812e8025693d86f566f9ad4b884f Mon Sep 17 00:00:00 2001 From: Cameron Ingham Date: Thu, 21 Aug 2025 14:02:34 -0700 Subject: [PATCH 5/5] [LOOP-5405] Activity Presets Core --- LoopKit/TemporaryPreset.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LoopKit/TemporaryPreset.swift b/LoopKit/TemporaryPreset.swift index 2e1baaade..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) } }