Skip to content

Commit 11333ee

Browse files
author
Rick Pasetto
authored
LOOP-1492: New therapy settings screen (#155)
* checkpoint * PR Feedback
1 parent 15a422a commit 11333ee

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

Loop/Managers/LoopDataManager.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,3 +1816,16 @@ extension LoopDataManager {
18161816
}
18171817
}
18181818
}
1819+
1820+
extension LoopDataManager {
1821+
public var therapySettings: TherapySettings {
1822+
TherapySettings(glucoseTargetRangeSchedule: settings.glucoseTargetRangeSchedule,
1823+
preMealTargetRange: settings.preMealTargetRange,
1824+
workoutTargetRange: settings.legacyWorkoutTargetRange,
1825+
maximumBasalRatePerHour: settings.maximumBasalRatePerHour,
1826+
maximumBolus: settings.maximumBolus,
1827+
suspendThreshold: settings.suspendThreshold,
1828+
insulinSensitivitySchedule: insulinSensitivitySchedule,
1829+
carbRatioSchedule: carbRatioSchedule)
1830+
}
1831+
}

Loop/View Controllers/SettingsTableViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ final class SettingsTableViewController: UITableViewController, IdentifiableClas
743743
notificationsCriticalAlertPermissionsViewModel: notificationsCriticalAlertPermissionsViewModel,
744744
pumpManagerSettingsViewModel: pumpViewModel,
745745
cgmManagerSettingsViewModel: cgmViewModel,
746+
therapySettings: dataManager.loopManager.therapySettings,
746747
initialDosingEnabled: dataManager.loopManager.settings.dosingEnabled,
747748
setDosingEnabled: { [weak self] in
748749
self?.setDosingEnabled($0)

Loop/Views/SettingsView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Copyright © 2020 LoopKit Authors. All rights reserved.
77
//
88

9+
import LoopKit
910
import LoopKitUI
1011
import SwiftUI
1112

@@ -73,7 +74,7 @@ extension SettingsView {
7374

7475
private var therapySettingsSection: some View {
7576
Section(header: SectionHeader(label: NSLocalizedString("Configuration", comment: "The title of the Configuration section in settings"))) {
76-
NavigationLink(destination: Text("Therapy Settings")) {
77+
NavigationLink(destination: TherapySettingsView(viewModel: TherapySettingsViewModel(therapySettings: viewModel.therapySettings))) {
7778
LargeButton(action: { },
7879
includeArrow: false,
7980
imageView: AnyView(Image("Therapy Icon")),
@@ -191,6 +192,7 @@ public struct SettingsView_Previews: PreviewProvider {
191192
notificationsCriticalAlertPermissionsViewModel: NotificationsCriticalAlertPermissionsViewModel(),
192193
pumpManagerSettingsViewModel: DeviceViewModel(),
193194
cgmManagerSettingsViewModel: DeviceViewModel(),
195+
therapySettings: TherapySettings(),
194196
initialDosingEnabled: true)
195197
return Group {
196198
SettingsView(viewModel: viewModel)

Loop/Views/SettingsViewModel.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ public class SettingsViewModel: ObservableObject {
4949

5050
var pumpManagerSettingsViewModel: DeviceViewModel
5151
var cgmManagerSettingsViewModel: DeviceViewModel
52+
var therapySettings: TherapySettings
5253

5354
lazy private var cancellables = Set<AnyCancellable>()
5455

5556
public init(appNameAndVersion: String,
5657
notificationsCriticalAlertPermissionsViewModel: NotificationsCriticalAlertPermissionsViewModel,
5758
pumpManagerSettingsViewModel: DeviceViewModel,
5859
cgmManagerSettingsViewModel: DeviceViewModel,
60+
therapySettings: TherapySettings,
5961
// TODO: This is temporary until I can figure out something cleaner
6062
initialDosingEnabled: Bool,
6163
setDosingEnabled: ((Bool) -> Void)? = nil
@@ -66,7 +68,8 @@ public class SettingsViewModel: ObservableObject {
6668
self.cgmManagerSettingsViewModel = cgmManagerSettingsViewModel
6769
self.setDosingEnabled = setDosingEnabled
6870
self.dosingEnabled = initialDosingEnabled
69-
71+
self.therapySettings = therapySettings
72+
7073
// This strangeness ensures the composed ViewModels' (ObservableObjects') changes get reported to this ViewModel (ObservableObject)
7174
notificationsCriticalAlertPermissionsViewModel.objectWillChange.sink { [weak self] in
7275
self?.objectWillChange.send()

0 commit comments

Comments
 (0)