Manos Chorianopoulos

fix pacing on user logout, add oldDayMeters

......@@ -121,71 +121,91 @@ public class swiftApi {
public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
if (GlobalVariables.trackingStepsEnabled == false) {
GlobalVariables.trackingStepsEnabled = true
// First get meters day value from database
swiftApi().getPacingDetailsAsync(getPacingCallback)
// Check if there are persistedSteps from previous app kill and save them
let persistedSteps = swiftApi().getSteps()
if (persistedSteps > 0) {
func getPacingCallback (_ pacingData: swiftApi.PacingDetails?) -> Void {
if (pacingData != nil) {
DispatchQueue.main.async {
let oldDayMeters: Double = pacingData?._meters._day._value ?? 0.0
let currentDateTime = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateString = dateFormatter.string(from: currentDateTime)
print("=== oldDayMeters ===")
print(oldDayMeters)
swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback)
}
func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void {
if (responseData != nil) {
DispatchQueue.main.async {
if (responseData?.getStatus == 1) {
GlobalVariables.savedSteps = 0
GlobalVariables.trackingStepsEnabled = true
// Check if there are persistedSteps from previous app kill and save them
let persistedSteps = swiftApi().getSteps()
if (persistedSteps > 0) {
let currentDateTime = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateString = dateFormatter.string(from: currentDateTime)
swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback)
}
func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void {
if (responseData != nil) {
DispatchQueue.main.async {
if (responseData?.getStatus == 1) {
GlobalVariables.savedSteps = 0
}
}
} else {
}
}
}
} else {
}
}
let instanceOfMyApi = MyApi()
instanceOfMyApi.startTrackingSteps(startTrackingCallback)
let instanceOfMyApi = MyApi()
instanceOfMyApi.startTrackingSteps(startTrackingCallback)
swiftApi().startTimer()
func startTrackingCallback(_ steps: NSNumber?) -> Void {
print("=== steps ===")
print(steps as? Int ?? 0)
swiftApi().startTimer()
func startTrackingCallback(_ steps: NSNumber?) -> Void {
print("=== steps ===")
print(steps as? Int ?? 0)
if (steps != nil) {
print("=== steps to save ===")
if (steps != nil) {
print("=== steps to save ===")
print((steps as! Int) - GlobalVariables.savedSteps)
swiftApi().setSteps((steps as! Int) - GlobalVariables.savedSteps)
print((steps as! Int) - GlobalVariables.savedSteps)
swiftApi().setSteps((steps as! Int) - GlobalVariables.savedSteps)
let metersCount = (steps as? Double ?? 0.0) * 0.762
swiftApi().setMetersCount(metersCount)
let metersCount = (steps as? Double ?? 0.0) * 0.762
swiftApi().setMetersCount(metersCount)
let pacingEvent = swiftApi.HealthEventModel()
pacingEvent._meters = metersCount
SwiftEventBus.post("meters_sent", sender: pacingEvent)
let pacingEvent = swiftApi.HealthEventModel()
pacingEvent._meters = metersCount + oldDayMeters
// SwiftEventBus.post("meters_sent", sender: pacingEvent)
print("=== MetersCount ===")
print(metersCount)
print("=== MetersCount ===")
print(metersCount)
let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview
swiftApi().setStepsWebview(newStepsWebview)
let newMetersWebview = Double(newStepsWebview) * 0.762
swiftApi().setMetersWebview(newMetersWebview)
print("=== Widget MetersCount ===")
print(metersCount + oldDayMeters)
print("=== StepsWebview ===")
print(newStepsWebview)
print("=== MetersWebview ===")
print(newMetersWebview)
}
let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview
swiftApi().setStepsWebview(newStepsWebview)
let newMetersWebview = Double(newStepsWebview) * 0.762
swiftApi().setMetersWebview(newMetersWebview)
getStepsCallback(steps as? Int ?? 0)
print("=== StepsWebview ===")
print(newStepsWebview)
print("=== MetersWebview ===")
print(newMetersWebview)
}
getStepsCallback(steps as? Int ?? 0)
}
}
}
}
}
}
......@@ -5746,4 +5766,11 @@ public class swiftApi {
}
public func logoutUser() -> Void {
if (GlobalVariables.trackingStepsEnabled == true) {
swiftApi().stopTrackingSteps()
}
}
}
......