Manos Chorianopoulos

PopupMerchantsViewController dynamic list

......@@ -655,17 +655,32 @@ import AVFoundation
@IBAction func redeemButtomAction(_ sender: Any) {
if (isSMCoupon == true) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
if let popupVC = storyboard.instantiateViewController(withIdentifier: "PopupMerchantsViewController") as? SwiftWarplyFramework.PopupMerchantsViewController {
popupVC.modalPresentationStyle = .overCurrentContext
popupVC.modalTransitionStyle = .crossDissolve
popupVC.coupon = coupon
// popupVC.headerText = "Βρες το προϊον στα supermarket"
// popupVC.buttonTitle = "Βρες το"
popupVC.buttonIcon = "shopping_cart"
// popupVC.footerText = "Η διαθεσιμότητα ενδέχεται να διαφέρει ανάλογα με την τοποθεσία."
var availableShopsList:Array<swiftApi.ShopAvailabilityItemModel> = []
let smCouponsetsList = swiftApi().getCouponSetsDealsList()
let couponsetUuid = coupon?.couponset_uuid
for couponset in smCouponsetsList {
if (couponset.uuid == couponsetUuid) {
availableShopsList = couponset.shop_availability ?? []
break;
}
}
if (availableShopsList.count > 0) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
if let popupVC = storyboard.instantiateViewController(withIdentifier: "PopupMerchantsViewController") as? SwiftWarplyFramework.PopupMerchantsViewController {
popupVC.modalPresentationStyle = .overCurrentContext
popupVC.modalTransitionStyle = .crossDissolve
popupVC.availableShopsList = availableShopsList
// popupVC.headerText = "Βρες το προϊον στα supermarket"
// popupVC.buttonTitle = "Βρες το"
popupVC.buttonIcon = "shopping_cart"
// popupVC.footerText = "Η διαθεσιμότητα ενδέχεται να διαφέρει ανάλογα με την τοποθεσία."
self.present(popupVC, animated: true, completion: nil)
}
self.present(popupVC, animated: true, completion: nil)
} else {
// TODO: add error popup
}
} else {
......
......@@ -23,6 +23,8 @@ class MerchantTableViewCell: UITableViewCell {
// Delegate variable
weak var delegate: MerchantTableViewCellDelegate?
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
var postImageURL: String? {
didSet {
if let url = postImageURL {
......@@ -71,9 +73,14 @@ class MerchantTableViewCell: UITableViewCell {
contentView.frame = contentView.frame.inset(by: margins)
}
func configureCell(merchant: swiftApi.MerchantModel, buttonTitle: String, iconImage: String?) {
func configureCell(shop: swiftApi.ShopAvailabilityItemModel, buttonTitle: String, iconImage: String?) {
self.postImageURL = merchant._img_preview
for merchant in merchantList {
if (merchant._uuid == shop._merchant_uuid) {
self.postImageURL = merchant._img_preview
break;
}
}
buttonTitleLable.text = buttonTitle
......
......@@ -13,14 +13,13 @@ class PopupMerchantsViewController: UIViewController {
@IBOutlet weak var closeButton: UIButton!
@IBOutlet weak var tableView: DynamicSizeTableView!
public var coupon: swiftApi.CouponItemModel?
public var availableShopsList:Array<swiftApi.ShopAvailabilityItemModel> = []
// public var coupon: swiftApi.CouponItemModel?
public var headerText: String? = "Βρες το προϊον στα supermarket"
public var buttonTitle: String? = "Βρες το"
public var buttonIcon: String?
public var footerText: String? = "Η διαθεσιμότητα ενδέχεται να διαφέρει ανάλογα με την τοποθεσία."
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
override func viewDidLoad() {
super.viewDidLoad()
......@@ -59,7 +58,7 @@ extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSour
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 0) {
return self.merchantList.count
return self.availableShopsList.count
} else if (section == 1) {
return 1
} else {
......@@ -82,7 +81,7 @@ extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSour
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 0) {
let cell = tableView.dequeueReusableCell(withIdentifier: "MerchantTableViewCellId", for: indexPath) as! MerchantTableViewCell
cell.configureCell(merchant: merchantList[indexPath.row], buttonTitle: self.buttonTitle ?? "Βρες το", iconImage: buttonIcon)
cell.configureCell(shop: availableShopsList[indexPath.row], buttonTitle: self.buttonTitle ?? "Βρες το", iconImage: buttonIcon)
// Set the delegate to self
cell.delegate = self
......@@ -98,20 +97,9 @@ extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSour
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// self.dismiss(animated: true, completion: {})
// TODO: DELETE LOGS
print(" didSelectRowAt Button tapped in row \(indexPath.row)")
// TODO: Open merchant url
// Do nothing - tap handled with protocol
// print(" didSelectRowAt Button tapped in row \(indexPath.row)")
// Logs
// let couponSetData: swiftApi.CouponSetItemModel? = coupons[indexPath.row].couponset_data
// print("Coupon clicked: " + (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 ?? ""))
}
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
......@@ -138,11 +126,14 @@ extension PopupMerchantsViewController: MerchantTableViewCellDelegate {
func didTapButton(in cell: MerchantTableViewCell) {
// Find the index path of the cell where the button was tapped
if let indexPath = tableView.indexPath(for: cell) {
// TODO: DELETE LOGS
print("Button tapped in row \(indexPath.row)")
print("Button tapped cell: \(cell)")
// Handle the button tap action here
let urlString = availableShopsList[indexPath.row]._product_url
if let url = URL(string: urlString){
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}
}
}
......