Manos Chorianopoulos

MyRewardsOffer delegate

......@@ -7,6 +7,10 @@
import UIKit
protocol MyRewardsOffersScrollTableViewCellDelegate: AnyObject {
func didSelectOffer(_ offer: OfferModel)
}
@objc public class MyRewardsOffersScrollTableViewCell: UITableViewCell {
@IBOutlet weak var categoryLabel: UILabel!
@IBOutlet weak var allButtonView: UIView!
......@@ -14,6 +18,7 @@ import UIKit
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var collectionViewHeightConstraint: NSLayoutConstraint!
weak var delegate: MyRewardsOffersScrollTableViewCellDelegate?
var data: SectionModel?
public override func awakeFromNib() {
......@@ -106,7 +111,7 @@ import UIKit
}
}
extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
public func numberOfSections(in collectionView: UICollectionView) -> Int {
......@@ -127,7 +132,9 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UICol
}
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// TODO: open offer
if let offer = self.data?.offers[indexPath.row] {
delegate?.didSelectOffer(offer)
}
}
// MARK: - UICollectionViewDelegateFlowLayout
......
......@@ -8,22 +8,22 @@
import UIKit
@objc public class CouponViewController: UIViewController {
var coupon: OfferModel?
public override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// Show navigation bar for this screen (with back button)
self.navigationController?.setNavigationBarHidden(false, animated: false)
// Configure the view with offer data
if let offer = coupon {
setupUI(with: offer)
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
private func setupUI(with coupon: OfferModel) {
// Set up the UI based on the offer data
}
*/
}
......
......@@ -423,7 +423,6 @@ struct OfferModel {
self.tableView.reloadData()
}
// Add navigation method
private func openCampaignViewController(with offer: OfferModel) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
......@@ -434,6 +433,13 @@ struct OfferModel {
// self.present(vc, animated: true)
}
}
private func openCouponViewController(with offer: OfferModel) {
let vc = SwiftWarplyFramework.CouponViewController(nibName: "CouponViewController", bundle: Bundle(for: MyEmptyClass.self))
vc.coupon = offer
self.navigationController?.pushViewController(vc, animated: true)
}
}
// MARK: - TableView
......@@ -471,7 +477,7 @@ extension MyRewardsViewController: UITableViewDelegate, UITableViewDataSource{
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 0) {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyRewardsBannerOffersScrollTableViewCell", for: indexPath) as! MyRewardsBannerOffersScrollTableViewCell
cell.delegate = self
cell.delegate = self // Set the banner offers delegate
cell.configureCell(data: self.bannerOffersSection)
// cell.parent = self
return cell
......@@ -479,6 +485,8 @@ extension MyRewardsViewController: UITableViewDelegate, UITableViewDataSource{
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyRewardsOffersScrollTableViewCell", for: indexPath) as! MyRewardsOffersScrollTableViewCell
cell.delegate = self // Set the offers delegate
if (indexPath.section == 1) {
cell.configureCell(data: self.topOffersSection)
} else if (indexPath.section == 2) {
......@@ -533,3 +541,11 @@ extension MyRewardsViewController: MyRewardsBannerOffersScrollTableViewCellDeleg
openCampaignViewController(with: offer)
}
}
// Add delegate conformance
extension MyRewardsViewController: MyRewardsOffersScrollTableViewCellDelegate {
func didSelectOffer(_ offer: OfferModel) {
// Navigate to CouponViewController
openCouponViewController(with: offer)
}
}
......