From 2ad6fdae2448db6d7290ac401d514b3e400269b2 Mon Sep 17 00:00:00 2001 From: Varun Shenoy Date: Tue, 26 Jan 2021 17:29:53 -0800 Subject: [PATCH 1/2] Assignment 2 with Firebase + Surveys --- Assignment Two.xcodeproj/project.pbxproj | 8 ++- Assignment Two/GoogleService-Info.plist | 34 +++++++++++++ Assignment Two/RKTaskSamples.swift | 65 +++++++++++++++++++++++- Assignment Two/Views/SurveyView.swift | 9 +++- 4 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 Assignment Two/GoogleService-Info.plist diff --git a/Assignment Two.xcodeproj/project.pbxproj b/Assignment Two.xcodeproj/project.pbxproj index 90fa3e5..0176df5 100644 --- a/Assignment Two.xcodeproj/project.pbxproj +++ b/Assignment Two.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 8EF8F77D2597C7DE000850BF /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EF8F77C2597C7DE000850BF /* ContentView.swift */; }; 8EF8F77F2597C7E1000850BF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8EF8F77E2597C7E1000850BF /* Assets.xcassets */; }; 8EF8F7822597C7E1000850BF /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8EF8F7812597C7E1000850BF /* Preview Assets.xcassets */; }; + E20FD4C925C0F50900101AC5 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = E20FD4C825C0F50900101AC5 /* GoogleService-Info.plist */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -41,6 +42,7 @@ 8EF8F77E2597C7E1000850BF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 8EF8F7812597C7E1000850BF /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 8EF8F7832597C7E1000850BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E20FD4C825C0F50900101AC5 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; E7DE9A4430C3A45320910A5E /* Pods_Assignment_Two.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Assignment_Two.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -124,6 +126,7 @@ 8EF8F77A2597C7DE000850BF /* Assignment_TwoApp.swift */, 8E35409825B90F1B007B7029 /* RKTaskDelegate.swift */, 8E0A956825B677950025461E /* RKTaskSamples.swift */, + E20FD4C825C0F50900101AC5 /* GoogleService-Info.plist */, ); path = "Assignment Two"; sourceTree = ""; @@ -215,6 +218,7 @@ files = ( 8EF8F7822597C7E1000850BF /* Preview Assets.xcassets in Resources */, 8EF8F77F2597C7E1000850BF /* Assets.xcassets in Resources */, + E20FD4C925C0F50900101AC5 /* GoogleService-Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -416,7 +420,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "edu.stanford.cs342.Assignment-Two"; + PRODUCT_BUNDLE_IDENTIFIER = "edu.stanford.cs342.demo-firebase"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Assignment Two/Supporting Files/Assignment Two-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -442,7 +446,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "edu.stanford.cs342.Assignment-Two"; + PRODUCT_BUNDLE_IDENTIFIER = "edu.stanford.cs342.demo-firebase"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Assignment Two/Supporting Files/Assignment Two-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/Assignment Two/GoogleService-Info.plist b/Assignment Two/GoogleService-Info.plist new file mode 100644 index 0000000..edf0933 --- /dev/null +++ b/Assignment Two/GoogleService-Info.plist @@ -0,0 +1,34 @@ + + + + + CLIENT_ID + 1024126292608-6vk699h4vjlphpq0mnndm274lnbuk61v.apps.googleusercontent.com + REVERSED_CLIENT_ID + com.googleusercontent.apps.1024126292608-6vk699h4vjlphpq0mnndm274lnbuk61v + API_KEY + AIzaSyBkIdG428OgHfOUG8RoWPluLqucP59lYBc + GCM_SENDER_ID + 1024126292608 + PLIST_VERSION + 1 + BUNDLE_ID + edu.stanford.cs342.demo-firebase + PROJECT_ID + cs342-demo + STORAGE_BUCKET + cs342-demo.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:1024126292608:ios:1281c954b0092f6cabcc65 + + \ No newline at end of file diff --git a/Assignment Two/RKTaskSamples.swift b/Assignment Two/RKTaskSamples.swift index c1a92f1..9afe5db 100644 --- a/Assignment Two/RKTaskSamples.swift +++ b/Assignment Two/RKTaskSamples.swift @@ -5,7 +5,6 @@ // Copyright © 2019 Stanford University. // All rights reserved. // - import ResearchKit /** @@ -25,6 +24,68 @@ struct RKTaskSamples { Add steps to the array above to create a survey! */ - return ORKOrderedTask(identifier: "SurveyTask-Assessment", steps: steps) + let booleanAnswer = ORKBooleanAnswerFormat(yesString: "YES!", noString: "Not now") + let booleanStep = ORKQuestionStep(identifier: "AreYouReady-Boolean", title: "Before we get started...", question: "Are you ready to start the test?", answer: booleanAnswer) + + steps += [booleanStep] + + let dateAnswerFormat = ORKDateAnswerFormat(style: .date) + let numberAnswerFormat = ORKNumericAnswerFormat(style: .integer, unit: nil, minimum: 0 as NSNumber, maximum: 100 as NSNumber) + + let ageFormItem = ORKFormItem(identifier: "RegistrationForm-Age", text: "How old are you?", answerFormat: numberAnswerFormat, optional: true) + let dateFormItem = ORKFormItem(identifier: "RegistrationForm-DateQuestion", text: "When did you have surgery?", answerFormat: dateAnswerFormat) + + let formStep = ORKFormStep(identifier: "RegistrationForm", title: "About you", text: "Please take a moment to answer some (very) quick questions!") + formStep.formItems = [dateFormItem, ageFormItem] + steps += [formStep] + + let summaryStep = ORKCompletionStep(identifier: "SummaryStep") + summaryStep.title = "Thank you." + summaryStep.text = "All done!" + steps += [summaryStep] + + let task = ORKNavigableOrderedTask(identifier: "SurveyTask-Assessment", steps: steps) + + let resultBooleanSelector = ORKResultSelector(resultIdentifier: booleanStep.identifier) + let predicate = ORKResultPredicate.predicateForBooleanQuestionResult(with: resultBooleanSelector, expectedAnswer: false) + let navigableRule = ORKPredicateStepNavigationRule(resultPredicatesAndDestinationStepIdentifiers: [(predicate, summaryStep.identifier)]) + task.setNavigationRule(navigableRule, forTriggerStepIdentifier: booleanStep.identifier) + + return task + }() + + /** + Sample task template! + */ + static let sampleTappingTask: ORKOrderedTask = { + var steps = [ORKStep]() + + /* + CS342 -- ASSIGNMENT 2 + Add steps to the array above to create a survey! + */ + + let booleanAnswer = ORKBooleanAnswerFormat(yesString: "YES!", noString: "Not now") + let booleanStep = ORKQuestionStep(identifier: "AreYouReady-Boolean", title: "Before we get started...", question: "Are you ready to start the test?", answer: booleanAnswer) + + steps += [booleanStep] + + // add an active task here + let tappingTask = ORKOrderedTask.twoFingerTappingIntervalTask(withIdentifier: "TappingTask", intendedUseDescription: "Finger tapping is a universal way to communicate.", duration: 5, handOptions: .right, options: ORKPredefinedTaskOption()) + steps += tappingTask.steps + + let summaryStep = ORKCompletionStep(identifier: "SummaryStep") + summaryStep.title = "Thank you." + summaryStep.text = "All done!" + steps += [summaryStep] + + let task = ORKNavigableOrderedTask(identifier: "SurveyTappingTask-Assessment", steps: steps) + + let resultBooleanSelector = ORKResultSelector(resultIdentifier: booleanStep.identifier) + let predicate = ORKResultPredicate.predicateForBooleanQuestionResult(with: resultBooleanSelector, expectedAnswer: false) + let navigableRule = ORKPredicateStepNavigationRule(resultPredicatesAndDestinationStepIdentifiers: [(predicate, summaryStep.identifier)]) + task.setNavigationRule(navigableRule, forTriggerStepIdentifier: booleanStep.identifier) + + return task }() } diff --git a/Assignment Two/Views/SurveyView.swift b/Assignment Two/Views/SurveyView.swift index bdbc6b2..118d191 100644 --- a/Assignment Two/Views/SurveyView.swift +++ b/Assignment Two/Views/SurveyView.swift @@ -1,3 +1,4 @@ + // // SurveyView.swift // Assignment Two @@ -6,7 +7,6 @@ // Copyright © 2019 Stanford University. // All rights reserved. // - import SwiftUI import ResearchKit @@ -37,10 +37,17 @@ struct SurveyView: View { */ // surveyOptional = /* my ORKOrderedTask */ + surveyOptional = RKTaskSamples.sampleSurveyTask }) { RoundedTextView("Start Survey", backgroundColor: .red) } + Button(action: { + surveyOptional = RKTaskSamples.sampleTappingTask + }) { + RoundedTextView("Start Tapping!", backgroundColor: .red) + } + Spacer() } .frame(maxWidth: .infinity) From 403279f0a7f9932815af52ea2f7a729d2e5bb297 Mon Sep 17 00:00:00 2001 From: Varun Shenoy Date: Tue, 26 Jan 2021 17:36:48 -0800 Subject: [PATCH 2/2] Update GoogleService-Info.plist --- Assignment Two/GoogleService-Info.plist | 35 +------------------------ 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/Assignment Two/GoogleService-Info.plist b/Assignment Two/GoogleService-Info.plist index edf0933..d69508b 100644 --- a/Assignment Two/GoogleService-Info.plist +++ b/Assignment Two/GoogleService-Info.plist @@ -1,34 +1 @@ - - - - - CLIENT_ID - 1024126292608-6vk699h4vjlphpq0mnndm274lnbuk61v.apps.googleusercontent.com - REVERSED_CLIENT_ID - com.googleusercontent.apps.1024126292608-6vk699h4vjlphpq0mnndm274lnbuk61v - API_KEY - AIzaSyBkIdG428OgHfOUG8RoWPluLqucP59lYBc - GCM_SENDER_ID - 1024126292608 - PLIST_VERSION - 1 - BUNDLE_ID - edu.stanford.cs342.demo-firebase - PROJECT_ID - cs342-demo - STORAGE_BUCKET - cs342-demo.appspot.com - IS_ADS_ENABLED - - IS_ANALYTICS_ENABLED - - IS_APPINVITE_ENABLED - - IS_GCM_ENABLED - - IS_SIGNIN_ENABLED - - GOOGLE_APP_ID - 1:1024126292608:ios:1281c954b0092f6cabcc65 - - \ No newline at end of file +