misc watch stuff including taps, sounds, maybe working
This commit is contained in:
@@ -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