add excersise subviews
This commit is contained in:
56
Werkout_ios/subview/AllEquipmentView.swift
Normal file
56
Werkout_ios/subview/AllEquipmentView.swift
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// AllEquipmentview.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/16/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AllEquipmentView: View {
|
||||
@Binding var selectedEquipment: [Equipment]
|
||||
@State var createWorkoutItemPickerViewModel: CreateWorkoutItemPickerViewModel?
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if let _ = DataStore.shared.allEquipment {
|
||||
Text("Select Equipment")
|
||||
.foregroundColor(.cyan)
|
||||
Text("\(selectedEquipment.count) Selected")
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
if let equipment = DataStore.shared.allEquipment {
|
||||
var createWorkoutItemPickerModels = [CreateWorkoutItemPickerModel]()
|
||||
equipment.forEach({
|
||||
let model = CreateWorkoutItemPickerModel(id: $0.id,
|
||||
name: $0.name.lowercased())
|
||||
createWorkoutItemPickerModels.append(model)
|
||||
})
|
||||
createWorkoutItemPickerModels = createWorkoutItemPickerModels.sorted(by: {
|
||||
$0.name < $1.name
|
||||
})
|
||||
let selectedIds = selectedEquipment.map { $0.id }
|
||||
createWorkoutItemPickerViewModel = CreateWorkoutItemPickerViewModel(allValues: createWorkoutItemPickerModels, selectedIds: selectedIds)
|
||||
}
|
||||
}
|
||||
.sheet(item: $createWorkoutItemPickerViewModel) { item in
|
||||
CreateWorkoutItemPickerView(viewModel: item, completed: { selectedids in
|
||||
if let equipment = DataStore.shared.allEquipment {
|
||||
selectedEquipment.removeAll()
|
||||
for id in selectedids {
|
||||
if let equipment = equipment.first(where: {
|
||||
$0.id == id
|
||||
}) {
|
||||
selectedEquipment.append(equipment)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#Preview {
|
||||
// AllEquipmentview()
|
||||
//}
|
||||
92
Werkout_ios/subview/AllExerciseView.swift
Normal file
92
Werkout_ios/subview/AllExerciseView.swift
Normal file
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// AllExerciseView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/16/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AVKit
|
||||
|
||||
struct AllExerciseView: View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@State var searchString: String = ""
|
||||
@Binding var filteredExercises: [Exercise]
|
||||
var selectedExercise: ((Exercise) -> Void)
|
||||
|
||||
@State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4")!)
|
||||
@State var videoExercise: Exercise? {
|
||||
didSet {
|
||||
if let viddd = self.videoExercise?.videoURL,
|
||||
let url = URL(string: BaseURLs.currentBaseURL + viddd) {
|
||||
self.avPlayer = AVPlayer(url: url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
TextField("Filter", text: $searchString)
|
||||
.padding()
|
||||
|
||||
List() {
|
||||
ForEach(filteredExercises, id: \.self) { exercise in
|
||||
if searchString.isEmpty || (exercise.name.lowercased().contains(searchString.lowercased()) || (exercise.muscleGroups ?? "").lowercased().contains(searchString.lowercased())) {
|
||||
HStack {
|
||||
VStack {
|
||||
Text(exercise.name)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
if exercise.side != nil && !exercise.side!.isEmpty {
|
||||
Text(exercise.side!)
|
||||
.font(.footnote)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
if exercise.equipmentRequired != nil && !exercise.equipmentRequired!.isEmpty {
|
||||
Text(exercise.spacedEquipmentRequired)
|
||||
.font(.footnote)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
if exercise.muscleGroups != nil && !exercise.muscleGroups!.isEmpty {
|
||||
Text(exercise.spacedMuscleGroups)
|
||||
.font(.footnote)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
selectedExercise(exercise)
|
||||
dismiss()
|
||||
}
|
||||
Button(action: {
|
||||
videoExercise = exercise
|
||||
}) {
|
||||
ZStack {
|
||||
Circle()
|
||||
.fill(.blue)
|
||||
.frame(width: 33, height: 33)
|
||||
Image(systemName: "video.fill")
|
||||
.frame(width: 33, height: 33)
|
||||
.foregroundColor(.white )
|
||||
}
|
||||
}
|
||||
.frame(width: 33, height: 33)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $videoExercise) { exercise in
|
||||
PlayerView(player: $avPlayer)
|
||||
.onAppear{
|
||||
avPlayer.play()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//#Preview {
|
||||
// AllExerciseView()
|
||||
//}
|
||||
66
Werkout_ios/subview/AllMusclesView.swift
Normal file
66
Werkout_ios/subview/AllMusclesView.swift
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// AllMusclesView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/16/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AllMusclesView: View {
|
||||
@Binding var selectedMuscles: [Muscle]
|
||||
@State var createWorkoutItemPickerViewModel: CreateWorkoutItemPickerViewModel?
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if let _ = DataStore.shared.allMuscles {
|
||||
Text("Select Muscles")
|
||||
.foregroundColor(.cyan)
|
||||
Text("\(selectedMuscles.count) Selected")
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
if let muscles = DataStore.shared.allMuscles {
|
||||
var createWorkoutItemPickerModels = [CreateWorkoutItemPickerModel]()
|
||||
muscles.forEach({
|
||||
let model = CreateWorkoutItemPickerModel(id: $0.id, name: $0.name.lowercased())
|
||||
createWorkoutItemPickerModels.append(model)
|
||||
})
|
||||
createWorkoutItemPickerModels = createWorkoutItemPickerModels.sorted(by: {
|
||||
$0.name < $1.name
|
||||
})
|
||||
let selectedIds = selectedMuscles.map { $0.id }
|
||||
createWorkoutItemPickerViewModel = CreateWorkoutItemPickerViewModel(allValues: createWorkoutItemPickerModels, selectedIds: selectedIds)
|
||||
}
|
||||
}
|
||||
.onAppear{
|
||||
if #function.hasPrefix("__preview") {
|
||||
DataStore.shared.setupFakeData()
|
||||
}
|
||||
guard let _ = DataStore.shared.allExercise,
|
||||
let muscles = DataStore.shared.allMuscles,
|
||||
let _ = DataStore.shared.allEquipment else {
|
||||
return
|
||||
}
|
||||
selectedMuscles = muscles
|
||||
}
|
||||
.sheet(item: $createWorkoutItemPickerViewModel) { item in
|
||||
CreateWorkoutItemPickerView(viewModel: item, completed: { selectedids in
|
||||
if let muscles = DataStore.shared.allMuscles {
|
||||
selectedMuscles.removeAll()
|
||||
for id in selectedids {
|
||||
if let muscle = muscles.first(where: {
|
||||
$0.id == id
|
||||
}) {
|
||||
selectedMuscles.append(muscle)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#Preview {
|
||||
// AllMusclesView()
|
||||
//}
|
||||
Reference in New Issue
Block a user