Manos Chorianopoulos

MyRewardsVC fixes

...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>0</integer> 10 + <integer>1</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>1</integer> 10 + <integer>0</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -64,4 +64,162 @@ public class MyRewardsOfferCollectionViewCell: UICollectionViewCell { ...@@ -64,4 +64,162 @@ public class MyRewardsOfferCollectionViewCell: UICollectionViewCell {
64 64
65 logoImage.image = UIImage(named: data.merchantLogo, in: Bundle.frameworkResourceBundle, compatibleWith: nil) 65 logoImage.image = UIImage(named: data.merchantLogo, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
66 } 66 }
67 +
68 + // MARK: - New configureCell methods for different data types
69 +
70 + func configureCell(data: CampaignItemModel) {
71 + // Use campaign's banner image if available
72 + let imageName = data._banner_img_mobile ?? ""
73 + if !imageName.isEmpty {
74 + bannerImage.image = UIImage(named: imageName, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
75 + } else {
76 + bannerImage.image = nil
77 + }
78 +
79 + // Default to not favorite for campaigns
80 + favoriteImage.image = UIImage(named: "favorite_empty", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
81 +
82 + // Use campaign category or type for discount display
83 + discountLabel.text = data._category ?? data._campaign_type ?? ""
84 + discountLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
85 + discountLabel.textColor = UIColor(rgb: 0xF2F2F2)
86 +
87 + // Default color for campaigns
88 + discountView.backgroundColor = UIColor(rgb: 0xEE417D)
89 +
90 + titleLabel.text = data._title ?? ""
91 + titleLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
92 + titleLabel.textColor = UIColor(rgb: 0x000F1E)
93 +
94 + subtitleLabel.text = data._subtitle ?? ""
95 + subtitleLabel.font = UIFont(name: "PingLCG-Regular", size: 14)
96 + subtitleLabel.textColor = UIColor(rgb: 0x00111B)
97 +
98 + // Use campaign expiration date
99 + expirationLabel.text = data._valid_until ?? ""
100 + expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
101 + expirationLabel.textColor = UIColor(rgb: 0x00111B)
102 +
103 + // Use campaign logo
104 + let logoName = data._logo_url ?? ""
105 + if !logoName.isEmpty {
106 + logoImage.image = UIImage(named: logoName, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
107 + } else {
108 + logoImage.image = nil
109 + }
110 + }
111 +
112 + func configureCell(data: CouponSetItemModel) {
113 + // Use coupon set preview image
114 + let imageName = data.img_preview ?? ""
115 + if !imageName.isEmpty {
116 + bannerImage.image = UIImage(named: imageName, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
117 + } else {
118 + bannerImage.image = nil
119 + }
120 +
121 + // Default to not favorite for coupon sets
122 + favoriteImage.image = UIImage(named: "favorite_empty", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
123 +
124 + // Use coupon set discount
125 + discountLabel.text = data.discount ?? ""
126 + discountLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
127 + discountLabel.textColor = UIColor(rgb: 0xF2F2F2)
128 +
129 + // Color based on discount type
130 + let discountColor: UInt = {
131 + switch data.discount_type {
132 + case "percentage":
133 + return 0xFF6B35
134 + case "value":
135 + return 0x28A745
136 + case "plus_one":
137 + return 0x007AFF
138 + default:
139 + return 0x6C757D
140 + }
141 + }()
142 + discountView.backgroundColor = UIColor(rgb: discountColor)
143 +
144 + titleLabel.text = data.name ?? ""
145 + titleLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
146 + titleLabel.textColor = UIColor(rgb: 0x000F1E)
147 +
148 + subtitleLabel.text = data.short_description ?? ""
149 + subtitleLabel.font = UIFont(name: "PingLCG-Regular", size: 14)
150 + subtitleLabel.textColor = UIColor(rgb: 0x00111B)
151 +
152 + expirationLabel.text = data.expiration ?? ""
153 + expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
154 + expirationLabel.textColor = UIColor(rgb: 0x00111B)
155 +
156 + // Use first image from img array if available
157 + if let imgArray = data.img, !imgArray.isEmpty {
158 + let logoName = imgArray[0]
159 + if !logoName.isEmpty {
160 + logoImage.image = UIImage(named: logoName, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
161 + } else {
162 + logoImage.image = nil
163 + }
164 + } else {
165 + logoImage.image = nil
166 + }
167 + }
168 +
169 + func configureCell(data: CouponItemModel) {
170 + // Use coupon image
171 + let imageName = data.image ?? ""
172 + if !imageName.isEmpty {
173 + bannerImage.image = UIImage(named: imageName, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
174 + } else {
175 + bannerImage.image = nil
176 + }
177 +
178 + // Default to not favorite for coupons
179 + favoriteImage.image = UIImage(named: "favorite_empty", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
180 +
181 + // Use coupon discount
182 + discountLabel.text = data.discount ?? ""
183 + discountLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
184 + discountLabel.textColor = UIColor(rgb: 0xF2F2F2)
185 +
186 + // Color based on coupon status
187 + let statusColor: UInt = {
188 + switch data.status {
189 + case 1:
190 + return 0x28A745 // Active - green
191 + case 0:
192 + return 0x6C757D // Used - gray
193 + default:
194 + return 0x007AFF // Default - blue
195 + }
196 + }()
197 + discountView.backgroundColor = UIColor(rgb: statusColor)
198 +
199 + titleLabel.text = data.name ?? ""
200 + titleLabel.font = UIFont(name: "PingLCG-Bold", size: 17)
201 + titleLabel.textColor = UIColor(rgb: 0x000F1E)
202 +
203 + subtitleLabel.text = data.short_description ?? ""
204 + subtitleLabel.font = UIFont(name: "PingLCG-Regular", size: 14)
205 + subtitleLabel.textColor = UIColor(rgb: 0x00111B)
206 +
207 + expirationLabel.text = data.expiration ?? ""
208 + expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
209 + expirationLabel.textColor = UIColor(rgb: 0x00111B)
210 +
211 + // Use coupon set data image if available
212 + if let couponSetData = data.couponset_data,
213 + let imgArray = couponSetData.img,
214 + !imgArray.isEmpty {
215 + let logoName = imgArray[0]
216 + if !logoName.isEmpty {
217 + logoImage.image = UIImage(named: logoName, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
218 + } else {
219 + logoImage.image = nil
220 + }
221 + } else {
222 + logoImage.image = nil
223 + }
224 + }
67 } 225 }
......
...@@ -145,22 +145,103 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UIColl ...@@ -145,22 +145,103 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UIColl
145 } 145 }
146 146
147 public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 147 public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
148 - return self.data?.offers.count ?? 0 148 + return self.data?.itemCount ?? 0
149 } 149 }
150 150
151 public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 151 public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
152 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyRewardsOfferCollectionViewCell", for: indexPath) as! MyRewardsOfferCollectionViewCell 152 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyRewardsOfferCollectionViewCell", for: indexPath) as! MyRewardsOfferCollectionViewCell
153 -// cell.configureCell(offer: self.data?.offers[indexPath.row]) 153 +
154 - if let offer = self.data?.offers[indexPath.row] { 154 + // Handle different item types with type checking
155 - cell.configureCell(data: offer) 155 + guard let data = self.data,
156 + let items = data.items,
157 + indexPath.row < items.count else {
158 + return cell
159 + }
160 +
161 + switch data.itemType {
162 + case .campaigns:
163 + if let campaign = items[indexPath.row] as? CampaignItemModel {
164 + cell.configureCell(data: campaign)
165 + }
166 + case .couponSets:
167 + if let couponSet = items[indexPath.row] as? CouponSetItemModel {
168 + cell.configureCell(data: couponSet)
169 + }
170 + case .coupons:
171 + if let coupon = items[indexPath.row] as? CouponItemModel {
172 + cell.configureCell(data: coupon)
156 } 173 }
174 + default:
175 + break
176 + }
177 +
157 return cell; 178 return cell;
158 } 179 }
159 180
160 public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 181 public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
161 - if let offer = self.data?.offers[indexPath.row] { 182 + // Handle different item types with type checking
183 + guard let data = self.data,
184 + let items = data.items,
185 + indexPath.row < items.count else {
186 + return
187 + }
188 +
189 + switch data.itemType {
190 + case .campaigns:
191 + if let campaign = items[indexPath.row] as? CampaignItemModel {
192 + // For now, we'll need to convert CampaignItemModel to OfferModel for delegate compatibility
193 + // This maintains backward compatibility while using the new data structure
194 + let offer = OfferModel(
195 + category: campaign._category ?? "",
196 + title: campaign._title ?? "",
197 + description: campaign._subtitle ?? "",
198 + discount: "",
199 + discountType: "",
200 + bannerImage: campaign._banner_img_mobile ?? "",
201 + merchantLogo: campaign._logo_url ?? "",
202 + expirationDate: "",
203 + color: 0x000000,
204 + isFavorite: false
205 + )
206 + delegate?.didSelectOffer(offer)
207 + }
208 + case .couponSets:
209 + if let couponSet = items[indexPath.row] as? CouponSetItemModel {
210 + // Convert CouponSetItemModel to OfferModel for delegate compatibility
211 + let offer = OfferModel(
212 + category: "",
213 + title: couponSet._name ?? "",
214 + description: couponSet._short_description ?? "",
215 + discount: "",
216 + discountType: "",
217 + bannerImage: "",
218 + merchantLogo: couponSet._img_preview ?? "",
219 + expirationDate: "",
220 + color: 0x000000,
221 + isFavorite: false
222 + )
162 delegate?.didSelectOffer(offer) 223 delegate?.didSelectOffer(offer)
163 } 224 }
225 + case .coupons:
226 + if let coupon = items[indexPath.row] as? CouponItemModel {
227 + // Convert CouponItemModel to OfferModel for delegate compatibility
228 + let offer = OfferModel(
229 + category: "",
230 + title: coupon._name ?? "",
231 + description: coupon._short_description ?? "",
232 + discount: "",
233 + discountType: "",
234 + bannerImage: "",
235 + merchantLogo: coupon._img_preview ?? "",
236 + expirationDate: "",
237 + color: 0x000000,
238 + isFavorite: false
239 + )
240 + delegate?.didSelectOffer(offer)
241 + }
242 + default:
243 + break
244 + }
164 } 245 }
165 246
166 // MARK: - UICollectionViewDelegateFlowLayout 247 // MARK: - UICollectionViewDelegateFlowLayout
......