ContactTrickEntry.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. struct ContactTrickEntry: JSON, Equatable, Hashable {
  2. var layout: ContactTrickLayout = .single
  3. var ring1: ContactTrickLargeRing = .none
  4. var primary: ContactTrickValue = .glucose
  5. var top: ContactTrickValue = .none
  6. var bottom: ContactTrickValue = .none
  7. var contactId: String? = nil
  8. var darkMode: Bool = true
  9. var ringWidth: Int = 7
  10. var ringGap: Int = 2
  11. var fontSize: Int = 300
  12. var secondaryFontSize: Int = 250
  13. var fontName: String = "Default Font"
  14. var fontWeight: FontWeight = .medium
  15. var fontTracking: FontTracking = .normal
  16. func isDefaultFont() -> Bool {
  17. fontName == "Default Font"
  18. }
  19. }
  20. protocol ContactTrickObserver {
  21. func basalProfileDidChange(_ entry: [ContactTrickEntry])
  22. }
  23. extension ContactTrickEntry {
  24. private enum CodingKeys: String, CodingKey {
  25. case layout
  26. case ring1
  27. case primary
  28. case top
  29. case bottom
  30. case contactId
  31. case darkMode
  32. case ringWidth
  33. case ringGap
  34. case fontSize
  35. case secondaryFontSize
  36. case fontName
  37. case fontWeight
  38. case fontTracking
  39. }
  40. init(from decoder: Decoder) throws {
  41. let container = try decoder.container(keyedBy: CodingKeys.self)
  42. let layout = try container.decodeIfPresent(ContactTrickLayout.self, forKey: .layout) ?? .single
  43. let ring1 = try container.decodeIfPresent(ContactTrickLargeRing.self, forKey: .ring1) ?? .none
  44. let primary = try container.decodeIfPresent(ContactTrickValue.self, forKey: .primary) ?? .glucose
  45. let top = try container.decodeIfPresent(ContactTrickValue.self, forKey: .top) ?? .none
  46. let bottom = try container.decodeIfPresent(ContactTrickValue.self, forKey: .bottom) ?? .none
  47. let contactId = try container.decodeIfPresent(String.self, forKey: .contactId)
  48. let darkMode = try container.decodeIfPresent(Bool.self, forKey: .darkMode) ?? true
  49. let ringWidth = try container.decodeIfPresent(Int.self, forKey: .ringWidth) ?? 7
  50. let ringGap = try container.decodeIfPresent(Int.self, forKey: .ringGap) ?? 2
  51. let fontSize = try container.decodeIfPresent(Int.self, forKey: .fontSize) ?? 300
  52. let secondaryFontSize = try container.decodeIfPresent(Int.self, forKey: .secondaryFontSize) ?? 250
  53. let fontName = try container.decodeIfPresent(String.self, forKey: .fontName) ?? "Default Font"
  54. let fontWeight = try container.decodeIfPresent(FontWeight.self, forKey: .fontWeight) ?? .regular
  55. let fontTracking = try container.decodeIfPresent(FontTracking.self, forKey: .fontTracking) ?? .normal
  56. self = ContactTrickEntry(
  57. layout: layout,
  58. ring1: ring1,
  59. primary: primary,
  60. top: top,
  61. bottom: bottom,
  62. contactId: contactId,
  63. darkMode: darkMode,
  64. ringWidth: ringWidth,
  65. ringGap: ringGap,
  66. fontSize: fontSize,
  67. secondaryFontSize: secondaryFontSize,
  68. fontName: fontName,
  69. fontWeight: fontWeight,
  70. fontTracking: fontTracking
  71. )
  72. }
  73. }