Manos Chorianopoulos

fix pacing already enabled

......@@ -206,7 +206,10 @@ var timer2: DispatchSourceTimer?
let pacingEvent = swiftApi.WarplyPacingEventModel()
pacingEvent._isVisible = true
SwiftEventBus.post("pacing", sender: pacingEvent)
if (swiftApi().getTrackingStepsEnabled() == false) {
self.startTrackingSteps()
}
} else if (eventArray[1] == "steps" && eventArray[2] == "shortcutDisabled") {
let pacingEvent = swiftApi.WarplyPacingEventModel()
......
......@@ -27,6 +27,7 @@ public struct GlobalVariables {
static var savedStepsWebview: Int = 0
static var metersWebview: Double = 0.0
static var merchantList: Array<swiftApi.MerchantModel> = []
static var trackingStepsEnabled: Bool = false
}
var timer: DispatchSourceTimer?
......@@ -85,9 +86,20 @@ public class swiftApi {
GlobalVariables.metersWebview = newValue
}
public func getTrackingStepsEnabled() -> Bool {
return GlobalVariables.trackingStepsEnabled
}
public func setTrackingStepsEnabled(_ newValue: Bool) -> Void {
GlobalVariables.trackingStepsEnabled = newValue
}
public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
if (GlobalVariables.trackingStepsEnabled == false) {
GlobalVariables.trackingStepsEnabled = true
// Check if there are persistedSteps from previous app kill and save them
let persistedSteps = swiftApi().getSteps()
if (persistedSteps > 0) {
......@@ -104,6 +116,7 @@ public class swiftApi {
if (responseData != nil) {
DispatchQueue.main.async {
if (responseData?.getStatus == 1) {
GlobalVariables.savedSteps = 0
}
}
} else {
......@@ -150,7 +163,7 @@ public class swiftApi {
getStepsCallback(steps as? Int ?? 0)
}
}
}
public func stopTrackingSteps() -> Void {
......@@ -159,6 +172,8 @@ public class swiftApi {
stopTimer()
GlobalVariables.trackingStepsEnabled = false
GlobalVariables.savedSteps = 0
swiftApi().setMetersCount(0.0)
......