Manos Chorianopoulos

CategoryOffers fixes part2

......@@ -22,8 +22,10 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell {
var postImageURL: String? {
didSet {
if let url = postImageURL {
self.bannerImage.image = UIImage()
self.bannerImage.image = UIImage() // UIImage(named: "loading")
UIImage.loadImageUsingCacheWithUrlString(url) { image in
// set the image only when we are still displaying the content for the image we finished downloading
if url == self.postImageURL {
self.bannerImage.image = image
}
......@@ -37,8 +39,10 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell {
var logoImageURL: String? {
didSet {
if let url = logoImageURL {
self.logoImage.image = UIImage()
self.logoImage.image = UIImage() // UIImage(named: "loading")
UIImage.loadImageUsingCacheWithUrlString(url) { image in
// set the image only when we are still displaying the content for the image we finished downloading
if url == self.logoImageURL {
self.logoImage.image = image
}
......@@ -57,57 +61,28 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell {
parentView.layer.cornerRadius = 12.0
parentView.clipsToBounds = true
logoImage.layer.cornerRadius = 8.0
logoImage.clipsToBounds = true
logoImage.backgroundColor = UIColor(rgb: 0xEEEEEE)
discountView.layer.cornerRadius = 17.0
discountView.clipsToBounds = true
}
func configureCell(data: OfferModel) {
bannerImage.image = UIImage(named: data.bannerImage, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
discountLabel.text = data.discount
discountLabel.font = UIFont(name: "PingLCG-Bold", size: 14)
discountLabel.textColor = UIColor(rgb: 0xFFFFFF)
discountView.backgroundColor = UIColor(rgb: 0xCBCBCB)
merchantNameLabel.text = data.title
merchantNameLabel.font = UIFont(name: "PingLCG-Regular", size: 12)
merchantNameLabel.textColor = UIColor(rgb: 0x000F1E)
titleLabel.text = data.title
titleLabel.font = UIFont(name: "PingLCG-Bold", size: 15)
titleLabel.textColor = UIColor(rgb: 0x000F1E)
subtitleLabel.text = data.description
subtitleLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
subtitleLabel.textColor = UIColor(rgb: 0x00111B)
expirationLabel.text = data.expirationDate
expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 12)
expirationLabel.textColor = UIColor(rgb: 0x9BA1A6)
logoImage.image = UIImage(named: data.merchantLogo, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
}
func configureCell(data: CouponSetItemModel) {
// Use coupon set preview image
self.postImageURL = data._app_img_preview
// Use coupon set discount
discountLabel.text = data._discount
discountLabel.font = UIFont(name: "PingLCG-Bold", size: 14)
discountLabel.textColor = UIColor(rgb: 0xFFFFFF)
// discountView.backgroundColor = UIColor(rgb: discountColor)
discountView.backgroundColor = UIColor(rgb: 0xCBCBCB)
// Merchant name
if let merchant = data._merchant {
merchantNameLabel.text = merchant._admin_name
self.logoImageURL = merchant._img_preview
} else {
merchantNameLabel.text = ""
self.logoImageURL = nil
}
merchantNameLabel.font = UIFont(name: "PingLCG-Regular", size: 12)
merchantNameLabel.textColor = UIColor(rgb: 0x000F1E)
......@@ -122,5 +97,12 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell {
expirationLabel.text = "until " + data.formattedEndDate(format: "dd-MM")
expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 12)
expirationLabel.textColor = UIColor(rgb: 0x9BA1A6)
// Use merchant logo from bound merchant data
if let merchant = data._merchant, !merchant._img_preview.isEmpty {
self.logoImageURL = merchant._img_preview
} else {
self.logoImageURL = nil
}
}
}
......
......@@ -88,46 +88,27 @@ extension CategoryOffersGridTableViewCell: UICollectionViewDataSource, UICollect
guard let data = self.data,
let items = data.items,
indexPath.row < items.count else {
indexPath.row < items.count,
let couponSet = items[indexPath.row] as? CouponSetItemModel else {
return cell
}
switch data.itemType {
case .couponSets:
if let couponSet = items[indexPath.row] as? CouponSetItemModel {
cell.configureCell(data: couponSet)
}
default:
if let offer = items[indexPath.row] as? OfferModel {
cell.configureCell(data: offer)
}
}
return cell
}
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let data = self.data,
let items = data.items,
indexPath.row < items.count else {
indexPath.row < items.count,
let couponSet = items[indexPath.row] as? CouponSetItemModel else {
return
}
switch data.itemType {
case .couponSets:
if let couponSet = items[indexPath.row] as? CouponSetItemModel {
let vc = CouponsetViewController(nibName: "CouponsetViewController", bundle: Bundle.frameworkResourceBundle)
let vc = SwiftWarplyFramework.CouponsetViewController(nibName: "CouponsetViewController", bundle: Bundle.frameworkBundle)
vc.couponset = couponSet
parentViewController?.navigationController?.pushViewController(vc, animated: true)
}
default:
if let offer = items[indexPath.row] as? OfferModel {
let vc = CouponViewController(nibName: "CouponViewController", bundle: Bundle.frameworkResourceBundle)
vc.offer = offer
parentViewController?.navigationController?.pushViewController(vc, animated: true)
}
}
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return itemSize()
......
......@@ -31,11 +31,11 @@ import UIKit
tableView.rowHeight = UITableView.automaticDimension
tableView.register(
UINib(nibName: "CategoryOffersHeaderTableViewCell", bundle: Bundle.frameworkResourceBundle),
UINib(nibName: "CategoryOffersHeaderTableViewCell", bundle: Bundle.frameworkBundle),
forCellReuseIdentifier: "CategoryOffersHeaderTableViewCell"
)
tableView.register(
UINib(nibName: "CategoryOffersGridTableViewCell", bundle: Bundle.frameworkResourceBundle),
UINib(nibName: "CategoryOffersGridTableViewCell", bundle: Bundle.frameworkBundle),
forCellReuseIdentifier: "CategoryOffersGridTableViewCell"
)
}
......
......@@ -804,7 +804,7 @@ extension MyRewardsViewController: MyRewardsOffersScrollTableViewCellDelegate {
}
func didSelectAllOffers(_ section: SectionModel) {
let vc = CategoryOffersViewController(nibName: "CategoryOffersViewController", bundle: Bundle.frameworkResourceBundle)
let vc = CategoryOffersViewController(nibName: "CategoryOffersViewController", bundle: Bundle.frameworkBundle)
vc.sectionData = section
if let navigationController = self.navigationController {
navigationController.pushViewController(vc, animated: true)
......