Showing
1 changed file
with
29 additions
and
2 deletions
| ... | @@ -121,6 +121,18 @@ public class swiftApi { | ... | @@ -121,6 +121,18 @@ public class swiftApi { |
| 121 | public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { | 121 | public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { |
| 122 | 122 | ||
| 123 | if (GlobalVariables.trackingStepsEnabled == false) { | 123 | if (GlobalVariables.trackingStepsEnabled == false) { |
| 124 | + // First get meters day value from database | ||
| 125 | + swiftApi().getPacingDetailsAsync(getPacingCallback) | ||
| 126 | + | ||
| 127 | + func getPacingCallback (_ pacingData: swiftApi.PacingDetails?) -> Void { | ||
| 128 | + if (pacingData != nil) { | ||
| 129 | + DispatchQueue.main.async { | ||
| 130 | + | ||
| 131 | + let oldDayMeters: Double = pacingData?._meters._day._value ?? 0.0 | ||
| 132 | + | ||
| 133 | + print("=== oldDayMeters ===") | ||
| 134 | + print(oldDayMeters) | ||
| 135 | + | ||
| 124 | GlobalVariables.trackingStepsEnabled = true | 136 | GlobalVariables.trackingStepsEnabled = true |
| 125 | 137 | ||
| 126 | // Check if there are persistedSteps from previous app kill and save them | 138 | // Check if there are persistedSteps from previous app kill and save them |
| ... | @@ -167,12 +179,15 @@ public class swiftApi { | ... | @@ -167,12 +179,15 @@ public class swiftApi { |
| 167 | swiftApi().setMetersCount(metersCount) | 179 | swiftApi().setMetersCount(metersCount) |
| 168 | 180 | ||
| 169 | let pacingEvent = swiftApi.HealthEventModel() | 181 | let pacingEvent = swiftApi.HealthEventModel() |
| 170 | - pacingEvent._meters = metersCount | 182 | + pacingEvent._meters = metersCount + oldDayMeters |
| 171 | - SwiftEventBus.post("meters_sent", sender: pacingEvent) | 183 | + // SwiftEventBus.post("meters_sent", sender: pacingEvent) |
| 172 | 184 | ||
| 173 | print("=== MetersCount ===") | 185 | print("=== MetersCount ===") |
| 174 | print(metersCount) | 186 | print(metersCount) |
| 175 | 187 | ||
| 188 | + print("=== Widget MetersCount ===") | ||
| 189 | + print(metersCount + oldDayMeters) | ||
| 190 | + | ||
| 176 | let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview | 191 | let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview |
| 177 | swiftApi().setStepsWebview(newStepsWebview) | 192 | swiftApi().setStepsWebview(newStepsWebview) |
| 178 | let newMetersWebview = Double(newStepsWebview) * 0.762 | 193 | let newMetersWebview = Double(newStepsWebview) * 0.762 |
| ... | @@ -186,6 +201,11 @@ public class swiftApi { | ... | @@ -186,6 +201,11 @@ public class swiftApi { |
| 186 | 201 | ||
| 187 | getStepsCallback(steps as? Int ?? 0) | 202 | getStepsCallback(steps as? Int ?? 0) |
| 188 | } | 203 | } |
| 204 | + | ||
| 205 | + } | ||
| 206 | + } | ||
| 207 | + } | ||
| 208 | + | ||
| 189 | } | 209 | } |
| 190 | } | 210 | } |
| 191 | 211 | ||
| ... | @@ -5746,4 +5766,11 @@ public class swiftApi { | ... | @@ -5746,4 +5766,11 @@ public class swiftApi { |
| 5746 | } | 5766 | } |
| 5747 | 5767 | ||
| 5748 | 5768 | ||
| 5769 | + public func logoutUser() -> Void { | ||
| 5770 | + if (GlobalVariables.trackingStepsEnabled == true) { | ||
| 5771 | + swiftApi().stopTrackingSteps() | ||
| 5772 | + } | ||
| 5773 | + } | ||
| 5774 | + | ||
| 5775 | + | ||
| 5749 | } | 5776 | } | ... | ... |
-
Please register or login to post a comment