DeactivatePodView.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // DeactivatePodView.swift
  3. // OmniKit
  4. //
  5. // Created by Pete Schwamb on 3/9/20.
  6. // Copyright © 2021 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import LoopKitUI
  10. import SlideButton
  11. struct DeactivatePodView: View {
  12. @ObservedObject var viewModel: DeactivatePodViewModel
  13. @Environment(\.verticalSizeClass) var verticalSizeClass
  14. @Environment(\.guidanceColors) var guidanceColors
  15. @State private var removePodModalIsPresented: Bool = false
  16. var body: some View {
  17. GuidePage(content: {
  18. VStack {
  19. LeadingImage("Pod")
  20. HStack {
  21. Text(viewModel.instructionText)
  22. .fixedSize(horizontal: false, vertical: true)
  23. Spacer()
  24. }
  25. }
  26. .padding(.bottom, 8)
  27. }) {
  28. VStack {
  29. if viewModel.state.showProgressDetail {
  30. VStack {
  31. viewModel.error.map {ErrorView($0).accessibility(sortPriority: 0)}
  32. if viewModel.error == nil {
  33. VStack {
  34. ProgressIndicatorView(state: viewModel.state.progressState)
  35. if self.viewModel.state.isFinished {
  36. FrameworkLocalText("Deactivated", comment: "Label text showing pod is deactivated")
  37. .bold()
  38. .padding(.top)
  39. }
  40. }
  41. .padding(.bottom, 8)
  42. }
  43. }
  44. .transition(AnyTransition.opacity.combined(with: .move(edge: .bottom)))
  45. }
  46. if viewModel.error != nil {
  47. Button(action: {
  48. if viewModel.podAttachedToBody {
  49. removePodModalIsPresented = true
  50. } else {
  51. viewModel.discardPod()
  52. }
  53. }) {
  54. FrameworkLocalText("Discard Pod", comment: "Text for discard pod button")
  55. .accessibility(identifier: "button_discard_pod_action")
  56. .actionButtonStyle(.destructive)
  57. }
  58. .disabled(viewModel.state.isProcessing)
  59. }
  60. actionButton
  61. .disabled(viewModel.state.isProcessing)
  62. }
  63. .padding()
  64. }
  65. .alert(isPresented: $removePodModalIsPresented) { removePodModal }
  66. .navigationBarTitle(LocalizedString("Deactivate Pod", comment: "navigation bar title for deactivate pod"), displayMode: .automatic)
  67. .navigationBarItems(trailing:
  68. Button("Cancel") {
  69. viewModel.didCancel?()
  70. }
  71. )
  72. }
  73. var removePodModal: Alert {
  74. return Alert(
  75. title: FrameworkLocalText("Remove Pod from Body", comment: "Title for remove pod modal"),
  76. message: FrameworkLocalText("Your Pod may still be delivering Insulin.\nRemove it from your body, then tap “Continue.“", comment: "Alert message body for confirm pod attachment"),
  77. primaryButton: .cancel(),
  78. secondaryButton: .default(FrameworkLocalText("Continue", comment: "Title of button to continue discard"), action: { viewModel.discardPod() })
  79. )
  80. }
  81. var actionText: some View {
  82. Text(self.viewModel.state.actionButtonDescription)
  83. .accessibility(identifier: "button_next_action")
  84. .accessibility(label: Text(self.viewModel.state.actionButtonAccessibilityLabel))
  85. .font(.headline)
  86. }
  87. @ViewBuilder
  88. var actionButton: some View {
  89. if self.viewModel.stateNeedsDeliberateUserAcceptance {
  90. SlideButton(styling: .init(indicatorSize: 60, indicatorColor: Color.red), action: {
  91. self.viewModel.continueButtonTapped()
  92. }) {
  93. actionText
  94. }
  95. } else {
  96. Button(action: {
  97. self.viewModel.continueButtonTapped()
  98. }) {
  99. actionText
  100. .actionButtonStyle(.primary)
  101. }
  102. }
  103. }
  104. }