ContactTrickEntry.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import SwiftUI
  2. struct ContactTrickEntry: Hashable, Sendable {
  3. var layout: ContactTrickLayout = .single
  4. var ring: ContactTrickLargeRing = .none
  5. var primary: ContactTrickValue = .glucose
  6. var top: ContactTrickValue = .none
  7. var bottom: ContactTrickValue = .none
  8. var contactId: String? = nil
  9. var darkMode: Bool = true
  10. var ringWidth: RingWidth = .regular
  11. var ringGap: RingGap = .small
  12. var fontSize: FontSize = .regular
  13. var secondaryFontSize: FontSize = .small
  14. var fontWeight: Font.Weight = .medium
  15. var fontWidth: Font.Width = .standard
  16. // Convert `fontWeight` to a String for Core Data storage
  17. var fontWeightString: String {
  18. fontWeight.asString
  19. }
  20. // Initialize `fontWeight` from a String
  21. static func fontWeight(from string: String) -> Font.Weight {
  22. Font.Weight.fromString(string)
  23. }
  24. // Convert `fontWidth` to a String for Core Data storage
  25. var fontWidthString: String {
  26. fontWidth.asString
  27. }
  28. // Initialize `fontWidth` from a String
  29. static func fontWidth(from string: String) -> Font.Width {
  30. Font.Width.fromString(string)
  31. }
  32. enum FontSize: Int, Codable, Sendable {
  33. case tiny = 200
  34. case small = 250
  35. case regular = 300
  36. case large = 400
  37. var displayName: String {
  38. switch self {
  39. case .tiny: return "Tiny"
  40. case .small: return "Small"
  41. case .regular: return "Regular"
  42. case .large: return "Large"
  43. }
  44. }
  45. }
  46. enum RingWidth: Int, Codable, Sendable {
  47. case tiny = 3
  48. case small = 5
  49. case regular = 7
  50. case medium = 10
  51. case large = 15
  52. var displayName: String {
  53. switch self {
  54. case .tiny: return "Tiny"
  55. case .small: return "Small"
  56. case .regular: return "Regular"
  57. case .medium: return "Medium"
  58. case .large: return "Large"
  59. }
  60. }
  61. }
  62. enum RingGap: Int, Codable, Sendable {
  63. case tiny = 1
  64. case small = 2
  65. case regular = 3
  66. case medium = 4
  67. case large = 5
  68. var displayName: String {
  69. switch self {
  70. case .tiny: return "Tiny"
  71. case .small: return "Small"
  72. case .regular: return "Regular"
  73. case .medium: return "Medium"
  74. case .large: return "Large"
  75. }
  76. }
  77. }
  78. }
  79. protocol ContactTrickObserver: Sendable {
  80. // TODO: is this required?
  81. // func basalProfileDidChange(_ entry: [ContactTrickEntry])
  82. }
  83. enum ContactTrickValue: String, JSON, CaseIterable, Identifiable, Codable {
  84. var id: String { rawValue }
  85. case none
  86. case glucose
  87. case eventualBG
  88. case delta
  89. case trend
  90. case lastLoopDate
  91. case cob
  92. case iob
  93. case ring
  94. var displayName: String {
  95. switch self {
  96. case .none:
  97. return NSLocalizedString("NoneContactValue", comment: "")
  98. case .glucose:
  99. return NSLocalizedString("GlucoseContactValue", comment: "")
  100. case .eventualBG:
  101. return NSLocalizedString("EventualBGContactValue", comment: "")
  102. case .delta:
  103. return NSLocalizedString("DeltaContactValue", comment: "")
  104. case .trend:
  105. return NSLocalizedString("TrendContactValue", comment: "")
  106. case .lastLoopDate:
  107. return NSLocalizedString("LastLoopTimeContactValue", comment: "")
  108. case .cob:
  109. return NSLocalizedString("COBContactValue", comment: "")
  110. case .iob:
  111. return NSLocalizedString("IOBContactValue", comment: "")
  112. case .ring:
  113. return NSLocalizedString("LoopStatusContactValue", comment: "")
  114. }
  115. }
  116. }
  117. enum ContactTrickLayout: String, JSON, CaseIterable, Identifiable, Codable {
  118. var id: String { rawValue }
  119. case single
  120. case split
  121. var displayName: String {
  122. switch self {
  123. case .single:
  124. return NSLocalizedString("Single", comment: "")
  125. case .split:
  126. return NSLocalizedString("Split", comment: "")
  127. }
  128. }
  129. }
  130. enum ContactTrickLargeRing: String, JSON, CaseIterable, Identifiable, Codable {
  131. var id: String { rawValue }
  132. case none
  133. case loop
  134. case iob
  135. case cob
  136. case iobcob
  137. var displayName: String {
  138. switch self {
  139. case .none:
  140. return NSLocalizedString("DontShowRing", comment: "")
  141. case .loop:
  142. return NSLocalizedString("LoopStatusRing", comment: "")
  143. case .iob:
  144. return NSLocalizedString("IOBRing", comment: "")
  145. case .cob:
  146. return NSLocalizedString("COBRing", comment: "")
  147. case .iobcob:
  148. return NSLocalizedString("IOB+COBRing", comment: "")
  149. }
  150. }
  151. }