Manos Chorianopoulos

Added CarouselList functions and functionality

......@@ -28,6 +28,7 @@ public struct GlobalVariables {
static var metersWebview: Double = 0.0
static var merchantList: Array<swiftApi.MerchantModel> = []
static var trackingStepsEnabled: Bool = false
static var carouselList: Array<swiftApi.CampaignItemModel> = []
}
var timer: DispatchSourceTimer?
......@@ -102,6 +103,19 @@ public class swiftApi {
GlobalVariables.trackingStepsEnabled = newValue
}
public func setCarouselList(_ campaigns: Array<CampaignItemModel>) -> Void {
// let sortedCampaigns = campaigns.sorted {
// ($0._sorting ?? 0) < ($1._sorting ?? 0)
// }
GlobalVariables.carouselList = campaigns
}
public func getCarouselList() -> Array<CampaignItemModel> {
return GlobalVariables.carouselList
}
public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
......@@ -764,6 +778,7 @@ public class swiftApi {
public var type: String?
public var sorting: Int?
private var ccms: LoyaltyContextualOfferModel?
private var carousel: String?
public init() {
self.index_url = ""
......@@ -786,6 +801,7 @@ public class swiftApi {
self.type = ""
self.sorting = 0
self.ccms = nil
self.carousel = "false"
}
public init(dictionary: [String: Any]) {
......@@ -810,6 +826,7 @@ public class swiftApi {
self.ccms_offer = extra_fields["ccms_offer"] as? String? ?? "false"
self.badge = extra_fields["badge"] as? String? ?? ""
self.type = extra_fields["type"] as? String? ?? ""
self.carousel = extra_fields["carousel"] as? String? ?? "false"
} else {
self.subcategory = ""
self.loyaltyCampaignId = ""
......@@ -817,6 +834,7 @@ public class swiftApi {
self.ccms_offer = "false"
self.badge = ""
self.type = ""
self.carousel = "false"
}
// let extra_fields = dictionary["extra_fields"] as AnyObject
......@@ -999,6 +1017,15 @@ public class swiftApi {
self.ccms = newValue
}
}
public var _carousel: String? {
get { // getter
return self.carousel
}
set(newValue) { //setter
self.carousel = newValue
}
}
}
public class CampaignDataModel {
......@@ -1067,6 +1094,7 @@ public class swiftApi {
func campaignsCallback(_ campaignsData: [AnyHashable: Any]?) -> Void {
var campaignsArray:Array<CampaignItemModel> = []
var carouselArray:Array<CampaignItemModel> = []
if let responseDataDictionary = campaignsData as? [String: AnyObject] {
......@@ -1091,7 +1119,13 @@ public class swiftApi {
swiftApi().setUniqueCampaignList(campaignsArray)
SwiftEventBus.post("campaigns_retrieved")
carouselArray = campaignsArray.filter {
let tempCampaign = $0
let isCarouselItem = (tempCampaign._carousel != nil) && (tempCampaign._carousel == "true")
return (isCarouselItem)
}
swiftApi().setCarouselList(carouselArray)
var filteredCampaigns = campaignsArray.filter {
let tempCampaign = $0
......@@ -1110,6 +1144,8 @@ public class swiftApi {
}
getCampaignsCallback(sortedCampaigns);
SwiftEventBus.post("campaigns_retrieved")
})
} else {
......