PopupMerchantsViewController.swift
5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// PopupSMMerchantsViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 17/10/24.
//
import UIKit
class PopupMerchantsViewController: UIViewController {
@IBOutlet weak var popupView: UIView!
@IBOutlet weak var headerLabel: UILabel!
@IBOutlet weak var closeButton: UIButton!
@IBOutlet weak var tableView: DynamicSizeTableView!
public var coupon: swiftApi.CouponItemModel?
public var headerText: String? = "Βρες το προϊον στα supermarket"
public var buttonTitle: String? = "Βρες το"
public var buttonIcon: String?
public var footerText: String? = "Η διαθεσιμότητα ενδέχεται να διαφέρει ανάλογα με την τοποθεσία."
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.contentInset.top = 40
popupView.clipsToBounds = true
popupView.layer.cornerRadius = 16
popupView.layer.maskedCorners = [ .layerMinXMinYCorner, .layerMaxXMinYCorner] // Top left, right corner radius
closeButton.setImage(UIImage(named: "ic_close_3.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
closeButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
// self.tableView.reloadData()
self.tableView.invalidateIntrinsicContentSize()
self.headerLabel.text = self.headerText
headerLabel.font = UIFont(name: "BTCosmo-Bold", size: 18)
headerLabel.textColor = UIColor(rgb: 0x000000)
}
// MARK: - UIButton Actions
@IBAction func closeButtonAction(_ sender: Any) {
self.dismiss(animated: true, completion: {})
}
}
// MARK: - TableView
extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSource{
public func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 0) {
return self.merchantList.count
} else if (section == 1) {
return 1
} else {
return 0
}
}
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (indexPath.section == 0) {
return 56.0 + 32.0
// return UITableViewAutomaticDimension
} else if (indexPath.section == 1) {
return 50.0
} else {
return 0.0
}
// return UITableViewAutomaticDimension
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 0) {
let cell = tableView.dequeueReusableCell(withIdentifier: "MerchantTableViewCellId", for: indexPath) as! MerchantTableViewCell
cell.configureCell(merchant: merchantList[indexPath.row], buttonTitle: self.buttonTitle ?? "Βρες το", iconImage: buttonIcon)
// Set the delegate to self
cell.delegate = self
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "PopupMerchantsFooterTableViewCellId", for: indexPath) as! PopupMerchantsFooterTableViewCell
cell.configureCell(title: self.footerText ?? "Η διαθεσιμότητα ενδέχεται να διαφέρει ανάλογα με την τοποθεσία.")
return cell
}
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// self.dismiss(animated: true, completion: {})
// TODO: DELETE LOGS
print(" didSelectRowAt Button tapped in row \(indexPath.row)")
// TODO: Open merchant url
// Logs
// let couponSetData: swiftApi.CouponSetItemModel? = coupons[indexPath.row].couponset_data
// print("Coupon clicked: " + (coupons[indexPath.row].coupon ?? ""))
// print("Coupon Name clicked: " + (couponSetData?.name ?? ""))
// print("Coupon Description clicked: " + (couponSetData?.short_description ?? ""))
// print("Coupon Expiration clicked: " + (coupons[indexPath.row].expiration ?? ""))
}
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return nil
}
public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.0
}
public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
// return CGFloat.leastNormalMagnitude
return 0.0
}
public func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return nil
}
}
// MARK: - MerchantTableViewCellDelegate
extension PopupMerchantsViewController: MerchantTableViewCellDelegate {
func didTapButton(in cell: MerchantTableViewCell) {
// Find the index path of the cell where the button was tapped
if let indexPath = tableView.indexPath(for: cell) {
// TODO: DELETE LOGS
print("Button tapped in row \(indexPath.row)")
print("Button tapped cell: \(cell)")
// Handle the button tap action here
}
}
}