WIP
This commit is contained in:
@@ -72,6 +72,6 @@ struct ExerciseExercise: Codable, Hashable {
|
|||||||
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,50 @@ class BridgeModule: ObservableObject {
|
|||||||
private var timer: Timer?
|
private var timer: Timer?
|
||||||
@Published var timeLeft: Int = 0
|
@Published var timeLeft: Int = 0
|
||||||
|
|
||||||
var timerCompleted: (() -> Void)?
|
|
||||||
@Published var currentExercise: ExerciseElement?
|
@Published var currentExercise: ExerciseElement?
|
||||||
var currentWorkout: Workout?
|
var currentWorkout: Workout?
|
||||||
@Published var currentExerciseIdx: Int = -1
|
var currentExerciseIdx: Int = -1
|
||||||
|
|
||||||
|
@Published var currentWorkoutRunTimeInSeconds: Int = -1
|
||||||
|
private var currentWorkoutRunTimer: Timer?
|
||||||
|
|
||||||
|
func start(workout: Workout, atExerciseIndex: Int = 0) {
|
||||||
|
self.currentWorkout = workout
|
||||||
|
currentWorkoutRunTimeInSeconds = 0
|
||||||
|
currentWorkoutRunTimer?.invalidate()
|
||||||
|
currentWorkoutRunTimer = nil
|
||||||
|
|
||||||
|
currentExerciseIdx = 0
|
||||||
|
let exercise = workout.exercises[currentExerciseIdx]
|
||||||
|
updateCurrent(exercise: exercise)
|
||||||
|
startWorkoutTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func completeWorkout() {
|
||||||
|
currentWorkoutRunTimeInSeconds = 0
|
||||||
|
currentWorkoutRunTimer?.invalidate()
|
||||||
|
currentWorkoutRunTimer = nil
|
||||||
|
|
||||||
|
currentWorkoutRunTimer?.invalidate()
|
||||||
|
currentWorkoutRunTimer = nil
|
||||||
|
|
||||||
|
currentWorkoutRunTimeInSeconds = -1
|
||||||
|
currentExerciseIdx = -1
|
||||||
|
|
||||||
|
currentExercise = nil
|
||||||
|
currentWorkout = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func startWorkoutTimer() {
|
||||||
|
currentWorkoutRunTimer?.invalidate()
|
||||||
|
currentWorkoutRunTimer = nil
|
||||||
|
currentWorkoutRunTimer = Timer.scheduledTimer(timeInterval: 1,
|
||||||
|
target: self,
|
||||||
|
selector: #selector(addOneToWorkoutRunTime),
|
||||||
|
userInfo: nil,
|
||||||
|
repeats: true)
|
||||||
|
currentWorkoutRunTimer?.fire()
|
||||||
|
}
|
||||||
|
|
||||||
private func startTimerWith(duration: Int) {
|
private func startTimerWith(duration: Int) {
|
||||||
timer?.invalidate()
|
timer?.invalidate()
|
||||||
@@ -37,17 +77,24 @@ class BridgeModule: ObservableObject {
|
|||||||
} else {
|
} else {
|
||||||
timer?.invalidate()
|
timer?.invalidate()
|
||||||
timer = nil
|
timer = nil
|
||||||
timerCompleted?()
|
|
||||||
|
currentExerciseIdx += 1
|
||||||
|
if let currentWorkout = currentWorkout {
|
||||||
|
if currentExerciseIdx < currentWorkout.exercises.count {
|
||||||
|
let nextExercise = currentWorkout.exercises[currentExerciseIdx]
|
||||||
|
updateCurrent(exercise: nextExercise)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateCurrent(workout: Workout) {
|
@objc func addOneToWorkoutRunTime() {
|
||||||
self.currentWorkout = workout
|
currentWorkoutRunTimeInSeconds += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateCurrent(exercise: ExerciseElement) {
|
func updateCurrent(exercise: ExerciseElement) {
|
||||||
self.currentExercise = exercise
|
self.currentExercise = exercise
|
||||||
|
|
||||||
if let duration = exercise.duration {
|
if let duration = exercise.duration {
|
||||||
startTimerWith(duration: duration)
|
startTimerWith(duration: duration)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,28 +12,52 @@ struct ExternalWorkoutDetailView: View {
|
|||||||
@StateObject var bridgeModule = BridgeModule.shared
|
@StateObject var bridgeModule = BridgeModule.shared
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if let workout = bridgeModule.currentWorkout {
|
ZStack {
|
||||||
GeometryReader { metrics in
|
if let workout = bridgeModule.currentWorkout {
|
||||||
VStack {
|
GeometryReader { metrics in
|
||||||
Text(workout.name)
|
VStack {
|
||||||
.font(Font.system(size: 100))
|
HStack {
|
||||||
.frame(width: metrics.size.width, height: metrics.size.height * 0.1)
|
if let currentExercise = bridgeModule.currentExercise {
|
||||||
|
VideoPlayerView(currentExercise: currentExercise.exercise)
|
||||||
HStack {
|
.frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.8)
|
||||||
if let currentExercise = bridgeModule.currentExercise {
|
}
|
||||||
VideoPlayerView(currentExercise: currentExercise.exercise)
|
|
||||||
.frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.7)
|
ExtExerciseList(workout: workout,
|
||||||
|
currentExerciseIdx: bridgeModule.currentExerciseIdx)
|
||||||
|
.frame(width: metrics.size.width * 0.4, height: metrics.size.height * 0.8)
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtExerciseList(workout: workout,
|
ExtCountdownView()
|
||||||
currentExerciseIdx: bridgeModule.currentExerciseIdx)
|
.frame(width: metrics.size.width-50, height: metrics.size.height * 0.2)
|
||||||
.frame(width: metrics.size.width * 0.4, height: metrics.size.height * 0.7)
|
.padding([.leading, .trailing], 50)
|
||||||
|
.background(Color(uiColor: UIColor.secondarySystemBackground))
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtCountdownView()
|
|
||||||
.frame(width: metrics.size.width-50, height: metrics.size.height * 0.2)
|
|
||||||
.padding([.leading, .trailing], 50)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Text("nothing here bro")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
.background(.background)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TitleView: View {
|
||||||
|
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack {
|
||||||
|
if let workout = bridgeModule.currentWorkout {
|
||||||
|
Text(workout.name)
|
||||||
|
.font(Font.system(size: 100))
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
if bridgeModule.currentWorkoutRunTimeInSeconds > -1 {
|
||||||
|
Text("\(bridgeModule.currentWorkoutRunTimeInSeconds)")
|
||||||
|
.font(Font.system(size: 100))
|
||||||
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||||
|
.padding(.trailing, 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,19 +93,29 @@ struct ExtCountdownView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
if let currenExercise = bridgeModule.currentExercise {
|
if let currenExercise = bridgeModule.currentExercise {
|
||||||
Text(currenExercise.exercise.name)
|
HStack {
|
||||||
.font(Font.system(size: 100))
|
Text(currenExercise.exercise.name)
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.font(Font.system(size: 100))
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
|
||||||
|
if bridgeModule.currentWorkoutRunTimeInSeconds > -1 {
|
||||||
|
Text("\(bridgeModule.currentWorkoutRunTimeInSeconds)")
|
||||||
|
.font(Font.system(size: 100))
|
||||||
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||||
|
.padding(.trailing, 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
HStack {
|
HStack {
|
||||||
if let duration = currenExercise.duration {
|
if let duration = currenExercise.duration {
|
||||||
ProgressView(value: Float(bridgeModule.timeLeft), total: Float(duration))
|
ProgressView(value: Float(bridgeModule.timeLeft), total: Float(duration))
|
||||||
.scaleEffect(x: 1, y: 6, anchor: .center)
|
.scaleEffect(x: 1, y: 6, anchor: .center)
|
||||||
Text("\(bridgeModule.timeLeft)")
|
Text("\(bridgeModule.timeLeft)")
|
||||||
.font(Font.system(size: 75))
|
.font(Font.system(size: 75))
|
||||||
.padding(.leading)
|
.padding([.leading, .trailing])
|
||||||
} else if let reps = currenExercise.reps {
|
} else if let reps = currenExercise.reps {
|
||||||
Text("\(reps)")
|
Text("\(reps)")
|
||||||
|
.font(Font.system(size: 75))
|
||||||
|
.padding([.leading, .trailing])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,6 +132,11 @@ struct VideoPlayerView: View {
|
|||||||
.onAppear{
|
.onAppear{
|
||||||
player = AVPlayer(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!)
|
player = AVPlayer(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!)
|
||||||
player.play()
|
player.play()
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: nil, queue: .main) { _ in
|
||||||
|
player.seek(to: .zero)
|
||||||
|
player.play()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,6 @@ struct WorkoutDetailView: View {
|
|||||||
var bridgeModule = BridgeModule.shared
|
var bridgeModule = BridgeModule.shared
|
||||||
@Environment(\.dismiss) var dismiss
|
@Environment(\.dismiss) var dismiss
|
||||||
|
|
||||||
@State var selectedIdx = 0 {
|
|
||||||
didSet {
|
|
||||||
runItemAt(idx: selectedIdx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
switch viewModel.status {
|
switch viewModel.status {
|
||||||
@@ -25,53 +19,70 @@ struct WorkoutDetailView: View {
|
|||||||
Text("Loading")
|
Text("Loading")
|
||||||
case .showWorkout(let workout):
|
case .showWorkout(let workout):
|
||||||
VStack {
|
VStack {
|
||||||
HStack {
|
TopButtonsView(workout: workout)
|
||||||
Button("i dont want to do this", action: {
|
|
||||||
bridgeModule.currentWorkout = nil
|
|
||||||
dismiss()
|
|
||||||
})
|
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
.background(.red)
|
|
||||||
|
|
||||||
Button("ohhh lets do it", action: {
|
|
||||||
bridgeModule.currentWorkout = workout
|
|
||||||
runItemAt(idx: 0)
|
|
||||||
})
|
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
.background(.green)
|
|
||||||
}
|
|
||||||
.frame(height: 88)
|
.frame(height: 88)
|
||||||
|
|
||||||
|
CurrentWorkoutElapsedTimeView()
|
||||||
ExerciseListView(workout: workout)
|
ExerciseListView(workout: workout)
|
||||||
CountdownView()
|
CountdownView()
|
||||||
}
|
}
|
||||||
.onAppear{
|
|
||||||
bridgeModule.timerCompleted = {
|
|
||||||
selectedIdx += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.interactiveDismissDisabled()
|
.interactiveDismissDisabled()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func runItemAt(idx: Int) {
|
struct TopButtonsView: View {
|
||||||
switch viewModel.status {
|
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||||
case .showWorkout(let workout):
|
var workout: Workout
|
||||||
if idx < workout.exercises.count {
|
@Environment(\.dismiss) var dismiss
|
||||||
let exercise = workout.exercises[idx]
|
|
||||||
bridgeModule.updateCurrent(exercise: exercise)
|
var body: some View {
|
||||||
bridgeModule.currentExerciseIdx = idx
|
HStack {
|
||||||
|
if bridgeModule.currentWorkoutRunTimeInSeconds == -1 {
|
||||||
|
Button(action: {
|
||||||
|
bridgeModule.completeWorkout()
|
||||||
|
dismiss()
|
||||||
|
}, label: {
|
||||||
|
Image(systemName: "xmark.octagon.fill")
|
||||||
|
.font(.title)
|
||||||
|
})
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
.background(.red)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
|
||||||
|
Button(action: {
|
||||||
|
bridgeModule.start(workout: workout)
|
||||||
|
}, label: {
|
||||||
|
Image(systemName: "figure.golf")
|
||||||
|
.font(.title)
|
||||||
|
})
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
.background(.green)
|
||||||
|
.foregroundColor(.white)
|
||||||
} else {
|
} else {
|
||||||
workoutComplete()
|
Button(action: {
|
||||||
|
bridgeModule.completeWorkout()
|
||||||
|
dismiss()
|
||||||
|
}, label: {
|
||||||
|
Image(systemName: "checkmark")
|
||||||
|
.font(.title)
|
||||||
|
})
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
.background(.blue)
|
||||||
|
.foregroundColor(.white)
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
fatalError("no workout!!")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CurrentWorkoutElapsedTimeView: View {
|
||||||
|
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||||
|
|
||||||
private func workoutComplete() {
|
var body: some View {
|
||||||
|
if bridgeModule.currentWorkoutRunTimeInSeconds > -1 {
|
||||||
|
Text("\(bridgeModule.currentWorkoutRunTimeInSeconds)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +95,9 @@ struct ExerciseListView: View {
|
|||||||
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||||
let obj = workout.exercisesSortedByCreated_at[i]
|
let obj = workout.exercisesSortedByCreated_at[i]
|
||||||
Text(obj.exercise.name)
|
Text(obj.exercise.name)
|
||||||
// .onTapGesture { selectedIdx = i }
|
.onTapGesture {
|
||||||
|
bridgeModule.start(workout: workout, atExerciseIndex: i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ struct Werkout_iosApp: App {
|
|||||||
as? UIWindowScene
|
as? UIWindowScene
|
||||||
|
|
||||||
let view = ExternalWorkoutDetailView()
|
let view = ExternalWorkoutDetailView()
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
let controller = UIHostingController(rootView: view)
|
let controller = UIHostingController(rootView: view)
|
||||||
window.rootViewController = controller
|
window.rootViewController = controller
|
||||||
window.isHidden = false
|
window.isHidden = false
|
||||||
|
|||||||
Reference in New Issue
Block a user