GlucoseNotificationSettingsRootView.swift 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import ActivityKit
  2. import Combine
  3. import SwiftUI
  4. import Swinject
  5. extension GlucoseNotificationSettings {
  6. struct RootView: BaseView {
  7. let resolver: Resolver
  8. @StateObject var state = StateModel()
  9. @State private var shouldDisplayHint: Bool = false
  10. @State var hintDetent = PresentationDetent.large
  11. @State var selectedVerboseHint: String?
  12. @State var hintLabel: String?
  13. @State private var decimalPlaceholder: Decimal = 0.0
  14. @State private var booleanPlaceholder: Bool = false
  15. private var glucoseFormatter: NumberFormatter {
  16. let formatter = NumberFormatter()
  17. formatter.numberStyle = .decimal
  18. formatter.maximumFractionDigits = 0
  19. if state.units == .mmolL {
  20. formatter.maximumFractionDigits = 1
  21. }
  22. formatter.roundingMode = .halfUp
  23. return formatter
  24. }
  25. private var carbsFormatter: NumberFormatter {
  26. let formatter = NumberFormatter()
  27. formatter.numberStyle = .decimal
  28. formatter.maximumFractionDigits = 0
  29. return formatter
  30. }
  31. @Environment(\.colorScheme) var colorScheme
  32. var color: LinearGradient {
  33. colorScheme == .dark ? LinearGradient(
  34. gradient: Gradient(colors: [
  35. Color.bgDarkBlue,
  36. Color.bgDarkerDarkBlue
  37. ]),
  38. startPoint: .top,
  39. endPoint: .bottom
  40. )
  41. :
  42. LinearGradient(
  43. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  44. startPoint: .top,
  45. endPoint: .bottom
  46. )
  47. }
  48. var body: some View {
  49. Form {
  50. SettingInputSection(
  51. decimalValue: $decimalPlaceholder,
  52. booleanValue: $state.glucoseBadge,
  53. shouldDisplayHint: $shouldDisplayHint,
  54. selectedVerboseHint: Binding(
  55. get: { selectedVerboseHint },
  56. set: {
  57. selectedVerboseHint = $0
  58. hintLabel = "Show Glucose App Badge"
  59. }
  60. ),
  61. units: state.units,
  62. type: .boolean,
  63. label: "Show Glucose App Badge",
  64. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  65. verboseHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  66. headerText: "Various Glucose Notifications"
  67. )
  68. SettingInputSection(
  69. decimalValue: $decimalPlaceholder,
  70. booleanValue: $state.glucoseNotificationsAlways,
  71. shouldDisplayHint: $shouldDisplayHint,
  72. selectedVerboseHint: Binding(
  73. get: { selectedVerboseHint },
  74. set: {
  75. selectedVerboseHint = $0
  76. hintLabel = "Always Notify Glucose"
  77. }
  78. ),
  79. units: state.units,
  80. type: .boolean,
  81. label: "Always Notify Glucose",
  82. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  83. verboseHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  84. )
  85. SettingInputSection(
  86. decimalValue: $decimalPlaceholder,
  87. booleanValue: $state.useAlarmSound,
  88. shouldDisplayHint: $shouldDisplayHint,
  89. selectedVerboseHint: Binding(
  90. get: { selectedVerboseHint },
  91. set: {
  92. selectedVerboseHint = $0
  93. hintLabel = "Play Alarm Sound"
  94. }
  95. ),
  96. units: state.units,
  97. type: .boolean,
  98. label: "Play Alarm Sound",
  99. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  100. verboseHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  101. )
  102. SettingInputSection(
  103. decimalValue: $decimalPlaceholder,
  104. booleanValue: $state.addSourceInfoToGlucoseNotifications,
  105. shouldDisplayHint: $shouldDisplayHint,
  106. selectedVerboseHint: Binding(
  107. get: { selectedVerboseHint },
  108. set: {
  109. selectedVerboseHint = $0
  110. hintLabel = "Add Glucose Source to Alarm"
  111. }
  112. ),
  113. units: state.units,
  114. type: .boolean,
  115. label: "Add Glucose Source to Alarm",
  116. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  117. verboseHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  118. )
  119. Section {
  120. HStack {
  121. Text("Low Glucose Alarm Limit")
  122. Spacer()
  123. TextFieldWithToolBar(text: $state.lowGlucose, placeholder: "0", numberFormatter: glucoseFormatter)
  124. Text(state.units.rawValue).foregroundColor(.secondary)
  125. }.padding(.top)
  126. HStack {
  127. Text("High Glucose Alarm Limit")
  128. Spacer()
  129. TextFieldWithToolBar(text: $state.highGlucose, placeholder: "0", numberFormatter: glucoseFormatter)
  130. Text(state.units.rawValue).foregroundColor(.secondary)
  131. }
  132. HStack(alignment: .top) {
  133. Text(
  134. "Set the lower and upper limit for glucose alarms. See hint for more details."
  135. )
  136. .font(.footnote)
  137. .foregroundColor(.secondary)
  138. .lineLimit(nil)
  139. Spacer()
  140. Button(
  141. action: {
  142. hintLabel = "Low and High Glucose Alarm Limits"
  143. selectedVerboseHint =
  144. "These two settings limit the range outside of which you will be notified via push notifications. If your CGM readings are below 'Low' or above 'High', you will receive a glucose alarm."
  145. shouldDisplayHint.toggle()
  146. },
  147. label: {
  148. HStack {
  149. Image(systemName: "questionmark.circle")
  150. }
  151. }
  152. ).buttonStyle(BorderlessButtonStyle())
  153. }.padding(.vertical)
  154. }
  155. .listRowBackground(Color.chart)
  156. }
  157. .sheet(isPresented: $shouldDisplayHint) {
  158. SettingInputHintView(
  159. hintDetent: $hintDetent,
  160. shouldDisplayHint: $shouldDisplayHint,
  161. hintLabel: hintLabel ?? "",
  162. hintText: selectedVerboseHint ?? "",
  163. sheetTitle: "Help"
  164. )
  165. }
  166. .scrollContentBackground(.hidden).background(color)
  167. .onAppear(perform: configureView)
  168. .navigationBarTitle("Glucose Notifications")
  169. .navigationBarTitleDisplayMode(.automatic)
  170. }
  171. }
  172. }