| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import SwiftUI
- import Swinject
- extension PumpSettingsEditor {
- struct RootView: BaseView {
- let resolver: Resolver
- @StateObject var state = StateModel()
- @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 formatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- return formatter
- }
- var body: some View {
- Form {
- Section(header: Text("Delivery limits")) {
- HStack {
- Text("Max Basal")
- DecimalTextField("U/hr", value: $state.maxBasal, formatter: formatter)
- }
- HStack {
- Text("Max Bolus")
- DecimalTextField("U", value: $state.maxBolus, formatter: formatter)
- }
- HStack {
- Text("Max Carbs")
- DecimalTextField("g", value: $state.maxCarbs, formatter: formatter)
- }
- }
- Section(header: Text("Duration of Insulin Action")) {
- HStack {
- Text("DIA")
- DecimalTextField("hours", value: $state.dia, formatter: formatter)
- }
- }
- Section {
- HStack {
- if state.syncInProgress {
- ProgressView().padding(.trailing, 10)
- }
- Button { state.save() }
- label: {
- Text(state.syncInProgress ? "Saving..." : "Save on Pump")
- }
- .disabled(state.syncInProgress)
- }
- }
- }
- .scrollContentBackground(.hidden).background(color)
- .onAppear(perform: configureView)
- .navigationTitle("Pump Settings")
- .navigationBarTitleDisplayMode(.automatic)
- }
- }
- }
|