Dimitris Togias

fix implementation details

...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 1EBE97212865EE460080EFF7 /* MFYInboxTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */; }; 19 1EBE97212865EE460080EFF7 /* MFYInboxTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */; };
20 1EBF5F072840E13F00B8B17F /* SwiftEventBus in Frameworks */ = {isa = PBXBuildFile; productRef = 1EBF5F062840E13F00B8B17F /* SwiftEventBus */; }; 20 1EBF5F072840E13F00B8B17F /* SwiftEventBus in Frameworks */ = {isa = PBXBuildFile; productRef = 1EBF5F062840E13F00B8B17F /* SwiftEventBus */; };
21 7630AD9A6242D60846D6750C /* Pods_SwiftWarplyFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */; }; 21 7630AD9A6242D60846D6750C /* Pods_SwiftWarplyFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */; };
22 + A04D31DE288FF670000E43B5 /* HistoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A04D31DD288FF670000E43B5 /* HistoryViewController.swift */; };
22 A079366E2885D07700064122 /* AnalysisChildViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079366D2885D07700064122 /* AnalysisChildViewController.swift */; }; 23 A079366E2885D07700064122 /* AnalysisChildViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079366D2885D07700064122 /* AnalysisChildViewController.swift */; };
23 A07936702885D95600064122 /* AnalysisItemViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079366F2885D95600064122 /* AnalysisItemViewCell.swift */; }; 24 A07936702885D95600064122 /* AnalysisItemViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079366F2885D95600064122 /* AnalysisItemViewCell.swift */; };
24 A07936732885E67400064122 /* AnalysisItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A07936722885E67400064122 /* AnalysisItem.swift */; }; 25 A07936732885E67400064122 /* AnalysisItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A07936722885E67400064122 /* AnalysisItem.swift */; };
...@@ -165,6 +166,7 @@ ...@@ -165,6 +166,7 @@
165 1EB5F4C728536FD60016F36E /* StepsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepsViewController.swift; sourceTree = "<group>"; }; 166 1EB5F4C728536FD60016F36E /* StepsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepsViewController.swift; sourceTree = "<group>"; };
166 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoyaltyAnalysisViewController.swift; sourceTree = "<group>"; }; 167 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoyaltyAnalysisViewController.swift; sourceTree = "<group>"; };
167 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFYInboxTableViewCell.swift; sourceTree = "<group>"; }; 168 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFYInboxTableViewCell.swift; sourceTree = "<group>"; };
169 + A04D31DD288FF670000E43B5 /* HistoryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HistoryViewController.swift; sourceTree = "<group>"; };
168 A079366D2885D07700064122 /* AnalysisChildViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisChildViewController.swift; sourceTree = "<group>"; }; 170 A079366D2885D07700064122 /* AnalysisChildViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisChildViewController.swift; sourceTree = "<group>"; };
169 A079366F2885D95600064122 /* AnalysisItemViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisItemViewCell.swift; sourceTree = "<group>"; }; 171 A079366F2885D95600064122 /* AnalysisItemViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisItemViewCell.swift; sourceTree = "<group>"; };
170 A07936722885E67400064122 /* AnalysisItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisItem.swift; sourceTree = "<group>"; }; 172 A07936722885E67400064122 /* AnalysisItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisItem.swift; sourceTree = "<group>"; };
...@@ -333,6 +335,7 @@ ...@@ -333,6 +335,7 @@
333 A079367A2885F2D100064122 /* cells */, 335 A079367A2885F2D100064122 /* cells */,
334 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */, 336 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */,
335 A079366D2885D07700064122 /* AnalysisChildViewController.swift */, 337 A079366D2885D07700064122 /* AnalysisChildViewController.swift */,
338 + A04D31DD288FF670000E43B5 /* HistoryViewController.swift */,
336 A09DBCAD2888BA8100DD50B0 /* SharingHistoryViewController.swift */, 339 A09DBCAD2888BA8100DD50B0 /* SharingHistoryViewController.swift */,
337 ); 340 );
338 name = analysis; 341 name = analysis;
...@@ -888,6 +891,7 @@ ...@@ -888,6 +891,7 @@
888 E6A7791A282933E60045BBA8 /* WLAPPActionHandler.m in Sources */, 891 E6A7791A282933E60045BBA8 /* WLAPPActionHandler.m in Sources */,
889 E6A778E1282933E60045BBA8 /* CouponViewController.swift in Sources */, 892 E6A778E1282933E60045BBA8 /* CouponViewController.swift in Sources */,
890 E6A77924282933E70045BBA8 /* NSString+SSToolkitAdditions.m in Sources */, 893 E6A77924282933E70045BBA8 /* NSString+SSToolkitAdditions.m in Sources */,
894 + A04D31DE288FF670000E43B5 /* HistoryViewController.swift in Sources */,
891 E6A7792A282933E70045BBA8 /* AFNetworkActivityIndicatorManager.m in Sources */, 895 E6A7792A282933E70045BBA8 /* AFNetworkActivityIndicatorManager.m in Sources */,
892 E6A77914282933E60045BBA8 /* WLUserManager.m in Sources */, 896 E6A77914282933E60045BBA8 /* WLUserManager.m in Sources */,
893 1EB236AF28816CAC0063777A /* NumbersTableViewCell.swift in Sources */, 897 1EB236AF28816CAC0063777A /* NumbersTableViewCell.swift in Sources */,
......
...@@ -14,10 +14,15 @@ class AnalysisHeaderMessageViewCell: UITableViewCell { ...@@ -14,10 +14,15 @@ class AnalysisHeaderMessageViewCell: UITableViewCell {
14 @IBOutlet weak var messageLabel: UILabel! 14 @IBOutlet weak var messageLabel: UILabel!
15 @IBOutlet weak var titleLabel: UILabel! 15 @IBOutlet weak var titleLabel: UILabel!
16 16
17 + public var loyaltyBadge:swiftApi.LoyaltyBadgeModel = swiftApi().getLoyaltyBadge()
18 +
17 // lifecycle 19 // lifecycle
18 override func awakeFromNib() { 20 override func awakeFromNib() {
19 super.awakeFromNib() 21 super.awakeFromNib()
20 22
23 + // image
24 + itemImage.image = UIImage(named: "ic_gift_circle", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil)
25 +
21 // title 26 // title
22 titleLabel.textColor = UIColor(rgb: 0x435563) 27 titleLabel.textColor = UIColor(rgb: 0x435563)
23 titleLabel.text = "Αναλυτικά:" 28 titleLabel.text = "Αναλυτικά:"
...@@ -26,7 +31,12 @@ class AnalysisHeaderMessageViewCell: UITableViewCell { ...@@ -26,7 +31,12 @@ class AnalysisHeaderMessageViewCell: UITableViewCell {
26 messageLabel.textColor = UIColor(rgb: 0x435563) 31 messageLabel.textColor = UIColor(rgb: 0x435563)
27 messageLabel.layer.borderWidth = 1.0 32 messageLabel.layer.borderWidth = 1.0
28 messageLabel.layer.borderColor = UIColor(rgb: 0xB2CE69).cgColor 33 messageLabel.layer.borderColor = UIColor(rgb: 0xB2CE69).cgColor
29 - messageLabel.text = "Μέχρι τώρα έχεις κερδίσει 20,00€ σε προσφορές από 3 κουπόνια!" 34 +
35 + let totalCouponDiscount = Float(round(100 * loyaltyBadge._value) / 100)
36 + var totalCouponDiscountString = "0"
37 + totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
38 +
39 + messageLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(loyaltyBadge._couponCount) + " κουπόνια!"
30 } 40 }
31 } 41 }
32 42
......
...@@ -17,6 +17,9 @@ class AnalysisHeaderViewCell: UITableViewCell { ...@@ -17,6 +17,9 @@ class AnalysisHeaderViewCell: UITableViewCell {
17 override func awakeFromNib() { 17 override func awakeFromNib() {
18 super.awakeFromNib() 18 super.awakeFromNib()
19 19
20 + // image
21 + itemImage.image = UIImage(named: "ic_gift_circle", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil)
22 +
20 // title 23 // title
21 titleLabel.textColor = UIColor(rgb: 0x435563) 24 titleLabel.textColor = UIColor(rgb: 0x435563)
22 titleLabel.text = "Αναλυτικά:" 25 titleLabel.text = "Αναλυτικά:"
......
...@@ -34,27 +34,41 @@ class AnalysisItemViewCell: UITableViewCell { ...@@ -34,27 +34,41 @@ class AnalysisItemViewCell: UITableViewCell {
34 } 34 }
35 35
36 extension AnalysisItemViewCell { 36 extension AnalysisItemViewCell {
37 - func configureCell(item: swiftApi.SharingCouponModel) { 37 + func configureCell(item: swiftApi.SharingCouponModel) {
38 - 38 +
39 - // TODO: this is not optimal. we need a static date formatter. we cannot instantiate a new object each time we render a new item. 39 + dateLabel.text = item._date
40 - let dateFormatter = DateFormatter()
41 - dateFormatter.dateFormat = "dd-MM-yyyy"
42 -
43 - if let date = item.date {
44 - let dateString = dateFormatter.string(from: date)
45 - dateLabel.text = dateString
46 - } else {
47 - dateLabel.text = ""
48 - }
49 -
50 //itemImage.image = 40 //itemImage.image =
51 - titleLabel.text = item.name 41 + titleLabel.text = item._name
52 - priceLabel.text = String(format: "%.2f€", item.discount) 42 +
43 + let priceFloat = Float(round(100 * (Float(item._discount) ?? 0.0)) / 100)
44 + var priceString = "0"
45 + priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
46 + priceLabel.text = priceString + "€"
53 47
54 - if ("sent" == item.sharingType) { 48 + if ("sent" == item._sharing_type) {
55 - subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς @%", "69740000000") 49 + subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς " + item._receiver_msisdn)
56 - } else if ("received" == item.sharingType) { 50 + } else if ("received" == item._sharing_type) {
57 - subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από @%", "69740000000") 51 + subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από " + item._sender_msisdn)
58 } 52 }
59 } 53 }
54 +
55 + func configureCell(item: swiftApi.CouponItemModel) {
56 +
57 +// COUPONSET: desc, img_preview, name, terms
58 +// COUPON: coupon, expiration, discount, status
59 +
60 + let couponSetData: swiftApi.CouponSetItemModel? = item.couponset_data
61 +
62 + dateLabel.text = item.expiration ?? "" // TODO: change
63 + itemImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache())
64 + titleLabel.text = couponSetData?.name ?? ""
65 +
66 + let priceFloat = Float(round(100 * (Float(item.discount ?? "") ?? 0.0)) / 100)
67 + var priceString = "0"
68 + priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
69 + priceLabel.text = priceString + "€"
70 +
71 + subtitleLabel.text = couponSetData?.short_description ?? ""
72 +
73 + }
60 } 74 }
......
1 +//
2 +// HistoryViewController.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Manos Chorianopoulos on 18/7/22.
6 +//
7 +
8 +import UIKit
9 +
10 +class HistoryViewController: AnalysisChildViewController {
11 +
12 + var loading: Bool = false
13 + var items: Array<swiftApi.CouponItemModel> = swiftApi().getCouponList()
14 +
15 + // TODO: remove this when configuring model
16 + let hasMessage = true
17 +
18 + // lifecycle
19 + override func viewDidLoad() {
20 +
21 + super.viewDidLoad()
22 +
23 + self.refreshControl = UIRefreshControl()
24 + self.refreshControl?.addTarget(self, action: #selector(handleRefresh(_:)), for: .valueChanged)
25 +
26 + handleRefresh(self.refreshControl!)
27 + }
28 +
29 + // mvp
30 + @objc func load() {
31 +
32 + if (loading) {
33 + return;
34 + }
35 +
36 + showLoading()
37 +
38 + items = swiftApi().getOldCouponList()
39 + showContent()
40 + self.tableView.reloadData()
41 + }
42 +
43 + private func showLoading() {
44 +
45 + loading = true
46 + if (self.refreshControl!.isRefreshing) {
47 + return;
48 + }
49 +
50 + self.refreshControl!.beginRefreshing()
51 + }
52 +
53 + private func showError() {
54 + }
55 +
56 + private func showContent() {
57 +
58 + loading = false
59 + self.refreshControl!.endRefreshing()
60 + }
61 +
62 + // private
63 + func responseCallback (_ data: Array<swiftApi.CouponItemModel>?) -> Void {
64 +
65 + self.items = data!
66 + showContent()
67 + DispatchQueue.main.async {
68 + self.tableView.reloadData()
69 + }
70 + }
71 +
72 + @objc func handleRefresh(_ refreshControl: UIRefreshControl) {
73 +
74 + self.perform(_: #selector(load), with: nil, afterDelay: 0.5)
75 + }
76 +
77 + // MARK: - Table view data source
78 + override func numberOfSections(in tableView: UITableView) -> Int {
79 + return 2
80 + }
81 +
82 + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
83 + if (section == 0) {
84 + return 1;
85 + }
86 +
87 + return items.count
88 + }
89 +
90 + override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
91 + if (indexPath.section == 0) {
92 + return hasMessage ? 380.0 : 280
93 + }
94 +
95 + return 140.0
96 + }
97 +
98 + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
99 +
100 + // header
101 + if (indexPath.section == 0) {
102 + if (hasMessage) {
103 + return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderMessageViewCell", for: indexPath) as! AnalysisHeaderMessageViewCell
104 + }
105 +
106 + return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderViewCell", for: indexPath) as! AnalysisHeaderViewCell
107 + }
108 +
109 + let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! AnalysisItemViewCell
110 + cell.configureCell(item: items[indexPath.row])
111 +
112 + return cell
113 + }
114 +}
...@@ -21,7 +21,7 @@ import RESegmentedControl ...@@ -21,7 +21,7 @@ import RESegmentedControl
21 21
22 // setup view 22 // setup view
23 setBackButton() 23 setBackButton()
24 - setNavigationTitle("Analysis") 24 + setNavigationTitle("Ανάλυση")
25 25
26 // tab 26 // tab
27 let titles = ["Εξαργυρωμένα", "Μοιρασμένα δώρα"] 27 let titles = ["Εξαργυρωμένα", "Μοιρασμένα δώρα"]
...@@ -41,24 +41,28 @@ import RESegmentedControl ...@@ -41,24 +41,28 @@ import RESegmentedControl
41 addChild(pageController) 41 addChild(pageController)
42 contentView.addSubview(pageController.view) 42 contentView.addSubview(pageController.view)
43 pageController .didMove(toParent: self) 43 pageController .didMove(toParent: self)
44 +
45 + let analysisVC = self.viewControllerAt(0)
46 + pageController.setViewControllers([analysisVC!], direction:.forward, animated:false)
44 } 47 }
45 48
46 //////////////////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////////////////
47 private func viewControllerAt(_ index:Int) -> AnalysisChildViewController? 50 private func viewControllerAt(_ index:Int) -> AnalysisChildViewController?
48 { 51 {
52 + let storyboard = UIStoryboard(name: "Main", bundle: nil)
53 +
49 if (index == 1) { 54 if (index == 1) {
50 - let analysisVC = SharingHistoryViewController() 55 + let analysisVC = storyboard.instantiateViewController(withIdentifier:"SharingHistoryViewController") as! SharingHistoryViewController
51 analysisVC.index = index; 56 analysisVC.index = index;
52 57
53 return analysisVC; 58 return analysisVC;
54 } 59 }
55 - 60 +
56 - let analysisVC = AnalysisChildViewController() 61 + let analysisVC = storyboard.instantiateViewController(withIdentifier:"HistoryViewController") as! HistoryViewController
57 analysisVC.index = index; 62 analysisVC.index = index;
58 - 63 +
59 return analysisVC; 64 return analysisVC;
60 } 65 }
61 -
62 } 66 }
63 67
64 // MARK: - PageViewController 68 // MARK: - PageViewController
......
...@@ -13,7 +13,7 @@ class SharingHistoryViewController: AnalysisChildViewController { ...@@ -13,7 +13,7 @@ class SharingHistoryViewController: AnalysisChildViewController {
13 var items: Array<swiftApi.SharingCouponModel> = Array() 13 var items: Array<swiftApi.SharingCouponModel> = Array()
14 14
15 // TODO: remove this when configuring model 15 // TODO: remove this when configuring model
16 - let hasMessage = true 16 + let hasMessage = false
17 17
18 // lifecycle 18 // lifecycle
19 override func viewDidLoad() { 19 override func viewDidLoad() {
...@@ -35,7 +35,7 @@ class SharingHistoryViewController: AnalysisChildViewController { ...@@ -35,7 +35,7 @@ class SharingHistoryViewController: AnalysisChildViewController {
35 35
36 showLoading() 36 showLoading()
37 37
38 - // TODO: Implement API call 38 + swiftApi().getSharingHistoryAsync(responseCallback)
39 } 39 }
40 40
41 private func showLoading() { 41 private func showLoading() {
...@@ -53,7 +53,7 @@ class SharingHistoryViewController: AnalysisChildViewController { ...@@ -53,7 +53,7 @@ class SharingHistoryViewController: AnalysisChildViewController {
53 53
54 private func showContent() { 54 private func showContent() {
55 55
56 - loading = true 56 + loading = false
57 self.refreshControl!.endRefreshing() 57 self.refreshControl!.endRefreshing()
58 } 58 }
59 59
...@@ -90,7 +90,7 @@ class SharingHistoryViewController: AnalysisChildViewController { ...@@ -90,7 +90,7 @@ class SharingHistoryViewController: AnalysisChildViewController {
90 return hasMessage ? 380.0 : 280 90 return hasMessage ? 380.0 : 280
91 } 91 }
92 92
93 - return 160.0 93 + return 140.0
94 } 94 }
95 95
96 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 96 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
......