LiveActivitySettingsStateModel.swift 2.0 KB

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