Manos Chorianopoulos

Add market coupons inner view

......@@ -22,7 +22,11 @@ import AVFoundation
@IBOutlet weak var merchantDescrTextView: UnselectableTappableTextView!
@IBOutlet weak var merchantDescrTextViewHeight: NSLayoutConstraint!
@IBOutlet weak var merchantDescrTextViewTopSpace: NSLayoutConstraint!
@IBOutlet weak var couponCodeLabel: UILabel!
@IBOutlet weak var couponCodeLabelHeight: NSLayoutConstraint!
@IBOutlet weak var couponView: UIView!
@IBOutlet weak var couponViewTopSpace: NSLayoutConstraint!
@IBOutlet weak var couponViewHeight: NSLayoutConstraint!
@IBOutlet weak var couponNumberLabel: CopyableLabel!
@IBOutlet weak var barcodeImage: UIImageView!
@IBOutlet weak var barcodeImageHeight: NSLayoutConstraint!
......@@ -59,6 +63,7 @@ import AVFoundation
public var coupon: swiftApi.CouponItemModel?
public var isFromWallet: Bool? = false
public var isMarket: Bool? = false
public override func viewDidLoad() {
super.viewDidLoad()
......@@ -95,17 +100,31 @@ import AVFoundation
// topBorderLine.heightAnchor.constraint(equalTo: topBorderLine.widthAnchor, multiplier: 1/aspectR)
// ])
// COUPONSET: desc, img_preview, name, terms
// COUPONSET: description, img_preview, name, terms
// COUPON: coupon, expiration, discount, status
// OLD COUPON KEYS: coupon, expiration, discount, status
// NEW COUPON KEYS (from couponset): inner_text, merchant_uuid
// MISSING KEYS (from couponset): img_preview, name, short_description, terms
let couponSetData: swiftApi.CouponSetItemModel? = coupon?.couponset_data
if (isMarket == true) {
couponImage.load(link: coupon?.image ?? "", placeholder: UIImage(), cache: URLCache())
} else {
couponImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache())
}
couponImage.contentMode = .scaleAspectFill
couponImageHeight.constant = 255 //230 // 253 // self.uiscreen.height * 0.25
if (isMarket == true) {
nameLabel.text = coupon?.name ?? ""
discriptionLabel.text = coupon?.short_description ?? ""
} else {
nameLabel.text = couponSetData?.name ?? ""
discriptionLabel.text = couponSetData?.short_description ?? ""
}
merchantDescrTextView.text = ""
merchantDescrTextViewTopSpace.constant = CGFloat(0)
......@@ -114,9 +133,15 @@ import AVFoundation
couponCodeLabelTopSpace.constant = CGFloat(35)
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
var merchantUuid: String = ""
if (isMarket == true) {
merchantUuid = coupon?.merchant_uuid ?? ""
} else {
merchantUuid = couponSetData?.merchant_uuid ?? ""
}
for merchant in merchantList {
if (merchant._uuid == couponSetData?.merchant_uuid) {
if (merchant._uuid == merchantUuid) {
let htmlMerchDescrText = merchant._body
if (htmlMerchDescrText != "") {
......@@ -146,6 +171,25 @@ import AVFoundation
couponNumberLabel.text = coupon?.coupon ?? ""
couponView.frame = CGRect(x: 0.0, y: 0.0, width: couponView.intrinsicContentSize.width, height: 55)
if (isMarket == true) {
couponCodeLabel.isHidden = true
couponCodeLabelHeight.constant = CGFloat(0)
couponCodeLabelTopSpace.constant = CGFloat(0)
couponView.isHidden = true
couponViewHeight.constant = CGFloat(0)
couponViewTopSpace.constant = CGFloat(0)
} else {
couponCodeLabel.isHidden = false
couponCodeLabelHeight.constant = CGFloat(20)
couponCodeLabelTopSpace.constant = CGFloat(35)
couponView.isHidden = true
couponViewHeight.constant = CGFloat(55)
couponViewTopSpace.constant = CGFloat(20)
}
let barcodeString = constructBarcode() ?? ""
barcodeLabel.text = barcodeString
......@@ -283,7 +327,13 @@ import AVFoundation
termsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
termsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
let htmlText = couponSetData?.terms ?? ""
var htmlText = ""
if (isMarket == true) {
htmlText = coupon?.terms ?? ""
} else {
htmlText = couponSetData?.terms ?? ""
}
termsTextView.attributedText = htmlText.htmlToAttributedString
termsTextView.font = UIFont(name: "PeridotPE-Regular", size: 14)
termsTextView.textColor = UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)
......@@ -297,7 +347,9 @@ import AVFoundation
// Uncomment if Barcode Section is active again
// toggleTerms()
if (isMarket == false) {
toggleBarcode()
}
// Logs
print("Coupon: " + (coupon?.coupon ?? ""))
......
......@@ -181,18 +181,19 @@ extension UnifiedCouponBarcodeViewController: UITableViewDelegate, UITableViewDa
// SwiftEventBus.post("couponBarcodePressed", sender: coupons[indexPath.row])
// Logs
// let couponSetData: swiftApi.CouponSetItemModel? = coupons[indexPath.row].couponset_data
// print("Coupon clicked: " + (coupons[indexPath.row].coupon ?? ""))
// let couponSetData: swiftApi.CouponSetItemModel? = self.coupon?._coupons[indexPath.row].couponset_data
// print("Coupon clicked: " + (self.coupon?._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 ?? ""))
// print("Coupon Expiration clicked: " + (self.coupon?._coupons[indexPath.row].expiration ?? ""))
// swiftApi().logTrackersEvent("click", ("Coupon:" + (couponSetData?.name ?? "")))
swiftApi().logTrackersEvent("click", ("Coupon:" + (self.coupon?._coupons[indexPath.row].name ?? "")))
// let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
// let vc = storyboard.instantiateViewController(withIdentifier: "CouponBarcodeViewController") as! SwiftWarplyFramework.CouponBarcodeViewController
// vc.coupon = self.coupon?._coupons[indexPath.row]
// self.navigationController?.pushViewController(vc, animated: true)
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "CouponBarcodeViewController") as! SwiftWarplyFramework.CouponBarcodeViewController
vc.coupon = self.coupon?._coupons[indexPath.row]
vc.isMarket = true
self.navigationController?.pushViewController(vc, animated: true)
}
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
......
......@@ -610,6 +610,8 @@ public class swiftApi {
// Market Coupon
public let inner_text: String?
public let merchant_uuid: String?
public let short_description: String?
public let terms: String?
public init(dictionary: [String: Any]) {
......@@ -626,6 +628,8 @@ public class swiftApi {
// Market Coupon
self.inner_text = dictionary["inner_text"] as? String? ?? ""
self.merchant_uuid = dictionary["merchant_uuid"] as? String? ?? ""
self.short_description = dictionary["short_description"] as? String? ?? ""
self.terms = dictionary["terms"] as? String? ?? ""
if let couponSetData = dictionary["couponset_data"] as? [String: Any]? ?? ["":""] {
......