Manos Chorianopoulos

UnifiedCouponBarcodeVC refactor

......@@ -92,4 +92,36 @@ import UIKit
expirationLabel.text = "Ισχύει έως "+(coupon.expiration ?? "")
}
func configureCell(coupon: swiftApi.CouponItemModel, isMarket: Bool) {
// COUPONSET: desc, img_preview, name, terms, merchant_uuid
// COUPON: coupon, expiration, discount, status
// MERCHANT: _img_preview,_admin_name
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
nameLabel.text = ""
for merchant in merchantList {
if (merchant._uuid == coupon.merchant_uuid) {
// couponImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
self.postImageURL = merchant._img_preview
nameLabel.text = merchant._admin_name
break;
}
}
// let priceFloat = Float(round(100 * (Float(coupon.discount ?? "0.0") ?? 0.0 )) / 100)
// var priceString = "0"
// priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
// dicountLabel.text = priceString + "€"
dicountLabel.text = (coupon.discount ?? "").replacingOccurrences(of: ".", with: ",", options: .literal, range: nil) + "€"
let htmlText = coupon.inner_text ?? ""
discriptionLabel.text = htmlText.htmlToString
// discriptionLabel.text = coupon.inner_text ?? ""
expirationLabel.text = "Ισχύει έως "+(coupon.expiration ?? "")
}
}
......
......@@ -6,12 +6,102 @@
//
import UIKit
//import RSBarcodes_Swift
import AVFoundation
// import SwiftEventBus
@objc public class UnifiedCouponBCFooterTableViewCell: UITableViewCell {
@objc public class UnifiedCouponBCFooterTableViewCell: UITableViewCell, UITextViewDelegate {
@IBOutlet weak var termsButton: UIButton!
@IBOutlet weak var termsTextView: UnselectableTappableTextView!
@IBOutlet weak var termsTextViewHeight: NSLayoutConstraint!
@IBOutlet weak var mapButton: UIButton!
@IBOutlet weak var mapButtonHeight: NSLayoutConstraint!
@IBOutlet weak var mapButtonTopSpace: NSLayoutConstraint!
public override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
termsTextView.delegate = self
mapButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Medium", size: 18)
mapButton.setTitle("Δες τα supermarket", for: .normal)
mapButton.setTitleColor(UIColor(red: 1.00, green: 1.00, blue: 1.00, alpha: 1.00), for: .normal)
mapButton.backgroundColor = UIColor(red: 0.47, green: 0.75, blue: 0.08, alpha: 1.00)
mapButton.layer.cornerRadius = 8.0
mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 44)
mapButton.contentEdgeInsets = UIEdgeInsets(top: 1, left: 16, bottom: 0, right: 16)
// mapButton.isHidden = true
// mapButtonHeight.constant = 0
// mapButtonTopSpace.constant = 0
// let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
// for merchant in merchantList {
// if (merchant._uuid == couponSetData?.merchant_uuid) {
// if (merchant._show_map == true) {
// mapButton.setTitle("Δες τα καταστήματα", for: .normal)
// mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 44)
// mapButton.contentEdgeInsets = UIEdgeInsets(top: 1, left: 16, bottom: 0, right: 16)
// mapButton.isHidden = false
// mapBtnVisible = true
// eshopBtnVisible = false
// mapButtonHeight.constant = 44
// mapButtonTopSpace.constant = 10
// } else if (merchant._eshop == true) {
// mapButton.setTitle("Δες το eshop", for: .normal)
// mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 44)
// mapButton.contentEdgeInsets = UIEdgeInsets(top: 1, left: 16, bottom: 0, right: 16)
// mapButton.isHidden = false
// mapBtnVisible = false
// eshopBtnVisible = true
// mapButtonHeight.constant = 44
// mapButtonTopSpace.constant = 10
// } else {
// mapButton.isHidden = true
// mapBtnVisible = false
// eshopBtnVisible = false
// mapButtonHeight.constant = 0
// mapButtonTopSpace.constant = 0
// }
// eshopWebsite = merchant._website
// break;
// }
// }
// Fix width for ipad
// if UIDevice.current.userInterfaceIdiom == .pad {
// // iPad
// mapButton.widthAnchor.constraint(equalToConstant: 250).isActive = true
// } else {
// // not iPad (iPhone, mac, tv, carPlay, unspecified)
// mapButton.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.6).isActive = true
// }
termsButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 16)
// termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
termsButton.setTitle("Όροι χρήσης", for: .normal)
termsButton.setTitleColor(UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00), for: .normal)
termsButton.setImage(UIImage(named: "ic_down_dark.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
termsButton.semanticContentAttribute = .forceRightToLeft
termsButton.tintColor = UIColor(red: 0.21, green: 0.32, blue: 0.41, alpha: 1.00)
termsButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0);
termsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
termsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
let termsText = "1. Το εκπτωτικό κουπόνι ισχύει έως την ημερομηνία που αναφέρεται παραπάνω\n2. To εκπτωτικό κουπόνι αφορά στα ενεργά κουπόνια προσφορών όπως αναφέρονται παραπάνω.\n3. Το εκπτωτικό κουπόνι μπορεί να χρησιμοποιηθεί σε μια μόνο συναλλαγή.\n4. Εάν δεν γίνει χρήση ενός επιμέρους κουπονιού προσφοράς από το εκπτωτικό κουπόνι, το κουπόνι προσφοράς επιστρέφει στο καλάθι στην ενότητα COSMOTE SuperMarket Deals"
termsTextView.attributedText = NSAttributedString(string: termsText)
termsTextView.font = UIFont(name: "PFSquareSansPro-Regular", size: 15)
termsTextView.textColor = UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00)
termsTextView.textAlignment = .center
termsTextView.isScrollEnabled = false
termsTextView.isUserInteractionEnabled = true
termsTextView.isEditable = false
termsTextView.isSelectable = true
termsTextView.dataDetectorTypes = [.link]
}
public override func setSelected(_ selected: Bool, animated: Bool) {
......@@ -19,5 +109,31 @@ import UIKit
// Configure the view for the selected state
}
public func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
UIApplication.shared.open(URL)
// Disable `.preview` by 3D Touch and other interactions
return false
}
func configureCell(termsVisible: Bool) {
toggleTerms(termsVisible: termsVisible)
}
func toggleTerms(termsVisible: Bool) {
if (termsVisible) {
termsTextView.isHidden = false
let targetSize = CGSize(width: termsTextView.frame.width, height: CGFloat(MAXFLOAT))
termsTextViewHeight.constant = termsTextView.sizeThatFits(targetSize).height
termsButton.setImage(UIImage(named: "ic_up_dark.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
} else {
termsTextView.isHidden = true
termsTextViewHeight.constant = CGFloat(0)
termsButton.setImage(UIImage(named: "ic_down_dark.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
}
}
}
......
......@@ -70,7 +70,7 @@ extension UITableView {
@IBOutlet weak var mapButtonTopSpace: NSLayoutConstraint!
@IBOutlet weak var showBarcodeButtonHeight: NSLayoutConstraint!
@IBOutlet weak var showBarcodeButtonTopSpace: NSLayoutConstraint!
@IBOutlet weak var tableView: ContentSizedTableView!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var tableViewHeight: NSLayoutConstraint!
@IBOutlet weak var showCouponsButton: UIButton!
......@@ -296,9 +296,9 @@ extension UITableView {
showCouponsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
showCouponsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
tableView.isScrollEnabled = false
tableView.isHidden = true
tableViewHeight.constant = CGFloat(0)
// tableView.isScrollEnabled = false
// tableView.isHidden = true
// tableViewHeight.constant = CGFloat(0)
// tableView.isHidden = false
// let targetSize = CGSize(width: tableView.frame.width, height: CGFloat(MAXFLOAT))
......@@ -476,17 +476,23 @@ extension UITableView {
// MARK: - Actions
@IBAction func showCouponsButtonAction(_ sender: Any) {
couponsVisible = !couponsVisible
toggleCoupons()
// self.tableView.reloadSections(IndexSet(0..<2), with: .none)
self.tableView.reloadData()
// toggleCoupons()
}
@IBAction func showBarcodeAction(_ sender: Any) {
barcodeVisible = !barcodeVisible
toggleBarcode()
// self.tableView.reloadSections(IndexSet(integer: 0), with: .none)
self.tableView.reloadData()
// toggleBarcode()
}
@IBAction func termsButtonAction(_ sender: Any) {
termsVisible = !termsVisible
toggleTerms()
// self.tableView.reloadSections(IndexSet(integer: 2), with: .none)
self.tableView.reloadData()
// toggleTerms()
}
@IBAction func mapButtonAction(_ sender: Any) {
......@@ -526,24 +532,73 @@ extension UITableView {
extension UnifiedCouponBarcodeViewController: UITableViewDelegate, UITableViewDataSource{
public func numberOfSections(in tableView: UITableView) -> Int {
return 1
return 3
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.coupon?._coupons.count ?? 0
if (section == 0) {
return 1
} else if (section == 1) {
if (couponsVisible == true) {
return self.coupon?._coupons.count ?? 0
} else {
return 0
}
} else if (section == 2) {
return 1
} else {
return 0
}
}
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 120.0 + 8.0
// return UITableViewAutomaticDimension
if (indexPath.section == 0) {
return UITableView.automaticDimension
} else if (indexPath.section == 1) {
if (couponsVisible == true) {
return 120.0 + 8.0
} else {
return 0.0
}
} else if (indexPath.section == 2) {
return UITableView.automaticDimension
} else {
return 0.0
}
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CouponsTableViewCellId", for: indexPath) as! CouponsTableViewCell
cell.configureCell(coupon: (self.coupon?._coupons[indexPath.row])!)
return cell
if (indexPath.section == 0) {
let cell = tableView.dequeueReusableCell(withIdentifier: "UnifiedCouponBCHeaderTableViewCell", for: indexPath) as! UnifiedCouponBCHeaderTableViewCell
cell.configureCell(coupon: self.coupon, couponsVisible: couponsVisible)
return cell
} else if (indexPath.section == 1) {
let cell = tableView.dequeueReusableCell(withIdentifier: "CouponsTableViewCellId", for: indexPath) as! CouponsTableViewCell
cell.configureCell(coupon: (self.coupon?._coupons[indexPath.row])!, isMarket: true)
// cell.couponBgImage.image = UIImage(named: "coupon_bg_shadow", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
cell.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor
cell.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
cell.layer.shadowOpacity = 1.0
cell.layer.shadowRadius = 6.0
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "UnifiedCouponBCFooterTableViewCell", for: indexPath) as! UnifiedCouponBCFooterTableViewCell
cell.configureCell(termsVisible: termsVisible)
return cell
}
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
......