GlucoseNotificationSettingsRootView.swift 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. type: .boolean,
  62. label: "Show Glucose App Badge",
  63. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  64. verboseHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  65. headerText: "Various Glucose Notifications"
  66. )
  67. SettingInputSection(
  68. decimalValue: $decimalPlaceholder,
  69. booleanValue: $state.glucoseNotificationsAlways,
  70. shouldDisplayHint: $shouldDisplayHint,
  71. selectedVerboseHint: Binding(
  72. get: { selectedVerboseHint },
  73. set: {
  74. selectedVerboseHint = $0
  75. hintLabel = "Always Notify Glucose"
  76. }
  77. ),
  78. type: .boolean,
  79. label: "Always Notify Glucose",
  80. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  81. verboseHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  82. )
  83. SettingInputSection(
  84. decimalValue: $decimalPlaceholder,
  85. booleanValue: $state.useAlarmSound,
  86. shouldDisplayHint: $shouldDisplayHint,
  87. selectedVerboseHint: Binding(
  88. get: { selectedVerboseHint },
  89. set: {
  90. selectedVerboseHint = $0
  91. hintLabel = "Play Alarm Sound"
  92. }
  93. ),
  94. type: .boolean,
  95. label: "Play Alarm Sound",
  96. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  97. verboseHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  98. )
  99. SettingInputSection(
  100. decimalValue: $decimalPlaceholder,
  101. booleanValue: $state.addSourceInfoToGlucoseNotifications,
  102. shouldDisplayHint: $shouldDisplayHint,
  103. selectedVerboseHint: Binding(
  104. get: { selectedVerboseHint },
  105. set: {
  106. selectedVerboseHint = $0
  107. hintLabel = "Add Glucose Source to Alarm"
  108. }
  109. ),
  110. type: .boolean,
  111. label: "Add Glucose Source to Alarm",
  112. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  113. verboseHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  114. )
  115. Section {
  116. HStack {
  117. Text("Low Glucose Alarm Limit")
  118. Spacer()
  119. TextFieldWithToolBar(text: $state.lowGlucose, placeholder: "0", numberFormatter: glucoseFormatter)
  120. Text(state.units.rawValue).foregroundColor(.secondary)
  121. }.padding(.top)
  122. HStack {
  123. Text("High Glucose Alarm Limit")
  124. Spacer()
  125. TextFieldWithToolBar(text: $state.highGlucose, placeholder: "0", numberFormatter: glucoseFormatter)
  126. Text(state.units.rawValue).foregroundColor(.secondary)
  127. }
  128. HStack(alignment: .top) {
  129. Text(
  130. "Set the lower and upper limit for glucose alarms. See hint for more details."
  131. )
  132. .font(.footnote)
  133. .foregroundColor(.secondary)
  134. .lineLimit(nil)
  135. Spacer()
  136. Button(
  137. action: {
  138. hintLabel = "Low and High Glucose Alarm Limits"
  139. selectedVerboseHint =
  140. "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."
  141. shouldDisplayHint.toggle()
  142. },
  143. label: {
  144. HStack {
  145. Image(systemName: "questionmark.circle")
  146. }
  147. }
  148. ).buttonStyle(BorderlessButtonStyle())
  149. }.padding(.vertical)
  150. }
  151. .listRowBackground(Color.chart)
  152. }
  153. .sheet(isPresented: $shouldDisplayHint) {
  154. SettingInputHintView(
  155. hintDetent: $hintDetent,
  156. shouldDisplayHint: $shouldDisplayHint,
  157. hintLabel: hintLabel ?? "",
  158. hintText: selectedVerboseHint ?? "",
  159. sheetTitle: "Help"
  160. )
  161. }
  162. .scrollContentBackground(.hidden).background(color)
  163. .onAppear(perform: configureView)
  164. .navigationBarTitle("Glucose Notifications")
  165. .navigationBarTitleDisplayMode(.automatic)
  166. }
  167. }
  168. }