Manos Chorianopoulos

add UnifiedCouponsViewController part 2

...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>0</integer> 10 + <integer>1</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>1</integer> 10 + <integer>0</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -10,22 +10,83 @@ import UIKit ...@@ -10,22 +10,83 @@ import UIKit
10 import SwiftEventBus 10 import SwiftEventBus
11 11
12 @objc public class UnifiedCouponsViewController: UIViewController { 12 @objc public class UnifiedCouponsViewController: UIViewController {
13 + @IBOutlet weak var backgroundImage: UIImageView!
14 + @IBOutlet weak var tableView: UITableView!
15 +
16 + public var unifiedCoupons:Array<swiftApi.UnifiedCouponModel> = []
13 17
14 public override func viewDidLoad() { 18 public override func viewDidLoad() {
15 super.viewDidLoad() 19 super.viewDidLoad()
20 +
21 + self.hidesBottomBarWhenPushed = true
22 +
23 + SwiftEventBus.onBackgroundThread(self, name: "unified_coupons_fetched") { result in
16 24
17 - // Do any additional setup after loading the view. 25 + DispatchQueue.main.async {
26 + self.unifiedCoupons = swiftApi().getUnifiedCouponList()
27 + self.tableView.reloadData()
28 + }
29 + }
30 +
31 + setBackButton()
32 + setNavigationTitle("SUPERMARKET DEALS")
33 +
34 +// backgroundImage.image = UIImage(named: "coupons_scrollview_dark", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
35 +
36 + tableView.delegate = self
37 + tableView.dataSource = self
38 +
39 +// tableView.clipsToBounds = true
40 +// tableView.layer.cornerRadius = 30
41 +// tableView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
42 + tableView.contentInset.top = 30
18 } 43 }
19 44
45 + public override func viewWillAppear(_ animated: Bool) {
46 + super.viewWillAppear(animated)
47 +
48 + swiftApi().logTrackersEvent("screen", "ActiveUnifiedCouponsScreen")
49 +
50 + self.unifiedCoupons = swiftApi().getUnifiedCouponList()
51 + self.tableView.reloadData()
52 +
53 + self.navigationController?.hideHairline()
54 + }
20 55
21 - /* 56 + // MARK: - Functions
22 - // MARK: - Navigation 57 +}
23 58
24 - // In a storyboard-based application, you will often want to do a little preparation before navigation 59 +// MARK: - TableView
25 - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 60 +extension UnifiedCouponsViewController: UITableViewDelegate, UITableViewDataSource{
26 - // Get the new view controller using segue.destination. 61 +
27 - // Pass the selected object to the new view controller. 62 + public func numberOfSections(in tableView: UITableView) -> Int {
63 + return 1
64 + }
65 +
66 + public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
67 + return self.unifiedCoupons.count
28 } 68 }
29 - */ 69 +
70 + public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
71 + return 130.0 + 8.0
72 +// return UITableViewAutomaticDimension
73 + }
74 +
75 + public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
76 + let cell = tableView.dequeueReusableCell(withIdentifier: "UnifiedCouponsTableViewCellId", for: indexPath) as! UnifiedCouponsTableViewCell
77 + cell.configureCell(coupon: unifiedCoupons[indexPath.row])
78 + return cell
79 + }
80 +
81 + public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
82 + let couponBarcode = unifiedCoupons[indexPath.row]._barcode
83 + swiftApi().logTrackersEvent("click", ("UnifiedCoupon:" + couponBarcode))
30 84
85 + let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
86 + let vc = storyboard.instantiateViewController(withIdentifier: "UnifiedCouponBarcodeViewController") as! SwiftWarplyFramework.UnifiedCouponBarcodeViewController
87 + vc.coupon = unifiedCoupons[indexPath.row]
88 + vc.isFromWallet = true
89 + self.navigationController?.pushViewController(vc, animated: true)
90 + }
91 +
31 } 92 }
......