generated from StanfordSpezi/SpeziTemplateApplication
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial setup of onboarding flow (#3)
* Initial setup of onboarding flow * Update strings * Fix typo
- Loading branch information
1 parent
d5c95c3
commit e5d5b74
Showing
18 changed files
with
286 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,23 +10,21 @@ SPDX-License-Identifier: MIT | |
|
||
# StrokeCog | ||
|
||
This repository contains the StrokeCog. | ||
The StrokeCog is using the [Spezi](https://github.com/StanfordSpezi/Spezi) ecosystem and builds on top of the [Stanford Spezi Template Application](https://github.com/StanfordSpezi/SpeziTemplateApplication). | ||
This repository contains the mobile application for the StrokeCog study at Stanford University. | ||
|
||
> [!NOTE] | ||
> Do you want to learn more about the Stanford Spezi Template Application and how to use, extend, and modify this application? Check out the [Stanford Spezi Template Application documentation](https://stanfordspezi.github.io/SpeziTemplateApplication) | ||
The StrokeCog study was built using the [Spezi](https://github.com/StanfordSpezi/Spezi) ecosystem and builds on top of the [Stanford Spezi Template Application](https://github.com/StanfordSpezi/SpeziTemplateApplication). | ||
|
||
|
||
## StrokeCog Features | ||
|
||
*Provide a comprehensive description of your application, including figures showing the application. You can learn more on how to structure a README in the [Stanford Spezi Documentation Guide](https://swiftpackageindex.com/stanfordspezi/spezi/documentation/spezi/documentation-guide)* | ||
- Location data collection | ||
- Health data collection | ||
- Daily surveys | ||
|
||
|
||
## Contributing | ||
|
||
*Ensure that you add an adequate contribution section to this README.* | ||
- Vishnu Ravi ([email protected]) | ||
- Sylvie Dobrota Lai ([email protected]) | ||
|
||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See [Licenses](LICENSES) for more information. | ||
[Odden Research Lab at Stanford University](https://michelleodden.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// | ||
// StudyIDView.swift | ||
// StrokeCog | ||
// | ||
// Created by Vishnu Ravi on 3/30/24. | ||
// | ||
|
||
import SpeziOnboarding | ||
import SpeziValidation | ||
import SpeziViews | ||
import SwiftUI | ||
|
||
struct StudyIDView: View { | ||
@Environment(OnboardingNavigationPath.self) private var onboardingNavigationPath | ||
@State private var studyID = "" | ||
@State private var showInvalidIDAlert = false | ||
@ValidationState private var validation | ||
|
||
var body: some View { | ||
VStack(spacing: 32) { | ||
OnboardingView( | ||
titleView: { | ||
OnboardingTitleView( | ||
title: "Study ID", | ||
subtitle: "Welcome to the StrokeCog study. To get started, please enter your study ID." | ||
) | ||
}, | ||
contentView: { | ||
studyIDEntryView | ||
}, | ||
actionView: { | ||
OnboardingActionsView( | ||
"Next", | ||
action: { | ||
guard validation.validateSubviews() else { | ||
return | ||
} | ||
|
||
if verify(id: studyID) { | ||
onboardingNavigationPath.nextStep() | ||
} else { | ||
showInvalidIDAlert = true | ||
} | ||
} | ||
) | ||
} | ||
) | ||
} | ||
} | ||
|
||
@ViewBuilder private var studyIDEntryView: some View { | ||
VerifiableTextField( | ||
LocalizedStringResource("Tap here and enter your Study ID"), | ||
text: $studyID | ||
) | ||
.autocorrectionDisabled() | ||
.textInputAutocapitalization(.characters) | ||
.textContentType(.oneTimeCode) | ||
.validate(input: studyID, rules: [validationRule]) | ||
.receiveValidation(in: $validation) | ||
.alert( | ||
"Error", | ||
isPresented: $showInvalidIDAlert | ||
) { | ||
Text("You've entered an invalid study ID.") | ||
Button("Try Again") { } | ||
} | ||
} | ||
|
||
private var validationRule: ValidationRule { | ||
ValidationRule( | ||
rule: { studyID in | ||
studyID.count >= 4 | ||
}, | ||
message: "A study ID should be at least 4 characters long." | ||
) | ||
} | ||
|
||
private func verify(id: String) -> Bool { | ||
var validStudyIDs = [String]() | ||
|
||
if let studyIDsURL = Bundle.main.url(forResource: "studyIDs", withExtension: ".csv"), | ||
let studyIDs = try? String(contentsOf: studyIDsURL) { | ||
let allStudyIDs = studyIDs.components(separatedBy: "\n") | ||
|
||
for studyID in allStudyIDs { | ||
validStudyIDs.append(studyID.filter { !$0.isWhitespace }) | ||
} | ||
|
||
return validStudyIDs.contains(id) | ||
} | ||
return false | ||
} | ||
} | ||
|
||
#Preview { | ||
StudyIDView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.