From db865ab099cada9e4fa996b46e1a0d41c29c8b8a Mon Sep 17 00:00:00 2001 From: Rhea Malhotra Date: Thu, 2 Mar 2023 18:37:50 -0800 Subject: [PATCH] Rhea's changes to photo upload feature, made sheet for photo upload when step count met --- GetMoovin/PhotoUpload/PhotoUpload.swift | 42 ++++--- GetMoovin/TodaysGoal/StepCountView.swift | 134 +++++++++++++++-------- 2 files changed, 113 insertions(+), 63 deletions(-) diff --git a/GetMoovin/PhotoUpload/PhotoUpload.swift b/GetMoovin/PhotoUpload/PhotoUpload.swift index 379a02a..e6cf99d 100644 --- a/GetMoovin/PhotoUpload/PhotoUpload.swift +++ b/GetMoovin/PhotoUpload/PhotoUpload.swift @@ -7,11 +7,15 @@ // import ImageSource +import GetMoovinSharedContext +import GetMoovinStepCountModule import SwiftUI struct PhotoUpload: View { @State var image: UIImage? + @EnvironmentObject var stepCountDataSource: StepCountDataSource + @AppStorage(StorageKeys.userInformation) var userInformation = UserInformation() private var swiftUIImage: Image? { @@ -19,25 +23,31 @@ struct PhotoUpload: View { Image(uiImage: $0) // swiftlint:disable:this accessibility_label_for_image } } - + var stepsLeft: Int { + (userInformation.stepGoal ?? 1000) - (stepCountDataSource.todaysSteps ?? 1000) + } var body: some View { - NavigationStack { - ImageSource(image: $image) - .clipShape(RoundedRectangle(cornerRadius: 8)) - .padding() - .navigationTitle("Photo Upload") - .toolbar { - if let swiftUIImage = swiftUIImage { - ToolbarItem { - ShareLink( - item: swiftUIImage, - subject: Text("GetMoovin 🚶"), - message: Text("I met my daily goal in GetMoovin!"), - preview: SharePreview("GetMoovin 🚶", image: swiftUIImage) - ) + if stepsLeft > 0 { + Text("Oops ... you havent walked ur steps!") + } else { + NavigationStack { + ImageSource(image: $image) + .clipShape(RoundedRectangle(cornerRadius: 8)) + .padding() + .navigationTitle("Photo Upload") + .toolbar { + if let swiftUIImage = swiftUIImage { + ToolbarItem { + ShareLink( + item: swiftUIImage, + subject: Text("GetMoovin 🚶"), + message: Text("I met my daily goal in GetMoovin!"), + preview: SharePreview("GetMoovin 🚶", image: swiftUIImage) + ) + } } } - } + } } } } diff --git a/GetMoovin/TodaysGoal/StepCountView.swift b/GetMoovin/TodaysGoal/StepCountView.swift index 1d9bee1..e8f5342 100644 --- a/GetMoovin/TodaysGoal/StepCountView.swift +++ b/GetMoovin/TodaysGoal/StepCountView.swift @@ -9,6 +9,7 @@ import Charts import GetMoovinSharedContext import GetMoovinStepCountModule +import ImageSource import SwiftUI struct StepsInfo: Identifiable { @@ -18,57 +19,96 @@ struct StepsInfo: Identifiable { var color: String } +struct SheetView: View { + @State var image: UIImage? + @EnvironmentObject var stepCountDataSource: StepCountDataSource + @AppStorage(StorageKeys.userInformation) var userInformation = UserInformation() + + private var swiftUIImage: Image? { + image.flatMap { + Image(uiImage: $0) // swiftlint:disable:this accessibility_label_for_image + } + } + var stepsLeft: Int { + (userInformation.stepGoal ?? 1000) - (stepCountDataSource.todaysSteps ?? 1000) + } + var body: some View { + NavigationStack { + ImageSource(image: $image) + .clipShape(RoundedRectangle(cornerRadius: 8)) + .padding() + .navigationTitle("Photo Upload") + .toolbar { + if let swiftUIImage = swiftUIImage { + ToolbarItem { + ShareLink( + item: swiftUIImage, + subject: Text("GetMoovin 🚶"), + message: Text("I met my daily goal in GetMoovin!"), + preview: SharePreview("GetMoovin 🚶", image: swiftUIImage) + ) + } + } + } + } + } +} + struct StepCountView: View { @Environment(\.scenePhase) var scenePhase @EnvironmentObject var stepCountDataSource: StepCountDataSource @AppStorage(StorageKeys.userInformation) var userInformation = UserInformation() @State var todaysSteps: Int? - - var body: some View { - VStack { - if todaysSteps != nil { - DailyProgressCircle(todaysSteps: $todaysSteps) - + @State var showingSheet = false - /*var body: some View { - let data: [StepsInfo] = [ - .init(type: "Steps", count: stepCountDataSource.todaysSteps ?? 7000, color: "Blue"), - .init(type: "Steps", count: 10000, color: "Grey") - ] - Chart { - ForEach(data) { shape in - BarMark( - x: .value("Shape Type", shape.type), - y: .value("Total Count", shape.count) - ) - .foregroundStyle(by: .value("Shape Color", shape.color)) - } - } - ScrollView { - VStack { - if let todaysSteps = stepCountDataSource.todaysSteps { - Text("Today's step count: \(todaysSteps)")*/ - - } else { - ProgressView() - .padding() + var stepsLeft: Int { + (userInformation.stepGoal ?? 1000) - (stepCountDataSource.todaysSteps ?? 1000) + } + var stepGoal: Int { + (userInformation.stepGoal ?? 1000) + } + + var body: some View { + // this doesnt change anything + VStack { + Text("Your current goal is: \(stepGoal) steps/day") + .padding() + if stepsLeft <= 0 { + Text("Congrats! You've met your daily goal") + if stepsLeft < 0 { + Text("Wow, today you exceeded your goal by \(abs(stepsLeft))") } - if let stepGoal = userInformation.stepGoal { - Text("The goal is: \(stepGoal)") + Button("Take your photo") { + showingSheet.toggle() } + .foregroundColor(.white) + .font(.title) + .padding() + .background(.blue) + .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) + .sheet(isPresented: $showingSheet) { + SheetView() + } + } else { + Text("You still need \(stepsLeft) steps to reach your goal!") } - - .refreshable { - loadStepCount() - } - .onAppear { - loadStepCount() - } - .onChange(of: scenePhase) { _ in - loadStepCount() + VStack { + DailyProgressCircle(todaysSteps: $todaysSteps) + .padding() + } + + .refreshable { + loadStepCount() + } + .onAppear { + loadStepCount() + } + .onChange(of: scenePhase) { _ in + loadStepCount() + } + } - } @@ -78,13 +118,13 @@ struct StepCountView: View { } } } - - + #if DEBUG -struct StepCountView_Previews: PreviewProvider { - static var previews: some View { - StepCountView() - .environmentObject(MockStepCountDataSource(todaysSteps: 1042) as StepCountDataSource) + struct StepCountView_Previews: PreviewProvider { + static var previews: some View { + StepCountView() + .environmentObject(MockStepCountDataSource(todaysSteps: 1042) as StepCountDataSource) + } } -} #endif +