NotificationsConfigRootView.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import ActivityKit
  2. import Combine
  3. import SwiftUI
  4. import Swinject
  5. extension NotificationsConfig {
  6. struct RootView: BaseView {
  7. let resolver: Resolver
  8. @StateObject var state = StateModel()
  9. @State private var systemLiveActivitySetting: Bool = {
  10. if #available(iOS 16.1, *) {
  11. ActivityAuthorizationInfo().areActivitiesEnabled
  12. } else {
  13. false
  14. }
  15. }()
  16. private var glucoseFormatter: NumberFormatter {
  17. let formatter = NumberFormatter()
  18. formatter.numberStyle = .decimal
  19. formatter.maximumFractionDigits = 0
  20. if state.units == .mmolL {
  21. formatter.maximumFractionDigits = 1
  22. }
  23. formatter.roundingMode = .halfUp
  24. return formatter
  25. }
  26. private var carbsFormatter: NumberFormatter {
  27. let formatter = NumberFormatter()
  28. formatter.numberStyle = .decimal
  29. formatter.maximumFractionDigits = 0
  30. return formatter
  31. }
  32. <<<<<<< HEAD
  33. @Environment(\.colorScheme) var colorScheme
  34. var color: LinearGradient {
  35. colorScheme == .dark ? LinearGradient(
  36. gradient: Gradient(colors: [
  37. Color.bgDarkBlue,
  38. Color.bgDarkerDarkBlue
  39. ]),
  40. startPoint: .top,
  41. endPoint: .bottom
  42. )
  43. :
  44. LinearGradient(
  45. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  46. startPoint: .top,
  47. endPoint: .bottom
  48. )
  49. }
  50. =======
  51. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  52. @ViewBuilder private func liveActivitySection() -> some View {
  53. if #available(iOS 16.2, *) {
  54. Section(
  55. header: Text("Live Activity"),
  56. footer: Text(
  57. liveActivityFooterText()
  58. ),
  59. content: {
  60. if !systemLiveActivitySetting {
  61. Button("Open Settings App") {
  62. UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
  63. }
  64. } else {
  65. <<<<<<< HEAD
  66. Toggle("Show Live Activity", isOn: $state.useLiveActivity) }
  67. =======
  68. Toggle("Show Live Activity", isOn: $state.useLiveActivity)
  69. }
  70. Picker(
  71. selection: $state.lockScreenView,
  72. label: Text("Lock screen widget")
  73. ) {
  74. ForEach(LockScreenView.allCases) { selection in
  75. Text(selection.displayName).tag(selection)
  76. }
  77. }
  78. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  79. }
  80. )
  81. .onReceive(resolver.resolve(LiveActivityBridge.self)!.$systemEnabled, perform: {
  82. self.systemLiveActivitySetting = $0
  83. })
  84. }
  85. }
  86. private func liveActivityFooterText() -> String {
  87. var footer =
  88. "Live activity displays blood glucose live on the lock screen and on the dynamic island (if available)"
  89. if !systemLiveActivitySetting {
  90. footer =
  91. <<<<<<< HEAD
  92. "Live activities are turned OFF in system settings. To enable live activities, go to Settings app -> iAPS -> Turn live Activities ON.\n\n" +
  93. =======
  94. "Live activities are turned OFF in system settings. To enable live activities, go to Settings app -> Trio -> Turn live Activities ON.\n\n" +
  95. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  96. footer
  97. }
  98. return footer
  99. }
  100. var body: some View {
  101. Form {
  102. Section(header: Text("Glucose")) {
  103. Toggle("Show glucose on the app badge", isOn: $state.glucoseBadge)
  104. Toggle("Always Notify Glucose", isOn: $state.glucoseNotificationsAlways)
  105. Toggle("Also play alert sound", isOn: $state.useAlarmSound)
  106. Toggle("Also add source info", isOn: $state.addSourceInfoToGlucoseNotifications)
  107. HStack {
  108. Text("Low")
  109. Spacer()
  110. TextFieldWithToolBar(text: $state.lowGlucose, placeholder: "0", numberFormatter: glucoseFormatter)
  111. Text(state.units.rawValue).foregroundColor(.secondary)
  112. }
  113. HStack {
  114. Text("High")
  115. Spacer()
  116. TextFieldWithToolBar(text: $state.highGlucose, placeholder: "0", numberFormatter: glucoseFormatter)
  117. Text(state.units.rawValue).foregroundColor(.secondary)
  118. }
  119. }
  120. Section(header: Text("Other")) {
  121. HStack {
  122. Text("Carbs Required Threshold")
  123. Spacer()
  124. TextFieldWithToolBar(
  125. text: $state.carbsRequiredThreshold,
  126. placeholder: "0",
  127. numberFormatter: carbsFormatter
  128. )
  129. Text("g").foregroundColor(.secondary)
  130. }
  131. }
  132. liveActivitySection()
  133. <<<<<<< HEAD
  134. }.scrollContentBackground(.hidden).background(color)
  135. =======
  136. }.scrollContentBackground(.hidden)
  137. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  138. .onAppear(perform: configureView)
  139. .navigationBarTitle("Notifications")
  140. .navigationBarTitleDisplayMode(.automatic)
  141. }
  142. }
  143. }