UserInterfaceSettingsStateModel.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import SwiftUI
  2. extension UserInterfaceSettings {
  3. final class StateModel: BaseStateModel<Provider> {
  4. @Published var overrideHbA1cUnit = false
  5. @Published var low: Decimal = 70
  6. @Published var high: Decimal = 180
  7. @Published var hours: Decimal = 6
  8. @Published var xGridLines = false
  9. @Published var yGridLines: Bool = false
  10. @Published var oneDimensionalGraph = false
  11. @Published var rulerMarks: Bool = true
  12. @Published var totalInsulinDisplayType: TotalInsulinDisplayType = .totalDailyDose
  13. @Published var showCarbsRequiredBadge: Bool = true
  14. @Published var carbsRequiredThreshold: Decimal = 0
  15. var units: GlucoseUnits = .mgdL
  16. override func subscribe() {
  17. let units = settingsManager.settings.units
  18. self.units = units
  19. subscribeSetting(\.overrideHbA1cUnit, on: $overrideHbA1cUnit) { overrideHbA1cUnit = $0 }
  20. subscribeSetting(\.xGridLines, on: $xGridLines) { xGridLines = $0 }
  21. subscribeSetting(\.yGridLines, on: $yGridLines) { yGridLines = $0 }
  22. subscribeSetting(\.rulerMarks, on: $rulerMarks) { rulerMarks = $0 }
  23. subscribeSetting(\.oneDimensionalGraph, on: $oneDimensionalGraph) { oneDimensionalGraph = $0 }
  24. subscribeSetting(\.totalInsulinDisplayType, on: $totalInsulinDisplayType) { totalInsulinDisplayType = $0 }
  25. subscribeSetting(\.low, on: $low) { low = $0 }
  26. subscribeSetting(\.high, on: $high) { high = $0 }
  27. subscribeSetting(\.showCarbsRequiredBadge, on: $showCarbsRequiredBadge) { showCarbsRequiredBadge = $0 }
  28. subscribeSetting(
  29. \.carbsRequiredThreshold,
  30. on: $carbsRequiredThreshold
  31. ) { carbsRequiredThreshold = $0 }
  32. }
  33. }
  34. }
  35. extension UserInterfaceSettings.StateModel: SettingsObserver {
  36. func settingsDidChange(_: FreeAPSSettings) {
  37. units = settingsManager.settings.units
  38. }
  39. }
  40. enum TotalInsulinDisplayType: String, JSON, CaseIterable, Identifiable, Codable, Hashable {
  41. var id: String { rawValue }
  42. case totalDailyDose
  43. case totalInsulinInScope
  44. var displayName: String {
  45. switch self {
  46. case .totalDailyDose:
  47. return NSLocalizedString("Total Daily Dose", comment: "")
  48. case .totalInsulinInScope:
  49. return NSLocalizedString("Total Insulin in Scope", comment: "")
  50. }
  51. }
  52. }