Manos Chorianopoulos

fix real time pacing

......@@ -71,7 +71,7 @@ var timer2: DispatchSourceTimer?
DispatchQueue.main.async {
// update your model objects and/or UI here
let metersParam = swiftApi().getMetersCount()
let metersParam = swiftApi().getMetersWebview()
let scriptSource = "passMeters(\(metersParam));"
self?.webview.evaluateJavaScript(scriptSource, completionHandler: { (object, error) in
......@@ -79,6 +79,13 @@ var timer2: DispatchSourceTimer?
print(object)
print("==== error ====")
print(error)
swiftApi().setSavedStepsWebview(swiftApi().getSavedStepsWebview() + swiftApi().getStepsWebview())
swiftApi().setStepsWebview(0)
swiftApi().setMetersWebview(0.0)
print("==== SavedStepsWebview ====")
print(swiftApi().getSavedStepsWebview())
})
}
}
......
......@@ -23,6 +23,9 @@ public struct GlobalVariables {
static var dealsSum: Float = 0.0
static var seasonalList: Array<swiftApi.LoyaltyGiftsForYouPackage> = []
static var savedSteps: Int = 0
static var stepsWebview: Int = 0
static var savedStepsWebview: Int = 0
static var metersWebview: Double = 0.0
static var merchantList: Array<swiftApi.MerchantModel> = []
}
......@@ -58,6 +61,30 @@ public class swiftApi {
UserDefaults.standard.set(newValue, forKey: "metersCount")
}
public func getStepsWebview() -> Int {
return GlobalVariables.stepsWebview
}
public func setStepsWebview(_ newValue: Int) -> Void {
GlobalVariables.stepsWebview = newValue
}
public func getSavedStepsWebview() -> Int {
return GlobalVariables.savedStepsWebview
}
public func setSavedStepsWebview(_ newValue: Int) -> Void {
GlobalVariables.savedStepsWebview = newValue
}
public func getMetersWebview() -> Double {
return GlobalVariables.metersWebview
}
public func setMetersWebview(_ newValue: Double) -> Void {
GlobalVariables.metersWebview = newValue
}
public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
......@@ -109,6 +136,16 @@ public class swiftApi {
print("=== MetersCount ===")
print(metersCount)
let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview
swiftApi().setStepsWebview(newStepsWebview)
let newMetersWebview = Double(newStepsWebview) * 0.762
swiftApi().setMetersWebview(newMetersWebview)
print("=== StepsWebview ===")
print(newStepsWebview)
print("=== MetersWebview ===")
print(newMetersWebview)
}
getStepsCallback(steps as? Int ?? 0)
......@@ -125,6 +162,10 @@ public class swiftApi {
GlobalVariables.savedSteps = 0
swiftApi().setMetersCount(0.0)
swiftApi().setStepsWebview(0)
swiftApi().setSavedStepsWebview(0)
swiftApi().setMetersWebview(0.0)
let persistedSteps = swiftApi().getSteps()
if (persistedSteps > 0) {
......