From 05a77f49dcc4e759d7e1cb0e76f3fe8dfa0472ae Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Tue, 19 Mar 2024 10:08:45 -0700 Subject: [PATCH] Minor layout and functionality follow-up (#63) # Minor layout and functionality follow-up ## :gear: Release Notes * Fixed Map Pin in German region * Minor layout issues in Assessments and Edit view * Add configurable minimum step count setting in Account Overview. ## :pencil: Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md). --- PICS/Account/AccountSheet.swift | 23 +++++++++-- PICS/Appointment/AppointmentView.swift | 38 ++++++++++--------- PICS/Appointment/MapView.swift | 5 ++- .../Views/AssessmentTaskSection.swift | 10 ++--- PICS/Assessment/Views/ResultsViz.swift | 2 +- PICS/HealthVisulization/HKVisualization.swift | 7 +++- PICS/Resources/Localizable.xcstrings | 12 ++++-- .../PatientInformation.swift | 15 ++++++++ 8 files changed, 81 insertions(+), 31 deletions(-) diff --git a/PICS/Account/AccountSheet.swift b/PICS/Account/AccountSheet.swift index a056e8e..8e4711f 100644 --- a/PICS/Account/AccountSheet.swift +++ b/PICS/Account/AccountSheet.swift @@ -16,6 +16,9 @@ struct AccountSheet: View { @Environment(Account.self) private var account + @Environment(PatientInformation.self) + private var patientInformation + @Environment(\.accountRequired) private var accountRequired @@ -28,10 +31,10 @@ struct AccountSheet: View { ZStack { if account.signedIn && !isInSetup { AccountOverview(isEditing: $overviewIsEditing) { - NavigationLink { + healthSection + + NavigationLink("LICENSE_INFO_TITLE") { ContributionsList() - } label: { - Text("LICENSE_INFO_TITLE") } } .onDisappear { @@ -61,6 +64,19 @@ struct AccountSheet: View { } } + @ViewBuilder var healthSection: some View { + @Bindable var patientInformation = patientInformation + Section("Health") { + Stepper(value: $patientInformation.minimumStepCount, in: 2000...15000, step: 200) { + VStack(alignment: .leading) { + Text("Recommended Step Count") + Text("\(patientInformation.minimumStepCount) steps") + .foregroundColor(.secondary) + } + } + } + } + var closeButton: some ToolbarContent { ToolbarItem(placement: .cancellationAction) { Button("CLOSE") { @@ -85,6 +101,7 @@ struct AccountSheet: View { #Preview("AccountSheet SignIn") { AccountSheet() + .environment(PatientInformation()) .previewWith { AccountConfiguration { MockUserIdPasswordAccountService() diff --git a/PICS/Appointment/AppointmentView.swift b/PICS/Appointment/AppointmentView.swift index f26fa94..8ec992f 100644 --- a/PICS/Appointment/AppointmentView.swift +++ b/PICS/Appointment/AppointmentView.swift @@ -50,29 +50,33 @@ struct AppointmentView: View { } .navigationTitle("APPOINTMENTS_NAVIGATION_TITLE") .sheet(isPresented: $showingEdit) { + // swiftlint:disable:previous closure_body_length NavigationStack { List { - Text("APPTQ_0") - .font(.headline) - .padding(.top, 32) - DateTimePickerView(selectedDateTime: $appt0User) - .padding(.bottom, 32) - Text("APPTQ_1") - .font(.headline) - DateTimePickerView(selectedDateTime: $appt1User) - .padding(.bottom, 32) - Text("APPTQ_2") - .font(.headline) - DateTimePickerView(selectedDateTime: $appt2User) - .padding(.bottom, 32) - Button("SAVE_BUTTON") { + Section { + Text("APPTQ_0") + .font(.headline) + DateTimePickerView(selectedDateTime: $appt0User) + } + Section { + Text("APPTQ_1") + .font(.headline) + DateTimePickerView(selectedDateTime: $appt1User) + } + Section { + Text("APPTQ_2") + .font(.headline) + DateTimePickerView(selectedDateTime: $appt2User) + } + + Button(action: { patientInformation.storeDates(appt0User, appt1User, appt2User) showingEdit.toggle() + }) { + Text("SAVE_BUTTON") + .frame(maxWidth: .infinity) } - .buttonStyle(.borderedProminent) - Spacer() } - .padding(.horizontal, 20) .navigationTitle("EDIT_APPT_HEADER") .navigationBarTitleDisplayMode(.inline) .toolbar { diff --git a/PICS/Appointment/MapView.swift b/PICS/Appointment/MapView.swift index d468108..b06fb62 100644 --- a/PICS/Appointment/MapView.swift +++ b/PICS/Appointment/MapView.swift @@ -25,7 +25,7 @@ struct MapView: View { private var region: MKCoordinateRegion { MKCoordinateRegion( center: coordinate, - span: MKCoordinateSpan(latitudeDelta: 0.002, longitudeDelta: 0.002) + span: MKCoordinateSpan(latitudeDelta: 0.003, longitudeDelta: 0.003) ) } @@ -74,6 +74,9 @@ struct MapView: View { } } + +#if DEBUG #Preview { MapView() } +#endif diff --git a/PICS/Assessment/Views/AssessmentTaskSection.swift b/PICS/Assessment/Views/AssessmentTaskSection.swift index b65f424..8120ab9 100644 --- a/PICS/Assessment/Views/AssessmentTaskSection.swift +++ b/PICS/Assessment/Views/AssessmentTaskSection.swift @@ -28,7 +28,6 @@ struct AssessmentTaskSection: View { } Divider() - .padding(.bottom, 5) Button(action: { presentingTask = task @@ -39,10 +38,11 @@ struct AssessmentTaskSection: View { Text("Retake Assessment") } } - .multilineTextAlignment(.center) - .foregroundStyle(.accent) - .accessibilityIdentifier(task.accessibilityIdentifier) - .buttonStyle(.plain) // Use style to restrict clickable area. + .padding(.vertical, 4) + .multilineTextAlignment(.center) + .foregroundStyle(.accent) + .accessibilityIdentifier(task.accessibilityIdentifier) + .buttonStyle(.plain) // Use style to restrict clickable area. } } } diff --git a/PICS/Assessment/Views/ResultsViz.swift b/PICS/Assessment/Views/ResultsViz.swift index 632a93c..1d5f807 100644 --- a/PICS/Assessment/Views/ResultsViz.swift +++ b/PICS/Assessment/Views/ResultsViz.swift @@ -113,7 +113,7 @@ struct ResultsViz: View { init(task: AssessmentTask, data: [AssessmentResult]) { self.task = task self.data = data - self.hasErrorCountMetrics = !data.contains { $0.errorCnt != nil } + self.hasErrorCountMetrics = data.contains { $0.errorCnt != nil } } diff --git a/PICS/HealthVisulization/HKVisualization.swift b/PICS/HealthVisulization/HKVisualization.swift index 406c325..bf5d5f3 100644 --- a/PICS/HealthVisulization/HKVisualization.swift +++ b/PICS/HealthVisulization/HKVisualization.swift @@ -22,6 +22,9 @@ struct HKData: Identifiable { } struct HKVisualization: View { + @Environment(PatientInformation.self) + private var patientInformation + @State var stepData: [HKData] = [] @State var heartRateData: [HKData] = [] @State var oxygenSaturationData: [HKData] = [] @@ -37,7 +40,7 @@ struct HKVisualization: View { xName: "Time", yName: "Step Count", title: "HKVIZ_PLOT_STEP_TITLE", - threshold: 5000.0, + threshold: Double(patientInformation.minimumStepCount), helperText: "HKVIZ_PLOT_STEP_RECOMD" ) } @@ -327,8 +330,10 @@ func parseSampleQueryData(results: [HKSample], quantityTypeIDF: HKQuantityTypeId return collectedData } + #if DEBUG #Preview { HKVisualization(presentingAccount: .constant(false)) + .environment(PatientInformation()) } #endif diff --git a/PICS/Resources/Localizable.xcstrings b/PICS/Resources/Localizable.xcstrings index 47b7b9a..1833cf5 100644 --- a/PICS/Resources/Localizable.xcstrings +++ b/PICS/Resources/Localizable.xcstrings @@ -6,6 +6,9 @@ }, "%@: Not Completed" : { + }, + "%lld steps" : { + }, "ACCOUNT_NEXT" : { "localizations" : { @@ -429,6 +432,9 @@ } } } + }, + "Health" : { + }, "HEALTHKIT_PERMISSIONS_BUTTON" : { "localizations" : { @@ -740,9 +746,6 @@ }, "Measurement" : { - }, - "Medication Plan" : { - }, "MEDICATION_SUBTITLE" : { "extractionState" : "manual", @@ -978,6 +981,9 @@ } } } + }, + "Recommended Step Count" : { + }, "Repository Link" : { "localizations" : { diff --git a/PICS/Schedule/PatientInformation/PatientInformation.swift b/PICS/Schedule/PatientInformation/PatientInformation.swift index 231db43..186a302 100644 --- a/PICS/Schedule/PatientInformation/PatientInformation.swift +++ b/PICS/Schedule/PatientInformation/PatientInformation.swift @@ -23,6 +23,9 @@ class PatientInformation { @AppStorage("isSurveyCompleted") @ObservationIgnored private var _isSurveyCompleted = false + @AppStorage("minimumStepCount") + @ObservationIgnored private var _minimumStepCount: Int = 5000 + var appt0: Date { get { self.access(keyPath: \.appt0) @@ -71,6 +74,18 @@ class PatientInformation { } } + var minimumStepCount: Int { + get { + self.access(keyPath: \.minimumStepCount) + return _minimumStepCount + } + set { + self.withMutation(keyPath: \.minimumStepCount) { + self._minimumStepCount = newValue + } + } + } + func storeDates(_ date0: Date, _ date1: Date, _ date2: Date) { self.appt0 = date0 self.appt1 = date1