DexcomSettingsView.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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("Username")
  15. TextField("Enter Username", text: $viewModel.userName)
  16. .textContentType(.username)
  17. .autocapitalization(.none)
  18. .disableAutocorrection(true)
  19. .multilineTextAlignment(.trailing)
  20. }
  21. HStack {
  22. Text("Password")
  23. TogglableSecureInput(
  24. placeholder: "Enter Password",
  25. text: $viewModel.password,
  26. style: .singleLine,
  27. textContentType: .password
  28. )
  29. }
  30. Picker("Server", selection: $viewModel.server) {
  31. Text("US").tag("US")
  32. Text("Outside US").tag("NON-US")
  33. }
  34. .pickerStyle(SegmentedPickerStyle())
  35. }
  36. if viewModel.isFreshSetup {
  37. Section {
  38. Button(action: {
  39. if let onContinueToUnits {
  40. onContinueToUnits()
  41. } else {
  42. showUnitsSetup = true
  43. }
  44. }) {
  45. HStack {
  46. Spacer()
  47. Text("Continue")
  48. .fontWeight(.semibold)
  49. Spacer()
  50. }
  51. }
  52. .buttonStyle(.borderedProminent)
  53. .disabled(!viewModel.hasCredentials)
  54. .listRowBackground(Color.clear)
  55. }
  56. }
  57. importSection
  58. }
  59. .navigationDestination(isPresented: $showUnitsSetup) {
  60. UnitsOnboardingView {
  61. dismiss()
  62. }
  63. }
  64. .preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme)
  65. .navigationBarTitle("Dexcom Settings", displayMode: .inline)
  66. .navigationBarBackButtonHidden(usesModalCloseButton)
  67. }
  68. private var importSection: some View {
  69. Section(header: Text("Import Settings")) {
  70. NavigationLink(destination: ImportExportSettingsView()) {
  71. HStack {
  72. Image(systemName: "square.and.arrow.down")
  73. .foregroundColor(.blue)
  74. Text("Import Settings from QR Code")
  75. }
  76. }
  77. }
  78. }
  79. }