| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
- import SwiftUI
- import Swinject
- extension UserInterfaceSettings {
- 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 displayPickerLowThreshold: Bool = false
- @State private var displayPickerHighThreshold: Bool = false
- @AppStorage("colorSchemePreference") private var colorSchemePreference: ColorSchemeOption = .systemDefault
- @Environment(\.colorScheme) var colorScheme
- var color: LinearGradient {
- colorScheme == .dark ? LinearGradient(
- gradient: Gradient(colors: [
- Color.bgDarkBlue,
- Color.bgDarkerDarkBlue
- ]),
- startPoint: .top,
- endPoint: .bottom
- )
- :
- LinearGradient(
- gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
- startPoint: .top,
- endPoint: .bottom
- )
- }
- private var glucoseFormatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- formatter.maximumFractionDigits = 0
- if state.units == .mmolL {
- formatter.maximumFractionDigits = 1
- }
- formatter.roundingMode = .halfUp
- return formatter
- }
- private var carbsFormatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- formatter.maximumFractionDigits = 0
- return formatter
- }
- var body: some View {
- Form {
- Section(
- header: Text("General Appearance"),
- content: {
- VStack {
- Picker(
- selection: $colorSchemePreference,
- label: Text("Color Scheme")
- ) {
- ForEach(ColorSchemeOption.allCases) { selection in
- Text(selection.displayName).tag(selection)
- }
- }.padding(.top)
- HStack(alignment: .top) {
- Text(
- "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- )
- .font(.footnote)
- .foregroundColor(.secondary)
- .lineLimit(nil)
- Spacer()
- Button(
- action: {
- hintLabel = "Color Scheme Preference"
- 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)
- Section {
- VStack {
- Picker(
- selection: $state.glucoseColorScheme,
- label: Text("Glucose Color Scheme")
- ) {
- ForEach(GlucoseColorScheme.allCases) { selection in
- Text(selection.displayName).tag(selection)
- }
- }.padding(.top)
- HStack(alignment: .top) {
- Text(
- "Glucose Scheme Preference ... dynamic or static ... Lorem ipsum dolor"
- )
- .font(.footnote)
- .foregroundColor(.secondary)
- .lineLimit(nil)
- Spacer()
- Button(
- action: {
- hintLabel = "Glucose Scheme Preference"
- selectedVerboseHint =
- "Glucose Scheme Preference... 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)
- Section(
- header: Text("Home View Settings"),
- content: {
- VStack {
- Toggle("Show X-Axis Grid Lines", isOn: $state.xGridLines)
- Toggle("Show Y-Axis Grid Lines", isOn: $state.yGridLines)
- HStack(alignment: .top) {
- Text(
- "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- )
- .font(.footnote)
- .foregroundColor(.secondary)
- .lineLimit(nil)
- Spacer()
- Button(
- action: {
- hintLabel = "Show Main Chart X- and Y-Axis Grid Lines"
- selectedVerboseHint = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- shouldDisplayHint.toggle()
- },
- label: {
- HStack {
- Image(systemName: "questionmark.circle")
- }
- }
- ).buttonStyle(BorderlessButtonStyle())
- }.padding(.top)
- }.padding(.vertical)
- }
- ).listRowBackground(Color.chart)
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.rulerMarks,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Show Low and High Thresholds"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Show Low and High Thresholds",
- miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
- verboseHint: "Display Low and High Thresholds… bla bla bla"
- )
- if state.rulerMarks {
- Section {
- VStack {
- VStack {
- HStack {
- Text("Low Threshold")
- Spacer()
- Group {
- Text(state.units == .mgdL ? state.low.description : state.low.asMmolL.description)
- .foregroundColor(!displayPickerLowThreshold ? .primary : .accentColor)
- Text(state.units == .mgdL ? " mg/dL" : " mmol/L").foregroundColor(.secondary)
- }
- }
- .onTapGesture {
- displayPickerLowThreshold.toggle()
- }
- }
- .padding(.top)
- if displayPickerLowThreshold {
- let setting = PickerSettingsProvider.shared.settings.low
- Picker(selection: $state.low, label: Text("")) {
- ForEach(
- PickerSettingsProvider.shared.generatePickerValues(from: setting, units: state.units),
- id: \.self
- ) { value in
- let displayValue = state.units == .mgdL ? value : value.asMmolL
- Text("\(displayValue.description)").tag(value)
- }
- }
- .pickerStyle(WheelPickerStyle())
- .frame(maxWidth: .infinity)
- }
- VStack {
- HStack {
- Text("High Threshold")
- Spacer()
- Group {
- Text(state.units == .mgdL ? state.high.description : state.high.asMmolL.description)
- .foregroundColor(!displayPickerHighThreshold ? .primary : .accentColor)
- Text(state.units == .mgdL ? " mg/dL" : " mmol/L").foregroundColor(.secondary)
- }
- }
- .onTapGesture {
- displayPickerHighThreshold.toggle()
- }
- }
- .padding(.top)
- if displayPickerHighThreshold {
- let setting = PickerSettingsProvider.shared.settings.high
- Picker(selection: $state.high, label: Text("")) {
- ForEach(
- PickerSettingsProvider.shared.generatePickerValues(from: setting, units: state.units),
- id: \.self
- ) { value in
- let displayValue = state.units == .mgdL ? value : value.asMmolL
- Text("\(displayValue.description)").tag(value)
- }
- }
- .pickerStyle(WheelPickerStyle())
- .frame(maxWidth: .infinity)
- }
- HStack(alignment: .top) {
- Text(
- "Sets thresholds for low and high glucose in home view main chart and statistics view."
- )
- .lineLimit(nil)
- .font(.footnote)
- .foregroundColor(.secondary)
- Spacer()
- Button(
- action: {
- hintLabel = "Low and High Thresholds"
- 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)
- }
- Section {
- VStack {
- Picker(
- selection: $state.forecastDisplayType,
- label: Text("Forecast Display Type")
- ) {
- ForEach(ForecastDisplayType.allCases) { selection in
- Text(selection.displayName).tag(selection)
- }
- }.padding(.top)
- HStack(alignment: .top) {
- Text(
- "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- )
- .font(.footnote)
- .foregroundColor(.secondary)
- .lineLimit(nil)
- Spacer()
- Button(
- action: {
- hintLabel = "Forecast Display Type"
- 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: $state.hours,
- booleanValue: $booleanPlaceholder,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "X-Axis Interval Step"
- }
- ),
- units: state.units,
- type: .decimal("hours"),
- label: "X-Axis Interval Step",
- miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
- verboseHint: "X-Axis Interval Step… bla bla bla"
- )
- Section {
- VStack {
- Picker(
- selection: $state.totalInsulinDisplayType,
- label: Text("Total Insulin Display Type")
- ) {
- ForEach(TotalInsulinDisplayType.allCases) { selection in
- Text(selection.displayName).tag(selection)
- }
- }.padding(.top)
- HStack(alignment: .top) {
- Text(
- "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- )
- .font(.footnote)
- .foregroundColor(.secondary)
- .lineLimit(nil)
- Spacer()
- Button(
- action: {
- hintLabel = "Total Insulin Display Type"
- 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)
- // TODO: this needs to be a picker: mmol/L or %
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.overrideHbA1cUnit,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Override HbA1c Unit"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Override HbA1c Unit",
- miniHint: "Display HbA1c in mmol/L or %. Default is percent.",
- verboseHint: "Override HbA1c Unit… bla bla bla",
- headerText: "Trio Statistics"
- )
- // TODO: this needs to be a picker: choose bar chart or progress bar
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.oneDimensionalGraph,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Standing / Laying TIR Chart"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Standing / Laying TIR Chart",
- miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
- verboseHint: "Standing / Laying TIR Chart… bla bla bla"
- )
- SettingInputSection(
- decimalValue: $state.carbsRequiredThreshold,
- booleanValue: $state.showCarbsRequiredBadge,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Show Carbs Required Badge"
- }
- ),
- units: state.units,
- type: .conditionalDecimal("carbsRequiredThreshold"),
- label: "Show Carbs Required Badge",
- conditionalLabel: "Carbs Required Threshold",
- miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
- verboseHint: "Show Carbs Required Badge… bla bla bla",
- headerText: "Carbs Required Badge"
- )
- }
- .sheet(isPresented: $shouldDisplayHint) {
- SettingInputHintView(
- hintDetent: $hintDetent,
- shouldDisplayHint: $shouldDisplayHint,
- hintLabel: hintLabel ?? "",
- hintText: selectedVerboseHint ?? "",
- sheetTitle: "Help"
- )
- }
- .scrollContentBackground(.hidden).background(color)
- .onAppear(perform: configureView)
- .navigationBarTitle("User Interface")
- .navigationBarTitleDisplayMode(.automatic)
- }
- }
- }
|