Skip to content

Commit 81a40d2

Browse files
authored
[LOOP-452] Carb Ratio Guardrails (#91)
* Integrate CarbRatioScheduleEditor * Update correction range overrides copy * Feedback from previous PR * Remove outdated comment
1 parent 405b93d commit 81a40d2

File tree

3 files changed

+23
-35
lines changed

3 files changed

+23
-35
lines changed

Loop/View Controllers/SettingsTableViewController.swift

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ final class SettingsTableViewController: UITableViewController {
244244
configCell.detailTextLabel?.text = SettingsTableViewCell.TapToSetString
245245
}
246246
case .correctionRangeOverrides:
247-
// TODO: Copy not final.
248-
configCell.textLabel?.text = NSLocalizedString("Correction Range Overrides", comment: "The title text for the correction range overrides")
247+
configCell.textLabel?.text = NSLocalizedString("Temporary Correction Ranges", comment: "The title text for the correction range overrides")
249248
if dataManager.loopManager.settings.preMealTargetRange == nil {
250249
configCell.detailTextLabel?.text = SettingsTableViewCell.TapToSetString
251250
} else {
@@ -438,21 +437,20 @@ final class SettingsTableViewController: UITableViewController {
438437
let row = ConfigurationRow(rawValue: indexPath.row)!
439438
switch row {
440439
case .carbRatio:
441-
let scheduleVC = DailyQuantityScheduleTableViewController()
442-
443-
scheduleVC.delegate = self
444-
scheduleVC.title = NSLocalizedString("Carb Ratios", comment: "The title of the carb ratios schedule screen")
445-
scheduleVC.unit = .gram()
446-
447-
if let schedule = dataManager.loopManager.carbRatioSchedule {
448-
scheduleVC.timeZone = schedule.timeZone
449-
scheduleVC.scheduleItems = schedule.items
450-
scheduleVC.unit = schedule.unit
451-
} else if let timeZone = dataManager.pumpManager?.status.timeZone {
452-
scheduleVC.timeZone = timeZone
453-
}
440+
let editor = CarbRatioScheduleEditor(
441+
schedule: dataManager.loopManager.carbRatioSchedule,
442+
onSave: { [dataManager] newSchedule in
443+
dataManager?.loopManager.carbRatioSchedule = newSchedule
444+
dataManager?.analyticsServicesManager.didChangeCarbRatioSchedule()
445+
tableView.reloadRows(at: [indexPath], with: .automatic)
446+
}
447+
)
448+
449+
let hostingController = DismissibleHostingController(rootView: editor, onDisappear: {
450+
tableView.deselectRow(at: indexPath, animated: true)
451+
})
454452

455-
show(scheduleVC, sender: sender)
453+
present(hostingController, animated: true)
456454
case .insulinSensitivity:
457455
let glucoseUnit = dataManager.loopManager.insulinSensitivitySchedule?.unit ?? dataManager.loopManager.glucoseStore.preferredUnit ?? HKUnit.milligramsPerDeciliter
458456

@@ -510,7 +508,7 @@ final class SettingsTableViewController: UITableViewController {
510508
tableView.deselectRow(at: indexPath, animated: true)
511509
})
512510

513-
self.present(hostingController, animated: true)
511+
present(hostingController, animated: true)
514512
case .suspendThreshold:
515513
func presentSuspendThresholdEditor(initialValue: HKQuantity?, unit: HKUnit) {
516514
let editor = SuspendThresholdEditor(
@@ -528,7 +526,7 @@ final class SettingsTableViewController: UITableViewController {
528526
tableView.deselectRow(at: indexPath, animated: true)
529527
})
530528

531-
self.present(hostingController, animated: true)
529+
present(hostingController, animated: true)
532530
}
533531

534532
if let minBGGuard = dataManager.loopManager.settings.suspendThreshold {
@@ -795,16 +793,8 @@ extension SettingsTableViewController: DailyValueScheduleTableViewControllerDele
795793
if let controller = controller as? BasalScheduleTableViewController {
796794
dataManager.loopManager.basalRateSchedule = BasalRateSchedule(dailyItems: controller.scheduleItems, timeZone: controller.timeZone)
797795
}
798-
case let row:
799-
if let controller = controller as? DailyQuantityScheduleTableViewController {
800-
switch row {
801-
case .carbRatio:
802-
dataManager.loopManager.carbRatioSchedule = CarbRatioSchedule(unit: controller.unit, dailyItems: controller.scheduleItems, timeZone: controller.timeZone)
803-
dataManager.analyticsServicesManager.didChangeCarbRatioSchedule()
804-
default:
805-
break
806-
}
807-
}
796+
default:
797+
break
808798
}
809799
default:
810800
break

Loop/Views/CorrectionRangeOverridesEditor.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ struct CorrectionRangeOverridesEditor: View {
6464

6565
var body: some View {
6666
ConfigurationPage(
67-
// TODO: Copy not final.
68-
title: Text("Correction Range Overrides", comment: "Title for correction range overrides page"),
67+
title: Text("Temporary\nCorrection Ranges", comment: "Title for temporary correction ranges page"),
6968
isSaveButtonEnabled: value != initialValue,
7069
cards: {
7170
card(for: .preMeal)
@@ -114,7 +113,7 @@ struct CorrectionRangeOverridesEditor: View {
114113
forceDisableAnimations: true
115114
)
116115
},
117-
valuePicker: {
116+
expandedContent: {
118117
GlucoseRangePicker(
119118
range: Binding(
120119
get: { self.value.ranges[preset] ?? self.guardrail(for: preset).recommendedBounds },
@@ -134,12 +133,11 @@ struct CorrectionRangeOverridesEditor: View {
134133
}
135134

136135
private func description(of preset: CorrectionRangeOverrides.Preset) -> Text {
137-
// TODO: Copy not final.
138136
switch preset {
139137
case .preMeal:
140-
return Text("When Pre-Meal Mode is active, the app adjusts insulin delivery in an effort to bring your glucose into your pre-meal correction range.", comment: "Description of pre-meal mode")
138+
return Text("Temporarily lower your glucose target before a meal to impact post-meal glucose spikes.", comment: "Description of pre-meal mode")
141139
case .workout:
142-
return Text("When Workout Mode is active, the app adjusts insulin delivery in an effort to bring your glucose into your workout correction range.", comment: "Description of workout mode")
140+
return Text("Temporarily raise your glucose target before, during, or after physical activity to reduce the risk of low glucose events.", comment: "Description of workout mode")
143141
}
144142
}
145143

Loop/Views/SuspendThresholdEditor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct SuspendThresholdEditor: View {
7575
forceDisableAnimations: true
7676
)
7777
},
78-
valuePicker: {
78+
expandedContent: {
7979
GlucoseValuePicker(
8080
value: $value.animation(),
8181
unit: unit,

0 commit comments

Comments
 (0)