|
@@ -1,12 +1,12 @@
|
|
|
//
|
|
//
|
|
|
-// AlgorithmSubstepView.swift
|
|
|
|
|
|
|
+// AlgorithmSettingsSubstepView.swift
|
|
|
// Trio
|
|
// Trio
|
|
|
//
|
|
//
|
|
|
// Created by Cengiz Deniz on 15.04.25.
|
|
// Created by Cengiz Deniz on 15.04.25.
|
|
|
//
|
|
//
|
|
|
import SwiftUI
|
|
import SwiftUI
|
|
|
|
|
|
|
|
-struct AlgorithmSubstepView<Substep: AlgorithmSubstepProtocol & RawRepresentable>: View where Substep.RawValue == Int {
|
|
|
|
|
|
|
+struct AlgorithmSettingsSubstepView<Substep: AlgorithmSubstepProtocol & RawRepresentable>: View where Substep.RawValue == Int {
|
|
|
@Bindable var state: Onboarding.StateModel
|
|
@Bindable var state: Onboarding.StateModel
|
|
|
let substep: Substep
|
|
let substep: Substep
|
|
|
|
|
|
|
@@ -73,7 +73,8 @@ struct AlgorithmSubstepView<Substep: AlgorithmSubstepProtocol & RawRepresentable
|
|
|
setting: nil,
|
|
setting: nil,
|
|
|
decimalValue: $decimalPlaceholder,
|
|
decimalValue: $decimalPlaceholder,
|
|
|
booleanValue: $state.enableSMBWithCOB,
|
|
booleanValue: $state.enableSMBWithCOB,
|
|
|
- type: OnboardingInputSectionType.boolean
|
|
|
|
|
|
|
+ type: OnboardingInputSectionType.boolean,
|
|
|
|
|
+ disabled: state.enableSMBAlways
|
|
|
)
|
|
)
|
|
|
case .enableSMBWithTempTarget:
|
|
case .enableSMBWithTempTarget:
|
|
|
algorithmSettingsInput(
|
|
algorithmSettingsInput(
|
|
@@ -82,7 +83,8 @@ struct AlgorithmSubstepView<Substep: AlgorithmSubstepProtocol & RawRepresentable
|
|
|
setting: nil,
|
|
setting: nil,
|
|
|
decimalValue: $decimalPlaceholder,
|
|
decimalValue: $decimalPlaceholder,
|
|
|
booleanValue: $state.enableSMBWithTempTarget,
|
|
booleanValue: $state.enableSMBWithTempTarget,
|
|
|
- type: OnboardingInputSectionType.boolean
|
|
|
|
|
|
|
+ type: OnboardingInputSectionType.boolean,
|
|
|
|
|
+ disabled: state.enableSMBAlways
|
|
|
)
|
|
)
|
|
|
case .enableSMBAfterCarbs:
|
|
case .enableSMBAfterCarbs:
|
|
|
algorithmSettingsInput(
|
|
algorithmSettingsInput(
|
|
@@ -91,7 +93,8 @@ struct AlgorithmSubstepView<Substep: AlgorithmSubstepProtocol & RawRepresentable
|
|
|
setting: nil,
|
|
setting: nil,
|
|
|
decimalValue: $decimalPlaceholder,
|
|
decimalValue: $decimalPlaceholder,
|
|
|
booleanValue: $state.enableSMBAfterCarbs,
|
|
booleanValue: $state.enableSMBAfterCarbs,
|
|
|
- type: OnboardingInputSectionType.boolean
|
|
|
|
|
|
|
+ type: OnboardingInputSectionType.boolean,
|
|
|
|
|
+ disabled: state.enableSMBAlways
|
|
|
)
|
|
)
|
|
|
case .enableSMBWithHighGlucoseTarget:
|
|
case .enableSMBWithHighGlucoseTarget:
|
|
|
algorithmSettingsInput(
|
|
algorithmSettingsInput(
|
|
@@ -100,7 +103,8 @@ struct AlgorithmSubstepView<Substep: AlgorithmSubstepProtocol & RawRepresentable
|
|
|
setting: nil,
|
|
setting: nil,
|
|
|
decimalValue: $decimalPlaceholder,
|
|
decimalValue: $decimalPlaceholder,
|
|
|
booleanValue: $state.enableSMBWithHighGlucoseTarget,
|
|
booleanValue: $state.enableSMBWithHighGlucoseTarget,
|
|
|
- type: OnboardingInputSectionType.boolean
|
|
|
|
|
|
|
+ type: OnboardingInputSectionType.boolean,
|
|
|
|
|
+ disabled: state.enableSMBAlways
|
|
|
)
|
|
)
|
|
|
if state.enableSMBWithHighGlucoseTarget {
|
|
if state.enableSMBWithHighGlucoseTarget {
|
|
|
algorithmSettingsInput(
|
|
algorithmSettingsInput(
|
|
@@ -109,7 +113,8 @@ struct AlgorithmSubstepView<Substep: AlgorithmSubstepProtocol & RawRepresentable
|
|
|
setting: settingsProvider.settings.enableSMB_high_bg_target,
|
|
setting: settingsProvider.settings.enableSMB_high_bg_target,
|
|
|
decimalValue: $state.highGlucoseTarget,
|
|
decimalValue: $state.highGlucoseTarget,
|
|
|
booleanValue: $booleanPlaceholder,
|
|
booleanValue: $booleanPlaceholder,
|
|
|
- type: OnboardingInputSectionType.decimal
|
|
|
|
|
|
|
+ type: OnboardingInputSectionType.decimal,
|
|
|
|
|
+ disabled: state.enableSMBAlways
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
case .allowSMBWithHighTempTarget:
|
|
case .allowSMBWithHighTempTarget:
|
|
@@ -211,7 +216,8 @@ struct AlgorithmSubstepView<Substep: AlgorithmSubstepProtocol & RawRepresentable
|
|
|
.padding(.horizontal)
|
|
.padding(.horizontal)
|
|
|
.multilineTextAlignment(.leading)
|
|
.multilineTextAlignment(.leading)
|
|
|
}
|
|
}
|
|
|
- .onDisappear {
|
|
|
|
|
|
|
+ .onAppear {
|
|
|
|
|
+ // Ensure picker view is closed, when switching between setting steps
|
|
|
shouldDisplayPicker = false
|
|
shouldDisplayPicker = false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -222,46 +228,58 @@ struct AlgorithmSubstepView<Substep: AlgorithmSubstepProtocol & RawRepresentable
|
|
|
setting: PickerSetting?,
|
|
setting: PickerSetting?,
|
|
|
decimalValue: Binding<Decimal>,
|
|
decimalValue: Binding<Decimal>,
|
|
|
booleanValue: Binding<Bool>,
|
|
booleanValue: Binding<Bool>,
|
|
|
- type: OnboardingInputSectionType
|
|
|
|
|
|
|
+ type: OnboardingInputSectionType,
|
|
|
|
|
+ disabled: Bool = false /// parameter only relevant for `Enable SMB Always` dependent settings
|
|
|
) -> some View {
|
|
) -> some View {
|
|
|
VStack {
|
|
VStack {
|
|
|
- switch type {
|
|
|
|
|
- case .boolean:
|
|
|
|
|
- Toggle(isOn: booleanValue) {
|
|
|
|
|
- Text(label)
|
|
|
|
|
- }.tint(Color.accentColor)
|
|
|
|
|
- case .decimal:
|
|
|
|
|
- Group {
|
|
|
|
|
- HStack {
|
|
|
|
|
|
|
+ VStack {
|
|
|
|
|
+ switch type {
|
|
|
|
|
+ case .boolean:
|
|
|
|
|
+ Toggle(isOn: booleanValue) {
|
|
|
Text(label)
|
|
Text(label)
|
|
|
- Spacer()
|
|
|
|
|
- displayText(for: substep, decimalValue: decimalValue.wrappedValue, units: state.units)
|
|
|
|
|
- .foregroundColor(!displayPicker.wrappedValue ? .primary : .accentColor)
|
|
|
|
|
- .onTapGesture {
|
|
|
|
|
- displayPicker.wrappedValue.toggle()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }.tint(Color.accentColor)
|
|
|
|
|
+ .disabled(disabled)
|
|
|
|
|
+ case .decimal:
|
|
|
|
|
+ Group {
|
|
|
|
|
+ HStack {
|
|
|
|
|
+ Text(label)
|
|
|
|
|
+ Spacer()
|
|
|
|
|
+ displayText(for: substep, decimalValue: decimalValue.wrappedValue, units: state.units)
|
|
|
|
|
+ .foregroundColor(!displayPicker.wrappedValue ? .primary : .accentColor)
|
|
|
|
|
+ .onTapGesture {
|
|
|
|
|
+ displayPicker.wrappedValue.toggle()
|
|
|
|
|
+ }
|
|
|
|
|
+ }.disabled(disabled)
|
|
|
|
|
|
|
|
- if displayPicker.wrappedValue {
|
|
|
|
|
- Picker(selection: decimalValue, label: Text(label)) {
|
|
|
|
|
- if let setting = setting {
|
|
|
|
|
- ForEach(
|
|
|
|
|
- settingsProvider.generatePickerValues(from: setting, units: state.units),
|
|
|
|
|
- id: \.self
|
|
|
|
|
- ) { value in
|
|
|
|
|
- displayText(for: substep, decimalValue: value, units: state.units).tag(value)
|
|
|
|
|
|
|
+ if displayPicker.wrappedValue {
|
|
|
|
|
+ Picker(selection: decimalValue, label: Text(label)) {
|
|
|
|
|
+ if let setting = setting {
|
|
|
|
|
+ ForEach(
|
|
|
|
|
+ settingsProvider.generatePickerValues(from: setting, units: state.units),
|
|
|
|
|
+ id: \.self
|
|
|
|
|
+ ) { value in
|
|
|
|
|
+ displayText(for: substep, decimalValue: value, units: state.units).tag(value)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ .disabled(disabled)
|
|
|
|
|
+ .pickerStyle(WheelPickerStyle())
|
|
|
|
|
+ .frame(maxWidth: .infinity)
|
|
|
}
|
|
}
|
|
|
- .pickerStyle(WheelPickerStyle())
|
|
|
|
|
- .frame(maxWidth: .infinity)
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ .padding()
|
|
|
|
|
+ .background(Color.chart.opacity(0.65))
|
|
|
|
|
+ .cornerRadius(10)
|
|
|
|
|
+
|
|
|
|
|
+ if disabled {
|
|
|
|
|
+ Text("Setting cannot be changed for as long as \"Enable SMB Always\" is enabled.")
|
|
|
|
|
+ .font(.footnote)
|
|
|
|
|
+ .foregroundColor(Color.orange)
|
|
|
|
|
+ .padding()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- .padding()
|
|
|
|
|
- .background(Color.chart.opacity(0.65))
|
|
|
|
|
- .cornerRadius(10)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private func displayText(for substep: Substep, decimalValue: Decimal, units: GlucoseUnits) -> Text {
|
|
private func displayText(for substep: Substep, decimalValue: Decimal, units: GlucoseUnits) -> Text {
|