Dimitris Togias

implement sections in MFYViewController

...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
38 A079367C2885F2F500064122 /* AnalysisHeaderViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079367B2885F2F500064122 /* AnalysisHeaderViewCell.swift */; }; 38 A079367C2885F2F500064122 /* AnalysisHeaderViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079367B2885F2F500064122 /* AnalysisHeaderViewCell.swift */; };
39 A079367E2885F60A00064122 /* AnalysisHeaderMessageViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079367D2885F60A00064122 /* AnalysisHeaderMessageViewCell.swift */; }; 39 A079367E2885F60A00064122 /* AnalysisHeaderMessageViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079367D2885F60A00064122 /* AnalysisHeaderMessageViewCell.swift */; };
40 A09DBCAE2888BA8100DD50B0 /* SharingHistoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A09DBCAD2888BA8100DD50B0 /* SharingHistoryViewController.swift */; }; 40 A09DBCAE2888BA8100DD50B0 /* SharingHistoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A09DBCAD2888BA8100DD50B0 /* SharingHistoryViewController.swift */; };
41 + A0C6F45228DAE36900B089D1 /* CampaignCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0C6F45128DAE36900B089D1 /* CampaignCategory.swift */; };
41 E6A77853282933340045BBA8 /* SwiftWarplyFramework.docc in Sources */ = {isa = PBXBuildFile; fileRef = E6A77852282933340045BBA8 /* SwiftWarplyFramework.docc */; }; 42 E6A77853282933340045BBA8 /* SwiftWarplyFramework.docc in Sources */ = {isa = PBXBuildFile; fileRef = E6A77852282933340045BBA8 /* SwiftWarplyFramework.docc */; };
42 E6A77854282933340045BBA8 /* SwiftWarplyFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = E6A77851282933340045BBA8 /* SwiftWarplyFramework.h */; settings = {ATTRIBUTES = (Public, ); }; }; 43 E6A77854282933340045BBA8 /* SwiftWarplyFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = E6A77851282933340045BBA8 /* SwiftWarplyFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
43 E6A778DF282933E60045BBA8 /* WarplyReactMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = E6A7785B282933E40045BBA8 /* WarplyReactMethods.m */; }; 44 E6A778DF282933E60045BBA8 /* WarplyReactMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = E6A7785B282933E40045BBA8 /* WarplyReactMethods.m */; };
...@@ -196,6 +197,7 @@ ...@@ -196,6 +197,7 @@
196 A079367B2885F2F500064122 /* AnalysisHeaderViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisHeaderViewCell.swift; sourceTree = "<group>"; }; 197 A079367B2885F2F500064122 /* AnalysisHeaderViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisHeaderViewCell.swift; sourceTree = "<group>"; };
197 A079367D2885F60A00064122 /* AnalysisHeaderMessageViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisHeaderMessageViewCell.swift; sourceTree = "<group>"; }; 198 A079367D2885F60A00064122 /* AnalysisHeaderMessageViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisHeaderMessageViewCell.swift; sourceTree = "<group>"; };
198 A09DBCAD2888BA8100DD50B0 /* SharingHistoryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SharingHistoryViewController.swift; sourceTree = "<group>"; }; 199 A09DBCAD2888BA8100DD50B0 /* SharingHistoryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SharingHistoryViewController.swift; sourceTree = "<group>"; };
200 + A0C6F45128DAE36900B089D1 /* CampaignCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CampaignCategory.swift; sourceTree = "<group>"; };
199 A9B7BE01A4E812DE49866EF8 /* Pods-SwiftWarplyFramework.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftWarplyFramework.debug.xcconfig"; path = "Target Support Files/Pods-SwiftWarplyFramework/Pods-SwiftWarplyFramework.debug.xcconfig"; sourceTree = "<group>"; }; 201 A9B7BE01A4E812DE49866EF8 /* Pods-SwiftWarplyFramework.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftWarplyFramework.debug.xcconfig"; path = "Target Support Files/Pods-SwiftWarplyFramework/Pods-SwiftWarplyFramework.debug.xcconfig"; sourceTree = "<group>"; };
200 B9EB8A451EF0C5AD75094EEE /* Pods-SwiftWarplyFramework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftWarplyFramework.release.xcconfig"; path = "Target Support Files/Pods-SwiftWarplyFramework/Pods-SwiftWarplyFramework.release.xcconfig"; sourceTree = "<group>"; }; 202 B9EB8A451EF0C5AD75094EEE /* Pods-SwiftWarplyFramework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftWarplyFramework.release.xcconfig"; path = "Target Support Files/Pods-SwiftWarplyFramework/Pods-SwiftWarplyFramework.release.xcconfig"; sourceTree = "<group>"; };
201 C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SwiftWarplyFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 203 C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SwiftWarplyFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; };
...@@ -386,6 +388,7 @@ ...@@ -386,6 +388,7 @@
386 isa = PBXGroup; 388 isa = PBXGroup;
387 children = ( 389 children = (
388 A07936722885E67400064122 /* AnalysisItem.swift */, 390 A07936722885E67400064122 /* AnalysisItem.swift */,
391 + A0C6F45128DAE36900B089D1 /* CampaignCategory.swift */,
389 ); 392 );
390 name = models; 393 name = models;
391 sourceTree = "<group>"; 394 sourceTree = "<group>";
...@@ -910,6 +913,7 @@ ...@@ -910,6 +913,7 @@
910 E6A77925282933E70045BBA8 /* UIProgressView+AFNetworking.m in Sources */, 913 E6A77925282933E70045BBA8 /* UIProgressView+AFNetworking.m in Sources */,
911 E6A77944282933E70045BBA8 /* AFSecurityPolicy.m in Sources */, 914 E6A77944282933E70045BBA8 /* AFSecurityPolicy.m in Sources */,
912 1EA1AF0A2835346A008998AA /* CouponsTableViewCell.swift in Sources */, 915 1EA1AF0A2835346A008998AA /* CouponsTableViewCell.swift in Sources */,
916 + A0C6F45228DAE36900B089D1 /* CampaignCategory.swift in Sources */,
913 E6A77A32282BA9C60045BBA8 /* CampaignViewController.swift in Sources */, 917 E6A77A32282BA9C60045BBA8 /* CampaignViewController.swift in Sources */,
914 E6A77917282933E60045BBA8 /* UIViewController+WLAdditions.m in Sources */, 918 E6A77917282933E60045BBA8 /* UIViewController+WLAdditions.m in Sources */,
915 1EA2BB792865BFE8003F2AB0 /* InboxTableViewCell.swift in Sources */, 919 1EA2BB792865BFE8003F2AB0 /* InboxTableViewCell.swift in Sources */,
......
1 +//
2 +// CampaignCategory.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Manos Chorianopoulos on 21/9/22.
6 +//
7 +
8 +import Foundation
9 +
10 +public class CampaignCategory: Codable {
11 +
12 + // attributes
13 + public var name: String?
14 + public var items: Array<swiftApi.CampaignItemModel>
15 +
16 + // initialization
17 + public init(_ name: String) {
18 + self.name = name
19 + self.items = [swiftApi.CampaignItemModel]()
20 + }
21 +}
...@@ -13,46 +13,22 @@ import SwiftEventBus ...@@ -13,46 +13,22 @@ import SwiftEventBus
13 @IBOutlet weak var mainView: UIView! 13 @IBOutlet weak var mainView: UIView!
14 @IBOutlet weak var tableView: UITableView! 14 @IBOutlet weak var tableView: UITableView!
15 15
16 + var categories: Array<CampaignCategory> = [CampaignCategory]()
17 +
16 public var campaigns:Array<swiftApi.CampaignItemModel> = swiftApi().mergeMFYCCMSLoyaltyCampaigns(campaigns: swiftApi().getCCMSLoyaltyCampaigns()) 18 public var campaigns:Array<swiftApi.CampaignItemModel> = swiftApi().mergeMFYCCMSLoyaltyCampaigns(campaigns: swiftApi().getCCMSLoyaltyCampaigns())
17 public var ccmsList:Array<swiftApi.LoyaltyContextualOfferModel> = swiftApi().getCCMSLoyaltyCampaigns() 19 public var ccmsList:Array<swiftApi.LoyaltyContextualOfferModel> = swiftApi().getCCMSLoyaltyCampaigns()
18 20
19 - 21 + // lifecycle
20 public override func viewDidLoad() { 22 public override func viewDidLoad() {
21 super.viewDidLoad() 23 super.viewDidLoad()
22 24
23 self.hidesBottomBarWhenPushed = true 25 self.hidesBottomBarWhenPushed = true
24 -
25 - if (ccmsList.count > 0) {
26 - for ccmsItem in ccmsList {
27 - if (((ccmsItem._loyaltyCampaignId == "") || (ccmsItem._loyaltyCampaignId == "NA")) && (ccmsItem._zone == "COSMOTE_APP_MORE4U")) {
28 - let newCampaign = swiftApi.CampaignItemModel()
29 - newCampaign._title = ccmsItem._title
30 - newCampaign._logo_url = ccmsItem._imageUrl
31 - newCampaign._subtitle = ccmsItem._subtitle
32 - newCampaign._message = ccmsItem._message
33 - newCampaign._ccms = ccmsItem
34 - campaigns.append(newCampaign)
35 - }
36 - }
37 - }
38 26
39 setBackButton() 27 setBackButton()
40 setNavigationTitle("MORE for YOU", "bold") 28 setNavigationTitle("MORE for YOU", "bold")
41 29
42 tableView.delegate = self 30 tableView.delegate = self
43 tableView.dataSource = self 31 tableView.dataSource = self
44 -
45 - SwiftEventBus.onMainThread(self, name: "ccms_retrieved") { result in
46 - print("===== SwiftEventBus ccms_retrieved =====")
47 - self.campaigns = swiftApi().mergeMFYCCMSLoyaltyCampaigns(campaigns: swiftApi().getCCMSLoyaltyCampaigns())
48 - self.tableView.reloadData()
49 - }
50 -
51 - SwiftEventBus.onMainThread(self, name: "campaigns_retrieved") { result in
52 - print("===== SwiftEventBus campaigns_retrieved =====")
53 - self.campaigns = swiftApi().mergeMFYCCMSLoyaltyCampaigns(campaigns: swiftApi().getCCMSLoyaltyCampaigns())
54 - self.tableView.reloadData()
55 - }
56 32
57 tableView.clipsToBounds = true 33 tableView.clipsToBounds = true
58 tableView.layer.cornerRadius = 30 34 tableView.layer.cornerRadius = 30
...@@ -65,24 +41,95 @@ import SwiftEventBus ...@@ -65,24 +41,95 @@ import SwiftEventBus
65 mainView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius 41 mainView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
66 mainView.backgroundColor = UIColor(red: 0.22, green: 0.32, blue: 0.40, alpha: 1.00) 42 mainView.backgroundColor = UIColor(red: 0.22, green: 0.32, blue: 0.40, alpha: 1.00)
67 43
44 + // data
45 + SwiftEventBus.onMainThread(self, name: "ccms_retrieved") { result in
46 + print("===== SwiftEventBus ccms_retrieved =====")
47 + self.campaigns = swiftApi().mergeMFYCCMSLoyaltyCampaigns(campaigns: swiftApi().getCCMSLoyaltyCampaigns())
48 + self.loadData()
49 + }
50 +
51 + SwiftEventBus.onMainThread(self, name: "campaigns_retrieved") { result in
52 + print("===== SwiftEventBus campaigns_retrieved =====")
53 + self.campaigns = swiftApi().mergeMFYCCMSLoyaltyCampaigns(campaigns: swiftApi().getCCMSLoyaltyCampaigns())
54 + self.loadData()
55 + }
56 +
57 + loadData()
68 } 58 }
69 59
60 + func loadData() {
61 +
62 + var newData = [CampaignCategory]()
63 +
64 + // parse campaigns
65 + var campaignsDict = [String:CampaignCategory]()
66 + for item in campaigns {
67 + guard let title = item._category_title else {
68 + continue
69 + }
70 +
71 + if (title.isEmpty) {
72 + continue
73 + }
74 +
75 + var category = campaignsDict[title]
76 + if (category == nil) {
77 + category = CampaignCategory(title)
78 + campaignsDict[title] = category
79 + newData.append(category!)
80 + }
81 +
82 + category?.items.append(item)
83 + }
84 +
85 + // parse ccms
86 + let category = CampaignCategory("ΑΛΛΕΣ")
87 + for ccmsItem in ccmsList {
88 + if (((ccmsItem._loyaltyCampaignId == "") || (ccmsItem._loyaltyCampaignId == "NA")) && (ccmsItem._zone == "COSMOTE_APP_MORE4U")) {
89 + let newCampaign = swiftApi.CampaignItemModel()
90 + newCampaign._title = ccmsItem._title
91 + newCampaign._logo_url = ccmsItem._imageUrl
92 + newCampaign._subtitle = ccmsItem._subtitle
93 + newCampaign._message = ccmsItem._message
94 + newCampaign._ccms = ccmsItem
95 + category.items.append(newCampaign)
96 + }
97 + }
98 +
99 + newData.append(category)
100 +
101 + // reload
102 + categories = newData
103 + self.tableView.reloadData()
104 + }
70 } 105 }
71 106
72 // MARK: - TableView 107 // MARK: - TableView
73 extension MFYViewController: UITableViewDelegate, UITableViewDataSource{ 108 extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
74 109
75 public func numberOfSections(in tableView: UITableView) -> Int { 110 public func numberOfSections(in tableView: UITableView) -> Int {
76 - return 1 111 + return self.categories.count
77 } 112 }
78 113
79 public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 114 public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
80 - return self.campaigns.count 115 + return self.categories[section].items.count
81 } 116 }
82 117
83 public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 118 public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
84 return 220.0 + 10.0 119 return 220.0 + 10.0
85 -// return UITableViewAutomaticDimension 120 + }
121 +
122 + public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
123 + let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 60))
124 + view.backgroundColor = .clear
125 +
126 + let titleLabel = UILabel(frame: CGRect(x: 15, y: 20, width: view.frame.width - 15, height: 40))
127 + titleLabel.font = UIFont(name: "PFSquareSansPro-Bold", size: 21)
128 + titleLabel.textColor = .white
129 + titleLabel.text = categories[section].name
130 +
131 + view.addSubview(titleLabel)
132 + return view
86 } 133 }
87 134
88 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 135 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
......
...@@ -781,6 +781,8 @@ public class swiftApi { ...@@ -781,6 +781,8 @@ public class swiftApi {
781 private var ccms: LoyaltyContextualOfferModel? 781 private var ccms: LoyaltyContextualOfferModel?
782 private var carousel: String? 782 private var carousel: String?
783 783
784 + private var category_title: String?
785 +
784 public init() { 786 public init() {
785 self.index_url = "" 787 self.index_url = ""
786 self.logo_url = "" 788 self.logo_url = ""
...@@ -828,6 +830,7 @@ public class swiftApi { ...@@ -828,6 +830,7 @@ public class swiftApi {
828 self.badge = extra_fields["badge"] as? String? ?? "" 830 self.badge = extra_fields["badge"] as? String? ?? ""
829 self.type = extra_fields["type"] as? String? ?? "" 831 self.type = extra_fields["type"] as? String? ?? ""
830 self.carousel = extra_fields["carousel"] as? String? ?? "false" 832 self.carousel = extra_fields["carousel"] as? String? ?? "false"
833 + self.category_title = extra_fields["category_title"] as? String ?? ""
831 } else { 834 } else {
832 self.subcategory = "" 835 self.subcategory = ""
833 self.loyaltyCampaignId = "" 836 self.loyaltyCampaignId = ""
...@@ -836,6 +839,7 @@ public class swiftApi { ...@@ -836,6 +839,7 @@ public class swiftApi {
836 self.badge = "" 839 self.badge = ""
837 self.type = "" 840 self.type = ""
838 self.carousel = "false" 841 self.carousel = "false"
842 + self.category_title = ""
839 } 843 }
840 844
841 // let extra_fields = dictionary["extra_fields"] as AnyObject 845 // let extra_fields = dictionary["extra_fields"] as AnyObject
...@@ -1027,6 +1031,12 @@ public class swiftApi { ...@@ -1027,6 +1031,12 @@ public class swiftApi {
1027 self.carousel = newValue 1031 self.carousel = newValue
1028 } 1032 }
1029 } 1033 }
1034 +
1035 + public var _category_title: String? {
1036 + get { // getter
1037 + return self.category_title
1038 + }
1039 + }
1030 } 1040 }
1031 1041
1032 public class CampaignDataModel { 1042 public class CampaignDataModel {
......