WIP
This commit is contained in:
@@ -114,7 +114,7 @@ class BridgeModule: NSObject, ObservableObject {
|
|||||||
currentWorkoutRunTimer?.fire()
|
currentWorkoutRunTimer?.fire()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func startTimerWith(duration: Int) {
|
private func startExerciseTimerWith(duration: Int) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.currentExerciseTimer?.invalidate()
|
self.currentExerciseTimer?.invalidate()
|
||||||
self.currentExerciseTimer = nil
|
self.currentExerciseTimer = nil
|
||||||
@@ -148,6 +148,15 @@ class BridgeModule: NSObject, ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pauseWorkout() {
|
||||||
|
if let _ = currentExerciseTimer {
|
||||||
|
currentExerciseTimer?.invalidate()
|
||||||
|
currentExerciseTimer = nil
|
||||||
|
} else {
|
||||||
|
startExerciseTimerWith(duration: currentExerciseTimeLeft)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func nextExercise() {
|
func nextExercise() {
|
||||||
currentExerciseIdx += 1
|
currentExerciseIdx += 1
|
||||||
if let currentWorkout = currentWorkout {
|
if let currentWorkout = currentWorkout {
|
||||||
@@ -166,10 +175,15 @@ class BridgeModule: NSObject, ObservableObject {
|
|||||||
|
|
||||||
func updateCurrent(exercise: ExerciseElement) {
|
func updateCurrent(exercise: ExerciseElement) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
self.currentExerciseTimer?.invalidate()
|
||||||
|
self.currentExerciseTimer = nil
|
||||||
|
|
||||||
self.currentExercise = exercise
|
self.currentExercise = exercise
|
||||||
|
|
||||||
if let duration = exercise.duration {
|
if let duration = exercise.duration,
|
||||||
self.startTimerWith(duration: duration)
|
duration > 0 {
|
||||||
|
print(duration)
|
||||||
|
self.startExerciseTimerWith(duration: duration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import UIKit
|
||||||
|
|
||||||
extension Dictionary {
|
extension Dictionary {
|
||||||
func percentEncoded() -> Data? {
|
func percentEncoded() -> Data? {
|
||||||
@@ -91,3 +92,15 @@ extension Date {
|
|||||||
return weekDay
|
return weekDay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Bundle {
|
||||||
|
public var icon: UIImage? {
|
||||||
|
if let icons = infoDictionary?["CFBundleIcons"] as? [String: Any],
|
||||||
|
let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String: Any],
|
||||||
|
let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String],
|
||||||
|
let lastIcon = iconFiles.last {
|
||||||
|
return UIImage(named: lastIcon)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ struct AllWorkoutsView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@State var isUpdating = false
|
||||||
@State var workouts: [Workout]?
|
@State var workouts: [Workout]?
|
||||||
var bridgeModule = BridgeModule.shared
|
var bridgeModule = BridgeModule.shared
|
||||||
@State public var needsUpdating: Bool = true
|
@State public var needsUpdating: Bool = true
|
||||||
@@ -52,10 +52,6 @@ struct AllWorkoutsView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
if let workouts = workouts {
|
if let workouts = workouts {
|
||||||
if dataStore.status == .loading {
|
|
||||||
ProgressView()
|
|
||||||
.progressViewStyle(.circular)
|
|
||||||
} else {
|
|
||||||
VStack {
|
VStack {
|
||||||
Picker("", selection: $selectedSegment) {
|
Picker("", selection: $selectedSegment) {
|
||||||
ForEach(MainViews.allCases, id: \.self) { viewType in
|
ForEach(MainViews.allCases, id: \.self) { viewType in
|
||||||
@@ -67,15 +63,23 @@ struct AllWorkoutsView: View {
|
|||||||
|
|
||||||
switch selectedSegment {
|
switch selectedSegment {
|
||||||
case .AllWorkout:
|
case .AllWorkout:
|
||||||
|
|
||||||
|
if isUpdating {
|
||||||
|
ProgressView()
|
||||||
|
.progressViewStyle(.circular)
|
||||||
|
}
|
||||||
|
|
||||||
AllWorkoutsListView(workouts: workouts, selectedWorkout: { workout in
|
AllWorkoutsListView(workouts: workouts, selectedWorkout: { workout in
|
||||||
selectedWorkout = workout
|
selectedWorkout = workout
|
||||||
|
}, refresh: {
|
||||||
|
self.needsUpdating = true
|
||||||
|
maybeUpdateShit()
|
||||||
})
|
})
|
||||||
Divider()
|
Divider()
|
||||||
case .MyWorkouts:
|
case .MyWorkouts:
|
||||||
plannedWorkout(workouts: UserStore.shared.plannedWorkouts)
|
plannedWorkout(workouts: UserStore.shared.plannedWorkouts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ProgressView()
|
ProgressView()
|
||||||
.progressViewStyle(.circular)
|
.progressViewStyle(.circular)
|
||||||
@@ -150,6 +154,7 @@ struct AllWorkoutsView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if needsUpdating {
|
if needsUpdating {
|
||||||
|
self.isUpdating = true
|
||||||
dataStore.fetchAllData()
|
dataStore.fetchAllData()
|
||||||
|
|
||||||
AllWorkoutFetchable().fetch(completion: { result in
|
AllWorkoutFetchable().fetch(completion: { result in
|
||||||
@@ -158,9 +163,12 @@ struct AllWorkoutsView: View {
|
|||||||
case .success(let model):
|
case .success(let model):
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.workouts = model
|
self.workouts = model
|
||||||
|
self.isUpdating = false
|
||||||
}
|
}
|
||||||
case .failure(_):
|
case .failure(_):
|
||||||
fatalError("shit broke")
|
DispatchQueue.main.async {
|
||||||
|
self.isUpdating = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -197,6 +205,7 @@ struct AllWorkoutsListView: View {
|
|||||||
return workouts
|
return workouts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var refresh: (() -> Void)
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
@@ -233,6 +242,9 @@ struct AllWorkoutsListView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.refreshable {
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
TextField("Filter", text: $searchString)
|
TextField("Filter", text: $searchString)
|
||||||
.padding(.leading)
|
.padding(.leading)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ struct ExternalWorkoutDetailView: View {
|
|||||||
VStack {
|
VStack {
|
||||||
if let currentExercisePositionString = bridgeModule.currentExercisePositionString {
|
if let currentExercisePositionString = bridgeModule.currentExercisePositionString {
|
||||||
Text(currentExercisePositionString)
|
Text(currentExercisePositionString)
|
||||||
.font(Font.system(size: 55))
|
.font(Font.system(size: 75))
|
||||||
.scaledToFit()
|
.scaledToFit()
|
||||||
.minimumScaleFactor(0.01)
|
.minimumScaleFactor(0.01)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
@@ -47,7 +47,21 @@ struct ExternalWorkoutDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Text("nothing here bro")
|
GeometryReader { metrics in
|
||||||
|
VStack {
|
||||||
|
Spacer()
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Image(uiImage: Bundle.main.icon ?? UIImage())
|
||||||
|
.resizable()
|
||||||
|
.scaledToFit()
|
||||||
|
.frame(width: metrics.size.width/2, height: metrics.size.height/2)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: bridgeModule.currentExercise, perform: { newValue in
|
.onChange(of: bridgeModule.currentExercise, perform: { newValue in
|
||||||
@@ -69,7 +83,7 @@ struct ExternalWorkoutDetailView: View {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
.background(.background)
|
.background(bridgeModule.currentWorkout == nil ? Color(red: 157/255, green: 138/255, blue: 255/255) : Color(uiColor: .systemBackground))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +174,8 @@ struct ExtCountdownView: View {
|
|||||||
.frame(height: metrics.size.height * 0.5)
|
.frame(height: metrics.size.height * 0.5)
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
if let duration = currenExercise.duration {
|
if let duration = currenExercise.duration,
|
||||||
|
duration > 0 {
|
||||||
ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration))
|
ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration))
|
||||||
.scaleEffect(x: 1, y: 6, anchor: .center)
|
.scaleEffect(x: 1, y: 6, anchor: .center)
|
||||||
Text("\(bridgeModule.currentExerciseTimeLeft)")
|
Text("\(bridgeModule.currentExerciseTimeLeft)")
|
||||||
@@ -170,9 +185,10 @@ struct ExtCountdownView: View {
|
|||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
.padding(.leading)
|
.padding(.leading)
|
||||||
.padding(.trailing, 100)
|
.padding(.trailing, 100)
|
||||||
} else if let reps = currenExercise.reps {
|
} else if let reps = currenExercise.reps,
|
||||||
|
reps > 0 {
|
||||||
Text("\(reps)")
|
Text("\(reps)")
|
||||||
.font(Font.system(size: 75))
|
.font(Font.system(size: 150))
|
||||||
.scaledToFit()
|
.scaledToFit()
|
||||||
.minimumScaleFactor(0.01)
|
.minimumScaleFactor(0.01)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
|
|||||||
@@ -204,6 +204,17 @@ struct ActionsView: View {
|
|||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
})
|
})
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
.background(.green)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
|
||||||
|
Button(action: {
|
||||||
|
bridgeModule.pauseWorkout()
|
||||||
|
}, label: {
|
||||||
|
Image(systemName: "pause.circle.fill")
|
||||||
|
.font(.title)
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
})
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
.background(.yellow)
|
.background(.yellow)
|
||||||
.foregroundColor(.white)
|
.foregroundColor(.white)
|
||||||
|
|
||||||
@@ -263,10 +274,10 @@ struct ExerciseListView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
ScrollViewReader { proxy in
|
||||||
List() {
|
List() {
|
||||||
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]
|
||||||
VStack {
|
|
||||||
HStack {
|
HStack {
|
||||||
if i == bridgeModule.currentExerciseIdx {
|
if i == bridgeModule.currentExerciseIdx {
|
||||||
Image(systemName: "checkmark")
|
Image(systemName: "checkmark")
|
||||||
@@ -274,6 +285,24 @@ struct ExerciseListView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Text(obj.exercise.name)
|
Text(obj.exercise.name)
|
||||||
|
.id(i)
|
||||||
|
|
||||||
|
if let reps = obj.reps,
|
||||||
|
reps > 0 {
|
||||||
|
Text("Reps: \(reps)")
|
||||||
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||||
|
}
|
||||||
|
if let weight = obj.weight,
|
||||||
|
weight > 0 {
|
||||||
|
Text(" - Weight: \(weight)")
|
||||||
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||||
|
}
|
||||||
|
if let duration = obj.duration,
|
||||||
|
duration > 0 {
|
||||||
|
Text("Duration: \(duration)")
|
||||||
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||||
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
@@ -303,6 +332,11 @@ struct ExerciseListView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onChange(of: bridgeModule.currentExerciseIdx, perform: { newValue in
|
||||||
|
withAnimation {
|
||||||
|
proxy.scrollTo(newValue, anchor: .top)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
.sheet(item: $videoExercise) { exercise in
|
.sheet(item: $videoExercise) { exercise in
|
||||||
PlayerView(player: $avPlayer)
|
PlayerView(player: $avPlayer)
|
||||||
@@ -317,7 +351,8 @@ struct CountdownView: View {
|
|||||||
@StateObject var bridgeModule = BridgeModule.shared
|
@StateObject var bridgeModule = BridgeModule.shared
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if let duration = bridgeModule.currentExercise?.duration {
|
if let duration = bridgeModule.currentExercise?.duration,
|
||||||
|
duration > 0 {
|
||||||
HStack {
|
HStack {
|
||||||
ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration))
|
ProgressView(value: Float(bridgeModule.currentExerciseTimeLeft), total: Float(duration))
|
||||||
Text("\(bridgeModule.currentExerciseTimeLeft)")
|
Text("\(bridgeModule.currentExerciseTimeLeft)")
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ struct Werkout_iosApp: App {
|
|||||||
.tag(3)
|
.tag(3)
|
||||||
}
|
}
|
||||||
.onAppear{
|
.onAppear{
|
||||||
|
UIApplication.shared.isIdleTimerDisabled = true
|
||||||
_ = try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: .default, options: .mixWithOthers)
|
_ = try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: .default, options: .mixWithOthers)
|
||||||
// UserStore.shared.logout()
|
// UserStore.shared.logout()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user