Manos Chorianopoulos

Add setVouchersFetched, vouchers_banner event

......@@ -76,6 +76,10 @@ import SwiftEventBus
var unifiedCouponsDiscount:Float = 0.0
var forYouExpanded: Bool = false;
// TODO: Add SwiftEventBus.post("vouchers_banner_pressed") on Voucher Banner press
public override func viewDidLoad() {
super.viewDidLoad()
......@@ -103,6 +107,22 @@ import SwiftEventBus
}
}
SwiftEventBus.onBackgroundThread(self, name: "vouchers_fetched") { result in
DispatchQueue.main.async {
print("=== vouchers_fetched event ===")
// TODO: hide Spinner
if (swiftApi().getShowVouchersBanner() == "true") {
// TODO: show Vouchers Banner
} else {
// TODO: hide Vouchers Banner
}
}
}
// TODO: DELETE ===>
// let coupon = swiftApi.ActiveDFYCouponModel()
// coupon._value = "12"
......@@ -462,6 +482,16 @@ import SwiftEventBus
// TODO: DELETE if emptyView is needed again
emptyView.isHidden = true
emptyViewHeight.constant = 0
if (swiftApi().getShowVouchersBanner() == "") {
// TODO: show Spinner
// TODO: hide Vouchers Banner
} else if (swiftApi().getShowVouchersBanner() == "true") {
// TODO: show Vouchers Banner
} else {
// TODO: hide Vouchers Banner
}
}
public override func viewWillAppear(_ animated: Bool) {
......@@ -530,8 +560,13 @@ import SwiftEventBus
self.stopTimer()
self.navigationController?.navigationBar.layer.shadowOpacity = 0.0
if self.isMovingFromParent {
// Clear ShowVouchersBanner state
swiftApi().clearShowVouchersBanner();
}
}
public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
......
......@@ -35,6 +35,7 @@ public struct GlobalVariables {
static var merchantList: Array<swiftApi.MerchantModel> = []
static var trackingStepsEnabled: Bool = false
static var carouselList: Array<swiftApi.CampaignItemModel> = []
static var showVouchersBanner: String = "" // We use String in order to have 3 different states: "", "true", "false"
}
var timer: DispatchSourceTimer?
......@@ -167,6 +168,32 @@ public class swiftApi {
}
public func setShowVouchersBanner(_ newValue: String) {
GlobalVariables.showVouchersBanner = newValue
}
public func getShowVouchersBanner() -> String {
return GlobalVariables.showVouchersBanner
}
public func clearShowVouchersBanner() -> Void {
GlobalVariables.showVouchersBanner = ""
}
public func setVouchersFetched(_ success: Bool) -> Void {
if (success == true) {
setShowVouchersBanner("true")
} else {
setShowVouchersBanner("false")
}
SwiftEventBus.post("vouchers_fetched")
}
public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
if (GlobalVariables.trackingStepsEnabled == false) {
......