Manos Chorianopoulos

UnifiedCouponBarcodeVC refactor

...@@ -92,4 +92,36 @@ import UIKit ...@@ -92,4 +92,36 @@ import UIKit
92 expirationLabel.text = "Ισχύει έως "+(coupon.expiration ?? "") 92 expirationLabel.text = "Ισχύει έως "+(coupon.expiration ?? "")
93 } 93 }
94 94
95 + func configureCell(coupon: swiftApi.CouponItemModel, isMarket: Bool) {
96 +// COUPONSET: desc, img_preview, name, terms, merchant_uuid
97 +// COUPON: coupon, expiration, discount, status
98 +// MERCHANT: _img_preview,_admin_name
99 +
100 + let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
101 +
102 + nameLabel.text = ""
103 +
104 + for merchant in merchantList {
105 + if (merchant._uuid == coupon.merchant_uuid) {
106 + // couponImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
107 + self.postImageURL = merchant._img_preview
108 + nameLabel.text = merchant._admin_name
109 + break;
110 + }
111 + }
112 +
113 +// let priceFloat = Float(round(100 * (Float(coupon.discount ?? "0.0") ?? 0.0 )) / 100)
114 +// var priceString = "0"
115 +// priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
116 +// dicountLabel.text = priceString + "€"
117 +
118 + dicountLabel.text = (coupon.discount ?? "").replacingOccurrences(of: ".", with: ",", options: .literal, range: nil) + "€"
119 +
120 + let htmlText = coupon.inner_text ?? ""
121 + discriptionLabel.text = htmlText.htmlToString
122 +// discriptionLabel.text = coupon.inner_text ?? ""
123 + expirationLabel.text = "Ισχύει έως "+(coupon.expiration ?? "")
124 +
125 + }
126 +
95 } 127 }
......
...@@ -6,12 +6,102 @@ ...@@ -6,12 +6,102 @@
6 // 6 //
7 7
8 import UIKit 8 import UIKit
9 +//import RSBarcodes_Swift
10 +import AVFoundation
11 +// import SwiftEventBus
9 12
10 -@objc public class UnifiedCouponBCFooterTableViewCell: UITableViewCell { 13 +@objc public class UnifiedCouponBCFooterTableViewCell: UITableViewCell, UITextViewDelegate {
14 + @IBOutlet weak var termsButton: UIButton!
15 + @IBOutlet weak var termsTextView: UnselectableTappableTextView!
16 + @IBOutlet weak var termsTextViewHeight: NSLayoutConstraint!
17 + @IBOutlet weak var mapButton: UIButton!
18 + @IBOutlet weak var mapButtonHeight: NSLayoutConstraint!
19 + @IBOutlet weak var mapButtonTopSpace: NSLayoutConstraint!
11 20
12 public override func awakeFromNib() { 21 public override func awakeFromNib() {
13 super.awakeFromNib() 22 super.awakeFromNib()
14 // Initialization code 23 // Initialization code
24 +
25 + termsTextView.delegate = self
26 +
27 + mapButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Medium", size: 18)
28 + mapButton.setTitle("Δες τα supermarket", for: .normal)
29 + mapButton.setTitleColor(UIColor(red: 1.00, green: 1.00, blue: 1.00, alpha: 1.00), for: .normal)
30 + mapButton.backgroundColor = UIColor(red: 0.47, green: 0.75, blue: 0.08, alpha: 1.00)
31 + mapButton.layer.cornerRadius = 8.0
32 + mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 44)
33 + mapButton.contentEdgeInsets = UIEdgeInsets(top: 1, left: 16, bottom: 0, right: 16)
34 +
35 + // mapButton.isHidden = true
36 + // mapButtonHeight.constant = 0
37 + // mapButtonTopSpace.constant = 0
38 +
39 + // let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
40 +
41 + // for merchant in merchantList {
42 + // if (merchant._uuid == couponSetData?.merchant_uuid) {
43 + // if (merchant._show_map == true) {
44 + // mapButton.setTitle("Δες τα καταστήματα", for: .normal)
45 + // mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 44)
46 + // mapButton.contentEdgeInsets = UIEdgeInsets(top: 1, left: 16, bottom: 0, right: 16)
47 + // mapButton.isHidden = false
48 + // mapBtnVisible = true
49 + // eshopBtnVisible = false
50 + // mapButtonHeight.constant = 44
51 + // mapButtonTopSpace.constant = 10
52 + // } else if (merchant._eshop == true) {
53 + // mapButton.setTitle("Δες το eshop", for: .normal)
54 + // mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 44)
55 + // mapButton.contentEdgeInsets = UIEdgeInsets(top: 1, left: 16, bottom: 0, right: 16)
56 + // mapButton.isHidden = false
57 + // mapBtnVisible = false
58 + // eshopBtnVisible = true
59 + // mapButtonHeight.constant = 44
60 + // mapButtonTopSpace.constant = 10
61 + // } else {
62 + // mapButton.isHidden = true
63 + // mapBtnVisible = false
64 + // eshopBtnVisible = false
65 + // mapButtonHeight.constant = 0
66 + // mapButtonTopSpace.constant = 0
67 + // }
68 + // eshopWebsite = merchant._website
69 + // break;
70 + // }
71 + // }
72 +
73 + // Fix width for ipad
74 +// if UIDevice.current.userInterfaceIdiom == .pad {
75 +// // iPad
76 +// mapButton.widthAnchor.constraint(equalToConstant: 250).isActive = true
77 +// } else {
78 +// // not iPad (iPhone, mac, tv, carPlay, unspecified)
79 +// mapButton.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.6).isActive = true
80 +// }
81 +
82 + termsButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 16)
83 +// termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
84 + termsButton.setTitle("Όροι χρήσης", for: .normal)
85 + termsButton.setTitleColor(UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00), for: .normal)
86 + termsButton.setImage(UIImage(named: "ic_down_dark.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
87 + termsButton.semanticContentAttribute = .forceRightToLeft
88 + termsButton.tintColor = UIColor(red: 0.21, green: 0.32, blue: 0.41, alpha: 1.00)
89 + termsButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0);
90 + termsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
91 + termsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
92 +
93 + let termsText = "1. Το εκπτωτικό κουπόνι ισχύει έως την ημερομηνία που αναφέρεται παραπάνω\n2. To εκπτωτικό κουπόνι αφορά στα ενεργά κουπόνια προσφορών όπως αναφέρονται παραπάνω.\n3. Το εκπτωτικό κουπόνι μπορεί να χρησιμοποιηθεί σε μια μόνο συναλλαγή.\n4. Εάν δεν γίνει χρήση ενός επιμέρους κουπονιού προσφοράς από το εκπτωτικό κουπόνι, το κουπόνι προσφοράς επιστρέφει στο καλάθι στην ενότητα COSMOTE SuperMarket Deals"
94 + termsTextView.attributedText = NSAttributedString(string: termsText)
95 + termsTextView.font = UIFont(name: "PFSquareSansPro-Regular", size: 15)
96 + termsTextView.textColor = UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00)
97 + termsTextView.textAlignment = .center
98 + termsTextView.isScrollEnabled = false
99 +
100 + termsTextView.isUserInteractionEnabled = true
101 + termsTextView.isEditable = false
102 + termsTextView.isSelectable = true
103 + termsTextView.dataDetectorTypes = [.link]
104 +
15 } 105 }
16 106
17 public override func setSelected(_ selected: Bool, animated: Bool) { 107 public override func setSelected(_ selected: Bool, animated: Bool) {
...@@ -19,5 +109,31 @@ import UIKit ...@@ -19,5 +109,31 @@ import UIKit
19 109
20 // Configure the view for the selected state 110 // Configure the view for the selected state
21 } 111 }
112 +
113 + public func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
114 + UIApplication.shared.open(URL)
115 +
116 + // Disable `.preview` by 3D Touch and other interactions
117 + return false
118 + }
119 +
120 + func configureCell(termsVisible: Bool) {
121 + toggleTerms(termsVisible: termsVisible)
122 + }
123 +
124 + func toggleTerms(termsVisible: Bool) {
125 + if (termsVisible) {
126 + termsTextView.isHidden = false
127 + let targetSize = CGSize(width: termsTextView.frame.width, height: CGFloat(MAXFLOAT))
128 + termsTextViewHeight.constant = termsTextView.sizeThatFits(targetSize).height
129 +
130 + termsButton.setImage(UIImage(named: "ic_up_dark.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
131 + } else {
132 + termsTextView.isHidden = true
133 + termsTextViewHeight.constant = CGFloat(0)
134 +
135 + termsButton.setImage(UIImage(named: "ic_down_dark.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
136 + }
137 + }
22 138
23 } 139 }
......
...@@ -70,7 +70,7 @@ extension UITableView { ...@@ -70,7 +70,7 @@ extension UITableView {
70 @IBOutlet weak var mapButtonTopSpace: NSLayoutConstraint! 70 @IBOutlet weak var mapButtonTopSpace: NSLayoutConstraint!
71 @IBOutlet weak var showBarcodeButtonHeight: NSLayoutConstraint! 71 @IBOutlet weak var showBarcodeButtonHeight: NSLayoutConstraint!
72 @IBOutlet weak var showBarcodeButtonTopSpace: NSLayoutConstraint! 72 @IBOutlet weak var showBarcodeButtonTopSpace: NSLayoutConstraint!
73 - @IBOutlet weak var tableView: ContentSizedTableView! 73 + @IBOutlet weak var tableView: UITableView!
74 @IBOutlet weak var tableViewHeight: NSLayoutConstraint! 74 @IBOutlet weak var tableViewHeight: NSLayoutConstraint!
75 @IBOutlet weak var showCouponsButton: UIButton! 75 @IBOutlet weak var showCouponsButton: UIButton!
76 76
...@@ -296,9 +296,9 @@ extension UITableView { ...@@ -296,9 +296,9 @@ extension UITableView {
296 showCouponsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5); 296 showCouponsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
297 showCouponsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8) 297 showCouponsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
298 298
299 - tableView.isScrollEnabled = false 299 +// tableView.isScrollEnabled = false
300 - tableView.isHidden = true 300 +// tableView.isHidden = true
301 - tableViewHeight.constant = CGFloat(0) 301 +// tableViewHeight.constant = CGFloat(0)
302 302
303 // tableView.isHidden = false 303 // tableView.isHidden = false
304 // let targetSize = CGSize(width: tableView.frame.width, height: CGFloat(MAXFLOAT)) 304 // let targetSize = CGSize(width: tableView.frame.width, height: CGFloat(MAXFLOAT))
...@@ -476,17 +476,23 @@ extension UITableView { ...@@ -476,17 +476,23 @@ extension UITableView {
476 // MARK: - Actions 476 // MARK: - Actions
477 @IBAction func showCouponsButtonAction(_ sender: Any) { 477 @IBAction func showCouponsButtonAction(_ sender: Any) {
478 couponsVisible = !couponsVisible 478 couponsVisible = !couponsVisible
479 - toggleCoupons() 479 +// self.tableView.reloadSections(IndexSet(0..<2), with: .none)
480 + self.tableView.reloadData()
481 +// toggleCoupons()
480 } 482 }
481 483
482 @IBAction func showBarcodeAction(_ sender: Any) { 484 @IBAction func showBarcodeAction(_ sender: Any) {
483 barcodeVisible = !barcodeVisible 485 barcodeVisible = !barcodeVisible
484 - toggleBarcode() 486 +// self.tableView.reloadSections(IndexSet(integer: 0), with: .none)
487 + self.tableView.reloadData()
488 +// toggleBarcode()
485 } 489 }
486 490
487 @IBAction func termsButtonAction(_ sender: Any) { 491 @IBAction func termsButtonAction(_ sender: Any) {
488 termsVisible = !termsVisible 492 termsVisible = !termsVisible
489 - toggleTerms() 493 +// self.tableView.reloadSections(IndexSet(integer: 2), with: .none)
494 + self.tableView.reloadData()
495 +// toggleTerms()
490 } 496 }
491 497
492 @IBAction func mapButtonAction(_ sender: Any) { 498 @IBAction func mapButtonAction(_ sender: Any) {
...@@ -526,24 +532,73 @@ extension UITableView { ...@@ -526,24 +532,73 @@ extension UITableView {
526 extension UnifiedCouponBarcodeViewController: UITableViewDelegate, UITableViewDataSource{ 532 extension UnifiedCouponBarcodeViewController: UITableViewDelegate, UITableViewDataSource{
527 533
528 public func numberOfSections(in tableView: UITableView) -> Int { 534 public func numberOfSections(in tableView: UITableView) -> Int {
529 - return 1 535 + return 3
530 } 536 }
531 537
532 public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 538 public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
533 - return self.coupon?._coupons.count ?? 0 539 + if (section == 0) {
540 + return 1
541 + } else if (section == 1) {
542 + if (couponsVisible == true) {
543 + return self.coupon?._coupons.count ?? 0
544 + } else {
545 + return 0
546 + }
547 +
548 + } else if (section == 2) {
549 + return 1
550 + } else {
551 + return 0
552 + }
553 +
534 } 554 }
535 555
536 public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 556 public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
537 - return 120.0 + 8.0 557 + if (indexPath.section == 0) {
538 -// return UITableViewAutomaticDimension 558 + return UITableView.automaticDimension
559 + } else if (indexPath.section == 1) {
560 + if (couponsVisible == true) {
561 + return 120.0 + 8.0
562 + } else {
563 + return 0.0
564 + }
565 +
566 + } else if (indexPath.section == 2) {
567 + return UITableView.automaticDimension
568 + } else {
569 + return 0.0
570 + }
539 } 571 }
540 572
541 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 573 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
542 - let cell = tableView.dequeueReusableCell(withIdentifier: "CouponsTableViewCellId", for: indexPath) as! CouponsTableViewCell 574 + if (indexPath.section == 0) {
543 - 575 + let cell = tableView.dequeueReusableCell(withIdentifier: "UnifiedCouponBCHeaderTableViewCell", for: indexPath) as! UnifiedCouponBCHeaderTableViewCell
544 - cell.configureCell(coupon: (self.coupon?._coupons[indexPath.row])!) 576 +
545 - 577 + cell.configureCell(coupon: self.coupon, couponsVisible: couponsVisible)
546 - return cell 578 +
579 + return cell
580 +
581 + } else if (indexPath.section == 1) {
582 + let cell = tableView.dequeueReusableCell(withIdentifier: "CouponsTableViewCellId", for: indexPath) as! CouponsTableViewCell
583 +
584 + cell.configureCell(coupon: (self.coupon?._coupons[indexPath.row])!, isMarket: true)
585 +
586 +// cell.couponBgImage.image = UIImage(named: "coupon_bg_shadow", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
587 +
588 + cell.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor
589 + cell.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
590 + cell.layer.shadowOpacity = 1.0
591 + cell.layer.shadowRadius = 6.0
592 +
593 + return cell
594 +
595 + } else {
596 + let cell = tableView.dequeueReusableCell(withIdentifier: "UnifiedCouponBCFooterTableViewCell", for: indexPath) as! UnifiedCouponBCFooterTableViewCell
597 +
598 + cell.configureCell(termsVisible: termsVisible)
599 +
600 + return cell
601 + }
547 } 602 }
548 603
549 public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 604 public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
......