ManualTempBasalViewModel.swift 749 B

12345678910111213141516171819202122232425
  1. import SwiftUI
  2. extension ManualTempBasal {
  3. class ViewModel<Provider>: BaseViewModel<Provider>, ObservableObject where Provider: ManualTempBasalProvider {
  4. @Injected() var apsManager: APSManager!
  5. @Published var rate: Decimal = 0
  6. @Published var durationIndex = 0
  7. let durationValues = stride(from: 30.0, to: 720.1, by: 30.0).map { $0 }
  8. override func subscribe() {}
  9. func cancel() {
  10. apsManager.enactTempBasal(rate: 0, duration: 0)
  11. showModal(for: nil)
  12. }
  13. func enact() {
  14. let duration = durationValues[durationIndex]
  15. apsManager.enactTempBasal(rate: Double(rate), duration: duration * 60)
  16. showModal(for: nil)
  17. }
  18. }
  19. }