Skip to content

Commit

Permalink
Merge remote-tracking branch 'diy/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed Feb 1, 2022
2 parents a5cacf8 + d5cbbe4 commit 365317a
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 45 deletions.
8 changes: 8 additions & 0 deletions Common/FeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct FeatureFlagConfiguration: Decodable {
let sensitivityOverridesEnabled: Bool
let simulatedCoreDataEnabled: Bool
let siriEnabled: Bool
let simpleBolusCalculatorEnabled: Bool

fileprivate init() {
// Swift compiler config is inverse, since the default state is enabled.
Expand Down Expand Up @@ -143,6 +144,12 @@ struct FeatureFlagConfiguration: Decodable {
#else
self.siriEnabled = true
#endif

#if SIMPLE_BOLUS_CALCULATOR_ENABLED
self.simpleBolusCalculatorEnabled = true
#else
self.simpleBolusCalculatorEnabled = false
#endif
}
}

Expand All @@ -167,6 +174,7 @@ extension FeatureFlagConfiguration : CustomDebugStringConvertible {
"* automaticBolusEnabled: \(automaticBolusEnabled)",
"* manualDoseEntryEnabled: \(manualDoseEntryEnabled)",
"* allowDebugFeatures: \(allowDebugFeatures)",
"* simpleBolusCalculatorEnabled: \(simpleBolusCalculatorEnabled)",
].joined(separator: "\n")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Loop.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ APP_STORE_URL =
SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited)

// General [DEFAULT]
LOOP_LOCAL_CACHE_DURATION_DAYS = 1
LOOP_LOCAL_CACHE_DURATION_DAYS = 7

// Entitlements [DEFAULT]
LOOP_ENTITLEMENTS = Loop/Loop.entitlements
Expand Down
20 changes: 9 additions & 11 deletions Loop/View Controllers/CarbAbsorptionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif
}

navigationItem.rightBarButtonItem?.isEnabled = isOnboardingComplete

if !closedLoopStatus.isClosedLoop {
allowEditing = false
}

allowEditing = closedLoopStatus.isClosedLoop || !FeatureFlags.simpleBolusCalculatorEnabled

if allowEditing {
navigationItem.rightBarButtonItems?.append(editButtonItem)
}
Expand Down Expand Up @@ -504,19 +502,19 @@ final class CarbAbsorptionViewController: LoopChartsTableViewController, Identif

@IBAction func presentCarbEntryScreen() {
let navigationWrapper: UINavigationController
if closedLoopStatus.isClosedLoop {
if FeatureFlags.simpleBolusCalculatorEnabled && !closedLoopStatus.isClosedLoop {
let viewModel = SimpleBolusViewModel(delegate: deviceManager, displayMealEntry: true)
let bolusEntryView = SimpleBolusView(viewModel: viewModel).environmentObject(DisplayGlucoseUnitObservable(displayGlucoseUnit: .milligramsPerDeciliter))
let hostingController = DismissibleHostingController(rootView: bolusEntryView, isModalInPresentation: false)
navigationWrapper = UINavigationController(rootViewController: hostingController)
hostingController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: navigationWrapper, action: #selector(dismissWithAnimation))
} else {
let carbEntryViewController = UIStoryboard(name: "Main", bundle: Bundle(for: AppDelegate.self)).instantiateViewController(withIdentifier: "CarbEntryViewController") as! CarbEntryViewController

carbEntryViewController.deviceManager = deviceManager
carbEntryViewController.defaultAbsorptionTimes = deviceManager.carbStore.defaultAbsorptionTimes
carbEntryViewController.preferredCarbUnit = deviceManager.carbStore.preferredUnit
navigationWrapper = UINavigationController(rootViewController: carbEntryViewController)
} else {
let viewModel = SimpleBolusViewModel(delegate: deviceManager, displayMealEntry: true)
let bolusEntryView = SimpleBolusView(viewModel: viewModel)
let hostingController = DismissibleHostingController(rootView: bolusEntryView, isModalInPresentation: false)
navigationWrapper = UINavigationController(rootViewController: hostingController)
hostingController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: navigationWrapper, action: #selector(dismissWithAnimation))
}
self.present(navigationWrapper, animated: true)
}
Expand Down
45 changes: 21 additions & 24 deletions Loop/View Controllers/StatusTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ final class StatusTableViewController: LoopChartsTableViewController {
let isClosedLoop = closedLoopStatus.isClosedLoop

toolbarItems![0].isEnabled = isPumpOnboarded
toolbarItems![2].isEnabled = isPumpOnboarded && isClosedLoop
toolbarItems![2].isEnabled = isPumpOnboarded && (isClosedLoop || !FeatureFlags.simpleBolusCalculatorEnabled)
toolbarItems![4].isEnabled = isPumpOnboarded
toolbarItems![6].isEnabled = isPumpOnboarded
toolbarItems![8].isEnabled = true
Expand Down Expand Up @@ -494,7 +494,7 @@ final class StatusTableViewController: LoopChartsTableViewController {
if let glucoseSamples = glucoseSamples {
self.statusCharts.setGlucoseValues(glucoseSamples)
}
if isClosedLoop, let predictedGlucoseValues = predictedGlucoseValues {
if (isClosedLoop || !FeatureFlags.simpleBolusCalculatorEnabled), let predictedGlucoseValues = predictedGlucoseValues {
self.statusCharts.setPredictedGlucoseValues(predictedGlucoseValues)
} else {
self.statusCharts.setPredictedGlucoseValues([])
Expand Down Expand Up @@ -782,7 +782,7 @@ final class StatusTableViewController: LoopChartsTableViewController {
}

private func updatePreMealModeAvailability(isClosedLoop: Bool) {
let allowed = onboardingManager.isComplete && isClosedLoop
let allowed = onboardingManager.isComplete && (isClosedLoop || !FeatureFlags.simpleBolusCalculatorEnabled)
toolbarItems![2] = createPreMealButtonItem(selected: preMealMode ?? false && allowed, isEnabled: allowed)
}

Expand Down Expand Up @@ -859,7 +859,7 @@ final class StatusTableViewController: LoopChartsTableViewController {
return self?.statusCharts.glucoseChart(withFrame: frame)?.view
})
cell.setTitleLabelText(label: NSLocalizedString("Glucose", comment: "The title of the glucose and prediction graph"))
cell.doesNavigate = closedLoopStatus.isClosedLoop
cell.doesNavigate = closedLoopStatus.isClosedLoop || !FeatureFlags.simpleBolusCalculatorEnabled
case .iob:
cell.setChartGenerator(generator: { [weak self] (frame) in
return self?.statusCharts.iobChart(withFrame: frame)?.view
Expand Down Expand Up @@ -1014,7 +1014,7 @@ final class StatusTableViewController: LoopChartsTableViewController {
} else {
cell.setSubtitleLabel(label: nil)
}
cell.doesNavigate = closedLoopStatus.isClosedLoop
cell.doesNavigate = closedLoopStatus.isClosedLoop || !FeatureFlags.simpleBolusCalculatorEnabled
case .iob:
if let currentIOB = currentIOBDescription {
cell.setSubtitleLabel(label: currentIOB)
Expand Down Expand Up @@ -1134,7 +1134,7 @@ final class StatusTableViewController: LoopChartsTableViewController {
case .charts:
switch ChartRow(rawValue: indexPath.row)! {
case .glucose:
if closedLoopStatus.isClosedLoop {
if closedLoopStatus.isClosedLoop || !FeatureFlags.simpleBolusCalculatorEnabled {
performSegue(withIdentifier: PredictionTableViewController.className, sender: indexPath)
}
case .iob, .dose:
Expand Down Expand Up @@ -1212,7 +1212,16 @@ final class StatusTableViewController: LoopChartsTableViewController {

func presentCarbEntryScreen(_ activity: NSUserActivity?) {
let navigationWrapper: UINavigationController
if closedLoopStatus.isClosedLoop {
if FeatureFlags.simpleBolusCalculatorEnabled && !closedLoopStatus.isClosedLoop {
let viewModel = SimpleBolusViewModel(delegate: deviceManager, displayMealEntry: true)
if let activity = activity {
viewModel.restoreUserActivityState(activity)
}
let bolusEntryView = SimpleBolusView(viewModel: viewModel).environmentObject(deviceManager.displayGlucoseUnitObservable)
let hostingController = DismissibleHostingController(rootView: bolusEntryView, isModalInPresentation: false)
navigationWrapper = UINavigationController(rootViewController: hostingController)
hostingController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: navigationWrapper, action: #selector(dismissWithAnimation))
} else {
let carbEntryViewController = UIStoryboard(name: "Main", bundle: Bundle(for: AppDelegate.self)).instantiateViewController(withIdentifier: "CarbEntryViewController") as! CarbEntryViewController

carbEntryViewController.deviceManager = deviceManager
Expand All @@ -1222,15 +1231,6 @@ final class StatusTableViewController: LoopChartsTableViewController {
carbEntryViewController.restoreUserActivityState(activity)
}
navigationWrapper = UINavigationController(rootViewController: carbEntryViewController)
} else {
let viewModel = SimpleBolusViewModel(delegate: deviceManager, displayMealEntry: true)
if let activity = activity {
viewModel.restoreUserActivityState(activity)
}
let bolusEntryView = SimpleBolusView(viewModel: viewModel).environmentObject(deviceManager.displayGlucoseUnitObservable)
let hostingController = DismissibleHostingController(rootView: bolusEntryView, isModalInPresentation: false)
navigationWrapper = UINavigationController(rootViewController: hostingController)
hostingController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: navigationWrapper, action: #selector(dismissWithAnimation))
}
present(navigationWrapper, animated: true)
}
Expand All @@ -1241,14 +1241,14 @@ final class StatusTableViewController: LoopChartsTableViewController {

func presentBolusEntryView(enableManualGlucoseEntry: Bool = false) {
let hostingController: DismissibleHostingController
if closedLoopStatus.isClosedLoop {
let viewModel = BolusEntryViewModel(delegate: deviceManager, isManualGlucoseEntryEnabled: enableManualGlucoseEntry)
let bolusEntryView = BolusEntryView(viewModel: viewModel).environmentObject(deviceManager.displayGlucoseUnitObservable)
hostingController = DismissibleHostingController(rootView: bolusEntryView, isModalInPresentation: false)
} else {
if FeatureFlags.simpleBolusCalculatorEnabled && !closedLoopStatus.isClosedLoop {
let viewModel = SimpleBolusViewModel(delegate: deviceManager, displayMealEntry: false)
let bolusEntryView = SimpleBolusView(viewModel: viewModel).environmentObject(deviceManager.displayGlucoseUnitObservable)
hostingController = DismissibleHostingController(rootView: bolusEntryView, isModalInPresentation: false)
} else {
let viewModel = BolusEntryViewModel(delegate: deviceManager, isManualGlucoseEntryEnabled: enableManualGlucoseEntry)
let bolusEntryView = BolusEntryView(viewModel: viewModel).environmentObject(deviceManager.displayGlucoseUnitObservable)
hostingController = DismissibleHostingController(rootView: bolusEntryView, isModalInPresentation: false)
}
let navigationWrapper = UINavigationController(rootViewController: hostingController)
hostingController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: navigationWrapper, action: #selector(dismissWithAnimation))
Expand Down Expand Up @@ -1663,9 +1663,6 @@ final class StatusTableViewController: LoopChartsTableViewController {
guard FeatureFlags.allowDebugFeatures else {
return
}
guard FeatureFlags.scenariosEnabled || FeatureFlags.simulatedCoreDataEnabled || FeatureFlags.mockTherapySettingsEnabled else {
fatalError("\(#function) should be invoked only when scenarios, simulated core data, or mock therapy settings are enabled")
}

let actionSheet = UIAlertController(title: "Debug", message: nil, preferredStyle: .actionSheet)
if FeatureFlags.scenariosEnabled {
Expand Down
1 change: 1 addition & 0 deletions Loop/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ extension SettingsView {
.sheet(isPresented: $therapySettingsIsPresented) {
TherapySettingsView(mode: .settings,
viewModel: TherapySettingsViewModel(therapySettings: self.viewModel.therapySettings(),
sensitivityOverridesEnabled: FeatureFlags.sensitivityOverridesEnabled,
delegate: self.viewModel.therapySettingsViewModelDelegate))
.environmentObject(displayGlucoseUnitObservable)
.environment(\.dismissAction, self.dismiss)
Expand Down
2 changes: 1 addition & 1 deletion Loop/Views/SimpleBolusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ struct SimpleBolusView: View {
private func closedLoopOffInformationalModal() -> SwiftUI.Alert {
return SwiftUI.Alert(
title: Text("Closed Loop OFF", comment: "Alert title for closed loop off informational modal"),
message: Text(String(format: NSLocalizedString("%1$@ is operating with Closed Loop in the OFF position. Your pump and CGM will continue operating, but your basal insulin will not adjust automatically.", comment: "Alert message for closed loop off informational modal. (1: app name)"), Bundle.main.bundleDisplayName))
message: Text(String(format: NSLocalizedString("%1$@ is operating with Closed Loop in the OFF position. Your pump and CGM will continue operating, but the app will not adjust dosing automatically.", comment: "Alert message for closed loop off informational modal. (1: app name)"), Bundle.main.bundleDisplayName))
)
}

Expand Down
2 changes: 1 addition & 1 deletion LoopUI/Views/LoopCompletionHUDView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extension LoopCompletionHUDView {
case .fresh:
if loopStateView.open {
return (title: LocalizedString("Closed Loop OFF", comment: "Title of green open loop OFF message"),
message: String(format: NSLocalizedString("\n%1$@ is operating with Closed Loop in the OFF position. Your pump and CGM will continue operating, but your basal insulin will not adjust automatically.\n\nTap Settings to toggle Closed Loop ON if you wish for the app to automate your insulin.", comment: "Green closed loop OFF message (1: app name)"), Bundle.main.bundleDisplayName))
message: String(format: NSLocalizedString("\n%1$@ is operating with Closed Loop in the OFF position. Your pump and CGM will continue operating, but the app will not adjust dosing automatically.\n\nTap Settings to toggle Closed Loop ON if you wish for the app to automate your insulin.", comment: "Green closed loop OFF message (1: app name)"), Bundle.main.bundleDisplayName))
} else {
return (title: LocalizedString("Closed Loop ON", comment: "Title of green closed loop ON message"),
message: String(format: LocalizedString("\n%1$@ is operating with Closed Loop in the ON position. Your last loop was successful within the last 5 minutes.", comment: "Green closed loop ON message (1: app name)"), Bundle.main.bundleDisplayName))
Expand Down
2 changes: 1 addition & 1 deletion WatchApp Extension/Controllers/ActionHUDController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class ActionHUDController: HUDInterfaceController {

let isClosedLoop = loopManager.activeContext?.isClosedLoop ?? false

if !isClosedLoop {
if !isClosedLoop && FeatureFlags.simpleBolusCalculatorEnabled {
preMealButtonGroup.state = .disabled
overrideButtonGroup.state = .disabled
carbsButtonGroup.state = .disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ extension CarbAndBolusFlow {
return 2
case .size42mm:
return 0
case .size40mm:
case .size40mm, .size41mm:
return configuration == .carbEntry ? 7 : 19
case .size44mm:
case .size44mm, .size45mm:
return 5
}
}
Expand Down Expand Up @@ -228,9 +228,9 @@ extension CarbAndBolusFlow {
switch sizeClass {
case .size38mm, .size42mm:
return 0
case .size40mm:
case .size40mm, .size41mm:
return 20
case .size44mm:
case .size44mm, .size45mm:
return 27
}
}
Expand Down
12 changes: 10 additions & 2 deletions WatchApp Extension/Views/Extensions/Environment+SizeClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ extension WKInterfaceDevice {
case size38mm
case size42mm

// Apple Watch Series 4 and later
// Apple Watch Series 4 - 6
case size40mm
case size44mm

// Apple Watch Series 7
case size41mm
case size45mm
}

var sizeClass: SizeClass {
if let sizeClass = SizeClass(screenSize: screenBounds.size) {
return sizeClass
} else {
assertionFailure("Unrecognized Watch size \(screenBounds.size)")
//assertionFailure("Unrecognized Watch size \(screenBounds.size)")
return .size40mm
}
}
Expand All @@ -61,8 +65,12 @@ extension WKInterfaceDevice.SizeClass {
return CGSize(width: 156, height: 195)
case .size40mm:
return CGSize(width: 162, height: 197)
case .size41mm:
return CGSize(width: 176, height: 215)
case .size44mm:
return CGSize(width: 184, height: 224)
case .size45mm:
return CGSize(width: 198, height: 242)
}
}

Expand Down

0 comments on commit 365317a

Please sign in to comment.