UnifiedCouponsViewController.swift
4.26 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
//
// UnifiedCouponsViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 20/10/23.
//
import Foundation
import UIKit
import SwiftEventBus
@objc public class UnifiedCouponsViewController: UIViewController {
@IBOutlet weak var backgroundImage: UIImageView!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var emptyView: UIView!
@IBOutlet weak var emptyViewHeight: NSLayoutConstraint!
@IBOutlet weak var emptyLabel: UILabel!
public var unifiedCoupons:Array<swiftApi.UnifiedCouponModel> = []
public override func viewDidLoad() {
super.viewDidLoad()
self.hidesBottomBarWhenPushed = true
SwiftEventBus.onBackgroundThread(self, name: "unified_coupons_fetched") { result in
DispatchQueue.main.async {
self.unifiedCoupons = swiftApi().getUnifiedCouponList()
self.tableView.reloadData()
if (self.unifiedCoupons.count == 0) {
self.emptyView.isHidden = false
self.emptyViewHeight.constant = self.emptyView.intrinsicContentSize.height
} else {
self.emptyView.isHidden = true
self.emptyViewHeight.constant = 0
}
}
}
setBackButton()
setNavigationTitle("SUPERMARKET DEALS")
// backgroundImage.image = UIImage(named: "coupons_scrollview_dark", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
tableView.delegate = self
tableView.dataSource = self
// tableView.clipsToBounds = true
// tableView.layer.cornerRadius = 30
// tableView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
tableView.contentInset.top = 30
emptyLabel.text = "Αυτήν τη στιγμή δεν έχεις κάποιο ενεργό κουπόνι. Στην ενότητα FOR YOU μπορείς να βρεις κουπόνια αποκλειστικά για σένα!"
}
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
swiftApi().logTrackersEvent("screen", "ActiveUnifiedCouponsScreen")
self.unifiedCoupons = swiftApi().getUnifiedCouponList()
self.tableView.reloadData()
if (self.unifiedCoupons.count == 0) {
self.emptyView.isHidden = false
self.emptyViewHeight.constant = self.emptyView.intrinsicContentSize.height
} else {
self.emptyView.isHidden = true
self.emptyViewHeight.constant = 0
}
self.navigationController?.hideHairline()
}
// MARK: - Functions
}
// MARK: - TableView
extension UnifiedCouponsViewController: UITableViewDelegate, UITableViewDataSource{
public func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.unifiedCoupons.count
}
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 130.0 + 8.0
// return UITableViewAutomaticDimension
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UnifiedCouponsTableViewCellId", for: indexPath) as! UnifiedCouponsTableViewCell
cell.configureCell(coupon: unifiedCoupons[indexPath.row])
return cell
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let couponBarcode = unifiedCoupons[indexPath.row]._barcode
swiftApi().logTrackersEvent("click", ("UnifiedCoupon:" + couponBarcode))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "UnifiedCouponBarcodeViewController") as! SwiftWarplyFramework.UnifiedCouponBarcodeViewController
vc.coupon = unifiedCoupons[indexPath.row]
vc.isFromWallet = true
self.navigationController?.pushViewController(vc, animated: true)
}
}