OmniPodPumpManager+UI.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // OmniPodPumpManager+UI.swift
  3. // OmniKitUI
  4. //
  5. // Created by Pete Schwamb on 8/4/18.
  6. // Copyright © 2018 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. import SwiftUI
  10. import UIKit
  11. import LoopKit
  12. import LoopKitUI
  13. import OmniKit
  14. import RileyLinkKitUI
  15. extension OmnipodPumpManager: PumpManagerUI {
  16. static public func setupViewController(insulinTintColor: Color, guidanceColors: GuidanceColors, allowedInsulinTypes: [InsulinType]) -> (UIViewController & PumpManagerSetupViewController & CompletionNotifying) {
  17. let navVC = OmnipodPumpManagerSetupViewController.instantiateFromStoryboard()
  18. let insulinSelectionView = InsulinTypeConfirmation(initialValue: .novolog, supportedInsulinTypes: allowedInsulinTypes) { (confirmedType) in
  19. navVC.insulinType = confirmedType
  20. let nextViewController = navVC.storyboard?.instantiateViewController(identifier: "RileyLinkSetup") as! RileyLinkSetupTableViewController
  21. navVC.pushViewController(nextViewController, animated: true)
  22. }
  23. let rootVC = UIHostingController(rootView: insulinSelectionView)
  24. rootVC.title = "Insulin Type"
  25. navVC.pushViewController(rootVC, animated: false)
  26. navVC.navigationBar.backgroundColor = .secondarySystemBackground
  27. return navVC
  28. }
  29. public func settingsViewController(insulinTintColor: Color, guidanceColors: GuidanceColors, allowedInsulinTypes: [InsulinType]) -> (UIViewController & CompletionNotifying) {
  30. let settings = OmnipodSettingsViewController(pumpManager: self)
  31. let nav = SettingsNavigationViewController(rootViewController: settings)
  32. return nav
  33. }
  34. public func deliveryUncertaintyRecoveryViewController(insulinTintColor: Color, guidanceColors: GuidanceColors) -> (UIViewController & CompletionNotifying) {
  35. // Return settings for now; uncertainty recovery not implemented yet
  36. let settings = OmnipodSettingsViewController(pumpManager: self)
  37. let nav = SettingsNavigationViewController(rootViewController: settings)
  38. return nav
  39. }
  40. public var smallImage: UIImage? {
  41. return UIImage(named: "Pod", in: Bundle(for: OmnipodSettingsViewController.self), compatibleWith: nil)!
  42. }
  43. public func hudProvider(insulinTintColor: Color, guidanceColors: GuidanceColors, allowedInsulinTypes: [InsulinType]) -> HUDProvider? {
  44. return OmnipodHUDProvider(pumpManager: self, insulinTintColor: insulinTintColor, guidanceColors: guidanceColors, allowedInsulinTypes: allowedInsulinTypes)
  45. }
  46. public static func createHUDView(rawValue: HUDProvider.HUDViewRawState) -> LevelHUDView? {
  47. return OmnipodHUDProvider.createHUDView(rawValue: rawValue)
  48. }
  49. }
  50. // MARK: - DeliveryLimitSettingsTableViewControllerSyncSource
  51. extension OmnipodPumpManager {
  52. public func syncDeliveryLimitSettings(for viewController: DeliveryLimitSettingsTableViewController, completion: @escaping (DeliveryLimitSettingsResult) -> Void) {
  53. guard let maxBasalRate = viewController.maximumBasalRatePerHour,
  54. let maxBolus = viewController.maximumBolus else
  55. {
  56. completion(.failure(PodCommsError.invalidData))
  57. return
  58. }
  59. completion(.success(maximumBasalRatePerHour: maxBasalRate, maximumBolus: maxBolus))
  60. }
  61. public func syncButtonTitle(for viewController: DeliveryLimitSettingsTableViewController) -> String {
  62. return LocalizedString("Save", comment: "Title of button to save delivery limit settings") }
  63. public func syncButtonDetailText(for viewController: DeliveryLimitSettingsTableViewController) -> String? {
  64. return nil
  65. }
  66. public func deliveryLimitSettingsTableViewControllerIsReadOnly(_ viewController: DeliveryLimitSettingsTableViewController) -> Bool {
  67. return false
  68. }
  69. }
  70. // MARK: - BasalScheduleTableViewControllerSyncSource
  71. extension OmnipodPumpManager {
  72. public func syncScheduleValues(for viewController: BasalScheduleTableViewController, completion: @escaping (SyncBasalScheduleResult<Double>) -> Void) {
  73. syncBasalRateSchedule(items: viewController.scheduleItems) { result in
  74. switch result {
  75. case .success(let schedule):
  76. completion(.success(scheduleItems: schedule.items, timeZone: schedule.timeZone))
  77. case .failure(let error):
  78. completion(.failure(error))
  79. }
  80. }
  81. }
  82. public func syncButtonTitle(for viewController: BasalScheduleTableViewController) -> String {
  83. if self.hasActivePod {
  84. return LocalizedString("Sync With Pod", comment: "Title of button to sync basal profile from pod")
  85. } else {
  86. return LocalizedString("Save", comment: "Title of button to sync basal profile when no pod paired")
  87. }
  88. }
  89. public func syncButtonDetailText(for viewController: BasalScheduleTableViewController) -> String? {
  90. return nil
  91. }
  92. public func basalScheduleTableViewControllerIsReadOnly(_ viewController: BasalScheduleTableViewController) -> Bool {
  93. return false
  94. }
  95. }