CarbEntryValidationNavigationDelegate.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // CarbEntryNavigationDelegate.swift
  3. // LoopKit
  4. //
  5. // Created by Jaim Zuber on 2/7/17.
  6. // Copyright © 2017 LoopKit Authors. All rights reserved.
  7. //
  8. import Foundation
  9. class CarbEntryNavigationDelegate {
  10. private lazy var validationTitle = LocalizedString("Warning", comment: "Title of an alert containing a validation warning")
  11. private lazy var dismissActionTitle = LocalizedString("com.loudnate.LoopKit.errorAlertActionTitle", value: "OK", comment: "The title of the action used to dismiss an error alert")
  12. func showAbsorptionTimeValidationWarning(for viewController: UIViewController, maxAbsorptionTime: TimeInterval) {
  13. let formatter = DateComponentsFormatter()
  14. formatter.allowedUnits = [.minute]
  15. formatter.unitsStyle = .full
  16. let message = String(
  17. format: LocalizedString("The maximum absorption time is %@", comment: "Alert body displayed absorption time greater than max (1: maximum absorption time)"),
  18. formatter.string(from: maxAbsorptionTime) ?? String(describing: maxAbsorptionTime))
  19. let alert = UIAlertController(title: validationTitle, message: message, preferredStyle: .alert)
  20. let action = UIAlertAction(title: dismissActionTitle, style: .default)
  21. alert.addAction(action)
  22. alert.preferredAction = action
  23. viewController.present(alert, animated: true)
  24. }
  25. func showMaxQuantityValidationWarning(for viewController: UIViewController, maxQuantityGrams: Double) {
  26. let message = String(
  27. format: LocalizedString("The maximum allowed amount is %@ grams", comment: "Alert body displayed for quantity greater than max (1: maximum quantity in grams)"),
  28. NumberFormatter.localizedString(from: NSNumber(value: maxQuantityGrams), number: .none)
  29. )
  30. let alert = UIAlertController(title: validationTitle, message: message, preferredStyle: .alert)
  31. let action = UIAlertAction(title: dismissActionTitle, style: .default)
  32. alert.addAction(action)
  33. alert.preferredAction = action
  34. viewController.present(alert, animated: true)
  35. }
  36. }