Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions LoopKit/TemporaryPreset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines -118 to +126
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to support migration from the old preset symbol type to the new one.

}
}

Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 5 additions & 6 deletions LoopKit/TemporaryScheduleOverride.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -77,7 +74,7 @@ public struct ActivityPreset: Hashable, Identifiable, Sendable, RawRepresentable
targetRange: defaultTargetRange,
insulinNeedsScaleFactor: defaultInsulinNeedsScaleFactor
),
duration: defaultDuration
duration: duration
)
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -365,6 +362,8 @@ extension TemporaryScheduleOverride.Context: Codable {
self = .preMeal
case CodableKeys.custom.rawValue:
self = .custom
case "legacyWorkout":
self = .custom
Comment on lines +365 to +366
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a legacy workout is found when trying to decode, I just have it marked as custom here. I think ideally, this would decode into a .preset(TemporaryPreset), but I'm not sure what settings I'd provide it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok as is.

default:
throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "invalid enumeration"))
}
Expand Down
3 changes: 0 additions & 3 deletions LoopKitUI/ViewModels/TherapySettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down