Manos Chorianopoulos

MyRewardsVC fixes

...@@ -121,23 +121,15 @@ extension MyRewardsBannerOffersScrollTableViewCell: UICollectionViewDataSource, ...@@ -121,23 +121,15 @@ extension MyRewardsBannerOffersScrollTableViewCell: UICollectionViewDataSource,
121 public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 121 public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
122 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyRewardsBannerOfferCollectionViewCell", for: indexPath) as! MyRewardsBannerOfferCollectionViewCell 122 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyRewardsBannerOfferCollectionViewCell", for: indexPath) as! MyRewardsBannerOfferCollectionViewCell
123 123
124 - // Handle different item types 124 + // Handle only CampaignItemModel - banner cells are campaign-specific
125 guard let data = self.data, 125 guard let data = self.data,
126 - let itemType = data.itemType,
127 let items = data.items, 126 let items = data.items,
128 - indexPath.row < items.count else { 127 + indexPath.row < items.count,
128 + let campaign = items[indexPath.row] as? CampaignItemModel else {
129 return cell 129 return cell
130 } 130 }
131 131
132 - switch itemType {
133 - case .campaigns:
134 - if let campaign = items[indexPath.row] as? CampaignItemModel {
135 cell.configureCell(data: campaign) 132 cell.configureCell(data: campaign)
136 - }
137 - default:
138 - // Handle other types if needed in the future
139 - break
140 - }
141 133
142 return cell 134 return cell
143 } 135 }
......
...@@ -65,49 +65,6 @@ public class MyRewardsOfferCollectionViewCell: UICollectionViewCell { ...@@ -65,49 +65,6 @@ public class MyRewardsOfferCollectionViewCell: UICollectionViewCell {
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 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 68
112 func configureCell(data: CouponSetItemModel) { 69 func configureCell(data: CouponSetItemModel) {
113 // Use coupon set preview image 70 // Use coupon set preview image
...@@ -166,60 +123,4 @@ public class MyRewardsOfferCollectionViewCell: UICollectionViewCell { ...@@ -166,60 +123,4 @@ public class MyRewardsOfferCollectionViewCell: UICollectionViewCell {
166 } 123 }
167 } 124 }
168 125
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 - }
225 } 126 }
......
...@@ -151,7 +151,7 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UIColl ...@@ -151,7 +151,7 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UIColl
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 153
154 - // Handle different item types with type checking 154 + // Handle only CouponSetItemModel and OfferModel - no campaigns
155 guard let data = self.data, 155 guard let data = self.data,
156 let items = data.items, 156 let items = data.items,
157 indexPath.row < items.count else { 157 indexPath.row < items.count else {
...@@ -159,27 +159,22 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UIColl ...@@ -159,27 +159,22 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UIColl
159 } 159 }
160 160
161 switch data.itemType { 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: 162 case .couponSets:
167 if let couponSet = items[indexPath.row] as? CouponSetItemModel { 163 if let couponSet = items[indexPath.row] as? CouponSetItemModel {
168 cell.configureCell(data: couponSet) 164 cell.configureCell(data: couponSet)
169 } 165 }
170 - case .coupons:
171 - if let coupon = items[indexPath.row] as? CouponItemModel {
172 - cell.configureCell(data: coupon)
173 - }
174 default: 166 default:
175 - break 167 + // Handle OfferModel for ProfileViewController compatibility
168 + if let offer = items[indexPath.row] as? OfferModel {
169 + cell.configureCell(data: offer)
170 + }
176 } 171 }
177 172
178 return cell; 173 return cell;
179 } 174 }
180 175
181 public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 176 public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
182 - // Handle different item types with type checking 177 + // Handle only CouponSetItemModel and OfferModel - no campaigns
183 guard let data = self.data, 178 guard let data = self.data,
184 let items = data.items, 179 let items = data.items,
185 indexPath.row < items.count else { 180 indexPath.row < items.count else {
...@@ -187,60 +182,28 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UIColl ...@@ -187,60 +182,28 @@ extension MyRewardsOffersScrollTableViewCell: UICollectionViewDataSource, UIColl
187 } 182 }
188 183
189 switch data.itemType { 184 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: 185 case .couponSets:
209 if let couponSet = items[indexPath.row] as? CouponSetItemModel { 186 if let couponSet = items[indexPath.row] as? CouponSetItemModel {
210 // Convert CouponSetItemModel to OfferModel for delegate compatibility 187 // Convert CouponSetItemModel to OfferModel for delegate compatibility
211 let offer = OfferModel( 188 let offer = OfferModel(
212 category: "", 189 category: "",
213 - title: couponSet._name ?? "", 190 + title: couponSet.name ?? "",
214 - description: couponSet._short_description ?? "", 191 + description: couponSet.short_description ?? "",
215 - discount: "", 192 + discount: couponSet.discount ?? "",
216 - discountType: "", 193 + discountType: couponSet.discount_type ?? "",
217 - bannerImage: "", 194 + bannerImage: couponSet.img_preview ?? "",
218 - merchantLogo: couponSet._img_preview ?? "", 195 + merchantLogo: couponSet.img?.first ?? "",
219 - expirationDate: "", 196 + expirationDate: couponSet.expiration ?? "",
220 color: 0x000000, 197 color: 0x000000,
221 isFavorite: false 198 isFavorite: false
222 ) 199 )
223 delegate?.didSelectOffer(offer) 200 delegate?.didSelectOffer(offer)
224 } 201 }
225 - case .coupons: 202 + default:
226 - if let coupon = items[indexPath.row] as? CouponItemModel { 203 + // Handle OfferModel directly for ProfileViewController compatibility
227 - // Convert CouponItemModel to OfferModel for delegate compatibility 204 + if let offer = items[indexPath.row] as? OfferModel {
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) 205 delegate?.didSelectOffer(offer)
241 } 206 }
242 - default:
243 - break
244 } 207 }
245 } 208 }
246 209
......
...@@ -247,16 +247,16 @@ import UIKit ...@@ -247,16 +247,16 @@ import UIKit
247 let forYouOffers = allOffers.filter { $0.category == "Προτάσεις για εσένα" } 247 let forYouOffers = allOffers.filter { $0.category == "Προτάσεις για εσένα" }
248 forYouOffersSection = SectionModel( 248 forYouOffersSection = SectionModel(
249 title: "Προτάσεις για εσένα", 249 title: "Προτάσεις για εσένα",
250 - count: forYouOffers.count, 250 + items: forYouOffers,
251 - offers: forYouOffers 251 + itemType: .offers
252 ) 252 )
253 253
254 - // Favorite Offers 254 + // Active Offers
255 let activeOffers = allOffers.filter { $0.active ?? false } 255 let activeOffers = allOffers.filter { $0.active ?? false }
256 activeOffersSection = SectionModel( 256 activeOffersSection = SectionModel(
257 title: "Ενεργά", 257 title: "Ενεργά",
258 - count: activeOffers.count, 258 + items: activeOffers,
259 - offers: activeOffers 259 + itemType: .offers
260 ) 260 )
261 261
262 filteredOffersSection = activeOffersSection 262 filteredOffersSection = activeOffersSection
...@@ -265,16 +265,16 @@ import UIKit ...@@ -265,16 +265,16 @@ import UIKit
265 let favoriteOffers = allOffers.filter { $0.isFavorite } 265 let favoriteOffers = allOffers.filter { $0.isFavorite }
266 favoriteOffersSection = SectionModel( 266 favoriteOffersSection = SectionModel(
267 title: "Αγαπημένα", 267 title: "Αγαπημένα",
268 - count: favoriteOffers.count, 268 + items: favoriteOffers,
269 - offers: favoriteOffers 269 + itemType: .offers
270 ) 270 )
271 271
272 - // Favorite Offers 272 + // Redeemed Offers
273 let redeemedOffers = allOffers.filter { $0.redeemed ?? false } 273 let redeemedOffers = allOffers.filter { $0.redeemed ?? false }
274 redeemedOffersSection = SectionModel( 274 redeemedOffersSection = SectionModel(
275 title: "Εξαργυρωμένα", 275 title: "Εξαργυρωμένα",
276 - count: redeemedOffers.count, 276 + items: redeemedOffers,
277 - offers: redeemedOffers 277 + itemType: .offers
278 ) 278 )
279 279
280 self.tableView.reloadData() 280 self.tableView.reloadData()
...@@ -314,7 +314,7 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource { ...@@ -314,7 +314,7 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource {
314 if (section <= 3) { 314 if (section <= 3) {
315 return 1 315 return 1
316 } else { 316 } else {
317 - return filteredOffersSection?.offers.count ?? 0 317 + return filteredOffersSection?.itemCount ?? 0
318 } 318 }
319 } 319 }
320 320
...@@ -383,7 +383,9 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource { ...@@ -383,7 +383,9 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource {
383 383
384 } else { 384 } else {
385 let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileCouponTableViewCell", for: indexPath) as! ProfileCouponTableViewCell 385 let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileCouponTableViewCell", for: indexPath) as! ProfileCouponTableViewCell
386 - if let offer = self.filteredOffersSection?.offers[indexPath.row] { 386 + if let items = self.filteredOffersSection?.items,
387 + indexPath.row < items.count,
388 + let offer = items[indexPath.row] as? OfferModel {
387 cell.configureCell(data: offer) 389 cell.configureCell(data: offer)
388 } 390 }
389 return cell 391 return cell
...@@ -395,7 +397,9 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource { ...@@ -395,7 +397,9 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource {
395 if (indexPath.section <= 3) { 397 if (indexPath.section <= 3) {
396 // Do nothing 398 // Do nothing
397 } else { 399 } else {
398 - if let offer = self.filteredOffersSection?.offers[indexPath.row] { 400 + if let items = self.filteredOffersSection?.items,
401 + indexPath.row < items.count,
402 + let offer = items[indexPath.row] as? OfferModel {
399 openCouponViewController(with: offer) 403 openCouponViewController(with: offer)
400 } 404 }
401 } 405 }
......