Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOOP-1485: add temporary correction range instructional screen + editor #13

Merged
merged 38 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
28c0916
Add delegate
Jul 1, 2020
2c67693
Add correction range editor
Jul 1, 2020
6515313
Add educational screen
Jul 1, 2020
5c3ccc4
Add correction range override editor
Jul 1, 2020
8d823e4
Call step completion delegate when done
Jul 2, 2020
e37d939
Merge branch 'LOOP-1484-CR' into LOOP-1485-temp-cr
Jul 2, 2020
d512942
Add correction range override info screen
Jul 2, 2020
9ba3927
Save workout range as well
Jul 2, 2020
fa1d0bf
Move flow button into setup service, and add setting delegate
Jul 2, 2020
0198d99
Merge branch 'LOOP-1484-CR' into LOOP-1485-temp-cr
Jul 2, 2020
e7726cf
Fix button jumping bug
Jul 2, 2020
94c198f
Merge branch 'LOOP-1484-CR' into LOOP-1485-temp-cr
Jul 2, 2020
82933e3
Clear screen stack if resetting
Jul 3, 2020
e719dff
Merge branch 'novalegra/LOOP-1484' into LOOP-1485-temp-cr
Jul 3, 2020
a27fd30
Use prescription instead of view model to vend settings
Jul 3, 2020
41b36a1
Use TherapySettings instead of LoopSettings
Jul 6, 2020
5508179
Merge remote-tracking branch 'origin/novalegra/LOOP-1484' into LOOP-1…
Jul 6, 2020
fe28d53
PR feedback
Jul 7, 2020
8349362
Merge branch 'LOOP-1484-CR' into LOOP-1485-temp-cr
Jul 7, 2020
f0adf19
Update based on PR
Jul 7, 2020
89ab963
More PR feedback
Jul 7, 2020
eff80e9
Merge branch 'LOOP-1484-CR' into LOOP-1485-temp-cr
Jul 7, 2020
107f81e
PR changes
Jul 7, 2020
3d2c379
Use secondary color if in dark mode, else blue gray
Jul 7, 2020
1f0413a
Merge branch 'LOOP-1484-CR' into LOOP-1485-temp-cr
Jul 7, 2020
cb9b2d6
Make titles appear at correct time
Jul 8, 2020
e85a9a4
Change coloring to .secondary
Jul 8, 2020
01a76f9
Hack to prevent jumping
Jul 8, 2020
aa0405e
Merge branch 'LOOP-1484-CR' into LOOP-1485-temp-cr
Jul 8, 2020
45e3393
Add jumping hack
Jul 8, 2020
4970ba8
Change name & clean up
Jul 8, 2020
fda9362
Merge branch 'LOOP-1484-CR' into LOOP-1485-temp-cr
Jul 8, 2020
673efbf
Remove userHasEdited
Jul 8, 2020
6304a95
Merge remote-tracking branch 'origin/dev' into LOOP-1485-temp-cr
Jul 8, 2020
74b2c51
Change name
Jul 8, 2020
9bd8522
Ensure title isn't cut off
Jul 8, 2020
cc569af
Make variable name more descriptive
Jul 9, 2020
adcc0c3
Merge in Michael's changes
Jul 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion TidepoolService.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
A9DAAD6A22E7E81E00E76C9F /* LoopKitUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9DAAD6922E7E81E00E76C9F /* LoopKitUI.framework */; };
A9DAAD6D22E7EA8F00E76C9F /* IdentifiableClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DAAD6C22E7EA8F00E76C9F /* IdentifiableClass.swift */; };
A9DAAD6F22E7EA9700E76C9F /* NibLoadable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DAAD6E22E7EA9700E76C9F /* NibLoadable.swift */; };
E916F56D24AD3DA600BE3547 /* CorrectionRangeOverrideReview.swift in Sources */ = {isa = PBXBuildFile; fileRef = E916F56C24AD3DA600BE3547 /* CorrectionRangeOverrideReview.swift */; };
E93BA05E24A14CBA00C5D7E6 /* PrescriptionReviewViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93BA05D24A14CBA00C5D7E6 /* PrescriptionReviewViewModel.swift */; };
E93BA06024A15FA800C5D7E6 /* PrescriptionDeviceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93BA05F24A15FA800C5D7E6 /* PrescriptionDeviceView.swift */; };
E93BA06224A29C9C00C5D7E6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E93BA06124A29C9C00C5D7E6 /* Assets.xcassets */; };
Expand Down Expand Up @@ -178,6 +179,7 @@
A9DAAD6922E7E81E00E76C9F /* LoopKitUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = LoopKitUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A9DAAD6C22E7EA8F00E76C9F /* IdentifiableClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifiableClass.swift; sourceTree = "<group>"; };
A9DAAD6E22E7EA9700E76C9F /* NibLoadable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NibLoadable.swift; sourceTree = "<group>"; };
E916F56C24AD3DA600BE3547 /* CorrectionRangeOverrideReview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CorrectionRangeOverrideReview.swift; sourceTree = "<group>"; };
E93BA05D24A14CBA00C5D7E6 /* PrescriptionReviewViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrescriptionReviewViewModel.swift; sourceTree = "<group>"; };
E93BA05F24A15FA800C5D7E6 /* PrescriptionDeviceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrescriptionDeviceView.swift; sourceTree = "<group>"; };
E93BA06124A29C9C00C5D7E6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -417,6 +419,7 @@
E93BA05F24A15FA800C5D7E6 /* PrescriptionDeviceView.swift */,
E991F1B624A548580059281B /* AdaptiveKeyboardPadding.swift */,
E991F1C424AAB25C0059281B /* CorrectionRangeReviewView.swift */,
E916F56C24AD3DA600BE3547 /* CorrectionRangeOverrideReview.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -790,10 +793,11 @@
A9DAAD3422E7CA1A00E76C9F /* LocalizedString.swift in Sources */,
A9DAAD3922E7DEE000E76C9F /* TidepoolService+UI.swift in Sources */,
A9DAAD6F22E7EA9700E76C9F /* NibLoadable.swift in Sources */,
E991F1C524AAB25C0059281B /* CorrectionRangeReviewView.swift in Sources */,
E93BA05E24A14CBA00C5D7E6 /* PrescriptionReviewViewModel.swift in Sources */,
E991F1C524AAB25C0059281B /* CorrectionRangeReviewView.swift in Sources */,
A92E770122E9181500591027 /* TidepoolServiceSetupViewController.swift in Sources */,
A9DAAD3B22E7DEF100E76C9F /* TidepoolServiceSettingsViewController.swift in Sources */,
E916F56D24AD3DA600BE3547 /* CorrectionRangeOverrideReview.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion TidepoolServiceKit/Mocks/MockPrescriptionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class MockPrescriptionManager {
suspendThreshold: GlucoseThreshold(unit: .milligramsPerDeciliter, value: 70),
insulinModel: MockPrescription.InsulinModel(modelType: .rapidAdult, actionDuration: .hours(6), peakActivity: .hours(3)),
preMealTargetRange: DoubleRange(minValue: 80.0, maxValue: 90.0),
workoutTargetRange: DoubleRange(minValue: 80.0, maxValue: 90.0))
workoutTargetRange: DoubleRange(minValue: 130.0, maxValue: 140.0))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ enum PrescriptionReviewScreen {
case reviewDevices
case correctionRangeInfo
case correctionRangeEditor
case correctionRangeOverrideInfo
case correctionRangeOverrideEditor

func next() -> PrescriptionReviewScreen? {
switch self {
Expand All @@ -26,6 +28,10 @@ enum PrescriptionReviewScreen {
case .correctionRangeInfo:
return .correctionRangeEditor
case .correctionRangeEditor:
return .correctionRangeOverrideInfo
case .correctionRangeOverrideInfo:
return .correctionRangeOverrideEditor
case .correctionRangeOverrideEditor:
return nil
}
}
Expand Down Expand Up @@ -96,7 +102,27 @@ class PrescriptionReviewUICoordinator: UINavigationController, CompletionNotifyi
}
let view = CorrectionRangeReviewView(model: viewModel, prescription: prescription)
let hostedView = DismissibleHostingController(rootView: view)
hostedView.navigationItem.largeTitleDisplayMode = .never // fix for jumping
hostedView.navigationItem.largeTitleDisplayMode = .never // TODO: hack to fix jumping, will be removed once editors have titles
return hostedView
case .correctionRangeOverrideInfo:
let exiting: (() -> Void) = { [weak self] in
self?.stepFinished()
}
let view = CorrectionRangeOverrideInformationView(onExit: exiting)
let hostedView = DismissibleHostingController(rootView: view)
hostedView.navigationItem.largeTitleDisplayMode = .always // TODO: hack to fix jumping, will be removed once editors have titles
hostedView.title = LocalizedString("Temporary Ranges", comment: "Title for temporary correction range informational screen") // TODO: make this title be "Temporary Correction Ranges" when SwiftUI supports multi-line titles
return hostedView
case .correctionRangeOverrideEditor:
guard let prescription = viewModel.prescription else {
// Go back to code entry step if we don't have prescription
let view = PrescriptionCodeEntryView(viewModel: viewModel)
return DismissibleHostingController(rootView: view)
}

let view = CorrectionRangeOverrideReview(model: viewModel, prescription: prescription)
let hostedView = DismissibleHostingController(rootView: view)
hostedView.navigationItem.largeTitleDisplayMode = .never // TODO: hack to fix jumping, will be removed once editors have titles
return hostedView
}
}
Expand Down Expand Up @@ -136,8 +162,8 @@ class PrescriptionReviewUICoordinator: UINavigationController, CompletionNotifyi
if let nextStep = currentScreen.next() {
navigate(to: nextStep)
} else {
if let settingDelegate = onReviewFinished {
settingDelegate(viewModel.settings)
if let onReviewFinished = onReviewFinished {
onReviewFinished(viewModel.settings)
}
completionDelegate?.completionNotifyingDidComplete(self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import Foundation
import TidepoolServiceKit
import LoopKit
import LoopKitUI
import HealthKit

class PrescriptionReviewViewModel: ObservableObject {
var didFinishStep: (() -> Void)
Expand Down Expand Up @@ -58,4 +60,9 @@ class PrescriptionReviewViewModel: ObservableObject {
func saveCorrectionRange(range: GlucoseRangeSchedule) {
settings.glucoseTargetRangeSchedule = range
}

func saveCorrectionRangeOverrides(overrides: CorrectionRangeOverrides, unit: HKUnit) {
settings.preMealTargetRange = overrides.preMeal?.doubleRange(for: unit)
settings.workoutTargetRange = overrides.workout?.doubleRange(for: unit)
}
}
44 changes: 44 additions & 0 deletions TidepoolServiceKitUI/Views/CorrectionRangeOverrideReview.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// CorrectionRangeOverrideReviewView.swift
// TidepoolServiceKitUI
//
// Created by Anna Quinlan on 7/1/20.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//

import SwiftUI
import TidepoolServiceKit
import LoopKit
import LoopKitUI

struct CorrectionRangeOverrideReview: View {
@ObservedObject var viewModel: PrescriptionReviewViewModel
let prescription: MockPrescription

init(
model: PrescriptionReviewViewModel,
prescription: MockPrescription
) {
self.viewModel = model
self.prescription = prescription
}

var body: some View {
CorrectionRangeOverridesEditor(
value: CorrectionRangeOverrides(
preMeal: prescription.preMealTargetRange,
workout: prescription.workoutTargetRange,
unit: prescription.bloodGlucoseUnit.hkUnit
),
unit: prescription.bloodGlucoseUnit.hkUnit,
correctionRangeScheduleRange: prescription.glucoseTargetRangeSchedule.scheduleRange(),
minValue: prescription.suspendThreshold.quantity,
onSave: { overrides in
self.viewModel.saveCorrectionRangeOverrides(overrides: overrides, unit: self.prescription.bloodGlucoseUnit.hkUnit)
self.viewModel.didFinishStep()
},
sensitivityOverridesEnabled: false,
mode: .flow
)
}
}
38 changes: 38 additions & 0 deletions TidepoolServiceKitUI/Views/CorrectionRangeReview.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// CorrectionRangeReview.swift
// TidepoolServiceKitUI
//
// Created by Anna Quinlan on 6/29/20.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//
import SwiftUI
import LoopKitUI
import LoopKit
import HealthKit
import TidepoolServiceKit

struct CorrectionRangeReview: View {
@ObservedObject var viewModel: PrescriptionReviewViewModel
let prescription: MockPrescription

init(
model: PrescriptionReviewViewModel,
prescription: MockPrescription
) {
self.viewModel = model
self.prescription = prescription
}

var body: some View {
CorrectionRangeScheduleEditor(
schedule: prescription.glucoseTargetRangeSchedule,
unit: prescription.bloodGlucoseUnit.hkUnit,
minValue: prescription.suspendThreshold.quantity,
onSave: { newSchedule in
self.viewModel.saveCorrectionRange(range: newSchedule)
self.viewModel.didFinishStep()
},
mode: .flow
)
}
}