forked from LoopKit/Loop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiveActivitySettings.swift
More file actions
154 lines (138 loc) · 7.16 KB
/
LiveActivitySettings.swift
File metadata and controls
154 lines (138 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// LiveActivitySettings.swift
// LoopCore
//
// Created by Bastiaan Verhaar on 04/07/2024.
// Copyright © 2024 LoopKit Authors. All rights reserved.
//
import Foundation
public enum BottomRowConfiguration: Codable {
case iob
case cob
case basal
case currentBg
case eventualBg
case deltaBg
case updatedAt
static let defaults: [BottomRowConfiguration] = [.currentBg, .iob, .cob, .updatedAt]
public static let all: [BottomRowConfiguration] = [.iob, .cob, .basal, .currentBg, .eventualBg, .deltaBg, .updatedAt]
public func name() -> String {
switch self {
case .iob:
return NSLocalizedString("IOB", comment: "Label used for the Insulin On Board value in the Live Activity view")
case .cob:
return NSLocalizedString("COB", comment: "Label used for the Carbohydrates On Board value in the Live Activity view")
case .basal:
return NSLocalizedString("Basal", comment: "Label used for the Basal Rate plot in the Live Activity view")
case .currentBg:
return NSLocalizedString("Current BG", comment: "Label not shown in the Live Activity view")
case .eventualBg:
return NSLocalizedString("Eventual BG", comment: "Label used for the Forecasted Glucose in the Live Activity view")
case .deltaBg:
return NSLocalizedString("Delta", comment: "Label used for the Delta Glucose in the Live Activity view")
case .updatedAt:
return NSLocalizedString("at", comment: "Label used for the Updated time value in the Live Activity view")
}
}
public func description() -> String {
switch self {
case .iob:
return NSLocalizedString("Active Insulin (IOB)", comment: "Description for the Insulin On Board selection for the Live Activity configuration")
case .cob:
return NSLocalizedString("Active Carbohydrates (COB)", comment: "Description for the Carbohydrates On Board selection for the Live Activity configuration")
case .basal:
return NSLocalizedString("Relative Basal Rate (Basal)", comment: "Description for the Basal Rate plot selection for the Live Activity configuration")
case .currentBg:
return NSLocalizedString("Current Glucose (Value and Arrow)", comment: "Description for the Current Glucose selection for the Live Activity configuration")
case .eventualBg:
return NSLocalizedString("Forecasted Glucose (Eventual BG)", comment: "Description for the Forecasted Glucose selection for the Live Activity configuration")
case .deltaBg:
return NSLocalizedString("Delta Glucose (Delta)", comment: "Description for the Delta Glucose selection for the Live Activity configuration")
case .updatedAt:
return NSLocalizedString("Updated (at)", comment: "Description for the Updated time selection for the Live Activity configuration")
}
}
}
public enum LiveActivityMode: Codable, CustomStringConvertible {
case large
case small
public static let all: [LiveActivityMode] = [.large, .small]
public var description: String {
NSLocalizedString("In which mode do you want to render the Live Activity", comment: "")
}
public func name() -> String {
switch self {
case .large:
return NSLocalizedString("Plot and Row", comment: "Short name to choose the Lock Screen display including the the plot")
case .small:
return NSLocalizedString("Row Only", comment: "Short name to choose the Lock Screen display without the plot")
}
}
}
public struct LiveActivitySettings: Codable, Equatable {
public var enabled: Bool
public var mode: LiveActivityMode
public var addPredictiveLine: Bool
public var useLimits: Bool
public var upperLimitChartMmol: Double
public var lowerLimitChartMmol: Double
public var upperLimitChartMg: Double
public var lowerLimitChartMg: Double
public var bottomRowConfiguration: [BottomRowConfiguration]
private enum CodingKeys: String, CodingKey {
case enabled
case mode
case addPredictiveLine
case bottomRowConfiguration
case useLimits
case upperLimitChartMmol
case lowerLimitChartMmol
case upperLimitChartMg
case lowerLimitChartMg
}
private static let defaultUpperLimitMmol = Double(10)
private static let defaultLowerLimitMmol = Double(4)
private static let defaultUpperLimitMg = Double(180)
private static let defaultLowerLimitMg = Double(72)
public init(from decoder:Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
self.enabled = try values.decode(Bool.self, forKey: .enabled)
self.mode = try values.decodeIfPresent(LiveActivityMode.self, forKey: .mode) ?? .large
self.addPredictiveLine = try values.decode(Bool.self, forKey: .addPredictiveLine)
self.useLimits = try values.decode(Bool.self, forKey: .useLimits)
self.upperLimitChartMmol = try values.decode(Double?.self, forKey: .upperLimitChartMmol) ?? LiveActivitySettings.defaultUpperLimitMmol
self.lowerLimitChartMmol = try values.decode(Double?.self, forKey: .lowerLimitChartMmol) ?? LiveActivitySettings.defaultLowerLimitMmol
self.upperLimitChartMg = try values.decode(Double?.self, forKey: .upperLimitChartMg) ?? LiveActivitySettings.defaultUpperLimitMg
self.lowerLimitChartMg = try values.decode(Double?.self, forKey: .lowerLimitChartMg) ?? LiveActivitySettings.defaultLowerLimitMg
self.bottomRowConfiguration = try values.decode([BottomRowConfiguration].self, forKey: .bottomRowConfiguration)
}
public init() {
self.enabled = true
self.mode = .large
self.addPredictiveLine = true
self.useLimits = true
self.upperLimitChartMmol = LiveActivitySettings.defaultUpperLimitMmol
self.lowerLimitChartMmol = LiveActivitySettings.defaultLowerLimitMmol
self.upperLimitChartMg = LiveActivitySettings.defaultUpperLimitMg
self.lowerLimitChartMg = LiveActivitySettings.defaultLowerLimitMg
self.bottomRowConfiguration = BottomRowConfiguration.defaults
}
public static func == (lhs: LiveActivitySettings, rhs: LiveActivitySettings) -> Bool {
return lhs.addPredictiveLine == rhs.addPredictiveLine &&
lhs.mode == rhs.mode &&
lhs.useLimits == rhs.useLimits &&
lhs.lowerLimitChartMmol == rhs.lowerLimitChartMmol &&
lhs.upperLimitChartMmol == rhs.upperLimitChartMmol &&
lhs.lowerLimitChartMg == rhs.lowerLimitChartMg &&
lhs.upperLimitChartMg == rhs.upperLimitChartMg
}
public static func != (lhs: LiveActivitySettings, rhs: LiveActivitySettings) -> Bool {
return lhs.addPredictiveLine != rhs.addPredictiveLine ||
lhs.mode != rhs.mode ||
lhs.useLimits != rhs.useLimits ||
lhs.lowerLimitChartMmol != rhs.lowerLimitChartMmol ||
lhs.upperLimitChartMmol != rhs.upperLimitChartMmol ||
lhs.lowerLimitChartMg != rhs.lowerLimitChartMg ||
lhs.upperLimitChartMg != rhs.upperLimitChartMg
}
}