WIP
This commit is contained in:
@@ -16,7 +16,7 @@ struct AddExerciseView: View {
|
||||
|
||||
@State var searchString: String = ""
|
||||
|
||||
@EnvironmentObject var bridgeModule: BridgeModule
|
||||
@StateObject var bridgeModule = BridgeModule.shared
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
var selectedWorkout: ((ExerciseExercise) -> Void)
|
||||
@@ -62,6 +62,8 @@ struct AddExerciseView: View {
|
||||
}.frame(height: 100)
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
if let equipment = DataStore.shared.allEquipment {
|
||||
Button("toggle all", action: {
|
||||
if self.selectedEquipment.count > 0 {
|
||||
@@ -100,12 +102,16 @@ struct AddExerciseView: View {
|
||||
}.frame(height: 100)
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
TextField("Filter", text: $searchString)
|
||||
.onReceive(Just(searchString)) { location in
|
||||
filterExercises()
|
||||
}
|
||||
.padding()
|
||||
|
||||
Divider()
|
||||
|
||||
List() {
|
||||
ForEach(filteredExercises.indices, id: \.self) { i in
|
||||
let obj = filteredExercises[i]
|
||||
@@ -142,6 +148,7 @@ struct AddExerciseView: View {
|
||||
selectedEquipment = equipment
|
||||
filteredExercises = exercises
|
||||
}
|
||||
.background(Color(uiColor: .tertiarySystemBackground))
|
||||
}
|
||||
|
||||
func filterExercises() {
|
||||
|
||||
@@ -10,15 +10,19 @@ import SwiftUI
|
||||
|
||||
struct AllWorkoutsView: View {
|
||||
@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 selectedWorkout: Workout? {
|
||||
didSet {
|
||||
bridgeModule.currentWorkout = selectedWorkout
|
||||
showWorkoutDetail = true
|
||||
bridgeModule.currentWorkout = self.selectedWorkout
|
||||
}
|
||||
}
|
||||
|
||||
let pub = NotificationCenter.default.publisher(for: NSNotification.Name("CreatedNewWorkout"))
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if let workouts = workouts {
|
||||
@@ -33,7 +37,7 @@ struct AllWorkoutsView: View {
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
selectedItem(workout: workout)
|
||||
selectedWorkout = workout
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,16 +45,19 @@ struct AllWorkoutsView: View {
|
||||
Text("no workouts")
|
||||
}
|
||||
}.onAppear{
|
||||
AllWorkoutFetchable().fetch(completion: { result in
|
||||
switch result {
|
||||
case .success(let model):
|
||||
DispatchQueue.main.async {
|
||||
self.workouts = model
|
||||
if needsUpdating {
|
||||
AllWorkoutFetchable().fetch(completion: { result in
|
||||
needsUpdating = false
|
||||
switch result {
|
||||
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) {
|
||||
if let selectedWorkout = selectedWorkout {
|
||||
@@ -58,12 +65,11 @@ struct AllWorkoutsView: View {
|
||||
WorkoutDetailView(viewModel: viewModel)
|
||||
}
|
||||
}
|
||||
.onReceive(pub) { (output) in
|
||||
self.needsUpdating = true
|
||||
}
|
||||
}
|
||||
|
||||
func selectedItem(workout: Workout) {
|
||||
selectedWorkout = workout
|
||||
}
|
||||
|
||||
|
||||
func testParse() {
|
||||
if let filepath = Bundle.main.path(forResource: "AllWorkouts", ofType: "json") {
|
||||
do {
|
||||
|
||||
@@ -95,4 +95,29 @@ class WorkoutViewModel: ObservableObject {
|
||||
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()
|
||||
|
||||
Button("Done", action: {
|
||||
|
||||
viewModel.uploadWorkout()
|
||||
})
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.frame(height: 44)
|
||||
|
||||
@@ -9,8 +9,7 @@ import SwiftUI
|
||||
import AVKit
|
||||
|
||||
struct ExternalWorkoutDetailView: View {
|
||||
@EnvironmentObject var bridgeModule: BridgeModule
|
||||
@State var player = AVPlayer()
|
||||
@StateObject var bridgeModule = BridgeModule.shared
|
||||
|
||||
var body: some View {
|
||||
if let workout = bridgeModule.currentWorkout {
|
||||
@@ -21,76 +20,88 @@ struct ExternalWorkoutDetailView: View {
|
||||
.frame(width: metrics.size.width, height: metrics.size.height * 0.1)
|
||||
|
||||
HStack {
|
||||
VideoPlayer(player: player)
|
||||
.onChange(of: bridgeModule.currentExerciseIdx, perform: { newValue in
|
||||
updateVideo()
|
||||
})
|
||||
if let currentExercise = bridgeModule.currentExercise {
|
||||
VideoPlayerView(currentExercise: currentExercise.exercise)
|
||||
.frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.7)
|
||||
}
|
||||
|
||||
if let workout = bridgeModule.currentWorkout {
|
||||
List() {
|
||||
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||
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)
|
||||
}
|
||||
ExtExerciseList(workout: workout,
|
||||
currentExerciseIdx: bridgeModule.currentExerciseIdx)
|
||||
.frame(width: metrics.size.width * 0.4, height: metrics.size.height * 0.7)
|
||||
}
|
||||
.frame(width: metrics.size.width, height: metrics.size.height * 0.7)
|
||||
|
||||
HStack {
|
||||
if let currenExercise = bridgeModule.currentExercise {
|
||||
VStack {
|
||||
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])
|
||||
ExtCountdownView()
|
||||
.frame(width: metrics.size.width-50, height: metrics.size.height * 0.2)
|
||||
.padding([.leading, .trailing], 50)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ExtExerciseList: View {
|
||||
var workout: Workout
|
||||
var currentExerciseIdx: Int
|
||||
|
||||
func updateVideo() {
|
||||
if let videoURL = bridgeModule.currentExercise?.exercise.videoURL {
|
||||
// let completeURL = "http://127.0.0.1:8000" + videoURL
|
||||
player = AVPlayer(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!)
|
||||
player.play()
|
||||
// print(completeURL)
|
||||
// player = AVPlayer(url: URL(string: completeURL)!)
|
||||
// player.play()
|
||||
var body: some View {
|
||||
List() {
|
||||
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||
let obj = workout.exercisesSortedByCreated_at[i]
|
||||
HStack {
|
||||
if i == currentExerciseIdx {
|
||||
Image(systemName: "checkmark")
|
||||
.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 {
|
||||
static var bridge = BridgeModule.shared
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import CoreData
|
||||
|
||||
struct MainView: View {
|
||||
@State var workout: Workout?
|
||||
@EnvironmentObject var bridgeModule: BridgeModule
|
||||
@StateObject var bridgeModule = BridgeModule.shared
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
import SwiftUI
|
||||
|
||||
struct WorkoutDetailView: View {
|
||||
@ObservedObject var viewModel: WorkoutDetailViewModel
|
||||
@EnvironmentObject var bridgeModule: BridgeModule
|
||||
@StateObject var viewModel: WorkoutDetailViewModel
|
||||
var bridgeModule = BridgeModule.shared
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
@State var selectedIdx = -1 {
|
||||
@State var selectedIdx = 0 {
|
||||
didSet {
|
||||
runItemAt(idx: selectedIdx)
|
||||
}
|
||||
@@ -34,26 +34,16 @@ struct WorkoutDetailView: View {
|
||||
.background(.red)
|
||||
|
||||
Button("ohhh lets do it", action: {
|
||||
bridgeModule.currentWorkout = workout
|
||||
runItemAt(idx: 0)
|
||||
})
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(.green)
|
||||
}
|
||||
.frame(height: 88)
|
||||
List() {
|
||||
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||
let obj = workout.exercisesSortedByCreated_at[i]
|
||||
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)
|
||||
}
|
||||
|
||||
ExerciseListView(workout: workout)
|
||||
CountdownView()
|
||||
}
|
||||
.onAppear{
|
||||
bridgeModule.timerCompleted = {
|
||||
@@ -63,9 +53,8 @@ struct WorkoutDetailView: View {
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func runItemAt(idx: Int) {
|
||||
switch viewModel.status {
|
||||
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 {
|
||||
static var previews: some View {
|
||||
WorkoutDetailView(viewModel: WorkoutDetailViewModel(workout: PreviewWorkout.workout()))
|
||||
|
||||
Reference in New Issue
Block a user