LiveActivitySettingsStateModel.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import Combine
  2. import SwiftUI
  3. extension LiveActivitySettings {
  4. final class StateModel: BaseStateModel<Provider> {
  5. @Injected() var storage: FileStorage!
  6. @Published var units: GlucoseUnits = .mgdL
  7. @Published var useLiveActivity = false
  8. @Published var lockScreenView: LockScreenView = .simple
  9. @Published var showChart: Bool = true
  10. @Published var showCurrentGlucose: Bool = true
  11. @Published var showChangeLabel: Bool = true
  12. @Published var showIOB: Bool = true
  13. @Published var showCOB: Bool = true
  14. @Published var showUpdatedLabel: Bool = true
  15. override func subscribe() {
  16. units = settingsManager.settings.units
  17. subscribeSetting(\.useLiveActivity, on: $useLiveActivity) { useLiveActivity = $0 }
  18. subscribeSetting(\.lockScreenView, on: $lockScreenView) { lockScreenView = $0 }
  19. subscribeSetting(\.showChart, on: $showChart) { showChart = $0 }
  20. subscribeSetting(\.showCurrentGlucose, on: $showCurrentGlucose) { showCurrentGlucose = $0 }
  21. subscribeSetting(\.showChangeLabel, on: $showChangeLabel) { showChangeLabel = $0 }
  22. subscribeSetting(\.showIOB, on: $showIOB) { showIOB = $0 }
  23. subscribeSetting(\.showCOB, on: $showCOB) { showCOB = $0 }
  24. subscribeSetting(\.showUpdatedLabel, on: $showUpdatedLabel) { showUpdatedLabel = $0 }
  25. }
  26. }
  27. }
  28. extension LiveActivitySettings.StateModel: SettingsObserver {
  29. func settingsDidChange(_: FreeAPSSettings) {
  30. units = settingsManager.settings.units
  31. showChart = settingsManager.settings.showChart
  32. showCurrentGlucose = settingsManager.settings.showCurrentGlucose
  33. showChangeLabel = settingsManager.settings.showChangeLabel
  34. showIOB = settingsManager.settings.showIOB
  35. showCOB = settingsManager.settings.showCOB
  36. showUpdatedLabel = settingsManager.settings.showUpdatedLabel
  37. }
  38. }