diff --git a/FitnessApp/Home/Models/Activity.swift b/FitnessApp/Home/Models/Activity.swift new file mode 100644 index 0000000..2af0469 --- /dev/null +++ b/FitnessApp/Home/Models/Activity.swift @@ -0,0 +1,16 @@ +// +// Activity.swift +// FitnessApp +// +// Created by Matt Bruce on 12/20/24. +// +import SwiftUI + +struct Activity { + let id: Int + let title: String + let subtitle: String + let image: String + let tintColor: Color + let amount: String +} diff --git a/FitnessApp/Home/Models/Workout.swift b/FitnessApp/Home/Models/Workout.swift new file mode 100644 index 0000000..bfed137 --- /dev/null +++ b/FitnessApp/Home/Models/Workout.swift @@ -0,0 +1,17 @@ +// +// Workout.swift +// FitnessApp +// +// Created by Matt Bruce on 12/20/24. +// +import SwiftUI + +struct Workout { + let id: Int + let title: String + let image: String + let tintColor: Color + let duration: String + let date: String + let calories: String +} diff --git a/FitnessApp/Home/ViewModels/HomeViewModel.swift b/FitnessApp/Home/ViewModels/HomeViewModel.swift new file mode 100644 index 0000000..4511501 --- /dev/null +++ b/FitnessApp/Home/ViewModels/HomeViewModel.swift @@ -0,0 +1,30 @@ +// +// HomeViewModel.swift +// FitnessApp +// +// Created by Matt Bruce on 12/20/24. +// +import SwiftUI + +@Observable +class HomeViewModel { + var activities: [Activity] = [] + var workouts: [Workout] = [] + var calories: Int = 123 + var active: Int = 205 + var stand: Int = 80 + + var mockActivities = [ + Activity(id: 0, title: "Today Steps", subtitle: "10,000 steps", image: "figure.walk", tintColor: .green, amount: "9,812"), + Activity(id: 1, title: "Today Steps", subtitle: "1,000 steps", image: "figure.walk", tintColor: .blue, amount: "812"), + Activity(id: 2, title: "Today Steps", subtitle: "12,000 steps", image: "figure.walk", tintColor: .purple, amount: "9,0000"), + Activity(id: 3, title: "Today Steps", subtitle: "50,000 steps", image: "figure.run", tintColor: .red, amount: "104,812") + ] + + var mockWorkouts = [ + Workout(id: 0, title: "Running", image: "figure.run", tintColor: .green, duration: "1 hrs", date: "Aug 3", calories: "100 kcal"), + Workout(id: 1, title: "Strength Training", image: "figure.run", tintColor: .purple, duration: "1.5 hrs", date: "Aug 3", calories: "130 kcal"), + Workout(id: 2, title: "Walking", image: "figure.run", tintColor: .blue, duration: ".5 hrs", date: "Aug 3", calories: "250 kcal"), + Workout(id: 3, title: "Bike", image: "figure.run", tintColor: .red, duration: "2 hrs", date: "Aug 29", calories: "500 kcal") + ] +} diff --git a/FitnessApp/Home/ActivityCard.swift b/FitnessApp/Home/Views/ActivityCard.swift similarity index 88% rename from FitnessApp/Home/ActivityCard.swift rename to FitnessApp/Home/Views/ActivityCard.swift index 65702ea..83936b2 100644 --- a/FitnessApp/Home/ActivityCard.swift +++ b/FitnessApp/Home/Views/ActivityCard.swift @@ -7,15 +7,6 @@ import SwiftUI -struct Activity { - let id: Int - let title: String - let subtitle: String - let image: String - let tintColor: Color - let amount: String -} - struct ActivityCard: View { @State var activity: Activity diff --git a/FitnessApp/Home/HomeView.swift b/FitnessApp/Home/Views/HomeView.swift similarity index 68% rename from FitnessApp/Home/HomeView.swift rename to FitnessApp/Home/Views/HomeView.swift index 55086e1..f78ec7d 100644 --- a/FitnessApp/Home/HomeView.swift +++ b/FitnessApp/Home/Views/HomeView.swift @@ -8,24 +8,8 @@ import SwiftUI struct HomeView: View { - @State var calories: Int = 123 - @State var active: Int = 205 - @State var stand: Int = 80 - - var mockActivities = [ - Activity(id: 0, title: "Today Steps", subtitle: "10,000 steps", image: "figure.walk", tintColor: .green, amount: "9,812"), - Activity(id: 1, title: "Today Steps", subtitle: "1,000 steps", image: "figure.walk", tintColor: .blue, amount: "812"), - Activity(id: 2, title: "Today Steps", subtitle: "12,000 steps", image: "figure.walk", tintColor: .purple, amount: "9,0000"), - Activity(id: 3, title: "Today Steps", subtitle: "50,000 steps", image: "figure.run", tintColor: .red, amount: "104,812") - ] - - var mockWorkouts = [ - Workout(id: 0, title: "Running", image: "figure.run", tintColor: .green, duration: "1 hrs", date: "Aug 3", calories: "100 kcal"), - Workout(id: 1, title: "Strength Training", image: "figure.run", tintColor: .purple, duration: "1.5 hrs", date: "Aug 3", calories: "130 kcal"), - Workout(id: 2, title: "Walking", image: "figure.run", tintColor: .blue, duration: ".5 hrs", date: "Aug 3", calories: "250 kcal"), - Workout(id: 3, title: "Bike", image: "figure.run", tintColor: .red, duration: "2 hrs", date: "Aug 29", calories: "500 kcal") - ] - + @State var viewModel: HomeViewModel = .init() + var body: some View { NavigationStack { ScrollView(showsIndicators: false) { @@ -44,7 +28,7 @@ struct HomeView: View { .bold() .foregroundColor(.red) - Text("123 kcal") + Text("\(viewModel.calories)") .bold() }.padding(.bottom) @@ -54,7 +38,7 @@ struct HomeView: View { .bold() .foregroundColor(.green) - Text("52 mins") + Text("\(viewModel.active)") .bold() }.padding(.bottom) @@ -65,7 +49,7 @@ struct HomeView: View { .bold() .foregroundColor(.blue) - Text("8 hrs") + Text("\(viewModel.stand)") .bold() } @@ -75,9 +59,9 @@ struct HomeView: View { ZStack { Spacer() - ProgressCircleView(progress: $calories, goal: 600, color: .red) - ProgressCircleView(progress: $active, goal: 600, color: .green).padding(.all, 20) - ProgressCircleView(progress: $stand, goal: 600, color: .blue).padding(.all, 40) + ProgressCircleView(progress: $viewModel.calories, goal: 600, color: .red) + ProgressCircleView(progress: $viewModel.active, goal: 600, color: .green).padding(.all, 20) + ProgressCircleView(progress: $viewModel.stand, goal: 600, color: .blue).padding(.all, 40) } .padding(.horizontal) @@ -105,13 +89,13 @@ struct HomeView: View { .padding(.horizontal) LazyVGrid(columns: Array(repeating: GridItem(spacing: 20), count: 2)) { - ForEach(mockActivities, id: \.id) { activity in + ForEach(viewModel.mockActivities , id: \.id) { activity in ActivityCard(activity: activity) } }.padding(.horizontal) - //Fitness Activity + //Recent Workouts HStack { Text("Recent Workouts") .font(.title2) @@ -130,7 +114,7 @@ struct HomeView: View { .padding(.horizontal) .padding(.top) LazyVStack{ - ForEach(mockWorkouts, id: \.id) { workout in + ForEach(viewModel.mockWorkouts, id: \.id) { workout in WorkoutCard(workout: workout) } } diff --git a/FitnessApp/Home/ProgressCircleView.swift b/FitnessApp/Home/Views/ProgressCircleView.swift similarity index 100% rename from FitnessApp/Home/ProgressCircleView.swift rename to FitnessApp/Home/Views/ProgressCircleView.swift diff --git a/FitnessApp/Home/WorkoutCard.swift b/FitnessApp/Home/Views/WorkoutCard.swift similarity index 86% rename from FitnessApp/Home/WorkoutCard.swift rename to FitnessApp/Home/Views/WorkoutCard.swift index 5c1722c..1a3100e 100644 --- a/FitnessApp/Home/WorkoutCard.swift +++ b/FitnessApp/Home/Views/WorkoutCard.swift @@ -7,17 +7,6 @@ import SwiftUI -struct Workout { - let id: Int - let title: String - let image: String - let tintColor: Color - let duration: String - let date: String - let calories: String -} - - struct WorkoutCard: View { @State var workout: Workout