Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d39dcb66f |
14
.claude/settings.local.json
Normal file
14
.claude/settings.local.json
Normal file
@@ -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:*)"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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]
|
||||
)
|
||||
|
||||
@@ -2,5 +2,6 @@ import Foundation
|
||||
|
||||
public enum AppNotifications {
|
||||
public static let createdNewWorkout = Notification.Name("CreatedNewWorkout")
|
||||
public static let userLoggedOut = Notification.Name("UserLoggedOut")
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 */;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
@@ -120,6 +124,10 @@ extension BridgeModule: WCSessionDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
func session(_ session: WCSession, didReceiveMessageData messageData: Data) {
|
||||
dataToAction(messageData: messageData)
|
||||
}
|
||||
|
||||
|
||||
func session(_ session: WCSession,
|
||||
activationDidCompleteWith activationState: WCSessionActivationState,
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<Data>(maxCount: 100)
|
||||
var lastSentInExercisePayload: Data?
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import SharedCore
|
||||
|
||||
class DataStore: ObservableObject {
|
||||
|
||||
@@ -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/"
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ struct AccountView: View {
|
||||
CompletedWorkoutsView()
|
||||
|
||||
Divider()
|
||||
.overlay(WerkoutTheme.divider)
|
||||
|
||||
ThotPreferenceView()
|
||||
|
||||
@@ -29,6 +30,7 @@ struct AccountView: View {
|
||||
Logoutview()
|
||||
}
|
||||
.padding()
|
||||
.background(WerkoutTheme.background)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,34 +19,40 @@ struct AddExerciseView: View {
|
||||
@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() {
|
||||
@@ -55,36 +61,16 @@ struct AddExerciseView: View {
|
||||
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
|
||||
}
|
||||
}
|
||||
let selectedMuscleIds = Set(selectedMuscles.map { $0.id })
|
||||
let selectedEquipmentIds = Set(selectedEquipment.map { $0.id })
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,88 +13,88 @@ enum SortType: String, CaseIterable {
|
||||
}
|
||||
|
||||
struct AllWorkoutsListView: View {
|
||||
@State var searchNameString: String = ""
|
||||
@State var selectedMuscles: Set<String> = []
|
||||
@State var selectedEquipment: Set<String> = []
|
||||
@Binding var uniqueWorkoutUsers: [RegisteredUser]?
|
||||
@State private var filteredRegisterdUser: RegisteredUser?
|
||||
|
||||
let workouts: [Workout]
|
||||
@Binding var searchText: String
|
||||
@Binding var selectedMuscles: Set<String>
|
||||
@Binding var selectedEquipment: Set<String>
|
||||
@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: {})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,22 +16,28 @@ enum MainViewTypes: Int, CaseIterable {
|
||||
|
||||
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
|
||||
@@ -51,50 +57,98 @@ struct AllWorkoutsView: View {
|
||||
|
||||
@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<String> = []
|
||||
@State private var selectedEquipment: Set<String> = []
|
||||
@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
|
||||
})
|
||||
private var hasActiveFilters: Bool {
|
||||
!selectedMuscles.isEmpty || !selectedEquipment.isEmpty || filteredRegisterdUser != nil
|
||||
}
|
||||
|
||||
switch selectedSegment {
|
||||
case .AllWorkout:
|
||||
if isUpdating {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
ZStack {
|
||||
WerkoutTheme.background.ignoresSafeArea()
|
||||
|
||||
if let workouts = workouts {
|
||||
VStack(spacing: 0) {
|
||||
// Active filter chips
|
||||
if hasActiveFilters {
|
||||
filterChipsRow
|
||||
}
|
||||
|
||||
AllWorkoutsListView(uniqueWorkoutUsers: $uniqueWorkoutUsers,
|
||||
workouts: workouts,
|
||||
selectedWorkout: { workout in
|
||||
selectedWorkout = workout
|
||||
}, refresh: {
|
||||
self.needsUpdating = true
|
||||
maybeRefreshData()
|
||||
})
|
||||
switch selectedSegment {
|
||||
case .AllWorkout:
|
||||
if isUpdating {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
.tint(WerkoutTheme.accent)
|
||||
}
|
||||
|
||||
Divider()
|
||||
case .MyWorkouts:
|
||||
PlannedWorkoutView(workouts: userStore.plannedWorkouts,
|
||||
selectedPlannedWorkout: $selectedPlannedWorkout)
|
||||
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,14 +168,162 @@ 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()
|
||||
}
|
||||
@@ -130,15 +332,7 @@ struct AllWorkoutsView: View {
|
||||
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
|
||||
}
|
||||
})
|
||||
@@ -176,6 +370,6 @@ struct AllWorkoutsView: View {
|
||||
|
||||
struct AllWorkoutsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AllWorkoutsView(workouts: PreviewData.allWorkouts())
|
||||
AllWorkoutsView()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ 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
|
||||
@@ -29,13 +29,19 @@ 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 {
|
||||
@@ -48,16 +54,25 @@ struct CompletedWorkoutView: View {
|
||||
.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()
|
||||
}
|
||||
|
||||
@@ -66,11 +81,13 @@ struct CompletedWorkoutView: View {
|
||||
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]) {
|
||||
|
||||
@@ -13,7 +13,7 @@ struct CreateExerciseActionsView: View {
|
||||
@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 {
|
||||
@@ -25,12 +25,15 @@ 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: {
|
||||
@@ -38,30 +41,37 @@ struct CreateExerciseActionsView: View {
|
||||
}, 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: {
|
||||
@@ -69,44 +79,47 @@ struct CreateExerciseActionsView: View {
|
||||
}, 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
|
||||
|
||||
@@ -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() {
|
||||
@@ -113,6 +117,31 @@ class WorkoutViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
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."
|
||||
}
|
||||
|
||||
@@ -15,16 +15,16 @@ struct CreateWorkoutItemPickerModel {
|
||||
|
||||
class CreateWorkoutItemPickerViewModel: Identifiable, ObservableObject {
|
||||
let allValues: [CreateWorkoutItemPickerModel]
|
||||
@Published var selectedIds: [Int]
|
||||
@Published var selectedIds: Set<Int>
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(WerkoutTheme.background)
|
||||
|
||||
TextField("Filter", text: $searchString)
|
||||
.padding()
|
||||
.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)
|
||||
|
||||
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()
|
||||
|
||||
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)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,18 +18,18 @@ struct CreateWorkoutMainView: View {
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -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<Bool>(
|
||||
get: { viewModel.validationError != nil },
|
||||
set: { _ in viewModel.validationError = nil }
|
||||
|
||||
@@ -14,30 +14,36 @@ struct CreateWorkoutSupersetActionsView: View {
|
||||
@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)
|
||||
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: {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -38,13 +38,13 @@ struct ExternalWorkoutDetailView: View {
|
||||
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)
|
||||
@@ -56,7 +56,7 @@ struct ExternalWorkoutDetailView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.background(Color(uiColor: .tertiarySystemGroupedBackground))
|
||||
.background(WerkoutTheme.surfaceCard)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -70,22 +70,13 @@ struct ExternalWorkoutDetailView: View {
|
||||
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()
|
||||
}
|
||||
@@ -94,14 +85,14 @@ struct ExternalWorkoutDetailView: View {
|
||||
}
|
||||
|
||||
}
|
||||
.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()
|
||||
|
||||
@@ -27,41 +27,51 @@ 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)
|
||||
@@ -73,11 +83,23 @@ struct LoginView: View {
|
||||
}
|
||||
.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: {
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -18,61 +18,72 @@ struct PlanWorkoutView: View {
|
||||
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()
|
||||
.overlay(WerkoutTheme.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")
|
||||
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)
|
||||
})
|
||||
.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")
|
||||
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: {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,21 +10,28 @@ 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)
|
||||
}
|
||||
}
|
||||
@@ -35,113 +42,106 @@ struct ExerciseListView: View {
|
||||
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")
|
||||
.accessibilityHint(isInWorkout ? "Jump to this exercise in the workout" : "Preview exercise video")
|
||||
|
||||
if bridgeModule.isInWorkout &&
|
||||
supersetIndex == bridgeModule.currentWorkoutInfo.supersetIndex &&
|
||||
exerciseIndex == bridgeModule.currentWorkoutInfo.exerciseIndex &&
|
||||
showExecersizeInfo {
|
||||
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{
|
||||
@@ -192,18 +192,32 @@ struct ExerciseListView: View {
|
||||
}
|
||||
|
||||
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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
@@ -23,44 +23,49 @@ struct WorkoutDetailView: View {
|
||||
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,35 +77,33 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,34 +113,49 @@ struct WorkoutDetailView: View {
|
||||
}
|
||||
|
||||
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))
|
||||
WerkoutTheme.divider.frame(height: 0.5)
|
||||
|
||||
ExerciseListView(workout: workout, showExecersizeInfo: $showExecersizeInfo)
|
||||
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()
|
||||
@@ -146,7 +164,7 @@ struct WorkoutDetailView: View {
|
||||
}, workout: workout, showAddToCalendar: viewModel.isPreview, startWorkoutAction: {
|
||||
startWorkout(workout: workout)
|
||||
})
|
||||
.frame(height: 44)
|
||||
.frame(height: 56)
|
||||
|
||||
}
|
||||
.sheet(item: $workoutComplete) { item in
|
||||
@@ -169,13 +187,14 @@ 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 = {
|
||||
|
||||
@@ -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)")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -76,8 +114,12 @@ struct WorkoutHistoryView: View {
|
||||
}
|
||||
|
||||
}
|
||||
.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)
|
||||
|
||||
127
iphone/Werkout_ios/WerkoutTheme.swift
Normal file
127
iphone/Werkout_ios/WerkoutTheme.swift
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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<UIScreen, Never> {
|
||||
private var screenDidConnectPublisher: AnyPublisher<UIWindowScene, Never> {
|
||||
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<UIScreen, Never> {
|
||||
private var screenDidDisconnectPublisher: AnyPublisher<UIWindowScene, Never> {
|
||||
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,32 +74,32 @@ 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)
|
||||
|
||||
@@ -19,90 +19,82 @@ struct ActionsView: View {
|
||||
@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) {
|
||||
@@ -118,7 +110,6 @@ struct ActionsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct ActionsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ActionsView(workout: PreviewData.workout(), showAddToCalendar: true, startWorkoutAction: {})
|
||||
|
||||
@@ -14,33 +14,37 @@ struct AddSupersetView: View {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
@@ -26,60 +27,66 @@ 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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,15 +12,15 @@ struct CaloriesBurnedView: View {
|
||||
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)
|
||||
}
|
||||
@@ -28,27 +28,29 @@ struct CaloriesBurnedView: View {
|
||||
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()
|
||||
//}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
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 {
|
||||
@@ -17,26 +17,41 @@ struct CompletedWorkoutsView: View {
|
||||
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)
|
||||
}
|
||||
@@ -44,14 +59,37 @@ struct CompletedWorkoutsView: View {
|
||||
} 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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,17 +19,18 @@ 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()
|
||||
|
||||
@@ -39,30 +40,37 @@ struct CreateWorkoutSupersetView: View {
|
||||
}, 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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ExtCountdownView: View {
|
||||
@StateObject var bridgeModule = BridgeModule.shared
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { metrics in
|
||||
@@ -16,7 +16,8 @@ struct ExtCountdownView: View {
|
||||
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)
|
||||
@@ -29,8 +30,10 @@ struct ExtCountdownView: View {
|
||||
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)
|
||||
@@ -41,7 +44,8 @@ struct ExtCountdownView: View {
|
||||
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)
|
||||
@@ -51,7 +55,8 @@ struct ExtCountdownView: View {
|
||||
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)
|
||||
|
||||
@@ -21,14 +21,15 @@ 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()
|
||||
@@ -38,31 +39,22 @@ struct ExtExerciseList: View {
|
||||
.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()
|
||||
}
|
||||
|
||||
@@ -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<String>
|
||||
@Binding var selectedEquipment: Set<String>
|
||||
@Binding var searchNameString: String
|
||||
@Binding var uniqueWorkoutUsers: [RegisteredUser]?
|
||||
@Binding var filteredRegisterdUser: RegisteredUser?
|
||||
@Binding var filteredWorkouts: [Workout]
|
||||
@Binding var workouts: [Workout]
|
||||
@Binding var currentSort: SortType?
|
||||
struct FilterChip: View {
|
||||
let label: String
|
||||
let color: Color
|
||||
let onRemove: () -> Void
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
TextField("Search by name" ,text: $searchNameString)
|
||||
.padding(.horizontal)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
HStack(spacing: WerkoutTheme.xs) {
|
||||
Text(label)
|
||||
.font(WerkoutTheme.caption)
|
||||
.foregroundStyle(color)
|
||||
|
||||
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)
|
||||
})
|
||||
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))
|
||||
}
|
||||
|
||||
@@ -12,26 +12,25 @@ struct InfoView: View {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,29 +11,35 @@ 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)
|
||||
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")
|
||||
})
|
||||
.frame(width: 44, height: 44)
|
||||
.foregroundColor(.white)
|
||||
.background(.green)
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,21 @@ struct NameView: 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,12 @@ import SwiftUI
|
||||
struct OvalTextFieldStyle: TextFieldStyle {
|
||||
func _body(configuration: TextField<Self._Label>) -> 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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,45 +11,55 @@ 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)
|
||||
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?.monthString ?? "-")
|
||||
.font(.title)
|
||||
Text(plannedWorkout.onDate.plannedDate?.dateString ?? "-")
|
||||
.font(.system(size: 28, weight: .black, design: .monospaced))
|
||||
.foregroundStyle(WerkoutTheme.accent)
|
||||
|
||||
Text(plannedWorkout.onDate.plannedDate?.dateString ?? "-")
|
||||
.font(.title)
|
||||
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()
|
||||
//}
|
||||
|
||||
@@ -13,19 +13,24 @@ struct RateWorkoutView: View {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ struct ThotPreferenceView: 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,15 @@ struct TitleView: 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)
|
||||
}
|
||||
|
||||
@@ -11,23 +11,18 @@ 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()
|
||||
//}
|
||||
|
||||
@@ -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)
|
||||
VStack(alignment: .leading, spacing: WerkoutTheme.xs) {
|
||||
Text(workout.name)
|
||||
.font(WerkoutTheme.cardTitle)
|
||||
.foregroundStyle(WerkoutTheme.textPrimary)
|
||||
.lineLimit(1)
|
||||
|
||||
Text(workout.description ?? "")
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
if let description = workout.description, !description.isEmpty {
|
||||
Text(description)
|
||||
.font(WerkoutTheme.bodyText)
|
||||
.foregroundStyle(WerkoutTheme.textSecondary)
|
||||
.lineLimit(2)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
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)"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user