PumpSettingsEditorRootView.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import SwiftUI
  2. import Swinject
  3. extension PumpSettingsEditor {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @Environment(\.colorScheme) var colorScheme
  8. var color: LinearGradient {
  9. colorScheme == .dark ? LinearGradient(
  10. gradient: Gradient(colors: [
  11. Color("Background_1"),
  12. Color("Background_1"),
  13. Color("Background_2")
  14. // Color("Background_1")
  15. ]),
  16. startPoint: .top,
  17. endPoint: .bottom
  18. )
  19. :
  20. LinearGradient(
  21. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. }
  26. private var formatter: NumberFormatter {
  27. let formatter = NumberFormatter()
  28. formatter.numberStyle = .decimal
  29. return formatter
  30. }
  31. var body: some View {
  32. Form {
  33. Section(header: Text("Delivery limits")) {
  34. HStack {
  35. Text("Max Basal")
  36. DecimalTextField("U/hr", value: $state.maxBasal, formatter: formatter)
  37. }
  38. HStack {
  39. Text("Max Bolus")
  40. DecimalTextField("U", value: $state.maxBolus, formatter: formatter)
  41. }
  42. HStack {
  43. Text("Max Carbs")
  44. DecimalTextField("g", value: $state.maxCarbs, formatter: formatter)
  45. }
  46. }
  47. Section(header: Text("Duration of Insulin Action")) {
  48. HStack {
  49. Text("DIA")
  50. DecimalTextField("hours", value: $state.dia, formatter: formatter)
  51. }
  52. }
  53. Section {
  54. HStack {
  55. if state.syncInProgress {
  56. ProgressView().padding(.trailing, 10)
  57. }
  58. Button { state.save() }
  59. label: {
  60. Text(state.syncInProgress ? "Saving..." : "Save on Pump")
  61. }
  62. .disabled(state.syncInProgress)
  63. }
  64. }
  65. }
  66. .scrollContentBackground(.hidden).background(color)
  67. .onAppear(perform: configureView)
  68. .navigationTitle("Pump Settings")
  69. .navigationBarTitleDisplayMode(.automatic)
  70. }
  71. }
  72. }