diff --git a/LifeSpace.xcodeproj/project.pbxproj b/LifeSpace.xcodeproj/project.pbxproj index 72b64aa..16688ee 100644 --- a/LifeSpace.xcodeproj/project.pbxproj +++ b/LifeSpace.xcodeproj/project.pbxproj @@ -832,7 +832,7 @@ CODE_SIGN_ENTITLEMENTS = "LifeSpace/Supporting Files/LifeSpace.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; @@ -1034,7 +1034,7 @@ CODE_SIGN_ENTITLEMENTS = "LifeSpace/Supporting Files/LifeSpace.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; @@ -1082,7 +1082,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = ""; diff --git a/LifeSpace/SharedContext/Constants.swift b/LifeSpace/SharedContext/Constants.swift index f203d12..aaca64b 100644 --- a/LifeSpace/SharedContext/Constants.swift +++ b/LifeSpace/SharedContext/Constants.swift @@ -7,12 +7,24 @@ /// Constants shared across the application for settings enum Constants { + // MARK: Survey Settings + /// Each day's survey opens by default in the evening at 7pm every day + /// and closes the next morning at 7am. + /// /// Hour to open the survey daily (in 24 hour time) static let hourToOpenSurvey = 19 + /// Hour to close the survey the following day (in 24 hour time) + static let hourToCloseSurvey = 7 + + // MARK: Location /// Minimum distance between locations to record (in meters) static let minDistanceBetweenPoints = 100.0 + + // MARK: URLs /// URL of the privacy policy for the app static let privacyPolicyURL = "https://michelleodden.com/cardinal-lifespace-privacy-policy/" + + // MARK: Collections /// User collection on Firestore static let userCollectionName = "ls_users" /// Location data collection on Firestore diff --git a/LifeSpace/Survey/DailySurveyTask.swift b/LifeSpace/Survey/DailySurveyTask.swift index 6ccaf9f..d2d02fa 100644 --- a/LifeSpace/Survey/DailySurveyTask.swift +++ b/LifeSpace/Survey/DailySurveyTask.swift @@ -57,19 +57,17 @@ class DailySurveyTask: ORKOrderedTask { steps.append(question3Step) // Question 4: Fatigue - let answerFormat4 = ORKAnswerFormat.scale( - withMaximumValue: 4, - minimumValue: 0, - defaultValue: 0, - step: 1, - vertical: false, - maximumValueDescription: "Very much", - minimumValueDescription: "Not at all" - ) + let answerFormat4 = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: [ + ORKTextChoice(text: "Not at all", value: 0 as NSNumber), + ORKTextChoice(text: "A little bit", value: 1 as NSNumber), + ORKTextChoice(text: "Somewhat", value: 2 as NSNumber), + ORKTextChoice(text: "Quite a bit", value: 3 as NSNumber), + ORKTextChoice(text: "Very much", value: 4 as NSNumber) + ]) let question4Step = ORKQuestionStep( identifier: "PhysicalWellBeingQuestion", title: "Physical Well-being", - question: "I feel fatigued", + question: "Consider your day today and evaluate your agreement with the following statement.", answer: answerFormat4 ) steps.append(question4Step) diff --git a/LifeSpace/Survey/DailySurveyTaskView.swift b/LifeSpace/Survey/DailySurveyTaskView.swift index ffe950f..cad50f1 100644 --- a/LifeSpace/Survey/DailySurveyTaskView.swift +++ b/LifeSpace/Survey/DailySurveyTaskView.swift @@ -35,9 +35,7 @@ struct DailySurveyTaskView: View { } Task { - savingSurvey = true await saveResponse(taskResult: taskResult) - savingSurvey = false showingSurvey = false } } @@ -148,10 +146,10 @@ struct DailySurveyTaskView: View { response.surveyName = "dailySurveyTask" - /// If the user is taking the survey before 7am, the `surveyDate` should reflect the previous day, + /// If the user is taking the survey the morning after, the `surveyDate` should reflect the previous day, /// otherwise it should reflect the current day. let surveyDate: Date - if SurveyModule.currentHour < 7 { + if SurveyModule.currentHour < Constants.hourToCloseSurvey { surveyDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())?.startOfDay ?? Date().startOfDay } else { surveyDate = Date().startOfDay @@ -182,21 +180,23 @@ struct DailySurveyTaskView: View { response.emotionalWellBeingQuestion = result?.intValue } - if let physicalWellBeingQuestion = taskResult.stepResult(forStepIdentifier: "PhysicalWellBeingQuestion")?.results { - let answer = physicalWellBeingQuestion[0] as? ORKScaleQuestionResult - if let result = answer?.scaleAnswer { - response.physicalWellBeingQuestion = Int(truncating: result) - } else { - response.physicalWellBeingQuestion = -1 - } + if let physicalWellBeingQuestion = taskResult.stepResult(forStepIdentifier: "PhysicalWellBeingQuestion"), + let result = physicalWellBeingQuestion.firstResult as? ORKChoiceQuestionResult, + let answer = result.choiceAnswers?.first as? NSNumber { + response.physicalWellBeingQuestion = answer.intValue + } else { + response.physicalWellBeingQuestion = -1 } do { + savingSurvey = true try await standard.add(response: response) // Update the last survey date in UserDefaults UserDefaults.standard.set(surveyDateString, forKey: StorageKeys.lastSurveyDate) + savingSurvey = false } catch { + savingSurvey = false self.errorMessage = error.localizedDescription self.didError.toggle() } diff --git a/LifeSpace/Survey/SurveyModule.swift b/LifeSpace/Survey/SurveyModule.swift index 3e5a749..2f5ccda 100644 --- a/LifeSpace/Survey/SurveyModule.swift +++ b/LifeSpace/Survey/SurveyModule.swift @@ -20,9 +20,9 @@ enum SurveyModule { } static var isPreviousDaySurvey: Bool { - /// If the user is taking the survey before 7am, they should be informed that they are taking the - /// previous day's survey - currentHour < 7 + /// If the user is taking the survey in the morning, they should be informed that their + /// results will apply to the previous day not the current day. + currentHour < Constants.hourToCloseSurvey } static var surveyAlreadyTaken: Bool { @@ -30,7 +30,7 @@ enum SurveyModule { /// Determine the survey date based on the current time let surveyDate: Date - if currentHour < 7 { + if currentHour < Constants.hourToCloseSurvey { surveyDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())?.startOfDay ?? Date().startOfDay } else { surveyDate = Date().startOfDay @@ -44,7 +44,6 @@ enum SurveyModule { } static var shouldShowSurvey: Bool { - /// The survey should only be shown if it between 7pm and 7am - currentHour < 7 || currentHour >= 19 + currentHour < Constants.hourToCloseSurvey || currentHour >= Constants.hourToOpenSurvey } }