Skip to content

Commit 620daea

Browse files
authored
[LOOP-5496-5600] disable pre-meal preset when in open loop (#875)
* disable pre-meal preset when in open loop * always display timestamp
1 parent aea3372 commit 620daea

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

Loop/Views/LoopStatusModalView.swift

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ struct LoopStatusModalView: View {
7878
Text("Last loop completed")
7979
Text("\(Image(systemName: "arrow.trianglehead.2.clockwise.rotate.90")) \(lastLoopCompletedString)")
8080
.foregroundStyle(freshnessColor)
81-
if viewModel.includeTimeStamp {
82-
Text(viewModel.formattedLastLoopCompleted)
81+
if viewModel.includeDateTimeStamp {
82+
Text(viewModel.formattedLastLoopCompletedDateTime)
83+
.foregroundStyle(freshnessColor)
84+
} else {
85+
Text(viewModel.formattedLastLoopCompletedTime)
8386
.foregroundStyle(freshnessColor)
8487
}
8588
}
@@ -131,14 +134,22 @@ struct LoopStatusModalView: View {
131134
}
132135

133136
struct LoopStatusModalViewModel {
134-
private var timeDateFormatter: DateFormatter = {
137+
private var dateTimeFormatter: DateFormatter = {
135138
let formatter = DateFormatter()
136139
formatter.dateStyle = .medium
137140
formatter.timeStyle = .short
138141
formatter.locale = Locale.current
139142
return formatter
140143
}()
141144

145+
private var timeFormatter: DateFormatter = {
146+
let formatter = DateFormatter()
147+
formatter.dateStyle = .none
148+
formatter.timeStyle = .short
149+
formatter.locale = Locale.current
150+
return formatter
151+
}()
152+
142153
var lastLoopCompleted: Date?
143154
var freshness: LoopCompletionFreshness {
144155
LoopCompletionFreshness(age: ago)
@@ -147,14 +158,18 @@ struct LoopStatusModalViewModel {
147158
guard let lastLoopCompleted else { return nil }
148159
return abs(min(0, lastLoopCompleted.timeIntervalSinceNow))
149160
}
150-
var includeTimeStamp: Bool { // only include if last loop was before today
161+
var includeDateTimeStamp: Bool { // only include if last loop was before today
151162
guard let lastLoopCompleted else { return false }
152163
let startOfToday = Calendar.current.startOfDay(for: Date())
153164
return lastLoopCompleted < startOfToday
154165
}
155-
var formattedLastLoopCompleted: String {
166+
var formattedLastLoopCompletedDateTime: String {
167+
guard let lastLoopCompleted else { return "Unknown" }
168+
return String(format: NSLocalizedString("at %1$@", comment: "when adding the date and time. (1: the formatted date and time)"), dateTimeFormatter.string(from: lastLoopCompleted))
169+
}
170+
var formattedLastLoopCompletedTime: String {
156171
guard let lastLoopCompleted else { return "Unknown" }
157-
return String(format: NSLocalizedString("at %1$@", comment: "when adding a timestamp. (1: the formatted timestamp)"), timeDateFormatter.string(from: lastLoopCompleted))
172+
return String(format: NSLocalizedString("at %1$@", comment: "when adding a timestamp. (1: the formatted timestamp)"), timeFormatter.string(from: lastLoopCompleted))
158173
}
159174

160175
var loopIconClosed: Bool

Loop/Views/Presets/Components/PresetDetentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct PresetDetentView: View {
8080
dismiss()
8181
}
8282
.buttonStyle(ActionButtonStyle())
83-
.disabled(temporaryPresetsManager.activeOverride != nil && preset.id != temporaryPresetsManager.activeOverride?.presetId)
83+
.disabled((temporaryPresetsManager.activeOverride != nil && preset.id != temporaryPresetsManager.activeOverride?.presetId) || (preset.isPreMeal && settingsManager.dosingEnabled == false))
8484
.accessibilityIdentifier("button_startPreset")
8585
case .end:
8686
Button("End Preset") {

0 commit comments

Comments
 (0)