diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..79167db --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,14 @@ +{ + "permissions": { + "allow": [ + "Bash(grep:*)", + "Bash(du -sh:*)", + "Bash(./scripts/smoke/build_ios.sh:*)", + "Bash(find .:*)", + "Bash(find:*)", + "Bash(ls:*)", + "Bash(tail:*)", + "Bash(head:*)" + ] + } +} diff --git a/SharedCore/Package.swift b/SharedCore/Package.swift index 266d78a..50b7ce0 100644 --- a/SharedCore/Package.swift +++ b/SharedCore/Package.swift @@ -1,10 +1,10 @@ -// swift-tools-version: 5.9 +// swift-tools-version: 6.2 import PackageDescription let package = Package( name: "SharedCore", platforms: [ - .iOS(.v16), + .iOS(.v26), .watchOS(.v9), .tvOS(.v16), .macOS(.v13) @@ -31,5 +31,6 @@ let package = Package( name: "SharedCoreTVOSTests", dependencies: ["SharedCore"] ) - ] + ], + swiftLanguageModes: [.v5] ) diff --git a/SharedCore/Sources/SharedCore/AppNotifications.swift b/SharedCore/Sources/SharedCore/AppNotifications.swift index 4f5d617..530998f 100644 --- a/SharedCore/Sources/SharedCore/AppNotifications.swift +++ b/SharedCore/Sources/SharedCore/AppNotifications.swift @@ -2,5 +2,6 @@ import Foundation public enum AppNotifications { public static let createdNewWorkout = Notification.Name("CreatedNewWorkout") + public static let userLoggedOut = Notification.Name("UserLoggedOut") } diff --git a/WekoutThotViewer/WekoutThotViewer/ContentView.swift b/WekoutThotViewer/WekoutThotViewer/ContentView.swift index e87a9e2..192d93c 100644 --- a/WekoutThotViewer/WekoutThotViewer/ContentView.swift +++ b/WekoutThotViewer/WekoutThotViewer/ContentView.swift @@ -15,7 +15,7 @@ struct ContentView: View { @ObservedObject var dataStore = DataStore.shared @State var nsfwVideos: [NSFWVideo]? @State private var showLoginView = false - @State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) + @State var avPlayer = AVPlayer(url: URL(string: BaseURLs.currentBaseURL + "/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) @State private var currentVideoURL: URL? let videoEnded = NotificationCenter.default.publisher(for: NSNotification.Name.AVPlayerItemDidPlayToEndTime) diff --git a/iphone/Werkout_ios.xcodeproj/project.pbxproj b/iphone/Werkout_ios.xcodeproj/project.pbxproj index 3a57402..99a1061 100644 --- a/iphone/Werkout_ios.xcodeproj/project.pbxproj +++ b/iphone/Werkout_ios.xcodeproj/project.pbxproj @@ -323,13 +323,6 @@ }; /* End PBXTargetDependency section */ -/* Begin XCLocalSwiftPackageReference section */ - D00100012E00000100000003 /* XCLocalSwiftPackageReference "../SharedCore" */ = { - isa = XCLocalSwiftPackageReference; - relativePath = ../SharedCore; - }; -/* End XCLocalSwiftPackageReference section */ - /* Begin XCBuildConfiguration section */ 1CF65A342A3972850042FFBD /* Debug */ = { isa = XCBuildConfiguration; @@ -461,9 +454,9 @@ ENABLE_APP_INTENTS_METADATA_GENERATION = NO; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; - EXCLUDED_SOURCE_FILE_NAMES = "Werkout_ios/Resources/Werkout-ios-Info.plist"; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_FILE = "Werkout-ios-Info.plist"; + EXCLUDED_SOURCE_FILE_NAMES = "Werkout_ios/Resources/Werkout-ios-Info.plist"; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = "Werkout-ios-Info.plist"; INFOPLIST_KEY_NSHealthShareUsageDescription = "Read your heart rate"; INFOPLIST_KEY_NSHealthUpdateUsageDescription = "Read your heart rate"; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; @@ -477,7 +470,7 @@ "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 16.4; + IPHONEOS_DEPLOYMENT_TARGET = 26.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.3; @@ -507,9 +500,9 @@ ENABLE_APP_INTENTS_METADATA_GENERATION = NO; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; - EXCLUDED_SOURCE_FILE_NAMES = "Werkout_ios/Resources/Werkout-ios-Info.plist"; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_FILE = "Werkout-ios-Info.plist"; + EXCLUDED_SOURCE_FILE_NAMES = "Werkout_ios/Resources/Werkout-ios-Info.plist"; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = "Werkout-ios-Info.plist"; INFOPLIST_KEY_NSHealthShareUsageDescription = "Read your heart rate"; INFOPLIST_KEY_NSHealthUpdateUsageDescription = "Read your heart rate"; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; @@ -523,7 +516,7 @@ "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 16.4; + IPHONEOS_DEPLOYMENT_TARGET = 26.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.3; @@ -613,14 +606,6 @@ }; /* End XCBuildConfiguration section */ -/* Begin XCSwiftPackageProductDependency section */ - D00100012E00000100000004 /* SharedCore */ = { - isa = XCSwiftPackageProductDependency; - package = D00100012E00000100000003 /* XCLocalSwiftPackageReference "../SharedCore" */; - productName = SharedCore; - }; -/* End XCSwiftPackageProductDependency section */ - /* Begin XCConfigurationList section */ 1CF65A1D2A3972840042FFBD /* Build configuration list for PBXProject "Werkout_ios" */ = { isa = XCConfigurationList; @@ -650,6 +635,21 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCLocalSwiftPackageReference section */ + D00100012E00000100000003 /* XCLocalSwiftPackageReference "../SharedCore" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = ../SharedCore; + }; +/* End XCLocalSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + D00100012E00000100000004 /* SharedCore */ = { + isa = XCSwiftPackageProductDependency; + package = D00100012E00000100000003 /* XCLocalSwiftPackageReference "../SharedCore" */; + productName = SharedCore; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 1CF65A1A2A3972840042FFBD /* Project object */; } diff --git a/iphone/Werkout_ios/Assets.xcassets/appColor.colorset/Contents.json b/iphone/Werkout_ios/Assets.xcassets/appColor.colorset/Contents.json index 42e5b65..79fcc6c 100644 --- a/iphone/Werkout_ios/Assets.xcassets/appColor.colorset/Contents.json +++ b/iphone/Werkout_ios/Assets.xcassets/appColor.colorset/Contents.json @@ -2,8 +2,13 @@ "colors" : [ { "color" : { - "platform" : "universal", - "reference" : "systemPurpleColor" + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "0.350", + "red" : "0.750" + } }, "idiom" : "universal" }, @@ -15,8 +20,13 @@ } ], "color" : { - "platform" : "universal", - "reference" : "systemPurpleColor" + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "0.350", + "red" : "0.750" + } }, "idiom" : "universal" } diff --git a/iphone/Werkout_ios/BaseURLs.swift b/iphone/Werkout_ios/BaseURLs.swift index c43c8e6..75d493c 100644 --- a/iphone/Werkout_ios/BaseURLs.swift +++ b/iphone/Werkout_ios/BaseURLs.swift @@ -9,7 +9,7 @@ import Foundation enum BaseURLs: String { case local = "http://127.0.0.1:8000" - case dev = "https://dev.werkout.fitness" + case dev = "https://werkout.treytartt.com" static var currentBaseURL: String { return BaseURLs.dev.rawValue diff --git a/iphone/Werkout_ios/BridgeModule+Timer.swift b/iphone/Werkout_ios/BridgeModule+Timer.swift index a42637a..a4e21e1 100644 --- a/iphone/Werkout_ios/BridgeModule+Timer.swift +++ b/iphone/Werkout_ios/BridgeModule+Timer.swift @@ -9,15 +9,18 @@ import Foundation extension BridgeModule { func startWorkoutTimer() { - currentWorkoutRunTimer?.invalidate() - currentWorkoutRunTimer = nil - currentWorkoutRunTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [weak self] _ in - guard let self else { return } - self.currentWorkoutRunTimeInSeconds += 1 - self.sendCurrentExerciseToWatch() - }) - currentWorkoutRunTimer?.tolerance = 0.1 - currentWorkoutRunTimer?.fire() + DispatchQueue.main.async { + self.currentWorkoutRunTimer?.invalidate() + self.currentWorkoutRunTimer = nil + self.currentWorkoutRunTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [weak self] _ in + guard let self else { return } + dispatchPrecondition(condition: .onQueue(.main)) + self.currentWorkoutRunTimeInSeconds += 1 + self.sendCurrentExerciseToWatch() + }) + self.currentWorkoutRunTimer?.tolerance = 0.1 + self.currentWorkoutRunTimer?.fire() + } } func startExerciseTimerWith(duration: Int) { diff --git a/iphone/Werkout_ios/BridgeModule+Watch.swift b/iphone/Werkout_ios/BridgeModule+Watch.swift index 96d81dd..506f070 100644 --- a/iphone/Werkout_ios/BridgeModule+Watch.swift +++ b/iphone/Werkout_ios/BridgeModule+Watch.swift @@ -39,17 +39,21 @@ extension BridgeModule: WCSessionDelegate { } private func flushQueuedWatchMessages() { - let queuedMessages = queuedWatchMessages.dequeueAll() - guard queuedMessages.isEmpty == false else { - return + watchMessageQueue.sync { + let queuedMessages = queuedWatchMessages.dequeueAll() + guard queuedMessages.isEmpty == false else { + return + } + queuedMessages.forEach { send($0) } } - queuedMessages.forEach { send($0) } } private func enqueueWatchMessage(_ data: Data) { - let droppedCount = queuedWatchMessages.enqueue(data) - if droppedCount > 0 { - watchBridgeLogger.warning("Dropping oldest queued watch message to enforce queue cap") + watchMessageQueue.sync { + let droppedCount = queuedWatchMessages.enqueue(data) + if droppedCount > 0 { + watchBridgeLogger.warning("Dropping oldest queued watch message to enforce queue cap") + } } } @@ -90,7 +94,7 @@ extension BridgeModule: WCSessionDelegate { } } - func session(_ session: WCSession, didReceiveMessageData messageData: Data) { + func dataToAction(messageData: Data) { do { let model = try WatchPayloadValidation.decode(WatchActions.self, from: messageData) DispatchQueue.main.async { @@ -119,6 +123,10 @@ extension BridgeModule: WCSessionDelegate { watchBridgeLogger.error("Rejected WatchActions payload: \(error.localizedDescription, privacy: .public)") } } + + func session(_ session: WCSession, didReceiveMessageData messageData: Data) { + dataToAction(messageData: messageData) + } func session(_ session: WCSession, @@ -158,6 +166,22 @@ extension BridgeModule: WCSessionDelegate { func sessionDidDeactivate(_ session: WCSession) { session.activate() } + + func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) { + if let messageData = applicationContext["package"] as? Data { + DispatchQueue.main.async { + self.dataToAction(messageData: messageData) + } + } + } + + func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) { + if let messageData = userInfo["package"] as? Data { + DispatchQueue.main.async { + self.dataToAction(messageData: messageData) + } + } + } #endif func send(_ data: Data) { guard WCSession.isSupported() else { diff --git a/iphone/Werkout_ios/BridgeModule.swift b/iphone/Werkout_ios/BridgeModule.swift index 594a418..d9563c2 100644 --- a/iphone/Werkout_ios/BridgeModule.swift +++ b/iphone/Werkout_ios/BridgeModule.swift @@ -55,6 +55,7 @@ class BridgeModule: NSObject, ObservableObject { @Published var isPaused = false let session: WCSession = WCSession.default + let watchMessageQueue = DispatchQueue(label: "com.werkout.watchMessageQueue") var queuedWatchMessages = BoundedFIFOQueue(maxCount: 100) var lastSentInExercisePayload: Data? } diff --git a/iphone/Werkout_ios/DataStore.swift b/iphone/Werkout_ios/DataStore.swift index 2c0af44..0806d9f 100644 --- a/iphone/Werkout_ios/DataStore.swift +++ b/iphone/Werkout_ios/DataStore.swift @@ -6,7 +6,7 @@ // import Foundation -import SwiftUI +import Combine import SharedCore class DataStore: ObservableObject { diff --git a/iphone/Werkout_ios/Network/Fetchables.swift b/iphone/Werkout_ios/Network/Fetchables.swift index 6f972a4..2b69d75 100644 --- a/iphone/Werkout_ios/Network/Fetchables.swift +++ b/iphone/Werkout_ios/Network/Fetchables.swift @@ -17,7 +17,7 @@ class WorkoutDetailFetchable: Fetchable { var endPoint: String init(workoutID: Int) { - self.endPoint = "/workout/"+String(workoutID)+"/details/" + self.endPoint = "/workout/\(workoutID)/details/" } } @@ -103,7 +103,7 @@ class AllNSFWVideosFetchable: Fetchable { var endPoint: String = "/videos/nsfw_videos/" } -class RefreshUserInfoFetcable: Fetchable { +class RefreshUserInfoFetchable: Fetchable { typealias Response = RegisteredUser var endPoint: String = "/registered_user/refresh/" } diff --git a/iphone/Werkout_ios/Network/Network.swift b/iphone/Werkout_ios/Network/Network.swift index 9f8138f..245cee6 100644 --- a/iphone/Werkout_ios/Network/Network.swift +++ b/iphone/Werkout_ios/Network/Network.swift @@ -173,7 +173,7 @@ extension Postable { } if let httpResponse = response as? HTTPURLResponse, - httpResponse.statusCode != successStatus { + !(200...299).contains(httpResponse.statusCode) { let responseBody = data.flatMap { String(data: $0, encoding: .utf8) } handleHTTPFailure(statusCode: httpResponse.statusCode, responseBody: responseBody, diff --git a/iphone/Werkout_ios/UserStore.swift b/iphone/Werkout_ios/UserStore.swift index 3de7184..5d6db45 100644 --- a/iphone/Werkout_ios/UserStore.swift +++ b/iphone/Werkout_ios/UserStore.swift @@ -148,7 +148,7 @@ class UserStore: ObservableObject { } public func refreshUserData() { - RefreshUserInfoFetcable().fetch(completion: { result in + RefreshUserInfoFetchable().fetch(completion: { result in switch result { case .success(let registeredUser): let sanitizedModel = self.userByReplacingToken(registeredUser, token: self.normalizedToken(from: registeredUser.token)) @@ -179,7 +179,7 @@ class UserStore: ObservableObject { runtimeReporter.recordInfo("User logged out", metadata: ["reason": reason]) DispatchQueue.main.async { - NotificationCenter.default.post(name: AppNotifications.createdNewWorkout, object: nil, userInfo: nil) + NotificationCenter.default.post(name: AppNotifications.userLoggedOut, object: nil, userInfo: nil) } } diff --git a/iphone/Werkout_ios/Views/AccountView/AccountView.swift b/iphone/Werkout_ios/Views/AccountView/AccountView.swift index 50e1df4..efa7cd9 100644 --- a/iphone/Werkout_ios/Views/AccountView/AccountView.swift +++ b/iphone/Werkout_ios/Views/AccountView/AccountView.swift @@ -10,32 +10,34 @@ import SwiftUI struct AccountView: View { @ObservedObject var userStore = UserStore.shared - - + + var body: some View { VStack(alignment: .leading) { NameView() - + CompletedWorkoutsView() - + Divider() - + .overlay(WerkoutTheme.divider) + ThotPreferenceView() - + ShowNextUpView() - + Spacer() - + Logoutview() } .padding() + .background(WerkoutTheme.background) } } //struct AccountView_Previews: PreviewProvider { // static let userStore = UserStore.shared // static let completedWorkouts = PreviewData.parseCompletedWorkouts() -// +// // static var previews: some View { // AccountView(completedWorkouts: completedWorkouts) // .onAppear{ diff --git a/iphone/Werkout_ios/Views/AddExercise/AddExerciseView.swift b/iphone/Werkout_ios/Views/AddExercise/AddExerciseView.swift index 662e063..6806e0a 100644 --- a/iphone/Werkout_ios/Views/AddExercise/AddExerciseView.swift +++ b/iphone/Werkout_ios/Views/AddExercise/AddExerciseView.swift @@ -14,77 +14,63 @@ struct AddExerciseView: View { case muscles case equipment } - + @State var selectedMuscles = [Muscle]() @State var selectedEquipment = [Equipment]() @State var filteredExercises = [Exercise]() - - @StateObject var bridgeModule = BridgeModule.shared + + @ObservedObject var bridgeModule = BridgeModule.shared let selectedExercise: ((Exercise) -> Void) - + var body: some View { - VStack { + VStack(spacing: 0) { AllExerciseView(filteredExercises: $filteredExercises, selectedExercise: { excercise in selectedExercise(excercise) }) - .padding(.top) - + .padding(.top, WerkoutTheme.md) + + Divider() + .overlay(WerkoutTheme.divider) + HStack { AllMusclesView(selectedMuscles: $selectedMuscles) .frame(maxWidth: .infinity) - + Divider() - + .overlay(WerkoutTheme.divider) + AllEquipmentView(selectedEquipment: $selectedEquipment) .frame(maxWidth: .infinity) } - .padding(.top) + .padding(.top, WerkoutTheme.sm) .frame(height: 44) } - .onChange(of: selectedMuscles, perform: { _ in + .background(WerkoutTheme.background) + .onChange(of: selectedMuscles) { _, _ in filterExercises() - }) .onChange(of: selectedEquipment, perform: { _ in + } + .onChange(of: selectedEquipment) { _, _ in filterExercises() - }) + } } - + func filterExercises() { guard let exercises = DataStore.shared.allExercise else { filteredExercises = [] return } - - let filtered = exercises.filter({ exercise in - var hasCorrectMuscles = false - if selectedMuscles.count == 0 { - hasCorrectMuscles = true - } else { - let exerciseMuscleIds = exercise.muscles.map({ $0.muscle ?? -1 }) - let selctedMuscleIds = selectedMuscles.map({ $0.id }) - // if one items match - if exerciseMuscleIds.contains(where: selctedMuscleIds.contains) { - // if all items match - hasCorrectMuscles = true - } - } - - var hasCorrectEquipment = false - if selectedEquipment.count == 0 { - hasCorrectEquipment = true - } else { - let exerciseEquipmentIds = exercise.equipment.map({ $0.equipment ?? -1 }) - let selctedEquipmentIds = selectedEquipment.map({ $0.id }) - // if one items match - if exerciseEquipmentIds.contains(where: selctedEquipmentIds.contains) { - // if all items match - hasCorrectEquipment = true - } - } - return hasCorrectMuscles && hasCorrectEquipment - }) - - filteredExercises = filtered + + let selectedMuscleIds = Set(selectedMuscles.map { $0.id }) + let selectedEquipmentIds = Set(selectedEquipment.map { $0.id }) + + filteredExercises = exercises.filter { exercise in + let muscleOK = selectedMuscleIds.isEmpty || + exercise.muscles.contains(where: { selectedMuscleIds.contains($0.muscle ?? -1) }) + let equipmentOK = selectedEquipmentIds.isEmpty || + exercise.equipment.contains(where: { selectedEquipmentIds.contains($0.equipment ?? -1) }) + return muscleOK && equipmentOK + } } } diff --git a/iphone/Werkout_ios/Views/AllWorkouts/AllWorkoutsListView.swift b/iphone/Werkout_ios/Views/AllWorkouts/AllWorkoutsListView.swift index ea4ed37..175db7c 100644 --- a/iphone/Werkout_ios/Views/AllWorkouts/AllWorkoutsListView.swift +++ b/iphone/Werkout_ios/Views/AllWorkouts/AllWorkoutsListView.swift @@ -13,88 +13,88 @@ enum SortType: String, CaseIterable { } struct AllWorkoutsListView: View { - @State var searchNameString: String = "" - @State var selectedMuscles: Set = [] - @State var selectedEquipment: Set = [] - @Binding var uniqueWorkoutUsers: [RegisteredUser]? - @State private var filteredRegisterdUser: RegisteredUser? - let workouts: [Workout] + @Binding var searchText: String + @Binding var selectedMuscles: Set + @Binding var selectedEquipment: Set + @Binding var filteredRegisterdUser: RegisteredUser? + @Binding var currentSort: SortType? + @Binding var sortAscending: Bool + let selectedWorkout: ((Workout) -> Void) - @State var filteredWorkouts = [Workout]() var refresh: (() -> Void) - @State var currentSort: SortType? - + + @State private var filteredWorkouts = [Workout]() + var body: some View { - VStack { - VStack { - if let filteredRegisterdUser = filteredRegisterdUser { - Text((filteredRegisterdUser.firstName ?? "NA") + "'s Workouts") - } - - FilterAllView(selectedMuscles: $selectedMuscles, - selectedEquipment: $selectedEquipment, - searchNameString: $searchNameString, - uniqueWorkoutUsers: $uniqueWorkoutUsers, - filteredRegisterdUser: $filteredRegisterdUser, - filteredWorkouts: $filteredWorkouts, - workouts: .constant(workouts), - currentSort: $currentSort) - } - - ScrollView { - LazyVStack(spacing: 10) { - ForEach(filteredWorkouts, id:\.id) { workout in - Button(action: { - selectedWorkout(workout) - }, label: { - WorkoutOverviewView(workout: workout) - .padding([.leading, .trailing], 4) - .contentShape(Rectangle()) - }) - .buttonStyle(.plain) - .accessibilityLabel("Open \(workout.name)") - .accessibilityHint("Shows workout details") - } + ScrollView { + LazyVStack(spacing: WerkoutTheme.sm) { + ForEach(filteredWorkouts, id: \.id) { workout in + Button(action: { + selectedWorkout(workout) + }, label: { + WorkoutOverviewView(workout: workout) + .padding(.horizontal, WerkoutTheme.sm) + .contentShape(Rectangle()) + }) + .buttonStyle(.plain) + .accessibilityLabel("Open \(workout.name)") + .accessibilityHint("Shows workout details") } } - .background(Color(uiColor: .systemBackground)) - .refreshable { - refresh() - } + .padding(.top, WerkoutTheme.sm) } - .onChange(of: searchNameString) { newValue in - filterWorkouts() + .scrollEdgeEffectStyle(.soft, for: .top) + .background(WerkoutTheme.background) + .refreshable { + refresh() } - .onChange(of: selectedMuscles) { newValue in - filterWorkouts() - } - .onChange(of: selectedEquipment) { newValue in - filterWorkouts() - } - .onAppear{ - filterWorkouts() - } - .onChange(of: workouts) { _ in - filterWorkouts() + .onAppear { + applyFilters() } + .onChange(of: searchText) { applyFilters() } + .onChange(of: selectedMuscles) { applyFilters() } + .onChange(of: selectedEquipment) { applyFilters() } + .onChange(of: filteredRegisterdUser) { applyFilters() } + .onChange(of: currentSort) { applyFilters() } + .onChange(of: sortAscending) { applyFilters() } + .onChange(of: workouts) { applyFilters() } } - - func filterWorkouts() { - filteredWorkouts = workouts.filterWorkouts( - nameSearchString: searchNameString, + + private func applyFilters() { + var results = workouts.filterWorkouts( + nameSearchString: searchText, musclesSearchString: selectedMuscles, equipmentSearchString: selectedEquipment, filteredRegisterdUser: filteredRegisterdUser ) + + if let sort = currentSort { + switch sort { + case .name: + results.sort { $0.name < $1.name } + case .createdDate: + results.sort { ($0.createdAt ?? Date()) < ($1.createdAt ?? Date()) } + } + if !sortAscending { + results.reverse() + } + } + + filteredWorkouts = results } } struct AllWorkoutsListView_Previews: PreviewProvider { static var previews: some View { - AllWorkoutsListView(uniqueWorkoutUsers: .constant([]), - workouts: PreviewData.allWorkouts(), - selectedWorkout: { workout in }, - refresh: { }) + AllWorkoutsListView(workouts: PreviewData.allWorkouts(), + searchText: .constant(""), + selectedMuscles: .constant([]), + selectedEquipment: .constant([]), + filteredRegisterdUser: .constant(nil), + currentSort: .constant(nil), + sortAscending: .constant(true), + selectedWorkout: { _ in }, + refresh: {}) } } diff --git a/iphone/Werkout_ios/Views/AllWorkouts/AllWorkoutsView.swift b/iphone/Werkout_ios/Views/AllWorkouts/AllWorkoutsView.swift index c5a6196..111baeb 100644 --- a/iphone/Werkout_ios/Views/AllWorkouts/AllWorkoutsView.swift +++ b/iphone/Werkout_ios/Views/AllWorkouts/AllWorkoutsView.swift @@ -13,88 +13,142 @@ import SharedCore enum MainViewTypes: Int, CaseIterable { case AllWorkout = 0 case MyWorkouts - + var title: String { switch self { - case .AllWorkout: return "All Workouts" case .MyWorkouts: - return "Planned Workouts" + return "Planned" } } } struct AllWorkoutsView: View { - @State var isUpdating = false - @State var workouts: [Workout]? - @State var uniqueWorkoutUsers: [RegisteredUser]? + @State private var isUpdating = false + + private var workouts: [Workout]? { + dataStore.allWorkouts?.sorted(by: { $0.createdAt ?? Date() < $1.createdAt ?? Date() }) + } + + private var uniqueWorkoutUsers: [RegisteredUser]? { + dataStore.workoutsUniqueUsers + } + let healthStore = HKHealthStore() var bridgeModule = BridgeModule.shared - @State public var needsUpdating: Bool = true - + @State private var needsUpdating: Bool = true + @ObservedObject var dataStore = DataStore.shared @ObservedObject var userStore = UserStore.shared - + @State private var showWorkoutDetail = false @State private var selectedWorkout: Workout? { didSet { bridgeModule.currentWorkoutInfo.workout = selectedWorkout } } - + @State private var selectedPlannedWorkout: Workout? { didSet { bridgeModule.currentWorkoutInfo.workout = selectedPlannedWorkout } } - + @State private var showLoginView = false @State private var selectedSegment: MainViewTypes = .AllWorkout - @State var selectedDate: Date = Date() + @State private var selectedDate: Date = Date() private let runtimeReporter = RuntimeReporter.shared - + + // MARK: - Hoisted filter state + + @State private var searchText = "" + @State private var selectedMuscles: Set = [] + @State private var selectedEquipment: Set = [] + @State private var filteredRegisterdUser: RegisteredUser? + @State private var currentSort: SortType? + @State private var sortAscending: Bool = true + let pub = NotificationCenter.default.publisher(for: AppNotifications.createdNewWorkout) - var body: some View { - ZStack { - if let workouts = workouts { - VStack { - AllWorkoutPickerView(mainViews: MainViewTypes.allCases, - selectedSegment: $selectedSegment, - showCurrentWorkout: { - selectedWorkout = bridgeModule.currentWorkoutInfo.workout - }) - - switch selectedSegment { - case .AllWorkout: - if isUpdating { - ProgressView() - .progressViewStyle(.circular) - } - - AllWorkoutsListView(uniqueWorkoutUsers: $uniqueWorkoutUsers, - workouts: workouts, - selectedWorkout: { workout in - selectedWorkout = workout - }, refresh: { - self.needsUpdating = true - maybeRefreshData() - }) + private var hasActiveFilters: Bool { + !selectedMuscles.isEmpty || !selectedEquipment.isEmpty || filteredRegisterdUser != nil + } - Divider() - case .MyWorkouts: - PlannedWorkoutView(workouts: userStore.plannedWorkouts, - selectedPlannedWorkout: $selectedPlannedWorkout) + var body: some View { + NavigationStack { + ZStack { + WerkoutTheme.background.ignoresSafeArea() + + if let workouts = workouts { + VStack(spacing: 0) { + // Active filter chips + if hasActiveFilters { + filterChipsRow + } + + switch selectedSegment { + case .AllWorkout: + if isUpdating { + ProgressView() + .progressViewStyle(.circular) + .tint(WerkoutTheme.accent) + } + + AllWorkoutsListView(workouts: workouts, + searchText: $searchText, + selectedMuscles: $selectedMuscles, + selectedEquipment: $selectedEquipment, + filteredRegisterdUser: $filteredRegisterdUser, + currentSort: $currentSort, + sortAscending: $sortAscending, + selectedWorkout: { workout in + selectedWorkout = workout + }, refresh: { + self.needsUpdating = true + maybeRefreshData() + }) + case .MyWorkouts: + PlannedWorkoutView(workouts: userStore.plannedWorkouts, + selectedPlannedWorkout: $selectedPlannedWorkout) + } + } + } else { + ProgressView() + .progressViewStyle(.circular) + .tint(WerkoutTheme.accent) + } + } + .navigationTitle("Workouts") + .searchable(text: $searchText, prompt: "Search workouts") + .toolbar { + ToolbarItem(placement: .principal) { + Picker("View", selection: $selectedSegment) { + ForEach(MainViewTypes.allCases, id: \.self) { viewType in + Text(viewType.title).tag(viewType) + } + } + .pickerStyle(.segmented) + .frame(width: 200) + } + + ToolbarItem(placement: .topBarTrailing) { + HStack(spacing: WerkoutTheme.sm) { + if bridgeModule.isInWorkout { + Button(action: { + selectedWorkout = bridgeModule.currentWorkoutInfo.workout + }) { + Image(systemName: "figure.strengthtraining.traditional") + } + .tint(WerkoutTheme.accent) + } + + filterMenu } } - } else { - ProgressView("Updating") } } - .background(Color(uiColor: .systemGray5)) - .onAppear{ -// UserStore.shared.logout() + .onAppear { authorizeHealthKit() maybeRefreshData() } @@ -114,31 +168,171 @@ struct AllWorkoutsView: View { }) .interactiveDismissDisabled() } - .onReceive(pub) { (output) in + .onReceive(pub) { _ in self.needsUpdating = true maybeRefreshData() } } + // MARK: - Filter Menu + + private var filterMenu: some View { + Menu { + // Sort section + Section("Sort") { + ForEach(SortType.allCases, id: \.self) { sortType in + Button(action: { + if currentSort == sortType { + sortAscending.toggle() + } else { + currentSort = sortType + sortAscending = true + } + }) { + Label { + Text(sortType.rawValue) + } icon: { + if currentSort == sortType { + Image(systemName: sortAscending ? "chevron.up" : "chevron.down") + } + } + } + } + } + + // Creator filter + if let users = uniqueWorkoutUsers, !users.isEmpty { + Section("Creator") { + ForEach(users, id: \.self) { user in + Button(action: { + filteredRegisterdUser = user + }) { + Label { + Text("\(user.firstName ?? "") \(user.lastName ?? "")") + } icon: { + if filteredRegisterdUser == user { + Image(systemName: "checkmark") + } + } + } + } + + Button("All Creators") { + filteredRegisterdUser = nil + } + } + } + + // Muscles filter + if let muscles = DataStore.shared.allMuscles { + Section("Muscles") { + ForEach(muscles, id: \.id) { muscle in + Button(action: { + if selectedMuscles.contains(muscle.name) { + selectedMuscles.remove(muscle.name) + } else { + selectedMuscles.insert(muscle.name) + } + }) { + Label { + Text(muscle.name) + } icon: { + if selectedMuscles.contains(muscle.name) { + Image(systemName: "checkmark") + } + } + } + } + } + } + + // Equipment filter + if let equipments = DataStore.shared.allEquipment { + Section("Equipment") { + ForEach(equipments, id: \.id) { equipment in + Button(action: { + if selectedEquipment.contains(equipment.name) { + selectedEquipment.remove(equipment.name) + } else { + selectedEquipment.insert(equipment.name) + } + }) { + Label { + Text(equipment.name) + } icon: { + if selectedEquipment.contains(equipment.name) { + Image(systemName: "checkmark") + } + } + } + } + } + } + + // Clear all + if hasActiveFilters || currentSort != nil { + Divider() + Button(role: .destructive) { + clearAllFilters() + } label: { + Label("Clear All Filters", systemImage: "xmark.circle") + } + } + } label: { + Image(systemName: hasActiveFilters ? "line.3.horizontal.decrease.circle.fill" : "line.3.horizontal.decrease.circle") + } + .tint(hasActiveFilters ? WerkoutTheme.accent : nil) + } + + // MARK: - Filter Chips Row + + private var filterChipsRow: some View { + ScrollView(.horizontal, showsIndicators: false) { + HStack(spacing: WerkoutTheme.sm) { + ForEach(Array(selectedMuscles), id: \.self) { muscle in + FilterChip(label: muscle, color: WerkoutTheme.accent) { + selectedMuscles.remove(muscle) + } + } + + ForEach(Array(selectedEquipment), id: \.self) { equipment in + FilterChip(label: equipment, color: WerkoutTheme.textSecondary) { + selectedEquipment.remove(equipment) + } + } + + if let user = filteredRegisterdUser { + FilterChip(label: user.firstName ?? "User", color: WerkoutTheme.accentNeon) { + filteredRegisterdUser = nil + } + } + } + .padding(.horizontal, WerkoutTheme.md) + .padding(.vertical, WerkoutTheme.xs) + } + } + + // MARK: - Actions + + private func clearAllFilters() { + selectedMuscles.removeAll() + selectedEquipment.removeAll() + filteredRegisterdUser = nil + currentSort = nil + sortAscending = true + } + func maybeRefreshData() { - if userStore.token != nil{ + if userStore.token != nil { if userStore.plannedWorkouts.isEmpty { userStore.fetchPlannedWorkouts() } - + if needsUpdating { self.isUpdating = true dataStore.fetchAllData(completion: { DispatchQueue.main.async { - guard let allWorkouts = dataStore.allWorkouts else { - self.isUpdating = false - return - } - self.workouts = allWorkouts.sorted(by: { - $0.createdAt ?? Date() < $1.createdAt ?? Date() - }) self.isUpdating = false - self.uniqueWorkoutUsers = dataStore.workoutsUniqueUsers self.needsUpdating = false } }) @@ -148,7 +342,7 @@ struct AllWorkoutsView: View { showLoginView = true } } - + func authorizeHealthKit() { let quantityTypes = [ HKObjectType.quantityType(forIdentifier: .heartRate), @@ -162,7 +356,7 @@ struct AllWorkoutsView: View { HKQuantityType.workoutType() ] ) - + healthStore.requestAuthorization(toShare: nil, read: healthKitTypes) { (success, error) in if success == false { runtimeReporter.recordWarning( @@ -176,6 +370,6 @@ struct AllWorkoutsView: View { struct AllWorkoutsView_Previews: PreviewProvider { static var previews: some View { - AllWorkoutsView(workouts: PreviewData.allWorkouts()) + AllWorkoutsView() } } diff --git a/iphone/Werkout_ios/Views/CompletedWorkout/CompletedWorkoutView.swift b/iphone/Werkout_ios/Views/CompletedWorkout/CompletedWorkoutView.swift index 137f6dc..b4aa6e1 100644 --- a/iphone/Werkout_ios/Views/CompletedWorkout/CompletedWorkoutView.swift +++ b/iphone/Werkout_ios/Views/CompletedWorkout/CompletedWorkoutView.swift @@ -11,15 +11,15 @@ import SharedCore struct CompletedWorkoutView: View { @ObservedObject var bridgeModule = BridgeModule.shared - @State var healthKitWorkoutData: HealthKitWorkoutData? - @State var difficulty: Float = 0 - @State var notes: String = "" - @State var isUploading: Bool = false - @State var gettingHealthKitData: Bool = false + @State private var healthKitWorkoutData: HealthKitWorkoutData? + @State private var difficulty: Float = 0 + @State private var notes: String = "" + @State private var isUploading: Bool = false + @State private var gettingHealthKitData: Bool = false @State private var hasError = false @State private var errorMessage = "" private let runtimeReporter = RuntimeReporter.shared - + var postData: [String: Any] let healthKitHelper = HealthKitHelper() let workout: Workout @@ -29,48 +29,65 @@ struct CompletedWorkoutView: View { var body: some View { ZStack { + WerkoutTheme.background + .ignoresSafeArea() + if isUploading { ProgressView("Uploading") + .foregroundStyle(WerkoutTheme.textPrimary) + .progressViewStyle(CircularProgressViewStyle(tint: WerkoutTheme.accent)) } VStack { WorkoutInfoView(workout: workout) - + Divider() - + .overlay(WerkoutTheme.divider) + HStack { if let calsBurned = healthKitWorkoutData?.caloriesBurned { CaloriesBurnedView(healthKitWorkoutData: $healthKitWorkoutData, calsBurned: calsBurned) } } - + RateWorkoutView(difficulty: $difficulty) .frame(maxHeight: 88) - + Divider() - + .overlay(WerkoutTheme.divider) + TextField("Notes", text: $notes) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textPrimary) .frame(height: 55) .textFieldStyle(PlainTextFieldStyle()) .padding([.horizontal], 4) - .overlay(RoundedRectangle(cornerRadius: 16).stroke(Color(uiColor: .clear))).background(Color(uiColor: .init(red: 200/255, green: 200/255, blue: 200/255, alpha: 0.2))) - .cornerRadius(8) - + .background(WerkoutTheme.surfaceElevated) + .overlay( + RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous) + .strokeBorder(WerkoutTheme.divider, lineWidth: 1) + ) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + if gettingHealthKitData { ProgressView("Getting HealthKit data") + .foregroundStyle(WerkoutTheme.textPrimary) + .progressViewStyle(CircularProgressViewStyle(tint: WerkoutTheme.accent)) .padding() } - + Spacer() - + Button("Upload", action: { upload(postBody: postData) }) + .font(.system(size: 16, weight: .bold)) + .foregroundStyle(WerkoutTheme.textPrimary) .frame(maxWidth: .infinity, alignment: .center) .frame(height: 44) - .foregroundColor(.blue) - .background(.yellow) - .cornerRadius(Constants.buttonRadius) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.success) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) .padding() .frame(maxWidth: .infinity) .disabled(isUploading || gettingHealthKitData) @@ -82,19 +99,6 @@ struct CompletedWorkoutView: View { } message: { Text(errorMessage) } -// .onChange(of: bridgeModule.healthKitUUID, perform: { healthKitUUID in -// if let healthKitUUID = healthKitUUID { -// gettingHealthKitData = true -// healthKitHelper.getDetails(forHealthKitUUID: healthKitUUID, -// completion: { healthKitWorkoutData in -// guard let healthStore = healthKitWorkoutData else { -// return -// } -// self.healthKitWorkoutData = healthKitWorkoutData -// gettingHealthKitData = false -// }) -// } -// }) } func upload(postBody: [String: Any]) { @@ -143,9 +147,9 @@ struct CompletedWorkoutView_Previews: PreviewProvider { "total_calories": Float(120.0), "heart_rates": [65,65,4,54,232,12] ] as [String : Any] - + static let workout = PreviewData.workout() - + static var previews: some View { CompletedWorkoutView(postData: CompletedWorkoutView_Previews.postBody, workout: workout, diff --git a/iphone/Werkout_ios/Views/CreateWorkout/CreateExerciseActionsView.swift b/iphone/Werkout_ios/Views/CreateWorkout/CreateExerciseActionsView.swift index a0ef016..a0cae25 100644 --- a/iphone/Werkout_ios/Views/CreateWorkout/CreateExerciseActionsView.swift +++ b/iphone/Werkout_ios/Views/CreateWorkout/CreateExerciseActionsView.swift @@ -12,8 +12,8 @@ struct CreateExerciseActionsView: View { @ObservedObject var workoutExercise: CreateWorkoutExercise @ObservedObject var superset: CreateWorkoutSuperSet var viewModel: WorkoutViewModel - - @State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) + + @State var avPlayer = AVPlayer(url: URL(string: BaseURLs.currentBaseURL + "/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) @State private var currentVideoURL: URL? @State var videoExercise: Exercise? { didSet { @@ -23,90 +23,103 @@ struct CreateExerciseActionsView: View { } } } - + var body: some View { - VStack { - VStack { + VStack(spacing: WerkoutTheme.sm) { + VStack(spacing: WerkoutTheme.xs) { HStack { Text("Reps: ") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) Text("\(workoutExercise.reps)") - .foregroundColor(workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color(uiColor: .label)) + .foregroundColor(workoutExercise.reps == 0 && workoutExercise.duration == 0 ? WerkoutTheme.danger : WerkoutTheme.textPrimary) + .font(WerkoutTheme.bodyText) .bold() - + Stepper("", onIncrement: { workoutExercise.increaseReps() }, onDecrement: { workoutExercise.decreaseReps() }) + .tint(WerkoutTheme.accent) .accessibilityLabel("Reps") } } - + HStack { Text("Weight: ") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) Text("\(workoutExercise.weight)") - + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textPrimary) + Stepper("", onIncrement: { workoutExercise.increaseWeight() }, onDecrement: { workoutExercise.decreaseWeight() }) + .tint(WerkoutTheme.accent) .accessibilityLabel("Weight") } - + HStack { Text("Duration: ") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) Text("\(workoutExercise.duration)") .foregroundColor( - workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color( - uiColor: .label - ) + workoutExercise.reps == 0 && workoutExercise.duration == 0 ? WerkoutTheme.danger : WerkoutTheme.textPrimary ) + .font(WerkoutTheme.bodyText) .bold() - + Stepper("", onIncrement: { workoutExercise.increaseDuration() }, onDecrement: { workoutExercise.decreaseDuration() }) + .tint(WerkoutTheme.accent) .accessibilityLabel("Duration") } - - HStack { - Spacer() - Button(action: { - videoExercise = workoutExercise.exercise - }) { - Image(systemName: "video.fill") + + GlassEffectContainer { + HStack { + Spacer() + Button(action: { + videoExercise = workoutExercise.exercise + }) { + Image(systemName: "video.fill") + .foregroundStyle(WerkoutTheme.textPrimary) + } + .frame(width: 88, height: 44) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + .buttonStyle(BorderlessButtonStyle()) + .accessibilityLabel("Preview exercise video") + .accessibilityHint("Opens a video preview for this exercise") + + Spacer() + + Spacer() + + Button(action: { + superset + .deleteExerciseForChosenSuperset(exercise: workoutExercise) + viewModel.increaseRandomNumberForUpdating() + }) { + Image(systemName: "trash.fill") + .foregroundStyle(WerkoutTheme.textPrimary) + } + .frame(width: 88, height: 44) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.danger) + .buttonStyle(BorderlessButtonStyle()) + .accessibilityLabel("Delete exercise") + .accessibilityHint("Removes this exercise from the superset") + + Spacer() } - .frame(width: 88, height: 44) - .foregroundColor(.white) - .background(.blue) - .cornerRadius(Constants.buttonRadius) - .buttonStyle(BorderlessButtonStyle()) - .accessibilityLabel("Preview exercise video") - .accessibilityHint("Opens a video preview for this exercise") - - Spacer() - - Spacer() - - Button(action: { - superset - .deleteExerciseForChosenSuperset(exercise: workoutExercise) - viewModel.increaseRandomNumberForUpdating() - }) { - Image(systemName: "trash.fill") - } - .frame(width: 88, height: 44) - .foregroundColor(.white) - .background(.red) - .cornerRadius(Constants.buttonRadius) - .buttonStyle(BorderlessButtonStyle()) - .accessibilityLabel("Delete exercise") - .accessibilityHint("Removes this exercise from the superset") - - Spacer() } } .sheet(item: $videoExercise) { exercise in diff --git a/iphone/Werkout_ios/Views/CreateWorkout/CreateViewModels.swift b/iphone/Werkout_ios/Views/CreateWorkout/CreateViewModels.swift index 5f0b402..17d2045 100644 --- a/iphone/Werkout_ios/Views/CreateWorkout/CreateViewModels.swift +++ b/iphone/Werkout_ios/Views/CreateWorkout/CreateViewModels.swift @@ -5,7 +5,8 @@ // Created by Trey Tartt on 6/18/23. // -import SwiftUI +import Combine +import Foundation import SharedCore class CreateWorkoutExercise: ObservableObject, Identifiable { @@ -93,6 +94,9 @@ class WorkoutViewModel: ObservableObject { @Published var description = String() @Published var validationError: String? @Published var isUploading = false + // MARK: - Manual Invalidation + // Workaround: nested ObservableObject changes don't propagate to parent. + // Remove when migrating to @Observable (iOS 17+). @Published var randomValueForUpdatingValue = 0 func increaseRandomNumberForUpdating() { @@ -112,7 +116,32 @@ class WorkoutViewModel: ObservableObject { increaseRandomNumberForUpdating() } } - + + func addExercise(_ exercise: Exercise, to superset: CreateWorkoutSuperSet) { + let workoutExercise = CreateWorkoutExercise(exercise: exercise) + superset.exercises.append(workoutExercise) + + if exercise.side?.isEmpty == false { + autoAddSiblingExercises(for: exercise, to: superset) + } + increaseRandomNumberForUpdating() + } + + private func autoAddSiblingExercises(for exercise: Exercise, to superset: CreateWorkoutSuperSet) { + guard let allExercises = DataStore.shared.allExercise else { return } + let siblings = allExercises.filter { $0.name == exercise.name } + guard siblings.count == 2, + let recover = allExercises.first(where: { $0.name.lowercased() == "recover" }) else { return } + + let recoverExercise = CreateWorkoutExercise(exercise: recover) + superset.exercises.append(recoverExercise) + + for sibling in siblings where sibling.id != exercise.id { + let otherSideExercise = CreateWorkoutExercise(exercise: sibling) + superset.exercises.append(otherSideExercise) + } + } + func showRoundsError() { validationError = "Each superset must have at least one round." } diff --git a/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutItemPickerView.swift b/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutItemPickerView.swift index 927869f..50cd795 100644 --- a/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutItemPickerView.swift +++ b/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutItemPickerView.swift @@ -15,16 +15,16 @@ struct CreateWorkoutItemPickerModel { class CreateWorkoutItemPickerViewModel: Identifiable, ObservableObject { let allValues: [CreateWorkoutItemPickerModel] - @Published var selectedIds: [Int] - + @Published var selectedIds: Set + init(allValues: [CreateWorkoutItemPickerModel], selectedIds: [Int]) { self.allValues = allValues - self.selectedIds = selectedIds + self.selectedIds = Set(selectedIds) } - + func toggleAll() { if selectedIds.isEmpty { - selectedIds.append(contentsOf: allValues.map({ $0.id })) + selectedIds = Set(allValues.map({ $0.id })) } else { selectedIds.removeAll() } @@ -38,65 +38,71 @@ struct CreateWorkoutItemPickerView: View { @State var searchString: String = "" var body: some View { - VStack { + VStack(spacing: 0) { List() { ForEach(viewModel.allValues, id:\.self.id) { value in if searchString.isEmpty || value.name.lowercased().contains(searchString.lowercased()) { - HStack { + HStack(spacing: WerkoutTheme.sm) { Circle() - .stroke(.blue, lineWidth: 1) - .background(Circle().fill(viewModel.selectedIds.contains(value.id) ? .blue :.clear)) + .stroke(WerkoutTheme.accent, lineWidth: 1.5) + .background(Circle().fill(viewModel.selectedIds.contains(value.id) ? WerkoutTheme.accent : Color.clear)) .frame(width: 33, height: 33) - + Text(value.name) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textPrimary) } .contentShape(Rectangle()) .onTapGesture { if viewModel.selectedIds.contains(value.id) { - if let idx = viewModel.selectedIds.firstIndex(of: value.id){ - viewModel.selectedIds.remove(at: idx) - } + viewModel.selectedIds.remove(value.id) } else { - viewModel.selectedIds.append(value.id) + viewModel.selectedIds.insert(value.id) } } + .listRowBackground(WerkoutTheme.surfaceCard) } } } - - TextField("Filter", text: $searchString) - .padding() - - - HStack { - Button(action: { - viewModel.toggleAll() - }, label: { - Image(systemName: "checklist") - .font(.title) - }) - .frame(maxWidth: 44, alignment: .center) - .frame(height: 44) - .foregroundColor(.green) - .background(.white) - .cornerRadius(Constants.buttonRadius) - .padding() + .scrollContentBackground(.hidden) + .background(WerkoutTheme.background) - Button(action: { - completed(viewModel.selectedIds) - dismiss() - }, label: { - Text("done") - }) - .frame(maxWidth: .infinity, alignment: .center) - .frame(height: 44) - .foregroundColor(.blue) - .background(.yellow) - .cornerRadius(Constants.buttonRadius) - .padding() - .frame(maxWidth: .infinity) + TextField("Filter", text: $searchString) + .werkoutTextField() + .padding(.horizontal, WerkoutTheme.md) + .padding(.vertical, WerkoutTheme.sm) + + GlassEffectContainer { + HStack(spacing: WerkoutTheme.md) { + Button(action: { + viewModel.toggleAll() + }, label: { + Image(systemName: "checklist") + .font(.title) + .foregroundStyle(WerkoutTheme.textPrimary) + }) + .frame(width: 44, height: 44) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.success) + + Button(action: { + completed(Array(viewModel.selectedIds)) + dismiss() + }, label: { + Text("Done") + .font(.system(size: 16, weight: .bold)) + .foregroundStyle(WerkoutTheme.textPrimary) + .frame(maxWidth: .infinity) + .frame(height: 44) + }) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + } + .padding(.horizontal, WerkoutTheme.md) + .padding(.vertical, WerkoutTheme.sm) } } + .background(WerkoutTheme.background) } } @@ -104,10 +110,10 @@ struct CreateWorkoutItemPickerView_Previews: PreviewProvider { static let fakeValues = [CreateWorkoutItemPickerModel(id: 1, name: "one"), CreateWorkoutItemPickerModel(id: 2, name: "two"), CreateWorkoutItemPickerModel(id: 3, name: "three")] - + static var previews: some View { CreateWorkoutItemPickerView(viewModel: CreateWorkoutItemPickerViewModel(allValues: fakeValues, selectedIds: [1]), completed: { selectedIds in - + }) } } diff --git a/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutMainView.swift b/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutMainView.swift index c44785f..bf18362 100644 --- a/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutMainView.swift +++ b/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutMainView.swift @@ -16,21 +16,21 @@ struct CreateWorkoutMainView: View { viewModel.title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false && viewModel.isUploading == false } - + var body: some View { - VStack { - VStack { + VStack(spacing: 0) { + VStack(spacing: WerkoutTheme.sm) { TextField("Title", text: $viewModel.title) - .padding(.horizontal) - .textFieldStyle(.roundedBorder) - + .werkoutTextField() + .padding(.horizontal, WerkoutTheme.md) + TextField("Description", text: $viewModel.description) - .padding(.horizontal) - .textFieldStyle(.roundedBorder) + .werkoutTextField() + .padding(.horizontal, WerkoutTheme.md) } - .padding(.bottom) - .background(Color(uiColor: .systemGray5)) - + .padding(.vertical, WerkoutTheme.md) + .background(WerkoutTheme.surfaceCard) + ScrollViewReader { proxy in List() { ForEach(viewModel.superSets) { superset in @@ -40,6 +40,7 @@ struct CreateWorkoutMainView: View { superset: superset, viewModel: viewModel) } + .listRowBackground(WerkoutTheme.surfaceCard) // after adding new exercise we have to scroll to the bottom // where the new exercise is sooo keep this so we can scroll // to id 999 @@ -48,91 +49,70 @@ struct CreateWorkoutMainView: View { .accessibilityHidden(true) .id(999) .listRowSeparator(.hidden) + .listRowBackground(Color.clear) } - .onChange(of: viewModel.randomValueForUpdatingValue, perform: { newValue in + .scrollContentBackground(.hidden) + .background(WerkoutTheme.background) + .onChange(of: viewModel.randomValueForUpdatingValue) { _, _ in withAnimation { proxy.scrollTo(999, anchor: .bottom) } - }) + } } .sheet(isPresented: $showAddExercise) { AddExerciseView(selectedExercise: { exercise in - let workoutExercise = CreateWorkoutExercise(exercise: exercise) - selectedCreateWorkoutSuperSet?.exercises.append(workoutExercise) - - - // if left or right auto add the other side - // with a recover in between b/c its - // eaiser to delete a recover than add one - if exercise.side?.isEmpty == false { - let exercises = DataStore.shared.allExercise?.filter({ - $0.name == exercise.name - }) - let recover = DataStore.shared.allExercise?.first(where: { - $0.name.lowercased() == "recover" - }) - if let exercises = exercises, let recover = recover { - if exercises.count == 2 { - let recoverWorkoutExercise = CreateWorkoutExercise(exercise: recover) - selectedCreateWorkoutSuperSet?.exercises.append(recoverWorkoutExercise) - for LRExercise in exercises { - if LRExercise.id != exercise.id { - let otherSideExercise = CreateWorkoutExercise(exercise: LRExercise) - selectedCreateWorkoutSuperSet?.exercises.append(otherSideExercise) - } - } - } - } + if let superset = selectedCreateWorkoutSuperSet { + viewModel.addExercise(exercise, to: superset) } - - viewModel.increaseRandomNumberForUpdating() selectedCreateWorkoutSuperSet = nil }) } - - HStack { - Button("Add Superset", action: { - viewModel.addNewSuperset() - }) - .frame(maxWidth: .infinity, alignment: .center) - .frame(height: 44) - .foregroundColor(.white) - .background(.blue) - .cornerRadius(Constants.buttonRadius) - .padding() - .frame(maxWidth: .infinity) - .accessibilityLabel("Add superset") - .accessibilityHint("Adds a new superset section to this workout") - - Divider() - - Button(action: { - viewModel.uploadWorkout() - }, label: { - if viewModel.isUploading { - ProgressView() - .progressViewStyle(.circular) - .tint(.white) - } else { - Text("Done") - } - }) - .frame(maxWidth: .infinity, alignment: .center) - .frame(height: 44) - .foregroundColor(.white) - .background(.green) - .cornerRadius(Constants.buttonRadius) - .padding() - .frame(maxWidth: .infinity) - .disabled(canSubmit == false) - .accessibilityLabel("Upload workout") - .accessibilityHint("Uploads this workout to your account") - } - .frame(height: 44) - + Divider() + .overlay(WerkoutTheme.divider) + + GlassEffectContainer { + HStack(spacing: WerkoutTheme.md) { + Button(action: { + viewModel.addNewSuperset() + }) { + Label("Add Superset", systemImage: "plus.circle.fill") + .font(.system(size: 15, weight: .bold)) + .foregroundStyle(WerkoutTheme.textPrimary) + .frame(maxWidth: .infinity) + .frame(height: 44) + } + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + .accessibilityLabel("Add superset") + .accessibilityHint("Adds a new superset section to this workout") + + Button(action: { + viewModel.uploadWorkout() + }, label: { + if viewModel.isUploading { + ProgressView() + .progressViewStyle(.circular) + .tint(WerkoutTheme.textPrimary) + } else { + Text("Done") + .font(.system(size: 15, weight: .bold)) + .foregroundStyle(WerkoutTheme.textPrimary) + } + }) + .frame(maxWidth: .infinity) + .frame(height: 44) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.success) + .disabled(canSubmit == false) + .accessibilityLabel("Upload workout") + .accessibilityHint("Uploads this workout to your account") + } + .padding(.horizontal, WerkoutTheme.md) + .padding(.vertical, WerkoutTheme.sm) + } } - .background(Color(uiColor: .systemGray5)) + .background(WerkoutTheme.background) .alert("Create Workout", isPresented: Binding( get: { viewModel.validationError != nil }, set: { _ in viewModel.validationError = nil } diff --git a/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutSupersetActionsView.swift b/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutSupersetActionsView.swift index bf7107b..046ccf9 100644 --- a/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutSupersetActionsView.swift +++ b/iphone/Werkout_ios/Views/CreateWorkout/CreateWorkoutSupersetActionsView.swift @@ -12,32 +12,38 @@ struct CreateWorkoutSupersetActionsView: View { @Binding var showAddExercise: Bool var viewModel: WorkoutViewModel @Binding var selectedCreateWorkoutSuperSet: CreateWorkoutSuperSet? - + var body: some View { - HStack { - Button(action: { - selectedCreateWorkoutSuperSet = workoutSuperSet - showAddExercise.toggle() - }) { - Text("Add exercise") - .padding() - } - .foregroundColor(.white) - .background(.green) - .frame(maxWidth: .infinity, alignment: .center) - - Button(action: { + GlassEffectContainer { + HStack(spacing: WerkoutTheme.md) { + Button(action: { + selectedCreateWorkoutSuperSet = workoutSuperSet + showAddExercise.toggle() + }) { + Text("Add exercise") + .font(.system(size: 15, weight: .bold)) + .foregroundStyle(WerkoutTheme.textPrimary) + .padding() + } + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.success) + .frame(maxWidth: .infinity, alignment: .center) + + Button(action: { // viewModel.delete(superset: workoutSuperSet) // viewModel.increaseRandomNumberForUpdating() // viewModel.objectWillChange.send() - - }) { - Text("Delete superset") - .padding() + + }) { + Text("Delete superset") + .font(.system(size: 15, weight: .bold)) + .foregroundStyle(WerkoutTheme.textPrimary) + .padding() + } + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.danger) + .frame(maxWidth: .infinity, alignment: .center) } - .foregroundColor(.white) - .background(.red) - .frame(maxWidth: .infinity, alignment: .center) } } } diff --git a/iphone/Werkout_ios/Views/ExternalWorkoutDetailView.swift b/iphone/Werkout_ios/Views/ExternalWorkoutDetailView.swift index 6eec289..dfa20a6 100644 --- a/iphone/Werkout_ios/Views/ExternalWorkoutDetailView.swift +++ b/iphone/Werkout_ios/Views/ExternalWorkoutDetailView.swift @@ -9,9 +9,9 @@ import SwiftUI import AVKit struct ExternalWorkoutDetailView: View { - @StateObject var bridgeModule = BridgeModule.shared - @State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) - @State var smallAVPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) + @ObservedObject var bridgeModule = BridgeModule.shared + @State var avPlayer = AVPlayer(url: URL(string: BaseURLs.currentBaseURL + "/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) + @State var smallAVPlayer = AVPlayer(url: URL(string: BaseURLs.currentBaseURL + "/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) @State private var currentVideoURL: URL? @State private var currentSmallVideoURL: URL? @AppStorage(Constants.extThotStyle) private var extThotStyle: ThotStyle = .never @@ -32,23 +32,23 @@ struct ExternalWorkoutDetailView: View { avPlayer.play() } } - + VStack { ExtExerciseList(workout: workout, allSupersetExecerciseIndex: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex) } .frame(width: metrics.size.width * 0.4, height: metrics.size.height * 0.8) - .padding([.top, .bottom], 20) + .padding([.top, .bottom], WerkoutTheme.lg) } - + HStack { ExtCountdownView() .padding(.leading, 50) - .padding(.bottom, 20) - + .padding(.bottom, WerkoutTheme.lg) + if extShowNextVideo && extThotStyle != .off { PlayerView(player: $smallAVPlayer) - .frame(width: metrics.size.width * 0.2, + .frame(width: metrics.size.width * 0.2, height: metrics.size.height * 0.2) .onAppear{ smallAVPlayer.isMuted = true @@ -56,7 +56,7 @@ struct ExternalWorkoutDetailView: View { } } } - .background(Color(uiColor: .tertiarySystemGroupedBackground)) + .background(WerkoutTheme.surfaceCard) } } } else { @@ -65,43 +65,34 @@ struct ExternalWorkoutDetailView: View { .edgesIgnoringSafeArea(.all) .scaledToFill() } - + VStack { HStack { if bridgeModule.currentWorkoutRunTimeInSeconds > -1 { Text(" \(Double(bridgeModule.currentWorkoutRunTimeInSeconds).asString(style: .positional)) ") - .font(Font.system(size: 120)) + .font(WerkoutTheme.stat) .minimumScaleFactor(0.01) .lineLimit(1) .padding() - .bold() - .foregroundColor(.white) - .background( - Capsule() - .strokeBorder(Color.black, lineWidth: 0.8) - .background(Color(uiColor: UIColor(red: 148/255, - green: 0, - blue: 211/255, - alpha: 0.5))) - .clipped() - ) - .clipShape(Capsule()) + .foregroundColor(WerkoutTheme.textPrimary) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) } Spacer() } .padding(.leading, 50) Spacer() } - + } - .onChange(of: bridgeModule.isInWorkout, perform: { _ in + .onChange(of: bridgeModule.isInWorkout) { playVideos() - }) - .onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex, perform: { _ in + } + .onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex) { playVideos() - }) + } .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(bridgeModule.currentWorkoutInfo.workout == nil ? Color(red: 157/255, green: 138/255, blue: 255/255) : Color(uiColor: .systemBackground)) + .background(bridgeModule.currentWorkoutInfo.workout == nil ? WerkoutTheme.accent : WerkoutTheme.background) .onReceive(NotificationCenter.default.publisher( for: UIScene.willEnterForegroundNotification)) { _ in avPlayer.play() @@ -112,7 +103,7 @@ struct ExternalWorkoutDetailView: View { smallAVPlayer.pause() } } - + func playVideos() { if let currentExtercise = bridgeModule.currentWorkoutInfo.currentExercise { if let videoURL = VideoURLCreator.videoURL( @@ -123,7 +114,7 @@ struct ExternalWorkoutDetailView: View { workout: bridgeModule.currentWorkoutInfo.workout) { updateMainPlayer(for: videoURL) } - + if let smallVideoURL = VideoURLCreator.videoURL( thotStyle: .never, gender: thotGenderOption, @@ -163,7 +154,7 @@ struct ExternalWorkoutDetailView: View { //struct ExternalWorkoutDetailView_Previews: PreviewProvider { // static var bridge = BridgeModule.shared -// +// // static var previews: some View { // ExternalWorkoutDetailView().environmentObject({ () -> BridgeModule in // let envObj = BridgeModule.shared diff --git a/iphone/Werkout_ios/Views/Login/LoginView.swift b/iphone/Werkout_ios/Views/Login/LoginView.swift index db0ee50..628a84c 100644 --- a/iphone/Werkout_ios/Views/Login/LoginView.swift +++ b/iphone/Werkout_ios/Views/Login/LoginView.swift @@ -13,12 +13,12 @@ struct LoginView: View { @Environment(\.dismiss) var dismiss let completion: (() -> Void) @State var isLoggingIn: Bool = false - + @State var errorTitle = "" @State var errorMessage = "" @State var hasError: Bool = false - - + + var body: some View { VStack { TextField("Email", text: $email) @@ -27,65 +27,87 @@ struct LoginView: View { .autocorrectionDisabled(true) .keyboardType(.emailAddress) .padding() - .background(Color.white) - .cornerRadius(8) + .background(WerkoutTheme.surfaceCard.opacity(0.8)) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + .overlay( + RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous) + .strokeBorder(WerkoutTheme.textSecondary.opacity(0.4), lineWidth: 1) + ) + .foregroundStyle(WerkoutTheme.textPrimary) .padding(.horizontal) .padding(.top, 25) - .foregroundStyle(.black) .accessibilityLabel("Email") .submitLabel(.next) - + SecureField("Password", text: $password) .textContentType(.password) .padding() - .background(Color.white) - .cornerRadius(8) + .background(WerkoutTheme.surfaceCard.opacity(0.8)) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + .overlay( + RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous) + .strokeBorder(WerkoutTheme.textSecondary.opacity(0.4), lineWidth: 1) + ) + .foregroundStyle(WerkoutTheme.textPrimary) .padding(.horizontal) .textInputAutocapitalization(.never) .autocorrectionDisabled(true) - .foregroundStyle(.black) .accessibilityLabel("Password") .submitLabel(.go) - + if isLoggingIn { ProgressView("Logging In") .padding() - .foregroundColor(.white) - .progressViewStyle(CircularProgressViewStyle(tint: .white)) + .foregroundStyle(WerkoutTheme.textPrimary) + .progressViewStyle(CircularProgressViewStyle(tint: WerkoutTheme.accent)) .scaleEffect(1.5, anchor: .center) } else { Button("Login", action: { login() }) + .font(.system(size: 16, weight: .bold)) + .foregroundStyle(WerkoutTheme.textPrimary) .frame(maxWidth: .infinity, alignment: .center) .frame(height: 44) - .foregroundColor(.blue) - .background(.yellow) - .cornerRadius(16) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) .padding() .frame(maxWidth: .infinity) .disabled(password.isEmpty || email.isEmpty) .accessibilityLabel("Log in") .accessibilityHint("Logs in using the entered email and password") } - + Spacer() } .padding() .background( - Image("icon") - .resizable() + ZStack { + Image("icon") + .resizable() + .edgesIgnoringSafeArea(.all) + .scaledToFill() + .accessibilityHidden(true) + + LinearGradient( + colors: [ + Color.black.opacity(0.0), + Color.black.opacity(0.6) + ], + startPoint: .top, + endPoint: .bottom + ) .edgesIgnoringSafeArea(.all) - .scaledToFill() - .accessibilityHidden(true) + } ) .alert(errorTitle, isPresented: $hasError, actions: { - + }, message: { Text(errorMessage) }) } - + func login() { let postData = [ "email": email, @@ -109,7 +131,7 @@ struct LoginView: View { struct LoginView_Previews: PreviewProvider { static var previews: some View { LoginView(completion: { - + }) } } diff --git a/iphone/Werkout_ios/Views/MainView.swift b/iphone/Werkout_ios/Views/MainView.swift index 426991b..6bf4b62 100644 --- a/iphone/Werkout_ios/Views/MainView.swift +++ b/iphone/Werkout_ios/Views/MainView.swift @@ -10,7 +10,7 @@ import CoreData struct MainView: View { @State var workout: Workout? - @StateObject var bridgeModule = BridgeModule.shared + @ObservedObject var bridgeModule = BridgeModule.shared var body: some View { ZStack { diff --git a/iphone/Werkout_ios/Views/PlanWorkoutView.swift b/iphone/Werkout_ios/Views/PlanWorkoutView.swift index e9cb51e..e1920b5 100644 --- a/iphone/Werkout_ios/Views/PlanWorkoutView.swift +++ b/iphone/Werkout_ios/Views/PlanWorkoutView.swift @@ -14,78 +14,89 @@ struct PlanWorkoutView: View { let workout: Workout @Environment(\.dismiss) var dismiss var addedPlannedWorkout: (() -> Void)? - + var body: some View { VStack() { Text(workout.name) - .font(.title) + .font(WerkoutTheme.heroTitle) + .foregroundStyle(WerkoutTheme.textPrimary) .frame(maxWidth: .infinity, alignment: .leading) Text(selectedDate.formatted(date: .abbreviated, time: .omitted)) .font(.system(size: 28)) .bold() - .foregroundColor(Color.accentColor) + .foregroundStyle(WerkoutTheme.accent) .padding() .animation(.spring(), value: selectedDate) - - Divider().frame(height: 1) - + + Divider() + .overlay(WerkoutTheme.divider) + .frame(height: 1) + DatePicker("Select Date", selection: $selectedDate, displayedComponents: [.date]) .padding(.horizontal) .datePickerStyle(.graphical) - + .tint(WerkoutTheme.accent) + .foregroundStyle(WerkoutTheme.textPrimary) + Divider() - - HStack { - Button(action: { - dismiss() - }, label: { - Image(systemName: "xmark.octagon.fill") - .font(.title) - .frame(maxWidth: .infinity, maxHeight: .infinity) - }) - .frame(maxWidth: .infinity, alignment: .center) - .frame(height: 44) - .foregroundColor(.white) - .background(.red) - .cornerRadius(Constants.buttonRadius) - .padding() - .accessibilityLabel("Cancel planning") - .accessibilityHint("Closes this screen without planning a workout") - - Button(action: { - planWorkout() - }, label: { - Image(systemName: "plus.app") - .font(.title) - .frame(maxWidth: .infinity, maxHeight: .infinity) - }) - .frame(maxWidth: .infinity, alignment: .center) - .frame(height: 44) - .foregroundColor(.blue) - .background(.yellow) - .cornerRadius(Constants.buttonRadius) - .padding() - .accessibilityLabel("Plan workout") - .accessibilityHint("Adds this workout to your selected date") + .overlay(WerkoutTheme.divider) + + GlassEffectContainer { + HStack { + Button(action: { + dismiss() + }, label: { + Image(systemName: "xmark.octagon.fill") + .font(.title) + .frame(maxWidth: .infinity, maxHeight: .infinity) + }) + .foregroundStyle(WerkoutTheme.textPrimary) + .frame(maxWidth: .infinity, alignment: .center) + .frame(height: 44) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.danger) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + .padding() + .accessibilityLabel("Cancel planning") + .accessibilityHint("Closes this screen without planning a workout") + + Button(action: { + planWorkout() + }, label: { + Image(systemName: "plus.app") + .font(.title) + .frame(maxWidth: .infinity, maxHeight: .infinity) + }) + .foregroundStyle(WerkoutTheme.textPrimary) + .frame(maxWidth: .infinity, alignment: .center) + .frame(height: 44) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + .padding() + .accessibilityLabel("Plan workout") + .accessibilityHint("Adds this workout to your selected date") + } } - + Spacer() } .padding() + .background(WerkoutTheme.background) .alert("Unable to Plan Workout", isPresented: $hasError) { Button("OK", role: .cancel) {} } message: { Text(errorMessage) } } - + func planWorkout() { let postData = [ "on_date": selectedDate.formatForPlannedWorkout, "workout": workout.id ] as [String : Any] - + PlanWorkoutFetchable(postData: postData).fetch(completion: { result in switch result { case .success(_): diff --git a/iphone/Werkout_ios/Views/WorkoutDetail/CurrentWorkoutElapsedTimeView.swift b/iphone/Werkout_ios/Views/WorkoutDetail/CurrentWorkoutElapsedTimeView.swift index ecd1a74..017cbb5 100644 --- a/iphone/Werkout_ios/Views/WorkoutDetail/CurrentWorkoutElapsedTimeView.swift +++ b/iphone/Werkout_ios/Views/WorkoutDetail/CurrentWorkoutElapsedTimeView.swift @@ -8,13 +8,14 @@ import SwiftUI struct CurrentWorkoutElapsedTimeView: View { - @ObservedObject var bridgeModule = BridgeModule.shared - + let currentWorkoutRunTimeInSeconds: Int + var body: some View { - if bridgeModule.currentWorkoutRunTimeInSeconds > -1 { + if currentWorkoutRunTimeInSeconds > -1 { VStack { - Text("\(Double(bridgeModule.currentWorkoutRunTimeInSeconds).asString(style: .positional))") - .font(.title2) + Text("\(Double(currentWorkoutRunTimeInSeconds).asString(style: .positional))") + .font(.system(size: 20, weight: .black, design: .monospaced)) + .foregroundStyle(WerkoutTheme.accent) } } } diff --git a/iphone/Werkout_ios/Views/WorkoutDetail/ExerciseListView.swift b/iphone/Werkout_ios/Views/WorkoutDetail/ExerciseListView.swift index ab1330c..861de5a 100644 --- a/iphone/Werkout_ios/Views/WorkoutDetail/ExerciseListView.swift +++ b/iphone/Werkout_ios/Views/WorkoutDetail/ExerciseListView.swift @@ -10,138 +10,138 @@ import AVKit struct ExerciseListView: View { @AppStorage(Constants.phoneThotStyle) private var phoneThotStyle: ThotStyle = .never - @ObservedObject var bridgeModule = BridgeModule.shared - @State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) + @State private var avPlayer = AVPlayer(url: URL(string: BaseURLs.currentBaseURL + "/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) @State private var previewVideoURL: URL? var workout: Workout @Binding var showExecersizeInfo: Bool @AppStorage(Constants.thotGenderOption) private var thotGenderOption: String = "female" - @State var videoExercise: Exercise? { + let isInWorkout: Bool + let currentSupersetIndex: Int + let currentExerciseIndex: Int + let allSupersetExecerciseIndex: Int + let currentExercise: SupersetExercise? + let currentWorkout: Workout? + let goToExerciseAt: (Int, Int) -> Void + + @State private var videoExercise: Exercise? { didSet { if let videoURL = VideoURLCreator.videoURL( thotStyle: phoneThotStyle, gender: thotGenderOption, defaultVideoURLStr: self.videoExercise?.videoURL, exerciseName: self.videoExercise?.name, - workout: bridgeModule.currentWorkoutInfo.workout) { + workout: currentWorkout) { updatePreviewPlayer(for: videoURL) } } } - + var body: some View { let supersets = workout.supersets?.sorted(by: { $0.order < $1.order }) ?? [] if supersets.isEmpty == false { ScrollViewReader { proxy in List() { - ForEach(supersets.indices, id: \.self) { supersetIndex in - let superset = supersets[supersetIndex] + ForEach(Array(supersets.enumerated()), id: \.offset) { supersetIndex, superset in Section(content: { - ForEach(superset.exercises.indices, id: \.self) { exerciseIndex in - let supersetExecercise = superset.exercises[exerciseIndex] + ForEach(Array(superset.exercises.enumerated()), id: \.offset) { exerciseIndex, supersetExecercise in let rowID = rowIdentifier( supersetIndex: supersetIndex, exerciseIndex: exerciseIndex, exercise: supersetExecercise ) + let isCurrentExercise = isInWorkout && + supersetIndex == currentSupersetIndex && + exerciseIndex == currentExerciseIndex + VStack { Button(action: { - if bridgeModule.isInWorkout { - bridgeModule.currentWorkoutInfo.goToExerciseAt( - supersetIndex: supersetIndex, - exerciseIndex: exerciseIndex) + if isInWorkout { + goToExerciseAt(supersetIndex, exerciseIndex) } else { videoExercise = supersetExecercise.exercise } }, label: { HStack { - if bridgeModule.isInWorkout && - supersetIndex == bridgeModule.currentWorkoutInfo.supersetIndex && - exerciseIndex == bridgeModule.currentWorkoutInfo.exerciseIndex { + if isCurrentExercise { Image(systemName: "figure.run") - .foregroundColor(Color("appColor")) + .foregroundStyle(WerkoutTheme.accent) } - + Text(supersetExecercise.exercise.extName) - + .foregroundStyle(WerkoutTheme.textPrimary) + Spacer() - + if let reps = supersetExecercise.reps, reps > 0 { - HStack { + HStack(spacing: 4) { Image(systemName: "number") - .foregroundColor(.white) - .frame(width: 20, alignment: .leading) Text("\(reps)") - .foregroundColor(.white) - .frame(width: 30, alignment: .trailing) - } - .padding([.top, .bottom], 5) - .padding([.leading], 10) - .padding([.trailing], 15) - .background(.blue) - .cornerRadius(5, corners: [.topLeft, .bottomLeft]) - .frame(alignment: .trailing) + .font(WerkoutTheme.caption) + .foregroundStyle(.white) + .padding(.horizontal, WerkoutTheme.sm) + .padding(.vertical, WerkoutTheme.xs) + .background(WerkoutTheme.accent) + .clipShape(Capsule()) } - + if let duration = supersetExecercise.duration, duration > 0 { - HStack { + HStack(spacing: 4) { Image(systemName: "stopwatch") - .foregroundColor(.white) - .frame(width: 20, alignment: .leading) Text("\(duration)") - .foregroundColor(.white) - .frame(width: 30, alignment: .trailing) } - .padding([.top, .bottom], 5) - .padding([.leading], 10) - .padding([.trailing], 15) - .background(.green) - .cornerRadius(5, corners: [.topLeft, .bottomLeft]) + .font(WerkoutTheme.caption) + .foregroundStyle(.white) + .padding(.horizontal, WerkoutTheme.sm) + .padding(.vertical, WerkoutTheme.xs) + .background(WerkoutTheme.success) + .clipShape(Capsule()) } } - .padding(.trailing, -20) .contentShape(Rectangle()) }) .buttonStyle(.plain) .accessibilityLabel("Exercise \(supersetExecercise.exercise.extName)") - .accessibilityHint(bridgeModule.isInWorkout ? "Jump to this exercise in the workout" : "Preview exercise video") - - if bridgeModule.isInWorkout && - supersetIndex == bridgeModule.currentWorkoutInfo.supersetIndex && - exerciseIndex == bridgeModule.currentWorkoutInfo.exerciseIndex && - showExecersizeInfo { + .accessibilityHint(isInWorkout ? "Jump to this exercise in the workout" : "Preview exercise video") + + if isCurrentExercise && showExecersizeInfo { detailView(forExercise: supersetExecercise) } - }.id(rowID) + } + .listRowBackground( + isCurrentExercise + ? WerkoutTheme.accent.opacity(0.1) + : WerkoutTheme.surfaceCard + ) + .id(rowID) } }, header: { HStack { Text(superset.name ?? "--") - .foregroundColor(Color("appColor")) - .bold() + .font(WerkoutTheme.sectionTitle) + .foregroundStyle(WerkoutTheme.accent) Spacer() Text("\(superset.rounds) rounds") - .foregroundColor(Color("appColor")) - .bold() - + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.accent) + if let estimatedTime = superset.estimatedTime { Text("@ " + estimatedTime.asString(style: .abbreviated)) - .foregroundColor(Color("appColor")) - .bold() + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.accent) } } }) } } - .onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex, perform: { newValue in - if let newCurrentExercise = bridgeModule.currentWorkoutInfo.currentExercise { + .scrollContentBackground(.hidden) + .background(WerkoutTheme.background) + .onChange(of: allSupersetExecerciseIndex) { _, _ in + if let newCurrentExercise = currentExercise { withAnimation { - let currentSupersetIndex = bridgeModule.currentWorkoutInfo.supersetIndex - let currentExerciseIndex = bridgeModule.currentWorkoutInfo.exerciseIndex proxy.scrollTo( rowIdentifier( supersetIndex: currentSupersetIndex, @@ -152,7 +152,7 @@ struct ExerciseListView: View { ) } } - }) + } .sheet(item: $videoExercise) { exercise in PlayerView(player: $avPlayer) .onAppear{ @@ -190,20 +190,34 @@ struct ExerciseListView: View { avPlayer.isMuted = true avPlayer.play() } - + func detailView(forExercise supersetExecercise: SupersetExercise) -> some View { - VStack { + VStack(spacing: WerkoutTheme.sm) { Text(supersetExecercise.exercise.description) - .frame(alignment: .leading) - Divider() + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) + .frame(maxWidth: .infinity, alignment: .leading) + WerkoutTheme.divider.frame(height: 0.5) Text(supersetExecercise.exercise.muscles.map({ $0.name }).joined(separator: ", ")) - .frame(alignment: .leading) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.accent) + .frame(maxWidth: .infinity, alignment: .leading) } } } struct ExerciseListView_Previews: PreviewProvider { static var previews: some View { - ExerciseListView(workout: PreviewData.workout(), showExecersizeInfo: .constant(true)) + ExerciseListView( + workout: PreviewData.workout(), + showExecersizeInfo: .constant(true), + isInWorkout: false, + currentSupersetIndex: 0, + currentExerciseIndex: 0, + allSupersetExecerciseIndex: 0, + currentExercise: nil, + currentWorkout: nil, + goToExerciseAt: { _, _ in } + ) } } diff --git a/iphone/Werkout_ios/Views/WorkoutDetail/WorkoutDetailView.swift b/iphone/Werkout_ios/Views/WorkoutDetail/WorkoutDetailView.swift index a95fc89..ddbc650 100644 --- a/iphone/Werkout_ios/Views/WorkoutDetail/WorkoutDetailView.swift +++ b/iphone/Werkout_ios/Views/WorkoutDetail/WorkoutDetailView.swift @@ -9,11 +9,11 @@ import SwiftUI import AVKit struct WorkoutDetailView: View { - @StateObject var viewModel: WorkoutDetailViewModel - @State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) + @ObservedObject var viewModel: WorkoutDetailViewModel + @State private var avPlayer = AVPlayer(url: URL(string: BaseURLs.currentBaseURL + "/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) @State private var currentVideoURL: URL? - - @StateObject var bridgeModule = BridgeModule.shared + + @ObservedObject var bridgeModule = BridgeModule.shared @Environment(\.dismiss) var dismiss @AppStorage(Constants.phoneThotStyle) private var phoneThotStyle: ThotStyle = .never @AppStorage(Constants.thotGenderOption) private var thotGenderOption: String = "female" @@ -22,45 +22,50 @@ struct WorkoutDetailView: View { case completedWorkout([String: Any]) var id: String { return "completedWorkoutSheet" } } - - @State var workoutComplete: Sheet? - @State var workoutToPlan: Workout? - @State var showExecersizeInfo: Bool = false - + + @State private var workoutComplete: Sheet? + @State private var workoutToPlan: Workout? + @State private var showExecersizeInfo: Bool = false + var body: some View { ZStack { + WerkoutTheme.background.ignoresSafeArea() + switch viewModel.status { case .loading: - Text("Loading") + ProgressView() + .tint(WerkoutTheme.accent) case .failed(let errorMessage): - VStack(spacing: 16) { + VStack(spacing: WerkoutTheme.md) { Text("Unable to load workout") - .font(.headline) + .font(WerkoutTheme.sectionTitle) + .foregroundStyle(WerkoutTheme.textPrimary) Text(errorMessage) - .font(.footnote) + .font(WerkoutTheme.bodyText) .multilineTextAlignment(.center) - .foregroundStyle(.secondary) + .foregroundStyle(WerkoutTheme.textSecondary) } .padding() case .showWorkout(let workout): VStack(spacing: 0) { if bridgeModule.isInWorkout { HStack { - CountdownView() + CountdownView( + currentExerciseDuration: bridgeModule.currentWorkoutInfo.currentExercise?.duration, + currentExerciseTimeLeft: bridgeModule.currentExerciseTimeLeft + ) } .padding() .frame(maxWidth: .infinity) - + if phoneThotStyle != .off { - GeometryReader { metrics in - ZStack { - PlayerView(player: $avPlayer) - .frame(width: metrics.size.width * 1, height: metrics.size.height * 1) - .onAppear{ - avPlayer.isMuted = true - avPlayer.play() - } - + PlayerView(player: $avPlayer) + .frame(height: 220) + .onAppear{ + avPlayer.isMuted = true + avPlayer.play() + } + .overlay(alignment: .bottomTrailing) { Button(action: { if let assetURL = ((avPlayer.currentItem?.asset) as? AVURLAsset)?.url, let currentExtercise = bridgeModule.currentWorkoutInfo.currentExercise, @@ -72,73 +77,86 @@ struct WorkoutDetailView: View { workout: bridgeModule.currentWorkoutInfo.workout) { updatePlayer(for: otherVideoURL) } - }, label: { + }) { Image(systemName: "arrow.triangle.2.circlepath.camera.fill") - .frame(width: 44, height: 44) - .foregroundColor(Color("appColor")) - }) - .foregroundColor(.blue) - .cornerRadius(Constants.buttonRadius) - .frame(width: 160, height: 120) - .position(x: metrics.size.width - 22, y: metrics.size.height - 30) + .font(.title2) + .padding(WerkoutTheme.sm) + } + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + .padding(WerkoutTheme.sm) .accessibilityLabel("Switch video style") .accessibilityHint("Toggles between alternate and default exercise videos") - + } + .overlay(alignment: .bottomLeading) { Button(action: { showExecersizeInfo.toggle() - }, label: { + }) { Image(systemName: "info.circle.fill") - .frame(width: 44, height: 44) - .foregroundColor(Color("appColor")) - }) - .foregroundColor(.blue) - .cornerRadius(Constants.buttonRadius) - .frame(width: 120, height: 120) - .position(x: 22, y: metrics.size.height - 30) + .font(.title2) + .padding(WerkoutTheme.sm) + } + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + .padding(WerkoutTheme.sm) .accessibilityLabel(showExecersizeInfo ? "Hide exercise info" : "Show exercise info") .accessibilityHint("Shows exercise description and target muscles") } - } - .padding([.top, .bottom]) - .background(Color(uiColor: .tertiarySystemBackground)) + .padding([.top, .bottom]) + .background(WerkoutTheme.background) } } - + if !bridgeModule.isInWorkout { InfoView(workout: workout) .padding(.bottom) } - + if bridgeModule.isInWorkout { - Divider() - .background(Color(uiColor: .secondaryLabel)) + WerkoutTheme.divider.frame(height: 0.5) HStack { Text("\(bridgeModule.currentWorkoutInfo.currentRound) of \(bridgeModule.currentWorkoutInfo.numberOfRoundsInCurrentSuperSet)") - .font(.title3) - .bold() + .font(.system(size: 17, weight: .bold, design: .monospaced)) + .foregroundStyle(WerkoutTheme.accent) .frame(maxWidth: .infinity, alignment: .leading) .padding(.leading, 10) - - CurrentWorkoutElapsedTimeView() + + CurrentWorkoutElapsedTimeView( + currentWorkoutRunTimeInSeconds: bridgeModule.currentWorkoutRunTimeInSeconds + ) .frame(maxWidth: .infinity, alignment: .center) - + Text(progressText) - .font(.title3) - .bold() + .font(.system(size: 17, weight: .bold, design: .monospaced)) + .foregroundStyle(WerkoutTheme.textPrimary) .frame(maxWidth: .infinity, alignment: .trailing) .padding(.trailing, 10) } .padding([.top, .bottom]) - .background(Color(uiColor: .tertiarySystemBackground)) + .background(WerkoutTheme.surfaceCard) } - - Divider() - .background(Color(uiColor: .secondaryLabel)) - - ExerciseListView(workout: workout, showExecersizeInfo: $showExecersizeInfo) + + WerkoutTheme.divider.frame(height: 0.5) + + ExerciseListView( + workout: workout, + showExecersizeInfo: $showExecersizeInfo, + isInWorkout: bridgeModule.isInWorkout, + currentSupersetIndex: bridgeModule.currentWorkoutInfo.supersetIndex, + currentExerciseIndex: bridgeModule.currentWorkoutInfo.exerciseIndex, + allSupersetExecerciseIndex: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex, + currentExercise: bridgeModule.currentWorkoutInfo.currentExercise, + currentWorkout: bridgeModule.currentWorkoutInfo.workout, + goToExerciseAt: { supersetIndex, exerciseIndex in + bridgeModule.currentWorkoutInfo.goToExerciseAt( + supersetIndex: supersetIndex, + exerciseIndex: exerciseIndex + ) + } + ) .padding([.top, .bottom], 10) - .background(Color(uiColor: .systemGroupedBackground)) - + .background(WerkoutTheme.background) + ActionsView(completedWorkout: { bridgeModule.completeWorkout() }, planWorkout: { workout in @@ -146,8 +164,8 @@ struct WorkoutDetailView: View { }, workout: workout, showAddToCalendar: viewModel.isPreview, startWorkoutAction: { startWorkout(workout: workout) }) - .frame(height: 44) - + .frame(height: 56) + } .sheet(item: $workoutComplete) { item in switch item { @@ -169,15 +187,16 @@ struct WorkoutDetailView: View { } } } - .onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex, perform: { _ in + .onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex) { _, _ in playVideos() - }) - .onChange(of: bridgeModule.isInWorkout, perform: { _ in + } + .onChange(of: bridgeModule.isInWorkout) { _, _ in playVideos() - }) + } .onAppear{ + viewModel.load() playVideos() - + bridgeModule.completedWorkout = { if let workoutData = createWorkoutData() { workoutComplete = .completedWorkout(workoutData) @@ -194,7 +213,7 @@ struct WorkoutDetailView: View { bridgeModule.completedWorkout = nil } } - + func playVideos() { if let currentExtercise = bridgeModule.currentWorkoutInfo.currentExercise { if let videoURL = VideoURLCreator.videoURL( @@ -221,7 +240,7 @@ struct WorkoutDetailView: View { avPlayer.isMuted = true avPlayer.play() } - + func startWorkout(workout: Workout) { bridgeModule.start(workout: workout) } @@ -235,7 +254,7 @@ struct WorkoutDetailView: View { let current = min(totalExercises, max(1, bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex + 1)) return "\(current)/\(totalExercises)" } - + func createWorkoutData() -> [String:Any]? { guard let workoutid = bridgeModule.currentWorkoutInfo.workout?.id, let startTime = bridgeModule.workoutStartDate?.timeFormatForUpload, @@ -249,7 +268,7 @@ struct WorkoutDetailView: View { "workout": workoutid, "total_time": bridgeModule.currentWorkoutRunTimeInSeconds ] as [String : Any] - + return postBody } } diff --git a/iphone/Werkout_ios/Views/WorkoutDetail/WorkoutDetailViewModel.swift b/iphone/Werkout_ios/Views/WorkoutDetail/WorkoutDetailViewModel.swift index 7af687a..fb52b8e 100644 --- a/iphone/Werkout_ios/Views/WorkoutDetail/WorkoutDetailViewModel.swift +++ b/iphone/Werkout_ios/Views/WorkoutDetail/WorkoutDetailViewModel.swift @@ -17,26 +17,32 @@ class WorkoutDetailViewModel: ObservableObject { @Published var status: WorkoutDetailViewModelStatus let isPreview: Bool - + let workout: Workout + init(workout: Workout, status: WorkoutDetailViewModelStatus? = nil, isPreview: Bool) { - self.status = .loading + self.workout = workout self.isPreview = isPreview - + if let passedStatus = status { self.status = passedStatus } else { - WorkoutDetailFetchable(workoutID: workout.id).fetch(completion: { result in - switch result { - case .success(let model): - DispatchQueue.main.async { - self.status = .showWorkout(model) - } - case .failure(let failure): - DispatchQueue.main.async { - self.status = .failed("Failed to load workout details: \(failure.localizedDescription)") - } - } - }) + self.status = .loading } } + + func load() { + guard case .loading = status else { return } + WorkoutDetailFetchable(workoutID: workout.id).fetch(completion: { result in + switch result { + case .success(let model): + DispatchQueue.main.async { + self.status = .showWorkout(model) + } + case .failure(let failure): + DispatchQueue.main.async { + self.status = .failed("Failed to load workout details: \(failure.localizedDescription)") + } + } + }) + } } diff --git a/iphone/Werkout_ios/Views/WorkoutHistoryView.swift b/iphone/Werkout_ios/Views/WorkoutHistoryView.swift index ecaaed0..3f556d1 100644 --- a/iphone/Werkout_ios/Views/WorkoutHistoryView.swift +++ b/iphone/Werkout_ios/Views/WorkoutHistoryView.swift @@ -14,10 +14,10 @@ struct WorkoutHistoryView: View { case average case hard case death - + var stringValue: String { switch self { - + case .easy: return "Easy" case .moderate: @@ -30,43 +30,81 @@ struct WorkoutHistoryView: View { return "Death" } } + + var color: Color { + switch self { + case .easy: + return WerkoutTheme.success + case .moderate: + return Color(red: 0.4, green: 0.8, blue: 0.2) + case .average: + return WerkoutTheme.warning + case .hard: + return Color(red: 1.0, green: 0.5, blue: 0.2) + case .death: + return WerkoutTheme.danger + } + } } - + let completedWorkouts: [CompletedWorkout] - + @State private var selectedPlannedWorkout: Workout? - + + private var sortedWorkouts: [CompletedWorkout] { + completedWorkouts.sorted(by: { $0.createdAt > $1.createdAt }) + } + var body: some View { List { - ForEach(completedWorkouts.sorted(by: { $0.createdAt > $1.createdAt }), id:\.self.id) { completedWorkout in + ForEach(sortedWorkouts, id: \.id) { completedWorkout in HStack { VStack { if let date = completedWorkout.workoutStartTime.dateFromServerDate { Text(date.monthString) - + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) + Text("\(date.get(.day))") + .font(WerkoutTheme.stat.monospacedDigit()) + .foregroundStyle(WerkoutTheme.accent) + Text("\(date.get(.hour))") + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textMuted) } } - + .frame(minWidth: 60) + VStack(alignment: .leading) { Text(completedWorkout.workout.name) - .font(.title3) - + .font(WerkoutTheme.cardTitle) + .foregroundStyle(WerkoutTheme.textPrimary) + if let desc = completedWorkout.workout.description { Text(desc) - .font(.footnote) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) } - + Divider() - + .overlay(WerkoutTheme.divider) + if let difficulty = completedWorkout.difficulty, - let string = DifficltyString.init(rawValue: difficulty)?.stringValue { - Text(string) + let difficultyEnum = DifficltyString(rawValue: difficulty) { + Text(difficultyEnum.stringValue) + .font(WerkoutTheme.caption) + .foregroundStyle(difficultyEnum.color) + .padding(.horizontal, WerkoutTheme.sm) + .padding(.vertical, WerkoutTheme.xs) + .background(difficultyEnum.color.opacity(0.15)) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.badgeRadius, style: .continuous)) } - + if let notes = completedWorkout.notes { Text(notes) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) } } .padding(.leading) @@ -74,10 +112,14 @@ struct WorkoutHistoryView: View { .onTapGesture { selectedPlannedWorkout = completedWorkout.workout } - + } + .listRowBackground(WerkoutTheme.surfaceCard) } } + .listStyle(.plain) + .background(WerkoutTheme.background) + .scrollContentBackground(.hidden) .sheet(item: $selectedPlannedWorkout) { item in let viewModel = WorkoutDetailViewModel(workout: item, isPreview: true) WorkoutDetailView(viewModel: viewModel) diff --git a/iphone/Werkout_ios/WerkoutTheme.swift b/iphone/Werkout_ios/WerkoutTheme.swift new file mode 100644 index 0000000..3414554 --- /dev/null +++ b/iphone/Werkout_ios/WerkoutTheme.swift @@ -0,0 +1,127 @@ +// +// WerkoutTheme.swift +// Werkout_ios +// +// Design system: iOS 26 Liquid Glass + Industrial Gym Aesthetic +// + +import SwiftUI + +// MARK: - Design Tokens + +enum WerkoutTheme { + + // MARK: Colors + + static let background = Color.black + static let surfaceCard = Color(white: 0.09) + static let surfaceElevated = Color(white: 0.12) + static let accent = Color("appColor") + static let accentNeon = Color(red: 0.75, green: 0.35, blue: 1.0) + static let success = Color(red: 0.0, green: 0.9, blue: 0.5) + static let danger = Color(red: 1.0, green: 0.25, blue: 0.3) + static let warning = Color(red: 1.0, green: 0.75, blue: 0.0) + static let textPrimary = Color.white + static let textSecondary = Color(white: 0.55) + static let textMuted = Color(white: 0.35) + static let divider = Color(white: 0.15) + + // MARK: Typography + + static let heroTitle = Font.system(size: 34, weight: .black, design: .rounded) + static let sectionTitle = Font.system(size: 20, weight: .heavy, design: .rounded) + static let cardTitle = Font.system(size: 17, weight: .bold) + static let bodyText = Font.system(size: 15, weight: .medium) + static let caption = Font.system(size: 12, weight: .semibold) + static let stat = Font.system(size: 48, weight: .black, design: .monospaced) + + // MARK: Spacing + + static let xs: CGFloat = 4 + static let sm: CGFloat = 8 + static let md: CGFloat = 16 + static let lg: CGFloat = 24 + static let xl: CGFloat = 32 + + // MARK: Corner Radius + + static let cardRadius: CGFloat = 16 + static let buttonRadius: CGFloat = 12 + static let badgeRadius: CGFloat = 8 + static let pillRadius: CGFloat = 20 +} + +// MARK: - Reusable View Modifiers + +struct WerkoutCardModifier: ViewModifier { + func body(content: Content) -> some View { + content + .padding(WerkoutTheme.md) + .background(WerkoutTheme.surfaceCard) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.cardRadius, style: .continuous)) + .overlay( + RoundedRectangle(cornerRadius: WerkoutTheme.cardRadius, style: .continuous) + .strokeBorder(WerkoutTheme.divider, lineWidth: 0.5) + ) + } +} + +struct WerkoutButtonModifier: ViewModifier { + var color: Color = WerkoutTheme.accent + + func body(content: Content) -> some View { + content + .font(.system(size: 16, weight: .bold)) + .foregroundStyle(.white) + .padding(.horizontal, WerkoutTheme.lg) + .padding(.vertical, WerkoutTheme.sm + 4) + .background(color) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + } +} + +struct WerkoutTextFieldModifier: ViewModifier { + func body(content: Content) -> some View { + content + .padding(12) + .background(WerkoutTheme.surfaceCard) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + .overlay( + RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous) + .strokeBorder(WerkoutTheme.accent.opacity(0.3), lineWidth: 1) + ) + .foregroundStyle(WerkoutTheme.textPrimary) + } +} + +extension View { + func werkoutCard() -> some View { + modifier(WerkoutCardModifier()) + } + + func werkoutButton(color: Color = WerkoutTheme.accent) -> some View { + modifier(WerkoutButtonModifier(color: color)) + } + + func werkoutTextField() -> some View { + modifier(WerkoutTextFieldModifier()) + } +} + +// MARK: - Button Style + +struct WerkoutActionButtonStyle: ButtonStyle { + var color: Color = WerkoutTheme.accent + + func makeBody(configuration: Configuration) -> some View { + configuration.label + .font(.system(size: 16, weight: .bold)) + .foregroundStyle(.white) + .padding(.horizontal, WerkoutTheme.lg) + .padding(.vertical, WerkoutTheme.sm + 4) + .background(color) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + .scaleEffect(configuration.isPressed ? 0.95 : 1.0) + .animation(.easeInOut(duration: 0.15), value: configuration.isPressed) + } +} diff --git a/iphone/Werkout_ios/Werkout_iosApp.swift b/iphone/Werkout_ios/Werkout_iosApp.swift index 1502ebd..111e3c5 100644 --- a/iphone/Werkout_ios/Werkout_iosApp.swift +++ b/iphone/Werkout_ios/Werkout_iosApp.swift @@ -17,7 +17,7 @@ struct Constants { static let extShowNextVideo = "extShowNextVideo" static let thotGenderOption = "thotGenderOption" - static let buttonRadius: CGFloat = 4 + static let buttonRadius: CGFloat = 12 } @main @@ -28,21 +28,21 @@ struct Werkout_iosApp: App { @Environment(\.scenePhase) private var scenePhase let pub = NotificationCenter.default.publisher(for: AppNotifications.createdNewWorkout) + let logoutPub = NotificationCenter.default.publisher(for: AppNotifications.userLoggedOut) - private var screenDidConnectPublisher: AnyPublisher { + private var screenDidConnectPublisher: AnyPublisher { NotificationCenter.default .publisher(for: UIScene.willConnectNotification) - .compactMap { ($0.object as? UIWindowScene)?.screen } - .filter { $0 != UIScreen.main } + .compactMap { $0.object as? UIWindowScene } + .filter { $0.screen != UIApplication.shared.connectedScenes.compactMap { ($0 as? UIWindowScene)?.screen }.first } .receive(on: RunLoop.main) .eraseToAnyPublisher() } - - private var screenDidDisconnectPublisher: AnyPublisher { + + private var screenDidDisconnectPublisher: AnyPublisher { NotificationCenter.default .publisher(for: UIScene.didDisconnectNotification) - .compactMap { ($0.object as? UIWindowScene)?.screen } - .filter { $0 != UIScreen.main } + .compactMap { $0.object as? UIWindowScene } .receive(on: RunLoop.main) .eraseToAnyPublisher() } @@ -51,14 +51,12 @@ struct Werkout_iosApp: App { WindowGroup { TabView(selection: $tabSelection) { AllWorkoutsView() - .onReceive( - screenDidConnectPublisher, - perform: screenDidConnect - ) - .onReceive( - screenDidDisconnectPublisher, - perform: screenDidDisconnect - ) + .onReceive(screenDidConnectPublisher) { scene in + screenDidConnect(scene) + } + .onReceive(screenDidDisconnectPublisher) { scene in + screenDidDisconnect(scene) + } .tabItem { Label("All Workouts", systemImage: "figure.strengthtraining.traditional") } @@ -76,33 +74,33 @@ struct Werkout_iosApp: App { } .tag(3) } - .accentColor(Color("appColor")) + .tint(WerkoutTheme.accent) + .tabBarMinimizeBehavior(.onScrollDown) + .preferredColorScheme(.dark) .onAppear{ UIApplication.shared.isIdleTimerDisabled = scenePhase == .active _ = try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: .default, options: .mixWithOthers) -// UserStore.shared.logout() } - .onChange(of: scenePhase) { phase in + .onChange(of: scenePhase) { _, phase in UIApplication.shared.isIdleTimerDisabled = phase == .active } - .onReceive(pub) { (output) in + .onReceive(pub) { _ in + self.tabSelection = 1 + } + .onReceive(logoutPub) { _ in self.tabSelection = 1 } } } - private func screenDidDisconnect(_ screen: UIScreen) { - additionalWindows.removeAll { $0.screen == screen } + private func screenDidDisconnect(_ scene: UIWindowScene) { + additionalWindows.removeAll { $0.windowScene == scene } BridgeModule.shared.isShowingOnExternalDisplay = false } - - private func screenDidConnect(_ screen: UIScreen) { - let window = UIWindow(frame: screen.bounds) - - window.windowScene = UIApplication.shared.connectedScenes - .first { ($0 as? UIWindowScene)?.screen == screen } - as? UIWindowScene - + + private func screenDidConnect(_ scene: UIWindowScene) { + let window = UIWindow(windowScene: scene) + let view = ExternalWorkoutDetailView() .preferredColorScheme(.dark) let controller = UIHostingController(rootView: view) diff --git a/iphone/Werkout_ios/subview/ActionsView.swift b/iphone/Werkout_ios/subview/ActionsView.swift index 5b971ea..8d27605 100644 --- a/iphone/Werkout_ios/subview/ActionsView.swift +++ b/iphone/Werkout_ios/subview/ActionsView.swift @@ -11,98 +11,90 @@ struct ActionsView: View { @ObservedObject var bridgeModule = BridgeModule.shared var completedWorkout: (() -> Void)? var planWorkout: ((Workout) -> Void)? - + var workout: Workout @Environment(\.dismiss) var dismiss var showAddToCalendar: Bool var startWorkoutAction: (() -> Void) @State var showCompleteSheet: Bool = false - + var body: some View { - HStack { - if bridgeModule.isInWorkout == false { - Button(action: { - bridgeModule.resetCurrentWorkout() - dismiss() - }, label: { - Image(systemName: "xmark.octagon.fill") - .font(.title) - .frame(maxWidth: .infinity, maxHeight: .infinity) - }) - .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(.red) - .foregroundColor(.white) - .accessibilityLabel("Close workout") - - if showAddToCalendar { + GlassEffectContainer { + HStack(spacing: WerkoutTheme.sm) { + if bridgeModule.isInWorkout == false { Button(action: { - planWorkout?(workout) + bridgeModule.resetCurrentWorkout() + dismiss() }, label: { - Image(systemName: "calendar.badge.plus") + Image(systemName: "xmark.octagon.fill") .font(.title) .frame(maxWidth: .infinity, maxHeight: .infinity) }) - .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(.blue) - .foregroundColor(.white) - .accessibilityLabel("Plan workout") + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.danger) + .accessibilityLabel("Close workout") + + if showAddToCalendar { + Button(action: { + planWorkout?(workout) + }, label: { + Image(systemName: "calendar.badge.plus") + .font(.title) + .frame(maxWidth: .infinity, maxHeight: .infinity) + }) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + .accessibilityLabel("Plan workout") + } + + Button(action: { + startWorkoutAction() + }, label: { + Image(systemName: "arrowtriangle.forward.fill") + .font(.title) + .frame(maxWidth: .infinity, maxHeight: .infinity) + }) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.success) + .accessibilityLabel("Start workout") + } else { + Button(action: { + showCompleteSheet.toggle() + }, label: { + Image(systemName: "checkmark") + .font(.title) + .frame(maxWidth: .infinity, maxHeight: .infinity) + }) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + .accessibilityLabel("Complete workout") + + Button(action: { + AudioEngine.shared.playFinished() + bridgeModule.pauseWorkout() + }, label: { + Image(systemName: bridgeModule.isPaused ? "play.circle.fill" : "pause.circle.fill") + .font(.title) + .frame(maxWidth: .infinity, maxHeight: .infinity) + }) + .glassEffect(.regular.interactive()) + .tint(bridgeModule.isPaused ? WerkoutTheme.success : WerkoutTheme.warning) + .accessibilityLabel(bridgeModule.isPaused ? "Resume workout" : "Pause workout") + + Button(action: { + AudioEngine.shared.playFinished() + nextExercise() + }, label: { + Image(systemName: "arrow.forward") + .font(.title) + .frame(maxWidth: .infinity, maxHeight: .infinity) + }) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.success) + .accessibilityLabel("Next exercise") } - - Button(action: { - startWorkoutAction() - }, label: { - Image(systemName: "arrowtriangle.forward.fill") - .font(.title) - .frame(maxWidth: .infinity, maxHeight: .infinity) - }) - .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(.green) - .foregroundColor(.white) - .accessibilityLabel("Start workout") - } else { - Button(action: { - showCompleteSheet.toggle() - }, label: { - Image(systemName: "checkmark") - .font(.title) - .frame(maxWidth: .infinity, maxHeight: .infinity) - }) - .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(.blue) - .foregroundColor(.white) - .accessibilityLabel("Complete workout") - - Button(action: { - AudioEngine.shared.playFinished() - bridgeModule.pauseWorkout() - }, label: { - bridgeModule.isPaused ? - Image(systemName: "play.circle.fill") - .font(.title) - .frame(maxWidth: .infinity, maxHeight: .infinity) - : - Image(systemName: "pause.circle.fill") - .font(.title) - .frame(maxWidth: .infinity, maxHeight: .infinity) - }) - .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(bridgeModule.isPaused ? .mint : .yellow) - .foregroundColor(.white) - .accessibilityLabel(bridgeModule.isPaused ? "Resume workout" : "Pause workout") - - Button(action: { - AudioEngine.shared.playFinished() - nextExercise() - }, label: { - Image(systemName: "arrow.forward") - .font(.title) - .frame(maxWidth: .infinity, maxHeight: .infinity) - }) - .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(.green) - .foregroundColor(.white) - .accessibilityLabel("Next exercise") } + .padding(.horizontal, WerkoutTheme.sm) } .alert("Complete Workout", isPresented: $showCompleteSheet) { Button("Complete Workout", role: .destructive) { @@ -112,13 +104,12 @@ struct ActionsView: View { Button("Back to workout", role: .cancel) { } } } - + func nextExercise() { bridgeModule.nextExercise() } } - struct ActionsView_Previews: PreviewProvider { static var previews: some View { ActionsView(workout: PreviewData.workout(), showAddToCalendar: true, startWorkoutAction: {}) diff --git a/iphone/Werkout_ios/subview/AddSupersetView.swift b/iphone/Werkout_ios/subview/AddSupersetView.swift index 59f03a4..c204e84 100644 --- a/iphone/Werkout_ios/subview/AddSupersetView.swift +++ b/iphone/Werkout_ios/subview/AddSupersetView.swift @@ -10,37 +10,41 @@ struct AddSupersetView: View { @ObservedObject var createWorkoutSuperSet: CreateWorkoutSuperSet var viewModel: WorkoutViewModel @Binding var selectedCreateWorkoutSuperSet: CreateWorkoutSuperSet? - + var body: some View { TabView { ForEach(createWorkoutSuperSet.exercises, id: \.id) { createWorkoutExercise in - VStack { + VStack(spacing: WerkoutTheme.sm) { Text(createWorkoutExercise.exercise.name) - .font(.title2) + .font(WerkoutTheme.cardTitle) + .foregroundStyle(WerkoutTheme.textPrimary) .frame(maxWidth: .infinity) if let side = createWorkoutExercise.exercise.side, side.isEmpty == false { Text(side) - .font(.title3) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) .frame(maxWidth: .infinity, alignment: .center) } CreateExerciseActionsView(workoutExercise: createWorkoutExercise, superset: createWorkoutSuperSet, viewModel: viewModel) } - .frame(width: 300.0) + .frame(maxWidth: .infinity) + .padding(.horizontal, WerkoutTheme.md) .padding(.bottom, 40) } } - .frame(height: 300) + .frame(minHeight: 220, maxHeight: 320) .tabViewStyle(.page) + .background(WerkoutTheme.background) .onAppear { setupAppearance() } } - + func setupAppearance() { - UIPageControl.appearance().currentPageIndicatorTintColor = .black - UIPageControl.appearance().pageIndicatorTintColor = UIColor.black.withAlphaComponent(0.2) + UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(WerkoutTheme.accent) + UIPageControl.appearance().pageIndicatorTintColor = UIColor(WerkoutTheme.accent).withAlphaComponent(0.25) } } diff --git a/iphone/Werkout_ios/subview/AllEquipmentView.swift b/iphone/Werkout_ios/subview/AllEquipmentView.swift index 09371e6..f8f5039 100644 --- a/iphone/Werkout_ios/subview/AllEquipmentView.swift +++ b/iphone/Werkout_ios/subview/AllEquipmentView.swift @@ -12,11 +12,14 @@ struct AllEquipmentView: View { @State var createWorkoutItemPickerViewModel: CreateWorkoutItemPickerViewModel? var body: some View { - VStack { + VStack(spacing: WerkoutTheme.xs) { if let _ = DataStore.shared.allEquipment { Text("Select Equipment") - .foregroundColor(.cyan) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.accent) Text("\(selectedEquipment.count) Selected") + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) } } .onTapGesture { diff --git a/iphone/Werkout_ios/subview/AllExerciseView.swift b/iphone/Werkout_ios/subview/AllExerciseView.swift index 2a87e44..5d134d8 100644 --- a/iphone/Werkout_ios/subview/AllExerciseView.swift +++ b/iphone/Werkout_ios/subview/AllExerciseView.swift @@ -12,9 +12,10 @@ struct AllExerciseView: View { @Environment(\.dismiss) var dismiss @State var searchString: String = "" @Binding var filteredExercises: [Exercise] + @State private var displayedExercises: [Exercise] = [] var selectedExercise: ((Exercise) -> Void) - - @State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) + + @State var avPlayer = AVPlayer(url: URL(string: BaseURLs.currentBaseURL + "/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null")) @State private var currentVideoURL: URL? @State var videoExercise: Exercise? { didSet { @@ -24,62 +25,68 @@ struct AllExerciseView: View { } } } - + var body: some View { - VStack { + VStack(spacing: WerkoutTheme.sm) { TextField("Filter", text: $searchString) - .padding(.horizontal) - .textFieldStyle(.roundedBorder) + .werkoutTextField() + .padding(.horizontal, WerkoutTheme.md) List() { - ForEach(filteredExercises, id: \.self) { exercise in - if searchString.isEmpty || exercise.name.lowercased().contains(searchString.lowercased()) { - HStack { - VStack { - Text(exercise.name) + ForEach(displayedExercises, id: \.self) { exercise in + HStack { + VStack(spacing: WerkoutTheme.xs) { + Text(exercise.name) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textPrimary) + .frame(maxWidth: .infinity, alignment: .leading) + + if let side = exercise.side, + side.isEmpty == false { + Text(side) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) .frame(maxWidth: .infinity, alignment: .leading) - - if let side = exercise.side, - side.isEmpty == false { - Text(side) - .font(.footnote) - .frame(maxWidth: .infinity, alignment: .leading) - } - - if exercise.equipmentRequired?.isEmpty == false { - Text(exercise.spacedEquipmentRequired) - .font(.footnote) - .frame(maxWidth: .infinity, alignment: .leading) - } - - if exercise.muscleGroups?.isEmpty == false { - Text(exercise.spacedMuscleGroups) - .font(.footnote) - .frame(maxWidth: .infinity, alignment: .leading) - } } - .contentShape(Rectangle()) - .onTapGesture { - selectedExercise(exercise) - dismiss() + + if exercise.equipmentRequired?.isEmpty == false { + Text(exercise.spacedEquipmentRequired) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) + .frame(maxWidth: .infinity, alignment: .leading) } - Button(action: { - videoExercise = exercise - }) { - ZStack { - Circle() - .fill(.blue) - .frame(width: 33, height: 33) - Image(systemName: "video.fill") - .frame(width: 33, height: 33) - .foregroundColor(.white ) - } + + if exercise.muscleGroups?.isEmpty == false { + Text(exercise.spacedMuscleGroups) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) + .frame(maxWidth: .infinity, alignment: .leading) } - .frame(width: 33, height: 33) } + .contentShape(Rectangle()) + .onTapGesture { + selectedExercise(exercise) + dismiss() + } + Button(action: { + videoExercise = exercise + }) { + ZStack { + Circle() + .fill(WerkoutTheme.accent) + .frame(width: 33, height: 33) + Image(systemName: "video.fill") + .frame(width: 33, height: 33) + .foregroundStyle(WerkoutTheme.textPrimary) + } + } + .frame(width: 33, height: 33) } + .listRowBackground(WerkoutTheme.surfaceCard) } } + .scrollContentBackground(.hidden) + .background(WerkoutTheme.background) } .sheet(item: $videoExercise) { exercise in PlayerView(player: $avPlayer) @@ -88,11 +95,23 @@ struct AllExerciseView: View { avPlayer.play() } } + .onAppear { applySearch() } + .onChange(of: searchString) { _, _ in applySearch() } + .onChange(of: filteredExercises) { _, _ in applySearch() } .onDisappear { avPlayer.pause() } } + private func applySearch() { + if searchString.isEmpty { + displayedExercises = filteredExercises + } else { + let query = searchString.lowercased() + displayedExercises = filteredExercises.filter { $0.name.lowercased().contains(query) } + } + } + private func updatePlayer(for url: URL) { if currentVideoURL == url { avPlayer.seek(to: .zero) diff --git a/iphone/Werkout_ios/subview/AllMusclesView.swift b/iphone/Werkout_ios/subview/AllMusclesView.swift index bc23185..e1e18ee 100644 --- a/iphone/Werkout_ios/subview/AllMusclesView.swift +++ b/iphone/Werkout_ios/subview/AllMusclesView.swift @@ -12,11 +12,14 @@ struct AllMusclesView: View { @State var createWorkoutItemPickerViewModel: CreateWorkoutItemPickerViewModel? var body: some View { - VStack { + VStack(spacing: WerkoutTheme.xs) { if let _ = DataStore.shared.allMuscles { Text("Select Muscles") - .foregroundColor(.cyan) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.accent) Text("\(selectedMuscles.count) Selected") + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) } } .onTapGesture { diff --git a/iphone/Werkout_ios/subview/AllWorkoutPickerView.swift b/iphone/Werkout_ios/subview/AllWorkoutPickerView.swift deleted file mode 100644 index f5ba29d..0000000 --- a/iphone/Werkout_ios/subview/AllWorkoutPickerView.swift +++ /dev/null @@ -1,37 +0,0 @@ -// -// AllWorkoutPickerView.swift -// Werkout_ios -// -// Created by Trey Tartt on 7/7/23. -// - -import SwiftUI - -struct AllWorkoutPickerView: View { - var mainViews: [MainViewTypes] - @Binding var selectedSegment: MainViewTypes - @StateObject var bridgeModule = BridgeModule.shared - var showCurrentWorkout: (() -> Void) - - var body: some View { - HStack { - Picker("", selection: $selectedSegment) { - ForEach(mainViews, id: \.self) { viewType in - Text(viewType.title) - } - } - .pickerStyle(.segmented) - .padding([.top, .leading, .trailing]) - - if bridgeModule.isInWorkout { - Button(action: { - showCurrentWorkout() - }, label: { - Image(systemName: "figure.strengthtraining.traditional") - .padding(.trailing) - }) - .tint(Color("appColor")) - } - } - } -} diff --git a/iphone/Werkout_ios/subview/CaloriesBurnedView.swift b/iphone/Werkout_ios/subview/CaloriesBurnedView.swift index d9afcc9..b1818bd 100644 --- a/iphone/Werkout_ios/subview/CaloriesBurnedView.swift +++ b/iphone/Werkout_ios/subview/CaloriesBurnedView.swift @@ -10,45 +10,47 @@ import SwiftUI struct CaloriesBurnedView: View { @Binding var healthKitWorkoutData: HealthKitWorkoutData? let calsBurned: Double - + var body: some View { - VStack { + VStack(spacing: WerkoutTheme.sm) { HStack { - HStack { + HStack(spacing: WerkoutTheme.sm) { Image(systemName: "flame.fill") - .foregroundColor(.orange) + .foregroundStyle(.orange) .font(.title) - VStack { - Text("\(calsBurned, specifier: "%.0f")") - } + Text("\(calsBurned, specifier: "%.0f")") + .font(.system(size: 28, weight: .black, design: .monospaced)) + .foregroundStyle(WerkoutTheme.textPrimary) } .frame(maxWidth: .infinity) } - + if let minHeart = healthKitWorkoutData?.minHeartRate, let maxHeart = healthKitWorkoutData?.maxHeartRate, let avgHeart = healthKitWorkoutData?.avgHeartRate { - VStack { - HStack { - Image(systemName: "heart") - .foregroundColor(.red) + VStack(spacing: WerkoutTheme.xs) { + HStack(spacing: WerkoutTheme.sm) { + Image(systemName: "heart.fill") + .foregroundStyle(WerkoutTheme.danger) .font(.title) VStack { HStack { Text("\(minHeart, specifier: "%.0f")") Text("-") + .foregroundStyle(WerkoutTheme.textMuted) Text("\(maxHeart, specifier: "%.0f")") } - Text("\(avgHeart, specifier: "%.0f")") + .font(.system(size: 20, weight: .bold, design: .monospaced)) + .foregroundStyle(WerkoutTheme.textPrimary) + Text("avg \(avgHeart, specifier: "%.0f")") + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) } } } .frame(maxWidth: .infinity) } } + .werkoutCard() } } - -//#Preview { -// CaloriesBurnedView() -//} diff --git a/iphone/Werkout_ios/subview/CompletedWorkoutsView.swift b/iphone/Werkout_ios/subview/CompletedWorkoutsView.swift index 5603d8a..24b469d 100644 --- a/iphone/Werkout_ios/subview/CompletedWorkoutsView.swift +++ b/iphone/Werkout_ios/subview/CompletedWorkoutsView.swift @@ -8,57 +8,95 @@ import SwiftUI struct CompletedWorkoutsView: View { - @State var completedWorkouts: [CompletedWorkout]? - @State var showCompletedWorkouts: Bool = false + @State private var completedWorkouts: [CompletedWorkout]? + @State private var showCompletedWorkouts: Bool = false @State private var loadError: String? var body: some View { VStack(alignment: .leading) { if let completedWorkouts = completedWorkouts { - + Divider() + .overlay(WerkoutTheme.divider) + Text("Workout History:") + .font(WerkoutTheme.sectionTitle) + .foregroundStyle(WerkoutTheme.textPrimary) + HStack { Text("Number of workouts:") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) Text("\(completedWorkouts.count)") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.accent) } - + if let lastWorkout = completedWorkouts.last { HStack { Text("Last workout:") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) Text(lastWorkout.workoutStartTime) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.accent) } - + Button("View All Workouts", action: { showCompletedWorkouts = true }) + .font(.system(size: 16, weight: .bold)) + .foregroundStyle(WerkoutTheme.textPrimary) .frame(maxWidth: .infinity, alignment: .center) .frame(height: 44) - .foregroundColor(.blue) - .background(.yellow) - .cornerRadius(Constants.buttonRadius) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) .padding() .frame(maxWidth: .infinity) } - + } else { if let loadError = loadError { Text(loadError) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.danger) } else { Text("loading completed workouts") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textMuted) } } } + .padding(WerkoutTheme.md) + .background(WerkoutTheme.surfaceCard) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.cardRadius, style: .continuous)) .onAppear{ fetchCompletedWorkouts() } + .refreshable { + await withCheckedContinuation { continuation in + CompletedWorkoutFetchable().fetch(completion: { result in + DispatchQueue.main.async { + switch result { + case .success(let model): + self.completedWorkouts = model + self.loadError = nil + case .failure(let failure): + self.loadError = "Unable to load workout history: \(failure.localizedDescription)" + } + continuation.resume() + } + }) + } + } .sheet(isPresented: $showCompletedWorkouts) { if let completedWorkouts = completedWorkouts { WorkoutHistoryView(completedWorkouts: completedWorkouts) } } } - + func fetchCompletedWorkouts() { CompletedWorkoutFetchable().fetch(completion: { result in switch result { diff --git a/iphone/Werkout_ios/subview/CountdownView.swift b/iphone/Werkout_ios/subview/CountdownView.swift index 84c374f..e1e48ed 100644 --- a/iphone/Werkout_ios/subview/CountdownView.swift +++ b/iphone/Werkout_ios/subview/CountdownView.swift @@ -8,15 +8,17 @@ import SwiftUI struct CountdownView: View { - @StateObject var bridgeModule = BridgeModule.shared - + let currentExerciseDuration: Int? + let currentExerciseTimeLeft: Int + var body: some View { - if let duration = bridgeModule.currentWorkoutInfo.currentExercise?.duration, + if let duration = currentExerciseDuration, duration > 0 { HStack { - if bridgeModule.currentExerciseTimeLeft >= 0 && duration > bridgeModule.currentExerciseTimeLeft { - ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration)) - .tint(Color("appColor")) + if currentExerciseTimeLeft >= 0 && duration > currentExerciseTimeLeft { + ProgressView(value: Float(currentExerciseTimeLeft), total: Float(duration)) + .tint(currentExerciseTimeLeft < 5 ? WerkoutTheme.danger : WerkoutTheme.accent) + .animation(.easeInOut, value: currentExerciseTimeLeft < 5) } } } @@ -25,6 +27,6 @@ struct CountdownView: View { struct CountdownView_Previews: PreviewProvider { static var previews: some View { - CountdownView() + CountdownView(currentExerciseDuration: 30, currentExerciseTimeLeft: 15) } } diff --git a/iphone/Werkout_ios/subview/CreateWorkoutSupersetView.swift b/iphone/Werkout_ios/subview/CreateWorkoutSupersetView.swift index 58e6c21..21bb314 100644 --- a/iphone/Werkout_ios/subview/CreateWorkoutSupersetView.swift +++ b/iphone/Werkout_ios/subview/CreateWorkoutSupersetView.swift @@ -11,7 +11,7 @@ struct CreateWorkoutSupersetView: View { @Binding var showAddExercise: Bool @ObservedObject var superset: CreateWorkoutSuperSet @ObservedObject var viewModel: WorkoutViewModel - + var body: some View { Section(content: { AddSupersetView( @@ -19,50 +19,58 @@ struct CreateWorkoutSupersetView: View { viewModel: viewModel, selectedCreateWorkoutSuperSet: $selectedCreateWorkoutSuperSet) }, header: { - VStack { + VStack(spacing: WerkoutTheme.sm) { HStack { TextField("Superset Title", text: $superset.title) - .font(.title2) + .font(WerkoutTheme.sectionTitle) + .foregroundStyle(WerkoutTheme.accent) } - - VStack { + + VStack(spacing: WerkoutTheme.sm) { HStack { Text("Exercises: \(superset.exercises.count)") - .font(.subheadline) - .bold() - + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) + Spacer() - + Button(action: { selectedCreateWorkoutSuperSet = superset showAddExercise = true }, label: { Image(systemName: "dumbbell.fill") .font(.title2) + .foregroundStyle(WerkoutTheme.accent) }) .accessibilityLabel("Add exercise") .accessibilityHint("Adds an exercise to this superset") - + Divider() - + .overlay(WerkoutTheme.divider) + Button(action: { viewModel.delete(superset: superset) }, label: { Image(systemName: "trash") .font(.title2) + .foregroundStyle(WerkoutTheme.danger) }) .accessibilityLabel("Delete superset") .accessibilityHint("Removes this superset") } - + Divider() - + .overlay(WerkoutTheme.divider) + Stepper(label: { HStack { Text("Rounds: ") - + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textPrimary) + Text("\(superset.numberOfRounds)") - .foregroundColor(superset.numberOfRounds > 0 ? Color(uiColor: .label) : .red) + .foregroundColor(superset.numberOfRounds > 0 ? WerkoutTheme.textPrimary : WerkoutTheme.danger) + .font(WerkoutTheme.bodyText) .bold() } }, onIncrement: { @@ -70,8 +78,10 @@ struct CreateWorkoutSupersetView: View { }, onDecrement: { superset.decreaseNumberOfRounds() }) + .tint(WerkoutTheme.accent) } } + .padding(.vertical, WerkoutTheme.xs) }) } } diff --git a/iphone/Werkout_ios/subview/ExtCountdownView.swift b/iphone/Werkout_ios/subview/ExtCountdownView.swift index 35f8bc9..d02e1e4 100644 --- a/iphone/Werkout_ios/subview/ExtCountdownView.swift +++ b/iphone/Werkout_ios/subview/ExtCountdownView.swift @@ -8,50 +8,55 @@ import SwiftUI struct ExtCountdownView: View { - @StateObject var bridgeModule = BridgeModule.shared - + @ObservedObject var bridgeModule = BridgeModule.shared + var body: some View { GeometryReader { metrics in VStack { if let currenExercise = bridgeModule.currentWorkoutInfo.currentExercise { HStack { Text(currenExercise.exercise.extName) - .font(.system(size: 200)) + .font(.system(size: 200, weight: .black, design: .rounded)) + .foregroundColor(WerkoutTheme.textPrimary) .scaledToFit() .minimumScaleFactor(0.01) .lineLimit(1) .frame(maxWidth: .infinity, alignment: .leading) } .frame(height: metrics.size.height * 0.5) - + HStack { if let duration = currenExercise.duration, duration > 0 { ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration)) .scaleEffect(x: 1, y: 6, anchor: .center) + .tint(WerkoutTheme.accent) Text("\(bridgeModule.currentExerciseTimeLeft)") - .font(Font.system(size: 100)) + .font(WerkoutTheme.stat) + .foregroundColor(WerkoutTheme.accent) .scaledToFit() .minimumScaleFactor(0.01) .lineLimit(1) .padding(.leading) .padding(.trailing, 100) } - + if let reps = currenExercise.reps, reps > 0 { Text(" X \(reps)") - .font(Font.system(size: 100)) + .font(.system(size: 100, weight: .heavy, design: .monospaced)) + .foregroundColor(WerkoutTheme.textPrimary) .scaledToFit() .minimumScaleFactor(0.01) .lineLimit(1) .frame(maxWidth: .infinity, alignment: .leading) } - + if let weight = currenExercise.weight, weight > 0 { Text(" @ \(weight)") - .font(Font.system(size: 100)) + .font(.system(size: 100, weight: .heavy, design: .monospaced)) + .foregroundColor(WerkoutTheme.textSecondary) .scaledToFit() .minimumScaleFactor(0.01) .lineLimit(1) diff --git a/iphone/Werkout_ios/subview/ExtExerciseList.swift b/iphone/Werkout_ios/subview/ExtExerciseList.swift index 1b325e4..4cfc7fc 100644 --- a/iphone/Werkout_ios/subview/ExtExerciseList.swift +++ b/iphone/Werkout_ios/subview/ExtExerciseList.swift @@ -10,7 +10,7 @@ import SwiftUI struct ExtExerciseList: View { var workout: Workout var allSupersetExecerciseIndex: Int - + var body: some View { if let allSupersetExecercise = workout.allSupersetExecercise { ZStack { @@ -21,49 +21,41 @@ struct ExtExerciseList: View { HStack { if supersetExecerciseIdx == allSupersetExecerciseIndex { Image(systemName: "figure.run") - .foregroundColor(Color("appColor")) + .foregroundColor(WerkoutTheme.accent) .font(Font.system(size: 55)) .minimumScaleFactor(0.01) .lineLimit(1) } - + Text(supersetExecercise.exercise.name) - .font(Font.system(size: 55)) + .font(Font.system(size: 55, weight: supersetExecerciseIdx == allSupersetExecerciseIndex ? .bold : .medium)) + .foregroundColor(supersetExecerciseIdx == allSupersetExecerciseIndex ? WerkoutTheme.textPrimary : WerkoutTheme.textSecondary) .minimumScaleFactor(0.01) .lineLimit(3) .padding() - + Spacer() } .id(supersetExecerciseIdx) } } - .onChange(of: allSupersetExecerciseIndex, perform: { newValue in + .onChange(of: allSupersetExecerciseIndex) { withAnimation { proxy.scrollTo(allSupersetExecerciseIndex, anchor: .top) } - }) - + } + } VStack { Text("\(allSupersetExecerciseIndex+1)/\(workout.allSupersetExecercise?.count ?? 0)") - .font(Font.system(size: 55)) + .font(Font.system(size: 55, weight: .bold, design: .monospaced)) .minimumScaleFactor(0.01) .lineLimit(1) .padding() - .bold() - .foregroundColor(.white) - .background( - Capsule() - .strokeBorder(Color.black, lineWidth: 0.8) - .background(Color(uiColor: UIColor(red: 148/255, - green: 0, - blue: 211/255, - alpha: 0.5))) - .clipped() - ) - .clipShape(Capsule()) - + .foregroundColor(WerkoutTheme.textPrimary) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.accent) + Spacer() } } diff --git a/iphone/Werkout_ios/subview/FilterAllView.swift b/iphone/Werkout_ios/subview/FilterAllView.swift index 448c7bf..d99eb62 100644 --- a/iphone/Werkout_ios/subview/FilterAllView.swift +++ b/iphone/Werkout_ios/subview/FilterAllView.swift @@ -1,5 +1,5 @@ // -// FilterAllView.swift +// FilterChip.swift // Werkout_ios // // Created by Trey Tartt on 11/25/24. @@ -7,153 +7,26 @@ import SwiftUI -struct FilterAllView: View { - @Binding var selectedMuscles: Set - @Binding var selectedEquipment: Set - @Binding var searchNameString: String - @Binding var uniqueWorkoutUsers: [RegisteredUser]? - @Binding var filteredRegisterdUser: RegisteredUser? - @Binding var filteredWorkouts: [Workout] - @Binding var workouts: [Workout] - @Binding var currentSort: SortType? - - var body: some View { - VStack { - TextField("Search by name" ,text: $searchNameString) - .padding(.horizontal) - .textFieldStyle(.roundedBorder) +struct FilterChip: View { + let label: String + let color: Color + let onRemove: () -> Void - HStack { - if let uniqueWorkoutUsers = uniqueWorkoutUsers { - Menu(content: { - ForEach(uniqueWorkoutUsers, id: \.self) { index in - Button(action: { - filteredRegisterdUser = index - filteredWorkouts = workouts.filterWorkouts( - nameSearchString: searchNameString, - musclesSearchString: selectedMuscles, - equipmentSearchString: selectedEquipment, - filteredRegisterdUser: filteredRegisterdUser - ) - }, label: { - Text((index.firstName ?? "") + " -" + (index.lastName ?? "")) - }) - } - - Button(action: { - filteredRegisterdUser = nil - filteredWorkouts = workouts.filterWorkouts( - nameSearchString: searchNameString, - musclesSearchString: selectedMuscles, - equipmentSearchString: selectedEquipment, - filteredRegisterdUser: filteredRegisterdUser - ) - }, label: { - Text("All") - }) - - }, label: { - Image(systemName: filteredRegisterdUser == nil ? "person.2" : "person.2.fill") - .padding(.trailing) - }) - } - - Menu(content: { - ForEach(SortType.allCases, id: \.self) { index in - Button(action: { - sortWorkouts(sortType: index) - }, label: { - Text(index.rawValue) - }) - } - }, label: { - Image(systemName: "list.number") - .padding(.trailing) - }) - - if let equipments = DataStore.shared.allEquipment { - Menu(content: { - ForEach(equipments, id: \.id) { equipment in - Button(action: { - if selectedEquipment.contains(equipment.name) { - selectedEquipment.remove(equipment.name) - } else { - selectedEquipment.insert(equipment.name) - } - }, label: { - if selectedEquipment.contains(equipment.name) { - Image(systemName: "checkmark") - } - Text(equipment.name) - }) - } - }, label: { - Image(systemName: "scalemass") - .padding(.trailing) - }) - } - - if let muscles = DataStore.shared.allMuscles { - Menu(content: { - ForEach(muscles, id: \.id) { muscle in - Button(action: { - if selectedMuscles.contains(muscle.name) { - selectedMuscles.remove(muscle.name) - } else { - selectedMuscles.insert(muscle.name) - } - }, label: { - if selectedMuscles.contains(muscle.name) { - Image(systemName: "checkmark") - } - Text(muscle.name) - }) - } - }, label: { - Image(systemName: "brain.head.profile") - .padding(.trailing) - }) - } - - Button(action: { - selectedMuscles.removeAll() - selectedEquipment.removeAll() - searchNameString = "" - filteredRegisterdUser = nil - }, label: { - Image(systemName: "xmark.circle") - .padding(.trailing) - }) + var body: some View { + HStack(spacing: WerkoutTheme.xs) { + Text(label) + .font(WerkoutTheme.caption) + .foregroundStyle(color) + + Button(action: onRemove) { + Image(systemName: "xmark") + .font(.system(size: 10, weight: .bold)) + .foregroundStyle(color.opacity(0.7)) } } - } - - func sortWorkouts(sortType: SortType) { - if currentSort == sortType { - filteredWorkouts = filteredWorkouts.reversed() - return - } - switch sortType { - case .name: - filteredWorkouts = filteredWorkouts.sorted(by: { - $0.name < $1.name - }) - case .createdDate: - filteredWorkouts = filteredWorkouts.sorted(by: { - $0.createdAt ?? Date() < $1.createdAt ?? Date() - }) - } - currentSort = sortType + .padding(.horizontal, WerkoutTheme.sm + 2) + .padding(.vertical, WerkoutTheme.xs + 2) + .background(color.opacity(0.12)) + .clipShape(Capsule()) } } - -#Preview { - FilterAllView(selectedMuscles: .constant([]), - selectedEquipment: .constant([]), - searchNameString: .constant(""), - uniqueWorkoutUsers: .constant(nil), - filteredRegisterdUser: .constant(nil), - filteredWorkouts: .constant(PreviewData.allWorkouts()), - workouts: .constant(PreviewData.allWorkouts()), - currentSort: .constant(nil)) -} diff --git a/iphone/Werkout_ios/subview/InfoView.swift b/iphone/Werkout_ios/subview/InfoView.swift index 10acfb8..1c8c5bc 100644 --- a/iphone/Werkout_ios/subview/InfoView.swift +++ b/iphone/Werkout_ios/subview/InfoView.swift @@ -10,28 +10,27 @@ import SwiftUI struct InfoView: View { @ObservedObject var bridgeModule = BridgeModule.shared var workout: Workout - + var body: some View { - VStack { + VStack(alignment: .leading, spacing: WerkoutTheme.sm) { Text(workout.name) - .frame(maxWidth: .infinity, alignment: .leading) - .font(.title3) - .padding() - + .font(WerkoutTheme.sectionTitle) + .foregroundStyle(WerkoutTheme.textPrimary) + if let desc = workout.description { Text(desc) - .frame(maxWidth: .infinity, alignment: .leading) - .font(.body) - .padding([.leading, .trailing]) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) } - + if let estimatedTime = workout.estimatedTime { Text(estimatedTime.asString(style: .abbreviated)) - .frame(maxWidth: .infinity, alignment: .leading) - .font(.body) - .padding([.leading, .trailing]) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.accent) } } + .padding() + .frame(maxWidth: .infinity, alignment: .leading) } } diff --git a/iphone/Werkout_ios/subview/Logoutview.swift b/iphone/Werkout_ios/subview/Logoutview.swift index 92473f0..3e5c80a 100644 --- a/iphone/Werkout_ios/subview/Logoutview.swift +++ b/iphone/Werkout_ios/subview/Logoutview.swift @@ -9,31 +9,37 @@ import SwiftUI struct Logoutview: View { @ObservedObject var userStore = UserStore.shared - + var body: some View { - HStack { - Button("Logout", action: { - userStore.logout() - }) - .frame(maxWidth: .infinity, alignment: .center) - .frame(height: 44) - .foregroundColor(.white) - .background(.red) - .cornerRadius(Constants.buttonRadius) - .padding() - .frame(maxWidth: .infinity) - - Button(action: { - userStore.refreshUserData() - }, label: { - Image(systemName: "arrow.triangle.2.circlepath") - }) - .frame(width: 44, height: 44) - .foregroundColor(.white) - .background(.green) - .cornerRadius(Constants.buttonRadius) - .padding() - .frame(maxWidth: .infinity) + GlassEffectContainer { + HStack { + Button("Logout", action: { + userStore.logout() + }) + .font(.system(size: 16, weight: .bold)) + .foregroundStyle(WerkoutTheme.textPrimary) + .frame(maxWidth: .infinity, alignment: .center) + .frame(height: 44) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.danger) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + .padding() + .frame(maxWidth: .infinity) + + Button(action: { + userStore.refreshUserData() + }, label: { + Image(systemName: "arrow.triangle.2.circlepath") + }) + .font(.title) + .foregroundStyle(WerkoutTheme.textPrimary) + .frame(width: 44, height: 44) + .glassEffect(.regular.interactive()) + .tint(WerkoutTheme.success) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + .padding() + .frame(maxWidth: .infinity) + } } } } diff --git a/iphone/Werkout_ios/subview/NameView.swift b/iphone/Werkout_ios/subview/NameView.swift index af56112..d15f28f 100644 --- a/iphone/Werkout_ios/subview/NameView.swift +++ b/iphone/Werkout_ios/subview/NameView.swift @@ -9,21 +9,26 @@ import SwiftUI struct NameView: View { @ObservedObject var userStore = UserStore.shared - + var body: some View { if let registeredUser = userStore.registeredUser { if let nickName = registeredUser.nickName { Text(nickName) - .font(.title) + .font(WerkoutTheme.heroTitle) + .foregroundStyle(WerkoutTheme.accent) } - + HStack { Text(registeredUser.firstName ?? "-") Text(registeredUser.lastName ?? "-") } - + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) + if let email = registeredUser.email { Text(email) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) } } } diff --git a/iphone/Werkout_ios/subview/OvalTextFieldStyle.swift b/iphone/Werkout_ios/subview/OvalTextFieldStyle.swift index ba7e208..610de93 100644 --- a/iphone/Werkout_ios/subview/OvalTextFieldStyle.swift +++ b/iphone/Werkout_ios/subview/OvalTextFieldStyle.swift @@ -10,9 +10,12 @@ import SwiftUI struct OvalTextFieldStyle: TextFieldStyle { func _body(configuration: TextField) -> some View { configuration - .padding(10) - .background(LinearGradient(gradient: Gradient(colors: [Color(uiColor: .secondarySystemBackground), Color(uiColor: .secondarySystemBackground)]), startPoint: .topLeading, endPoint: .bottomTrailing)) - .cornerRadius(20) - .shadow(color: Color(red: 120/255, green: 120/255, blue: 120/255, opacity: 1), radius: 5) + .padding(12) + .background(WerkoutTheme.surfaceCard) + .clipShape(RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous)) + .overlay( + RoundedRectangle(cornerRadius: WerkoutTheme.buttonRadius, style: .continuous) + .strokeBorder(WerkoutTheme.accent.opacity(0.3), lineWidth: 1) + ) } } diff --git a/iphone/Werkout_ios/subview/PlannedWorkoutView.swift b/iphone/Werkout_ios/subview/PlannedWorkoutView.swift index 1ced27d..f95ac93 100644 --- a/iphone/Werkout_ios/subview/PlannedWorkoutView.swift +++ b/iphone/Werkout_ios/subview/PlannedWorkoutView.swift @@ -10,46 +10,56 @@ import SwiftUI struct PlannedWorkoutView: View { let workouts: [PlannedWorkout] @Binding var selectedPlannedWorkout: Workout? - + + private var sortedWorkouts: [PlannedWorkout] { + workouts.sorted(by: { $0.onDate < $1.onDate }) + } + var body: some View { - List { - ForEach(workouts.sorted(by: { $0.onDate < $1.onDate }), id: \.id) { plannedWorkout in - Button(action: { - selectedPlannedWorkout = plannedWorkout.workout - }, label: { - HStack { - VStack(alignment: .leading) { - Text(plannedWorkout.onDate.plannedDate?.weekDay ?? "-") - .font(.title) - - Text(plannedWorkout.onDate.plannedDate?.monthString ?? "-") - .font(.title) - - Text(plannedWorkout.onDate.plannedDate?.dateString ?? "-") - .font(.title) + ScrollView { + LazyVStack(spacing: WerkoutTheme.sm) { + ForEach(sortedWorkouts, id: \.id) { plannedWorkout in + Button(action: { + selectedPlannedWorkout = plannedWorkout.workout + }, label: { + HStack(spacing: WerkoutTheme.md) { + VStack(spacing: WerkoutTheme.xs) { + Text(plannedWorkout.onDate.plannedDate?.weekDay ?? "-") + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.accent) + + Text(plannedWorkout.onDate.plannedDate?.dateString ?? "-") + .font(.system(size: 28, weight: .black, design: .monospaced)) + .foregroundStyle(WerkoutTheme.accent) + + Text(plannedWorkout.onDate.plannedDate?.monthString ?? "-") + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textSecondary) + } + .frame(width: 60) + + WerkoutTheme.divider.frame(width: 0.5) + + VStack(alignment: .leading, spacing: WerkoutTheme.xs) { + Text(plannedWorkout.workout.name) + .font(WerkoutTheme.cardTitle) + .foregroundStyle(WerkoutTheme.textPrimary) + + Text(plannedWorkout.workout.description ?? "") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) + } + .frame(maxWidth: .infinity, alignment: .leading) } - - Divider() - - VStack { - Text(plannedWorkout.workout.name) - .font(.title) - .frame(maxWidth: .infinity, alignment: .leading) - - Text(plannedWorkout.workout.description ?? "") - .font(.body) - .frame(maxWidth: .infinity, alignment: .leading) - } - } - }) - .buttonStyle(.plain) - .accessibilityLabel("Open planned workout \(plannedWorkout.workout.name)") - .accessibilityHint("Shows workout details") + .werkoutCard() + }) + .buttonStyle(.plain) + .accessibilityLabel("Open planned workout \(plannedWorkout.workout.name)") + .accessibilityHint("Shows workout details") + } } + .padding(.horizontal, WerkoutTheme.sm) } + .scrollEdgeEffectStyle(.soft, for: .top) } } - -//#Preview { -// PlannedWorkoutView() -//} diff --git a/iphone/Werkout_ios/subview/RateWorkoutView.swift b/iphone/Werkout_ios/subview/RateWorkoutView.swift index cccc1e5..edb1cb1 100644 --- a/iphone/Werkout_ios/subview/RateWorkoutView.swift +++ b/iphone/Werkout_ios/subview/RateWorkoutView.swift @@ -9,23 +9,28 @@ import SwiftUI struct RateWorkoutView: View { @Binding var difficulty: Float - + var body: some View { VStack { Divider() - + .overlay(WerkoutTheme.divider) + HStack { Text("No Rate") - .foregroundColor(.black) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textMuted) Text("Easy") - .foregroundColor(.green) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.success) Spacer() Text("Death") - .foregroundColor(.red) + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.danger) } - + ZStack { Slider(value: $difficulty, in: 0...5, step: 1) + .tint(WerkoutTheme.accent) } } } diff --git a/iphone/Werkout_ios/subview/ShowNextUpView.swift b/iphone/Werkout_ios/subview/ShowNextUpView.swift index 32d8465..8371e2f 100644 --- a/iphone/Werkout_ios/subview/ShowNextUpView.swift +++ b/iphone/Werkout_ios/subview/ShowNextUpView.swift @@ -13,7 +13,10 @@ struct ShowNextUpView: View { var body: some View { Toggle(isOn: $extShowNextVideo, label: { Text("Show next up video") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textPrimary) }) + .tint(WerkoutTheme.accent) } } diff --git a/iphone/Werkout_ios/subview/ThotPreferenceView.swift b/iphone/Werkout_ios/subview/ThotPreferenceView.swift index 0563bf9..1be61dc 100644 --- a/iphone/Werkout_ios/subview/ThotPreferenceView.swift +++ b/iphone/Werkout_ios/subview/ThotPreferenceView.swift @@ -12,11 +12,13 @@ struct ThotPreferenceView: View { @AppStorage(Constants.phoneThotStyle) private var phoneThotStyle: ThotStyle = .never @AppStorage(Constants.extThotStyle) private var extThotStyle: ThotStyle = .never @AppStorage(Constants.thotGenderOption) private var thotGenderOption: String = "female" - + var body: some View { if userStore.registeredUser?.NSFWValue ?? false { Group { Text("Phone THOT Style:") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) Picker("Phone THOT Style:", selection: $phoneThotStyle) { ForEach(ThotStyle.allCases, id: \.self) { style in Text(style.stringValue()) @@ -24,10 +26,14 @@ struct ThotPreferenceView: View { } } .pickerStyle(.segmented) - + .tint(WerkoutTheme.accent) + Divider() - + .overlay(WerkoutTheme.divider) + Text("External THOT Style:") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) Picker("External THOT Style:", selection: $extThotStyle) { ForEach(ThotStyle.allCases, id: \.self) { style in Text(style.stringValue()) @@ -35,10 +41,14 @@ struct ThotPreferenceView: View { } } .pickerStyle(.segmented) - + .tint(WerkoutTheme.accent) + if let genderOptions = DataStore.shared.nsfwGenderOptions { Divider() + .overlay(WerkoutTheme.divider) Text("Video Gender:") + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) Picker("Video Gender:", selection: $thotGenderOption) { ForEach(genderOptions, id: \.self) { option in Text(option.capitalized) @@ -46,6 +56,7 @@ struct ThotPreferenceView: View { } } .pickerStyle(.segmented) + .tint(WerkoutTheme.accent) } } } diff --git a/iphone/Werkout_ios/subview/TitleView.swift b/iphone/Werkout_ios/subview/TitleView.swift index 2baff1b..33a0c07 100644 --- a/iphone/Werkout_ios/subview/TitleView.swift +++ b/iphone/Werkout_ios/subview/TitleView.swift @@ -9,18 +9,20 @@ import SwiftUI struct TitleView: View { @ObservedObject var bridgeModule = BridgeModule.shared - + var body: some View { HStack { if let workout = bridgeModule.currentWorkoutInfo.workout { Text(workout.name) - .font(Font.system(size: 100)) + .font(.system(size: 100, weight: .black, design: .rounded)) + .foregroundColor(WerkoutTheme.textPrimary) .frame(maxWidth: .infinity, alignment: .leading) } - + if bridgeModule.currentWorkoutRunTimeInSeconds > -1 { Text("\(bridgeModule.currentWorkoutRunTimeInSeconds)") - .font(Font.system(size: 100)) + .font(WerkoutTheme.stat) + .foregroundColor(WerkoutTheme.accent) .frame(maxWidth: .infinity, alignment: .trailing) .padding(.trailing, 100) } diff --git a/iphone/Werkout_ios/subview/WorkoutInfoView.swift b/iphone/Werkout_ios/subview/WorkoutInfoView.swift index a16aef6..d091a3e 100644 --- a/iphone/Werkout_ios/subview/WorkoutInfoView.swift +++ b/iphone/Werkout_ios/subview/WorkoutInfoView.swift @@ -9,25 +9,20 @@ import SwiftUI struct WorkoutInfoView: View { let workout: Workout - + var body: some View { - VStack { + VStack(alignment: .leading, spacing: WerkoutTheme.sm) { Text(workout.name) - .frame(maxWidth: .infinity, alignment: .leading) - .font(.title3) - .padding(.top - ) + .font(WerkoutTheme.sectionTitle) + .foregroundStyle(WerkoutTheme.textPrimary) + if let desc = workout.description { Text(desc) - .frame(maxWidth: .infinity, alignment: .leading) - .font(.body) - .padding(.top) - + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) } } + .padding() + .frame(maxWidth: .infinity, alignment: .leading) } } - -//#Preview { -// WorkoutInfoView() -//} diff --git a/iphone/Werkout_ios/subview/WorkoutOverviewView.swift b/iphone/Werkout_ios/subview/WorkoutOverviewView.swift index a79ce2f..2d12d96 100644 --- a/iphone/Werkout_ios/subview/WorkoutOverviewView.swift +++ b/iphone/Werkout_ios/subview/WorkoutOverviewView.swift @@ -9,58 +9,47 @@ import SwiftUI struct WorkoutOverviewView: View { let workout: Workout + var body: some View { - VStack { - HStack { - VStack { - Text(workout.name) - .font(.title2) - .frame(maxWidth: .infinity, alignment: .leading) - - Text(workout.description ?? "") - .frame(maxWidth: .infinity, alignment: .leading) - - if let estimatedTime = workout.estimatedTime { - Text("Time: " + estimatedTime.asString(style: .abbreviated)) - .frame(maxWidth: .infinity, alignment: .leading) - } - - if let createdAt = workout.createdAt { - Text(createdAt, style: .date) - .font(.footnote) - .frame(maxWidth: .infinity, alignment: .leading) - } + VStack(alignment: .leading, spacing: WerkoutTheme.xs) { + Text(workout.name) + .font(WerkoutTheme.cardTitle) + .foregroundStyle(WerkoutTheme.textPrimary) + .lineLimit(1) + + if let description = workout.description, !description.isEmpty { + Text(description) + .font(WerkoutTheme.bodyText) + .foregroundStyle(WerkoutTheme.textSecondary) + .lineLimit(2) + } + + HStack(spacing: 12) { + if let estimatedTime = workout.estimatedTime { + Label(estimatedTime.asString(style: .abbreviated), systemImage: "clock") } + if let exerciseCount = workout.exercise_count { - VStack { - Text("\(exerciseCount)") - .font(.body.bold()) - Text("exercises") - .font(.footnote) - .foregroundColor(Color(uiColor: .systemGray2)) - } + Label("\(exerciseCount) exercises", systemImage: "list.bullet") + } + + if let muscles = workout.muscles, !muscles.isEmpty { + Label(muscleSummary(muscles), systemImage: "figure.strengthtraining.traditional") } } - - if let muscles = workout.muscles, - muscles.joined(separator: ", ").count > 0{ - Divider() - Text(muscles.joined(separator: ", ")) - .font(.footnote) - .frame(maxWidth: .infinity, alignment: .leading) - } - - if let equipment = workout.equipment, - equipment.joined(separator: ", ").count > 0 { - Divider() - Text(equipment.joined(separator: ", ")) - .font(.footnote) - .frame(maxWidth: .infinity, alignment: .leading) - } + .font(WerkoutTheme.caption) + .foregroundStyle(WerkoutTheme.textMuted) } - .padding() - .background(Color(uiColor: .secondarySystemBackground)) - .cornerRadius(2) + .frame(maxWidth: .infinity, alignment: .leading) + .werkoutCard() + } + + private func muscleSummary(_ muscles: [String]) -> String { + guard let first = muscles.first else { return "" } + if muscles.count <= 2 { + return muscles.joined(separator: ", ") + } + return "\(first), \(muscles[1]) +\(muscles.count - 2)" } } diff --git a/iphone/Werkout_watch Watch App/WatchMainViewModel.swift b/iphone/Werkout_watch Watch App/WatchMainViewModel.swift index 25e0c47..abb7c89 100644 --- a/iphone/Werkout_watch Watch App/WatchMainViewModel.swift +++ b/iphone/Werkout_watch Watch App/WatchMainViewModel.swift @@ -18,9 +18,9 @@ class WatchMainViewModel: NSObject, ObservableObject { var session: WCSession - @Published var watchPackageModel = WatchMainViewModel.defualtPackageModle + @Published var watchPackageModel = WatchMainViewModel.defaultPackageModel - static var defualtPackageModle: WatchPackageModel { + static var defaultPackageModel: WatchPackageModel { WatchPackageModel(currentExerciseName: "", currentExerciseID: -1, currentTimeLeft: -1, workoutStartDate: Date()) } @@ -66,7 +66,6 @@ class WatchMainViewModel: NSObject, ObservableObject { func pauseWorkout() { send(.pauseWorkout) WKInterfaceDevice.current().play(.start) - WatchWorkout.shared.togglePaused() } func dataToAction(messageData: Data) { @@ -81,10 +80,10 @@ class WatchMainViewModel: NSObject, ObservableObject { } self.watchPackageModel = newWatchPackageModel case .reset: - self.watchPackageModel = WatchMainViewModel.defualtPackageModle + self.watchPackageModel = WatchMainViewModel.defaultPackageModel WatchWorkout.shared.stopWorkout(sendDetails: false) case .endWorkout: - self.watchPackageModel = WatchMainViewModel.defualtPackageModle + self.watchPackageModel = WatchMainViewModel.defaultPackageModel WatchWorkout.shared.stopWorkout(sendDetails: true) case .startWorkout: WatchWorkout.shared.startWorkout()