diff --git a/OwnYourData.xcodeproj/project.pbxproj b/OwnYourData.xcodeproj/project.pbxproj index 72848e0..7162457 100644 --- a/OwnYourData.xcodeproj/project.pbxproj +++ b/OwnYourData.xcodeproj/project.pbxproj @@ -49,6 +49,11 @@ 2FB2FCD729CBDDC00027D85A /* Consent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FB2FCCC29CBDDC00027D85A /* Consent.swift */; }; 2FC9759F2978E39600BA99FE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2FC9759E2978E39600BA99FE /* Localizable.strings */; }; 2FC975A82978F11A00BA99FE /* Home.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FC975A72978F11A00BA99FE /* Home.swift */; }; + 2FE573A329CD4617008EBBD4 /* PDFDocument+Transferable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE573A229CD4617008EBBD4 /* PDFDocument+Transferable.swift */; }; + 2FE573A529CD464F008EBBD4 /* PDFListDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE573A429CD464F008EBBD4 /* PDFListDetailView.swift */; }; + 2FE573A729CD4672008EBBD4 /* PDFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE573A629CD4672008EBBD4 /* PDFView.swift */; }; + 2FE573A929CD4697008EBBD4 /* PDFListRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE573A829CD4697008EBBD4 /* PDFListRow.swift */; }; + 2FE573AB29CD46BF008EBBD4 /* DocumentManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE573AA29CD46BF008EBBD4 /* DocumentManager.swift */; }; 2FED18F22999AAF400A51A28 /* Account in Frameworks */ = {isa = PBXBuildFile; productRef = 2FED18F12999AAF400A51A28 /* Account */; }; 2FED18F42999AAF400A51A28 /* FirebaseAccount in Frameworks */ = {isa = PBXBuildFile; productRef = 2FED18F32999AAF400A51A28 /* FirebaseAccount */; }; 2FED18FA299A0C7600A51A28 /* FHIRToFirestoreAdapter in Frameworks */ = {isa = PBXBuildFile; productRef = 2FED18F9299A0C7600A51A28 /* FHIRToFirestoreAdapter */; }; @@ -113,6 +118,11 @@ 2FC94CD4298B0A1D009C8209 /* TemplateApplication.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = TemplateApplication.xctestplan; sourceTree = ""; }; 2FC9759E2978E39600BA99FE /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = ""; }; 2FC975A72978F11A00BA99FE /* Home.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Home.swift; sourceTree = ""; }; + 2FE573A229CD4617008EBBD4 /* PDFDocument+Transferable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PDFDocument+Transferable.swift"; sourceTree = ""; }; + 2FE573A429CD464F008EBBD4 /* PDFListDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFListDetailView.swift; sourceTree = ""; }; + 2FE573A629CD4672008EBBD4 /* PDFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFView.swift; sourceTree = ""; }; + 2FE573A829CD4697008EBBD4 /* PDFListRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFListRow.swift; sourceTree = ""; }; + 2FE573AA29CD46BF008EBBD4 /* DocumentManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentManager.swift; sourceTree = ""; }; 653A254D283387FE005D4D48 /* OwnYourData.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OwnYourData.app; sourceTree = BUILT_PRODUCTS_DIR; }; 653A2550283387FE005D4D48 /* TemplateApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateApplication.swift; sourceTree = ""; }; 653A255428338800005D4D48 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -220,6 +230,19 @@ path = "Supporting Files"; sourceTree = ""; }; + 2FE573A129CD4600008EBBD4 /* Documents */ = { + isa = PBXGroup; + children = ( + 2FE573A229CD4617008EBBD4 /* PDFDocument+Transferable.swift */, + 2FE573A429CD464F008EBBD4 /* PDFListDetailView.swift */, + 2FE573A629CD4672008EBBD4 /* PDFView.swift */, + 2FE573A829CD4697008EBBD4 /* PDFListRow.swift */, + 2FE573AA29CD46BF008EBBD4 /* DocumentManager.swift */, + FC1294D229CC1B760008FF21 /* DocumentGalleryView.swift */, + ); + path = Documents; + sourceTree = ""; + }; 653A2544283387FE005D4D48 = { isa = PBXGroup; children = ( @@ -250,13 +273,13 @@ FCD3FFB629CD0C31004D1E0E /* LogoView.swift */, 2F5E32BC297E05EA003432F8 /* TemplateAppDelegate.swift */, 2FB2FCD829CBDDC30027D85A /* Onboarding */, + 2FE573A129CD4600008EBBD4 /* Documents */, 2FC975A72978F11A00BA99FE /* Home.swift */, 2FB2943429CBA29900EE91A0 /* AddDataView.swift */, 2FB2943729CBA29900EE91A0 /* ClinicalTrialsView.swift */, 2FB2943229CBA29900EE91A0 /* HealthRecordView.swift */, 2FA2023229CBCC0C0039C21A /* DocumentScanner.swift */, 2FB2943529CBA29900EE91A0 /* HomeTabView.swift */, - FC1294D229CC1B760008FF21 /* DocumentGalleryView.swift */, 2FB2943329CBA29900EE91A0 /* ProfileView.swift */, 2FB2943629CBA29900EE91A0 /* ShareView.swift */, 27DD24A329CCE56300A6EEBC /* WebView.swift */, @@ -475,13 +498,17 @@ 2FB2FCD229CBDDC00027D85A /* AccountSetup.swift in Sources */, 2FB2FCB829CBDC0E0027D85A /* StorageKeys.swift in Sources */, 2FB2FCD429CBDDC00027D85A /* String+ModuleLocalized.swift in Sources */, + 2FE573A929CD4697008EBBD4 /* PDFListRow.swift in Sources */, + 2FE573AB29CD46BF008EBBD4 /* DocumentManager.swift in Sources */, 2FA2023329CBCC0C0039C21A /* DocumentScanner.swift in Sources */, 2FB2943829CBA29900EE91A0 /* HealthRecordView.swift in Sources */, FCD3FFB729CD0C31004D1E0E /* LogoView.swift in Sources */, 2FB2FCD029CBDDC00027D85A /* TemplateSignUp.swift in Sources */, 2FB2FCD729CBDDC00027D85A /* Consent.swift in Sources */, 2FB2FCD329CBDDC00027D85A /* TemplateLogin.swift in Sources */, + 2FE573A729CD4672008EBBD4 /* PDFView.swift in Sources */, 2FC975A82978F11A00BA99FE /* Home.swift in Sources */, + 2FE573A329CD4617008EBBD4 /* PDFDocument+Transferable.swift in Sources */, 2F4E23832989D51F0013F3D9 /* TemplateAppTestingSetup.swift in Sources */, 2F5E32BD297E05EA003432F8 /* TemplateAppDelegate.swift in Sources */, 2FB2FCD129CBDDC00027D85A /* UserView.swift in Sources */, @@ -493,6 +520,7 @@ 2FB2943D29CBA29900EE91A0 /* ClinicalTrialsView.swift in Sources */, 2FB2943929CBA29900EE91A0 /* ProfileView.swift in Sources */, FCD3FFB929CD1A49004D1E0E /* RecordInstructView.swift in Sources */, + 2FE573A529CD464F008EBBD4 /* PDFListDetailView.swift in Sources */, 2FB2FCD629CBDDC00027D85A /* HealthKitPermissions.swift in Sources */, 2FB2FCD529CBDDC00027D85A /* OnboardingFlow.swift in Sources */, 2FB2FCCF29CBDDC00027D85A /* IconView.swift in Sources */, diff --git a/TemplateApplication/AddDataView.swift b/TemplateApplication/AddDataView.swift index 816f940..07fc8e6 100644 --- a/TemplateApplication/AddDataView.swift +++ b/TemplateApplication/AddDataView.swift @@ -18,7 +18,6 @@ import UIKit struct AddDataView: View { @Environment(\.openURL) var openURL - @State var document: PDFDocument? @State var showingPicker = false @@ -72,7 +71,7 @@ struct AddDataView: View { } .padding(.bottom, 30) .fullScreenCover(isPresented: $showingPicker) { - DocumentScanner(document: $document) + DocumentScanner() .background { Color.black.ignoresSafeArea() } diff --git a/TemplateApplication/DocumentGalleryView.swift b/TemplateApplication/DocumentGalleryView.swift deleted file mode 100644 index 426eddc..0000000 --- a/TemplateApplication/DocumentGalleryView.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// This source file is part of the Stanford CardinalKit Template Application project -// -// SPDX-FileCopyrightText: 2023 Stanford University -// -// SPDX-License-Identifier: MIT -// - -import SwiftUI - -struct DocumentGalleryView: View { - var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) - } -} - -struct DocumentGalleryView_Previews: PreviewProvider { - static var previews: some View { - DocumentGalleryView() - } -} diff --git a/TemplateApplication/DocumentScanner.swift b/TemplateApplication/DocumentScanner.swift index 5036ef1..dfc4b36 100644 --- a/TemplateApplication/DocumentScanner.swift +++ b/TemplateApplication/DocumentScanner.swift @@ -13,16 +13,16 @@ import VisionKit struct DocumentScanner: UIViewControllerRepresentable { class Coordinator: NSObject, VNDocumentCameraViewControllerDelegate { - @Binding var document: PDFDocument? + let documentManager: DocumentManager - init(document: Binding) { - self._document = document + init(documentManager: DocumentManager) { + self.documentManager = documentManager } func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) { - let pdfDocument = self.document ?? PDFDocument() + let pdfDocument = PDFDocument() if pdfDocument.documentAttributes == nil { pdfDocument.documentAttributes = [:] @@ -40,13 +40,14 @@ struct DocumentScanner: UIViewControllerRepresentable { pdfDocument.insert(pdfPage, at: pdfDocument.pageCount) } - document = pdfDocument + documentManager.store(document: pdfDocument, title: scan.title) + controller.dismiss(animated: true) } } - @Binding var document: PDFDocument? + @EnvironmentObject var documentManager: DocumentManager func makeUIViewController(context: Context) -> some VNDocumentCameraViewController { @@ -56,7 +57,7 @@ struct DocumentScanner: UIViewControllerRepresentable { } func makeCoordinator() -> Coordinator { - Coordinator(document: $document) + Coordinator(documentManager: documentManager) } func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {} diff --git a/TemplateApplication/Documents/DocumentGalleryView.swift b/TemplateApplication/Documents/DocumentGalleryView.swift new file mode 100644 index 0000000..1b483d8 --- /dev/null +++ b/TemplateApplication/Documents/DocumentGalleryView.swift @@ -0,0 +1,54 @@ +// +// This source file is part of the Stanford CardinalKit Template Application project +// +// SPDX-FileCopyrightText: 2023 Stanford University +// +// SPDX-License-Identifier: MIT +// + +import PDFKit +import SwiftUI + + +struct DocumentGalleryView: View { + @EnvironmentObject var documentManager: DocumentManager + @State var documentScanner = false + + + var body: some View { + Group { + if documentManager.documents.isEmpty { + Text("No Documents") + } else { + List(documentManager.documents, id: \.documentURL) { document in + PDFListRow(document: document) + } + } + } + .toolbar { + ToolbarItem { + Button( + action: { + documentScanner = true + }, + label: { + Image(systemName: "plus") + } + ) + } + } + .fullScreenCover(isPresented: $documentScanner) { + DocumentScanner() + .background { + Color.black.ignoresSafeArea() + } + } + .navigationTitle("Documents") + } +} + +struct DocumentGalleryView_Previews: PreviewProvider { + static var previews: some View { + DocumentGalleryView() + } +} diff --git a/TemplateApplication/Documents/DocumentManager.swift b/TemplateApplication/Documents/DocumentManager.swift new file mode 100644 index 0000000..23385c5 --- /dev/null +++ b/TemplateApplication/Documents/DocumentManager.swift @@ -0,0 +1,79 @@ +// +// This source file is part of the Stanford CardinalKit Template Application project +// +// SPDX-FileCopyrightText: 2023 Stanford University +// +// SPDX-License-Identifier: MIT +// + +import PDFKit + + +class DocumentManager: ObservableObject { + var documents: [PDFDocument] = [] { + willSet { + self.objectWillChange.send() + } + } + + + init() { + guard let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { + return + } + + let ownYourDataDirectory = documentDirectory.appending(path: "OwnYourData") + + + var documents: [PDFDocument] = [] + do { + let items = try FileManager.default.contentsOfDirectory(at: ownYourDataDirectory, includingPropertiesForKeys: nil) + for item in items { + if let document = PDFDocument(url: item) { + documents.append(document) + } + } + self.documents = documents + } catch { + return + } + } + + + func store(document: PDFDocument, title: String) { + guard let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { + return + } + + try? FileManager.default.createDirectory(at: documentDirectory.appending(path: "OwnYourData"), withIntermediateDirectories: true) + + let documentBaseName: String + if title.isEmpty { + documentBaseName = "Document" + } else { + documentBaseName = title + } + + var documentName = documentBaseName + + for index in 1...Int.max { + if !FileManager.default.fileExists(atPath: documentDirectory.appending(path: "OwnYourData/\(documentName).pdf").path()) { + break + } + documentName = documentBaseName + "\(index)" + } + + let documentPath = documentDirectory.appending(path: "OwnYourData/\(documentName).pdf") + + let documentSaved = document.write(to: documentPath) + + print("Saved the document \(documentSaved) to \(documentPath)") + + if let loadedFromURLDocument = PDFDocument(url: documentPath) { + self.documents.append(loadedFromURLDocument) + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + self.objectWillChange.send() + } + } + } +} diff --git a/TemplateApplication/Documents/PDFDocument+Transferable.swift b/TemplateApplication/Documents/PDFDocument+Transferable.swift new file mode 100644 index 0000000..49f3927 --- /dev/null +++ b/TemplateApplication/Documents/PDFDocument+Transferable.swift @@ -0,0 +1,33 @@ +// +// This source file is part of the Stanford CardinalKit Template Application project +// +// SPDX-FileCopyrightText: 2023 Stanford University +// +// SPDX-License-Identifier: MIT +// + +import PDFKit +import SwiftUI + + +extension PDFDocument: Transferable { + public static var transferRepresentation: some TransferRepresentation { + DataRepresentation( + contentType: .pdf, + exporting: { pdf in + if let data = pdf.dataRepresentation() { + return data + } else { + return Data() + } + }, + importing: { data in + if let pdf = PDFDocument(data: data) { + return pdf + } else { + return PDFDocument() + } + } + ) + } +} diff --git a/TemplateApplication/Documents/PDFListDetailView.swift b/TemplateApplication/Documents/PDFListDetailView.swift new file mode 100644 index 0000000..59030fc --- /dev/null +++ b/TemplateApplication/Documents/PDFListDetailView.swift @@ -0,0 +1,24 @@ +// +// This source file is part of the Stanford CardinalKit Template Application project +// +// SPDX-FileCopyrightText: 2023 Stanford University +// +// SPDX-License-Identifier: MIT +// + +import PDFKit +import SwiftUI + + +struct PDFListDetailView: View { + let document: PDFDocument + + var body: some View { + PDFView(document) + .toolbar { + ToolbarItem { + ShareLink(item: document, preview: SharePreview("PDF")) + } + } + } +} diff --git a/TemplateApplication/Documents/PDFListRow.swift b/TemplateApplication/Documents/PDFListRow.swift new file mode 100644 index 0000000..3efd015 --- /dev/null +++ b/TemplateApplication/Documents/PDFListRow.swift @@ -0,0 +1,51 @@ +// +// This source file is part of the Stanford CardinalKit Template Application project +// +// SPDX-FileCopyrightText: 2023 Stanford University +// +// SPDX-License-Identifier: MIT +// + +import PDFKit +import SwiftUI + + +struct PDFListRow: View { + let document: PDFDocument + + + private var documentName: String { + document.documentURL?.lastPathComponent ?? "Document" + } + + private var documentCreationDate: Date { + guard let documentURL = document.documentURL, + let attributes = try? FileManager.default.attributesOfItem(atPath: documentURL.path()), + let creationDate = attributes[.creationDate] as? Date else { + return .now + } + + return creationDate + } + + var body: some View { + NavigationLink(destination: PDFListDetailView(document: document)) { + HStack(alignment: .top) { + VStack(alignment: .leading) { + Text(documentName) + .font(.title3.bold()) + HStack { + Text(documentCreationDate, style: .date) + Text(documentCreationDate, style: .time) + } + .font(.body) + } + Spacer() + PDFView(document) + .frame(width: 50, height: 50) + } + .padding() + .frame(height: 60) + } + } +} diff --git a/TemplateApplication/Documents/PDFView.swift b/TemplateApplication/Documents/PDFView.swift new file mode 100644 index 0000000..9882df6 --- /dev/null +++ b/TemplateApplication/Documents/PDFView.swift @@ -0,0 +1,30 @@ +// +// This source file is part of the Stanford CardinalKit Template Application project +// +// SPDX-FileCopyrightText: 2023 Stanford University +// +// SPDX-License-Identifier: MIT +// + +import PDFKit +import SwiftUI + + +struct PDFView: UIViewRepresentable { + let document: PDFDocument + + + init(_ document: PDFDocument) { + self.document = document + } + + + func makeUIView(context: Context) -> PDFKit.PDFView { + let pdfView = PDFKit.PDFView() + pdfView.document = document + pdfView.autoScales = true + return pdfView + } + + func updateUIView(_ uiView: PDFKit.PDFView, context: Context) { } +} diff --git a/TemplateApplication/Extensions & Infrastructure/StorageKeys.swift b/TemplateApplication/Extensions & Infrastructure/StorageKeys.swift index 3c2a2c4..5f900bc 100644 --- a/TemplateApplication/Extensions & Infrastructure/StorageKeys.swift +++ b/TemplateApplication/Extensions & Infrastructure/StorageKeys.swift @@ -18,4 +18,9 @@ public enum StorageKeys { // MARK: - Home /// The currently selected home tab. public static let homeTabSelection = "home.tabselection" + + + // MARK: - Name + /// The name of the currently signed in user + public static let userName = "user.name" } diff --git a/TemplateApplication/HomeTabView.swift b/TemplateApplication/HomeTabView.swift index be2341b..0aac4c8 100644 --- a/TemplateApplication/HomeTabView.swift +++ b/TemplateApplication/HomeTabView.swift @@ -13,8 +13,10 @@ import SwiftUI struct HomeTabView: View { + @AppStorage(StorageKeys.userName) var appStorageUserName = "" @State private var userName: String = "" + var body: some View { NavigationStack { VStack { @@ -48,7 +50,7 @@ struct HomeTabView: View { .padding(.bottom, 20) NavigationLink(destination: DocumentGalleryView()) { - Text("Documents") + Text("Scanned Documents") .font(.headline) .fontWeight(.bold) .padding() @@ -83,6 +85,7 @@ struct HomeTabView: View { } func getUserName() { + userName = appStorageUserName.split(separator: " ").first.map(String.init) ?? "" if let user = Auth.auth().currentUser { user.reload { error in if let error = error { diff --git a/TemplateApplication/Onboarding/AccountSetup/AccountSetup.swift b/TemplateApplication/Onboarding/AccountSetup/AccountSetup.swift index 3fb5d20..6a95aca 100644 --- a/TemplateApplication/Onboarding/AccountSetup/AccountSetup.swift +++ b/TemplateApplication/Onboarding/AccountSetup/AccountSetup.swift @@ -16,6 +16,7 @@ import SwiftUI struct AccountSetup: View { + @AppStorage(StorageKeys.userName) var username = "" @Binding private var onboardingSteps: [OnboardingFlow.Step] @EnvironmentObject var account: Account @@ -62,10 +63,7 @@ struct AccountSetup: View { } } - let defaults = UserDefaults.standard - defaults.set(firstName, forKey: "firstName") - defaults.set(lastName, forKey: "lastName") - defaults.set(email, forKey: "email") + self.username = "\(firstName) \(lastName)" } onboardingSteps.append(.healthKitPermissions) diff --git a/TemplateApplication/ProfileView.swift b/TemplateApplication/ProfileView.swift index a2dd39d..b8be032 100644 --- a/TemplateApplication/ProfileView.swift +++ b/TemplateApplication/ProfileView.swift @@ -14,8 +14,8 @@ import SwiftUI struct ProfileView: View { let user = Auth.auth().currentUser - @State private var firstName = "" - @State private var lastName = "" + @AppStorage(StorageKeys.userName) var appStorageUserName = "" + @State private var userName = "" @State private var email = "" @@ -29,7 +29,7 @@ struct ProfileView: View { .accessibility(label: Text("profile image")) VStack(spacing: 10) { - Text("\(firstName) \(lastName)") + Text("\(userName)") .font(.title2) Text("Email: \(email)") .font(.subheadline) @@ -64,13 +64,15 @@ struct ProfileView: View { private func fetchUserData() { + self.userName = appStorageUserName + if let currentUser = user { let docRef = Firestore.firestore().collection("users").document(currentUser.uid) docRef.getDocument { document, _ in if let document = document, document.exists { let data = document.data() - self.firstName = data?["firstName"] as? String ?? "" - self.lastName = data?["lastName"] as? String ?? "" + self.userName = "\(data?["firstName"] as? String ?? "") \(data?["lastName"] as? String ?? "")" + self.appStorageUserName = self.userName self.email = currentUser.email ?? "" } else { print("Document does not exist") diff --git a/TemplateApplication/ShareView.swift b/TemplateApplication/ShareView.swift index dd2a216..aac222a 100644 --- a/TemplateApplication/ShareView.swift +++ b/TemplateApplication/ShareView.swift @@ -18,35 +18,11 @@ struct ShareView: View { @Environment(\.openURL) var openURL var body: some View { - VStack { - LogoView() - Spacer() - Text("Share \nHealth Records") - .font(.largeTitle) - .foregroundColor(Color.accentColor) - .multilineTextAlignment(.center) - Button(action: { - guard let url = URL(string: "x-apple-health://") else { - fatalError("Could not create a Health App URL") - } - openURL(url) - }) { - Text("Open Health App") - .font(.headline) - .fontWeight(.bold) - .padding() - .frame(maxWidth: .infinity) - .foregroundColor(Color.white) - .background(Color(UIColor(named: "ButtonColor_light") ?? .gray)) - .cornerRadius(10) - .padding(.leading) - .padding(.trailing) - } - - Spacer().frame(height: 40) - + NavigationStack { VStack { - Text("Share \nDocuments") + LogoView() + Spacer() + Text("Share \nHealth Records") .font(.largeTitle) .foregroundColor(Color.accentColor) .multilineTextAlignment(.center) @@ -56,7 +32,7 @@ struct ShareView: View { } openURL(url) }) { - Text("Select Documents") + Text("Open Health App") .font(.headline) .fontWeight(.bold) .padding() @@ -67,8 +43,47 @@ struct ShareView: View { .padding(.leading) .padding(.trailing) } + + Spacer().frame(height: 40) + + VStack { + Text("Share \nDocuments") + .font(.largeTitle) + .foregroundColor(Color.accentColor) + .multilineTextAlignment(.center) + NavigationLink(destination: DocumentGalleryView()) { + Text("Scanned Documents") + .font(.headline) + .fontWeight(.bold) + .padding() + .frame(maxWidth: .infinity) + .foregroundColor(.white) + .background(Color(UIColor(named: "ButtonColor_light") ?? .gray)) + .cornerRadius(10) + .padding(.leading) + .padding(.trailing) + } + .padding(.bottom, 20) + Button(action: { + guard let url = URL(string: "x-apple-health://") else { + fatalError("Could not create a Health App URL") + } + openURL(url) + }) { + Text("Apple Health Documents") + .font(.headline) + .fontWeight(.bold) + .padding() + .frame(maxWidth: .infinity) + .foregroundColor(Color.white) + .background(Color(UIColor(named: "ButtonColor_light") ?? .gray)) + .cornerRadius(10) + .padding(.leading) + .padding(.trailing) + } + } + .padding(.bottom, 30) } - .padding(.bottom, 30) } } } diff --git a/TemplateApplication/TemplateApplication.swift b/TemplateApplication/TemplateApplication.swift index 346030a..f414cce 100644 --- a/TemplateApplication/TemplateApplication.swift +++ b/TemplateApplication/TemplateApplication.swift @@ -22,6 +22,7 @@ struct TemplateApplication: App { .sheet(isPresented: !$completedOnboardingFlow) { OnboardingFlow() } + .environmentObject(DocumentManager()) .testingSetup() .cardinalKit(appDelegate) }