| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- 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
- @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("Home View Settings"),
- content: {
- VStack {
- Toggle("Show X-Axis Grid Lines", isOn: $state.xGridLines)
- Toggle("Show Y-Axis Grid Line", 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(.bottom)
- }
- ).listRowBackground(Color.chart)
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.rulerMarks,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Show Low and High Thresholds"
- }
- ),
- 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"
- )
- Section {
- VStack {
- HStack {
- Text("Low Threshold")
- Spacer()
- TextFieldWithToolBar(text: $state.low, placeholder: "0", numberFormatter: glucoseFormatter)
- Text(state.units.rawValue).foregroundColor(.secondary)
- }.padding(.top)
- HStack {
- Text("High Threshold")
- Spacer()
- TextFieldWithToolBar(text: $state.high, placeholder: "0", numberFormatter: glucoseFormatter)
- Text(state.units.rawValue).foregroundColor(.secondary)
- }
- 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(.bottom)
- }.listRowBackground(Color.chart)
- SettingInputSection(
- decimalValue: $state.hours,
- booleanValue: $booleanPlaceholder,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "X-Axis Interval Step"
- }
- ),
- type: .decimal,
- 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"
- }
- ),
- 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"
- }
- ),
- 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"
- }
- ),
- type: .conditionalDecimal,
- 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)
- }
- }
- }
|