Manos Chorianopoulos

fix pacing on user logout, add oldDayMeters

......@@ -121,6 +121,18 @@ public class swiftApi {
public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
if (GlobalVariables.trackingStepsEnabled == false) {
// First get meters day value from database
swiftApi().getPacingDetailsAsync(getPacingCallback)
func getPacingCallback (_ pacingData: swiftApi.PacingDetails?) -> Void {
if (pacingData != nil) {
DispatchQueue.main.async {
let oldDayMeters: Double = pacingData?._meters._day._value ?? 0.0
print("=== oldDayMeters ===")
print(oldDayMeters)
GlobalVariables.trackingStepsEnabled = true
// Check if there are persistedSteps from previous app kill and save them
......@@ -167,12 +179,15 @@ public class swiftApi {
swiftApi().setMetersCount(metersCount)
let pacingEvent = swiftApi.HealthEventModel()
pacingEvent._meters = metersCount
SwiftEventBus.post("meters_sent", sender: pacingEvent)
pacingEvent._meters = metersCount + oldDayMeters
// SwiftEventBus.post("meters_sent", sender: pacingEvent)
print("=== MetersCount ===")
print(metersCount)
print("=== Widget MetersCount ===")
print(metersCount + oldDayMeters)
let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview
swiftApi().setStepsWebview(newStepsWebview)
let newMetersWebview = Double(newStepsWebview) * 0.762
......@@ -186,6 +201,11 @@ public class swiftApi {
getStepsCallback(steps as? Int ?? 0)
}
}
}
}
}
}
......@@ -5746,4 +5766,11 @@ public class swiftApi {
}
public func logoutUser() -> Void {
if (GlobalVariables.trackingStepsEnabled == true) {
swiftApi().stopTrackingSteps()
}
}
}
......