ContactColorMode.swift 1002 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // LoopFollow
  2. // ContactColorMode.swift
  3. import UIKit
  4. enum ContactColorMode: String, Codable, CaseIterable {
  5. case staticColor = "Static"
  6. case dynamic = "Dynamic"
  7. var displayName: String {
  8. switch self {
  9. case .staticColor:
  10. return String(localized: "Static")
  11. case .dynamic:
  12. return String(localized: "Dynamic (BG Range)")
  13. }
  14. }
  15. /// Returns the appropriate text color based on the mode and BG value
  16. func textColor(for bgValue: Double, staticColor: UIColor) -> UIColor {
  17. switch self {
  18. case .staticColor:
  19. return staticColor
  20. case .dynamic:
  21. let highLine = Storage.shared.highLine.value
  22. let lowLine = Storage.shared.lowLine.value
  23. if bgValue >= highLine {
  24. return .systemYellow
  25. } else if bgValue <= lowLine {
  26. return .systemRed
  27. } else {
  28. return .systemGreen
  29. }
  30. }
  31. }
  32. }