Manos Chorianopoulos

fix pacing already enabled

...@@ -206,7 +206,10 @@ var timer2: DispatchSourceTimer? ...@@ -206,7 +206,10 @@ var timer2: DispatchSourceTimer?
206 let pacingEvent = swiftApi.WarplyPacingEventModel() 206 let pacingEvent = swiftApi.WarplyPacingEventModel()
207 pacingEvent._isVisible = true 207 pacingEvent._isVisible = true
208 SwiftEventBus.post("pacing", sender: pacingEvent) 208 SwiftEventBus.post("pacing", sender: pacingEvent)
209 +
210 + if (swiftApi().getTrackingStepsEnabled() == false) {
209 self.startTrackingSteps() 211 self.startTrackingSteps()
212 + }
210 213
211 } else if (eventArray[1] == "steps" && eventArray[2] == "shortcutDisabled") { 214 } else if (eventArray[1] == "steps" && eventArray[2] == "shortcutDisabled") {
212 let pacingEvent = swiftApi.WarplyPacingEventModel() 215 let pacingEvent = swiftApi.WarplyPacingEventModel()
......
...@@ -27,6 +27,7 @@ public struct GlobalVariables { ...@@ -27,6 +27,7 @@ public struct GlobalVariables {
27 static var savedStepsWebview: Int = 0 27 static var savedStepsWebview: Int = 0
28 static var metersWebview: Double = 0.0 28 static var metersWebview: Double = 0.0
29 static var merchantList: Array<swiftApi.MerchantModel> = [] 29 static var merchantList: Array<swiftApi.MerchantModel> = []
30 + static var trackingStepsEnabled: Bool = false
30 } 31 }
31 32
32 var timer: DispatchSourceTimer? 33 var timer: DispatchSourceTimer?
...@@ -85,9 +86,20 @@ public class swiftApi { ...@@ -85,9 +86,20 @@ public class swiftApi {
85 GlobalVariables.metersWebview = newValue 86 GlobalVariables.metersWebview = newValue
86 } 87 }
87 88
89 + public func getTrackingStepsEnabled() -> Bool {
90 + return GlobalVariables.trackingStepsEnabled
91 + }
92 +
93 + public func setTrackingStepsEnabled(_ newValue: Bool) -> Void {
94 + GlobalVariables.trackingStepsEnabled = newValue
95 + }
96 +
88 97
89 public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { 98 public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
90 99
100 + if (GlobalVariables.trackingStepsEnabled == false) {
101 + GlobalVariables.trackingStepsEnabled = true
102 +
91 // Check if there are persistedSteps from previous app kill and save them 103 // Check if there are persistedSteps from previous app kill and save them
92 let persistedSteps = swiftApi().getSteps() 104 let persistedSteps = swiftApi().getSteps()
93 if (persistedSteps > 0) { 105 if (persistedSteps > 0) {
...@@ -104,6 +116,7 @@ public class swiftApi { ...@@ -104,6 +116,7 @@ public class swiftApi {
104 if (responseData != nil) { 116 if (responseData != nil) {
105 DispatchQueue.main.async { 117 DispatchQueue.main.async {
106 if (responseData?.getStatus == 1) { 118 if (responseData?.getStatus == 1) {
119 + GlobalVariables.savedSteps = 0
107 } 120 }
108 } 121 }
109 } else { 122 } else {
...@@ -150,7 +163,7 @@ public class swiftApi { ...@@ -150,7 +163,7 @@ public class swiftApi {
150 163
151 getStepsCallback(steps as? Int ?? 0) 164 getStepsCallback(steps as? Int ?? 0)
152 } 165 }
153 - 166 + }
154 } 167 }
155 168
156 public func stopTrackingSteps() -> Void { 169 public func stopTrackingSteps() -> Void {
...@@ -159,6 +172,8 @@ public class swiftApi { ...@@ -159,6 +172,8 @@ public class swiftApi {
159 172
160 stopTimer() 173 stopTimer()
161 174
175 + GlobalVariables.trackingStepsEnabled = false
176 +
162 GlobalVariables.savedSteps = 0 177 GlobalVariables.savedSteps = 0
163 swiftApi().setMetersCount(0.0) 178 swiftApi().setMetersCount(0.0)
164 179
......