Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Button on Home Page to show PDF for estimating portion sizes #52

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Stronger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
2FE5DCB129EE6107004B9AB4 /* AccountOnboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE5DCAC29EE6107004B9AB4 /* AccountOnboarding.swift */; };
2FF53D8B2A8725DE00042B76 /* SpeziMockWebService in Frameworks */ = {isa = PBXBuildFile; productRef = 2FF53D8A2A8725DE00042B76 /* SpeziMockWebService */; };
2FF53D8D2A8729D600042B76 /* StrongerStandard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FF53D8C2A8729D600042B76 /* StrongerStandard.swift */; };
3821BC9E2B98A2A100F623B4 /* measurements.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 3821BC9D2B98A2A100F623B4 /* measurements.pdf */; };
38756AA32B946C6700FDF599 /* pulldowns.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 38756A942B946C5800FDF599 /* pulldowns.mp4 */; };
38756AA42B946C6700FDF599 /* rows.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 38756A952B946C5800FDF599 /* rows.mp4 */; };
38756AA52B946C6700FDF599 /* lungesright.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 38756A962B946C5800FDF599 /* lungesright.mp4 */; };
Expand Down Expand Up @@ -199,6 +200,7 @@
2FE5DC5529EDD811004B9AB4 /* SocialSupportQuestionnaire.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = SocialSupportQuestionnaire.json; sourceTree = "<group>"; };
2FE5DCAC29EE6107004B9AB4 /* AccountOnboarding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountOnboarding.swift; sourceTree = "<group>"; };
2FF53D8C2A8729D600042B76 /* StrongerStandard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StrongerStandard.swift; sourceTree = "<group>"; };
3821BC9D2B98A2A100F623B4 /* measurements.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = measurements.pdf; sourceTree = "<group>"; };
38756A942B946C5800FDF599 /* pulldowns.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = pulldowns.mp4; sourceTree = "<group>"; };
38756A952B946C5800FDF599 /* rows.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = rows.mp4; sourceTree = "<group>"; };
38756A962B946C5800FDF599 /* lungesright.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = lungesright.mp4; sourceTree = "<group>"; };
Expand Down Expand Up @@ -374,6 +376,7 @@
2FE5DC2D29EDD792004B9AB4 /* Resources */ = {
isa = PBXGroup;
children = (
3821BC9D2B98A2A100F623B4 /* measurements.pdf */,
38756AB12B946D0E00FDF599 /* ExerciseInfo.json */,
4036AE6A2B9543ED00F4DDBB /* exercise_list.json */,
38756AA12B946C6700FDF599 /* calfraises.mp4 */,
Expand Down Expand Up @@ -766,6 +769,7 @@
2FA0BFED2ACC977500E0EF83 /* Localizable.xcstrings in Resources */,
38756AAE2B946C6700FDF599 /* squats.mp4 in Resources */,
38756AA52B946C6700FDF599 /* lungesright.mp4 in Resources */,
3821BC9E2B98A2A100F623B4 /* measurements.pdf in Resources */,
38756AA72B946C6700FDF599 /* pushups.mp4 in Resources */,
38756AA32B946C6700FDF599 /* pulldowns.mp4 in Resources */,
4036AE6B2B9543ED00F4DDBB /* exercise_list.json in Resources */,
Expand Down
53 changes: 49 additions & 4 deletions Stronger/MainPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,70 @@
// Created by Tulika Jha on 18/02/24.
//


import Firebase
import FirebaseAuth
import FirebaseCore
import FirebaseFirestore
import PDFKit
import SpeziAccount
import SwiftUI
import WebKit

struct PDFViewer: View {
var body: some View {
if let path = Bundle.main.path(forResource: "measurements", ofType: "pdf"), let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path)) {
PDFKitView(pdfDocument: pdfDocument)
} else {
Text("Unable to load the PDF file.")
}
}

Check warning on line 28 in Stronger/MainPage.swift

View check run for this annotation

Codecov / codecov/patch

Stronger/MainPage.swift#L22-L28

Added lines #L22 - L28 were not covered by tests
}
// Create a PDFKitView to wrap the PDFKit's PDFView
struct PDFKitView: UIViewRepresentable {
let pdfDocument: PDFDocument
func makeUIView(context: Context) -> PDFView {
let pdfView = PDFView()
pdfView.document = pdfDocument
pdfView.autoScales = true
return pdfView
}
func updateUIView(_ uiView: PDFView, context: Context) {
// Update the view if needed
}

Check warning on line 41 in Stronger/MainPage.swift

View check run for this annotation

Codecov / codecov/patch

Stronger/MainPage.swift#L33-L41

Added lines #L33 - L41 were not covered by tests
}

struct EstimatePortionButton: View {
@Binding var showingPDF: Bool
var body: some View {
Button(action: {
showingPDF = true

Check warning on line 48 in Stronger/MainPage.swift

View check run for this annotation

Codecov / codecov/patch

Stronger/MainPage.swift#L48

Added line #L48 was not covered by tests
}) {
Text("Estimate Portion Size?")

.font(.system(size: 10))
.padding()
.background(Color.green)
.foregroundColor(.white)
.cornerRadius(8)
}
.padding() // Adjust padding as needed
.sheet(isPresented: $showingPDF) {
PDFViewer()
}

Check warning on line 61 in Stronger/MainPage.swift

View check run for this annotation

Codecov / codecov/patch

Stronger/MainPage.swift#L60-L61

Added lines #L60 - L61 were not covered by tests
}
}

struct MainPage: View {
@State private var userID: String = "temp"
@State private var currProtein: Double = 0.0
@State private var targetProtein: Double = 0.0

@State private var showingPDF = false
@Environment(Account.self) var account

// private var targetProtein: Double = 0.0

var body: some View {
@ScaledMetric var proteinVStackSpace = 10
@ScaledMetric var proteinVStackSpace = 0.0000000000000002
NavigationView {
VStack {
VStack {
Expand Down Expand Up @@ -64,9 +108,10 @@
NavigationLink(destination: ChatWindow()) {
Text("Log more with ProBot!")
}
EstimatePortionButton(showingPDF: $showingPDF)
}
.frame(width: UIScreen.main.bounds.width * 0.45)
}.padding()
}
NavigationLink(destination: ProteinStats().id(UUID())) {
Text("Weekly Stats")
.padding()
Expand Down
10 changes: 8 additions & 2 deletions Stronger/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@
}
}
}
},
"Estimate Portion Size?" : {

},
"Exercise named %@ not found" : {

Expand Down Expand Up @@ -645,10 +648,10 @@
"Protein Content" : {

},
"Protein Data" : {
"Protein intake (grams)" : {

},
"Protein intake (grams)" : {
"Protein Intake Data" : {

},
"Protein intake in the last 7 days" : {
Expand Down Expand Up @@ -800,6 +803,9 @@
},
"This Week's Fitness Progress\n" : {

},
"Unable to load the PDF file." : {

},
"Upload Exercise Log" : {

Expand Down
Binary file added Stronger/Resources/measurements.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions Stronger/Resources/measurements.pdf.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

This source file is part of the Stronger based on the Stanford Spezi Template Application project

SPDX-FileCopyrightText: 2023 Stanford University

SPDX-License-Identifier: MIT
Loading