Manos Chorianopoulos

fix real time pacing

...@@ -71,7 +71,7 @@ var timer2: DispatchSourceTimer? ...@@ -71,7 +71,7 @@ var timer2: DispatchSourceTimer?
71 71
72 DispatchQueue.main.async { 72 DispatchQueue.main.async {
73 // update your model objects and/or UI here 73 // update your model objects and/or UI here
74 - let metersParam = swiftApi().getMetersCount() 74 + let metersParam = swiftApi().getMetersWebview()
75 let scriptSource = "passMeters(\(metersParam));" 75 let scriptSource = "passMeters(\(metersParam));"
76 76
77 self?.webview.evaluateJavaScript(scriptSource, completionHandler: { (object, error) in 77 self?.webview.evaluateJavaScript(scriptSource, completionHandler: { (object, error) in
...@@ -79,6 +79,13 @@ var timer2: DispatchSourceTimer? ...@@ -79,6 +79,13 @@ var timer2: DispatchSourceTimer?
79 print(object) 79 print(object)
80 print("==== error ====") 80 print("==== error ====")
81 print(error) 81 print(error)
82 +
83 + swiftApi().setSavedStepsWebview(swiftApi().getSavedStepsWebview() + swiftApi().getStepsWebview())
84 + swiftApi().setStepsWebview(0)
85 + swiftApi().setMetersWebview(0.0)
86 +
87 + print("==== SavedStepsWebview ====")
88 + print(swiftApi().getSavedStepsWebview())
82 }) 89 })
83 } 90 }
84 } 91 }
......
...@@ -23,6 +23,9 @@ public struct GlobalVariables { ...@@ -23,6 +23,9 @@ public struct GlobalVariables {
23 static var dealsSum: Float = 0.0 23 static var dealsSum: Float = 0.0
24 static var seasonalList: Array<swiftApi.LoyaltyGiftsForYouPackage> = [] 24 static var seasonalList: Array<swiftApi.LoyaltyGiftsForYouPackage> = []
25 static var savedSteps: Int = 0 25 static var savedSteps: Int = 0
26 + static var stepsWebview: Int = 0
27 + static var savedStepsWebview: Int = 0
28 + static var metersWebview: Double = 0.0
26 static var merchantList: Array<swiftApi.MerchantModel> = [] 29 static var merchantList: Array<swiftApi.MerchantModel> = []
27 } 30 }
28 31
...@@ -58,6 +61,30 @@ public class swiftApi { ...@@ -58,6 +61,30 @@ public class swiftApi {
58 UserDefaults.standard.set(newValue, forKey: "metersCount") 61 UserDefaults.standard.set(newValue, forKey: "metersCount")
59 } 62 }
60 63
64 + public func getStepsWebview() -> Int {
65 + return GlobalVariables.stepsWebview
66 + }
67 +
68 + public func setStepsWebview(_ newValue: Int) -> Void {
69 + GlobalVariables.stepsWebview = newValue
70 + }
71 +
72 + public func getSavedStepsWebview() -> Int {
73 + return GlobalVariables.savedStepsWebview
74 + }
75 +
76 + public func setSavedStepsWebview(_ newValue: Int) -> Void {
77 + GlobalVariables.savedStepsWebview = newValue
78 + }
79 +
80 + public func getMetersWebview() -> Double {
81 + return GlobalVariables.metersWebview
82 + }
83 +
84 + public func setMetersWebview(_ newValue: Double) -> Void {
85 + GlobalVariables.metersWebview = newValue
86 + }
87 +
61 88
62 public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { 89 public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
63 90
...@@ -109,6 +136,16 @@ public class swiftApi { ...@@ -109,6 +136,16 @@ public class swiftApi {
109 136
110 print("=== MetersCount ===") 137 print("=== MetersCount ===")
111 print(metersCount) 138 print(metersCount)
139 +
140 + let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview
141 + swiftApi().setStepsWebview(newStepsWebview)
142 + let newMetersWebview = Double(newStepsWebview) * 0.762
143 + swiftApi().setMetersWebview(newMetersWebview)
144 +
145 + print("=== StepsWebview ===")
146 + print(newStepsWebview)
147 + print("=== MetersWebview ===")
148 + print(newMetersWebview)
112 } 149 }
113 150
114 getStepsCallback(steps as? Int ?? 0) 151 getStepsCallback(steps as? Int ?? 0)
...@@ -125,6 +162,10 @@ public class swiftApi { ...@@ -125,6 +162,10 @@ public class swiftApi {
125 GlobalVariables.savedSteps = 0 162 GlobalVariables.savedSteps = 0
126 swiftApi().setMetersCount(0.0) 163 swiftApi().setMetersCount(0.0)
127 164
165 + swiftApi().setStepsWebview(0)
166 + swiftApi().setSavedStepsWebview(0)
167 + swiftApi().setMetersWebview(0.0)
168 +
128 let persistedSteps = swiftApi().getSteps() 169 let persistedSteps = swiftApi().getSteps()
129 if (persistedSteps > 0) { 170 if (persistedSteps > 0) {
130 171
......