| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import SwiftUI
- import Swinject
- extension BolusCalculatorConfig {
- struct RootView: BaseView {
- let resolver: Resolver
- @StateObject var state = StateModel()
- @State private var shouldDisplayHint: Bool = false
- @State var hintDetent = PresentationDetent.large
- @State var selectedVerboseHint: String?
- @State var hintLabel: String?
- @State private var decimalPlaceholder: Decimal = 0.0
- @State private var booleanPlaceholder: Bool = false
- @Environment(\.colorScheme) var colorScheme
- @Environment(AppState.self) var appState
- private var conversionFormatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- formatter.maximumFractionDigits = 1
- return formatter
- }
- private var formatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- return formatter
- }
- var body: some View {
- Form {
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.displayPresets,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Display Meal Presets"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Display Meal Presets",
- miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
- verboseHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- )
- SettingInputSection(
- decimalValue: $state.overrideFactor,
- booleanValue: $booleanPlaceholder,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Recommended Bolus Percentage"
- }
- ),
- units: state.units,
- type: .decimal("overrideFactor"),
- label: "Recommended Bolus Percentage",
- miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
- verboseHint: "Recommended Bolus Percentage… bla bla bla",
- headerText: "Calculator Configuration"
- )
- SettingInputSection(
- decimalValue: $state.fattyMealFactor,
- booleanValue: $state.fattyMeals,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Fatty Meal Factor"
- }
- ),
- units: state.units,
- type: .conditionalDecimal("fattyMealFactor"),
- label: "Enable Fatty Meal Factor",
- conditionalLabel: "Fatty Meal Factor",
- miniHint: "Lower your bolus recommendation by factor x for fatty meals.",
- verboseHint: "You can add the option in your bolus calculator to apply another (!) customizable factor at the end of the calculation which could be useful for fatty meals, e.g Pizza (default 0.7)."
- )
- SettingInputSection(
- decimalValue: $state.sweetMealFactor,
- booleanValue: $state.sweetMeals,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Super Bolus & Sweet Meal Factor"
- }
- ),
- units: state.units,
- type: .conditionalDecimal("sweetMealFactor"),
- label: "Enable Super Bolus",
- conditionalLabel: "Super Bolus Factor",
- miniHint: "Add x times current scheduled basal rate to your bolus recommendation.",
- verboseHint: "You can enable the super bolus functionality which could be useful when eating sweets/cake etc. Therefore your current basal rate will be added x-times to your bolus recommendation. You can adjust the factor X here, the default is 2 times your current scheduled basal rate."
- )
- }
- .sheet(isPresented: $shouldDisplayHint) {
- SettingInputHintView(
- hintDetent: $hintDetent,
- shouldDisplayHint: $shouldDisplayHint,
- hintLabel: hintLabel ?? "",
- hintText: selectedVerboseHint ?? "",
- sheetTitle: "Help"
- )
- }
- .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
- .onAppear(perform: configureView)
- .navigationBarTitle("Bolus Calculator")
- .navigationBarTitleDisplayMode(.automatic)
- }
- }
- }
|