Skip to content

Commit 1ff5463

Browse files
committed
The view is divided into small parts.
1 parent 3f688b1 commit 1ff5463

File tree

1 file changed

+91
-68
lines changed

1 file changed

+91
-68
lines changed

Loop/Views/MicrobolusView.swift

Lines changed: 91 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -134,98 +134,121 @@ struct MicrobolusView: View {
134134

135135
var body: some View {
136136
Form {
137-
Section {
138-
HStack {
139-
Image(systemName: "exclamationmark.triangle.fill")
140-
.foregroundColor(.orange)
141-
.padding(.trailing)
137+
self.topSection
138+
self.withCobSection
139+
self.withoutCobSection
140+
self.partialApplicationSection
141+
self.safeModeSection
142+
self.temporaryOverridesSection
143+
self.otherOptionsSection
144+
}
145+
.navigationBarTitle("Microboluses")
146+
.modifier(AdaptsToSoftwareKeyboard())
147+
}
142148

143-
Text("Caution! Microboluses have potential to reduce the safety effects of other mitigations like max temp basal rate. Please be careful!\nThe actual size of a microbolus is always limited to the partial application of recommended bolus.")
144-
.font(.caption)
145-
}
149+
private var topSection: some View {
150+
Section {
151+
HStack {
152+
Image(systemName: "exclamationmark.triangle.fill")
153+
.foregroundColor(.orange)
154+
.padding(.trailing)
146155

156+
Text("Caution! Microboluses have potential to reduce the safety effects of other mitigations like max temp basal rate. Please be careful!\nThe actual size of a microbolus is always limited to the partial application of recommended bolus.")
157+
.font(.caption)
147158
}
148-
Section(footer:
149-
Text("This is the maximum minutes of basal that can be delivered as a single microbolus with uncovered COB. This allows you to make microboluses behave more aggressively. It is recommended that this value is set to start at 30, in line with default, and if you choose to increase this value, do so in no more than 15 minute increments, keeping a close eye on the effects of the changes.")
150-
) {
151-
Toggle (isOn: $viewModel.microbolusesWithCOB) {
152-
Text("Enable With Carbs")
153-
}
154159

155-
Picker(selection: $viewModel.pickerWithCOBIndex, label: Text("Maximum Size")) {
156-
ForEach(0 ..< viewModel.values.count) { index in
157-
Text("\(self.viewModel.values[index])").tag(index)
158-
}
159-
}
160+
}
161+
}
162+
163+
private var withCobSection: some View {
164+
Section(footer:
165+
Text("This is the maximum minutes of basal that can be delivered as a single microbolus with uncovered COB. This allows you to make microboluses behave more aggressively. It is recommended that this value is set to start at 30, in line with default, and if you choose to increase this value, do so in no more than 15 minute increments, keeping a close eye on the effects of the changes.")
166+
) {
167+
Toggle (isOn: $viewModel.microbolusesWithCOB) {
168+
Text("Enable With Carbs")
160169
}
161170

162-
Section(footer:
163-
Text("This is the maximum minutes of basal that can be delivered as a single microbolus without COB.")
164-
) {
165-
Toggle (isOn: $viewModel.microbolusesWithoutCOB) {
166-
Text("Enable Without Carbs")
167-
}
168-
Picker(selection: $viewModel.pickerWithoutCOBIndex, label: Text("Maximum Size")) {
169-
ForEach(0 ..< viewModel.values.count) { index in
170-
Text("\(self.viewModel.values[index])").tag(index)
171-
}
171+
Picker(selection: $viewModel.pickerWithCOBIndex, label: Text("Maximum Size")) {
172+
ForEach(0 ..< viewModel.values.count) { index in
173+
Text("\(self.viewModel.values[index])").tag(index)
172174
}
173175
}
176+
}
177+
}
174178

175-
Section(footer:
176-
Text("What part of the recommended bolus will be applied automatically.")
177-
) {
178-
Picker(selection: $viewModel.partialApplicationIndex, label: Text("Partial Application")) {
179-
ForEach(0 ..< viewModel.partialApplicationValues.count) { index in
180-
Text(String(format: "%.0f %%", self.viewModel.partialApplicationValues[index] * 100)).tag(index)
181-
}
179+
private var withoutCobSection: some View {
180+
Section(footer:
181+
Text("This is the maximum minutes of basal that can be delivered as a single microbolus without COB.")
182+
) {
183+
Toggle (isOn: $viewModel.microbolusesWithoutCOB) {
184+
Text("Enable Without Carbs")
185+
}
186+
Picker(selection: $viewModel.pickerWithoutCOBIndex, label: Text("Maximum Size")) {
187+
ForEach(0 ..< viewModel.values.count) { index in
188+
Text("\(self.viewModel.values[index])").tag(index)
182189
}
183190
}
191+
}
192+
}
184193

185-
Section(header: Text("Safe Mode").font(.headline), footer:
186-
Text("• If Enabled and predicted glucose in 15 minutes is lower than current glucose, microboluses are not allowed.\n• If Limited and the predicted glucose in 15 minutes is lower than current glucose, the maximum microbolus size is limited to 30 basal minutes.\n• If Disabled, there are no restrictions.")
187-
) {
188-
Picker(selection: $viewModel.safeMode, label: Text("Safe Mode")) {
189-
ForEach(Microbolus.SafeMode.allCases, id: \.self) { value in
190-
Text("\(value.displayName)").tag(value)
191-
}
194+
private var partialApplicationSection: some View {
195+
Section(footer:
196+
Text("What part of the recommended bolus will be applied automatically.")
197+
) {
198+
Picker(selection: $viewModel.partialApplicationIndex, label: Text("Partial Application")) {
199+
ForEach(0 ..< viewModel.partialApplicationValues.count) { index in
200+
Text(String(format: "%.0f %%", self.viewModel.partialApplicationValues[index] * 100)).tag(index)
192201
}
193-
.pickerStyle(SegmentedPickerStyle())
194202
}
203+
}
204+
}
195205

196-
Section(header: Text("Temporary overrides").font(.headline)) {
197-
Toggle (isOn: $viewModel.disableByOverride) {
198-
Text("Disable MB by enabling temporary override")
206+
private var safeModeSection: some View {
207+
Section(header: Text("Safe Mode").font(.headline), footer:
208+
Text("• If Enabled and predicted glucose in 15 minutes is lower than current glucose, microboluses are not allowed.\n• If Limited and the predicted glucose in 15 minutes is lower than current glucose, the maximum microbolus size is limited to 30 basal minutes.\n• If Disabled, there are no restrictions.")
209+
) {
210+
Picker(selection: $viewModel.safeMode, label: Text("Safe Mode")) {
211+
ForEach(Microbolus.SafeMode.allCases, id: \.self) { value in
212+
Text("\(value.displayName)").tag(value)
199213
}
214+
}
215+
.pickerStyle(SegmentedPickerStyle())
216+
}
217+
}
200218

201-
VStack(alignment: .leading) {
202-
Text("If the override's target range starts at the given value or more").font(.caption)
203-
HStack {
204-
TextField("0", text: $viewModel.lowerBound)
205-
.keyboardType(.decimalPad)
206-
.multilineTextAlignment(.trailing)
207219

208-
Text(viewModel.unit.localizedShortUnitString)
209-
}
210-
}
220+
private var temporaryOverridesSection: some View {
221+
Section(header: Text("Temporary overrides").font(.headline)) {
222+
Toggle (isOn: $viewModel.disableByOverride) {
223+
Text("Disable MB by enabling temporary override")
211224
}
212225

213-
Section(header: Text("Other Options").font(.headline), footer:
214-
Text("This is the minimum microbolus size in units that will be delivered. Only if the microbolus calculated is equal to or greater than this number of units will a bolus be delivered.")
215-
) {
216-
Toggle (isOn: $viewModel.openBolusScreen) {
217-
Text("Open Bolus screen after Carbs")
218-
}
226+
VStack(alignment: .leading) {
227+
Text("If the override's target range starts at the given value or more").font(.caption)
228+
HStack {
229+
TextField("0", text: $viewModel.lowerBound)
230+
.keyboardType(.decimalPad)
231+
.multilineTextAlignment(.trailing)
219232

220-
Picker(selection: $viewModel.pickerMinimumBolusSizeIndex, label: Text("Minimum Bolus Size")) {
221-
ForEach(0 ..< viewModel.minimumBolusSizeValues.count) { index in Text(String(format: "%.2f U", self.viewModel.minimumBolusSizeValues[index])).tag(index)
222-
}
233+
Text(viewModel.unit.localizedShortUnitString)
223234
}
224235
}
236+
}
237+
}
238+
239+
private var otherOptionsSection: some View {
240+
Section(header: Text("Other Options").font(.headline), footer:
241+
Text("This is the minimum microbolus size in units that will be delivered. Only if the microbolus calculated is equal to or greater than this number of units will a bolus be delivered.")
242+
) {
243+
Toggle (isOn: $viewModel.openBolusScreen) {
244+
Text("Open Bolus screen after Carbs")
245+
}
225246

247+
Picker(selection: $viewModel.pickerMinimumBolusSizeIndex, label: Text("Minimum Bolus Size")) {
248+
ForEach(0 ..< viewModel.minimumBolusSizeValues.count) { index in Text(String(format: "%.2f U", self.viewModel.minimumBolusSizeValues[index])).tag(index)
249+
}
250+
}
226251
}
227-
.navigationBarTitle("Microboluses")
228-
.modifier(AdaptsToSoftwareKeyboard())
229252
}
230253
}
231254

@@ -250,7 +273,7 @@ struct MicrobolusView_Previews: PreviewProvider {
250273
)
251274
)
252275
.environment(\.colorScheme, .dark)
253-
.previewLayout(.fixed(width: 375, height: 1000))
276+
.previewLayout(.fixed(width: 375, height: 1300))
254277
}
255278
}
256279

0 commit comments

Comments
 (0)