Showing
1 changed file
with
77 additions
and
50 deletions
... | @@ -121,71 +121,91 @@ public class swiftApi { | ... | @@ -121,71 +121,91 @@ 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 | - GlobalVariables.trackingStepsEnabled = true | 124 | + // First get meters day value from database |
125 | + swiftApi().getPacingDetailsAsync(getPacingCallback) | ||
125 | 126 | ||
126 | - // Check if there are persistedSteps from previous app kill and save them | 127 | + func getPacingCallback (_ pacingData: swiftApi.PacingDetails?) -> Void { |
127 | - let persistedSteps = swiftApi().getSteps() | 128 | + if (pacingData != nil) { |
128 | - if (persistedSteps > 0) { | 129 | + DispatchQueue.main.async { |
130 | + | ||
131 | + let oldDayMeters: Double = pacingData?._meters._day._value ?? 0.0 | ||
129 | 132 | ||
130 | - let currentDateTime = Date() | 133 | + print("=== oldDayMeters ===") |
131 | - let dateFormatter = DateFormatter() | 134 | + print(oldDayMeters) |
132 | - dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | ||
133 | - let dateString = dateFormatter.string(from: currentDateTime) | ||
134 | 135 | ||
135 | - swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback) | 136 | + GlobalVariables.trackingStepsEnabled = true |
136 | - } | 137 | + |
137 | - | 138 | + // Check if there are persistedSteps from previous app kill and save them |
138 | - func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void { | 139 | + let persistedSteps = swiftApi().getSteps() |
139 | - if (responseData != nil) { | 140 | + if (persistedSteps > 0) { |
140 | - DispatchQueue.main.async { | 141 | + |
141 | - if (responseData?.getStatus == 1) { | 142 | + let currentDateTime = Date() |
142 | - GlobalVariables.savedSteps = 0 | 143 | + let dateFormatter = DateFormatter() |
144 | + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | ||
145 | + let dateString = dateFormatter.string(from: currentDateTime) | ||
146 | + | ||
147 | + swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback) | ||
148 | + } | ||
149 | + | ||
150 | + func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void { | ||
151 | + if (responseData != nil) { | ||
152 | + DispatchQueue.main.async { | ||
153 | + if (responseData?.getStatus == 1) { | ||
154 | + GlobalVariables.savedSteps = 0 | ||
155 | + } | ||
156 | + } | ||
157 | + } else { | ||
158 | + } | ||
143 | } | 159 | } |
144 | - } | ||
145 | - } else { | ||
146 | - } | ||
147 | - } | ||
148 | 160 | ||
149 | - let instanceOfMyApi = MyApi() | 161 | + let instanceOfMyApi = MyApi() |
150 | - instanceOfMyApi.startTrackingSteps(startTrackingCallback) | 162 | + instanceOfMyApi.startTrackingSteps(startTrackingCallback) |
151 | 163 | ||
152 | - swiftApi().startTimer() | 164 | + swiftApi().startTimer() |
153 | - | 165 | + |
154 | - | 166 | + |
155 | - func startTrackingCallback(_ steps: NSNumber?) -> Void { | 167 | + func startTrackingCallback(_ steps: NSNumber?) -> Void { |
156 | - | 168 | + |
157 | - print("=== steps ===") | 169 | + print("=== steps ===") |
158 | - print(steps as? Int ?? 0) | 170 | + print(steps as? Int ?? 0) |
159 | 171 | ||
160 | - if (steps != nil) { | 172 | + if (steps != nil) { |
161 | - print("=== steps to save ===") | 173 | + print("=== steps to save ===") |
162 | 174 | ||
163 | - print((steps as! Int) - GlobalVariables.savedSteps) | 175 | + print((steps as! Int) - GlobalVariables.savedSteps) |
164 | - swiftApi().setSteps((steps as! Int) - GlobalVariables.savedSteps) | 176 | + swiftApi().setSteps((steps as! Int) - GlobalVariables.savedSteps) |
165 | 177 | ||
166 | - let metersCount = (steps as? Double ?? 0.0) * 0.762 | 178 | + let metersCount = (steps as? Double ?? 0.0) * 0.762 |
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 | ||
176 | - let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview | 188 | + print("=== Widget MetersCount ===") |
177 | - swiftApi().setStepsWebview(newStepsWebview) | 189 | + print(metersCount + oldDayMeters) |
178 | - let newMetersWebview = Double(newStepsWebview) * 0.762 | ||
179 | - swiftApi().setMetersWebview(newMetersWebview) | ||
180 | 190 | ||
181 | - print("=== StepsWebview ===") | 191 | + let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview |
182 | - print(newStepsWebview) | 192 | + swiftApi().setStepsWebview(newStepsWebview) |
183 | - print("=== MetersWebview ===") | 193 | + let newMetersWebview = Double(newStepsWebview) * 0.762 |
184 | - print(newMetersWebview) | 194 | + swiftApi().setMetersWebview(newMetersWebview) |
185 | - } | ||
186 | 195 | ||
187 | - getStepsCallback(steps as? Int ?? 0) | 196 | + print("=== StepsWebview ===") |
197 | + print(newStepsWebview) | ||
198 | + print("=== MetersWebview ===") | ||
199 | + print(newMetersWebview) | ||
200 | + } | ||
201 | + | ||
202 | + getStepsCallback(steps as? Int ?? 0) | ||
203 | + } | ||
204 | + | ||
205 | + } | ||
206 | + } | ||
188 | } | 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