WIP
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
1CF65A7D2A41275D0042FFBD /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A7C2A41275D0042FFBD /* Network.swift */; };
|
1CF65A7D2A41275D0042FFBD /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A7C2A41275D0042FFBD /* Network.swift */; };
|
||||||
1CF65A7F2A4129320042FFBD /* Fetchables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A7E2A4129320042FFBD /* Fetchables.swift */; };
|
1CF65A7F2A4129320042FFBD /* Fetchables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A7E2A4129320042FFBD /* Fetchables.swift */; };
|
||||||
1CF65A812A412AA30042FFBD /* DataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A802A412AA30042FFBD /* DataStore.swift */; };
|
1CF65A812A412AA30042FFBD /* DataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A802A412AA30042FFBD /* DataStore.swift */; };
|
||||||
|
1CF65A832A42347D0042FFBD /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF65A822A42347D0042FFBD /* Extensions.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@@ -77,6 +78,7 @@
|
|||||||
1CF65A7C2A41275D0042FFBD /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
|
1CF65A7C2A41275D0042FFBD /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
|
||||||
1CF65A7E2A4129320042FFBD /* Fetchables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fetchables.swift; sourceTree = "<group>"; };
|
1CF65A7E2A4129320042FFBD /* Fetchables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fetchables.swift; sourceTree = "<group>"; };
|
||||||
1CF65A802A412AA30042FFBD /* DataStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStore.swift; sourceTree = "<group>"; };
|
1CF65A802A412AA30042FFBD /* DataStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStore.swift; sourceTree = "<group>"; };
|
||||||
|
1CF65A822A42347D0042FFBD /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -112,6 +114,7 @@
|
|||||||
1CF65A552A3AA6800042FFBD /* Werkout-ios-Info.plist */,
|
1CF65A552A3AA6800042FFBD /* Werkout-ios-Info.plist */,
|
||||||
1CF65A482A39FB910042FFBD /* JSON */,
|
1CF65A482A39FB910042FFBD /* JSON */,
|
||||||
1CF65A252A3972840042FFBD /* Werkout_iosApp.swift */,
|
1CF65A252A3972840042FFBD /* Werkout_iosApp.swift */,
|
||||||
|
1CF65A822A42347D0042FFBD /* Extensions.swift */,
|
||||||
1CF65A272A3972840042FFBD /* Persistence.swift */,
|
1CF65A272A3972840042FFBD /* Persistence.swift */,
|
||||||
1CF65A4F2A3A1EA90042FFBD /* BridgeModule.swift */,
|
1CF65A4F2A3A1EA90042FFBD /* BridgeModule.swift */,
|
||||||
1CF65A3F2A3973840042FFBD /* Views */,
|
1CF65A3F2A3973840042FFBD /* Views */,
|
||||||
@@ -291,6 +294,7 @@
|
|||||||
1CF65A2D2A3972840042FFBD /* MainView.swift in Sources */,
|
1CF65A2D2A3972840042FFBD /* MainView.swift in Sources */,
|
||||||
1CF65A7D2A41275D0042FFBD /* Network.swift in Sources */,
|
1CF65A7D2A41275D0042FFBD /* Network.swift in Sources */,
|
||||||
1CF65A732A3F60D20042FFBD /* CreateExerciseActionsView.swift in Sources */,
|
1CF65A732A3F60D20042FFBD /* CreateExerciseActionsView.swift in Sources */,
|
||||||
|
1CF65A832A42347D0042FFBD /* Extensions.swift in Sources */,
|
||||||
1CF65A282A3972840042FFBD /* Persistence.swift in Sources */,
|
1CF65A282A3972840042FFBD /* Persistence.swift in Sources */,
|
||||||
1CF65A5B2A3BF4BE0042FFBD /* Equipment.swift in Sources */,
|
1CF65A5B2A3BF4BE0042FFBD /* Equipment.swift in Sources */,
|
||||||
1CF65A452A39FB550042FFBD /* Exercise.swift in Sources */,
|
1CF65A452A39FB550042FFBD /* Exercise.swift in Sources */,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ struct ExerciseElement: Codable {
|
|||||||
let weight: Int?
|
let weight: Int?
|
||||||
let reps: Int?
|
let reps: Int?
|
||||||
let duration: Int?
|
let duration: Int?
|
||||||
let durationAudio: String
|
let durationAudio: String?
|
||||||
let weightAudio: String?
|
let weightAudio: String?
|
||||||
let createdAt: String
|
let createdAt: String
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ struct ExerciseElement: Codable {
|
|||||||
let df = DateFormatter()
|
let df = DateFormatter()
|
||||||
df.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
|
df.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
|
||||||
df.locale = Locale(identifier: "en_US_POSIX")
|
df.locale = Locale(identifier: "en_US_POSIX")
|
||||||
return df.date(from: self.createdAt ?? "") ?? Date()
|
return df.date(from: self.createdAt) ?? Date()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ struct Workout: Codable {
|
|||||||
let name: String
|
let name: String
|
||||||
let description: String?
|
let description: String?
|
||||||
let exercises: [ExerciseElement]
|
let exercises: [ExerciseElement]
|
||||||
let registeredUser: RegisteredUser
|
let registeredUser: RegisteredUser?
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case name, description, exercises, id
|
case name, description, exercises, id
|
||||||
@@ -29,7 +29,7 @@ struct Workout: Codable {
|
|||||||
|
|
||||||
self.name = try container.decode(String.self, forKey: .name)
|
self.name = try container.decode(String.self, forKey: .name)
|
||||||
self.description = try container.decodeIfPresent(String.self, forKey: .description)
|
self.description = try container.decodeIfPresent(String.self, forKey: .description)
|
||||||
self.registeredUser = try container.decode(RegisteredUser.self, forKey: .registeredUser)
|
self.registeredUser = try container.decodeIfPresent(RegisteredUser.self, forKey: .registeredUser)
|
||||||
self.id = try container.decode(Int.self, forKey: .id)
|
self.id = try container.decode(Int.self, forKey: .id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class BridgeModule: ObservableObject {
|
|||||||
|
|
||||||
var timerCompleted: (() -> Void)?
|
var timerCompleted: (() -> Void)?
|
||||||
@Published var currentExercise: ExerciseElement?
|
@Published var currentExercise: ExerciseElement?
|
||||||
@Published var currentWorkout: Workout?
|
var currentWorkout: Workout?
|
||||||
@Published var currentExerciseIdx: Int = -1
|
@Published var currentExerciseIdx: Int = -1
|
||||||
|
|
||||||
private func startTimerWith(duration: Int) {
|
private func startTimerWith(duration: Int) {
|
||||||
|
|||||||
31
Werkout_ios/Extensions.swift
Normal file
31
Werkout_ios/Extensions.swift
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// Extensions.swift
|
||||||
|
// Werkout_ios
|
||||||
|
//
|
||||||
|
// Created by Trey Tartt on 6/20/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
extension Dictionary {
|
||||||
|
func percentEncoded() -> Data? {
|
||||||
|
map { key, value in
|
||||||
|
let escapedKey = "\(key)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? ""
|
||||||
|
let escapedValue = "\(value)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? ""
|
||||||
|
return escapedKey + "=" + escapedValue
|
||||||
|
}
|
||||||
|
.joined(separator: "&")
|
||||||
|
.data(using: .utf8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension CharacterSet {
|
||||||
|
static let urlQueryValueAllowed: CharacterSet = {
|
||||||
|
let generalDelimitersToEncode = ":#[]@" // does not include "?" or "/" due to RFC 3986 - Section 3.4
|
||||||
|
let subDelimitersToEncode = "!$&'()*+,;="
|
||||||
|
|
||||||
|
var allowed: CharacterSet = .urlQueryAllowed
|
||||||
|
allowed.remove(charactersIn: "\(generalDelimitersToEncode)\(subDelimitersToEncode)")
|
||||||
|
return allowed
|
||||||
|
}()
|
||||||
|
}
|
||||||
@@ -35,3 +35,14 @@ class AllExerciseFetchable: Fetchable {
|
|||||||
typealias Response = [ExerciseExercise]
|
typealias Response = [ExerciseExercise]
|
||||||
var endPoint: String = "exercise/all/"
|
var endPoint: String = "exercise/all/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CreateWorkoutFetchable: Postable {
|
||||||
|
var postableData: [String : Any]?
|
||||||
|
|
||||||
|
typealias Response = Workout
|
||||||
|
var endPoint: String = "workout/create/"
|
||||||
|
|
||||||
|
init(postData: [String: Any]) {
|
||||||
|
self.postableData = postData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ enum FetchableError: Error {
|
|||||||
case noData
|
case noData
|
||||||
case decodeError(Error)
|
case decodeError(Error)
|
||||||
case endOfFileError
|
case endOfFileError
|
||||||
|
case noPostData
|
||||||
|
case statusError(Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol Fetchable {
|
protocol Fetchable {
|
||||||
@@ -19,10 +21,13 @@ protocol Fetchable {
|
|||||||
|
|
||||||
var baseURL: String { get }
|
var baseURL: String { get }
|
||||||
var endPoint: String { get }
|
var endPoint: String { get }
|
||||||
|
|
||||||
func fetch(completion: @escaping (Result<Response, FetchableError>) -> Void)
|
func fetch(completion: @escaping (Result<Response, FetchableError>) -> Void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protocol Postable: Fetchable {
|
||||||
|
var postableData: [String: Any]? { get }
|
||||||
|
}
|
||||||
|
|
||||||
extension Fetchable {
|
extension Fetchable {
|
||||||
var baseURL: String {
|
var baseURL: String {
|
||||||
"http://127.0.0.1:8000/"
|
"http://127.0.0.1:8000/"
|
||||||
@@ -54,3 +59,53 @@ extension Fetchable {
|
|||||||
task.resume()
|
task.resume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Postable {
|
||||||
|
func fetch(completion: @escaping (Result<Response, FetchableError>) -> Void) {
|
||||||
|
guard let postableData = postableData else {
|
||||||
|
completion(.failure(.noPostData))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = URL(string: baseURL+endPoint)!
|
||||||
|
|
||||||
|
let postData = try! JSONSerialization.data(withJSONObject:postableData)
|
||||||
|
|
||||||
|
var request = URLRequest(url: url,timeoutInterval: Double.infinity)
|
||||||
|
request.addValue("Token fd59cbf6f5db98726e896cdb6b095ecb9c43a592", forHTTPHeaderField: "Authorization")
|
||||||
|
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
|
request.httpMethod = "POST"
|
||||||
|
request.httpBody = postData
|
||||||
|
|
||||||
|
let task = URLSession.shared.dataTask(with: request, completionHandler: { data, response, error in
|
||||||
|
if let error = error {
|
||||||
|
completion(.failure(.apiError(error)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if let httpRespone = response as? HTTPURLResponse {
|
||||||
|
if httpRespone.statusCode != 201 {
|
||||||
|
completion(.failure(.statusError(httpRespone.statusCode)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let data = data else {
|
||||||
|
completion(.failure(.noData))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
let model = try JSONDecoder().decode(Response.self, from: data)
|
||||||
|
completion(.success(model))
|
||||||
|
return
|
||||||
|
} catch {
|
||||||
|
completion(.failure(.decodeError(error)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
task.resume()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ struct AddExerciseView: View {
|
|||||||
|
|
||||||
@State var searchString: String = ""
|
@State var searchString: String = ""
|
||||||
|
|
||||||
@EnvironmentObject var bridgeModule: BridgeModule
|
@StateObject var bridgeModule = BridgeModule.shared
|
||||||
@Environment(\.dismiss) var dismiss
|
@Environment(\.dismiss) var dismiss
|
||||||
|
|
||||||
var selectedWorkout: ((ExerciseExercise) -> Void)
|
var selectedWorkout: ((ExerciseExercise) -> Void)
|
||||||
@@ -62,6 +62,8 @@ struct AddExerciseView: View {
|
|||||||
}.frame(height: 100)
|
}.frame(height: 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
if let equipment = DataStore.shared.allEquipment {
|
if let equipment = DataStore.shared.allEquipment {
|
||||||
Button("toggle all", action: {
|
Button("toggle all", action: {
|
||||||
if self.selectedEquipment.count > 0 {
|
if self.selectedEquipment.count > 0 {
|
||||||
@@ -100,12 +102,16 @@ struct AddExerciseView: View {
|
|||||||
}.frame(height: 100)
|
}.frame(height: 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
TextField("Filter", text: $searchString)
|
TextField("Filter", text: $searchString)
|
||||||
.onReceive(Just(searchString)) { location in
|
.onReceive(Just(searchString)) { location in
|
||||||
filterExercises()
|
filterExercises()
|
||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
List() {
|
List() {
|
||||||
ForEach(filteredExercises.indices, id: \.self) { i in
|
ForEach(filteredExercises.indices, id: \.self) { i in
|
||||||
let obj = filteredExercises[i]
|
let obj = filteredExercises[i]
|
||||||
@@ -142,6 +148,7 @@ struct AddExerciseView: View {
|
|||||||
selectedEquipment = equipment
|
selectedEquipment = equipment
|
||||||
filteredExercises = exercises
|
filteredExercises = exercises
|
||||||
}
|
}
|
||||||
|
.background(Color(uiColor: .tertiarySystemBackground))
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterExercises() {
|
func filterExercises() {
|
||||||
|
|||||||
@@ -10,15 +10,19 @@ import SwiftUI
|
|||||||
|
|
||||||
struct AllWorkoutsView: View {
|
struct AllWorkoutsView: View {
|
||||||
@State var workouts: [Workout]?
|
@State var workouts: [Workout]?
|
||||||
@EnvironmentObject var bridgeModule: BridgeModule
|
var bridgeModule = BridgeModule.shared
|
||||||
|
@State public var needsUpdating: Bool = true
|
||||||
|
|
||||||
@State private var showWorkoutDetail = false
|
@State private var showWorkoutDetail = false
|
||||||
@State private var selectedWorkout: Workout? {
|
@State private var selectedWorkout: Workout? {
|
||||||
didSet {
|
didSet {
|
||||||
|
bridgeModule.currentWorkout = selectedWorkout
|
||||||
showWorkoutDetail = true
|
showWorkoutDetail = true
|
||||||
bridgeModule.currentWorkout = self.selectedWorkout
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pub = NotificationCenter.default.publisher(for: NSNotification.Name("CreatedNewWorkout"))
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
if let workouts = workouts {
|
if let workouts = workouts {
|
||||||
@@ -33,7 +37,7 @@ struct AllWorkoutsView: View {
|
|||||||
}
|
}
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
selectedItem(workout: workout)
|
selectedWorkout = workout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,16 +45,19 @@ struct AllWorkoutsView: View {
|
|||||||
Text("no workouts")
|
Text("no workouts")
|
||||||
}
|
}
|
||||||
}.onAppear{
|
}.onAppear{
|
||||||
AllWorkoutFetchable().fetch(completion: { result in
|
if needsUpdating {
|
||||||
switch result {
|
AllWorkoutFetchable().fetch(completion: { result in
|
||||||
case .success(let model):
|
needsUpdating = false
|
||||||
DispatchQueue.main.async {
|
switch result {
|
||||||
self.workouts = model
|
case .success(let model):
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.workouts = model
|
||||||
|
}
|
||||||
|
case .failure(let failure):
|
||||||
|
fatalError("shit broke")
|
||||||
}
|
}
|
||||||
case .failure(let failure):
|
})
|
||||||
fatalError("shit broke")
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $showWorkoutDetail) {
|
.sheet(isPresented: $showWorkoutDetail) {
|
||||||
if let selectedWorkout = selectedWorkout {
|
if let selectedWorkout = selectedWorkout {
|
||||||
@@ -58,12 +65,11 @@ struct AllWorkoutsView: View {
|
|||||||
WorkoutDetailView(viewModel: viewModel)
|
WorkoutDetailView(viewModel: viewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onReceive(pub) { (output) in
|
||||||
|
self.needsUpdating = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectedItem(workout: Workout) {
|
|
||||||
selectedWorkout = workout
|
|
||||||
}
|
|
||||||
|
|
||||||
func testParse() {
|
func testParse() {
|
||||||
if let filepath = Bundle.main.path(forResource: "AllWorkouts", ofType: "json") {
|
if let filepath = Bundle.main.path(forResource: "AllWorkouts", ofType: "json") {
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -95,4 +95,29 @@ class WorkoutViewModel: ObservableObject {
|
|||||||
superSets.remove(at: idx)
|
superSets.remove(at: idx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func uploadWorkout() {
|
||||||
|
var exercises = [[String: Any]]()
|
||||||
|
superSets.forEach({ superset in
|
||||||
|
for _ in 0 ..< superset.numberOfRounds {
|
||||||
|
for exercise in superset.exercises {
|
||||||
|
let item = ["id": exercise.exercise.id, "reps": exercise.reps, "weight": exercise.weight, "duration": exercise.duration] as [String : Any]
|
||||||
|
exercises.append(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
let uploadBody = ["name": title, "description": "description", "exercise_data": exercises] as [String : Any]
|
||||||
|
CreateWorkoutFetchable(postData: uploadBody).fetch(completion: { result in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
switch result {
|
||||||
|
case .success(_):
|
||||||
|
self.superSets.removeAll()
|
||||||
|
self.title = ""
|
||||||
|
NotificationCenter.default.post(name: NSNotification.Name("CreatedNewWorkout"), object: nil, userInfo: nil)
|
||||||
|
case .failure(let failure):
|
||||||
|
print(failure)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ struct CreateWorkoutMainView: View {
|
|||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
Button("Done", action: {
|
Button("Done", action: {
|
||||||
|
viewModel.uploadWorkout()
|
||||||
})
|
})
|
||||||
.frame(maxWidth: .infinity, alignment: .center)
|
.frame(maxWidth: .infinity, alignment: .center)
|
||||||
.frame(height: 44)
|
.frame(height: 44)
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import SwiftUI
|
|||||||
import AVKit
|
import AVKit
|
||||||
|
|
||||||
struct ExternalWorkoutDetailView: View {
|
struct ExternalWorkoutDetailView: View {
|
||||||
@EnvironmentObject var bridgeModule: BridgeModule
|
@StateObject var bridgeModule = BridgeModule.shared
|
||||||
@State var player = AVPlayer()
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if let workout = bridgeModule.currentWorkout {
|
if let workout = bridgeModule.currentWorkout {
|
||||||
@@ -21,76 +20,88 @@ struct ExternalWorkoutDetailView: View {
|
|||||||
.frame(width: metrics.size.width, height: metrics.size.height * 0.1)
|
.frame(width: metrics.size.width, height: metrics.size.height * 0.1)
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
VideoPlayer(player: player)
|
if let currentExercise = bridgeModule.currentExercise {
|
||||||
.onChange(of: bridgeModule.currentExerciseIdx, perform: { newValue in
|
VideoPlayerView(currentExercise: currentExercise.exercise)
|
||||||
updateVideo()
|
.frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.7)
|
||||||
})
|
}
|
||||||
|
|
||||||
if let workout = bridgeModule.currentWorkout {
|
ExtExerciseList(workout: workout,
|
||||||
List() {
|
currentExerciseIdx: bridgeModule.currentExerciseIdx)
|
||||||
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
.frame(width: metrics.size.width * 0.4, height: metrics.size.height * 0.7)
|
||||||
let obj = workout.exercisesSortedByCreated_at[i]
|
|
||||||
HStack {
|
|
||||||
if let _ = bridgeModule.currentExercise {
|
|
||||||
if i == bridgeModule.currentExerciseIdx {
|
|
||||||
Image(systemName: "checkmark")
|
|
||||||
.font(Font.system(size: 75))
|
|
||||||
.foregroundColor(.green)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Text(obj.exercise.name ?? "")
|
|
||||||
.font(Font.system(size: 75))
|
|
||||||
.padding()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.frame(width: metrics.size.width * 0.4)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.frame(width: metrics.size.width, height: metrics.size.height * 0.7)
|
|
||||||
|
|
||||||
HStack {
|
ExtCountdownView()
|
||||||
if let currenExercise = bridgeModule.currentExercise {
|
.frame(width: metrics.size.width-50, height: metrics.size.height * 0.2)
|
||||||
VStack {
|
.padding([.leading, .trailing], 50)
|
||||||
Text(currenExercise.exercise.name ?? "")
|
|
||||||
.font(Font.system(size: 100))
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
|
||||||
|
|
||||||
HStack {
|
|
||||||
if let duration = currenExercise.duration {
|
|
||||||
ProgressView(value: Float(bridgeModule.timeLeft), total: Float(duration))
|
|
||||||
.scaleEffect(x: 1, y: 6, anchor: .center)
|
|
||||||
Text("\(bridgeModule.timeLeft)")
|
|
||||||
.font(Font.system(size: 75))
|
|
||||||
.padding(.leading)
|
|
||||||
} else if let reps = currenExercise.reps {
|
|
||||||
Text("\(reps)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding([.leading, .trailing], 50)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.frame(width: metrics.size.width, height: metrics.size.height * 0.2)
|
|
||||||
.padding([.leading, .trailing])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ExtExerciseList: View {
|
||||||
|
var workout: Workout
|
||||||
|
var currentExerciseIdx: Int
|
||||||
|
|
||||||
func updateVideo() {
|
var body: some View {
|
||||||
if let videoURL = bridgeModule.currentExercise?.exercise.videoURL {
|
List() {
|
||||||
// let completeURL = "http://127.0.0.1:8000" + videoURL
|
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||||
player = AVPlayer(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!)
|
let obj = workout.exercisesSortedByCreated_at[i]
|
||||||
player.play()
|
HStack {
|
||||||
// print(completeURL)
|
if i == currentExerciseIdx {
|
||||||
// player = AVPlayer(url: URL(string: completeURL)!)
|
Image(systemName: "checkmark")
|
||||||
// player.play()
|
.font(Font.system(size: 75))
|
||||||
|
.foregroundColor(.green)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(obj.exercise.name)
|
||||||
|
.font(Font.system(size: 75))
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ExtCountdownView: View {
|
||||||
|
@StateObject var bridgeModule = BridgeModule.shared
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
if let currenExercise = bridgeModule.currentExercise {
|
||||||
|
Text(currenExercise.exercise.name)
|
||||||
|
.font(Font.system(size: 100))
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
if let duration = currenExercise.duration {
|
||||||
|
ProgressView(value: Float(bridgeModule.timeLeft), total: Float(duration))
|
||||||
|
.scaleEffect(x: 1, y: 6, anchor: .center)
|
||||||
|
Text("\(bridgeModule.timeLeft)")
|
||||||
|
.font(Font.system(size: 75))
|
||||||
|
.padding(.leading)
|
||||||
|
} else if let reps = currenExercise.reps {
|
||||||
|
Text("\(reps)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct VideoPlayerView: View {
|
||||||
|
var currentExercise: ExerciseExercise
|
||||||
|
@State var player = AVPlayer()
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VideoPlayer(player: player)
|
||||||
|
.onAppear{
|
||||||
|
player = AVPlayer(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!)
|
||||||
|
player.play()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct ExternalWorkoutDetailView_Previews: PreviewProvider {
|
struct ExternalWorkoutDetailView_Previews: PreviewProvider {
|
||||||
static var bridge = BridgeModule.shared
|
static var bridge = BridgeModule.shared
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import CoreData
|
|||||||
|
|
||||||
struct MainView: View {
|
struct MainView: View {
|
||||||
@State var workout: Workout?
|
@State var workout: Workout?
|
||||||
@EnvironmentObject var bridgeModule: BridgeModule
|
@StateObject var bridgeModule = BridgeModule.shared
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
|
|||||||
@@ -8,11 +8,11 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct WorkoutDetailView: View {
|
struct WorkoutDetailView: View {
|
||||||
@ObservedObject var viewModel: WorkoutDetailViewModel
|
@StateObject var viewModel: WorkoutDetailViewModel
|
||||||
@EnvironmentObject var bridgeModule: BridgeModule
|
var bridgeModule = BridgeModule.shared
|
||||||
@Environment(\.dismiss) var dismiss
|
@Environment(\.dismiss) var dismiss
|
||||||
|
|
||||||
@State var selectedIdx = -1 {
|
@State var selectedIdx = 0 {
|
||||||
didSet {
|
didSet {
|
||||||
runItemAt(idx: selectedIdx)
|
runItemAt(idx: selectedIdx)
|
||||||
}
|
}
|
||||||
@@ -34,26 +34,16 @@ struct WorkoutDetailView: View {
|
|||||||
.background(.red)
|
.background(.red)
|
||||||
|
|
||||||
Button("ohhh lets do it", action: {
|
Button("ohhh lets do it", action: {
|
||||||
|
bridgeModule.currentWorkout = workout
|
||||||
runItemAt(idx: 0)
|
runItemAt(idx: 0)
|
||||||
})
|
})
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
.background(.green)
|
.background(.green)
|
||||||
}
|
}
|
||||||
.frame(height: 88)
|
.frame(height: 88)
|
||||||
List() {
|
|
||||||
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
ExerciseListView(workout: workout)
|
||||||
let obj = workout.exercisesSortedByCreated_at[i]
|
CountdownView()
|
||||||
Text(obj.exercise.name ?? "")
|
|
||||||
.onTapGesture { selectedIdx = i }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let duration = bridgeModule.currentExercise?.duration {
|
|
||||||
HStack {
|
|
||||||
ProgressView(value: Float(bridgeModule.timeLeft), total: Float(duration))
|
|
||||||
Text("\(bridgeModule.timeLeft)")
|
|
||||||
}.padding(16)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onAppear{
|
.onAppear{
|
||||||
bridgeModule.timerCompleted = {
|
bridgeModule.timerCompleted = {
|
||||||
@@ -63,9 +53,8 @@ struct WorkoutDetailView: View {
|
|||||||
.interactiveDismissDisabled()
|
.interactiveDismissDisabled()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runItemAt(idx: Int) {
|
func runItemAt(idx: Int) {
|
||||||
switch viewModel.status {
|
switch viewModel.status {
|
||||||
case .showWorkout(let workout):
|
case .showWorkout(let workout):
|
||||||
@@ -86,6 +75,36 @@ struct WorkoutDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ExerciseListView: View {
|
||||||
|
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||||
|
var workout: Workout
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
List() {
|
||||||
|
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||||
|
let obj = workout.exercisesSortedByCreated_at[i]
|
||||||
|
Text(obj.exercise.name)
|
||||||
|
// .onTapGesture { selectedIdx = i }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CountdownView: View {
|
||||||
|
@StateObject var bridgeModule = BridgeModule.shared
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
if let duration = bridgeModule.currentExercise?.duration {
|
||||||
|
HStack {
|
||||||
|
ProgressView(value: Float(bridgeModule.timeLeft), total: Float(duration))
|
||||||
|
Text("\(bridgeModule.timeLeft)")
|
||||||
|
}.padding(16)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct WorkoutDetailView_Previews: PreviewProvider {
|
struct WorkoutDetailView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
WorkoutDetailView(viewModel: WorkoutDetailViewModel(workout: PreviewWorkout.workout()))
|
WorkoutDetailView(viewModel: WorkoutDetailViewModel(workout: PreviewWorkout.workout()))
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ import Combine
|
|||||||
@main
|
@main
|
||||||
struct Werkout_iosApp: App {
|
struct Werkout_iosApp: App {
|
||||||
let persistenceController = PersistenceController.shared
|
let persistenceController = PersistenceController.shared
|
||||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
|
||||||
@State var additionalWindows: [UIWindow] = []
|
@State var additionalWindows: [UIWindow] = []
|
||||||
|
@State private var tabSelection = 1
|
||||||
|
|
||||||
|
let pub = NotificationCenter.default.publisher(for: NSNotification.Name("CreatedNewWorkout"))
|
||||||
|
|
||||||
private var screenDidConnectPublisher: AnyPublisher<UIScreen, Never> {
|
private var screenDidConnectPublisher: AnyPublisher<UIScreen, Never> {
|
||||||
NotificationCenter.default
|
NotificationCenter.default
|
||||||
@@ -32,9 +34,8 @@ struct Werkout_iosApp: App {
|
|||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
TabView {
|
TabView(selection: $tabSelection) {
|
||||||
AllWorkoutsView()
|
AllWorkoutsView()
|
||||||
.environmentObject(bridgeModule)
|
|
||||||
.onReceive(
|
.onReceive(
|
||||||
screenDidConnectPublisher,
|
screenDidConnectPublisher,
|
||||||
perform: screenDidConnect
|
perform: screenDidConnect
|
||||||
@@ -46,25 +47,32 @@ struct Werkout_iosApp: App {
|
|||||||
.tabItem {
|
.tabItem {
|
||||||
Label("All Workouts", systemImage: "figure.strengthtraining.traditional")
|
Label("All Workouts", systemImage: "figure.strengthtraining.traditional")
|
||||||
}
|
}
|
||||||
|
.tag(1)
|
||||||
|
|
||||||
CreateWorkoutMainView()
|
CreateWorkoutMainView()
|
||||||
.tabItem {
|
.tabItem {
|
||||||
Label("Create Workout", systemImage: "plus.app.fill")
|
Label("Create Workout", systemImage: "plus.app.fill")
|
||||||
}
|
}
|
||||||
|
.tag(2)
|
||||||
|
|
||||||
AccountView()
|
AccountView()
|
||||||
.tabItem {
|
.tabItem {
|
||||||
Label("Accounts", systemImage: "person.fill.turn.down")
|
Label("Accounts", systemImage: "person.fill.turn.down")
|
||||||
}
|
}
|
||||||
|
.tag(3)
|
||||||
}
|
}
|
||||||
.onAppear{
|
.onAppear{
|
||||||
DataStore.shared.fetchAllData()
|
DataStore.shared.fetchAllData()
|
||||||
}
|
}
|
||||||
|
.onReceive(pub) { (output) in
|
||||||
|
self.tabSelection = 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func screenDidDisconnect(_ screen: UIScreen) {
|
private func screenDidDisconnect(_ screen: UIScreen) {
|
||||||
additionalWindows.removeAll { $0.screen == screen }
|
additionalWindows.removeAll { $0.screen == screen }
|
||||||
bridgeModule.isShowingOnExternalDisplay = false
|
BridgeModule.shared.isShowingOnExternalDisplay = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private func screenDidConnect(_ screen: UIScreen) {
|
private func screenDidConnect(_ screen: UIScreen) {
|
||||||
@@ -75,11 +83,10 @@ struct Werkout_iosApp: App {
|
|||||||
as? UIWindowScene
|
as? UIWindowScene
|
||||||
|
|
||||||
let view = ExternalWorkoutDetailView()
|
let view = ExternalWorkoutDetailView()
|
||||||
.environmentObject(bridgeModule)
|
|
||||||
let controller = UIHostingController(rootView: view)
|
let controller = UIHostingController(rootView: view)
|
||||||
window.rootViewController = controller
|
window.rootViewController = controller
|
||||||
window.isHidden = false
|
window.isHidden = false
|
||||||
additionalWindows.append(window)
|
additionalWindows.append(window)
|
||||||
bridgeModule.isShowingOnExternalDisplay = true
|
BridgeModule.shared.isShowingOnExternalDisplay = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user