Przeglądaj źródła

Single target range (#94)

Jon B Mårtensson 3 lat temu
rodzic
commit
e0454e4849

+ 2 - 2
FreeAPS/Sources/Modules/TargetsEditor/TargetsEditorDataFlow.swift

@@ -9,9 +9,9 @@ enum TargetsEditor {
         var highIndex = 0
         var timeIndex = 0
 
-        init(lowIndex: Int, highIndex: Int, timeIndex: Int) {
+        init(lowIndex: Int, highIndex _: Int, timeIndex: Int) {
             self.lowIndex = lowIndex
-            self.highIndex = highIndex
+            highIndex = lowIndex
             self.timeIndex = timeIndex
         }
 

+ 3 - 3
FreeAPS/Sources/Modules/TargetsEditor/TargetsEditorStateModel.swift

@@ -28,7 +28,7 @@ extension TargetsEditor {
             items = profile.targets.map { value in
                 let timeIndex = timeValues.firstIndex(of: Double(value.offset * 60)) ?? 0
                 let lowIndex = rateValues.firstIndex(of: Double(value.low)) ?? 0
-                let highIndex = rateValues.firstIndex(of: Double(value.high)) ?? 0
+                let highIndex = lowIndex
                 return Item(lowIndex: lowIndex, highIndex: highIndex, timeIndex: timeIndex)
             }
         }
@@ -40,7 +40,7 @@ extension TargetsEditor {
             if let last = items.last {
                 time = last.timeIndex + 1
                 low = last.lowIndex
-                high = last.highIndex
+                high = low
             }
 
             let newItem = Item(lowIndex: low, highIndex: high, timeIndex: time)
@@ -56,7 +56,7 @@ extension TargetsEditor {
                 let date = Date(timeIntervalSince1970: self.timeValues[item.timeIndex])
                 let minutes = Int(date.timeIntervalSince1970 / 60)
                 let low = Decimal(self.rateValues[item.lowIndex])
-                let high = Decimal(self.rateValues[item.highIndex])
+                let high = low
                 return BGTargetEntry(low: low, high: high, start: fotmatter.string(from: date), offset: minutes)
             }
             let profile = BGTargets(units: units, userPrefferedUnits: settingsManager.settings.units, targets: targets)

+ 1 - 17
FreeAPS/Sources/Modules/TargetsEditor/View/TargetsEditorRootView.swift

@@ -54,8 +54,7 @@ extension TargetsEditor {
             GeometryReader { geometry in
                 VStack {
                     HStack {
-                        Text("Low target").frame(width: geometry.size.width / 3)
-                        Text("High target").frame(width: geometry.size.width / 3)
+                        Text("Target").frame(width: geometry.size.width / 3)
                         Text("Time").frame(width: geometry.size.width / 3)
                     }
                     HStack(spacing: 0) {
@@ -69,17 +68,6 @@ extension TargetsEditor {
                         }
                         .frame(maxWidth: geometry.size.width / 3)
                         .clipped()
-                        Picker(selection: $state.items[index].highIndex, label: EmptyView()) {
-                            ForEach(0 ..< state.rateValues.count, id: \.self) { i in
-                                Text(
-                                    self.rateFormatter
-                                        .string(from: state.rateValues[i] as NSNumber) ?? ""
-                                ).tag(i)
-                            }
-                        }
-                        .frame(maxWidth: geometry.size.width / 3)
-                        .clipped()
-
                         Picker(selection: $state.items[index].timeIndex, label: EmptyView()) {
                             ForEach(0 ..< state.timeValues.count, id: \.self) { i in
                                 Text(
@@ -106,10 +94,6 @@ extension TargetsEditor {
                             Text(
                                 "\(rateFormatter.string(from: state.rateValues[item.lowIndex] as NSNumber) ?? "0")"
                             )
-                            Text("–").foregroundColor(.secondary)
-                            Text(
-                                "\(rateFormatter.string(from: state.rateValues[item.highIndex] as NSNumber) ?? "0")"
-                            )
                             Text("\(state.units.rawValue)").foregroundColor(.secondary)
                             Spacer()
                             Text("starts at").foregroundColor(.secondary)