misc watch stuff including taps, sounds, maybe working
This commit is contained in:
@@ -44,9 +44,15 @@ struct WatchControlView: View {
|
||||
Button(action: {
|
||||
vm.pauseWorkout()
|
||||
}, label: {
|
||||
Image(systemName: "pause")
|
||||
.font(.title)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
if vm.isPaused {
|
||||
Image(systemName: "play")
|
||||
.font(.title)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else {
|
||||
Image(systemName: "pause")
|
||||
.font(.title)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
})
|
||||
.buttonStyle(BorderedButtonStyle(tint: .blue))
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ extension WatchMainViewModel {
|
||||
}
|
||||
}
|
||||
isInWorkout = true
|
||||
isPaused = false
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
} else {
|
||||
print("did not init workout")
|
||||
}
|
||||
@@ -69,6 +71,7 @@ extension WatchMainViewModel {
|
||||
self.hkBuilder = nil
|
||||
self.heartRates.removeAll()
|
||||
self.isInWorkout = false
|
||||
self.isPaused = false
|
||||
|
||||
guard let id = workout?.uuid else {
|
||||
return
|
||||
|
||||
@@ -20,13 +20,14 @@ class WatchMainViewModel: NSObject, ObservableObject {
|
||||
@Published var heartValue: Int?
|
||||
|
||||
static var defualtPackageModle: WatchPackageModel {
|
||||
WatchPackageModel(currentExerciseName: "", currentTimeLeft: -1, workoutStartDate: Date())
|
||||
WatchPackageModel(currentExerciseName: "", currentExerciseID: -1, currentTimeLeft: -1, workoutStartDate: Date())
|
||||
}
|
||||
|
||||
let healthStore = HKHealthStore()
|
||||
var hkWorkoutSession: HKWorkoutSession?
|
||||
var hkBuilder: HKLiveWorkoutBuilder?
|
||||
var heartRates = [Int]()
|
||||
@Published var isPaused = false
|
||||
|
||||
override init() {
|
||||
session = WCSession.default
|
||||
@@ -56,38 +57,51 @@ class WatchMainViewModel: NSObject, ObservableObject {
|
||||
let nextExerciseAction = WatchActions.nextExercise
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
send(data)
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
|
||||
func restartExercise() {
|
||||
let nextExerciseAction = WatchActions.restartExercise
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
send(data)
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
|
||||
func previousExercise() {
|
||||
let nextExerciseAction = WatchActions.previousExercise
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
send(data)
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
|
||||
func completeWorkout() {
|
||||
let nextExerciseAction = WatchActions.stopWorkout
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
send(data)
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
|
||||
func pauseWorkout() {
|
||||
let nextExerciseAction = WatchActions.pauseWorkout
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
send(data)
|
||||
isPaused = !isPaused
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
|
||||
func dataToAction(messageData: Data) {
|
||||
if let model = try? JSONDecoder().decode(PhoneToWatchActions.self, from: messageData) {
|
||||
DispatchQueue.main.async {
|
||||
switch model {
|
||||
case .inExercise(let data):
|
||||
self.watchPackageModel = data
|
||||
case .inExercise(let newWatchPackageModel):
|
||||
if !self.isInWorkout {
|
||||
self.startWorkout()
|
||||
}
|
||||
if self.watchPackageModel.currentExerciseID != newWatchPackageModel.currentExerciseID {
|
||||
self.isPaused = false
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
self.watchPackageModel = newWatchPackageModel
|
||||
case .reset:
|
||||
self.isInWorkout = false
|
||||
self.watchPackageModel = WatchMainViewModel.defualtPackageModle
|
||||
|
||||
Reference in New Issue
Block a user