LowReservoirReminderSetupView.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // LowReservoirReminderSetupView.swift
  3. // OmniKit
  4. //
  5. // Created by Pete Schwamb on 5/17/21.
  6. // Copyright © 2021 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import LoopKitUI
  10. import LoopKit
  11. import HealthKit
  12. import OmniKit
  13. struct LowReservoirReminderSetupView: View {
  14. @State var lowReservoirReminderValue: Int
  15. public var valueChanged: ((_ value: Int) -> Void)?
  16. public var continueButtonTapped: (() -> Void)?
  17. public var cancelButtonTapped: (() -> Void)?
  18. var insulinQuantityFormatter = QuantityFormatter(for: .internationalUnit())
  19. func formatValue(_ value: Int) -> String {
  20. return insulinQuantityFormatter.string(from: HKQuantity(unit: .internationalUnit(), doubleValue: Double(value)), for: .internationalUnit()) ?? ""
  21. }
  22. var body: some View {
  23. GuidePage(content: {
  24. VStack(alignment: .leading, spacing: 15) {
  25. Text(LocalizedString("The App notifies you when the amount of insulin in the Pod reaches this level (50-10 U).\n\nScroll to set the number of units at which you would like to be reminded.", comment: "Description text on LowReservoirReminderSetupView"))
  26. Divider()
  27. HStack {
  28. Text(LocalizedString("Low Reservoir", comment: "Label text for low reservoir value row"))
  29. Spacer()
  30. Text(formatValue(lowReservoirReminderValue))
  31. }
  32. picker
  33. }
  34. .padding(.vertical, 8)
  35. }) {
  36. VStack {
  37. Button(action: {
  38. continueButtonTapped?()
  39. }) {
  40. Text(LocalizedString("Next", comment: "Text of continue button on ExpirationReminderSetupView"))
  41. .actionButtonStyle(.primary)
  42. }
  43. }
  44. .padding()
  45. }
  46. .navigationBarTitle(LocalizedString("Low Reservoir", comment: "navigation bar title for low reservoir"), displayMode: .automatic)
  47. .toolbar {
  48. ToolbarItem(placement: .navigationBarTrailing) {
  49. Button(LocalizedString("Cancel", comment: "Cancel button title"), action: {
  50. cancelButtonTapped?()
  51. })
  52. }
  53. }
  54. }
  55. private var picker: some View {
  56. Picker("", selection: $lowReservoirReminderValue) {
  57. ForEach(Pod.allowedLowReservoirReminderValues, id: \.self) { value in
  58. Text(formatValue(value))
  59. }
  60. }.pickerStyle(WheelPickerStyle())
  61. .onChange(of: lowReservoirReminderValue) { value in
  62. valueChanged?(value)
  63. }
  64. }
  65. }
  66. struct LowReservoirReminderSetupView_Previews: PreviewProvider {
  67. static var previews: some View {
  68. LowReservoirReminderSetupView(lowReservoirReminderValue: 10)
  69. }
  70. }