Manos Chorianopoulos

MyRewardsOffer delegate

...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
7 7
8 import UIKit 8 import UIKit
9 9
10 +protocol MyRewardsOffersScrollTableViewCellDelegate: AnyObject {
11 + func didSelectOffer(_ offer: OfferModel)
12 +}
13 +
10 @objc public class MyRewardsOffersScrollTableViewCell: UITableViewCell { 14 @objc public class MyRewardsOffersScrollTableViewCell: UITableViewCell {
11 @IBOutlet weak var categoryLabel: UILabel! 15 @IBOutlet weak var categoryLabel: UILabel!
12 @IBOutlet weak var allButtonView: UIView! 16 @IBOutlet weak var allButtonView: UIView!
...@@ -14,6 +18,7 @@ import UIKit ...@@ -14,6 +18,7 @@ import UIKit
14 @IBOutlet weak var collectionView: UICollectionView! 18 @IBOutlet weak var collectionView: UICollectionView!
15 @IBOutlet weak var collectionViewHeightConstraint: NSLayoutConstraint! 19 @IBOutlet weak var collectionViewHeightConstraint: NSLayoutConstraint!
16 20
21 + weak var delegate: MyRewardsOffersScrollTableViewCellDelegate?
17 var data: SectionModel? 22 var data: SectionModel?
18 23
19 public override func awakeFromNib() { 24 public override func awakeFromNib() {
...@@ -106,7 +111,7 @@ import UIKit ...@@ -106,7 +111,7 @@ import UIKit
106 } 111 }
107 } 112 }
108 113
109 -extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout { 114 +extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
110 115
111 116
112 public func numberOfSections(in collectionView: UICollectionView) -> Int { 117 public func numberOfSections(in collectionView: UICollectionView) -> Int {
...@@ -127,7 +132,9 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UICol ...@@ -127,7 +132,9 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UICol
127 } 132 }
128 133
129 public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 134 public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
130 -// TODO: open offer 135 + if let offer = self.data?.offers[indexPath.row] {
136 + delegate?.didSelectOffer(offer)
137 + }
131 } 138 }
132 139
133 // MARK: - UICollectionViewDelegateFlowLayout 140 // MARK: - UICollectionViewDelegateFlowLayout
......
...@@ -8,22 +8,22 @@ ...@@ -8,22 +8,22 @@
8 import UIKit 8 import UIKit
9 9
10 @objc public class CouponViewController: UIViewController { 10 @objc public class CouponViewController: UIViewController {
11 + var coupon: OfferModel?
11 12
12 public override func viewDidLoad() { 13 public override func viewDidLoad() {
13 super.viewDidLoad() 14 super.viewDidLoad()
14 15
15 - // Do any additional setup after loading the view. 16 + // Show navigation bar for this screen (with back button)
17 + self.navigationController?.setNavigationBarHidden(false, animated: false)
18 +
19 + // Configure the view with offer data
20 + if let offer = coupon {
21 + setupUI(with: offer)
22 + }
16 } 23 }
17 24
18 - 25 + private func setupUI(with coupon: OfferModel) {
19 - /* 26 + // Set up the UI based on the offer data
20 - // MARK: - Navigation
21 -
22 - // In a storyboard-based application, you will often want to do a little preparation before navigation
23 - override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
24 - // Get the new view controller using segue.destination.
25 - // Pass the selected object to the new view controller.
26 } 27 }
27 - */
28 28
29 } 29 }
......
...@@ -423,7 +423,6 @@ struct OfferModel { ...@@ -423,7 +423,6 @@ struct OfferModel {
423 self.tableView.reloadData() 423 self.tableView.reloadData()
424 } 424 }
425 425
426 - // Add navigation method
427 private func openCampaignViewController(with offer: OfferModel) { 426 private func openCampaignViewController(with offer: OfferModel) {
428 427
429 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self)) 428 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
...@@ -434,6 +433,13 @@ struct OfferModel { ...@@ -434,6 +433,13 @@ struct OfferModel {
434 // self.present(vc, animated: true) 433 // self.present(vc, animated: true)
435 } 434 }
436 } 435 }
436 +
437 + private func openCouponViewController(with offer: OfferModel) {
438 + let vc = SwiftWarplyFramework.CouponViewController(nibName: "CouponViewController", bundle: Bundle(for: MyEmptyClass.self))
439 + vc.coupon = offer
440 +
441 + self.navigationController?.pushViewController(vc, animated: true)
442 + }
437 } 443 }
438 444
439 // MARK: - TableView 445 // MARK: - TableView
...@@ -471,7 +477,7 @@ extension MyRewardsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -471,7 +477,7 @@ extension MyRewardsViewController: UITableViewDelegate, UITableViewDataSource{
471 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 477 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
472 if (indexPath.section == 0) { 478 if (indexPath.section == 0) {
473 let cell = tableView.dequeueReusableCell(withIdentifier: "MyRewardsBannerOffersScrollTableViewCell", for: indexPath) as! MyRewardsBannerOffersScrollTableViewCell 479 let cell = tableView.dequeueReusableCell(withIdentifier: "MyRewardsBannerOffersScrollTableViewCell", for: indexPath) as! MyRewardsBannerOffersScrollTableViewCell
474 - cell.delegate = self 480 + cell.delegate = self // Set the banner offers delegate
475 cell.configureCell(data: self.bannerOffersSection) 481 cell.configureCell(data: self.bannerOffersSection)
476 // cell.parent = self 482 // cell.parent = self
477 return cell 483 return cell
...@@ -479,6 +485,8 @@ extension MyRewardsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -479,6 +485,8 @@ extension MyRewardsViewController: UITableViewDelegate, UITableViewDataSource{
479 } else { 485 } else {
480 let cell = tableView.dequeueReusableCell(withIdentifier: "MyRewardsOffersScrollTableViewCell", for: indexPath) as! MyRewardsOffersScrollTableViewCell 486 let cell = tableView.dequeueReusableCell(withIdentifier: "MyRewardsOffersScrollTableViewCell", for: indexPath) as! MyRewardsOffersScrollTableViewCell
481 487
488 + cell.delegate = self // Set the offers delegate
489 +
482 if (indexPath.section == 1) { 490 if (indexPath.section == 1) {
483 cell.configureCell(data: self.topOffersSection) 491 cell.configureCell(data: self.topOffersSection)
484 } else if (indexPath.section == 2) { 492 } else if (indexPath.section == 2) {
...@@ -533,3 +541,11 @@ extension MyRewardsViewController: MyRewardsBannerOffersScrollTableViewCellDeleg ...@@ -533,3 +541,11 @@ extension MyRewardsViewController: MyRewardsBannerOffersScrollTableViewCellDeleg
533 openCampaignViewController(with: offer) 541 openCampaignViewController(with: offer)
534 } 542 }
535 } 543 }
544 +
545 +// Add delegate conformance
546 +extension MyRewardsViewController: MyRewardsOffersScrollTableViewCellDelegate {
547 + func didSelectOffer(_ offer: OfferModel) {
548 + // Navigate to CouponViewController
549 + openCouponViewController(with: offer)
550 + }
551 +}
......