AutotuneConfigRootView.swift 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //Commenting out Autotune from Settings Menu until full removal is complete
  2. //import SwiftUI
  3. //import Swinject
  4. //
  5. //extension AutotuneConfig {
  6. //struct RootView: BaseView {
  7. //let resolver: Resolver
  8. //@StateObject var state = StateModel()
  9. //
  10. //@State private var shouldDisplayHint: Bool = false
  11. //@State var hintDetent = PresentationDetent.large
  12. //@State var selectedVerboseHint: AnyView?
  13. //@State var hintLabel: String?
  14. //@State private var decimalPlaceholder: Decimal = 0.0
  15. //@State private var booleanPlaceholder: Bool = false
  16. //
  17. //@State var replaceAlert = false
  18. //
  19. //@Environment(\.colorScheme) var colorScheme
  20. //var color: LinearGradient {
  21. //colorScheme == .dark ? LinearGradient(
  22. //gradient: Gradient(colors: [
  23. //Color.bgDarkBlue,
  24. //Color.bgDarkerDarkBlue
  25. //]),
  26. //startPoint: .top,
  27. //endPoint: .bottom
  28. //)
  29. //:
  30. //LinearGradient(
  31. //gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  32. //startPoint: .top,
  33. //endPoint: .bottom
  34. //)
  35. //}
  36. //private var isfFormatter: NumberFormatter {
  37. //let formatter = NumberFormatter()
  38. //formatter.numberStyle = .decimal
  39. //formatter.maximumFractionDigits = 2
  40. //return formatter
  41. //}
  42. //private var rateFormatter: NumberFormatter {
  43. //let formatter = NumberFormatter()
  44. //formatter.numberStyle = .decimal
  45. //formatter.maximumFractionDigits = 2
  46. //return formatter
  47. //}
  48. //private var dateFormatter: DateFormatter {
  49. //let formatter = DateFormatter()
  50. //formatter.dateStyle = .medium
  51. //formatter.timeStyle = .short
  52. //return formatter
  53. //}
  54. //var body: some View {
  55. //Form {
  56. //SettingInputSection(
  57. //decimalValue: $decimalPlaceholder,
  58. //booleanValue: $state.useAutotune,
  59. //shouldDisplayHint: $shouldDisplayHint,
  60. //selectedVerboseHint: Binding(
  61. //get: { selectedVerboseHint },
  62. //set: {
  63. //selectedVerboseHint = $0.map { AnyView($0) }
  64. //hintLabel = "Use Autotune"
  65. //}
  66. //),
  67. //units: state.units,
  68. //type: .boolean,
  69. //label: "Use Autotune",
  70. //miniHint: "It is not advised to use Autotune with Trio",
  71. //verboseHint: VStack(spacing: 10) {
  72. //Text("Default: OFF").bold()
  73. //VStack(alignment: .leading, spacing: 10) {
  74. //Text("It is not advised to use Autotune with Trio").bold()
  75. //Text("Autotune is not designed to work with Trio. It is best to keep Autotune off and do not use it.")
  76. //}
  77. //},
  78. //headerText: "Data-driven Adjustments"
  79. //)
  80. //
  81. //if state.useAutotune {
  82. //SettingInputSection(
  83. //decimalValue: $decimalPlaceholder,
  84. //booleanValue: $state.onlyAutotuneBasals,
  85. //shouldDisplayHint: $shouldDisplayHint,
  86. //selectedVerboseHint: Binding(
  87. //get: { selectedVerboseHint },
  88. //set: {
  89. //selectedVerboseHint = $0.map { AnyView($0) }
  90. //hintLabel = "Only Autotune Basal Insulin"
  91. //}
  92. //),
  93. //units: state.units,
  94. //type: .boolean,
  95. //label: "Only Autotune Basal Insulin",
  96. //miniHint: "Restricts Autotune adjustments to only basal settings",
  97. //verboseHint: Text("Restricts Autotune adjustments to only basal settings.")
  98. //)
  99. //}
  100. //Section(
  101. //header: HStack {
  102. //Text("Last run")
  103. //Spacer()
  104. //Text(dateFormatter.string(from: state.publishedDate))
  105. //},
  106. //content: {
  107. //Button {
  108. //state.run()
  109. //} label: {
  110. //Text("Run now")
  111. //}
  112. //.frame(maxWidth: .infinity, alignment: .center)
  113. //.listRowBackground(Color(.systemBlue))
  114. //.tint(.white)
  115. //}
  116. //)
  117. //
  118. //if let autotune = state.autotune {
  119. //if !state.onlyAutotuneBasals {
  120. //Section {
  121. //HStack {
  122. //Text("Carb ratio")
  123. //Spacer()
  124. //Text(isfFormatter.string(from: autotune.carbRatio as NSNumber) ?? "0")
  125. //Text("g/U").foregroundColor(.secondary)
  126. //}
  127. //HStack {
  128. //Text("Sensitivity")
  129. //Spacer()
  130. //if state.units == .mmolL {
  131. //Text(isfFormatter.string(from: autotune.sensitivity.asMmolL as NSNumber) ?? "0")
  132. //} else {
  133. //Text(isfFormatter.string(from: autotune.sensitivity as NSNumber) ?? "0")
  134. //}
  135. //Text(state.units.rawValue + "/U").foregroundColor(.secondary)
  136. //}
  137. //}
  138. //.listRowBackground(Color.chart)
  139. //}
  140. //
  141. //Section(header: Text("Basal profile")) {
  142. //ForEach(0 ..< autotune.basalProfile.count, id: \.self) { index in
  143. //HStack {
  144. //Text(autotune.basalProfile[index].start).foregroundColor(.secondary)
  145. //Spacer()
  146. //Text(rateFormatter.string(from: autotune.basalProfile[index].rate as NSNumber) ?? "0")
  147. //Text("U/hr").foregroundColor(.secondary)
  148. //}
  149. //}
  150. //HStack {
  151. //Text("Total")
  152. //.bold()
  153. //.foregroundColor(.primary)
  154. //Spacer()
  155. //Text(rateFormatter.string(from: autotune.basalProfile.reduce(0) { $0 + $1.rate } as NSNumber) ?? "0")
  156. //.foregroundColor(.primary) +
  157. //Text(" U/day")
  158. //.foregroundColor(.secondary)
  159. //}
  160. //}
  161. //.listRowBackground(Color.chart)
  162. //Section {
  163. //Button {
  164. //Task {
  165. //await state.delete()
  166. //}
  167. //} label: {
  168. //Text("Delete Autotune Data")
  169. //}
  170. //.frame(maxWidth: .infinity, alignment: .center)
  171. //.listRowBackground(Color(.loopRed))
  172. //.tint(.white)
  173. }
  174. // Section {
  175. // Button {
  176. // replaceAlert = true
  177. // } label: {
  178. // Text("Save as Normal Basal Rates")
  179. // }
  180. // .frame(maxWidth: .infinity, alignment: .center)
  181. // .listRowBackground(Color(.systemGray4))
  182. // .tint(.white)
  183. // }
  184. //}
  185. //}
  186. //.sheet(isPresented: $shouldDisplayHint) {
  187. //SettingInputHintView(
  188. //hintDetent: $hintDetent,
  189. //shouldDisplayHint: $shouldDisplayHint,
  190. //hintLabel: hintLabel ?? "",
  191. //hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  192. //sheetTitle: "Help"
  193. //)
  194. //}
  195. //.scrollContentBackground(.hidden).background(color)
  196. //.onAppear(perform: configureView)
  197. //.navigationTitle("Autotune")
  198. //.navigationBarTitleDisplayMode(.automatic)
  199. //.alert(Text("Are you sure?"), isPresented: $replaceAlert) {
  200. //Button("Yes", action: {
  201. //state.replace()
  202. //replaceAlert.toggle()
  203. //})
  204. //Button("No", action: { replaceAlert.toggle() })
  205. //}
  206. //}
  207. //}
  208. //}