Manos Chorianopoulos

CategoryOffers fixes part2

...@@ -22,8 +22,10 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell { ...@@ -22,8 +22,10 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell {
22 var postImageURL: String? { 22 var postImageURL: String? {
23 didSet { 23 didSet {
24 if let url = postImageURL { 24 if let url = postImageURL {
25 - self.bannerImage.image = UIImage() 25 + self.bannerImage.image = UIImage() // UIImage(named: "loading")
26 +
26 UIImage.loadImageUsingCacheWithUrlString(url) { image in 27 UIImage.loadImageUsingCacheWithUrlString(url) { image in
28 + // set the image only when we are still displaying the content for the image we finished downloading
27 if url == self.postImageURL { 29 if url == self.postImageURL {
28 self.bannerImage.image = image 30 self.bannerImage.image = image
29 } 31 }
...@@ -37,8 +39,10 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell { ...@@ -37,8 +39,10 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell {
37 var logoImageURL: String? { 39 var logoImageURL: String? {
38 didSet { 40 didSet {
39 if let url = logoImageURL { 41 if let url = logoImageURL {
40 - self.logoImage.image = UIImage() 42 + self.logoImage.image = UIImage() // UIImage(named: "loading")
43 +
41 UIImage.loadImageUsingCacheWithUrlString(url) { image in 44 UIImage.loadImageUsingCacheWithUrlString(url) { image in
45 + // set the image only when we are still displaying the content for the image we finished downloading
42 if url == self.logoImageURL { 46 if url == self.logoImageURL {
43 self.logoImage.image = image 47 self.logoImage.image = image
44 } 48 }
...@@ -57,57 +61,28 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell { ...@@ -57,57 +61,28 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell {
57 parentView.layer.cornerRadius = 12.0 61 parentView.layer.cornerRadius = 12.0
58 parentView.clipsToBounds = true 62 parentView.clipsToBounds = true
59 63
60 - logoImage.layer.cornerRadius = 8.0
61 - logoImage.clipsToBounds = true
62 - logoImage.backgroundColor = UIColor(rgb: 0xEEEEEE)
63 -
64 discountView.layer.cornerRadius = 17.0 64 discountView.layer.cornerRadius = 17.0
65 discountView.clipsToBounds = true 65 discountView.clipsToBounds = true
66 } 66 }
67 67
68 - func configureCell(data: OfferModel) {
69 - bannerImage.image = UIImage(named: data.bannerImage, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
70 -
71 - discountLabel.text = data.discount
72 - discountLabel.font = UIFont(name: "PingLCG-Bold", size: 14)
73 - discountLabel.textColor = UIColor(rgb: 0xFFFFFF)
74 - discountView.backgroundColor = UIColor(rgb: 0xCBCBCB)
75 -
76 - merchantNameLabel.text = data.title
77 - merchantNameLabel.font = UIFont(name: "PingLCG-Regular", size: 12)
78 - merchantNameLabel.textColor = UIColor(rgb: 0x000F1E)
79 -
80 - titleLabel.text = data.title
81 - titleLabel.font = UIFont(name: "PingLCG-Bold", size: 15)
82 - titleLabel.textColor = UIColor(rgb: 0x000F1E)
83 -
84 - subtitleLabel.text = data.description
85 - subtitleLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
86 - subtitleLabel.textColor = UIColor(rgb: 0x00111B)
87 -
88 - expirationLabel.text = data.expirationDate
89 - expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 12)
90 - expirationLabel.textColor = UIColor(rgb: 0x9BA1A6)
91 -
92 - logoImage.image = UIImage(named: data.merchantLogo, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
93 - }
94 -
95 func configureCell(data: CouponSetItemModel) { 68 func configureCell(data: CouponSetItemModel) {
69 + // Use coupon set preview image
96 self.postImageURL = data._app_img_preview 70 self.postImageURL = data._app_img_preview
97 71
72 + // Use coupon set discount
98 discountLabel.text = data._discount 73 discountLabel.text = data._discount
99 discountLabel.font = UIFont(name: "PingLCG-Bold", size: 14) 74 discountLabel.font = UIFont(name: "PingLCG-Bold", size: 14)
100 discountLabel.textColor = UIColor(rgb: 0xFFFFFF) 75 discountLabel.textColor = UIColor(rgb: 0xFFFFFF)
76 +
77 + // discountView.backgroundColor = UIColor(rgb: discountColor)
101 discountView.backgroundColor = UIColor(rgb: 0xCBCBCB) 78 discountView.backgroundColor = UIColor(rgb: 0xCBCBCB)
102 79
80 + // Merchant name
103 if let merchant = data._merchant { 81 if let merchant = data._merchant {
104 merchantNameLabel.text = merchant._admin_name 82 merchantNameLabel.text = merchant._admin_name
105 - self.logoImageURL = merchant._img_preview
106 } else { 83 } else {
107 merchantNameLabel.text = "" 84 merchantNameLabel.text = ""
108 - self.logoImageURL = nil
109 } 85 }
110 -
111 merchantNameLabel.font = UIFont(name: "PingLCG-Regular", size: 12) 86 merchantNameLabel.font = UIFont(name: "PingLCG-Regular", size: 12)
112 merchantNameLabel.textColor = UIColor(rgb: 0x000F1E) 87 merchantNameLabel.textColor = UIColor(rgb: 0x000F1E)
113 88
...@@ -122,5 +97,12 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell { ...@@ -122,5 +97,12 @@ public class CategoryOfferCollectionViewCell: UICollectionViewCell {
122 expirationLabel.text = "until " + data.formattedEndDate(format: "dd-MM") 97 expirationLabel.text = "until " + data.formattedEndDate(format: "dd-MM")
123 expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 12) 98 expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 12)
124 expirationLabel.textColor = UIColor(rgb: 0x9BA1A6) 99 expirationLabel.textColor = UIColor(rgb: 0x9BA1A6)
100 +
101 + // Use merchant logo from bound merchant data
102 + if let merchant = data._merchant, !merchant._img_preview.isEmpty {
103 + self.logoImageURL = merchant._img_preview
104 + } else {
105 + self.logoImageURL = nil
106 + }
125 } 107 }
126 } 108 }
......
...@@ -88,46 +88,27 @@ extension CategoryOffersGridTableViewCell: UICollectionViewDataSource, UICollect ...@@ -88,46 +88,27 @@ extension CategoryOffersGridTableViewCell: UICollectionViewDataSource, UICollect
88 88
89 guard let data = self.data, 89 guard let data = self.data,
90 let items = data.items, 90 let items = data.items,
91 - indexPath.row < items.count else { 91 + indexPath.row < items.count,
92 + let couponSet = items[indexPath.row] as? CouponSetItemModel else {
92 return cell 93 return cell
93 } 94 }
94 95
95 - switch data.itemType {
96 - case .couponSets:
97 - if let couponSet = items[indexPath.row] as? CouponSetItemModel {
98 cell.configureCell(data: couponSet) 96 cell.configureCell(data: couponSet)
99 - }
100 - default:
101 - if let offer = items[indexPath.row] as? OfferModel {
102 - cell.configureCell(data: offer)
103 - }
104 - }
105 -
106 return cell 97 return cell
107 } 98 }
108 99
109 public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 100 public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
110 guard let data = self.data, 101 guard let data = self.data,
111 let items = data.items, 102 let items = data.items,
112 - indexPath.row < items.count else { 103 + indexPath.row < items.count,
104 + let couponSet = items[indexPath.row] as? CouponSetItemModel else {
113 return 105 return
114 } 106 }
115 107
116 - switch data.itemType { 108 + let vc = SwiftWarplyFramework.CouponsetViewController(nibName: "CouponsetViewController", bundle: Bundle.frameworkBundle)
117 - case .couponSets:
118 - if let couponSet = items[indexPath.row] as? CouponSetItemModel {
119 - let vc = CouponsetViewController(nibName: "CouponsetViewController", bundle: Bundle.frameworkResourceBundle)
120 vc.couponset = couponSet 109 vc.couponset = couponSet
121 parentViewController?.navigationController?.pushViewController(vc, animated: true) 110 parentViewController?.navigationController?.pushViewController(vc, animated: true)
122 } 111 }
123 - default:
124 - if let offer = items[indexPath.row] as? OfferModel {
125 - let vc = CouponViewController(nibName: "CouponViewController", bundle: Bundle.frameworkResourceBundle)
126 - vc.offer = offer
127 - parentViewController?.navigationController?.pushViewController(vc, animated: true)
128 - }
129 - }
130 - }
131 112
132 public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 113 public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
133 return itemSize() 114 return itemSize()
......
...@@ -31,11 +31,11 @@ import UIKit ...@@ -31,11 +31,11 @@ import UIKit
31 tableView.rowHeight = UITableView.automaticDimension 31 tableView.rowHeight = UITableView.automaticDimension
32 32
33 tableView.register( 33 tableView.register(
34 - UINib(nibName: "CategoryOffersHeaderTableViewCell", bundle: Bundle.frameworkResourceBundle), 34 + UINib(nibName: "CategoryOffersHeaderTableViewCell", bundle: Bundle.frameworkBundle),
35 forCellReuseIdentifier: "CategoryOffersHeaderTableViewCell" 35 forCellReuseIdentifier: "CategoryOffersHeaderTableViewCell"
36 ) 36 )
37 tableView.register( 37 tableView.register(
38 - UINib(nibName: "CategoryOffersGridTableViewCell", bundle: Bundle.frameworkResourceBundle), 38 + UINib(nibName: "CategoryOffersGridTableViewCell", bundle: Bundle.frameworkBundle),
39 forCellReuseIdentifier: "CategoryOffersGridTableViewCell" 39 forCellReuseIdentifier: "CategoryOffersGridTableViewCell"
40 ) 40 )
41 } 41 }
......
...@@ -804,7 +804,7 @@ extension MyRewardsViewController: MyRewardsOffersScrollTableViewCellDelegate { ...@@ -804,7 +804,7 @@ extension MyRewardsViewController: MyRewardsOffersScrollTableViewCellDelegate {
804 } 804 }
805 805
806 func didSelectAllOffers(_ section: SectionModel) { 806 func didSelectAllOffers(_ section: SectionModel) {
807 - let vc = CategoryOffersViewController(nibName: "CategoryOffersViewController", bundle: Bundle.frameworkResourceBundle) 807 + let vc = CategoryOffersViewController(nibName: "CategoryOffersViewController", bundle: Bundle.frameworkBundle)
808 vc.sectionData = section 808 vc.sectionData = section
809 if let navigationController = self.navigationController { 809 if let navigationController = self.navigationController {
810 navigationController.pushViewController(vc, animated: true) 810 navigationController.pushViewController(vc, animated: true)
......