Showing
2 changed files
with
66 additions
and
48 deletions
... | @@ -177,7 +177,7 @@ var timer2: DispatchSourceTimer? | ... | @@ -177,7 +177,7 @@ var timer2: DispatchSourceTimer? |
177 | 177 | ||
178 | DispatchQueue.main.async { | 178 | DispatchQueue.main.async { |
179 | SwiftEventBus.post("coupons_fetched") | 179 | SwiftEventBus.post("coupons_fetched") |
180 | - | 180 | + |
181 | print("========= getCouponsRequest SUCCESSSS CampaignVC =========") | 181 | print("========= getCouponsRequest SUCCESSSS CampaignVC =========") |
182 | 182 | ||
183 | print("========= getCouponsRequest count CampaignVC =========") | 183 | print("========= getCouponsRequest count CampaignVC =========") |
... | @@ -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 | - self.startTrackingSteps() | 209 | + |
210 | + if (swiftApi().getTrackingStepsEnabled() == false) { | ||
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,72 +86,84 @@ public class swiftApi { | ... | @@ -85,72 +86,84 @@ 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 | ||
91 | - // Check if there are persistedSteps from previous app kill and save them | 100 | + if (GlobalVariables.trackingStepsEnabled == false) { |
92 | - let persistedSteps = swiftApi().getSteps() | 101 | + GlobalVariables.trackingStepsEnabled = true |
93 | - if (persistedSteps > 0) { | ||
94 | 102 | ||
95 | - let currentDateTime = Date() | 103 | + // Check if there are persistedSteps from previous app kill and save them |
96 | - let dateFormatter = DateFormatter() | 104 | + let persistedSteps = swiftApi().getSteps() |
97 | - dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | 105 | + if (persistedSteps > 0) { |
98 | - let dateString = dateFormatter.string(from: currentDateTime) | ||
99 | 106 | ||
100 | - swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback) | 107 | + let currentDateTime = Date() |
101 | - } | 108 | + let dateFormatter = DateFormatter() |
102 | - | 109 | + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" |
103 | - func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void { | 110 | + let dateString = dateFormatter.string(from: currentDateTime) |
104 | - if (responseData != nil) { | 111 | + |
105 | - DispatchQueue.main.async { | 112 | + swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback) |
106 | - if (responseData?.getStatus == 1) { | 113 | + } |
114 | + | ||
115 | + func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void { | ||
116 | + if (responseData != nil) { | ||
117 | + DispatchQueue.main.async { | ||
118 | + if (responseData?.getStatus == 1) { | ||
119 | + GlobalVariables.savedSteps = 0 | ||
120 | + } | ||
107 | } | 121 | } |
122 | + } else { | ||
108 | } | 123 | } |
109 | - } else { | ||
110 | } | 124 | } |
111 | - } | ||
112 | 125 | ||
113 | - let instanceOfMyApi = MyApi() | 126 | + let instanceOfMyApi = MyApi() |
114 | - instanceOfMyApi.startTrackingSteps(startTrackingCallback) | 127 | + instanceOfMyApi.startTrackingSteps(startTrackingCallback) |
115 | 128 | ||
116 | - swiftApi().startTimer() | 129 | + swiftApi().startTimer() |
117 | - | ||
118 | - | ||
119 | - func startTrackingCallback(_ steps: NSNumber?) -> Void { | ||
120 | 130 | ||
121 | - print("=== steps ===") | 131 | + |
122 | - print(steps as? Int ?? 0) | 132 | + func startTrackingCallback(_ steps: NSNumber?) -> Void { |
133 | + | ||
134 | + print("=== steps ===") | ||
135 | + print(steps as? Int ?? 0) | ||
123 | 136 | ||
124 | - if (steps != nil) { | 137 | + if (steps != nil) { |
125 | - print("=== steps to save ===") | 138 | + print("=== steps to save ===") |
126 | 139 | ||
127 | - print((steps as! Int) - GlobalVariables.savedSteps) | 140 | + print((steps as! Int) - GlobalVariables.savedSteps) |
128 | - swiftApi().setSteps((steps as! Int) - GlobalVariables.savedSteps) | 141 | + swiftApi().setSteps((steps as! Int) - GlobalVariables.savedSteps) |
129 | 142 | ||
130 | - let metersCount = (steps as? Double ?? 0.0) * 0.762 | 143 | + let metersCount = (steps as? Double ?? 0.0) * 0.762 |
131 | - swiftApi().setMetersCount(metersCount) | 144 | + swiftApi().setMetersCount(metersCount) |
132 | 145 | ||
133 | - let pacingEvent = swiftApi.HealthEventModel() | 146 | + let pacingEvent = swiftApi.HealthEventModel() |
134 | - pacingEvent._meters = metersCount | 147 | + pacingEvent._meters = metersCount |
135 | - SwiftEventBus.post("meters_sent", sender: pacingEvent) | 148 | + SwiftEventBus.post("meters_sent", sender: pacingEvent) |
136 | 149 | ||
137 | - print("=== MetersCount ===") | 150 | + print("=== MetersCount ===") |
138 | - print(metersCount) | 151 | + print(metersCount) |
139 | 152 | ||
140 | - let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview | 153 | + let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview |
141 | - swiftApi().setStepsWebview(newStepsWebview) | 154 | + swiftApi().setStepsWebview(newStepsWebview) |
142 | - let newMetersWebview = Double(newStepsWebview) * 0.762 | 155 | + let newMetersWebview = Double(newStepsWebview) * 0.762 |
143 | - swiftApi().setMetersWebview(newMetersWebview) | 156 | + swiftApi().setMetersWebview(newMetersWebview) |
144 | 157 | ||
145 | - print("=== StepsWebview ===") | 158 | + print("=== StepsWebview ===") |
146 | - print(newStepsWebview) | 159 | + print(newStepsWebview) |
147 | - print("=== MetersWebview ===") | 160 | + print("=== MetersWebview ===") |
148 | - print(newMetersWebview) | 161 | + print(newMetersWebview) |
149 | - } | 162 | + } |
150 | 163 | ||
151 | - getStepsCallback(steps as? Int ?? 0) | 164 | + getStepsCallback(steps as? Int ?? 0) |
165 | + } | ||
152 | } | 166 | } |
153 | - | ||
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 | ... | ... |
-
Please register or login to post a comment