| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- import SwiftUI
- import Swinject
- extension MealSettings {
- 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
- @State private var displayPickerMaxCarbs: Bool = false
- @State private var displayPickerMaxFat: Bool = false
- @State private var displayPickerMaxProtein: 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 intFormater: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.allowsFloats = false
- return formatter
- }
- private var formatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- return formatter
- }
- var body: some View {
- Form {
- Section(
- header: Text("Limits per Entry"),
- content: {
- VStack {
- VStack {
- HStack {
- Text("Max Carbs")
- Spacer()
- Group {
- Text(state.maxCarbs.description)
- .foregroundColor(!displayPickerMaxCarbs ? .primary : .accentColor)
- Text(" g").foregroundColor(.secondary)
- }
- }
- .onTapGesture {
- displayPickerMaxCarbs.toggle()
- }
- }.padding(.top)
- if displayPickerMaxCarbs {
- let setting = PickerSettingsProvider.shared.settings.maxCarbs
- Picker(selection: $state.maxCarbs, label: Text("")) {
- ForEach(
- PickerSettingsProvider.shared.generatePickerValues(from: setting, units: state.units),
- id: \.self
- ) { value in
- Text("\(value.description)").tag(value)
- }
- }
- .pickerStyle(WheelPickerStyle())
- .frame(maxWidth: .infinity)
- }
- if state.useFPUconversion {
- VStack {
- HStack {
- Text("Max Fat")
- Spacer()
- Group {
- Text(state.maxFat.description)
- .foregroundColor(!displayPickerMaxFat ? .primary : .accentColor)
- Text(" g").foregroundColor(.secondary)
- }
- }
- .onTapGesture {
- displayPickerMaxFat.toggle()
- }
- }
- .padding(.top)
- if displayPickerMaxFat {
- let setting = PickerSettingsProvider.shared.settings.maxFat
- Picker(selection: $state.maxFat, label: Text("")) {
- ForEach(
- PickerSettingsProvider.shared.generatePickerValues(from: setting, units: state.units),
- id: \.self
- ) { value in
- Text("\(value.description)").tag(value)
- }
- }
- .pickerStyle(WheelPickerStyle())
- .frame(maxWidth: .infinity)
- }
- VStack {
- HStack {
- Text("Max Protein")
- Spacer()
- Group {
- Text(state.maxProtein.description)
- .foregroundColor(!displayPickerMaxProtein ? .primary : .accentColor)
- Text(" g").foregroundColor(.secondary)
- }
- }
- .onTapGesture {
- displayPickerMaxProtein.toggle()
- }
- }
- .padding(.top)
- if displayPickerMaxProtein {
- let setting = PickerSettingsProvider.shared.settings.maxProtein
- Picker(selection: $state.maxProtein, label: Text("")) {
- ForEach(
- PickerSettingsProvider.shared.generatePickerValues(from: setting, units: state.units),
- id: \.self
- ) { value in
- Text("\(value.description)").tag(value)
- }
- }
- .pickerStyle(WheelPickerStyle())
- .frame(maxWidth: .infinity)
- }
- }
- HStack(alignment: .top) {
- Text(
- "Set limits for entering meals in treatment view."
- )
- .lineLimit(nil)
- .font(.footnote)
- .foregroundColor(.secondary)
- Spacer()
- Button(
- action: {
- hintLabel = "Limits per Entry"
- selectedVerboseHint = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- shouldDisplayHint.toggle()
- },
- label: {
- HStack {
- Image(systemName: "questionmark.circle")
- }
- }
- ).buttonStyle(BorderlessButtonStyle())
- }.padding(.top)
- }.padding(.bottom)
- }
- ).listRowBackground(Color.chart)
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.useFPUconversion,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Display and Allow Fat and Protein Entries"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Display and Allow Fat and Protein Entries",
- miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
- verboseHint: "Allows fat and protein to be converted into future carb equivalents using the Warsaw formula of kilocalories divided by 10.\n\nDefaults: Spread Duration: 8 h, Spread Interval: 30 min, FPU Factor: 0.5, Delay 60 min.",
- headerText: "Fat and Protein"
- )
- if state.useFPUconversion {
- SettingInputSection(
- decimalValue: $state.delay,
- booleanValue: $booleanPlaceholder,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Fat and Protein Delay"
- }
- ),
- units: state.units,
- type: .decimal("delay"),
- label: "Fat and Protein Delay",
- miniHint: "Delay is time from now until the first future carb entry.",
- verboseHint: "X-Axis Interval Step… bla bla bla"
- )
- SettingInputSection(
- decimalValue: $state.timeCap,
- booleanValue: $booleanPlaceholder,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Maximum Duration (hours)"
- }
- ),
- units: state.units,
- type: .decimal("timeCap"),
- label: "Maximum Duration (hours)",
- miniHint: "Carb spread over a maximum number of hours (5-12).",
- verboseHint: "This spreads the carb equivilants over a maximum duration setting that can be configured from 5-12 hours."
- )
- SettingInputSection(
- decimalValue: $state.minuteInterval,
- booleanValue: $booleanPlaceholder,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Spread Interval (minutes)"
- }
- ),
- units: state.units,
- type: .decimal("minuteInterval"),
- label: "Spread Interval (minutes)",
- miniHint: "Interval in minutes is how many minutes are between entries.",
- verboseHint: "Interval in minutes is how many minutes are between entries. The shorter the interval, the smoother the result. 10, 15, 20, 30, or 60 are reasonable choices."
- )
- SettingInputSection(
- decimalValue: $state.individualAdjustmentFactor,
- booleanValue: $booleanPlaceholder,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Fat and Protein Factor"
- }
- ),
- units: state.units,
- type: .decimal("individualAdjustmentFactor"),
- label: "Fat and Protein Factor",
- miniHint: "Influences how many carb equivalents are recorded for fat and protein.",
- verboseHint: "The Fat and Protein Factor influences how much effect the fat and protein has on the entries. 1.0 is full effect (original Warsaw Method) and 0.5 is half effect. Note that you may find that your normal carb ratio needs to increase to a larger number if you begin adding fat and protein entries. For this reason, it is best to start with a factor of about 0.5 to ease into it."
- )
- }
- }
- .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("Meal Settings")
- .navigationBarTitleDisplayMode(.automatic)
- }
- }
- }
|