Manos Chorianopoulos

fix pacing already enabled

......@@ -177,7 +177,7 @@ var timer2: DispatchSourceTimer?
DispatchQueue.main.async {
SwiftEventBus.post("coupons_fetched")
print("========= getCouponsRequest SUCCESSSS CampaignVC =========")
print("========= getCouponsRequest count CampaignVC =========")
......@@ -206,7 +206,10 @@ var timer2: DispatchSourceTimer?
let pacingEvent = swiftApi.WarplyPacingEventModel()
pacingEvent._isVisible = true
SwiftEventBus.post("pacing", sender: pacingEvent)
self.startTrackingSteps()
if (swiftApi().getTrackingStepsEnabled() == false) {
self.startTrackingSteps()
}
} else if (eventArray[1] == "steps" && eventArray[2] == "shortcutDisabled") {
let pacingEvent = swiftApi.WarplyPacingEventModel()
......
......@@ -27,6 +27,7 @@ public struct GlobalVariables {
static var savedStepsWebview: Int = 0
static var metersWebview: Double = 0.0
static var merchantList: Array<swiftApi.MerchantModel> = []
static var trackingStepsEnabled: Bool = false
}
var timer: DispatchSourceTimer?
......@@ -85,72 +86,84 @@ public class swiftApi {
GlobalVariables.metersWebview = newValue
}
public func getTrackingStepsEnabled() -> Bool {
return GlobalVariables.trackingStepsEnabled
}
public func setTrackingStepsEnabled(_ newValue: Bool) -> Void {
GlobalVariables.trackingStepsEnabled = newValue
}
public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
// Check if there are persistedSteps from previous app kill and save them
let persistedSteps = swiftApi().getSteps()
if (persistedSteps > 0) {
if (GlobalVariables.trackingStepsEnabled == false) {
GlobalVariables.trackingStepsEnabled = true
let currentDateTime = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateString = dateFormatter.string(from: currentDateTime)
// Check if there are persistedSteps from previous app kill and save them
let persistedSteps = swiftApi().getSteps()
if (persistedSteps > 0) {
swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback)
}
func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void {
if (responseData != nil) {
DispatchQueue.main.async {
if (responseData?.getStatus == 1) {
let currentDateTime = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateString = dateFormatter.string(from: currentDateTime)
swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback)
}
func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void {
if (responseData != nil) {
DispatchQueue.main.async {
if (responseData?.getStatus == 1) {
GlobalVariables.savedSteps = 0
}
}
} else {
}
} else {
}
}
let instanceOfMyApi = MyApi()
instanceOfMyApi.startTrackingSteps(startTrackingCallback)
let instanceOfMyApi = MyApi()
instanceOfMyApi.startTrackingSteps(startTrackingCallback)
swiftApi().startTimer()
func startTrackingCallback(_ steps: NSNumber?) -> Void {
swiftApi().startTimer()
print("=== steps ===")
print(steps as? Int ?? 0)
func startTrackingCallback(_ steps: NSNumber?) -> Void {
print("=== steps ===")
print(steps as? Int ?? 0)
if (steps != nil) {
print("=== steps to save ===")
if (steps != nil) {
print("=== steps to save ===")
print((steps as! Int) - GlobalVariables.savedSteps)
swiftApi().setSteps((steps as! Int) - GlobalVariables.savedSteps)
print((steps as! Int) - GlobalVariables.savedSteps)
swiftApi().setSteps((steps as! Int) - GlobalVariables.savedSteps)
let metersCount = (steps as? Double ?? 0.0) * 0.762
swiftApi().setMetersCount(metersCount)
let metersCount = (steps as? Double ?? 0.0) * 0.762
swiftApi().setMetersCount(metersCount)
let pacingEvent = swiftApi.HealthEventModel()
pacingEvent._meters = metersCount
SwiftEventBus.post("meters_sent", sender: pacingEvent)
let pacingEvent = swiftApi.HealthEventModel()
pacingEvent._meters = metersCount
SwiftEventBus.post("meters_sent", sender: pacingEvent)
print("=== MetersCount ===")
print(metersCount)
print("=== MetersCount ===")
print(metersCount)
let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview
swiftApi().setStepsWebview(newStepsWebview)
let newMetersWebview = Double(newStepsWebview) * 0.762
swiftApi().setMetersWebview(newMetersWebview)
let newStepsWebview = (steps as! Int) - GlobalVariables.savedStepsWebview
swiftApi().setStepsWebview(newStepsWebview)
let newMetersWebview = Double(newStepsWebview) * 0.762
swiftApi().setMetersWebview(newMetersWebview)
print("=== StepsWebview ===")
print(newStepsWebview)
print("=== MetersWebview ===")
print(newMetersWebview)
}
print("=== StepsWebview ===")
print(newStepsWebview)
print("=== MetersWebview ===")
print(newMetersWebview)
}
getStepsCallback(steps as? Int ?? 0)
getStepsCallback(steps as? Int ?? 0)
}
}
}
public func stopTrackingSteps() -> Void {
......@@ -159,6 +172,8 @@ public class swiftApi {
stopTimer()
GlobalVariables.trackingStepsEnabled = false
GlobalVariables.savedSteps = 0
swiftApi().setMetersCount(0.0)
......