ContactTrickEntry.swift 4.7 KB

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