DexcomSettingsView.swift 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // LoopFollow
  2. // DexcomSettingsView.swift
  3. import SwiftUI
  4. struct DexcomSettingsView: View {
  5. @ObservedObject var viewModel: DexcomSettingsViewModel
  6. var usesModalCloseButton: Bool = false
  7. var onContinueToUnits: (() -> Void)? = nil
  8. @State private var showUnitsSetup = false
  9. @Environment(\.dismiss) private var dismiss
  10. var body: some View {
  11. Form {
  12. Section(header: Text("Dexcom Settings")) {
  13. HStack {
  14. Text("User Name")
  15. TextField("Enter User Name", text: $viewModel.userName)
  16. .autocapitalization(.none)
  17. .disableAutocorrection(true)
  18. .multilineTextAlignment(.trailing)
  19. }
  20. HStack {
  21. Text("Password")
  22. TogglableSecureInput(
  23. placeholder: "Enter Password",
  24. text: $viewModel.password,
  25. style: .singleLine
  26. )
  27. }
  28. Picker("Server", selection: $viewModel.server) {
  29. Text("US").tag("US")
  30. Text("NON-US").tag("NON-US")
  31. }
  32. .pickerStyle(SegmentedPickerStyle())
  33. }
  34. if viewModel.isFreshSetup {
  35. Section {
  36. Button(action: {
  37. if let onContinueToUnits {
  38. onContinueToUnits()
  39. } else {
  40. showUnitsSetup = true
  41. }
  42. }) {
  43. HStack {
  44. Spacer()
  45. Text("Continue")
  46. .fontWeight(.semibold)
  47. Spacer()
  48. }
  49. }
  50. .buttonStyle(.borderedProminent)
  51. .disabled(!viewModel.hasCredentials)
  52. .listRowBackground(Color.clear)
  53. }
  54. }
  55. importSection
  56. }
  57. .navigationDestination(isPresented: $showUnitsSetup) {
  58. UnitsOnboardingView {
  59. dismiss()
  60. }
  61. }
  62. .preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme)
  63. .navigationBarTitle("Dexcom Settings", displayMode: .inline)
  64. .navigationBarBackButtonHidden(usesModalCloseButton)
  65. }
  66. private var importSection: some View {
  67. Section(header: Text("Import Settings")) {
  68. NavigationLink(destination: ImportExportSettingsView()) {
  69. HStack {
  70. Image(systemName: "square.and.arrow.down")
  71. .foregroundColor(.blue)
  72. Text("Import Settings from QR Code")
  73. }
  74. }
  75. }
  76. }
  77. }