| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- import LoopKitUI
- import SwiftUI
- import Swinject
- extension CGM {
- struct RootView: BaseView {
- let resolver: Resolver
- let displayClose: Bool
- @StateObject var state = StateModel()
- @State private var setupCGM = false
- @State private var shouldDisplayHint: Bool = false
- @State var hintDetent = PresentationDetent.large
- @State var selectedVerboseHint: String?
- @State var hintLabel: String?
- @State private var decimalPlaceholder: Decimal = 0.0
- @State private var booleanPlaceholder: Bool = false
- @Environment(\.colorScheme) var colorScheme
- @Environment(AppState.self) var appState
- var body: some View {
- NavigationView {
- Form {
- Section(
- header: Text("CGM Integration to Trio"),
- content: {
- VStack {
- Picker("Type", selection: $state.cgmCurrent) {
- ForEach(state.listOfCGM) { type in
- VStack(alignment: .leading) {
- Text(type.displayName)
- Text(type.subtitle).font(.caption).foregroundColor(.secondary)
- }.tag(type)
- }
- }.padding(.top)
- HStack(alignment: .top) {
- Text(
- "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- )
- .font(.footnote)
- .foregroundColor(.secondary)
- .lineLimit(nil)
- Spacer()
- Button(
- action: {
- hintLabel = "Available CGM Types for Trio"
- selectedVerboseHint =
- "CGM Types… bla bla \n\nLorem ipsum dolor sit amet, consetetur sadipscing elitr."
- shouldDisplayHint.toggle()
- },
- label: {
- HStack {
- Image(systemName: "questionmark.circle")
- }
- }
- ).buttonStyle(BorderlessButtonStyle())
- }.padding(.top)
- }.padding(.bottom)
- if let link = state.cgmCurrent.type.externalLink {
- Button {
- UIApplication.shared.open(link, options: [:], completionHandler: nil)
- } label: {
- HStack {
- Text("About this source")
- Spacer()
- Image(systemName: "chevron.right")
- }
- }
- .frame(maxWidth: .infinity, alignment: .leading)
- }
- if state.cgmCurrent.type == .plugin {
- Button {
- setupCGM.toggle()
- } label: {
- HStack {
- Text("CGM Configuration")
- Spacer()
- Image(systemName: "chevron.right")
- }
- }
- .frame(maxWidth: .infinity, alignment: .leading)
- }
- }
- ).listRowBackground(Color.chart)
- if let appURL = state.urlOfApp() {
- Section {
- Button {
- UIApplication.shared.open(appURL, options: [:]) { success in
- if !success {
- self.router.alertMessage
- .send(MessageContent(content: "Unable to open the app", type: .warning))
- }
- }
- }
- label: {
- Label(state.displayNameOfApp() ?? "-", systemImage: "waveform.path.ecg.rectangle").font(.title3)
- .padding() }
- .frame(maxWidth: .infinity, alignment: .center)
- .buttonStyle(.bordered)
- }
- .listRowBackground(Color.clear)
- } else if state.cgmCurrent.type == .nightscout {
- if let url = state.url {
- Section {
- Button {
- UIApplication.shared.open(url, options: [:]) { success in
- if !success {
- self.router.alertMessage
- .send(MessageContent(content: "No URL available", type: .warning))
- }
- }
- }
- label: { Label("Open URL", systemImage: "waveform.path.ecg.rectangle").font(.title3).padding() }
- .frame(maxWidth: .infinity, alignment: .center)
- .buttonStyle(.bordered)
- }
- .listRowBackground(Color.clear)
- } else {
- Section {
- Button {
- state.showModal(for: .nighscoutConfigDirect)
- }
- label: {
- Label("Config Nightscout", systemImage: "waveform.path.ecg.rectangle").font(.title3).padding()
- }
- .frame(maxWidth: .infinity, alignment: .center)
- .buttonStyle(.bordered)
- }
- .listRowBackground(Color.clear)
- }
- }
- if state.cgmCurrent.type == .xdrip {
- Section(header: Text("Heartbeat")) {
- VStack(alignment: .leading) {
- if let cgmTransmitterDeviceAddress = state.cgmTransmitterDeviceAddress {
- Text("CGM address :").padding(.top)
- Text(cgmTransmitterDeviceAddress)
- } else {
- Text("CGM is not used as heartbeat.").padding(.top)
- }
- HStack(alignment: .top) {
- Text(
- "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- )
- .font(.footnote)
- .foregroundColor(.secondary)
- .lineLimit(nil)
- Spacer()
- Button(
- action: {
- hintLabel = "CGM Heartbeat"
- selectedVerboseHint = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
- shouldDisplayHint.toggle()
- },
- label: {
- HStack {
- Image(systemName: "questionmark.circle")
- }
- }
- ).buttonStyle(BorderlessButtonStyle())
- }.padding(.vertical)
- }
- }.listRowBackground(Color.chart)
- }
- if state.cgmCurrent.type == .plugin && state.cgmCurrent.id.contains("Libre") {
- Section {
- Text("Libre Calibrations").navigationLink(to: .calibrations, from: self)
- }.listRowBackground(Color.chart)
- }
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.smoothGlucose,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Smooth Glucose Value"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Smooth Glucose Value",
- miniHint: "Smooth CGM readings using Savitzky–Golay filtering.",
- verboseHint: "Smooth Glucose Value… bla bla bla"
- )
- }
- .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
- .onAppear(perform: configureView)
- .navigationTitle("CGM")
- .navigationBarTitleDisplayMode(.automatic)
- .sheet(isPresented: $shouldDisplayHint) {
- SettingInputHintView(
- hintDetent: $hintDetent,
- shouldDisplayHint: $shouldDisplayHint,
- hintLabel: hintLabel ?? "",
- hintText: selectedVerboseHint ?? "",
- sheetTitle: "Help"
- )
- }
- .sheet(isPresented: $setupCGM) {
- if let cgmFetchManager = state.cgmManager,
- let cgmManager = cgmFetchManager.cgmManager,
- state.cgmCurrent.type == cgmFetchManager.cgmGlucoseSourceType,
- state.cgmCurrent.id == cgmFetchManager.cgmGlucosePluginId
- {
- CGMSettingsView(
- cgmManager: cgmManager,
- bluetoothManager: state.provider.apsManager.bluetoothManager!,
- unit: state.settingsManager.settings.units,
- completionDelegate: state
- )
- } else {
- CGMSetupView(
- CGMType: state.cgmCurrent,
- bluetoothManager: state.provider.apsManager.bluetoothManager!,
- unit: state.settingsManager.settings.units,
- completionDelegate: state,
- setupDelegate: state,
- pluginCGMManager: self.state.pluginCGMManager
- )
- }
- }
- .onChange(of: setupCGM) { _, setupCGM in
- state.setupCGM = setupCGM
- }
- .onChange(of: state.setupCGM) { _, setupCGM in
- self.setupCGM = setupCGM
- }
- .screenNavigation(self)
- }
- }
- }
- }
|