Manos Chorianopoulos

add MarketPassViewController

...@@ -10,6 +10,18 @@ import RSBarcodes_Swift ...@@ -10,6 +10,18 @@ import RSBarcodes_Swift
10 import AVFoundation 10 import AVFoundation
11 11
12 @objc public class MarketPassViewController: UIViewController { 12 @objc public class MarketPassViewController: UIViewController {
13 + @IBOutlet weak var passContainerView: UIView!
14 + @IBOutlet weak var passTitleLabel: UILabel!
15 + @IBOutlet weak var passSubtitleLabel: UILabel!
16 + @IBOutlet weak var barcodeView: UIView!
17 + @IBOutlet weak var barcodeImage: UIImageView!
18 + @IBOutlet weak var barcodeImageHeight: NSLayoutConstraint!
19 + @IBOutlet weak var barcodeLabel: UILabel!
20 + @IBOutlet weak var couponsValueLabel: UILabel!
21 + @IBOutlet weak var smLogosView: UIView!
22 + @IBOutlet weak var mapButton: UIButton!
23 +
24 + let uiscreen: CGRect = UIScreen.main.bounds
13 25
14 public override func viewDidLoad() { 26 public override func viewDidLoad() {
15 super.viewDidLoad() 27 super.viewDidLoad()
...@@ -21,8 +33,13 @@ import AVFoundation ...@@ -21,8 +33,13 @@ import AVFoundation
21 // Setup the info button with an action 33 // Setup the info button with an action
22 setNavBarRightInfoButton() { 34 setNavBarRightInfoButton() {
23 // This closure is the action that will be executed when the info button is tapped 35 // This closure is the action that will be executed when the info button is tapped
24 -// self.presentInfoPopup() 36 +
37 + let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
38 + let vc = storyboard.instantiateViewController(withIdentifier: "MarketPassInfoViewController") as! SwiftWarplyFramework.MarketPassInfoViewController
39 + self.navigationController?.pushViewController(vc, animated: true)
25 } 40 }
41 +
42 + setupUI()
26 } 43 }
27 44
28 public override func viewWillAppear(_ animated: Bool) { 45 public override func viewWillAppear(_ animated: Bool) {
...@@ -33,4 +50,151 @@ import AVFoundation ...@@ -33,4 +50,151 @@ import AVFoundation
33 self.navigationController?.hideHairline() 50 self.navigationController?.hideHairline()
34 } 51 }
35 52
53 + // MARK: - Functions
54 + func setupUI() {
55 + passContainerView.backgroundColor = UIColor(rgb: 0x36B32B)
56 + passContainerView.layer.cornerRadius = 16.0
57 + // Add shadow
58 + passContainerView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.31).cgColor
59 + passContainerView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
60 + passContainerView.layer.shadowOpacity = 1.0
61 + passContainerView.layer.shadowRadius = 3.0
62 +
63 + passTitleLabel.text = "SUPERMARKET DEALS CARD"
64 +// passTitleLabel.font = UIFont(name: "BTCosmo-Bold", size: 23)
65 + passTitleLabel.font = UIFont(name: "BTCosmo-Bold", size: 22)
66 + passTitleLabel.textColor = .white
67 +
68 + passSubtitleLabel.text = "Χρησιμοποίησε τον κωδικό σου και κέρδισε έκπτωση στις αγορές σου!"
69 + passSubtitleLabel.font = UIFont(name: "PeridotPE-Regular", size: 17.0)
70 + passSubtitleLabel.textColor = .white
71 +
72 + barcodeView.backgroundColor = .white
73 + barcodeView.layer.cornerRadius = 16.0
74 + barcodeView.layer.borderWidth = 2
75 + barcodeView.layer.borderColor = UIColor(rgb: 0xDADDE4).cgColor
76 +
77 + //TODO: FIX
78 +// let barcodeString = constructBarcode(coupon: coupon) ?? ""
79 +// let barcodeString = coupon?._barcode ?? ""
80 + let barcodeString = "4006381333931"
81 + barcodeLabel.text = barcodeString
82 + barcodeLabel.font = UIFont(name: "PeridotPE-Regular", size: 19.0)
83 + barcodeLabel.textColor = UIColor(rgb: 0x212121)
84 +
85 + if let barcodeUIImage = RSUnifiedCodeGenerator.shared.generateCode(barcodeString, machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue, targetSize: CGSize(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.12)) {
86 +// if let barcodeUIImage = RSUnifiedCodeGenerator.shared.generateCode(barcodeString, machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue, targetSize: CGSize(width: 110, height: 83)) {
87 + barcodeImage.image = barcodeUIImage
88 +
89 + barcodeImageHeight.constant = self.uiscreen.height * 0.12
90 +// barcodeImageHeight.constant = 83
91 +
92 + } else {
93 + barcodeImageHeight.constant = 0
94 + }
95 +
96 + // TODO: FIX
97 + let couponsValueString = "30"
98 + let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white]
99 + let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white]
100 +
101 + let couponsValueNormalText1 = "Έχεις κουπόνια συνολικής αξίας "
102 + let couponsValueBoldText = couponsValueString + "€"
103 +
104 + let couponsValueAttributedString = NSMutableAttributedString(string:couponsValueNormalText1, attributes:attrRegular)
105 + let couponsValueBoldString = NSMutableAttributedString(string: couponsValueBoldText, attributes:attrBold)
106 +
107 + couponsValueAttributedString.append(couponsValueBoldString)
108 + couponsValueLabel.attributedText = couponsValueAttributedString
109 +
110 + mapButton.titleLabel?.font = UIFont(name: "PeridotPE-SBold", size: 16)
111 + mapButton.setTitle("Δες στο χάρτη", for: .normal)
112 + mapButton.setTitleColor(UIColor(rgb: 0x006D26), for: .normal)
113 + mapButton.layer.cornerRadius = 10.0
114 + mapButton.frame = CGRect(x: 0.0, y: 0.0, width: 148, height: 48)
115 +// mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 55)
116 +// mapButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 25, bottom: 0, right: 25)
117 + mapButton.backgroundColor = .clear
118 + mapButton.layer.borderWidth = 2
119 + mapButton.layer.borderColor = UIColor(rgb: 0x006D26).cgColor
120 +
121 + smLogosView.layer.cornerRadius = 16.0
122 + smLogosView.layer.maskedCorners = [ .layerMinXMaxYCorner, .layerMaxXMaxYCorner] // Bottom left, right corner radius
123 +
124 + // TODO: FIX - Replace with dynamic images
125 + let imageNames = ["active_code_logo_2", "active_code_logo_2", "active_code_logo_2"]
126 +// let images = imageNames.compactMap { UIImage(named: $0) }
127 + let images = imageNames.compactMap { UIImage(named: $0, in: MyEmptyClass.resourceBundle(), compatibleWith: nil) }
128 +
129 + // Create a horizontal stack view
130 + let stackView = UIStackView()
131 + stackView.axis = .horizontal
132 + stackView.spacing = 15 // Spacing between images
133 + stackView.alignment = .center
134 + stackView.distribution = .equalSpacing
135 +
136 + // Add UIImageViews to the stack view
137 + for image in images {
138 + let imageView = UIImageView(image: image)
139 + imageView.contentMode = .scaleAspectFit
140 + imageView.widthAnchor.constraint(equalToConstant: 40).isActive = true // Set a width
141 + imageView.heightAnchor.constraint(equalToConstant: 40).isActive = true // Set a height
142 + stackView.addArrangedSubview(imageView)
143 + }
144 +
145 + // Add the stack view to your main view
146 + smLogosView.addSubview(stackView)
147 +
148 + // Set up constraints for the stack view
149 + stackView.translatesAutoresizingMaskIntoConstraints = false
150 + NSLayoutConstraint.activate([
151 + stackView.leadingAnchor.constraint(equalTo: smLogosView.leadingAnchor, constant: 25),
152 + stackView.centerYAnchor.constraint(equalTo: smLogosView.centerYAnchor),
153 + ])
154 + }
155 +
156 + func constructBarcode() -> String? {
157 + // EAN 13 barcode construction
158 + //TODO: FIX
159 +// let couponString = coupon?._barcode ?? ""
160 + let couponString = "123456789101112"
161 +
162 + if (!couponString.isEmpty) {
163 + var checkDigit = 0;
164 + var result = 0;
165 +
166 + var fixedCouponCode = couponString;
167 + if (fixedCouponCode.count < 12) {
168 + let loops = 12 - fixedCouponCode.count;
169 + var zerosStr = "";
170 + for i in 0 ..< loops {
171 + zerosStr += "0"
172 + }
173 + // fixedCouponCode = zerosStr + fixedCouponCode;
174 + fixedCouponCode = fixedCouponCode + zerosStr;
175 + }
176 +
177 + var multiplier = 3;
178 + for idx in (0 ... (fixedCouponCode.count - 1)).reversed() {
179 + let curChar = fixedCouponCode[idx];
180 + result += (Int(curChar) ?? 0) * multiplier;
181 + multiplier = multiplier == 3 ? 1 : 3;
182 + }
183 + checkDigit = 10 - (result % 10);
184 +
185 + let barcodeStr = fixedCouponCode + String(checkDigit);
186 + return barcodeStr;
187 + }
188 +
189 + return ""
190 + }
191 +
192 + // MARK: - Actions
193 + @IBAction func mapButtonAction(_ sender: Any) {
194 + let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
195 + let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
196 + vc.campaignUrl = swiftApi().getMarketPassMapUrl()
197 + self.navigationController?.pushViewController(vc, animated: true)
198 + }
199 +
36 } 200 }
......
...@@ -170,7 +170,8 @@ extension WalletActiveCouponsScrollTableViewCell: UICollectionViewDataSource,UIC ...@@ -170,7 +170,8 @@ extension WalletActiveCouponsScrollTableViewCell: UICollectionViewDataSource,UIC
170 swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveMarketBanner")) 170 swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveMarketBanner"))
171 171
172 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self)) 172 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
173 - let vc = storyboard.instantiateViewController(withIdentifier: "UnifiedCouponsViewController") as! SwiftWarplyFramework.UnifiedCouponsViewController 173 + // let vc = storyboard.instantiateViewController(withIdentifier: "UnifiedCouponsViewController") as! SwiftWarplyFramework.UnifiedCouponsViewController
174 + let vc = storyboard.instantiateViewController(withIdentifier: "MarketPassViewController") as! SwiftWarplyFramework.MarketPassViewController
174 parent?.navigationController?.pushViewController(vc, animated: true) 175 parent?.navigationController?.pushViewController(vc, animated: true)
175 176
176 } else if (badgeId == "gfy") { 177 } else if (badgeId == "gfy") {
......
...@@ -9357,5 +9357,13 @@ public class swiftApi { ...@@ -9357,5 +9357,13 @@ public class swiftApi {
9357 } 9357 }
9358 } 9358 }
9359 9359
9360 + public func getMarketPassMapUrl() -> String {
9361 + let appUuid = swiftApi().getAppUuid()
9362 + if (appUuid == "f83dfde1145e4c2da69793abb2f579af") {
9363 + return "https://dev.supermarketdeals.eu/map"
9364 + } else {
9365 + return "https://supermarketdeals.eu/map"
9366 + }
9367 + }
9360 9368
9361 } 9369 }
......